[Zodb-checkins] CVS: Zope/lib/Components/ExtensionClass/src - ExtensionClass.c:1.54
Jeremy Hylton
jeremy@zope.com
Tue, 18 Jun 2002 18:40:16 -0400
Update of /cvs-repository/Zope/lib/Components/ExtensionClass/src
In directory cvs.zope.org:/tmp/cvs-serv10078
Modified Files:
ExtensionClass.c
Log Message:
experimental change to help debugging: given decent repr to PMethod objects
It's experimental because I just called snprintf() directly, even
though later version of Python go through elaborate rituals before
calling it.
=== Zope/lib/Components/ExtensionClass/src/ExtensionClass.c 1.53 => 1.54 ===
static PyObject *
+PMethod_repr(PMethod *self)
+{
+ char *func_name, buf[8192];
+ int n;
+
+ func_name = PyString_AS_STRING(((PyFunctionObject*)self->meth)->func_name);
+ if (self->self) {
+ PyObject *repr = PyObject_Repr(self->self);
+ if (!repr)
+ return NULL;
+ n = snprintf(buf, sizeof(buf),
+ "<bound method %s.%s of %s>",
+ self->type->tp_name, func_name,
+ PyString_AS_STRING(repr));
+ if (n == -1)
+ n = sizeof(buf) - 1;
+ }
+ else {
+ n = snprintf(buf, sizeof(buf),
+ "<unbound method %s.%s>",
+ self->type->tp_name, func_name);
+ if (n == -1)
+ n = sizeof(buf) - 1;
+ }
+ return PyString_FromStringAndSize(buf, n);
+}
+
+static PyObject *
PMethod_getattro(PMethod *self, PyObject *oname)
{
PyObject *r;
@@ -924,7 +952,7 @@
0, /*tp_getattr*/
(setattrfunc)0, /*tp_setattr*/
(cmpfunc)0, /*tp_compare*/
- (reprfunc)0, /*tp_repr*/
+ (reprfunc)PMethod_repr, /*tp_repr*/
0, /*tp_as_number*/
0, /*tp_as_sequence*/
0, /*tp_as_mapping*/