Problem with Python Extensions

Chris Bardon cmbardon at engmail.uwaterloo.ca
Thu Mar 21 02:21:31 EST 2002


If anyone could help me with this problem it would be greatly
appreciated:

I'm trying to write a simple Python extension for use in Truespace
4.3.  At this point, I'm just trying to assess what can be done with
it, so I'd like to be able to start with an example that just returns
a value.  The problem is, my extension crashes truespace whenever I
try to import it.  I've created the dll using MS Visual C++ 6 and
Python 1.5-I've also included the source for the dll below (like I
said-starting simple).  When I try to import this into truspace's
python interface (import CommExt), the script causes an invalid page
exception in MFC42.DLL.  I'm linking this against python15.lib, as
obtained from python.org.

If anyone has had a similar problem, or can see from my source what my
problem might be, your help would be greatly appreciated.

Thanks,

Chris Bardon


//CommExt.cpp
//Another stab at making a truespace extension

#include "Python.h"

PyObject* comm(PyObject *self, PyObject *args);

static PyMethodDef commMethods[] =
{
  {"comm", comm, 1},
  {NULL,      NULL}        /* Sentinel */

};

static PyObject *CommExtError;

extern "C"__declspec(dllexport) void initCommExt()
{
	Py_InitModule("CommExt", commMethods);  //this is the line that
crashes TS!
}


PyObject* comm(PyObject *self, PyObject *args)
{
	int result=42;
	return Py_BuildValue("i", result);
}



More information about the Python-list mailing list