Re: PyObject_New

2005-10-07 Thread Jeremy Moles
I just noticed this response right as I sent my other message. For some reason my news reader didn't thread it, so it was all by itself... Please disregard the rant concerning creation of objects in C. :) /me hugs Martin /me ducks and hides! On Fri, 2005-10-07 at 09:57 +0200, "Martin v. Löwis" wr

Re: PyObject_New

2005-10-07 Thread Martin v. Löwis
Jeremy Moles wrote: > PyObject* obj = _PyObject_New(&PyType_MyType); > obj = PyObject_Init(obj, &PyType_MyType); > > ... > > return obj; The call to PyObject_Init is redundant: _PyObject_New is malloc+init. However, this shouldn't cause any crashes (except in the de

Re: PyObject_New

2005-10-06 Thread Gerhard Häring
Jeremy Moles wrote: > [...] What I'm trying > now is the following: > > PyObject* obj = _PyObject_New(&PyType_MyType); > obj = PyObject_Init(obj, &PyType_MyType); > > ... > > return obj; > > When "obj" gets back to the interpreter, Python sees it (or rather, it's >

PyObject_New

2005-10-06 Thread Jeremy Moles
Hey guys, sorry to ask another question of this nature, but I can't find the answer or a single example of it anywhere. I'm sure it's been asked before, but my google-fu isn't strong enough to find anything. I have the following: struct MyType { PyObject_HEAD

Re: PyObject_New not running tp_new for iterators?

2005-04-21 Thread Gregory Bond
I wrote: [snip] > What am I missing? The fundamental problem is that this: if (!(ro = PyObject_New(MyIter, &MyIterType))) return NULL; is really only a malloc() - it doesn't call the tp_new function at all. This is not really clear in the 2.3 version of the C API document

PyObject_New not running tp_new for iterators?

2005-04-20 Thread Gregory Bond
myiter e = myiter.MyIter() str(e) '' e.next() 0 e.next() 1 e.next() 2 e.next() 3 However, if I create the MyIter object from a C factory function: static PyObject * FromFile(PyObject *self, PyObject *args) { MyIter *ro; if (!PyArg_ParseTuple(args, "")) ret