PyCheck for a classes defined in python and user data in PyObject_HEAD

Gabriel Genellina gagsl-py2 at yahoo.com.ar
Fri Nov 2 01:04:23 EDT 2007


En Thu, 01 Nov 2007 22:13:35 -0300, <sndive at gmail.com> escribió:

> On Nov 1, 4:14 pm, snd... at gmail.com wrote:
>> q#1:
>> in C I want to check if a given PyObject is a xml.dom.minidom.Node (or
>> a derivative).
>> how do i extract a PyTypeObject for such a class?
>
> nevermind, i found an instance object that will work for me
> as long as i figure out where is the documentation
> beyond this:
> http://docs.python.org/api/instanceObjects.html
> on the data attrib access and extracting PyClassObject from it.

classic_class = PyObject_GetAttrString( your_classic_instance, "__class__")

>> issue #2
>> I'm in a situation when i don't really need to extend python with any
>> classes of my own but
>> i do have extra luggage for the python data structures such as tuples,
>> lists, dictionaries, etc
>> on the c++ side. I see no place in PyObject_HEAD where i can stick a
>> void* to my extra data.

Assuming you can recompile all the extensions you use, you could insert  
your void* into _PyObject_HEAD_EXTRA and _PyObject_EXTRA_INIT

>> If i enter a feature request into bugzilla for python do you think it
>> will be well received?
>> #ifdefed of course like the prev/next extras.

I think a code patch + test suite + doc patches will be much more well  
received...

-- 
Gabriel Genellina




More information about the Python-list mailing list