ExtensionClass: calling basicnew from C code
I'm still working with ExtensionClass to build a Versant module that supports persistence nicely, and just discovered the __basicnew__ method that returns an uninitialized instance of a class. Is there a good way to get the same effect as this method from the C level? Other than the following code: basicnew = PyObject_GetAttrString( classObj, "__basicnew__" ); if (basicnew == NULL) { Py_DECREF( classObj ); return NULL; } Erg = (VLinkObject*)PyEval_CallObjectWithKeywords(basicnew,NULL,NULL); This code seems to work fine; having to do a getattr seems inelegant, that's all. -- A.M. Kuchling http://starship.python.net/crew/amk/ I was never so amazed in my life as when the Sniffer drew his concealed weapon from its case and struck me to the ground, stone dead. -- Robertson Davies, first line of _Murther and Walking Spirits_
On Mon, 24 Apr 2000, Andrew M. Kuchling wrote:
I'm still working with ExtensionClass to build a Versant module that supports persistence nicely, and just discovered the __basicnew__ method that returns an uninitialized instance of a class. Is there a good way to get the same effect as this method from the C level? Other than the following code:
basicnew = PyObject_GetAttrString( classObj, "__basicnew__" ); if (basicnew == NULL) { Py_DECREF( classObj ); return NULL; }
Erg = (VLinkObject*)PyEval_CallObjectWithKeywords(basicnew,NULL,NULL);
This code seems to work fine; having to do a getattr seems inelegant, that's all.
Well you could use PyObject_CallMethod: Erg = (VLinkObject *)PyObject_CallMethod(classObj, "__basicnew__", ""); That does pretty much the same thing as your code, but is a bit shorter. James. -- Email: james@daa.com.au WWW: http://www.daa.com.au/~james/
participants (2)
-
Andrew M. Kuchling -
James Henstridge