Use unique_ptr and shared_ptr from Cython

This commit is contained in:
Uwe L. Korn committed 2016-06-10 11:56:53 +02:00
1 parent 8f6010aa58
commit 000e1e34d6
4 files changed
+10 -25

No files matched your search

+1 -19
View File
@@ -19,6 +19,7 @@
from libc.stdint cimport *
from libcpp cimport bool as c_bool
from libcpp.memory cimport shared_ptr, unique_ptr
from libcpp.string cimport string as c_string
from libcpp.vector cimport vector
@@ -32,22 +33,3 @@ cdef extern from "<iostream>":
cdef extern from "<Python.h>":
void Py_XDECREF(PyObject* o)
cdef extern from "<memory>" namespace "std" nogil:
cdef cppclass unique_ptr[T]:
unique_ptr()
unique_ptr(T*)
T* get()
T* release()
void reset()
void reset(nullptr_t)
void reset(T*)
void swap(unique_ptr&)
cdef cppclass shared_ptr[T]:
shared_ptr()
shared_ptr(T*)
T* get()
void reset()
void reset(T* p)
void swap(shared_ptr&)
+2 -2
View File
@@ -59,13 +59,13 @@ def write_table(table, filename, chunk_size=None):
"""
cdef Table table_ = table
cdef CTable* ctable_ = table_.table
cdef shared_ptr[OutputStream] sink = shared_ptr[OutputStream](
new LocalFileOutputStream(tobytes(filename)))
cdef shared_ptr[OutputStream] sink
cdef int64_t chunk_size_ = 0
if chunk_size is None:
chunk_size_ = min(ctable_.num_rows(), int(2**16))
else:
chunk_size_ = chunk_size
sink.reset(new LocalFileOutputStream(tobytes(filename)))
check_cstatus(WriteFlatTable(ctable_, default_memory_pool(), sink, chunk_size_))
+6 -3
View File
@@ -201,7 +201,9 @@ def string():
def list_(DataType value_type):
cdef DataType out = DataType()
out.init(shared_ptr[CDataType](new CListType(value_type.sp_type)))
cdef shared_ptr[CDataType] list_type
list_type.reset(new CListType(value_type.sp_type))
out.init(list_type)
return out
def struct(fields):
@@ -212,12 +214,13 @@ def struct(fields):
DataType out = DataType()
Field field
vector[shared_ptr[CField]] c_fields
cdef shared_ptr[CDataType] struct_type
for field in fields:
c_fields.push_back(field.sp_field)
out.init(shared_ptr[CDataType](
new CStructType(c_fields)))
struct_type.reset(new CStructType(c_fields))
out.init(struct_type)
return out
def schema(fields):
+1 -1
View File
@@ -242,7 +242,7 @@ setup(
'clean': clean,
'build_ext': build_ext
},
install_requires=['cython >= 0.21', 'numpy >= 1.9'],
install_requires=['cython >= 0.23', 'numpy >= 1.9'],
description=DESC,
license='Apache License, Version 2.0',
maintainer="Apache Arrow Developers",