Defining Python class methods in C
Bryan
belred1 at yahoo.com
Sat Mar 22 20:32:13 EST 2003
i found one of my problems:
i was using METH_NOARGS for get_path. when i changed to METH_VARARGS
my callback got called. but the self variable in context_get_path is
NULL. so i can't get to the variables i stored in the context_object
from the __init__ call.
bryan
-----
static PyMethodDef context_methods[] = {
{"__init__", context_init, METH_VARARGS, "Create context"},
{"get_path", context_get_path, METH_VARARGS, "Get the path"},
{NULL, NULL, 0, NULL}
};
static PyObject* context_get_path(PyObject *self, PyObject *args)
{
context_object *context_obj = (context_object*)self;
wgagent_provider_context *ctx = NULL;
PyObject *py_str_path = NULL;
printf("context_get_path:");
if (self) {
printf("self is not NULL");
else
printf("self is NULL");
if (context_obj) {
printf("context_obj");
sscanf(context_obj->context, "%p", &ctx);
if (ctx) {
py_str_path = PyString_FromString("c:\\test");
}
}
if (py_str_path) {
return py_str_path;
}
else {
Py_INCREF(Py_None);
return Py_None;
}
}
More information about the Python-list
mailing list