Acees violation from extension if compiled with MinGW, but ok with Borland
Andrew Gregory
andrew.gregory at npl.co.uk
Mon Dec 16 10:36:29 EST 2002
More information about the Python-list mailing list
Mon Dec 16 10:36:29 EST 2002
- Previous message (by thread): [Q] pindent improvement
- Next message (by thread): Tkinter/win32ui compatibility
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
The function mysquare below generates a python exception if the
argument is zero. This works perfectly when compiled with Borland, but
generates an "access violation" (run time error 0xc0000005) if
compiled with MinGW.
Using MSVC Python 2.2.2 binaries.
_pysimple.h
static char Myerrorstring[80];
// Error class
class Myerror
{
// Constructor
public:
Myerror(char *s) { sprintf(Myerrorstring,"%s",s); };
};
// Function
int mysquare(int i)
{
if (i==0)
{ throw Myerror("Input zero"); };
return i*i;
};
Used SWIG -c++ -python pysimple.i to generate pysimple_wrap.cxx
where pysimple.i is
%module pysimple
%{
#include "pysimple.h"
%}
%exception {
try {
$action
}
catch (Myerror) {
PyErr_SetString(PyExc_SystemError,Myerrorstring);
return NULL;
}
}
%include pysimple.h
Compiled using distutils
python setup.py build --compiler=mingw32
where for MinGW setup.py is
from distutils.core import setup, Extension
setup (name = "_pysimple",
version = "1.0",
maintainer = "Andrew Gregory",
maintainer_email = "andrew.gregory at npl.co.uk",
description = "Sample Python C++ DLL",
ext_modules = [Extension('_pysimple',
library_dirs=['C:\\mingw\\lib'],
libraries=['supc++'], # if using iostreams etc.
use stdc++
sources=['pysimple_wrap.cxx'])])
- Previous message (by thread): [Q] pindent improvement
- Next message (by thread): Tkinter/win32ui compatibility
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
More information about the Python-list mailing list