Skip to content

Instantly share code, notes, and snippets.

@robertwb
Created January 3, 2016 01:26
Show Gist options
  • Save robertwb/1385afaea4df10eb224a to your computer and use it in GitHub Desktop.
Save robertwb/1385afaea4df10eb224a to your computer and use it in GitHub Desktop.
#distutils: language=c++
from libcpp.memory cimport shared_ptr
from cpython.buffer cimport PyObject_GetBuffer, PyBUF_FULL
cdef extern from *:
cdef cppclass CppObj:
pass
cdef shared_ptr[CppObj] cpp_function(Py_buffer *buf)
cdef class PyObj:
cdef shared_ptr[CppObj] _ptr
@staticmethod
cdef create(shared_ptr[CppObj] ptr):
cdef PyObj py_obj = PyObj()
py_obj._ptr = ptr
return py_obj
cdef test_wrap(mat):
cdef Py_buffer buf
PyObject_GetBuffer(mat, &buf, PyBUF_FULL)
cdef shared_ptr[CppObj] obj_ptr = cpp_function(&buf)
return PyObj.create(obj_ptr)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment