<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html><head><meta content="text/html;charset=UTF-8" http-equiv="Content-Type"></head><body >I checked for Null also. But No change in the result. Still getting the system error.<br>But when i m calling only c.c(5) function and not calling c.path("hi python c api") function, i m getting proper output without any system error.<br>Any clue? <br> <br> Subject: Re: Getting System error with PyModule_AddIntConstant funtion<br> From: Philip Semanchuk <<a mailid="philip%40semanchuk.com" href="mailto:philip@semanchuk.com" target="_blank">philip@semanchuk.com</a>><br> Date: Tue, 18 May 2010 11:50:46 -0400<br> To: "python-list (General)" <<a mailid="python-list%40python.org" href="mailto:python-list@python.org" target="_blank">python-list@python.org</a>><br> <br> ------------------------- Contents -------------------------<br> <br>  <br> On May 18, 2010, at 11:41 AM, MathanK wrote: <br>  <br> > Following is a Python C api which runs properly without   <br> > PyModule_AddIntConstant function. <br> > <br> > <br> > But when PyModule_AddIntConstant() function is used, getting the   <br> > following error when i call <br> > c. path("test call"); <br> > " SystemError: NULL result without error in PyObject_Call " <br>  <br> Hi Mathan, <br> You're not checking the return code from PyModule_Create(). Is it   <br> returning NULL? <br>  <br> Also, there's a list specific to Python's C API. You might get a   <br> better response to your question there: <br> <a href="http://mail.python.org/mailman/listinfo/capi-sig" target="_blank">http://mail.python.org/mailman/listinfo/capi-sig</a> <br>  <br>  <br> bye <br> Philip <br>  <br>  <br> > <br> > <br> > Python C api- c.c <br> > <br> > <br> > int test(int a){ <br> >     return (2*a+a); <br> > } <br> > <br> > <br> > PyObject* dict = NULL; <br> > <br> > <br> > static PyObject* path(PyObject* self, PyObject* args) { <br> >     char *cpath; <br> >     PyUnicodeObject *path; <br> >     PyUnicodeObject *test; <br> > <br> > <br> >     if (!PyArg_ParseTuple(args, "s", &amp;path)) <br> >        return NULL; <br> >     cpath = (char *)path; <br> >     test = (PyUnicodeObject*)(cpath); <br> >     PyObject *testDict = PyDict_New(); <br> >     int testVal = PyDict_SetItem(testDict, (PyObject   <br> > *)PyUnicode_FromString(cpath), (PyObject   <br> > *)PyUnicode_FromString(cpath)); <br> > <br> >     return Py_BuildValue("s", test); <br> > } <br> > static PyObject* c(PyObject* self, PyObject* args) { <br> > <br> >     int a; <br> >     int result; <br> >    if(!PyArg_ParseTuple(args, "i", &amp;a)) <br> >         return NULL; <br> >     result = test(a); <br> >     return Py_BuildValue("i", result); <br> > <br> > } <br> > <br> > <br> > static PyMethodDef cmethods[] = { <br> >     {"c", c, METH_VARARGS, "watch"}, <br> >     {"path", path, METH_VARARGS, "test"}, <br> >     {NULL, NULL, 0, NULL}, <br> > }; <br> > <br> > <br> > static struct PyModuleDef c_Module = { <br> >     PyModuleDef_HEAD_INIT, <br> >     "c", <br> >     ( <br> >   "Interface." <br> >     ), <br> >     -1, <br> >     cmethods <br> > }; <br> > <br> > <br> > PyMODINIT_FUNC PyInit_c(void) { <br> > <br> >     PyObject* obj = PyModule_Create(&amp;c_Module); <br> >     long lon1 = 0; <br> >     PyModule_AddIntConstant(obj, "test", lon1); <br> > <br> > } <br> > <br> > <br> > int main(int argc, wchar_t *argv[]) <br> > { <br> >     PyImport_AppendInittab("c", PyInit_c); <br> >     Py_SetProgramName(argv[0]); <br> >     Py_Initialize(); <br> >     PyImport_ImportModule("c"); <br> >     return 0; <br> > } <br> <font style="color: rgb(255, 0, 0); font-family: Comic Sans MS; background-color: rgb(255, 255, 255);" size="1"><span><span><span></span></span></span></font><span><span><span><span></span></span></span></span></body></html>