Need help porting a C++ / Python Embedded app to multiple platforms

2008-02-05 Thread jpw
I am writing a Python / C++ embed app and it need to work on 3
platforms

I have the PYTHONPATH variable set correctly and have gone back and
downloaded compiled and installed the latest Python 2.5.1  on Solaris
and Linux. adding in the --enable-shared when running the ./
configure ... file

Mac - good to go there was no need do anything except update to 2.5
and add the PYTHONPATH

Solaris 10 -
Linux - Errors occur in the same point at runtime as soon as I try to
do load a module
The load module code is as follows:

PyObject* name = PyString_FromString(moduleName.c_str());
PyObject* mModule = PyImport_Import(name);
Py_DECREF(name);

if (mModule == 0)
{
std::ostringstream oss;
oss << "Failed to load module <" << moduleName << ">";
throw PythonException(oss.str());
}


both errors indicate a problem with libc.so

LINUX error stacktrace:

terminate called after throwing an instance of

'PythonWrapper::PythonException'
  what():  N13PythonWrapper15PythonExceptionE

Program received signal SIGABRT, Aborted.
[Switching to Thread 1161832800 (LWP 16508)]
0x0033f332e21d in raise () from /lib64/tls/libc.so.6
(gdb) where
#0  0x0033f332e21d in raise () from /lib64/tls/libc.so.6
#1  0x0033f332fa1e in abort () from /lib64/tls/libc.so.6
#2  0x002a96360a20 in __gnu_cxx::__verbose_terminate_handler ()
at ../../../../gcc-4.0.4/libstdc++-v3/libsupc++/vterminate.cc:97
#3  0x002a9635ea66 in __cxxabiv1::__terminate (handler=0x405f)
at ../../../../gcc-4.0.4/libstdc++-v3/libsupc++/eh_terminate.cc:43
#4  0x002a9635ea93 in std::terminate ()
at ../../../../gcc-4.0.4/libstdc++-v3/libsupc++/eh_terminate.cc:53
#5  0x002a9635eb7a in __cxa_throw (obj=,
tinfo=, dest=)
at ../../../../gcc-4.0.4/libstdc++-v3/libsupc++/eh_throw.cc:77
#6  0x005bb73d in PythonWrapper::Python::loadModule
(this=0x94f080,
[EMAIL PROTECTED]) at PythonWrapper.C:425


SOLARIS call stack:

Program received signal SIGABRT, Aborted.
[Switching to LWP 12]
0xfe7412a4 in _lwp_kill () from /usr/lib/libc.so.1
(gdb) where
#0  0xfe7412a4 in _lwp_kill () from /usr/lib/libc.so.1
#1  0xfe6dfe20 in raise () from /usr/lib/libc.so.1
#2  0xfe6c0040 in abort () from /usr/lib/libc.so.1
#3  0xfe92e64c in __gnu_cxx::__verbose_terminate_handler ()
at ../../../../gcc-4.0.4/libstdc++-v3/libsupc++/vterminate.cc:97
#4  0xfe92bfd8 in __cxxabiv1::__terminate (
handler=0xfe92e438 <__gnu_cxx::__verbose_terminate_handler()>)
at ../../../../gcc-4.0.4/libstdc++-v3/libsupc++/eh_terminate.cc:43
#5  0xfe92c028 in std::terminate ()
at ../../../../gcc-4.0.4/libstdc++-v3/libsupc++/eh_terminate.cc:53
#6  0xfe92c18c in __cxa_throw (obj=,
tinfo=0x3a3568,
dest=0x272e6c <~PythonException>)
at ../../../../gcc-4.0.4/libstdc++-v3/libsupc++/eh_throw.cc:77
#7  0x0027422c in PythonWrapper::Python::loadModule (this=0x46bc48,
[EMAIL PROTECTED]) at PythonWrapper.C:425

Any help would be greatly appreciated, jpw
-- 
http://mail.python.org/mailman/listinfo/python-list


Python / C++ embed halfway working - question about constructors

