[Python-Dev] Re: C new-style classes and GC (original) (raw)
Jim Fulton jim@zope.com
Fri, 16 May 2003 16:30:47 -0400
- Previous message: [Python-Dev] Re: C new-style classes and GC
- Next message: [Python-Dev] Re: C new-style classes and GC
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Jeremy Hylton wrote:
I'm willing to believe there is a new and better way, but I don't think I know what it is.
You can read the documentation for it here:
http://www.python.org/dev/doc/devel/ext/defining-new-types.html
:)
How do we change this code, written using the old PyObjectGCNew() to do things the new way?
Jeremy PyObject * PyDictNew(void) { register dictobject *mp; if (dummy == NULL) { /* Auto-initialize dummy */ dummy = PyStringFromString(""); if (dummy == NULL) return NULL; #ifdef SHOWCONVERSIONCOUNTS PyAtExit(showcounts); #endif } mp = PyObjectGCNew(dictobject, &PyDictType); if (mp == NULL) return NULL; EMPTYTOMINSIZE(mp); mp->malookup = lookdictstring; #ifdef SHOWCONVERSIONCOUNTS ++created; #endif PyObjectGCTRACK(mp); return (PyObject *)mp; }
see dict_new in the same file.
The new way to create instances if types is to call the types.
I don't know wht PyDict_New doesn't just call the dict type. Maybe doing things in-line like this is just an optimization.
Jim
-- Jim Fulton mailto:jim@zope.com Python Powered! CTO (703) 361-1714 http://www.python.org Zope Corporation http://www.zope.com http://www.zope.org
- Previous message: [Python-Dev] Re: C new-style classes and GC
- Next message: [Python-Dev] Re: C new-style classes and GC
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]