|
From: David B. <dav...@us...> - 2004-12-05 02:19:15
|
Update of /cvsroot/frontierkernel/Frontier/Common/source In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv14548/source Modified Files: Tag: sidewinder-branch about.c langpython.c Log Message: can call odb objects from frontier, tweaked version number in about.c Index: about.c =================================================================== RCS file: /cvsroot/frontierkernel/Frontier/Common/source/about.c,v retrieving revision 1.4.4.1 retrieving revision 1.4.4.2 diff -C2 -d -r1.4.4.1 -r1.4.4.2 *** about.c 28 Nov 2004 06:51:47 -0000 1.4.4.1 --- about.c 5 Dec 2004 02:19:05 -0000 1.4.4.2 *************** *** 797,800 **** --- 797,804 ---- filegetprogramversion (bs); + + #ifdef FRONTIER_PYTHON + pushstring ("\x07" "-Python", bs); + #endif #ifdef fltrialsize Index: langpython.c =================================================================== RCS file: /cvsroot/frontierkernel/Frontier/Common/source/langpython.c,v retrieving revision 1.2.4.26 retrieving revision 1.2.4.27 diff -C2 -d -r1.2.4.26 -r1.2.4.27 *** langpython.c 2 Dec 2004 07:59:33 -0000 1.2.4.26 --- langpython.c 5 Dec 2004 02:19:06 -0000 1.2.4.27 *************** *** 41,45 **** //#include "op.h" //#include "opinternal.h" ! //#include "oplist.h" //#include "opverbs.h" #include "kernelverbs.h" --- 41,45 ---- //#include "op.h" //#include "opinternal.h" ! #include "oplist.h" //#include "opverbs.h" #include "kernelverbs.h" *************** *** 97,100 **** --- 97,101 ---- #include <time.h> + extern boolean langpushlistval (hdllistrecord hlist, ptrstring pkey, tyvaluerecord *val); #if defined(WIN95VERSION) || (defined(MACVERSION) && TARGET_RT_MAC_MACHO) *************** *** 239,242 **** --- 240,245 ---- PyGILState_STATE (*ptr_PyGILState_Ensure) (void); void (*ptr_PyGILState_Release) (PyGILState_STATE); + + void (*ptr__PyObject_Dump) (PyObject *); } py; *************** *** 354,357 **** --- 357,362 ---- #define PyGILState_Release (*py.ptr_PyGILState_Release) + #define _PyObject_Dump (*py.ptr__PyObject_Dump) + static boolean importsymbol (typythonlib hm, char *symbol, void **ptraddress) { *************** *** 503,506 **** --- 508,513 ---- fl = fl && IMPORTSYMBOL (hm, PyGILState_Release); + fl = fl && IMPORTSYMBOL (hm, _PyObject_Dump); + if (fl) { *************** *** 562,569 **** /* forward declarations */ ! static PyObject *newTableObject(hdlhashtable hdl); static PyObject *newOutlineObject(void); static PyObject *newWPTextObject(void); ! static PyObject *newScriptObject(void); static PyObject *newInternalValueObject(tyvaluetype vt); static PyObject *newExternalValueObject(tyexternalid ei); --- 569,576 ---- /* forward declarations */ ! static PyObject *newTableObject(hdlhashtable parent, bigstring loc, hdlhashtable hdl); static PyObject *newOutlineObject(void); static PyObject *newWPTextObject(void); ! static PyObject *newScriptObject(hdlhashtable parent, bigstring loc, tyvaluerecord *tvr); static PyObject *newInternalValueObject(tyvaluetype vt); static PyObject *newExternalValueObject(tyexternalid ei); *************** *** 695,699 **** } ! return false; } --- 702,706 ---- } ! return true; } *************** *** 800,804 **** static boolean ! convertfrontiervalue(tyvaluerecord *tvr, PyObject **pptr) { tyexternalid extType = ctexternalprocessors; --- 807,811 ---- static boolean ! convertfrontiervalue(hdlhashtable tbl, bigstring loc, tyvaluerecord *tvr, PyObject **pptr) { tyexternalid extType = ctexternalprocessors; *************** *** 909,913 **** return false; ! *pptr = newTableObject(table); break; --- 916,920 ---- return false; ! *pptr = newTableObject(tbl, loc, table); break; *************** *** 930,934 **** case idscriptprocessor: { ! *pptr = newScriptObject(); break; --- 937,941 ---- case idscriptprocessor: { ! *pptr = newScriptObject(tbl, loc, tvr); break; *************** *** 1012,1016 **** copyptocstring(loc, cname); ! if (!convertfrontiervalue(&val, &result)) { PyErr_SetString(PyExc_SystemError, "Cannot convert value"); return NULL; --- 1019,1023 ---- copyptocstring(loc, cname); ! if (!convertfrontiervalue(adr, loc, &val, &result)) { PyErr_SetString(PyExc_SystemError, "Cannot convert value"); return NULL; *************** *** 1067,1071 **** } ! if (!convertfrontiervalue(&v, &result)) { PyErr_SetString(PyExc_SystemError, "Couldn't execute because of an error converting the UserTalk return value."); releasepythonlock(); --- 1074,1078 ---- } ! if (!convertfrontiervalue(nil, zerostring, &v, &result)) { PyErr_SetString(PyExc_SystemError, "Couldn't execute because of an error converting the UserTalk return value."); releasepythonlock(); *************** *** 1150,1153 **** --- 1157,1162 ---- PyObject_HEAD hdlhashtable table; + hdlhashtable parent; + bigstring name; } frontier_TableObject; *************** *** 1180,1184 **** } ! if (!convertfrontiervalue(&val, &result)) { char msg[300]; sprintf(msg, "Cannot convert table entry named %s.", name); --- 1189,1193 ---- } ! if (!convertfrontiervalue(self->table, loc, &val, &result)) { char msg[300]; sprintf(msg, "Cannot convert table entry named %s.", name); *************** *** 1251,1255 **** } ! if (!convertfrontiervalue(&((**node).val), &result)) { PyErr_SetString(PyExc_ValueError, "Cannot convert value"); releasepythonlock(); --- 1260,1264 ---- } ! if (!convertfrontiervalue(self->table, (**node).hashkey, &((**node).val), &result)) { PyErr_SetString(PyExc_ValueError, "Cannot convert value"); releasepythonlock(); *************** *** 1388,1392 **** } ! nt = newTableObject(newTable); releasepythonlock(); --- 1397,1401 ---- } ! nt = newTableObject(newTable, loc, newTable); releasepythonlock(); *************** *** 1497,1502 **** --- 1506,1574 ---- typedef struct { PyObject_HEAD + tyvaluerecord value; + hdlhashtable parent; + bigstring name; } frontier_ScriptObject; + static PyObject * + Script_call(frontier_ScriptObject *self, PyObject *args, PyObject *kw) { + tyvaluerecord params, retval; + int len, i; + PyObject *returned; + bigstring funcname; + + //printf("__call__\n"); + + getpythonlock(); + + // get python args + //_PyObject_Dump(args); + //_PyObject_Dump(kw); + + // convert python args to vparams + // get a new frontier list + setnilvalue(¶ms); + if (!coercevalue(¶ms, listvaluetype)) + goto exitnone; + + // for each python parameter, convert and push a new value + len = PyTuple_GET_SIZE(args); + for (i = 0; i < len; i++) { + PyObject *obj = PyTuple_GET_ITEM(args, i); + tyvaluerecord arg; + if (!pythontofrontier(obj, &arg)) + goto exitnone; + if (!langpushlistval(params.data.listvalue, nil, &arg)) + goto exitnone; + } + + // call the script + releasepythonlock(); + + if (!langexternalgetquotedpath(self->parent, self->name, funcname)) { + getpythonlock(); + goto exitnone; + } + + if (!langrunscript(funcname, ¶ms, nil, &retval)) { + getpythonlock(); + goto exitnone; + } + + // convert result to python + if (!convertfrontiervalue(nil, zerostring, &retval, &returned)) + goto exitnone; + + releasepythonlock(); + + //return result + return returned; + + exitnone: + releasepythonlock(); + Py_XINCREF(Py_None); + return Py_None; + } + static PyTypeObject frontier_ScriptType = { PyObject_HEAD_INIT(NULL) *************** *** 1515,1519 **** 0, /*tp_as_mapping*/ 0, /*tp_hash */ ! 0, /*tp_call*/ 0, /*tp_str*/ 0, /*tp_getattro*/ --- 1587,1591 ---- 0, /*tp_as_mapping*/ 0, /*tp_hash */ ! (ternaryfunc)Script_call, /*tp_call*/ 0, /*tp_str*/ 0, /*tp_getattro*/ *************** *** 1571,1575 **** static PyObject * ! newTableObject(hdlhashtable hdl) { PyObject *class; frontier_TableObject *obj; --- 1643,1647 ---- static PyObject * ! newTableObject(hdlhashtable parent, bigstring loc, hdlhashtable hdl) { PyObject *class; frontier_TableObject *obj; *************** *** 1578,1581 **** --- 1650,1655 ---- obj = PyObject_New(frontier_TableObject, (PyTypeObject *)class); obj->table = hdl; + obj->parent = parent; + copystring(loc, obj->name); return (PyObject *)obj; *************** *** 1605,1609 **** static PyObject * ! newScriptObject() { PyObject *class; frontier_ScriptObject *obj; --- 1679,1683 ---- static PyObject * ! newScriptObject(hdlhashtable parent, bigstring loc, tyvaluerecord *tvr) { PyObject *class; frontier_ScriptObject *obj; *************** *** 1611,1614 **** --- 1685,1691 ---- class = PyObject_GetAttrString(frontierModule, "Script"); obj = PyObject_New(frontier_ScriptObject, (PyTypeObject *)class); + obj->value = *tvr; + obj->parent = parent; + copystring(loc, obj->name); return (PyObject *)obj; *************** *** 1817,1825 **** (**thisNode).link = nil; if ((**thisNode).nodetype == constop) { ! convertfrontiervalue(&((**thisNode).nodeval), &arg); } else { tyvaluerecord tvr; evaluatetree(thisNode, &tvr); ! convertfrontiervalue(&tvr, &arg); } PyList_Append(argList, arg); --- 1894,1902 ---- (**thisNode).link = nil; if ((**thisNode).nodetype == constop) { ! convertfrontiervalue(nil, zerostring, &((**thisNode).nodeval), &arg); } else { tyvaluerecord tvr; evaluatetree(thisNode, &tvr); ! convertfrontiervalue(nil, zerostring, &tvr, &arg); } PyList_Append(argList, arg); |