[Zope-dev] ExtensionClass: calling basicnew from C code

James Henstridge james@daa.com.au
Tue, 25 Apr 2000 09:06:22 +0800 (WST)


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/