2008-03-26 Thread jpw
I am running  my C++ / Python App on a MacBook Pro with 2.5 installed

I have had some success in that I can load a module, get the class,
get the reference, but when the python class calls another python
class I don't ever seem to get the object back from the constructor.

I am doing the following in the C++ file:

Py_Initialize()
PyObject* module = PyImport_Import(moduleName);
PyObject* class = PyObject_GetAttrString(module, className);

Py_DECREF(module);
Py_DECREF(class);

// Create the TSAFE object constructor arguments:
// a file, and an int
PyObject* tsafeOutputFile = PyFile_FromString("TsafeOutput", "a");
PyObject* resolveValue = PyInt_FromLong(0);

PyObject* classArgumentTuple = PyTuple_New(2);
PyTuple_SetItem(classArgumentTuple, 0, tsafeOutputFile);
PyTuple_SetItem(classArgumentTuple, 1, resolveValue);

classReference = PyEval_CallObject(class, classArgumentTuple);
Py_MY_INCREF(classReference);
Py_MY_DECREF(class);

PyObject* pythonMethod = PyObject_GetAttrString(classReference,
"registerFlight");

registerReturn = PyEval_CallObject(pythonMethod, argumentTuple);
Py_MY_DECREF(pythonMethod);
Py_MY_DECREF(argumentTuple);


Essentially the code above should:

 call class constructor
 call registerFlight()
calls registerFlight_()
 calls _flightPointer() -> where I never get by the
section of
code where the
Flight.py Constructor
get called

Each flight should be added to my class object to build up a
dictionary
of flights.

The python class methods getting called are detailed below and I never
get by the
call to _flightPointer().  I have opened a file and write to it at
each step of
code and I never get all the way through the _flightPointer() method

Is there something I am missing here I cannot print the data out of
the
__init__ method in the Flight.py file?

I did not include all of the code here because I am hoping the issue
is I
have got something wrong and it's not the python code but me.

Ant help will be greatly appreciated.

def registerFlight(self, ID, ACtype="?", IFR=1, RVSM=0, ATCcat="?",
filedAlt=0, filedSpeed=0):
"register flight (unitless args for outside client)"

filedAlt *= FL # FL = Flight Level = 100 ft
filedSpeed *= kn # kn = knots

self.registerFlight_(ID, ACtype, IFR, RVSM, ATCcat,
filedAlt,filedSpeed)

def registerFlight_(self, ID, ACtype="?", IFR=1, RVSM=0, ATCcat="?",
filedAlt=0, filedSpeed=0):
"register flight (accepts arguments with units)"

flight = self._flightPointer(ID)

flight.registerFlight(ACtype, IFR, RVSM, ATCcat, filedAlt,
filedSpeed)

 def _flightPointer(self, ID, track=0, Flight=Flight):
"manage tracked and untracked flight lists"

fltPointerFile = open('TSAFE_flightPointerOut', 'a')
fltPointerFile.write("In the _flightPointer function\n")

flights = self.flights
unflights = self.untrackedFlights

if ID in flights:
fltPointerFile.write("in first IF\n")
return flights[ID]

if track: # new data record is a track update - start tracking
if ID in unflights: # move flight to tracked status
flights[ID] = unflights[ID]
del unflights[ID]
else: flights[ID] = Flight(ID) # new Flight object
return flights[ID]

## THIS IS THE SECTION OF CODE NOT RETURNING A REFERENCE TO
THE Flight object
if ID not in unflights:
fltPointerFile.write(ID)
fltPointerFile.write("  In if ID not in unflights\n\n")

unflights[ID] = Flight(ID)

fltPointerFile.write("BACK FROM CALLING Flight(ID)\n")

unflightsValue = ("unflights[ID]", unflights[ID])
unflightsString = str(unflightsValue)
fltPointerFile.write("Return value is ")
fltPointerFile.write(unflightsString)
fltPointerFile.write('\n')

return unflights[ID]
-- 
http://mail.python.org/mailman/listinfo/python-list