Creating a new object of your own type in a C extension.

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Heiko Wundram

    Creating a new object of your own type in a C extension.

    Hi all!

    Just a small question concerning type creation in a C object: If I create a
    class which is overridable, I'd like to have that class create objects of
    it's overridden type, e.g. I have a class X which is implemented in C, which
    is wrapped in Python by a class Y, now I initialize a Y class, and call a
    member of X on that class, and I'd like the member of X to return an object
    of class Y. What is a correct way of doing this? I've not found any nice
    implementation hints in the documentation.. .

    1) PyObject_New(Xs truct, self->ob_type (which should point to the type of Y))
    2) self->ob_type->tp_new(self->ob_type,NULL,N ULL)
    3) anything else?

    I don't see any of this being used in the Python object classes (e.g.
    overridden classes of int return int when e.g. __add__ is called, etc.).

    Thanks for any help!

    Heiko.

Working...