[capi-sig] Create new object

Hrvoje Niksic hniksic at xemacs.org
Mon Jul 27 23:05:36 CEST 2009


Shaun Savage <savages at mozapps.org> writes:

> I am trying to create a new python object of type  Foo from a C program.
>
> typedef struct (
>     PyObject_HEAD
>     PyObject ....,
> ...
> } Foo;
>
> static PyTypeObject FooType = {
>     PyObject_HEAD_INIT(NULL)
>     0,
>     "foo.Foo",
>     sizeof(Foo),
> 0,
> ...
> }
>
> in the code i have
>
> self = (Foo*) PyObject_CallObject((PyObject*)&FooType, NULL);

You need to use PyObject_CallFunctionObjArgs, like this:

self = (Foo *)PyObject_CallFunctionObjArgs((PyObject*)&FooType, NULL);

PyObject_CallObject is when you already have an argument tuple at the
ready.


More information about the capi-sig mailing list