Add Cython functionality to directly wrap grpc_arg

pull/16192/head
Mehrdad Afshari 7 years ago
parent 682d093868
commit fbfebd8e4e
  1. 5
      src/python/grpcio/grpc/_cython/_cygrpc/arguments.pxd.pxi
  2. 14
      src/python/grpcio/grpc/_cython/_cygrpc/arguments.pyx.pxi

@ -1,4 +1,4 @@
# Copyright 2018 gRPC authors.
# Copyright 2018 The gRPC Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
@ -22,6 +22,9 @@ cdef void _destroy_pointer(void* pointer)
cdef int _compare_pointer(void* first_pointer, void* second_pointer)
cdef tuple _wrap_grpc_arg(grpc_arg arg)
cdef class _ArgumentProcessor:
cdef grpc_arg c_argument

@ -34,6 +34,18 @@ cdef int _compare_pointer(void* first_pointer, void* second_pointer):
return 0
cdef class _GrpcArgWrapper:
cdef grpc_arg arg
cdef tuple _wrap_grpc_arg(grpc_arg arg):
wrapped = _GrpcArgWrapper()
wrapped.arg = arg
return ("grpc.python._cygrpc._GrpcArgWrapper", wrapped)
cdef class _ArgumentProcessor:
cdef void c(self, argument, grpc_arg_pointer_vtable *vtable, references):
@ -51,6 +63,8 @@ cdef class _ArgumentProcessor:
if encoded_value is not value:
references.append(encoded_value)
self.c_argument.value.string = encoded_value
elif isinstance(value, _GrpcArgWrapper):
self.c_argument = (<_GrpcArgWrapper>value).arg
elif hasattr(value, '__int__'):
# Pointer objects must override __int__() to return
# the underlying C address (Python ints are word size). The

Loading…
Cancel
Save