Jeremy Moles writes:

in the world I got the idea from! According to the docs, METH_VARARGS is
(PyObject*, PyObject*)?

Right.

                        My prototype shouldn't even compile... but it

Why wouldn't it compile?

2. No where in the docs does it show how to "correctly" create an
instance of your custom PyTypeObject in C (rather than in the
interpreter). I'm using:

That's what tp_alloc is for.  Then you call tp_init to initialize it.

But, your tp_new handler should already invoke tp_alloc, so it's cleaner to call tp_new, followed by tp_init.

3. I'm not able to return the "self" argument (useful, for instance,
when you want to chain a group of method calls) without screwing things
up really, really bad. For example:

PyObject* somefunc(cstruct* self, PyObject* args, PyObject* kargs) {
        self->pointerToData->doSomeStuff();
        
        return (PyObject*)(self);
}

...returns "something"; it has the methods you would expect, but trying
to use the object when it gets back to the interpreter is pretty much
undefined behavior. :) It's seen as a "<refcnt...>" instance in the
interpreter, even though a dir() shows it still has the methods you
would expect.

You need to increment the reference count of the object, in this case.

Attachment: pgpU4yWTepvmr.pgp
Description: PGP signature

-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to