[yast-commit] r41345 - in /trunk/python-bindings/src: YCPDeclarations.cc YPython.cc YPythonNamespace.cc
Author: dfiser Date: Wed Oct 10 18:30:11 2007 New Revision: 41345 URL: http://svn.opensuse.org/viewcvs/yast?rev=41345&view=rev Log: - YPythonNamespace now uses YCPDeclarations class to determine YCP types in function declarations in python module. - Added some necessary error checkings, before that it sometimes causes segmentation faults. Modified: trunk/python-bindings/src/YCPDeclarations.cc trunk/python-bindings/src/YPython.cc trunk/python-bindings/src/YPythonNamespace.cc Modified: trunk/python-bindings/src/YCPDeclarations.cc URL: http://svn.opensuse.org/viewcvs/yast/trunk/python-bindings/src/YCPDeclarations.cc?rev=41345&r1=41344&r2=41345&view=diff ============================================================================== --- trunk/python-bindings/src/YCPDeclarations.cc (original) +++ trunk/python-bindings/src/YCPDeclarations.cc Wed Oct 10 18:30:11 2007 @@ -111,6 +111,9 @@ PyObject *YCPDeclarations::_getItemFromFunctionMap(PyObject *key) { + if (_py_self == NULL) + return NULL; + PyObject *dict = PyModule_GetDict(_py_self); PyObject *func_map = PyDict_GetItemString(dict, "_function_map"); @@ -158,6 +161,9 @@ { DBG("YCPDeclarations - constructor"); _py_self = PyImport_ImportModule("YCPDeclarations"); + if (_py_self == NULL){ + DBG("YCPDeclarations::YCPDeclarations() - Failed to import YCPDeclarations module!"); + } } YCPDeclarations::~YCPDeclarations() Modified: trunk/python-bindings/src/YPython.cc URL: http://svn.opensuse.org/viewcvs/yast/trunk/python-bindings/src/YPython.cc?rev=41345&r1=41344&r2=41345&view=diff ============================================================================== --- trunk/python-bindings/src/YPython.cc (original) +++ trunk/python-bindings/src/YPython.cc Wed Oct 10 18:30:11 2007 @@ -140,6 +140,16 @@ //check if dictionary contain "dictionary" for module if ( PyDict_Contains(YPython::_pMainDicts, pModuleName) == 0) { pMain = PyImport_ImportModule(module_name.c_str()); + if (pMain == NULL){ + y2error("Can't import module %s", module_name.c_str()); + + if (PyErr_Occurred() != NULL){ + PyErr_Print(); + } + + return YCPError("The module was not imported"); + } + int ret = PyDict_SetItem(YPython::_pMainDicts, pModuleName, PyModule_GetDict(pMain)); if (ret != 0) return YCPError("The module was not imported"); Modified: trunk/python-bindings/src/YPythonNamespace.cc URL: http://svn.opensuse.org/viewcvs/yast/trunk/python-bindings/src/YPythonNamespace.cc?rev=41345&r1=41344&r2=41345&view=diff ============================================================================== --- trunk/python-bindings/src/YPythonNamespace.cc (original) +++ trunk/python-bindings/src/YPythonNamespace.cc Wed Oct 10 18:30:11 2007 @@ -18,6 +18,11 @@ #include <YPython.h> #include <stdio.h> +#include "YCPDeclarations.h" +#define DBG(str) \ + std::cerr << __FILE__ << ": " << __LINE__ << ": " << str << std::endl; \ + std::cerr.flush() + /** @@ -148,6 +153,12 @@ PyObject * fun_names; //list of keys from dictionary (YPython::yPython()->pMain()) PyObject * fun_code; //code of function + //Declarations (using YPCDelcarations python module) + YCPDeclarations *decl = YCPDeclarations::instance(); + FunctionTypePtr sym_tp; + std::vector<constTypePtr> list_of_types; + int tmp; + int num_fun_names = 0; //number of keys from dictionary int count = 0; // position. arbitrary numbering @@ -155,6 +166,10 @@ //obtain main dictionary of globals variables pMainDict = PyDict_GetItemString(YPython::yPython()->pMainDicts(),name.c_str()); + if (pMainDict == NULL){ + y2error("Can't load module %s", name.c_str()); + return; + } //keys from dictionary fun_names = PyDict_Keys(pMainDict); @@ -172,14 +187,26 @@ //check if symbol is callable if (PyFunction_Check(pFunc)) { - FunctionTypePtr sym_tp = new FunctionType (Type::Any); - fun_code = PyFunction_GetCode(pFunc); num = ((PyCodeObject *) fun_code)->co_argcount; - //y2milestone ("Number of parameters: %d", num); - //add types and number of arguments into SymbolEntry table - for (long j = 0; j < num; j++) { - sym_tp->concat(Type::Any); + + if (decl->exists((PyFunctionObject *)pFunc) + && decl->numParams((PyFunctionObject *)pFunc) == num){ + + sym_tp = new FunctionType(decl->returnType((PyFunctionObject *)pFunc)); + + list_of_types = decl->params((PyFunctionObject *)pFunc); + tmp = list_of_types.size(); + for (int i=0; i < tmp; i++){ + sym_tp->concat(list_of_types[i]); + } + }else{ + sym_tp = new FunctionType(Type::Any); + //y2milestone ("Number of parameters: %d", num); + //add types and number of arguments into SymbolEntry table + for (long j = 0; j < num; j++) { + sym_tp->concat(Type::Any); + } } //y2milestone ("Callable function %s", PyString_AsString(item)); // symbol entry for the function -- To unsubscribe, e-mail: yast-commit+unsubscribe@opensuse.org For additional commands, e-mail: yast-commit+help@opensuse.org
participants (1)
-
dfiser@svn.opensuse.org