Commit 9b115852 authored by Jeremy Hylton's avatar Jeremy Hylton

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.
parent 436ff1ef
......@@ -21,7 +21,7 @@ static char ExtensionClass_module_documentation[] =
" - They provide access to unbound methods,\n"
" - They can be called to create instances.\n"
"\n"
"$Id: ExtensionClass.c,v 1.53 2002/06/10 22:48:46 jeremy Exp $\n"
"$Id: ExtensionClass.c,v 1.54 2002/06/18 22:40:15 jeremy Exp $\n"
;
#include <stdio.h>
......@@ -820,6 +820,34 @@ PMethod_call(PMethod *self, PyObject *args, PyObject *kw)
"s", self->type->tp_name);
}
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)
{
......@@ -924,7 +952,7 @@ static PyTypeObject PMethodType = {
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*/
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment