diff options
author | Craig Tiller <ctiller@google.com> | 2017-01-17 16:51:08 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-01-17 16:51:08 -0800 |
commit | 35d89551304a1945e67254920356542f94b45707 (patch) | |
tree | 1305db2a31fe7439dcc0345ca7f3a0392173ad71 | |
parent | 7bb90fa57c07741556eb14ae8f058ecfff3e838c (diff) | |
parent | a47245112ba370bf411c3c90cff02da962775fa8 (diff) |
Merge pull request #46 from soltanmm-google/heatbeat's-aerys-is-an-awesome-dance-tune-y'all
Fix Python errors
-rw-r--r-- | src/python/grpcio/grpc/_cython/_cygrpc/records.pxd.pxi | 4 | ||||
-rw-r--r-- | src/python/grpcio/grpc/_cython/_cygrpc/records.pyx.pxi | 16 |
2 files changed, 13 insertions, 7 deletions
diff --git a/src/python/grpcio/grpc/_cython/_cygrpc/records.pxd.pxi b/src/python/grpcio/grpc/_cython/_cygrpc/records.pxd.pxi index 3644b7cdae..e927605384 100644 --- a/src/python/grpcio/grpc/_cython/_cygrpc/records.pxd.pxi +++ b/src/python/grpcio/grpc/_cython/_cygrpc/records.pxd.pxi @@ -117,8 +117,8 @@ cdef class Metadata: cdef grpc_metadata_array c_metadata_array cdef bint owns_metadata_slices cdef object metadata - cdef void _claim_slice_ownership(self) nogil - cdef void _drop_slice_ownership(self) nogil + cdef void _claim_slice_ownership(self) + cdef void _drop_slice_ownership(self) cdef class Operation: diff --git a/src/python/grpcio/grpc/_cython/_cygrpc/records.pyx.pxi b/src/python/grpcio/grpc/_cython/_cygrpc/records.pyx.pxi index 30e7b9657a..d7a7713332 100644 --- a/src/python/grpcio/grpc/_cython/_cygrpc/records.pyx.pxi +++ b/src/python/grpcio/grpc/_cython/_cygrpc/records.pyx.pxi @@ -466,6 +466,10 @@ cdef class _MetadataIterator: else: raise StopIteration +cdef grpc_slice _copy_slice(grpc_slice slice) nogil: + cdef void *start = grpc_slice_start_ptr(slice) + cdef size_t length = grpc_slice_length(slice) + return grpc_slice_from_copied_buffer(<const char *>start, length) cdef class Metadata: @@ -489,8 +493,8 @@ cdef class Metadata: (<Metadatum>self.metadata[i]).c_metadata) def __dealloc__(self): + self._drop_slice_ownership() with nogil: - self._drop_slice_ownership() # this frees the allocated memory for the grpc_metadata_array (although # it'd be nice if that were documented somewhere...) # TODO(atash): document this in the C core @@ -510,15 +514,17 @@ cdef class Metadata: def __iter__(self): return _MetadataIterator(self) - cdef void _claim_slice_ownership(self) nogil: + cdef void _claim_slice_ownership(self): if self.owns_metadata_slices: return for i in range(self.c_metadata_array.count): - grpc_slice_ref(self.c_metadata_array.metadata[i].key) - grpc_slice_ref(self.c_metadata_array.metadata[i].value) + self.c_metadata_array.metadata[i].key = _copy_slice( + self.c_metadata_array.metadata[i].key) + self.c_metadata_array.metadata[i].value = _copy_slice( + self.c_metadata_array.metadata[i].value) self.owns_metadata_slices = True - cdef void _drop_slice_ownership(self) nogil: + cdef void _drop_slice_ownership(self): if not self.owns_metadata_slices: return for i in range(self.c_metadata_array.count): |