[Pyrex] Question about object creation

Martin Sjögren msjogren at gmail.com
Tue Aug 17 16:54:11 CEST 2004


On Mon, 16 Aug 2004 13:26:17 +1200, Greg Ewing
<greg at cosc.canterbury.ac.nz> wrote:
> Martin <msjogren at gmail.com>:
> 
> > Yes, from what you're saying it seems like I won't be able to do what
> > I want, but this has little (probably nothing) to do with pyrex, and
> > everything to do with how the new-style types work.
> 
> A trick you might consider is wrapping the X509_NAME in a PyCObject,
> passing that to the extension type's constructor, and unwrapping it
> inside the extension type's __new__ method. If you check carefully
> enough, that would prevent Python code from being able to successfully
> call the constructor, since it won't be able to manufacture the right
> kind of PyCObject.

Hmm, using PyCObject is an interesting thought. The thing is that I
*want* to let python code instantiate the type in the normal way, as a
copy constructor (or even without arguments for creating a new
X509_NAME) , but I also need to be able to internally create an
X509Name (which is the python type) object given an existing X509_NAME
pointer, and wrapping the X509_NAME in a PyCObject before
instantiating the type sounds a lot saner than instantiating an
X509Name that creates a new X509_NAME pointer and then immediately
free it and replace it.

Thanks for the suggestion, even if this perhaps wasn't exactly how you
intended it. :-)


Cheers,
Martin




More information about the Pyrex mailing list