From gagsl-py2 at yahoo.com.ar Fri Jan 8 17:45:02 2010 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Fri, 8 Jan 2010 08:45:02 -0800 (PST) Subject: [capi-sig] Create instance given its type Message-ID: <445773.22325.qm@web32803.mail.mud.yahoo.com> Hello I want to create an instance given its type object. I expected that calling the type would be enough, something like this: obj = (MyFooObject *) PyObject_CallFunctionObjArgs(&MyFooType, other, arguments, NULL) but it doesn't work (nor even compiles, I think). So this is what I'm doing now: obj = (MyFooObject *) PyObject_CallMethod((PyObject *)&PyType_Type, "__call__", "OOO", &MyFooType, other, arguments); where MyFooType is a PyTypeObject struct. Ok, it works, but I'm pretty sure there is a more direct way - but how? Thanks, -- Gabriel Genellina Yahoo! Cocina Encontra las mejores recetas con Yahoo! Cocina. http://ar.mujer.yahoo.com/cocina/ From python_capi at behnel.de Fri Jan 8 19:03:12 2010 From: python_capi at behnel.de (Stefan Behnel) Date: Fri, 08 Jan 2010 19:03:12 +0100 Subject: [capi-sig] Create instance given its type In-Reply-To: <445773.22325.qm@web32803.mail.mud.yahoo.com> References: <445773.22325.qm@web32803.mail.mud.yahoo.com> Message-ID: <4B477360.3030908@behnel.de> Gabriel Genellina, 08.01.2010 17:45: > I want to create an instance given its type object. I expected that > calling the type would be enough, something like this: > > obj = (MyFooObject *) PyObject_CallFunctionObjArgs(&MyFooType, other, arguments, NULL) > > but it doesn't work (nor even compiles, I think). You think? Didn't you try it? You might have to cast the type pointer to PyObject* to make it work. Stefan From lanyjie at yahoo.com Tue Jan 26 12:17:23 2010 From: lanyjie at yahoo.com (Yingjie Lan) Date: Tue, 26 Jan 2010 03:17:23 -0800 (PST) Subject: [capi-sig] announcement: expy release 0.5 Message-ID: <290176.43047.qm@web54204.mail.re2.yahoo.com> Hi all, This is to announce expy release 0.5. expy is an express way to extend Python. For more information and tutorials on expy, see: http://expy.sf.net/ Cheers, Yingjie From philip at semanchuk.com Sun Jan 31 00:19:31 2010 From: philip at semanchuk.com (Philip Semanchuk) Date: Sat, 30 Jan 2010 18:19:31 -0500 Subject: [capi-sig] Python 3.x PyObject_HEAD versus PyObject_VAR_HEAD Message-ID: <7E5ED525-E6CF-4CAA-ADD1-ED5FBDAD6551@semanchuk.com> Hi all, I'm trying to port my posix_ipc extension to Python 3, and I'm confused by the documentation for PyObject_HEAD and PyObject_VAR_HEAD. My understanding is that a PyObject-derived type should begin its PyTypeObject struct with PyObject_HEAD and a PyVarObject-derived type with PyObject_VAR_HEAD. the documentation says of PyVarObject, "This type does not often appear in the Python/C API." http://docs.python.org/3.1/c-api/structures.html#PyVarObject The doc also says that PyObject_VAR_HEAD, "is used when declaring new types which represent objects with a length that varies from instance to instance." http://docs.python.org/3.1/c-api/structures.html#PyObject_VAR_HEAD I assumed, then, that PyObject_VAR_HEAD would also appear infrequently, but that's not the case at all. In fact, I can't find PyObject_HEAD used at all in the Python 3.1.1 source code, whereas PyObject_VAR_HEAD is used hundreds of times, including for objects that don't have a length (like the float type, for instance). Is the documentation wrong, or am I misreading it? Suggestions appreciated. THanks Philip