|
From: David B. <dav...@us...> - 2004-11-23 02:34:07
|
Update of /cvsroot/frontierkernel/Frontier/Common/source In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv32297 Modified Files: Tag: sidewinder-branch langpython.c Log Message: moved var declarations to the beginning of a block, rather than next to the code that uses them. I hate what VC++ makes me do. Why can't it at least keep up with the syntax? Index: langpython.c =================================================================== RCS file: /cvsroot/frontierkernel/Frontier/Common/source/langpython.c,v retrieving revision 1.2.4.4 retrieving revision 1.2.4.5 diff -C2 -d -r1.2.4.4 -r1.2.4.5 *** langpython.c 23 Nov 2004 01:54:39 -0000 1.2.4.4 --- langpython.c 23 Nov 2004 02:33:55 -0000 1.2.4.5 *************** *** 67,74 **** #include "langpython.h" ! #ifdef MACVERSION ! #include <Python/Python.h> ! #else ! #endif #include <time.h> --- 67,71 ---- #include "langpython.h" ! #if defined(MACVERSION) && defined(TARGET_RT_MAC_MACHO) #include <Python/Python.h> #else #include <Python.h> #endif #include <time.h> *************** *** 138,143 **** int len = PyList_Size(keys); int i; - hdlhashtable newTable; if (!langassignnewtablevalue(hdl, name, &newTable)) return false; --- 135,140 ---- int len = PyList_Size(keys); int i; hdlhashtable newTable; + if (!langassignnewtablevalue(hdl, name, &newTable)) return false; *************** *** 147,151 **** PyObject *v = PyDict_GetItem(obj, k); char *key = PyString_AsString(k); - bigstring tn; --- 144,147 ---- *************** *** 197,208 **** hdlhashtable newTable; - if (!langassignnewtablevalue(hdl, name, &newTable)) - return false; - tyvaluerecord realPart; tyvaluerecord imagPart; - double r, i; r = PyComplex_RealAsDouble(obj); i = PyComplex_ImagAsDouble(obj); --- 193,203 ---- hdlhashtable newTable; tyvaluerecord realPart; tyvaluerecord imagPart; double r, i; + if (!langassignnewtablevalue(hdl, name, &newTable)) + return false; + r = PyComplex_RealAsDouble(obj); i = PyComplex_ImagAsDouble(obj); *************** *** 271,274 **** --- 266,270 ---- int len = gethandlesize(tvr->data.stringvalue); char *val = malloc(len + 1); + strncpy(val, *(tvr->data.stringvalue), len); val[len] = 0; *************** *** 309,312 **** --- 305,309 ---- case booleanvaluetype: { int val = 0; + if (tvr->data.flvalue) val = -1; *************** *** 366,369 **** --- 363,367 ---- case idtableprocessor: { hdlhashtable table; + if (!langexternalvaltotable(*tvr, &table, HNoNode)) return false; *************** *** 437,440 **** --- 435,444 ---- fetchAux(char *as) { tyvaluerecord tvr; + bigstring loc; + hdlhashtable adr; + tyvaluerecord val; + hdlhashnode node; + char cname[sizeof(bigstring)]; + PyObject *result; if (!newheapvalue(as, strlen(as), stringvaluetype, &tvr)) { *************** *** 450,456 **** } - bigstring loc; - hdlhashtable adr; - if (!getaddressvalue(tvr, &adr, loc)) { char msg[300]; --- 454,457 ---- *************** *** 459,466 **** return NULL; } ! ! tyvaluerecord val; ! hdlhashnode node; ! if (!hashtablelookup(adr, loc, &val, &node)) { char msg[300]; --- 460,464 ---- return NULL; } ! if (!hashtablelookup(adr, loc, &val, &node)) { char msg[300]; *************** *** 470,477 **** } - char cname[stringsize(loc)]; copyptocstring(loc, cname); - PyObject *result; if (!convertfrontiervalue(&val, &result)) { PyErr_SetString(PyExc_SystemError, "Cannot convert value"); --- 468,473 ---- *************** *** 497,500 **** --- 493,499 ---- evaluateString(PyObject *self, PyObject *args) { char *s; + Handle htext; + tyvaluerecord v; + PyObject *result; if (!PyArg_ParseTuple(args, "s:evaluate", &s)) { *************** *** 503,507 **** } - Handle htext; if (!newfilledhandle(s, strlen(s), &htext)) { PyErr_SetString(PyExc_SystemError, "Couldn't execute because I couldn't allocate space for the string."); --- 502,505 ---- *************** *** 509,513 **** } - tyvaluerecord v; if (!langrun(htext, &v)) { PyErr_SetString(PyExc_SyntaxError, "Couldn't execute because of a syntax error in the UserTalk code."); --- 507,510 ---- *************** *** 515,519 **** } - PyObject *result; if (!convertfrontiervalue(&v, &result)) { PyErr_SetString(PyExc_SystemError, "Couldn't execute because of an error converting the UserTalk return value."); --- 512,515 ---- *************** *** 611,619 **** Table_get(frontier_TableObject *self, char *name) { bigstring loc; - - copyctopstring(name, loc); - tyvaluerecord val; hdlhashnode node; if (!hashtablelookup(self->table, loc, &val, &node)) { --- 607,615 ---- Table_get(frontier_TableObject *self, char *name) { bigstring loc; tyvaluerecord val; hdlhashnode node; + PyObject *result; + + copyctopstring(name, loc); if (!hashtablelookup(self->table, loc, &val, &node)) { *************** *** 624,629 **** } - PyObject *result; - if (!convertfrontiervalue(&val, &result)) { char msg[300]; --- 620,623 ---- *************** *** 672,675 **** --- 666,671 ---- Table_getIndex(frontier_TableObject *self, int index) { hdlhashnode node; + PyObject *result; + if (!hashgetnthnode(self->table, index, &node)) { PyErr_SetString(PyExc_IndexError, "Index out of bounds"); *************** *** 677,681 **** } - PyObject *result; if (!convertfrontiervalue(&((**node).val), &result)) { PyErr_SetString(PyExc_ValueError, "Cannot convert value"); --- 673,676 ---- *************** *** 702,708 **** static PyObject * Table_getItem(frontier_TableObject *self, PyObject *key) { if (PyInt_Check(key)) return Table_getIndex(self, PyInt_AsLong(key)); ! char *keyName = PyString_AsString(PyObject_Str(key)); return Table_get(self, keyName); } --- 697,704 ---- static PyObject * Table_getItem(frontier_TableObject *self, PyObject *key) { + char *keyName; if (PyInt_Check(key)) return Table_getIndex(self, PyInt_AsLong(key)); ! keyName = PyString_AsString(PyObject_Str(key)); return Table_get(self, keyName); } *************** *** 710,716 **** static int Table_setItem(frontier_TableObject *self, PyObject *key, PyObject *val) { if (PyInt_Check(key)) return Table_setIndex(self, PyInt_AsLong(key), val); ! char *keyName = PyString_AsString(PyObject_Str(key)); return Table_setattr(self, keyName, val); } --- 706,713 ---- static int Table_setItem(frontier_TableObject *self, PyObject *key, PyObject *val) { + char *keyName; if (PyInt_Check(key)) return Table_setIndex(self, PyInt_AsLong(key), val); ! keyName = PyString_AsString(PyObject_Str(key)); return Table_setattr(self, keyName, val); } *************** *** 763,766 **** --- 760,766 ---- Table_newTable(frontier_TableObject *self, PyObject *args) { char *name; + bigstring loc; + hdlhashtable newTable; + if (!PyArg_ParseTuple(args, "s:newTable", &name)) { PyErr_SetString(PyExc_TypeError, "Table.newTable requires a string argument"); *************** *** 768,776 **** } - bigstring loc; - copyctopstring(name, loc); - hdlhashtable newTable; if (!langassignnewtablevalue(self->table, loc, &newTable)) { PyErr_SetString(PyExc_SystemError, "Cannot create table"); --- 768,773 ---- *************** *** 1055,1063 **** boolean runstringverb(hdltreenode hp1, tyvaluerecord *v) { ! // if Python hasn't been started, start it and create our globals. // startInterpreter(); // set up default frontier return value // --- 1052,1072 ---- boolean runstringverb(hdltreenode hp1, tyvaluerecord *v) { ! Handle pythonCode; ! tyvaluerecord adrOutput; ! tyvaluerecord adrError; ! hdlhashtable htableOutput; ! hdlhashtable htableError; ! bigstring locOutput; ! bigstring locError; ! PyObject *locals; ! PyObject *result; ! PyObject *err; ! // if Python hasn't been started, start it and create our globals. // startInterpreter(); + locals = globals; // hack alert -- confirm why I need to do this + // set up default frontier return value // *************** *** 1065,1072 **** return false; - Handle pythonCode; - tyvaluerecord adrOutput; - tyvaluerecord adrError; - // first param: handle to python code string // --- 1074,1077 ---- *************** *** 1083,1092 **** if (!getaddressparam(hp1, 3, &adrError)) return false; ! ! hdlhashtable htableOutput; ! hdlhashtable htableError; ! bigstring locOutput; ! bigstring locError; ! // derefernce pointer to output variable // --- 1088,1092 ---- if (!getaddressparam(hp1, 3, &adrError)) return false; ! // derefernce pointer to output variable // *************** *** 1103,1110 **** if (!enlargehandle(pythonCode, gethandlesize(pythonCode) + 1, "\0")) return false; ! ! PyObject *locals = globals; //PyDict_New(); ! PyObject *result; ! // set up the interpreter to capture the output // --- 1103,1107 ---- if (!enlargehandle(pythonCode, gethandlesize(pythonCode) + 1, "\0")) return false; ! // set up the interpreter to capture the output // *************** *** 1116,1189 **** result = PyRun_String(*pythonCode, Py_file_input, globals, locals); if (result) Py_DECREF(result); ! PyObject *err = PyErr_Occurred(); if (err) { PyErr_Print(); // get the error output // ! PyObject *ferr = PyDict_GetItemString(locals, "_f_err"); ! PyObject *outputString = PyObject_CallMethod(ferr, "getvalue", NULL); result = PyObject_CallMethod(ferr, "close", NULL); if (result) Py_DECREF(result); ! char *output = PyString_AsString(outputString); ! ! tyvaluerecord errorValue; ! ! if (!newheapvalue(output, strlen(output), stringvaluetype, &errorValue)) { ! Py_DECREF(outputString); ! return false; ! } ! exemptfromtmpstack(&errorValue); - if (!hashtableassign(htableError, locError, errorValue)) { - Py_DECREF(outputString); - return false; - } - - if (!setbooleanvalue(false, v)) { Py_DECREF(outputString); - return false; } - - Py_DECREF(outputString); } ! // get the output ! // ! PyObject *foutput = PyDict_GetItemString(locals, "_f_output"); ! PyObject *outputString = PyObject_CallMethod(foutput, "getvalue", NULL); ! result = PyObject_CallMethod(foutput, "close", NULL); ! if (result) Py_DECREF(result); ! ! // convert the output from a python string into a cstring ! // ! char *output = PyString_AsString(outputString); ! ! // copy the output into the frontier variable that was passed in ! // ! tyvaluerecord outputValue; ! ! boolean retcode = true; ! ! if (!newheapvalue(output, strlen(output), stringvaluetype, &outputValue)) ! retcode = false; ! ! exemptfromtmpstack(&outputValue); ! ! if (retcode && !hashtableassign(htableOutput, locOutput, outputValue)) ! retcode = false; ! // erase all sign of us ! // ! result = PyRun_String("sys.stdout = _f_old_output; sys.stderr = _f_old_err", Py_file_input, globals, locals); ! if (result) Py_DECREF(result); ! Py_DECREF(outputString); ! //Py_DECREF(locals); ! return retcode; } --- 1113,1194 ---- result = PyRun_String(*pythonCode, Py_file_input, globals, locals); if (result) Py_DECREF(result); ! err = PyErr_Occurred(); if (err) { + PyObject *ferr; + PyObject *outputString; + PyErr_Print(); // get the error output // ! ferr = PyDict_GetItemString(locals, "_f_err"); ! outputString = PyObject_CallMethod(ferr, "getvalue", NULL); result = PyObject_CallMethod(ferr, "close", NULL); if (result) Py_DECREF(result); ! bundle { ! tyvaluerecord errorValue; ! char *output = PyString_AsString(outputString); ! ! if (!newheapvalue(output, strlen(output), stringvaluetype, &errorValue)) { ! Py_DECREF(outputString); ! return false; ! } ! ! exemptfromtmpstack(&errorValue); ! if (!hashtableassign(htableError, locError, errorValue)) { ! Py_DECREF(outputString); ! return false; ! } ! ! if (!setbooleanvalue(false, v)) { ! Py_DECREF(outputString); ! return false; ! } Py_DECREF(outputString); } } ! bundle { ! PyObject *foutput; ! PyObject *outputString; ! char *output; ! tyvaluerecord outputValue; ! boolean retcode = true; ! // get the output ! // ! foutput = PyDict_GetItemString(locals, "_f_output"); ! outputString = PyObject_CallMethod(foutput, "getvalue", NULL); ! result = PyObject_CallMethod(foutput, "close", NULL); ! if (result) Py_DECREF(result); ! // convert the output from a python string into a cstring ! // ! output = PyString_AsString(outputString); ! // copy the output into the frontier variable that was passed in ! // ! if (!newheapvalue(output, strlen(output), stringvaluetype, &outputValue)) ! retcode = false; ! ! exemptfromtmpstack(&outputValue); ! ! if (retcode && !hashtableassign(htableOutput, locOutput, outputValue)) ! retcode = false; ! ! // erase all sign of us ! // ! result = PyRun_String("sys.stdout = _f_old_output; sys.stderr = _f_old_err", Py_file_input, globals, locals); ! if (result) Py_DECREF(result); ! ! Py_DECREF(outputString); ! //Py_DECREF(locals); ! ! return retcode; ! } } |