Author: juhliarik
Date: Mon Jan 21 11:21:31 2008
New Revision: 43767
URL: http://svn.opensuse.org/viewcvs/yast?rev=43767&view=rev
Log:
added patch for bug#355064 SCR.Write doesn't work
Modified:
trunk/python-bindings/src/YCP.cc
trunk/python-bindings/src/YPython.cc
Modified: trunk/python-bindings/src/YCP.cc
URL: http://svn.opensuse.org/viewcvs/yast/trunk/python-bindings/src/YCP.cc?rev=43767&r1=43766&r2=43767&view=diff
==============================================================================
--- trunk/python-bindings/src/YCP.cc (original)
+++ trunk/python-bindings/src/YCP.cc Mon Jan 21 11:21:31 2008
@@ -572,7 +572,11 @@
for (int i=1; i< number_args; i++) {
pPythonValue = PyTuple_GetItem(args, i);
if (pPythonValue) {
- ycpArg = ypython->PythonTypeToYCPType(pPythonValue);
+
+ if (pPythonValue != Py_None)
+ ycpArg = ypython->PythonTypeToYCPType(pPythonValue);
+ else
+ ycpArg = YCPVoid();
if (ycpArg.isNull ()) {
// an error has already been reported, now refine it.
@@ -586,17 +590,19 @@
// Such YConsts without a specific type produce invalid
// bytecode. (Which is OK here)
// The actual parameter's YCode becomes owned by the function call?
-
YConst *param_c = new YConst (YCode::ycConstant, ycpArg);
// for attaching the parameter, must get the real type so that it matches
constTypePtr act_param_tp = Type::vt2type (ycpArg->valuetype());
+
+
// Attach the parameter
// Returns NULL if OK, Type::Error if excessive argument
// Other errors (bad code, bad type) shouldn't happen
constTypePtr err_tp = bi_call->attachParameter (param_c, act_param_tp);
+
if (err_tp != NULL) {
if (err_tp->isError ()) {
// where we were called from.
@@ -666,6 +672,8 @@
YPython *ypython = YPython::yPython ();
+
+
if (number_args >= 2) {
//obtain name of namespace (first argument)
pPythonValue = PyTuple_GetItem(args, 0);
@@ -691,7 +699,7 @@
if (pPythonValue) {
if (PyString_Check(pPythonValue)) {
func_name = strcpy(func_name, PyString_AsString(pPythonValue));
-
+ //y2milestone("Call_YCPFunction: NS: %s FUN: %s",ns_name, func_name);
} else {
y2error ("Wrong type of name for function. String is necessary.");
//printf("Wrong type of name for function. String is necessary..\n");
@@ -708,6 +716,7 @@
//printf("function: %s\n", func_name);
// create namespace
Y2Namespace *ns = getNs (ns_name, func_name);
+ //y2milestone("jj");
if (ns == NULL) {
y2error ("Creating namespace fault.");
//printf("Creating namespace fault..\n");
@@ -732,7 +741,7 @@
y2error ("No such function %s::%s", ns_name, func_name);
//printf("No such symbol %s::%s\n", ns_name, func_name);
return PyExc_RuntimeError;
- }
+ }
if (fun_type->parameterCount() > (number_args-2)) {
y2error ("Too much arguments");
return PyExc_SyntaxError;
@@ -772,7 +781,6 @@
//printf("Problem with finishing arguments for adding arguments of function %s\n", func_name);
return PyExc_RuntimeError;
}
-
ycpRetValue = func_call->evaluateCall ();
delete func_call;
if (ycpRetValue.isNull ()) {
@@ -784,6 +792,7 @@
delete []func_name;
pReturnValue = ypython->YCPTypeToPythonType(ycpRetValue);
+
Py_INCREF(pReturnValue);
return pReturnValue;
Modified: trunk/python-bindings/src/YPython.cc
URL: http://svn.opensuse.org/viewcvs/yast/trunk/python-bindings/src/YPython.cc?rev=43767&r1=43766&r2=43767&view=diff
==============================================================================
--- trunk/python-bindings/src/YPython.cc (original)
+++ trunk/python-bindings/src/YPython.cc Mon Jan 21 11:21:31 2008
@@ -188,28 +188,40 @@
{
PyObject* pMainDict; // dictionary of module
PyObject* pFunc; // function from dictionary
- PyObject* pArgs; // tuple object of argument for function
+ PyObject* pArgs = NULL; // tuple object of argument for function
PyObject* pReturn; // return value from python
YCPValue result = YCPNull ();
//obtain correct dictionary for module
pMainDict = PyDict_GetItemString(YPython::yPython()->pMainDicts(),module.c_str());
//obtain function from dictionary
+
+ if (PyDict_Contains(pMainDict,PyString_FromString(function.c_str())) ==1)
+ cout <<"jj nasiel..." << endl;
pFunc = PyDict_GetItemString(pMainDict, function.c_str());
- pArgs = PyTuple_New(argList->size()-1);
+
+ if (argList->size() !=0)
+ pArgs = PyTuple_New(argList->size()-1);
//Parsing argumments
PyObject *pArg;
- y2milestone ("name of function %s and number of arguments %d", function.c_str(), argList->size()-1);
+ //y2milestone ("name of function %s and number of arguments %d", function.c_str(), argList->size()-1);
for ( int i=1; i < argList->size(); i++ ) {
pArg = YCPTypeToPythonType(argList->value(i));
PyTuple_SetItem(pArgs,i-1, pArg);
}
//calling function from python
- pReturn = PyObject_CallObject(pFunc, pArgs);
+
+ if (PyCallable_Check(pFunc))
+ cout <<"OKI" <