version 1.17 | | version 1.18 |
---|
| | |
/* You should have received a copy of the GNU General Public License */ | | /* You should have received a copy of the GNU General Public License */ |
/* along with this program; if not, write to the Free Software */ | | /* along with this program; if not, write to the Free Software */ |
/* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ | | /* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ |
/* */ /*****************************************************************************/ | | /* */ |
| | /*****************************************************************************/ |
| | |
/* First let's include the header file needed */ | | /* First let's include the header file needed */ |
| | |
| | |
return NULL; | | return NULL; |
} | | } |
| | |
| | void freeContext(CFPContext* context) |
| | { |
| | Py_XDECREF(context->who); |
| | Py_XDECREF(context->activator); |
| | Py_XDECREF(context->third); |
| | free(context); |
| | } |
| | |
static int do_script(CFPContext* context) | | static int do_script(CFPContext* context) |
{ | | { |
FILE* scriptfile; | | FILE* scriptfile; |
| | PyObject* built; |
PyObject* dict; | | PyObject* dict; |
| | #if 0 |
| | PyObject* list; |
| | PyObject* ret; |
| | int item;
|
| | #endif |
| | |
scriptfile = fopen(context->script,"r"); | | scriptfile = fopen(context->script,"r"); |
if (scriptfile == NULL) | | if (scriptfile == NULL) |
| | |
} | | } |
pushContext(context); | | pushContext(context); |
dict = PyDict_New(); | | dict = PyDict_New(); |
PyDict_SetItemString(dict, "__builtins__", PyEval_GetBuiltins()); | | built = PyEval_GetBuiltins(); |
PyRun_File(scriptfile, context->script, Py_file_input, dict, dict); | | PyDict_SetItemString(dict, "__builtins__", built); |
| | Py_XDECREF(built); |
| | ret = PyRun_File(scriptfile, context->script, Py_file_input, dict, dict); |
if (PyErr_Occurred()) | | if (PyErr_Occurred()) |
{ | | { |
PyErr_Print(); | | PyErr_Print(); |
} | | } |
| | Py_XDECREF(ret);
|
| | #if 0 |
| | printf( "cfpython - %d items in heap\n", PyDict_Size(dict)); |
| | list = PyDict_Values(dict); |
| | for (item = PyList_Size(list) - 1; item >= 0; item--) |
| | { |
| | dict = PyList_GET_ITEM(list,item); |
| | ret = PyObject_Str(dict); |
| | printf(" ref %s = %d\n",PyString_AsString(ret),dict->ob_refcnt); |
| | Py_XDECREF(ret); |
| | } |
| | Py_DECREF(list);
|
| | #endif |
Py_DECREF(dict); | | Py_DECREF(dict); |
fclose(scriptfile); | | fclose(scriptfile); |
return 1; | | return 1; |
| | |
snprintf(context->options, sizeof(context->options), "%s", params); | | snprintf(context->options, sizeof(context->options), "%s", params); |
context->returnvalue = 1; /* Default is "command successful" */ | | context->returnvalue = 1; /* Default is "command successful" */ |
| | |
Py_XINCREF(context->who); | | |
| | |
if (!do_script(context)) | | if (!do_script(context)) |
{ | | { |
free(context); | | freeContext(context); |
return rv; | | return rv; |
} | | } |
| | |
context = popContext(); | | context = popContext(); |
rv = context->returnvalue; | | rv = context->returnvalue; |
Py_XDECREF(context->who); | | freeContext(context); |
Py_XDECREF(context->activator); | | |
Py_XDECREF(context->third); | | |
free(context); | | |
printf("Execution complete"); | | printf("Execution complete"); |
return rv; | | return rv; |
} | | } |
| | |
| | |
if (!do_script(context)) | | if (!do_script(context)) |
{ | | { |
free(context); | | freeContext(context); |
return &rv; | | return &rv; |
} | | } |
| | |
context = popContext(); | | context = popContext(); |
rv = context->returnvalue; | | rv = context->returnvalue; |
Py_XDECREF(context->who); | | freeContext(context); |
Py_XDECREF(context->activator); | | |
Py_XDECREF(context->third); | | |
free(context); | | |
| | |
return &rv; | | return &rv; |
} | | } |
| | |
| | |
if (!do_script(context)) | | if (!do_script(context)) |
{ | | { |
free(context); | | freeContext(context); |
return &rv; | | return &rv; |
} | | } |
| | |
context = popContext(); | | context = popContext(); |
rv = context->returnvalue; | | rv = context->returnvalue; |
Py_XDECREF(context->who); | | freeContext(context); |
Py_XDECREF(context->activator); | | |
Py_XDECREF(context->third); | | |
free(context); | | |
return &rv; | | return &rv; |
} | | } |
| | |