other ext. prob [was: Re: seg. fault with ext. module]

Gorny gorny at hobbiton.org
Sat Aug 25 12:51:42 EDT 2001


> You forgot to increment the reference count for None, which creates a
> problem at termination time.
>
> See http://www.python.org/doc/current/ext/refcounts.html
>
> hth,
> /steffen

Allright, I get that point now. But after a look on xxmodule.c contained
in the pythonsrc distribution I've noticed the following functions:

static void Xxo_dealloc(XxoObject *self)
{
 Py_XDECREF(self->x_attr);
 PyObject_Del(self);
}

static PyObject *
Xxo_getattr(XxoObject *self, char *name)
{
 if (self->x_attr != NULL) {
  PyObject *v = PyDict_GetItemString(self->x_attr, name);
  if (v != NULL) {
   Py_INCREF(v);
   return v;
  }
 }
 return Py_FindMethod(Xxo_methods, (PyObject *)self, name);
}

static int
Xxo_setattr(XxoObject *self, char *name, PyObject *v)
{
 if (self->x_attr == NULL) {
  self->x_attr = PyDict_New();
  if (self->x_attr == NULL)
   return -1;
 }
 if (v == NULL) {
  int rv = PyDict_DelItemString(self->x_attr, name);
  if (rv < 0)
   PyErr_SetString(PyExc_AttributeError,
           "delete non-existing Xxo attribute");
  return rv;
 }
 else
  return PyDict_SetItemString(self->x_attr, name, v);
}

these are not mentiond in the methods passed to Py_InitModule().
In what circumstances calls the python interpreter these functions?
Just when an getattr and a setattr() call are made to the Xxo-module?
eg.
>>> import Xxo
>>> getattr(Xxo, 'foobar')   <---- calling Xxo_getattr()???


Greets,
Gorny


--
"When I was a little kid, I had this dream where a snake would rule and
dominate
the entire world (actually, I guess that a penguin was also part of the
dream...
but never mind)" -- Python Develper's Handbook, Andre Lessa
http://gorny.cjb.net





More information about the Python-list mailing list