Text archives Help
- From: bigler@sci.utah.edu
- To: manta@sci.utah.edu
- Subject: [MANTA] r967 - trunk/SwigInterface
- Date: Fri, 3 Mar 2006 01:04:38 -0700 (MST)
Author: bigler
Date: Fri Mar 3 01:04:37 2006
New Revision: 967
Modified:
trunk/SwigInterface/python.cc
Log:
Fix crash calling functions with arguments. The PyTuple_SetItem
function was using i instead if i-first_arg.
Made i only scoped in the commandline parser. Use first_arg
externally.
Modified: trunk/SwigInterface/python.cc
==============================================================================
--- trunk/SwigInterface/python.cc (original)
+++ trunk/SwigInterface/python.cc Fri Mar 3 01:04:37 2006
@@ -96,9 +96,9 @@
string file_name;
string function_name = "make_scene";
- int i;
+ int first_arg = -1;
- for (i=0;i<args.size();++i) {
+ for (int i=0;i<args.size();++i) {
if (args[i] == "-file") {
if (!getStringArg( i, args, file_name )) {
throw IllegalArgument("-file <filename>", i, args);
@@ -111,6 +111,7 @@
}
else {
// Beginning of function arguments
+ first_arg = i;
break;
}
}
@@ -136,9 +137,11 @@
/* pFun: Borrowed reference */
if (pFunc && PyCallable_Check(pFunc)) {
- pArgs = PyTuple_New( args.size()-i);
- for (; i < args.size(); ++i) {
- pValue = PyString_FromString(args[i].c_str());
+ int num_args = args.size()-first_arg;
+ fprintf(stderr, "num args %d", num_args);
+ pArgs = PyTuple_New( num_args );
+ for (int argi = first_arg; argi < args.size(); ++argi) {
+ pValue = PyString_FromString(args[argi].c_str());
if (!pValue) {
Py_DECREF(pArgs);
Py_DECREF(pModule);
@@ -146,7 +149,7 @@
return 0;
}
/* pValue reference stolen here: */
- PyTuple_SetItem(pArgs, i, pValue);
+ PyTuple_SetItem(pArgs, argi-first_arg, pValue);
}
// Invoke the function.
@@ -155,7 +158,7 @@
if (pValue != NULL) {
std::cerr << "Function call successful" << std::endl;
- printf("Result of call: %ld\n", PyInt_AsLong(pValue));
+ // printf("Result of call: %s\n", PyString_AsString(pValue));
Py_DECREF(pValue);
}
else {
- [MANTA] r967 - trunk/SwigInterface, bigler, 03/03/2006
Archive powered by MHonArc 2.6.16.