Re: Storing a C pointer in a Python class instance

2009-10-06 Thread lallous
"Carl Banks" wrote in message news:d50bba1e-b272-4e39-8a58-377531278...@z4g2000prh.googlegroups.com... On Sep 30, 5:24 am, "lallous" wrote: Hello After using the PyCObject, I cannot pickle the class anymore. Any simple solution to this problem? (or resorting to __reduce__ is the only soluti

Re: Storing a C pointer in a Python class instance

2009-09-30 Thread sturlamolden
On 30 Sep, 19:03, Carl Banks wrote: > Second, CObjects do not have a __del__ method.  They call the supplied > constructor from the type's tp_dealloc slot.  Use of the tp_dealloc > slot does not, by itself, prevent cyclic GC. > > Bottom line is, the CObject's deallocator is as reliable as a custo

Re: Storing a C pointer in a Python class instance

2009-09-30 Thread Carl Banks
On Sep 29, 11:16 am, sturlamolden wrote: > On 29 Sep, 19:11, Carl Banks wrote: > > > CObjects can be passed a C function as a deallocator; this should work > > as reliably as a custom class deallocator. > > Except that __del__ prevents cyclic GC. You are mistaken on two counts. First of all, a

Re: Storing a C pointer in a Python class instance

2009-09-30 Thread Carl Banks
On Sep 30, 5:24 am, "lallous" wrote: > Hello > > After using the PyCObject, I cannot pickle the class anymore. > Any simple solution to this problem? (or resorting to __reduce__ is the only > solution?) You can't pickle a CObject, you'd have to create a custom type (one that implements one of th

Re: Storing a C pointer in a Python class instance

2009-09-30 Thread lallous
Hello After using the PyCObject, I cannot pickle the class anymore. Any simple solution to this problem? (or resorting to __reduce__ is the only solution?) Thanks, Elias "Falcolas" wrote in message news:9d3790aa-f7d9-4bb5-a81f-5428b2d60...@v25g2000yqk.googlegroups.com... On Sep 29, 2:27 am

Re: Storing a C pointer in a Python class instance

2009-09-30 Thread lallous
Thanks everyone. Finally, I used Falcolas suggestion and took into consideration sturlamolden's comments. Regards, Elias "lallous" wrote in message news:h9sgcn$iv...@aioe.org... Hello From my C extension module I want to store a C pointer in a given PyObject. The only way I figure how to

Re: Storing a C pointer in a Python class instance

2009-09-29 Thread sturlamolden
On 29 Sep, 19:11, Carl Banks wrote: > CObjects can be passed a C function as a deallocator; this should work > as reliably as a custom class deallocator. > > Carl Banks Except that __del__ prevents cyclic GC. -- http://mail.python.org/mailman/listinfo/python-list

Re: Storing a C pointer in a Python class instance

2009-09-29 Thread Carl Banks
On Sep 29, 9:42 am, sturlamolden wrote: > You can use PyCObject, or write your own extension type that wraps the > pointer (very easy to to with Cython or Pyrex). The advantage of using > an extension type is you have a guarantee from Python on the > deallocator method being called (cdef __dealloc

Re: Storing a C pointer in a Python class instance

2009-09-29 Thread sturlamolden
On 29 Sep, 10:27, "lallous" wrote: > Hello > > From my C extension module I want to store a C pointer in a given PyObject. > > The only way I figure how to do it is to use Py_BuildValues and store the > poiner casted to Py_ssize_t, Formally, you should cast the pointer to Py_intptr_t, as it has t

Re: Storing a C pointer in a Python class instance

2009-09-29 Thread Falcolas
On Sep 29, 2:27 am, "lallous" wrote: > Hello > > From my C extension module I want to store a C pointer in a given PyObject. > > The only way I figure how to do it is to use Py_BuildValues and store the > poiner casted to Py_ssize_t, thus: > > Py_BuildValues("n", (Py_ssize_t)my_ptr) > > Can it be

Storing a C pointer in a Python class instance

2009-09-29 Thread lallous
Hello From my C extension module I want to store a C pointer in a given PyObject. The only way I figure how to do it is to use Py_BuildValues and store the poiner casted to Py_ssize_t, thus: Py_BuildValues("n", (Py_ssize_t)my_ptr) Can it be done differently? Regards, Elias -- http://ma