Python Aborts when I quit

tilwe ashish.tilwe at db.com
Fri Oct 19 11:56:14 EDT 2001


"Steve Holden" <sholden at holdenweb.com> wrote in message news:<U7Dz7.36688$cb.711917 at atlpnn01.usenetserver.com>...
> .....
> I too, am puzzled, but for a different reason. If you have indeed
> cut-and-pasted the stuff above from Python interpreter sessions and files, I
> am puzzled as to why you don't see error messages!
> 
> Firstly, shouldn't
> 
> >>> print testvar()
> 
> have been
> 
> >>> print c_plus_plus_module.testvar()
>.....
> 
> regards
>  Steve

Hi Steve,
	I have reduced the code to a manageable size. The actual code is
about 1500 lines. It was only after I had the above code was when I
started
getting errors. Here is the actual code.

First the C++ code (Again only error function is displayed)
-------------------------------------------------------------------------
static char errMsg[1024] ;
const int intmax = ~((unsigned)1 << (8 * (int)sizeof(int)) - 1) ;

static PyObject *
makeCall(PyObject * self, PyObject * args)
{
	PyObject * rRow = NULL ;
	int func ;
	char * funcval ;

	try {
		errMsg[0] = '\0' ;
		if(!PyArg_ParseTuple(args, "is", &func, &funcval))
			throw "Invalid arguments for makeCall()" ;
		// func is a index to the list of library functions.
		// call() will lookup up this number and return
		// an 2-dimensional array where each element could be of
		// three types (integer, float or string). If func is out of
		// range return an array with rows/cols = 0

		const ResultSet& result = call(func, funcval) ;
		int row = result.getNumberOfLines() ;
		int col = result.getNumberOfCols() ;
		int x ;
		if(row == 0 || col == 0)
			throw "Empty ResultSet returned" ;

		rRow = PyTuple_New(row) ;
		for(x = 0 ; x < row ; x++) {
			int y ;
			PyObject * rCol ;
			rCol = PyTuple_New(col) ;
			for(y = 0 ; y < col ; y++) {
				PyObject * item ;
				if(result[x][y].isNumber()) {
					double val = (double) result[x][y] ;
					if(val < intmax && val == (int) val)
						item = PyInt_FromLong((long) val) ;
					else
						item = PyFloat_FromDouble(val) ; ;
				} else
					item = PyString_FromString((const char *)result[x][y]) ;
				if(item)
					PyTuple_SetItem(rCol, y, item) ;
			}
			PyTuple_SetItem(rRow, x, rCol) ;
		}
	} catch(const char * err) {
		strcpy(errMsg, err) ;
		cerr << "Error: " << err << endl ;
		rRow = Py_None ;
	}
	return rRow ;
}
static PyObject *
getError(PyObject * self, PyObject * args)
{
	return PyString_FromString(errMsg) ;
}
-------------------------------------------------------------------------

Now for the Python Module

File: MyTools.py
-------------------------------------------------------------------------
import libPyTAPI
def LoadLibrary(libname):
	return libPyTAPI.makeCall(11, libname)

def Insert(token):
	return libPyTAPI.makeCall(12, token)

def Append(token)
	return libPyTAPI.makeCall(13, token)

def Delete(token):
	return libPyTAPI.makeCall(14, token)

def getError():
	return libPyTAPI.getError()

def Unique(token):
	return libPyTAPI.makeCall(15, token)

def Display():
	return libPyTAPI.makeCall(17, "all")

def RowInsert(token):
	return libPyTAPI.makeCall(21, token)

def ColInsert(token):
	return libPyTAPI.makeCall(22, token)

def ClearRow(rowno):
	return libPyTAPI.makeCall(16, rowno)

def Clear():
	return libPyTAPI.makeCall(16, "all")

.... And all the rest 30 more functions
-------------------------------------------------------------------------

Now I have Python script which imports "MyTools.py". This script
runs and executes as expected. The only problem comes when I execute
sys.exit(0) in the script. I believe that somewhere I have to
increment
or decrement the reference count of the result set, BUT I have no idea
where to start?

Any pointers??????????????

Tilwe



More information about the Python-list mailing list