Getting System error with PyModule_AddIntConstant funtion

MathanK switch2mathan at gmail.com
Tue May 18 11:41:29 EDT 2010


Following is a Python C api which runs properly without PyModule_AddIntConstant function. 


But when PyModule_AddIntConstant() function is used, getting the following error when i call 
c. path("test call");
" SystemError: NULL result without error in PyObject_Call "


Python C api- c.c


int test(int a){
     return (2*a+a);
 }
 

 PyObject* dict = NULL;
 

 static PyObject* path(PyObject* self, PyObject* args) {
     char *cpath;
     PyUnicodeObject *path;
     PyUnicodeObject *test; 
 

     if (!PyArg_ParseTuple(args, "s", &path))
        return NULL; 
     cpath = (char *)path; 
     test = (PyUnicodeObject*)(cpath); 
     PyObject *testDict = PyDict_New();
     int testVal = PyDict_SetItem(testDict, (PyObject *)PyUnicode_FromString(cpath), (PyObject *)PyUnicode_FromString(cpath));
  
     return Py_BuildValue("s", test);
 }
 static PyObject* c(PyObject* self, PyObject* args) {
     
     int a;
     int result;
    if(!PyArg_ParseTuple(args, "i", &a))
         return NULL;
     result = test(a);
     return Py_BuildValue("i", result);
  
 }
 

 static PyMethodDef cmethods[] = {
     {"c", c, METH_VARARGS, "watch"},
     {"path", path, METH_VARARGS, "test"},
     {NULL, NULL, 0, NULL},
 };
 

 static struct PyModuleDef c_Module = {
     PyModuleDef_HEAD_INIT,
     "c",
     (
   "Interface."
     ),
     -1,
     cmethods
 };
 

 PyMODINIT_FUNC PyInit_c(void) {
  
     PyObject* obj = PyModule_Create(&c_Module);
     long lon1 = 0;
     PyModule_AddIntConstant(obj, "test", lon1);
     
 }
 

 int main(int argc, wchar_t *argv[])
 {
     PyImport_AppendInittab("c", PyInit_c);
     Py_SetProgramName(argv[0]);
     Py_Initialize();
     PyImport_ImportModule("c");
     return 0;
 }
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20100518/9d62c82c/attachment.html>


More information about the Python-list mailing list