aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/python/grpcio/grpc/_cython/_cygrpc/records.pyx.pxi
diff options
context:
space:
mode:
authorGravatar kpayson64 <kpayson@google.com>2016-10-13 15:12:33 -0700
committerGravatar GitHub <noreply@github.com>2016-10-13 15:12:33 -0700
commit448a16dd2886c84295d3ffc8aae2ccbecb462d38 (patch)
tree78fe799739e55c5cca0d2553ab615d1efdbf0344 /src/python/grpcio/grpc/_cython/_cygrpc/records.pyx.pxi
parent58628ae7a70feff295fc7f44de60686439a2beca (diff)
parent58c0f96f1962652e80d9aba43f260240daf610f0 (diff)
Merge pull request #8127 from kpayson64/allow_pointers
Allow pointer channel args python
Diffstat (limited to 'src/python/grpcio/grpc/_cython/_cygrpc/records.pyx.pxi')
-rw-r--r--src/python/grpcio/grpc/_cython/_cygrpc/records.pyx.pxi34
1 files changed, 32 insertions, 2 deletions
diff --git a/src/python/grpcio/grpc/_cython/_cygrpc/records.pyx.pxi b/src/python/grpcio/grpc/_cython/_cygrpc/records.pyx.pxi
index 5a11a08f54..8a4eef4d2e 100644
--- a/src/python/grpcio/grpc/_cython/_cygrpc/records.pyx.pxi
+++ b/src/python/grpcio/grpc/_cython/_cygrpc/records.pyx.pxi
@@ -27,6 +27,7 @@
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+from libc.stdint cimport intptr_t
class ConnectivityState:
idle = GRPC_CHANNEL_IDLE
@@ -304,20 +305,49 @@ cdef class SslPemKeyCertPair:
self.c_pair.certificate_chain = self.certificate_chain
+
+cdef void* copy_ptr(void* ptr):
+ return ptr
+
+
+cdef void destroy_ptr(void* ptr):
+ pass
+
+
+cdef int compare_ptr(void* ptr1, void* ptr2):
+ if ptr1 < ptr2:
+ return -1
+ elif ptr1 > ptr2:
+ return 1
+ else:
+ return 0
+
+
cdef class ChannelArg:
def __cinit__(self, bytes key, value):
self.key = key
+ self.value = value
self.c_arg.key = self.key
if isinstance(value, int):
- self.value = value
self.c_arg.type = GRPC_ARG_INTEGER
self.c_arg.value.integer = self.value
elif isinstance(value, bytes):
- self.value = value
self.c_arg.type = GRPC_ARG_STRING
self.c_arg.value.string = self.value
+ elif hasattr(value, '__int__'):
+ # Pointer objects must override __int__() to return
+ # the underlying C address (Python ints are word size). The
+ # lifecycle of the pointer is fixed to the lifecycle of the
+ # python object wrapping it.
+ self.ptr_vtable.copy = &copy_ptr
+ self.ptr_vtable.destroy = &destroy_ptr
+ self.ptr_vtable.cmp = &compare_ptr
+ self.c_arg.type = GRPC_ARG_POINTER
+ self.c_arg.value.pointer.vtable = &self.ptr_vtable
+ self.c_arg.value.pointer.address = <void*>(<intptr_t>int(self.value))
else:
+ # TODO Add supported pointer types to this message
raise TypeError('Expected int or bytes, got {}'.format(type(value)))