Merge branch 'master' into C
This commit is contained in:
commit
55741f9e31
62 changed files with 57301 additions and 21514 deletions
|
|
@ -4,6 +4,7 @@ class
|
|||
constants
|
||||
contract
|
||||
docstrings
|
||||
doxygen
|
||||
enum
|
||||
exception
|
||||
exceptproxy
|
||||
|
|
@ -14,7 +15,6 @@ functor
|
|||
import
|
||||
import_template
|
||||
import_packages
|
||||
java
|
||||
#libffi
|
||||
multimap
|
||||
operator
|
||||
|
|
|
|||
|
|
@ -86,7 +86,7 @@ Note: when creating a C++ extension, you must run SWIG with the <tt>-c++</tt> op
|
|||
|
||||
<h2>A sample Python script</h2>
|
||||
|
||||
Click <a href="example.py">here</a> to see a script that calls the C++ functions from Python.
|
||||
Click <a href="runme.py">here</a> to see a script that calls the C++ functions from Python.
|
||||
|
||||
<h2>Key points</h2>
|
||||
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ to see a SWIG interface with some constant declarations in it.
|
|||
|
||||
<h2>Accessing Constants from Python</h2>
|
||||
|
||||
Click <a href="example.py">here</a> to see a script that prints out the values
|
||||
Click <a href="runme.py">here</a> to see a script that prints out the values
|
||||
of the constants contained in the above file.
|
||||
|
||||
<h2>Key points</h2>
|
||||
|
|
|
|||
27
Examples/python/doxygen/Makefile
Normal file
27
Examples/python/doxygen/Makefile
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
TOP = ../..
|
||||
SWIGEXE = $(TOP)/../swig
|
||||
SWIG_LIB_DIR = $(TOP)/../$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib
|
||||
CXXSRCS = example.cxx
|
||||
TARGET = example
|
||||
INTERFACE = example.i
|
||||
LIBS = -lm
|
||||
SWIGOPT = -doxygen
|
||||
|
||||
check: build
|
||||
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' python_run
|
||||
|
||||
build:
|
||||
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' \
|
||||
SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \
|
||||
SWIGOPT='$(SWIGOPT)' \
|
||||
TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' python_cpp
|
||||
|
||||
static:
|
||||
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' \
|
||||
SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \
|
||||
SWIGOPT='$(SWIGOPT)' \
|
||||
TARGET='mypython' INTERFACE='$(INTERFACE)' python_cpp_static
|
||||
|
||||
clean:
|
||||
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' TARGET='$(TARGET)' python_clean
|
||||
rm -f example.html
|
||||
48
Examples/python/doxygen/example.cxx
Normal file
48
Examples/python/doxygen/example.cxx
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
/* File : example.cxx */
|
||||
|
||||
#include "example.h"
|
||||
#define M_PI 3.14159265358979323846
|
||||
|
||||
/* Move the shape to a new location */
|
||||
void Shape::move(double dx, double dy) {
|
||||
x += dx;
|
||||
y += dy;
|
||||
}
|
||||
|
||||
int Shape::nshapes = 0;
|
||||
|
||||
Circle::Circle(double r) : radius(r) {
|
||||
NumCircles++;
|
||||
}
|
||||
|
||||
double Circle::area() {
|
||||
return M_PI*radius*radius;
|
||||
}
|
||||
|
||||
double Circle::perimeter() {
|
||||
return 2*M_PI*radius;
|
||||
}
|
||||
|
||||
Square::Square(double w) : width(w) {
|
||||
NumSquares++;
|
||||
}
|
||||
|
||||
double Square::area() {
|
||||
return width*width;
|
||||
}
|
||||
|
||||
double Square::perimeter() {
|
||||
return 4*width;
|
||||
}
|
||||
|
||||
int NumSquares = 0;
|
||||
int NumCircles = 0;
|
||||
|
||||
Square MakeSquare(double r) {
|
||||
return Square(r);
|
||||
}
|
||||
|
||||
Circle MakeCircle(double w) {
|
||||
return Circle(w);
|
||||
}
|
||||
|
||||
152
Examples/python/doxygen/example.dsp
Normal file
152
Examples/python/doxygen/example.dsp
Normal file
|
|
@ -0,0 +1,152 @@
|
|||
# Microsoft Developer Studio Project File - Name="example" - Package Owner=<4>
|
||||
# Microsoft Developer Studio Generated Build File, Format Version 6.00
|
||||
# ** DO NOT EDIT **
|
||||
|
||||
# TARGTYPE "Win32 (x86) Dynamic-Link Library" 0x0102
|
||||
|
||||
CFG=example - Win32 Release
|
||||
!MESSAGE This is not a valid makefile. To build this project using NMAKE,
|
||||
!MESSAGE use the Export Makefile command and run
|
||||
!MESSAGE
|
||||
!MESSAGE NMAKE /f "example.mak".
|
||||
!MESSAGE
|
||||
!MESSAGE You can specify a configuration when running NMAKE
|
||||
!MESSAGE by defining the macro CFG on the command line. For example:
|
||||
!MESSAGE
|
||||
!MESSAGE NMAKE /f "example.mak" CFG="example - Win32 Release"
|
||||
!MESSAGE
|
||||
!MESSAGE Possible choices for configuration are:
|
||||
!MESSAGE
|
||||
!MESSAGE "example - Win32 Debug" (based on "Win32 (x86) Dynamic-Link Library")
|
||||
!MESSAGE "example - Win32 Release" (based on "Win32 (x86) Dynamic-Link Library")
|
||||
!MESSAGE
|
||||
|
||||
# Begin Project
|
||||
# PROP AllowPerConfigDependencies 0
|
||||
# PROP Scc_ProjName ""
|
||||
# PROP Scc_LocalPath ""
|
||||
CPP=cl.exe
|
||||
MTL=midl.exe
|
||||
RSC=rc.exe
|
||||
|
||||
!IF "$(CFG)" == "example - Win32 Debug"
|
||||
|
||||
# PROP BASE Use_MFC 0
|
||||
# PROP BASE Use_Debug_Libraries 1
|
||||
# PROP BASE Output_Dir "Debug"
|
||||
# PROP BASE Intermediate_Dir "Debug"
|
||||
# PROP BASE Target_Dir ""
|
||||
# PROP Use_MFC 0
|
||||
# PROP Use_Debug_Libraries 1
|
||||
# PROP Output_Dir "Debug"
|
||||
# PROP Intermediate_Dir "Debug"
|
||||
# PROP Ignore_Export_Lib 0
|
||||
# PROP Target_Dir ""
|
||||
# ADD BASE CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "EXAMPLE_EXPORTS" /YX /FD /GZ /c
|
||||
# ADD CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /I "$(PYTHON_INCLUDE)" /D "SWIG_PYTHON_INTERPRETER_NO_DEBUG" /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "EXAMPLE_EXPORTS" /YX /FD /GZ /c
|
||||
# ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /win32
|
||||
# ADD MTL /nologo /D "_DEBUG" /mktyplib203 /win32
|
||||
# ADD BASE RSC /l 0x809 /d "_DEBUG"
|
||||
# ADD RSC /l 0x809 /d "_DEBUG"
|
||||
BSC32=bscmake.exe
|
||||
# ADD BASE BSC32 /nologo
|
||||
# ADD BSC32 /nologo
|
||||
LINK32=link.exe
|
||||
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib /nologo /dll /debug /machine:I386 /pdbtype:sept
|
||||
# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib "$(PYTHON_LIB)" /nologo /dll /debug /machine:I386 /out:"_example.pyd" /pdbtype:sept
|
||||
|
||||
!ELSEIF "$(CFG)" == "example - Win32 Release"
|
||||
|
||||
# PROP BASE Use_MFC 0
|
||||
# PROP BASE Use_Debug_Libraries 0
|
||||
# PROP BASE Output_Dir "Release"
|
||||
# PROP BASE Intermediate_Dir "Release"
|
||||
# PROP BASE Target_Dir ""
|
||||
# PROP Use_MFC 0
|
||||
# PROP Use_Debug_Libraries 0
|
||||
# PROP Output_Dir "Release"
|
||||
# PROP Intermediate_Dir "Release"
|
||||
# PROP Ignore_Export_Lib 0
|
||||
# PROP Target_Dir ""
|
||||
# ADD BASE CPP /nologo /MT /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "EXAMPLE_EXPORTS" /YX /FD /c
|
||||
# ADD CPP /nologo /MT /W3 /GX /O2 /I "$(PYTHON_INCLUDE)" /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "EXAMPLE_EXPORTS" /YX /FD /c
|
||||
# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32
|
||||
# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32
|
||||
# ADD BASE RSC /l 0x809 /d "NDEBUG"
|
||||
# ADD RSC /l 0x809 /d "NDEBUG"
|
||||
BSC32=bscmake.exe
|
||||
# ADD BASE BSC32 /nologo
|
||||
# ADD BSC32 /nologo
|
||||
LINK32=link.exe
|
||||
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib /nologo /dll /machine:I386
|
||||
# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib "$(PYTHON_LIB)" /nologo /dll /machine:I386 /out:"_example.pyd"
|
||||
|
||||
!ENDIF
|
||||
|
||||
# Begin Target
|
||||
|
||||
# Name "example - Win32 Debug"
|
||||
# Name "example - Win32 Release"
|
||||
# Begin Group "Source Files"
|
||||
|
||||
# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\example.cxx
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\example_wrap.cxx
|
||||
# End Source File
|
||||
# End Group
|
||||
# Begin Group "Header Files"
|
||||
|
||||
# PROP Default_Filter "h;hpp;hxx;hm;inl"
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\example.h
|
||||
# End Source File
|
||||
# End Group
|
||||
# Begin Group "Resource Files"
|
||||
|
||||
# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"
|
||||
# End Group
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\example.i
|
||||
|
||||
!IF "$(CFG)" == "example - Win32 Debug"
|
||||
|
||||
# Begin Custom Build
|
||||
InputPath=.\example.i
|
||||
InputName=example
|
||||
|
||||
"$(InputName)_wrap.cxx" : $(SOURCE) "$(INTDIR)" "$(OUTDIR)"
|
||||
echo In order to function correctly, please ensure the following environment variables are correctly set:
|
||||
echo PYTHON_INCLUDE: %PYTHON_INCLUDE%
|
||||
echo PYTHON_LIB: %PYTHON_LIB%
|
||||
echo on
|
||||
..\..\..\swig.exe -c++ -python "$(InputPath)"
|
||||
|
||||
# End Custom Build
|
||||
|
||||
!ELSEIF "$(CFG)" == "example - Win32 Release"
|
||||
|
||||
# Begin Custom Build
|
||||
InputPath=.\example.i
|
||||
InputName=example
|
||||
|
||||
"$(InputName)_wrap.cxx" : $(SOURCE) "$(INTDIR)" "$(OUTDIR)"
|
||||
echo In order to function correctly, please ensure the following environment variables are correctly set:
|
||||
echo PYTHON_INCLUDE: %PYTHON_INCLUDE%
|
||||
echo PYTHON_LIB: %PYTHON_LIB%
|
||||
echo on
|
||||
..\..\..\swig.exe -c++ -python "$(InputPath)"
|
||||
|
||||
# End Custom Build
|
||||
|
||||
!ENDIF
|
||||
|
||||
# End Source File
|
||||
# End Target
|
||||
# End Project
|
||||
107
Examples/python/doxygen/example.h
Normal file
107
Examples/python/doxygen/example.h
Normal file
|
|
@ -0,0 +1,107 @@
|
|||
/*! \file example.h
|
||||
This file provides a simple set of Shape classes. */
|
||||
|
||||
/*! Base class for all shapes.
|
||||
\author Bob
|
||||
*/
|
||||
class Shape {
|
||||
public:
|
||||
/*! Default constructor for creating a Shape */
|
||||
Shape() {
|
||||
nshapes++;
|
||||
}
|
||||
/*! Destructor for destroying a Shape */
|
||||
virtual ~Shape() {
|
||||
nshapes--;
|
||||
}
|
||||
double x; /*!< x co-ordinate */
|
||||
double y; /*!< y co-ordinate */
|
||||
void move(double dx, double dy); /*!< Move a shape to a new co-ordinate
|
||||
\param dx x co-ordinate
|
||||
\param dy y co-ordinate */
|
||||
virtual double area() = 0; /*!< \return the area */
|
||||
virtual double perimeter() = 0; /*!< \return the perimeter */
|
||||
static int nshapes; /*!< Number of shapes currently in existence */
|
||||
};
|
||||
|
||||
/*! A class for representing a circle.
|
||||
\author Jack
|
||||
*/
|
||||
class Circle : public Shape {
|
||||
private:
|
||||
double radius;
|
||||
public:
|
||||
/*! Construct a circle
|
||||
* \param r radius of the circle */
|
||||
Circle(double r);
|
||||
/*! Calculate the area of the circle
|
||||
* \return calculated area */
|
||||
virtual double area();
|
||||
/*! Calculate the perimeter of the circle
|
||||
* \return calculated perimeter of the circle */
|
||||
virtual double perimeter();
|
||||
};
|
||||
|
||||
/// A class for representing a square.
|
||||
class Square : public Shape {
|
||||
private:
|
||||
double width;
|
||||
public:
|
||||
/** Construct a square
|
||||
* \param w width of the square */
|
||||
Square(double w);
|
||||
/** Calculate the area of the square
|
||||
* \return calculated area */
|
||||
virtual double area();
|
||||
/** Calculate the perimeter of the square
|
||||
* \return calculated perimeter of the square */
|
||||
virtual double perimeter();
|
||||
};
|
||||
|
||||
/// A class for representing a rectangle, templated on the type for the rectangle dimensions
|
||||
template<typename T>
|
||||
class Rectangle : public Shape {
|
||||
private:
|
||||
T height;
|
||||
T width;
|
||||
public:
|
||||
/** Construct a rectangle
|
||||
* \param h height of the rectangle
|
||||
* \param w width of the rectangle */
|
||||
Rectangle(T h, T w) : height(h), width(w) {}
|
||||
/** Calculate the area of the rectangle
|
||||
* \return calculated area */
|
||||
virtual double area() { return width*height; }
|
||||
/** Calculate the perimeter of the rectangle
|
||||
* \return calculated perimeter of the rectangle */
|
||||
virtual double perimeter() { return 2*height + 2*width; }
|
||||
};
|
||||
|
||||
|
||||
/*! Factory function for creating a square
|
||||
* \param r width of the square
|
||||
* \return a fully constructed square */
|
||||
Square MakeSquare(double r);
|
||||
|
||||
/*! Factory function for creating a circle
|
||||
* \param w radius of the circle
|
||||
* \return a fully constructed circle */
|
||||
Circle MakeCircle(double w);
|
||||
|
||||
/*! Factory function for creating a rectangle
|
||||
* \param h height of the rectangle
|
||||
* \param w width of the rectangle
|
||||
* \return a fully constructed rectangle */
|
||||
template<typename T>
|
||||
Rectangle<T> MakeRectangle(T h, T w) {
|
||||
return Rectangle<T>(h, w);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*! Total number of circles ever created */
|
||||
extern int NumCircles;
|
||||
|
||||
/// Total number of squares ever created
|
||||
extern int NumSquares;
|
||||
|
||||
17
Examples/python/doxygen/example.i
Normal file
17
Examples/python/doxygen/example.i
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
%module example
|
||||
|
||||
%{
|
||||
#include "example.h"
|
||||
%}
|
||||
|
||||
%immutable NumSquares;
|
||||
%immutable NumCircles;
|
||||
|
||||
%include "example.h"
|
||||
|
||||
/*! - this instantiation uses type int */
|
||||
%template(RectangleInt) Rectangle<int>;
|
||||
|
||||
/*! - this instantiation uses type int */
|
||||
%template(MakeRectangleInt) MakeRectangle<int>;
|
||||
|
||||
28
Examples/python/doxygen/runme.py
Normal file
28
Examples/python/doxygen/runme.py
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
# This example shows simple usage of the wrapped Shape classes.
|
||||
# The main purpose of this example is to show the doxygen comments translation to PyDoc comments.
|
||||
# Users should look at the generated example.py file.
|
||||
# The generated PyDoc can be viewed in a browser by opening the example.html file.
|
||||
|
||||
import example
|
||||
|
||||
print "Creating some objects:"
|
||||
c = example.MakeCircle(10)
|
||||
print " Created circle", c
|
||||
s = example.MakeSquare(10)
|
||||
print " Created square", s
|
||||
r = example.MakeRectangleInt(10, 20)
|
||||
print " Created rectangle", r
|
||||
|
||||
print "\nHere are some properties of the shapes:"
|
||||
for o in [c, s, r]:
|
||||
print " ", o
|
||||
print " area = ", o.area()
|
||||
print " perimeter = ", o.perimeter()
|
||||
|
||||
print "\nRunning pydoc, this is the equivalent to executing: pydoc -w ./example.py"
|
||||
|
||||
import pydoc
|
||||
|
||||
pydoc.writedoc("example")
|
||||
|
||||
print "Open example.html in your browser to view the generated python docs"
|
||||
|
|
@ -19,7 +19,7 @@ of enumerated types are handled as integers.
|
|||
<ul>
|
||||
<li><a href="example.h">example.h</a>. Header file containing some enums.
|
||||
<li><a href="example.i">example.i</a>. Interface file.
|
||||
<li><a href="example.py">example.py</a>. Sample Python script.
|
||||
<li><a href="runme.py">runme.py</a>. Sample Python script.
|
||||
</ul>
|
||||
|
||||
<h2>Notes</h2>
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
/* File : example.h */
|
||||
|
||||
#include <string>
|
||||
#include <string.h>
|
||||
#ifndef SWIG
|
||||
struct A {
|
||||
};
|
||||
|
|
@ -16,30 +16,26 @@ public:
|
|||
char msg[256];
|
||||
};
|
||||
|
||||
#if defined(_MSC_VER)
|
||||
#pragma warning(disable: 4290) // C++ exception specification ignored except to indicate a function is not __declspec(nothrow)
|
||||
#endif
|
||||
|
||||
class Test {
|
||||
public:
|
||||
int simple() throw(int) {
|
||||
int simple() {
|
||||
throw(37);
|
||||
return 1;
|
||||
}
|
||||
int message() throw(const char *) {
|
||||
int message() {
|
||||
throw("I died.");
|
||||
return 1;
|
||||
}
|
||||
int hosed() throw(Exc) {
|
||||
int hosed() {
|
||||
throw(Exc(42,"Hosed"));
|
||||
return 1;
|
||||
}
|
||||
int unknown() throw(A*) {
|
||||
int unknown() {
|
||||
static A a;
|
||||
throw &a;
|
||||
return 1;
|
||||
}
|
||||
int multi(int x) throw(int, const char *, Exc) {
|
||||
int multi(int x) {
|
||||
if (x == 1) throw(37);
|
||||
if (x == 2) throw("Bleah!");
|
||||
if (x == 3) throw(Exc(42,"No-go-diggy-die"));
|
||||
|
|
@ -47,7 +43,3 @@ public:
|
|||
}
|
||||
};
|
||||
|
||||
#if defined(_MSC_VER)
|
||||
#pragma warning(default: 4290) // C++ exception specification ignored except to indicate a function is not __declspec(nothrow)
|
||||
#endif
|
||||
|
||||
|
|
|
|||
|
|
@ -7,6 +7,12 @@
|
|||
|
||||
%include "std_string.i"
|
||||
|
||||
%catches(int) Test::simple();
|
||||
%catches(const char *) Test::message();
|
||||
%catches(Exc) Test::hosed();
|
||||
%catches(A*) Test::unknown();
|
||||
%catches(int, const char *, Exc) Test::multi(int x);
|
||||
|
||||
/* Let's just grab the original header file here */
|
||||
%include "example.h"
|
||||
|
||||
|
|
|
|||
|
|
@ -8,10 +8,6 @@ class FullError {
|
|||
FullError(int m) : maxsize(m) { }
|
||||
};
|
||||
|
||||
#if defined(_MSC_VER)
|
||||
#pragma warning(disable: 4290) // C++ exception specification ignored except to indicate a function is not __declspec(nothrow)
|
||||
#endif
|
||||
|
||||
template<typename T> class Queue {
|
||||
int maxsize;
|
||||
T *items;
|
||||
|
|
@ -27,7 +23,7 @@ template<typename T> class Queue {
|
|||
~Queue() {
|
||||
delete [] items;
|
||||
}
|
||||
void enqueue(T x) throw(FullError) {
|
||||
void enqueue(T x) {
|
||||
if (nitems == maxsize) {
|
||||
throw FullError(maxsize);
|
||||
}
|
||||
|
|
@ -47,8 +43,3 @@ template<typename T> class Queue {
|
|||
}
|
||||
};
|
||||
|
||||
|
||||
#if defined(_MSC_VER)
|
||||
#pragma warning(default: 4290) // C++ exception specification ignored except to indicate a function is not __declspec(nothrow)
|
||||
#endif
|
||||
|
||||
|
|
|
|||
|
|
@ -20,29 +20,12 @@
|
|||
the header file, the enqueue method throws FullError and
|
||||
the dequeue method throws EmptyError. Since we don't
|
||||
want to define an exception handler for everything, we
|
||||
simply write a handler each method individually.
|
||||
simply write a handler for each method individually.
|
||||
|
||||
Note: the *::enqueue syntax means that we simply define
|
||||
the handler for any class with this method defined.
|
||||
*/
|
||||
|
||||
/*
|
||||
First we need to 'disable' the default swig throw mechanism for the
|
||||
FullError class. We do this by rethrowing the exception.
|
||||
|
||||
Note that this is necessary since the class appears in a throw
|
||||
declaration:
|
||||
|
||||
|
||||
void enqueue(T x) throw(FullError);
|
||||
|
||||
hence, swig recognizes it as an exception class and it will generate
|
||||
the necessary code to catch it and rethrow it to the python side.
|
||||
|
||||
*/
|
||||
%typemap(throws) FullError "(void)$1; throw;";
|
||||
|
||||
|
||||
%exception *::enqueue {
|
||||
try {
|
||||
$action
|
||||
|
|
@ -76,15 +59,15 @@
|
|||
*/
|
||||
|
||||
/*
|
||||
Now, the EmpytError doesn't appear in a throw declaration, and hence
|
||||
we need to 'mark' it as an exception class. In python, classes that
|
||||
are used as exception are 'special', and need to be wrapped as
|
||||
'classic' ones.
|
||||
|
||||
This is a python issue, and if you don't mark the class, you will
|
||||
see 'interesting' behaviours at the python side.
|
||||
|
||||
Python classes that are used as exceptions need to be subclasses of the
|
||||
"Exception" class, and so SWIG needs to know which wrapped classes may be
|
||||
used in this way. You can explicitly tell SWIG this by using
|
||||
%exceptionclass. SWIG will implicitly set this feature for classes which
|
||||
appear in a throw declaration, but it's not a problem to explicitly
|
||||
mark such classes as well.
|
||||
|
||||
This is a Python requirement - if you fail to mark such classes with
|
||||
%exceptionclass you may see 'interesting' behaviour on the Python side.
|
||||
*/
|
||||
%exceptionclass EmptyError;
|
||||
%exceptionclass FullError;
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ class CEO(example.Manager):
|
|||
|
||||
# Create an instance of our employee extension class, CEO. The calls to
|
||||
# getName() and getPosition() are standard, the call to getTitle() uses
|
||||
# the director wrappers to call CEO.getPosition. e = CEO("Alice")
|
||||
# the director wrappers to call CEO.getPosition.
|
||||
|
||||
e = CEO("Alice")
|
||||
print e.getName(), "is a", e.getPosition()
|
||||
|
|
|
|||
|
|
@ -65,7 +65,7 @@ Here are some files that illustrate this with a simple example:
|
|||
<li><a href="example.c">example.c</a>
|
||||
<li><a href="example.h">example.h</a>
|
||||
<li><a href="example.i">example.i</a> (SWIG interface)
|
||||
<li><a href="example.py">example.py</a> (Sample script)
|
||||
<li><a href="runme.py">runme.py</a> (Sample script)
|
||||
</ul>
|
||||
|
||||
<h2>Notes</h2>
|
||||
|
|
|
|||
|
|
@ -8,11 +8,12 @@ import_packages_subdirs = \
|
|||
from_init1 \
|
||||
from_init2 \
|
||||
from_init3 \
|
||||
module_is_init \
|
||||
relativeimport1 \
|
||||
relativeimport2 \
|
||||
relativeimport3 \
|
||||
split_modules \
|
||||
namespace_pkg
|
||||
namespace_pkg \
|
||||
|
||||
|
||||
check: build
|
||||
|
|
@ -21,19 +22,19 @@ check: build
|
|||
mkdir -p `dirname $$file`; \
|
||||
cp "${SRCDIR}$$file" "$$file" || exit 1; \
|
||||
done; \
|
||||
fi; \
|
||||
fi
|
||||
for s in $(import_packages_subdirs); do \
|
||||
(cd $$s && $(MAKE) check); \
|
||||
(cd $$s && $(MAKE) check) || exit 1; \
|
||||
done
|
||||
|
||||
build:
|
||||
for s in $(import_packages_subdirs); do \
|
||||
(cd $$s && $(MAKE) SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' build); \
|
||||
(cd $$s && $(MAKE) SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' build) || exit 1; \
|
||||
done
|
||||
|
||||
static:
|
||||
for s in $(import_packages_subdirs); do \
|
||||
(cd $$s && $(MAKE) SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' static); \
|
||||
(cd $$s && $(MAKE) SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' static) || exit 1; \
|
||||
done
|
||||
|
||||
clean:
|
||||
|
|
@ -42,7 +43,7 @@ clean:
|
|||
for file in `cd $(SRCDIR) && find . -type f -name "*.py"`; do \
|
||||
rm -f "$$file" || exit 1; \
|
||||
done; \
|
||||
fi; \
|
||||
fi
|
||||
for s in $(import_packages_subdirs); do \
|
||||
(cd $$s && $(MAKE) clean); \
|
||||
(cd $$s && $(MAKE) clean) || exit 1; \
|
||||
done
|
||||
|
|
|
|||
|
|
@ -1,13 +1,35 @@
|
|||
import sys
|
||||
import os.path
|
||||
import subprocess
|
||||
import sys
|
||||
|
||||
def run_except_on_windows(commandline, env=None):
|
||||
if os.name != "nt" and sys.platform != "cygwin":
|
||||
# Strange failures on windows/cygin/mingw
|
||||
subprocess.check_call(commandline, env=env, shell=True)
|
||||
print(" Finished running: " + commandline)
|
||||
|
||||
# Test import of modules content from within __init__.py
|
||||
testname = os.path.basename(os.path.dirname(os.path.abspath(__file__)))
|
||||
print "Testing " + testname + " - %module(package=...) + python 'import' in __init__.py"
|
||||
|
||||
if sys.version_info < (2, 5):
|
||||
print " Skipping test as Python version is < 2.5 and does not support relative import syntax: 'from . import x'"
|
||||
sys.exit(0)
|
||||
|
||||
if sys.version_info < (3, 0):
|
||||
import py2.pkg2
|
||||
print " Finished importing py2.pkg2"
|
||||
commandline = sys.executable + " -m py2.pkg2.bar"
|
||||
run_except_on_windows(commandline)
|
||||
commandline = sys.executable + " -m py2.pkg2.foo"
|
||||
run_except_on_windows(commandline)
|
||||
else:
|
||||
import py3.pkg2
|
||||
print " Finished importing py3.pkg2"
|
||||
# commandline = sys.executable + " -m py3.pkg2.bar"
|
||||
# run_except_on_windows(commandline)
|
||||
# commandline = sys.executable + " -m py3.pkg2.foo"
|
||||
# run_except_on_windows(commandline)
|
||||
|
||||
# TODO: Commented out code above results in (from python-3.6 onwards):
|
||||
# RuntimeWarning: 'py3.pkg2.bar' found in sys.modules after import of package 'py3.pkg2', but prior to execution of 'py3.pkg2.bar'; this may result in unpredictable behaviour
|
||||
|
|
|
|||
|
|
@ -1,13 +1,31 @@
|
|||
import sys
|
||||
import os.path
|
||||
import subprocess
|
||||
import sys
|
||||
|
||||
def run_except_on_windows(commandline, env=None):
|
||||
if os.name != "nt" and sys.platform != "cygwin":
|
||||
# Strange failures on windows/cygin/mingw
|
||||
subprocess.check_call(commandline, env=env, shell=True)
|
||||
print(" Finished running: " + commandline)
|
||||
|
||||
# Test import of modules content from within __init__.py
|
||||
testname = os.path.basename(os.path.dirname(os.path.abspath(__file__)))
|
||||
print "Testing " + testname + " - %module(package=...) + python 'import' in __init__.py"
|
||||
|
||||
if sys.version_info < (2, 5):
|
||||
print " Skipping test as Python version is < 2.5 and does not support relative import syntax: 'from . import x'"
|
||||
sys.exit(0)
|
||||
|
||||
if sys.version_info < (3, 0):
|
||||
import py2.pkg2
|
||||
print " Finished importing py2.pkg2"
|
||||
commandline = sys.executable + " -m py2.pkg2.bar"
|
||||
run_except_on_windows(commandline)
|
||||
else:
|
||||
import py3.pkg2
|
||||
print " Finished importing py3.pkg2"
|
||||
# commandline = sys.executable + " -m py3.pkg2.bar"
|
||||
# run_except_on_windows(commandline)
|
||||
|
||||
# TODO: Commented out code above results in (from python-3.6 onwards):
|
||||
# RuntimeWarning: 'py3.pkg2.bar' found in sys.modules after import of package 'py3.pkg2', but prior to execution of 'py3.pkg2.bar'; this may result in unpredictable behaviour
|
||||
|
|
|
|||
|
|
@ -1,13 +1,31 @@
|
|||
import sys
|
||||
import os.path
|
||||
import subprocess
|
||||
import sys
|
||||
|
||||
def run_except_on_windows(commandline, env=None):
|
||||
if os.name != "nt" and sys.platform != "cygwin":
|
||||
# Strange failures on windows/cygin/mingw
|
||||
subprocess.check_call(commandline, env=env, shell=True)
|
||||
print(" Finished running: " + commandline)
|
||||
|
||||
# Test import of modules content from within __init__.py
|
||||
testname = os.path.basename(os.path.dirname(os.path.abspath(__file__)))
|
||||
print "Testing " + testname + " - %module(package=...) + python 'import' in __init__.py"
|
||||
|
||||
if sys.version_info < (2, 5):
|
||||
print " Skipping test as Python version is < 2.5 and does not support relative import syntax: 'from . import x'"
|
||||
sys.exit(0)
|
||||
|
||||
if sys.version_info < (3, 0):
|
||||
import py2.pkg2
|
||||
print " Finished importing py2.pkg2"
|
||||
commandline = sys.executable + " -m py2.pkg2.bar"
|
||||
run_except_on_windows(commandline)
|
||||
else:
|
||||
import py3.pkg2
|
||||
print " Finished importing py3.pkg2"
|
||||
# commandline = sys.executable + " -m py3.pkg2.bar"
|
||||
# run_except_on_windows(commandline)
|
||||
|
||||
# TODO: Commented out code above results in (from python-3.6 onwards):
|
||||
# RuntimeWarning: 'py3.pkg2.bar' found in sys.modules after import of package 'py3.pkg2', but prior to execution of 'py3.pkg2.bar'; this may result in unpredictable behaviour
|
||||
|
|
|
|||
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue