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

sndive at gmail.com sndive at gmail.com
Thu Nov 15 22:27:42 EST 2007


On Nov 1, 11:04 pm, "Gabriel Genellina" <gagsl-... at yahoo.com.ar>
wrote:
> En Thu, 01 Nov 2007 22:13:35 -0300, <snd... 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

i added two void pointers to head_extra and 0,0, to the extra_init.
For some reason i get garbage in them from PyEval_EvalCode :-(
(that's after i blew the build dir and rebuilt 2.4.4 from scratch
so i don't think i have a bad build)



More information about the Python-list mailing list