Merge branch 'master' into C
This commit is contained in:
commit
7c402ad148
2760 changed files with 114689 additions and 39303 deletions
|
|
@ -1,22 +1,24 @@
|
|||
TOP = ../..
|
||||
SWIG = $(TOP)/../preinst-swig
|
||||
SWIGEXE = $(TOP)/../swig
|
||||
SWIG_LIB_DIR = $(TOP)/../$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib
|
||||
CXXSRCS = example.cxx
|
||||
TARGET = example
|
||||
INTERFACE = example.i
|
||||
LIBS = -lm
|
||||
SWIGOPT =
|
||||
SWIGOPT =
|
||||
|
||||
all::
|
||||
$(MAKE) -f $(TOP)/Makefile $(SWIGLIB) CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \
|
||||
check: build
|
||||
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' python_run
|
||||
|
||||
build:
|
||||
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' $(SWIGLIB) CXXSRCS='$(CXXSRCS)' \
|
||||
SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \
|
||||
SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' python_cpp
|
||||
|
||||
static::
|
||||
$(MAKE) -f $(TOP)/Makefile $(SWIGLIB) CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \
|
||||
static:
|
||||
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' $(SWIGLIB) CXXSRCS='$(CXXSRCS)' \
|
||||
SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \
|
||||
SWIGOPT='$(SWIGOPT)' TARGET='mypython' INTERFACE='$(INTERFACE)' python_cpp_static
|
||||
|
||||
clean::
|
||||
$(MAKE) -f $(TOP)/Makefile python_clean
|
||||
rm -f $(TARGET).py
|
||||
|
||||
check: all
|
||||
$(MAKE) -f $(TOP)/Makefile python_run
|
||||
clean:
|
||||
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' TARGET='$(TARGET)' python_clean
|
||||
|
|
|
|||
|
|
@ -4,8 +4,6 @@
|
|||
#include "example.h"
|
||||
%}
|
||||
|
||||
%include "std_string.i"
|
||||
|
||||
/* turn on director wrapping Callback */
|
||||
%feature("director") Callback;
|
||||
|
||||
|
|
|
|||
|
|
@ -2,14 +2,16 @@
|
|||
|
||||
# This file illustrates the cross language polymorphism using directors.
|
||||
|
||||
import example
|
||||
import example
|
||||
|
||||
|
||||
class PyCallback(example.Callback):
|
||||
def __init__(self):
|
||||
example.Callback.__init__(self)
|
||||
def run(self):
|
||||
print "PyCallback.run()"
|
||||
|
||||
def __init__(self):
|
||||
example.Callback.__init__(self)
|
||||
|
||||
def run(self):
|
||||
print "PyCallback.run()"
|
||||
|
||||
# Create an Caller instance
|
||||
|
||||
|
|
@ -25,7 +27,7 @@ callback = example.Callback()
|
|||
callback.thisown = 0
|
||||
caller.setCallback(callback)
|
||||
caller.call()
|
||||
caller.delCallback();
|
||||
caller.delCallback()
|
||||
|
||||
print
|
||||
print "Adding and calling a Python callback"
|
||||
|
|
@ -42,7 +44,7 @@ print
|
|||
print "Adding and calling another Python callback"
|
||||
print "------------------------------------------"
|
||||
|
||||
# Lets do the same but use the weak reference this time.
|
||||
# Let's do the same but use the weak reference this time.
|
||||
|
||||
callback = PyCallback().__disown__()
|
||||
caller.setCallback(callback)
|
||||
|
|
@ -53,4 +55,3 @@ caller.delCallback()
|
|||
|
||||
print
|
||||
print "python exit"
|
||||
|
||||
|
|
|
|||
|
|
@ -13,6 +13,7 @@ funcptr2
|
|||
functor
|
||||
import
|
||||
import_template
|
||||
import_packages
|
||||
java
|
||||
#libffi
|
||||
multimap
|
||||
|
|
@ -23,7 +24,6 @@ simple
|
|||
smartptr
|
||||
std_vector
|
||||
std_map
|
||||
swigrun
|
||||
template
|
||||
varargs
|
||||
variables
|
||||
|
|
|
|||
|
|
@ -1,21 +1,23 @@
|
|||
TOP = ../..
|
||||
SWIG = $(TOP)/../preinst-swig
|
||||
SWIGEXE = $(TOP)/../swig
|
||||
SWIG_LIB_DIR = $(TOP)/../$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib
|
||||
CXXSRCS = example.cxx
|
||||
TARGET = example
|
||||
INTERFACE = example.i
|
||||
LIBS = -lm
|
||||
|
||||
all::
|
||||
$(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \
|
||||
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)' \
|
||||
TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' python_cpp
|
||||
|
||||
static::
|
||||
$(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \
|
||||
static:
|
||||
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' \
|
||||
SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \
|
||||
TARGET='mypython' INTERFACE='$(INTERFACE)' python_cpp_static
|
||||
|
||||
clean::
|
||||
$(MAKE) -f $(TOP)/Makefile python_clean
|
||||
rm -f $(TARGET).py
|
||||
|
||||
check: all
|
||||
$(MAKE) -f $(TOP)/Makefile python_run
|
||||
clean:
|
||||
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' TARGET='$(TARGET)' python_clean
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
/* File : example.c */
|
||||
/* File : example.cxx */
|
||||
|
||||
#include "example.h"
|
||||
#define M_PI 3.14159265358979323846
|
||||
|
|
@ -11,18 +11,18 @@ void Shape::move(double dx, double dy) {
|
|||
|
||||
int Shape::nshapes = 0;
|
||||
|
||||
double Circle::area(void) {
|
||||
double Circle::area() {
|
||||
return M_PI*radius*radius;
|
||||
}
|
||||
|
||||
double Circle::perimeter(void) {
|
||||
double Circle::perimeter() {
|
||||
return 2*M_PI*radius;
|
||||
}
|
||||
|
||||
double Square::area(void) {
|
||||
double Square::area() {
|
||||
return width*width;
|
||||
}
|
||||
|
||||
double Square::perimeter(void) {
|
||||
double Square::perimeter() {
|
||||
return 4*width;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -43,7 +43,7 @@ RSC=rc.exe
|
|||
# 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 "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"
|
||||
|
|
@ -126,7 +126,7 @@ InputName=example
|
|||
echo PYTHON_INCLUDE: %PYTHON_INCLUDE%
|
||||
echo PYTHON_LIB: %PYTHON_LIB%
|
||||
echo on
|
||||
..\..\..\swig.exe -c++ -python $(InputPath)
|
||||
..\..\..\swig.exe -c++ -python "$(InputPath)"
|
||||
|
||||
# End Custom Build
|
||||
|
||||
|
|
@ -141,7 +141,7 @@ InputName=example
|
|||
echo PYTHON_INCLUDE: %PYTHON_INCLUDE%
|
||||
echo PYTHON_LIB: %PYTHON_LIB%
|
||||
echo on
|
||||
..\..\..\swig.exe -c++ -python $(InputPath)
|
||||
..\..\..\swig.exe -c++ -python "$(InputPath)"
|
||||
|
||||
# End Custom Build
|
||||
|
||||
|
|
|
|||
|
|
@ -7,11 +7,11 @@ public:
|
|||
}
|
||||
virtual ~Shape() {
|
||||
nshapes--;
|
||||
};
|
||||
double x, y;
|
||||
}
|
||||
double x, y;
|
||||
void move(double dx, double dy);
|
||||
virtual double area(void) = 0;
|
||||
virtual double perimeter(void) = 0;
|
||||
virtual double area() = 0;
|
||||
virtual double perimeter() = 0;
|
||||
static int nshapes;
|
||||
};
|
||||
|
||||
|
|
@ -19,21 +19,16 @@ class Circle : public Shape {
|
|||
private:
|
||||
double radius;
|
||||
public:
|
||||
Circle(double r) : radius(r) { };
|
||||
virtual double area(void);
|
||||
virtual double perimeter(void);
|
||||
Circle(double r) : radius(r) { }
|
||||
virtual double area();
|
||||
virtual double perimeter();
|
||||
};
|
||||
|
||||
class Square : public Shape {
|
||||
private:
|
||||
double width;
|
||||
public:
|
||||
Square(double w) : width(w) { };
|
||||
virtual double area(void);
|
||||
virtual double perimeter(void);
|
||||
Square(double w) : width(w) { }
|
||||
virtual double area();
|
||||
virtual double perimeter();
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -11,4 +11,3 @@
|
|||
|
||||
/* Let's just grab the original header file here */
|
||||
%include "example.h"
|
||||
|
||||
|
|
|
|||
|
|
@ -12,9 +12,7 @@
|
|||
<H2>Wrapping a simple C++ class</H2>
|
||||
|
||||
<p>
|
||||
This example illustrates the most primitive form of C++ class wrapping performed
|
||||
by SWIG. In this case, C++ classes are simply transformed into a collection of
|
||||
C-style functions that provide access to class members.
|
||||
This example illustrates wrapping a simple C++ class to give a Python class.
|
||||
|
||||
<h2>The C++ Code</h2>
|
||||
|
||||
|
|
@ -32,8 +30,8 @@ public:
|
|||
}
|
||||
virtual ~Shape() {
|
||||
nshapes--;
|
||||
};
|
||||
double x, y;
|
||||
}
|
||||
double x, y;
|
||||
void move(double dx, double dy);
|
||||
virtual double area() = 0;
|
||||
virtual double perimeter() = 0;
|
||||
|
|
@ -44,7 +42,7 @@ class Circle : public Shape {
|
|||
private:
|
||||
double radius;
|
||||
public:
|
||||
Circle(double r) : radius(r) { };
|
||||
Circle(double r) : radius(r) { }
|
||||
virtual double area();
|
||||
virtual double perimeter();
|
||||
};
|
||||
|
|
@ -53,7 +51,7 @@ class Square : public Shape {
|
|||
private:
|
||||
double width;
|
||||
public:
|
||||
Square(double w) : width(w) { };
|
||||
Square(double w) : width(w) { }
|
||||
virtual double area();
|
||||
virtual double perimeter();
|
||||
};
|
||||
|
|
@ -102,51 +100,34 @@ c = example.new_Circle(10.0)
|
|||
</blockquote>
|
||||
|
||||
<p>
|
||||
<li>To access member data, a pair of accessor functions are used.
|
||||
<li>Member variables of the C++ class are wrapped as attributes of the Python class.
|
||||
For example:
|
||||
|
||||
<blockquote>
|
||||
<pre>
|
||||
example.Shape_x_set(c,15) # Set member data
|
||||
x = example.Shape_x_get(c) # Get member data
|
||||
</pre>
|
||||
</blockquote>
|
||||
|
||||
Note: when accessing member data, the name of the class in which
|
||||
the member data was must be used. In this case, <tt>Shape_x_get()</tt>
|
||||
and <tt>Shape_x_set()</tt> are used since 'x' was defined in Shape.
|
||||
|
||||
<p>
|
||||
<li>To invoke a member function, you simply do this
|
||||
|
||||
<blockquote>
|
||||
<pre>
|
||||
print "The area is ", example.Shape_area(c)
|
||||
c.x = 15 # Set member data
|
||||
x = c.x # Get member data
|
||||
</pre>
|
||||
</blockquote>
|
||||
|
||||
<p>
|
||||
<li>Type checking knows about the inheritance structure of C++. For example:
|
||||
<li>Member function are invoked as you would expect:
|
||||
|
||||
<blockquote>
|
||||
<pre>
|
||||
example.Shape_area(c) # Works (c is a Shape)
|
||||
example.Circle_area(c) # Works (c is a Circle)
|
||||
example.Square_area(c) # Fails (c is definitely not a Square)
|
||||
print "The area is ", c.area()
|
||||
</pre>
|
||||
</blockquote>
|
||||
|
||||
<p>
|
||||
<li>To invoke a destructor, simply do this
|
||||
<li>To invoke a destructor, simply call <code>del</code> on the object:
|
||||
|
||||
<blockquote>
|
||||
<pre>
|
||||
example.delete_Shape(c) # Deletes a shape
|
||||
del c # Deletes a shape
|
||||
</pre>
|
||||
</blockquote>
|
||||
|
||||
(Note: destructors are currently not inherited. This might change later).
|
||||
|
||||
<p>
|
||||
<li>Static member variables are wrapped as C global variables. For example:
|
||||
|
||||
|
|
@ -162,52 +143,12 @@ example.cvar.Shapes_nshapes = 13 # Set a static data member
|
|||
<h2>General Comments</h2>
|
||||
|
||||
<ul>
|
||||
<li>This low-level interface is not the only way to handle C++ code.
|
||||
Proxy classes provide a much higher-level interface.
|
||||
|
||||
<p>
|
||||
<li>SWIG *does* know how to properly perform upcasting of objects in
|
||||
<li>SWIG <b>does</b> know how to properly perform upcasting of objects in
|
||||
an inheritance hierarchy (including multiple inheritance). Therefore
|
||||
it is perfectly safe to pass an object of a derived class to any
|
||||
function involving a base class.
|
||||
|
||||
<p>
|
||||
<li>A wide variety of C++ features are not currently supported by SWIG. Here is the
|
||||
short and incomplete list:
|
||||
|
||||
<p>
|
||||
<ul>
|
||||
<li>Overloaded methods and functions. SWIG wrappers don't know how to resolve name
|
||||
conflicts so you must give an alternative name to any overloaded method name using the
|
||||
%name directive like this:
|
||||
|
||||
<blockquote>
|
||||
<pre>
|
||||
void foo(int a);
|
||||
%name(foo2) void foo(double a, double b);
|
||||
</pre>
|
||||
</blockquote>
|
||||
|
||||
<p>
|
||||
<li>Overloaded operators. Not supported at all. The only workaround for this is
|
||||
to write a helper function. For example:
|
||||
|
||||
<blockquote>
|
||||
<pre>
|
||||
%inline %{
|
||||
Vector *vector_add(Vector *a, Vector *b) {
|
||||
... whatever ...
|
||||
}
|
||||
%}
|
||||
</pre>
|
||||
</blockquote>
|
||||
|
||||
<p>
|
||||
<li>Namespaces. Not supported at all. Won't be supported until SWIG2.0 (if at all).
|
||||
|
||||
<p>
|
||||
<li>Dave's snide remark: Like a large bottle of strong Tequilla, it's better to
|
||||
use C++ in moderation.
|
||||
<li>C++ Namespaces - %nspace isn't yet supported for Python.
|
||||
|
||||
</ul>
|
||||
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
# This file illustrates the proxy class C++ interface generated
|
||||
# by SWIG.
|
||||
|
||||
import example
|
||||
import example
|
||||
|
||||
# ----- Object creation -----
|
||||
|
||||
|
|
@ -15,7 +15,7 @@ print " Created square", s
|
|||
|
||||
# ----- Access a static member -----
|
||||
|
||||
print "\nA total of", example.cvar.Shape_nshapes,"shapes were created"
|
||||
print "\nA total of", example.cvar.Shape_nshapes, "shapes were created"
|
||||
|
||||
# ----- Member data access -----
|
||||
|
||||
|
|
@ -28,16 +28,18 @@ s.x = -10
|
|||
s.y = 5
|
||||
|
||||
print "\nHere is their current position:"
|
||||
print " Circle = (%f, %f)" % (c.x,c.y)
|
||||
print " Square = (%f, %f)" % (s.x,s.y)
|
||||
print " Circle = (%f, %f)" % (c.x, c.y)
|
||||
print " Square = (%f, %f)" % (s.x, s.y)
|
||||
|
||||
# ----- Call some methods -----
|
||||
|
||||
print "\nHere are some properties of the shapes:"
|
||||
for o in [c,s]:
|
||||
print " ", o
|
||||
print " area = ", o.area()
|
||||
print " perimeter = ", o.perimeter()
|
||||
for o in [c, s]:
|
||||
print " ", o
|
||||
print " area = ", o.area()
|
||||
print " perimeter = ", o.perimeter()
|
||||
# prevent o from holding a reference to the last object looked at
|
||||
o = None
|
||||
|
||||
print "\nGuess I'll clean up now"
|
||||
|
||||
|
|
@ -45,7 +47,5 @@ print "\nGuess I'll clean up now"
|
|||
del c
|
||||
del s
|
||||
|
||||
s = 3
|
||||
print example.cvar.Shape_nshapes,"shapes remain"
|
||||
print example.cvar.Shape_nshapes, "shapes remain"
|
||||
print "Goodbye"
|
||||
|
||||
|
|
|
|||
|
|
@ -1,20 +1,22 @@
|
|||
TOP = ../..
|
||||
SWIG = $(TOP)/../preinst-swig
|
||||
SRCS =
|
||||
SWIGEXE = $(TOP)/../swig
|
||||
SWIG_LIB_DIR = $(TOP)/../$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib
|
||||
SRCS =
|
||||
TARGET = example
|
||||
INTERFACE = example.i
|
||||
|
||||
all::
|
||||
$(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \
|
||||
check: build
|
||||
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' python_run
|
||||
|
||||
build:
|
||||
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' \
|
||||
SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \
|
||||
TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' python
|
||||
|
||||
static::
|
||||
$(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \
|
||||
static:
|
||||
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' \
|
||||
SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \
|
||||
TARGET='mypython' INTERFACE='$(INTERFACE)' python_static
|
||||
|
||||
clean::
|
||||
$(MAKE) -f $(TOP)/Makefile python_clean
|
||||
rm -f $(TARGET).py
|
||||
|
||||
check: all
|
||||
$(MAKE) -f $(TOP)/Makefile python_run
|
||||
clean:
|
||||
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' TARGET='$(TARGET)' python_clean
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
# file: runme.py
|
||||
|
||||
import example
|
||||
import example
|
||||
|
||||
print "ICONST =", example.ICONST, "(should be 42)"
|
||||
print "FCONST =", example.FCONST, "(should be 2.1828)"
|
||||
|
|
@ -8,7 +8,7 @@ print "CCONST =", example.CCONST, "(should be 'x')"
|
|||
print "CCONST2 =", example.CCONST2, "(this should be on a new line)"
|
||||
print "SCONST =", example.SCONST, "(should be 'Hello World')"
|
||||
print "SCONST2 =", example.SCONST2, "(should be '\"Hello World\"')"
|
||||
print "EXPR =", example.EXPR, "(should be 48.5484)"
|
||||
print "EXPR =", example.EXPR, "(should be 48.5484)"
|
||||
print "iconst =", example.iconst, "(should be 37)"
|
||||
print "fconst =", example.fconst, "(should be 3.14)"
|
||||
|
||||
|
|
@ -21,7 +21,3 @@ try:
|
|||
print "FOO = ", example.FOO, "(Arg! This shouldn't print anything)"
|
||||
except AttributeError:
|
||||
print "FOO isn't defined (good)"
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -1,20 +1,23 @@
|
|||
TOP = ../..
|
||||
SWIG = $(TOP)/../preinst-swig
|
||||
SWIGEXE = $(TOP)/../swig
|
||||
SWIG_LIB_DIR = $(TOP)/../$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib
|
||||
SRCS = example.c
|
||||
TARGET = example
|
||||
INTERFACE = example.i
|
||||
SWIGOPT =
|
||||
all::
|
||||
$(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \
|
||||
TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' python
|
||||
SWIGOPT =
|
||||
|
||||
static::
|
||||
$(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \
|
||||
TARGET='mypython' INTERFACE='$(INTERFACE)' python_static
|
||||
check: build
|
||||
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' python_run
|
||||
|
||||
clean::
|
||||
$(MAKE) -f $(TOP)/Makefile python_clean
|
||||
rm -f $(TARGET).py
|
||||
build:
|
||||
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' \
|
||||
SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \
|
||||
SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' python
|
||||
|
||||
check: all
|
||||
$(MAKE) -f $(TOP)/Makefile python_run
|
||||
static:
|
||||
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' \
|
||||
SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \
|
||||
SWIGOPT='$(SWIGOPT)' TARGET='mypython' INTERFACE='$(INTERFACE)' python_static
|
||||
|
||||
clean:
|
||||
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' TARGET='$(TARGET)' python_clean
|
||||
|
|
|
|||
|
|
@ -43,7 +43,7 @@ RSC=rc.exe
|
|||
# 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 "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"
|
||||
|
|
@ -122,7 +122,7 @@ InputName=example
|
|||
echo PYTHON_INCLUDE: %PYTHON_INCLUDE%
|
||||
echo PYTHON_LIB: %PYTHON_LIB%
|
||||
echo on
|
||||
..\..\..\swig.exe -python $(InputPath)
|
||||
..\..\..\swig.exe -python "$(InputPath)"
|
||||
|
||||
# End Custom Build
|
||||
|
||||
|
|
@ -137,7 +137,7 @@ InputName=example
|
|||
echo PYTHON_INCLUDE: %PYTHON_INCLUDE%
|
||||
echo PYTHON_LIB: %PYTHON_LIB%
|
||||
echo on
|
||||
..\..\..\swig.exe -python $(InputPath)
|
||||
..\..\..\swig.exe -python "$(InputPath)"
|
||||
|
||||
# End Custom Build
|
||||
|
||||
|
|
|
|||
|
|
@ -1,13 +1,13 @@
|
|||
# file: runme.py
|
||||
|
||||
import example
|
||||
import example
|
||||
|
||||
# Call our gcd() function
|
||||
|
||||
x = 42
|
||||
y = 105
|
||||
g = example.gcd(x,y)
|
||||
print "The gcd of %d and %d is %d" % (x,y,g)
|
||||
g = example.gcd(x, y)
|
||||
print "The gcd of %d and %d is %d" % (x, y, g)
|
||||
|
||||
# Manipulate the Foo global variable
|
||||
|
||||
|
|
@ -19,12 +19,3 @@ example.cvar.Foo = 3.1415926
|
|||
|
||||
# See if the change took effect
|
||||
print "Foo = ", example.cvar.Foo
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -1,24 +1,26 @@
|
|||
TOP = ../..
|
||||
SWIG = $(TOP)/../preinst-swig
|
||||
SWIGEXE = $(TOP)/../swig
|
||||
SWIG_LIB_DIR = $(TOP)/../$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib
|
||||
CXXSRCS = example.cxx
|
||||
TARGET = example
|
||||
INTERFACE = example.i
|
||||
LIBS = -lm
|
||||
SWIGOPT = -O
|
||||
|
||||
all::
|
||||
$(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \
|
||||
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 CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \
|
||||
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 python_clean
|
||||
rm -f $(TARGET).py
|
||||
|
||||
check: all
|
||||
$(MAKE) -f $(TOP)/Makefile python_run
|
||||
clean:
|
||||
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' TARGET='$(TARGET)' python_clean
|
||||
|
|
|
|||
|
|
@ -1,6 +1,5 @@
|
|||
# file: runme.py
|
||||
|
||||
import example
|
||||
import example
|
||||
|
||||
print "example.Foo.bar.__doc__ =", repr(example.Foo.bar.__doc__), "(Should be 'No comment')"
|
||||
|
||||
|
|
|
|||
|
|
@ -1,21 +1,23 @@
|
|||
TOP = ../..
|
||||
SWIG = $(TOP)/../preinst-swig
|
||||
SWIGEXE = $(TOP)/../swig
|
||||
SWIG_LIB_DIR = $(TOP)/../$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib
|
||||
CXXSRCS = example.cxx
|
||||
TARGET = example
|
||||
INTERFACE = example.i
|
||||
LIBS = -lm
|
||||
|
||||
all::
|
||||
$(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \
|
||||
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)' \
|
||||
TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' python_cpp
|
||||
|
||||
static::
|
||||
$(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \
|
||||
static:
|
||||
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' \
|
||||
SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \
|
||||
TARGET='mypython' INTERFACE='$(INTERFACE)' python_cpp_static
|
||||
|
||||
clean::
|
||||
$(MAKE) -f $(TOP)/Makefile python_clean
|
||||
rm -f $(TARGET).py
|
||||
|
||||
check: all
|
||||
$(MAKE) -f $(TOP)/Makefile python_run
|
||||
clean:
|
||||
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' TARGET='$(TARGET)' python_clean
|
||||
|
|
|
|||
|
|
@ -18,9 +18,9 @@ print " Foo_LUDICROUS =", example.Foo.LUDICROUS
|
|||
print "\nTesting use of enums with functions\n"
|
||||
|
||||
example.enum_test(example.RED, example.Foo.IMPULSE)
|
||||
example.enum_test(example.BLUE, example.Foo.WARP)
|
||||
example.enum_test(example.BLUE, example.Foo.WARP)
|
||||
example.enum_test(example.GREEN, example.Foo.LUDICROUS)
|
||||
example.enum_test(1234,5678)
|
||||
example.enum_test(1234, 5678)
|
||||
|
||||
print "\nTesting use of enum with class method"
|
||||
f = example.Foo()
|
||||
|
|
@ -28,4 +28,3 @@ f = example.Foo()
|
|||
f.enum_test(example.Foo.IMPULSE)
|
||||
f.enum_test(example.Foo.WARP)
|
||||
f.enum_test(example.Foo.LUDICROUS)
|
||||
|
||||
|
|
|
|||
|
|
@ -1,21 +1,23 @@
|
|||
TOP = ../..
|
||||
SWIG = $(TOP)/../preinst-swig
|
||||
CXXSRCS =
|
||||
SWIGEXE = $(TOP)/../swig
|
||||
SWIG_LIB_DIR = $(TOP)/../$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib
|
||||
CXXSRCS =
|
||||
TARGET = example
|
||||
INTERFACE = example.i
|
||||
LIBS = -lm
|
||||
|
||||
all::
|
||||
$(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \
|
||||
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)' \
|
||||
TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' python_cpp
|
||||
|
||||
static::
|
||||
$(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \
|
||||
static:
|
||||
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' \
|
||||
SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \
|
||||
TARGET='mypython' INTERFACE='$(INTERFACE)' python_cpp_static
|
||||
|
||||
clean::
|
||||
$(MAKE) -f $(TOP)/Makefile python_clean
|
||||
rm -f $(TARGET).py
|
||||
|
||||
check: all
|
||||
$(MAKE) -f $(TOP)/Makefile python_run
|
||||
clean:
|
||||
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' TARGET='$(TARGET)' python_clean
|
||||
|
|
|
|||
|
|
@ -10,3 +10,12 @@
|
|||
/* Let's just grab the original header file here */
|
||||
%include "example.h"
|
||||
|
||||
%inline %{
|
||||
// The -builtin SWIG option results in SWIGPYTHON_BUILTIN being defined
|
||||
#ifdef SWIGPYTHON_BUILTIN
|
||||
bool is_python_builtin() { return true; }
|
||||
#else
|
||||
bool is_python_builtin() { return false; }
|
||||
#endif
|
||||
%}
|
||||
|
||||
|
|
|
|||
|
|
@ -6,31 +6,37 @@ import example
|
|||
|
||||
t = example.Test()
|
||||
try:
|
||||
t.unknown()
|
||||
except RuntimeError,e:
|
||||
print "incomplete type", e.args[0]
|
||||
t.unknown()
|
||||
except RuntimeError, e:
|
||||
print "incomplete type", e.args[0]
|
||||
|
||||
try:
|
||||
t.simple()
|
||||
except RuntimeError,e:
|
||||
print e.args[0]
|
||||
t.simple()
|
||||
except RuntimeError, e:
|
||||
print e.args[0]
|
||||
|
||||
try:
|
||||
t.message()
|
||||
except RuntimeError,e:
|
||||
print e.args[0]
|
||||
|
||||
try:
|
||||
t.hosed()
|
||||
except example.Exc,e:
|
||||
print e.code, e.msg
|
||||
|
||||
for i in range(1,4):
|
||||
try:
|
||||
t.multi(i)
|
||||
except RuntimeError,e:
|
||||
print e.args[0]
|
||||
except example.Exc,e:
|
||||
print e.code, e.msg
|
||||
t.message()
|
||||
except RuntimeError, e:
|
||||
print e.args[0]
|
||||
|
||||
if not example.is_python_builtin():
|
||||
try:
|
||||
t.hosed()
|
||||
except example.Exc, e:
|
||||
print e.code, e.msg
|
||||
else:
|
||||
try:
|
||||
t.hosed()
|
||||
except BaseException, e:
|
||||
# Throwing builtin classes as exceptions not supported (-builtin
|
||||
# option)
|
||||
print e
|
||||
|
||||
for i in range(1, 4):
|
||||
try:
|
||||
t.multi(i)
|
||||
except RuntimeError, e:
|
||||
print e.args[0]
|
||||
except example.Exc, e:
|
||||
print e.code, e.msg
|
||||
|
|
|
|||
|
|
@ -1,22 +1,24 @@
|
|||
TOP = ../..
|
||||
SWIG = $(TOP)/../preinst-swig
|
||||
CXXSRCS =
|
||||
SWIGEXE = $(TOP)/../swig
|
||||
SWIG_LIB_DIR = $(TOP)/../$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib
|
||||
CXXSRCS =
|
||||
TARGET = example
|
||||
INTERFACE = example.i
|
||||
LIBS = -lm
|
||||
SWIGOPT =
|
||||
SWIGOPT =
|
||||
|
||||
all::
|
||||
$(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \
|
||||
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 CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \
|
||||
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 python_clean
|
||||
rm -f $(TARGET).py
|
||||
|
||||
check: all
|
||||
$(MAKE) -f $(TOP)/Makefile python_run
|
||||
clean:
|
||||
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' TARGET='$(TARGET)' python_clean
|
||||
|
|
|
|||
|
|
@ -109,6 +109,12 @@
|
|||
%template(doubleQueue) Queue<double>;
|
||||
|
||||
|
||||
|
||||
|
||||
%inline %{
|
||||
// The -builtin SWIG option results in SWIGPYTHON_BUILTIN being defined
|
||||
#ifdef SWIGPYTHON_BUILTIN
|
||||
bool is_python_builtin() { return true; }
|
||||
#else
|
||||
bool is_python_builtin() { return false; }
|
||||
#endif
|
||||
%}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,23 +1,29 @@
|
|||
# file: runme.py
|
||||
import example
|
||||
|
||||
if example.is_python_builtin():
|
||||
print "Skipping example: -builtin option does not support %exceptionclass"
|
||||
exit(0)
|
||||
|
||||
q = example.intQueue(10)
|
||||
|
||||
print "Inserting items into intQueue"
|
||||
|
||||
print type(example.FullError)
|
||||
|
||||
try:
|
||||
for i in range(0,100):
|
||||
q.enqueue(i)
|
||||
except example.FullError,e:
|
||||
print "Maxsize is", e.maxsize
|
||||
for i in range(0, 100):
|
||||
q.enqueue(i)
|
||||
except example.FullError, e:
|
||||
print "Maxsize is", e.maxsize
|
||||
|
||||
print "Removing items"
|
||||
|
||||
try:
|
||||
while 1:
|
||||
q.dequeue()
|
||||
except example.EmptyError,e:
|
||||
pass
|
||||
while 1:
|
||||
q.dequeue()
|
||||
except example.EmptyError, e:
|
||||
pass
|
||||
|
||||
|
||||
q = example.doubleQueue(1000)
|
||||
|
|
@ -25,21 +31,15 @@ q = example.doubleQueue(1000)
|
|||
print "Inserting items into doubleQueue"
|
||||
|
||||
try:
|
||||
for i in range(0,10000):
|
||||
q.enqueue(i*1.5)
|
||||
except example.FullError,e:
|
||||
print "Maxsize is", e.maxsize
|
||||
for i in range(0, 10000):
|
||||
q.enqueue(i * 1.5)
|
||||
except example.FullError, e:
|
||||
print "Maxsize is", e.maxsize
|
||||
|
||||
print "Removing items"
|
||||
|
||||
try:
|
||||
while 1:
|
||||
q.dequeue()
|
||||
except example.EmptyError,e:
|
||||
pass
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
while 1:
|
||||
q.dequeue()
|
||||
except example.EmptyError, e:
|
||||
pass
|
||||
|
|
|
|||
|
|
@ -1,22 +1,24 @@
|
|||
TOP = ../..
|
||||
SWIG = $(TOP)/../preinst-swig
|
||||
SWIGEXE = $(TOP)/../swig
|
||||
SWIG_LIB_DIR = $(TOP)/../$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib
|
||||
CXXSRCS = example.cxx
|
||||
TARGET = example
|
||||
INTERFACE = example.i
|
||||
LIBS = -lm
|
||||
SWIGOPT =
|
||||
SWIGOPT =
|
||||
|
||||
all::
|
||||
$(MAKE) -f $(TOP)/Makefile $(SWIGLIB) CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \
|
||||
check: build
|
||||
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' python_run
|
||||
|
||||
build:
|
||||
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' $(SWIGLIB) CXXSRCS='$(CXXSRCS)' \
|
||||
SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \
|
||||
SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' python_cpp
|
||||
|
||||
static::
|
||||
$(MAKE) -f $(TOP)/Makefile $(SWIGLIB) CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \
|
||||
static:
|
||||
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' $(SWIGLIB) CXXSRCS='$(CXXSRCS)' \
|
||||
SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \
|
||||
SWIGOPT='$(SWIGOPT)' TARGET='mypython' INTERFACE='$(INTERFACE)' python_cpp_static
|
||||
|
||||
clean::
|
||||
$(MAKE) -f $(TOP)/Makefile python_clean
|
||||
rm -f $(TARGET).py
|
||||
|
||||
check: all
|
||||
$(MAKE) -f $(TOP)/Makefile python_run
|
||||
clean:
|
||||
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' TARGET='$(TARGET)' python_clean
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ public:
|
|||
virtual std::string getTitle() { return getPosition() + " " + getName(); }
|
||||
virtual std::string getName() { return name; }
|
||||
virtual std::string getPosition() const { return "Employee"; }
|
||||
virtual ~Employee() { printf("~Employee() @ %p\n", this); }
|
||||
virtual ~Employee() { printf("~Employee() @ %p\n", (void *)this); }
|
||||
};
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -2,16 +2,18 @@
|
|||
|
||||
# This file illustrates the cross language polymorphism using directors.
|
||||
|
||||
import example
|
||||
import example
|
||||
|
||||
|
||||
# CEO class, which overrides Employee::getPosition().
|
||||
|
||||
class CEO(example.Manager):
|
||||
def __init__(self, name):
|
||||
example.Manager.__init__(self, name)
|
||||
def getPosition(self):
|
||||
return "CEO"
|
||||
|
||||
def __init__(self, name):
|
||||
example.Manager.__init__(self, name)
|
||||
|
||||
def getPosition(self):
|
||||
return "CEO"
|
||||
|
||||
|
||||
# Create an instance of our employee extension class, CEO. The calls to
|
||||
|
|
@ -78,4 +80,3 @@ print "----------------------"
|
|||
# All done.
|
||||
|
||||
print "python exit"
|
||||
|
||||
|
|
|
|||
|
|
@ -1,20 +1,22 @@
|
|||
TOP = ../..
|
||||
SWIG = $(TOP)/../preinst-swig
|
||||
SWIGEXE = $(TOP)/../swig
|
||||
SWIG_LIB_DIR = $(TOP)/../$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib
|
||||
SRCS = example.c
|
||||
TARGET = example
|
||||
INTERFACE = example.i
|
||||
|
||||
all::
|
||||
$(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \
|
||||
check: build
|
||||
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' python_run
|
||||
|
||||
build:
|
||||
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' \
|
||||
SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \
|
||||
TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' python
|
||||
|
||||
static::
|
||||
$(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \
|
||||
static:
|
||||
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' \
|
||||
SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \
|
||||
TARGET='mypython' INTERFACE='$(INTERFACE)' python_static
|
||||
|
||||
clean::
|
||||
$(MAKE) -f $(TOP)/Makefile python_clean
|
||||
rm -f $(TARGET).py
|
||||
|
||||
check: all
|
||||
$(MAKE) -f $(TOP)/Makefile python_run
|
||||
clean:
|
||||
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' TARGET='$(TARGET)' python_clean
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
# file: runme.py
|
||||
|
||||
import example
|
||||
import example
|
||||
|
||||
a = 37
|
||||
b = 42
|
||||
|
|
@ -10,9 +10,9 @@ b = 42
|
|||
print "Trying some C callback functions"
|
||||
print " a =", a
|
||||
print " b =", b
|
||||
print " ADD(a,b) =", example.do_op(a,b,example.ADD)
|
||||
print " SUB(a,b) =", example.do_op(a,b,example.SUB)
|
||||
print " MUL(a,b) =", example.do_op(a,b,example.MUL)
|
||||
print " ADD(a,b) =", example.do_op(a, b, example.ADD)
|
||||
print " SUB(a,b) =", example.do_op(a, b, example.SUB)
|
||||
print " MUL(a,b) =", example.do_op(a, b, example.MUL)
|
||||
|
||||
print "Here is what the C callback function objects look like in Python"
|
||||
print " ADD =", example.ADD
|
||||
|
|
|
|||
|
|
@ -1,20 +1,22 @@
|
|||
TOP = ../..
|
||||
SWIG = $(TOP)/../preinst-swig
|
||||
SWIGEXE = $(TOP)/../swig
|
||||
SWIG_LIB_DIR = $(TOP)/../$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib
|
||||
SRCS = example.c
|
||||
TARGET = example
|
||||
INTERFACE = example.i
|
||||
|
||||
all::
|
||||
$(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \
|
||||
check: build
|
||||
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' python_run
|
||||
|
||||
build:
|
||||
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' \
|
||||
SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \
|
||||
TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' python
|
||||
|
||||
static::
|
||||
$(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \
|
||||
static:
|
||||
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' \
|
||||
SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \
|
||||
TARGET='mypython' INTERFACE='$(INTERFACE)' python_static
|
||||
|
||||
clean::
|
||||
$(MAKE) -f $(TOP)/Makefile python_clean
|
||||
rm -f $(TARGET).py
|
||||
|
||||
check: all
|
||||
$(MAKE) -f $(TOP)/Makefile python_run
|
||||
clean:
|
||||
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' TARGET='$(TARGET)' python_clean
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
# file: runme.py
|
||||
|
||||
import example
|
||||
import example
|
||||
|
||||
a = 37
|
||||
b = 42
|
||||
|
|
@ -10,9 +10,9 @@ b = 42
|
|||
print "Trying some C callback functions"
|
||||
print " a =", a
|
||||
print " b =", b
|
||||
print " ADD(a,b) =", example.do_op(a,b,example.ADD)
|
||||
print " SUB(a,b) =", example.do_op(a,b,example.SUB)
|
||||
print " MUL(a,b) =", example.do_op(a,b,example.MUL)
|
||||
print " ADD(a,b) =", example.do_op(a, b, example.ADD)
|
||||
print " SUB(a,b) =", example.do_op(a, b, example.SUB)
|
||||
print " MUL(a,b) =", example.do_op(a, b, example.MUL)
|
||||
|
||||
print "Here is what the C callback function objects look like in Python"
|
||||
print " ADD =", example.ADD
|
||||
|
|
@ -20,5 +20,5 @@ print " SUB =", example.SUB
|
|||
print " MUL =", example.MUL
|
||||
|
||||
print "Call the functions directly..."
|
||||
print " add(a,b) =", example.add(a,b)
|
||||
print " sub(a,b) =", example.sub(a,b)
|
||||
print " add(a,b) =", example.add(a, b)
|
||||
print " sub(a,b) =", example.sub(a, b)
|
||||
|
|
|
|||
|
|
@ -1,22 +1,24 @@
|
|||
TOP = ../..
|
||||
SWIG = $(TOP)/../preinst-swig
|
||||
CXXSRCS =
|
||||
SWIGEXE = $(TOP)/../swig
|
||||
SWIG_LIB_DIR = $(TOP)/../$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib
|
||||
CXXSRCS =
|
||||
TARGET = example
|
||||
INTERFACE = example.i
|
||||
LIBS = -lm
|
||||
SWIGOPT =
|
||||
SWIGOPT =
|
||||
|
||||
all::
|
||||
$(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \
|
||||
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 CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \
|
||||
static:
|
||||
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' \
|
||||
SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \
|
||||
TARGET='mypython' INTERFACE='$(INTERFACE)' python_cpp_static
|
||||
|
||||
clean::
|
||||
$(MAKE) -f $(TOP)/Makefile python_clean
|
||||
rm -f $(TARGET).py
|
||||
|
||||
check: all
|
||||
$(MAKE) -f $(TOP)/Makefile python_run
|
||||
clean:
|
||||
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' TARGET='$(TARGET)' python_clean
|
||||
|
|
|
|||
|
|
@ -8,10 +8,9 @@ b = example.doubleSum(100.0)
|
|||
# Use the objects. They should be callable just like a normal
|
||||
# python function.
|
||||
|
||||
for i in range(0,100):
|
||||
for i in range(0, 100):
|
||||
a(i) # Note: function call
|
||||
b(math.sqrt(i)) # Note: function call
|
||||
|
||||
print a.result()
|
||||
print b.result()
|
||||
|
||||
|
|
|
|||
|
|
@ -1,22 +1,27 @@
|
|||
TOP = ../..
|
||||
SWIG = $(TOP)/../preinst-swig
|
||||
SWIGEXE = $(TOP)/../swig
|
||||
SWIG_LIB_DIR = $(TOP)/../$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib
|
||||
SWIGOPT =
|
||||
LIBS =
|
||||
|
||||
all::
|
||||
$(MAKE) -f $(TOP)/Makefile SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \
|
||||
LIBS='$(LIBS)' TARGET='base' INTERFACE='base.i' python_cpp
|
||||
$(MAKE) -f $(TOP)/Makefile SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \
|
||||
LIBS='$(LIBS)' TARGET='foo' INTERFACE='foo.i' python_cpp
|
||||
$(MAKE) -f $(TOP)/Makefile SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \
|
||||
LIBS='$(LIBS)' TARGET='bar' INTERFACE='bar.i' python_cpp
|
||||
$(MAKE) -f $(TOP)/Makefile SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \
|
||||
LIBS='$(LIBS)' TARGET='spam' INTERFACE='spam.i' python_cpp
|
||||
check: build
|
||||
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' python_run
|
||||
|
||||
build:
|
||||
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' \
|
||||
SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \
|
||||
SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' TARGET='base' INTERFACE='base.i' python_cpp
|
||||
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' \
|
||||
SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \
|
||||
SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' TARGET='foo' INTERFACE='foo.i' python_cpp
|
||||
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' \
|
||||
SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \
|
||||
SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' TARGET='bar' INTERFACE='bar.i' python_cpp
|
||||
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' \
|
||||
SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \
|
||||
SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' TARGET='spam' INTERFACE='spam.i' python_cpp
|
||||
|
||||
|
||||
clean::
|
||||
$(MAKE) -f $(TOP)/Makefile python_clean
|
||||
@rm -f foo.py bar.py spam.py base.py
|
||||
|
||||
check: all
|
||||
$(MAKE) -f $(TOP)/Makefile python_run
|
||||
clean:
|
||||
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' TARGET='$(TARGET)' python_clean
|
||||
rm -f foo.py bar.py spam.py base.py
|
||||
|
|
|
|||
|
|
@ -43,7 +43,7 @@ RSC=rc.exe
|
|||
# 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 "BAR_EXPORTS" /YX /FD /GZ /c
|
||||
# ADD CPP /nologo /MTd /W3 /Gm /GR /GX /ZI /Od /I "$(PYTHON_INCLUDE)" /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "BAR_EXPORTS" /YX /FD /GZ /c
|
||||
# ADD CPP /nologo /MTd /W3 /Gm /GR /GX /ZI /Od /I "$(PYTHON_INCLUDE)" /D "SWIG_PYTHON_INTERPRETER_NO_DEBUG" /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "BAR_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"
|
||||
|
|
@ -118,7 +118,7 @@ InputName=bar
|
|||
echo PYTHON_INCLUDE: %PYTHON_INCLUDE%
|
||||
echo PYTHON_LIB: %PYTHON_LIB%
|
||||
echo on
|
||||
..\..\..\swig.exe -c++ -python $(InputPath)
|
||||
..\..\..\swig.exe -c++ -python "$(InputPath)"
|
||||
|
||||
# End Custom Build
|
||||
|
||||
|
|
@ -133,7 +133,7 @@ InputName=bar
|
|||
echo PYTHON_INCLUDE: %PYTHON_INCLUDE%
|
||||
echo PYTHON_LIB: %PYTHON_LIB%
|
||||
echo on
|
||||
..\..\..\swig.exe -c++ -python $(InputPath)
|
||||
..\..\..\swig.exe -c++ -python "$(InputPath)"
|
||||
|
||||
# End Custom Build
|
||||
|
||||
|
|
|
|||
|
|
@ -43,7 +43,7 @@ RSC=rc.exe
|
|||
# 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 "BASE_EXPORTS" /YX /FD /GZ /c
|
||||
# ADD CPP /nologo /MTd /W3 /Gm /GR /GX /ZI /Od /I "$(PYTHON_INCLUDE)" /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "BASE_EXPORTS" /YX /FD /GZ /c
|
||||
# ADD CPP /nologo /MTd /W3 /Gm /GR /GX /ZI /Od /I "$(PYTHON_INCLUDE)" /D "SWIG_PYTHON_INTERPRETER_NO_DEBUG" /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "BASE_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"
|
||||
|
|
@ -118,7 +118,7 @@ InputName=base
|
|||
echo PYTHON_INCLUDE: %PYTHON_INCLUDE%
|
||||
echo PYTHON_LIB: %PYTHON_LIB%
|
||||
echo on
|
||||
..\..\..\swig.exe -c++ -python $(InputPath)
|
||||
..\..\..\swig.exe -c++ -python "$(InputPath)"
|
||||
|
||||
# End Custom Build
|
||||
|
||||
|
|
@ -133,7 +133,7 @@ InputName=base
|
|||
echo PYTHON_INCLUDE: %PYTHON_INCLUDE%
|
||||
echo PYTHON_LIB: %PYTHON_LIB%
|
||||
echo on
|
||||
..\..\..\swig.exe -c++ -python $(InputPath)
|
||||
..\..\..\swig.exe -c++ -python "$(InputPath)"
|
||||
|
||||
# End Custom Build
|
||||
|
||||
|
|
|
|||
|
|
@ -2,8 +2,8 @@
|
|||
|
||||
class Base {
|
||||
public:
|
||||
Base() { };
|
||||
virtual ~Base() { };
|
||||
Base() { }
|
||||
virtual ~Base() { }
|
||||
virtual void A() {
|
||||
printf("I'm Base::A\n");
|
||||
}
|
||||
|
|
|
|||
|
|
@ -43,7 +43,7 @@ RSC=rc.exe
|
|||
# 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 "FOO_EXPORTS" /YX /FD /GZ /c
|
||||
# ADD CPP /nologo /MTd /W3 /Gm /GR /GX /ZI /Od /I "$(PYTHON_INCLUDE)" /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "FOO_EXPORTS" /YX /FD /GZ /c
|
||||
# ADD CPP /nologo /MTd /W3 /Gm /GR /GX /ZI /Od /I "$(PYTHON_INCLUDE)" /D "SWIG_PYTHON_INTERPRETER_NO_DEBUG" /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "FOO_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"
|
||||
|
|
@ -118,7 +118,7 @@ InputName=foo
|
|||
echo PYTHON_INCLUDE: %PYTHON_INCLUDE%
|
||||
echo PYTHON_LIB: %PYTHON_LIB%
|
||||
echo on
|
||||
..\..\..\swig.exe -c++ -python $(InputPath)
|
||||
..\..\..\swig.exe -c++ -python "$(InputPath)"
|
||||
|
||||
# End Custom Build
|
||||
|
||||
|
|
@ -133,7 +133,7 @@ InputName=foo
|
|||
echo PYTHON_INCLUDE: %PYTHON_INCLUDE%
|
||||
echo PYTHON_LIB: %PYTHON_LIB%
|
||||
echo on
|
||||
..\..\..\swig.exe -c++ -python $(InputPath)
|
||||
..\..\..\swig.exe -c++ -python "$(InputPath)"
|
||||
|
||||
# End Custom Build
|
||||
|
||||
|
|
|
|||
|
|
@ -81,31 +81,27 @@ x = d.toBase()
|
|||
print " Spam -> Base -> Foo : ",
|
||||
y = foo.Foo_fromBase(x)
|
||||
if y:
|
||||
print "bad swig"
|
||||
print "bad swig"
|
||||
else:
|
||||
print "good swig"
|
||||
print "good swig"
|
||||
|
||||
print " Spam -> Base -> Bar : ",
|
||||
y = bar.Bar_fromBase(x)
|
||||
if y:
|
||||
print "good swig"
|
||||
print "good swig"
|
||||
else:
|
||||
print "bad swig"
|
||||
|
||||
print "bad swig"
|
||||
|
||||
print " Spam -> Base -> Spam : ",
|
||||
y = spam.Spam_fromBase(x)
|
||||
if y:
|
||||
print "good swig"
|
||||
print "good swig"
|
||||
else:
|
||||
print "bad swig"
|
||||
print "bad swig"
|
||||
|
||||
print " Foo -> Spam : ",
|
||||
y = spam.Spam_fromBase(b)
|
||||
if y:
|
||||
print "bad swig"
|
||||
print "bad swig"
|
||||
else:
|
||||
print "good swig"
|
||||
|
||||
|
||||
|
||||
|
||||
print "good swig"
|
||||
|
|
|
|||
|
|
@ -43,7 +43,7 @@ RSC=rc.exe
|
|||
# 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 "SPAM_EXPORTS" /YX /FD /GZ /c
|
||||
# ADD CPP /nologo /MTd /W3 /Gm /GR /GX /ZI /Od /I "$(PYTHON_INCLUDE)" /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "SPAM_EXPORTS" /YX /FD /GZ /c
|
||||
# ADD CPP /nologo /MTd /W3 /Gm /GR /GX /ZI /Od /I "$(PYTHON_INCLUDE)" /D "SWIG_PYTHON_INTERPRETER_NO_DEBUG" /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "SPAM_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"
|
||||
|
|
@ -118,7 +118,7 @@ InputName=spam
|
|||
echo PYTHON_INCLUDE: %PYTHON_INCLUDE%
|
||||
echo PYTHON_LIB: %PYTHON_LIB%
|
||||
echo on
|
||||
..\..\..\swig.exe -c++ -python $(InputPath)
|
||||
..\..\..\swig.exe -c++ -python "$(InputPath)"
|
||||
|
||||
# End Custom Build
|
||||
|
||||
|
|
@ -133,7 +133,7 @@ InputName=spam
|
|||
echo PYTHON_INCLUDE: %PYTHON_INCLUDE%
|
||||
echo PYTHON_LIB: %PYTHON_LIB%
|
||||
echo on
|
||||
..\..\..\swig.exe -c++ -python $(InputPath)
|
||||
..\..\..\swig.exe -c++ -python "$(InputPath)"
|
||||
|
||||
# End Custom Build
|
||||
|
||||
|
|
|
|||
44
Examples/python/import_packages/Makefile
Normal file
44
Examples/python/import_packages/Makefile
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
TOP = ../..
|
||||
SWIGOPT =
|
||||
LIBS =
|
||||
|
||||
import_packages_subdirs = \
|
||||
same_modnames1 \
|
||||
same_modnames2 \
|
||||
from_init1 \
|
||||
from_init2 \
|
||||
from_init3 \
|
||||
relativeimport1 \
|
||||
relativeimport2 \
|
||||
relativeimport3
|
||||
|
||||
check: build
|
||||
if test "x$(SRCDIR)" != x; then \
|
||||
for file in `cd $(SRCDIR) && find . -type f -name __init__.py`; do \
|
||||
cp "${SRCDIR}$$file" "$$file" || exit 1; \
|
||||
done; \
|
||||
fi; \
|
||||
for s in $(import_packages_subdirs); do \
|
||||
(cd $$s && $(MAKE) check); \
|
||||
done
|
||||
|
||||
build:
|
||||
for s in $(import_packages_subdirs); do \
|
||||
(cd $$s && $(MAKE) SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' build); \
|
||||
done
|
||||
|
||||
static:
|
||||
for s in $(import_packages_subdirs); do \
|
||||
(cd $$s && $(MAKE) SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' static); \
|
||||
done
|
||||
|
||||
clean:
|
||||
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' python_clean
|
||||
if test "x$(SRCDIR)" != x; then \
|
||||
for file in `cd $(SRCDIR) && find . -type f -name __init__.py`; do \
|
||||
rm -f "$$file" || exit 1; \
|
||||
done; \
|
||||
fi; \
|
||||
for s in $(import_packages_subdirs); do \
|
||||
(cd $$s && $(MAKE) clean); \
|
||||
done
|
||||
2
Examples/python/import_packages/README
Normal file
2
Examples/python/import_packages/README
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
These are actually regression tests for SF bug #1297 (GH issue #7).
|
||||
See individual READMEs in subdirectories.
|
||||
22
Examples/python/import_packages/from_init1/Makefile
Normal file
22
Examples/python/import_packages/from_init1/Makefile
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
TOP = ../../..
|
||||
LIBS =
|
||||
|
||||
ifeq (,$(PY3))
|
||||
PKG1DIR = "py2"
|
||||
else
|
||||
PKG1DIR = "py3"
|
||||
endif
|
||||
|
||||
check: build
|
||||
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' python_run
|
||||
|
||||
build:
|
||||
cd $(PKG1DIR) && $(MAKE) SWIGOPT='$(SWIGOPT) -relativeimport' LIBS='$(LIBS)' build
|
||||
|
||||
static:
|
||||
cd $(PKG1DIR) && $(MAKE) SWIGOPT='$(SWIGOPT) -relativeimport' LIBS='$(LIBS)' static
|
||||
|
||||
clean:
|
||||
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' python_clean
|
||||
cd py2 && $(MAKE) clean
|
||||
cd py3 && $(MAKE) clean
|
||||
63
Examples/python/import_packages/from_init1/README
Normal file
63
Examples/python/import_packages/from_init1/README
Normal file
|
|
@ -0,0 +1,63 @@
|
|||
This example tests the %import directive and python import from __init__.py.
|
||||
|
||||
This case is not correctly handled by swig 2.
|
||||
|
||||
The issue was reported as Source Forge bug #1297 and later as GitHub issue #7.
|
||||
|
||||
Use 'python runme.py' to run a test.
|
||||
|
||||
|
||||
Overview:
|
||||
---------
|
||||
|
||||
The example defines 2 different extension modules--each wrapping a separate C++
|
||||
class.
|
||||
|
||||
pyX/pkg2/foo.i - Pkg2_Foo class
|
||||
pyX/pkg2/bar.i - Pkg2_Bar class derived from Pkg2_Foo
|
||||
|
||||
and the package pyX.pkg2 has:
|
||||
|
||||
pyX/pkg2/__init__.py - which imports something from "bar" module (we
|
||||
import Pkg2_Bar class, but it is not the clue,
|
||||
the clue is the 'from' keyword)
|
||||
|
||||
For example with python2.x the py2/pkg2/__init__.py imports Pkg2_Bar class
|
||||
as follows
|
||||
|
||||
from bar import Pkg2_Bar # [1]
|
||||
|
||||
Such cases doesn't work when fully qualified python module names are used by
|
||||
swig (swig 2.0.10, e.g.) to generate python import directives (SF bug #1297).
|
||||
The generated file "py2/pkg2/bar.py" has following lines:
|
||||
|
||||
import py2.pkg2.foo # [2]
|
||||
class Pkg2_Bar(py2.pkg2.foo.Pkg2_Foo): # [3]
|
||||
|
||||
but it's not possible to import anything from py2.pkg2 subpackage, e.g.
|
||||
|
||||
import py2.pkg2
|
||||
|
||||
fails with the following exception:
|
||||
|
||||
Traceback (most recent call last):
|
||||
File "runme.py", line 3, in <module>
|
||||
import py2.pkg2
|
||||
File "py2/pkg2/__init__.py", line 7, in <module>
|
||||
from .bar import Pkg2_Bar
|
||||
File "py2/pkg2/bar.py", line 71, in <module>
|
||||
class Pkg2_Bar(py2.pkg2.foo.Pkg2_Foo):
|
||||
AttributeError: 'module' object has no attribute 'pkg2'
|
||||
|
||||
|
||||
It seems like during the import [1], the sub-package pkg2 is not yet fully
|
||||
initialized, so py2.pkg2 is not known. The above exception is raised at
|
||||
line [3]. The problem disappears, for example, if we force swig to use relative
|
||||
package names.
|
||||
|
||||
If everything works well, the package py2.pkg2 shall load properly.
|
||||
|
||||
Unix:
|
||||
-----
|
||||
- Run make
|
||||
- Run the test as described above
|
||||
13
Examples/python/import_packages/from_init1/py2/Makefile
Normal file
13
Examples/python/import_packages/from_init1/py2/Makefile
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
TOP = ../../../..
|
||||
SWIGOPT =
|
||||
LIBS =
|
||||
|
||||
build:
|
||||
cd pkg2 && $(MAKE) SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' build
|
||||
|
||||
static:
|
||||
cd pkg2 && $(MAKE) SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' static
|
||||
|
||||
clean:
|
||||
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' python_clean
|
||||
cd pkg2 && $(MAKE) clean
|
||||
25
Examples/python/import_packages/from_init1/py2/pkg2/Makefile
Normal file
25
Examples/python/import_packages/from_init1/py2/pkg2/Makefile
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
TOP = ../../../../..
|
||||
SWIGEXE = $(TOP)/../swig
|
||||
SWIG_LIB_DIR = $(TOP)/../$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib
|
||||
SWIGOPT =
|
||||
LIBS =
|
||||
|
||||
build:
|
||||
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' \
|
||||
SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \
|
||||
SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' TARGET='foo' INTERFACE='foo.i' python_cpp
|
||||
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' \
|
||||
SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \
|
||||
SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' TARGET='bar' INTERFACE='bar.i' python_cpp
|
||||
|
||||
static:
|
||||
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' \
|
||||
SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \
|
||||
SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' TARGET='foo' INTERFACE='foo.i' python_cpp_static
|
||||
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' \
|
||||
SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \
|
||||
SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' TARGET='bar' INTERFACE='bar.i' python_cpp_static
|
||||
|
||||
clean::
|
||||
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' TARGET='foo' python_clean
|
||||
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' TARGET='bar' python_clean
|
||||
|
|
@ -0,0 +1 @@
|
|||
from bar import Pkg2_Bar
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
#ifndef PY2_PKG2_BAR_HPP
|
||||
#define PY2_PKG2_BAR_HPP
|
||||
#include "../../py2/pkg2/foo.hpp"
|
||||
struct Pkg2_Bar : Pkg2_Foo {};
|
||||
#endif /* PY2_PKG2_BAR_HPP */
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
%module(package="py2.pkg2") bar
|
||||
%{
|
||||
#include "../../py2/pkg2/bar.hpp"
|
||||
%}
|
||||
%import "../../py2/pkg2/foo.i"
|
||||
%include "../../py2/pkg2/bar.hpp"
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
#ifndef PY2_PKG2_FOO_HPP
|
||||
#define PY2_PKG2_FOO_HPP
|
||||
struct Pkg2_Foo {};
|
||||
#endif /* PY2_PKG2_FOO_HPP */
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
%module(package="py2.pkg2") foo
|
||||
%{
|
||||
#include "../../py2/pkg2/foo.hpp"
|
||||
%}
|
||||
%include "../../py2/pkg2/foo.hpp"
|
||||
13
Examples/python/import_packages/from_init1/py3/Makefile
Normal file
13
Examples/python/import_packages/from_init1/py3/Makefile
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
TOP = ../../../..
|
||||
SWIGOPT =
|
||||
LIBS =
|
||||
|
||||
build:
|
||||
cd pkg2 && $(MAKE) SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' build
|
||||
|
||||
static:
|
||||
cd pkg2 && $(MAKE) SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' static
|
||||
|
||||
clean:
|
||||
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' python_clean
|
||||
cd pkg2 && $(MAKE) clean
|
||||
25
Examples/python/import_packages/from_init1/py3/pkg2/Makefile
Normal file
25
Examples/python/import_packages/from_init1/py3/pkg2/Makefile
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
TOP = ../../../../..
|
||||
SWIGEXE = $(TOP)/../swig
|
||||
SWIG_LIB_DIR = $(TOP)/../$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib
|
||||
SWIGOPT =
|
||||
LIBS =
|
||||
|
||||
build:
|
||||
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' \
|
||||
SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \
|
||||
SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' TARGET='foo' INTERFACE='foo.i' python_cpp
|
||||
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' \
|
||||
SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \
|
||||
SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' TARGET='bar' INTERFACE='bar.i' python_cpp
|
||||
|
||||
static:
|
||||
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' \
|
||||
SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \
|
||||
SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' TARGET='foo' INTERFACE='foo.i' python_cpp_static
|
||||
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' \
|
||||
SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \
|
||||
SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' TARGET='bar' INTERFACE='bar.i' python_cpp_static
|
||||
|
||||
clean::
|
||||
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' TARGET='foo' python_clean
|
||||
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' TARGET='bar' python_clean
|
||||
|
|
@ -0,0 +1 @@
|
|||
from .bar import Pkg2_Bar
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
#ifndef PY3_PKG2_BAR_HPP
|
||||
#define PY3_PKG2_BAR_HPP
|
||||
#include "../../py3/pkg2/foo.hpp"
|
||||
struct Pkg2_Bar : Pkg2_Foo {};
|
||||
#endif /* PY3_PKG2_BAR_HPP */
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
%module(package="py3.pkg2") bar
|
||||
%{
|
||||
#include "../../py3/pkg2/bar.hpp"
|
||||
%}
|
||||
%import "../../py3/pkg2/foo.i"
|
||||
%include "../../py3/pkg2/bar.hpp"
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
#ifndef PY3_PKG2_FOO_HPP
|
||||
#define PY3_PKG2_FOO_HPP
|
||||
struct Pkg2_Foo {};
|
||||
#endif /* PY3_PKG2_FOO_HPP */
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
%module(package="py3.pkg2") foo
|
||||
%{
|
||||
#include "../../py3/pkg2/foo.hpp"
|
||||
%}
|
||||
%include "../../py3/pkg2/foo.hpp"
|
||||
13
Examples/python/import_packages/from_init1/runme.py
Normal file
13
Examples/python/import_packages/from_init1/runme.py
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
import sys
|
||||
import os.path
|
||||
|
||||
# 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 < (3, 0):
|
||||
import py2.pkg2
|
||||
print " Finished importing py2.pkg2"
|
||||
else:
|
||||
import py3.pkg2
|
||||
print " Finished importing py3.pkg2"
|
||||
22
Examples/python/import_packages/from_init2/Makefile
Normal file
22
Examples/python/import_packages/from_init2/Makefile
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
TOP = ../../..
|
||||
LIBS =
|
||||
|
||||
ifeq (,$(PY3))
|
||||
PKG1DIR = "py2"
|
||||
else
|
||||
PKG1DIR = "py3"
|
||||
endif
|
||||
|
||||
check: build
|
||||
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' python_run
|
||||
|
||||
build:
|
||||
cd $(PKG1DIR) && $(MAKE) SWIGOPT='$(SWIGOPT) -relativeimport' LIBS='$(LIBS)' build
|
||||
|
||||
static:
|
||||
cd $(PKG1DIR) && $(MAKE) SWIGOPT='$(SWIGOPT) -relativeimport' LIBS='$(LIBS)' static
|
||||
|
||||
clean:
|
||||
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' python_clean
|
||||
cd py2 && $(MAKE) clean
|
||||
cd py3 && $(MAKE) clean
|
||||
81
Examples/python/import_packages/from_init2/README
Normal file
81
Examples/python/import_packages/from_init2/README
Normal file
|
|
@ -0,0 +1,81 @@
|
|||
This example tests the %import directive and python import from __init__.py.
|
||||
|
||||
This case is not correctly handled by swig 2.
|
||||
|
||||
The issue was reported as Source Forge bug #1297 and later as GitHub issue #7.
|
||||
|
||||
Use 'python runme.py' to run a test.
|
||||
|
||||
Overview:
|
||||
---------
|
||||
|
||||
The example defines 2 different extension modules--each wrapping a separate C++
|
||||
class.
|
||||
|
||||
pyX/pkg2/pkg3/foo.i - Pkg3_Foo class
|
||||
pyX/pkg2/bar.i - Pkg2_Bar class derived from Pkg3_Foo
|
||||
|
||||
and the package pyX.pkg2 has:
|
||||
|
||||
pyX/pkg2/__init__.py - which imports something from "bar" module
|
||||
|
||||
For example with python 2.x the py2/pkg2/__init__.py imports Pkg2_Bar class as
|
||||
follows
|
||||
|
||||
from bar import Pkg2_Bar # [1]
|
||||
|
||||
Such cases doesn't work when fully qualified python module names are used by
|
||||
swig to generate python import directives (SF bug #1297). The generated file
|
||||
"py2/pkg2/bar.py" has following lines:
|
||||
|
||||
import py2.pkg2.pkg3.foo # [2]
|
||||
class Pkg2_Bar(py2.pkg2.pkg3.foo.Pkg3_Foo): # [3]
|
||||
|
||||
and it's not possible to import anything from py2.pkg2 subpackage, e.g.
|
||||
|
||||
import py2.pkg2
|
||||
|
||||
fails with the following exception:
|
||||
|
||||
Traceback (most recent call last):
|
||||
File "runme.py", line 3, in <module>
|
||||
import py2.pkg2
|
||||
File "py2/pkg2/__init__.py", line 4, in <module>
|
||||
from bar import Pkg2_Bar
|
||||
File "py2/pkg2/bar.py", line 71, in <module>
|
||||
class Pkg2_Bar(py2.pkg2.pkg3.foo.Pkg3_Foo):
|
||||
AttributeError: 'module' object has no attribute 'pkg2'
|
||||
|
||||
It seems like during the import [1], the subpackage pkg2 is not yet fully
|
||||
initialized, so pyX.pkg2 is not known. The above exception is raised at line [3].
|
||||
The problem disappears, for example, if we force swig to use relative package
|
||||
names.
|
||||
|
||||
The difference between this ('from_init2') case and the case
|
||||
'from_init1' is that here it's not sufficient to import relative module
|
||||
by just ignoring the package part of the fully qualified module name. IOW
|
||||
it is not correct to force swig to put:
|
||||
|
||||
import foo
|
||||
class Pkg2_Bar(foo.Pkg3_Foo)
|
||||
|
||||
into pyX/pkg2/bar.py (note, that this would work for 'from_init1' case).
|
||||
The import directive shall be rather:
|
||||
|
||||
import pkg3.foo
|
||||
|
||||
for python 2.x and:
|
||||
|
||||
from . import pkg3
|
||||
import pkg3.foo
|
||||
|
||||
for python 3, and the class definition shall begin with:
|
||||
|
||||
class Pkg2_Bar(pkg3.foo.Pkg3_Foo)
|
||||
|
||||
If everything works well, the package pyX.pkg2 shall load properly.
|
||||
|
||||
Unix:
|
||||
-----
|
||||
- Run make
|
||||
- Run the test as described above
|
||||
13
Examples/python/import_packages/from_init2/py2/Makefile
Normal file
13
Examples/python/import_packages/from_init2/py2/Makefile
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
TOP = ../../../..
|
||||
SWIGOPT =
|
||||
LIBS =
|
||||
|
||||
build:
|
||||
cd pkg2 && $(MAKE) SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' build
|
||||
|
||||
static:
|
||||
cd pkg2 && $(MAKE) SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' static
|
||||
|
||||
clean:
|
||||
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' python_clean
|
||||
cd pkg2 && $(MAKE) clean
|
||||
21
Examples/python/import_packages/from_init2/py2/pkg2/Makefile
Normal file
21
Examples/python/import_packages/from_init2/py2/pkg2/Makefile
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
TOP = ../../../../..
|
||||
SWIGEXE = $(TOP)/../swig
|
||||
SWIG_LIB_DIR = $(TOP)/../$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib
|
||||
SWIGOPT =
|
||||
LIBS =
|
||||
|
||||
build:
|
||||
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' \
|
||||
SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \
|
||||
SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' TARGET='bar' INTERFACE='bar.i' python_cpp
|
||||
cd pkg3 && $(MAKE) SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' build
|
||||
|
||||
static:
|
||||
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' \
|
||||
SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \
|
||||
SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' TARGET='bar' INTERFACE='bar.i' python_cpp
|
||||
cd pkg3 && $(MAKE) SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' static
|
||||
|
||||
clean:
|
||||
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' TARGET='bar' python_clean
|
||||
cd pkg3 && $(MAKE) clean
|
||||
|
|
@ -0,0 +1 @@
|
|||
from bar import Pkg2_Bar
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
#ifndef PY2_PKG2_BAR_HPP
|
||||
#define PY2_PKG2_BAR_HPP
|
||||
#include "../../py2/pkg2/pkg3/foo.hpp"
|
||||
struct Pkg2_Bar : Pkg3_Foo {};
|
||||
#endif /* PY2_PKG2_BAR_HPP */
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
%module(package="py2.pkg2") bar
|
||||
%{
|
||||
#include "../../py2/pkg2/bar.hpp"
|
||||
%}
|
||||
%import "../../py2/pkg2/pkg3/foo.i"
|
||||
%include "../../py2/pkg2/bar.hpp"
|
||||
|
|
@ -0,0 +1,18 @@
|
|||
TOP = ../../../../../..
|
||||
SWIGEXE = $(TOP)/../swig
|
||||
SWIG_LIB_DIR = $(TOP)/../$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib
|
||||
SWIGOPT =
|
||||
LIBS =
|
||||
|
||||
build:
|
||||
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' \
|
||||
SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \
|
||||
SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' TARGET='foo' INTERFACE='foo.i' python_cpp
|
||||
|
||||
static:
|
||||
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' \
|
||||
SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \
|
||||
SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' TARGET='foo' INTERFACE='foo.i' python_cpp_static
|
||||
|
||||
clean:
|
||||
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' TARGET='foo' python_clean
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
#ifndef PY2_PKG2_PKG3_FOO_HPP
|
||||
#define PY2_PKG2_PKG3_FOO_HPP
|
||||
struct Pkg3_Foo {};
|
||||
#endif /* PY2_PKG2_PKG3_FOO_HPP */
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
%module(package="py2.pkg2.pkg3") foo
|
||||
%{
|
||||
#include "../../../py2/pkg2/pkg3/foo.hpp"
|
||||
%}
|
||||
%include "../../../py2/pkg2/pkg3/foo.hpp"
|
||||
13
Examples/python/import_packages/from_init2/py3/Makefile
Normal file
13
Examples/python/import_packages/from_init2/py3/Makefile
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
TOP = ../../../..
|
||||
SWIGOPT =
|
||||
LIBS =
|
||||
|
||||
build:
|
||||
cd pkg2 && $(MAKE) SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' build
|
||||
|
||||
static:
|
||||
cd pkg2 && $(MAKE) SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' static
|
||||
|
||||
clean:
|
||||
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' python_clean
|
||||
cd pkg2 && $(MAKE) clean
|
||||
21
Examples/python/import_packages/from_init2/py3/pkg2/Makefile
Normal file
21
Examples/python/import_packages/from_init2/py3/pkg2/Makefile
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
TOP = ../../../../..
|
||||
SWIGEXE = $(TOP)/../swig
|
||||
SWIG_LIB_DIR = $(TOP)/../$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib
|
||||
SWIGOPT =
|
||||
LIBS =
|
||||
|
||||
build:
|
||||
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' \
|
||||
SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \
|
||||
SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' TARGET='bar' INTERFACE='bar.i' python_cpp
|
||||
cd pkg3 && $(MAKE) SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' build
|
||||
|
||||
static:
|
||||
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' \
|
||||
SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \
|
||||
SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' TARGET='bar' INTERFACE='bar.i' python_cpp
|
||||
cd pkg3 && $(MAKE) SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' static
|
||||
|
||||
clean:
|
||||
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' TARGET='bar' python_clean
|
||||
cd pkg3 && $(MAKE) clean
|
||||
|
|
@ -0,0 +1 @@
|
|||
from .bar import Pkg2_Bar
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
#ifndef PY3_PKG2_BAR_HPP
|
||||
#define PY3_PKG2_BAR_HPP
|
||||
#include "../../py3/pkg2/pkg3/foo.hpp"
|
||||
struct Pkg2_Bar : Pkg3_Foo {};
|
||||
#endif /* PY3_PKG2_BAR_HPP */
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
%module(package="py3.pkg2") bar
|
||||
%{
|
||||
#include "../../py3/pkg2/bar.hpp"
|
||||
%}
|
||||
%import "../../py3/pkg2/pkg3/foo.i"
|
||||
%include "../../py3/pkg2/bar.hpp"
|
||||
|
|
@ -0,0 +1,18 @@
|
|||
TOP = ../../../../../..
|
||||
SWIGEXE = $(TOP)/../swig
|
||||
SWIG_LIB_DIR = $(TOP)/../$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib
|
||||
SWIGOPT =
|
||||
LIBS =
|
||||
|
||||
build:
|
||||
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' \
|
||||
SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \
|
||||
SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' TARGET='foo' INTERFACE='foo.i' python_cpp
|
||||
|
||||
static:
|
||||
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' \
|
||||
SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \
|
||||
SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' TARGET='foo' INTERFACE='foo.i' python_cpp_static
|
||||
|
||||
clean:
|
||||
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' TARGET='foo' python_clean
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
#ifndef PY3_PKG2_PKG3_FOO_HPP
|
||||
#define PY3_PKG2_PKG3_FOO_HPP
|
||||
struct Pkg3_Foo {};
|
||||
#endif /* PY3_PKG2_PKG3_FOO_HPP */
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
%module(package="py3.pkg2.pkg3") foo
|
||||
%{
|
||||
#include "../../../py3/pkg2/pkg3/foo.hpp"
|
||||
%}
|
||||
%include "../../../py3/pkg2/pkg3/foo.hpp"
|
||||
13
Examples/python/import_packages/from_init2/runme.py
Normal file
13
Examples/python/import_packages/from_init2/runme.py
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
import sys
|
||||
import os.path
|
||||
|
||||
# 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 < (3, 0):
|
||||
import py2.pkg2
|
||||
print " Finished importing py2.pkg2"
|
||||
else:
|
||||
import py3.pkg2
|
||||
print " Finished importing py3.pkg2"
|
||||
22
Examples/python/import_packages/from_init3/Makefile
Normal file
22
Examples/python/import_packages/from_init3/Makefile
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
TOP = ../../..
|
||||
LIBS =
|
||||
|
||||
ifeq (,$(PY3))
|
||||
PKG1DIR = "py2"
|
||||
else
|
||||
PKG1DIR = "py3"
|
||||
endif
|
||||
|
||||
check: build
|
||||
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' python_run
|
||||
|
||||
build:
|
||||
cd $(PKG1DIR) && $(MAKE) SWIGOPT='$(SWIGOPT) -relativeimport' LIBS='$(LIBS)' build
|
||||
|
||||
static:
|
||||
cd $(PKG1DIR) && $(MAKE) SWIGOPT='$(SWIGOPT) -relativeimport' LIBS='$(LIBS)' static
|
||||
|
||||
clean:
|
||||
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' python_clean
|
||||
cd py2 && $(MAKE) clean
|
||||
cd py3 && $(MAKE) clean
|
||||
67
Examples/python/import_packages/from_init3/README
Normal file
67
Examples/python/import_packages/from_init3/README
Normal file
|
|
@ -0,0 +1,67 @@
|
|||
This example tests the %import directive and python import from __init__.py.
|
||||
|
||||
This case is not correctly handled by swig 2.
|
||||
|
||||
The issue was reported as Source Forge bug #1297 and later as GitHub issue #7.
|
||||
|
||||
Use 'python runme.py' to run a test.
|
||||
|
||||
Overview:
|
||||
---------
|
||||
|
||||
The example defines 2 different extension modules--each wrapping a separate C++
|
||||
class.
|
||||
|
||||
pyX/pkg2/pkg3/pkg4/foo.i - Pkg4_Foo class
|
||||
pyX/pkg2/bar.i - Pkg2_Bar class derived from Pkg4_Foo
|
||||
|
||||
and the package pyX.pkg2 has:
|
||||
|
||||
pyX/pkg2/__init__.py - which imports something from "bar" module
|
||||
|
||||
For example with python 2.x the py2/pkg2/__init__.py imports Pkg2_Bar class as
|
||||
follows
|
||||
|
||||
from bar import Pkg2_Bar # [1]
|
||||
|
||||
Such cases doesn't work when fully qualified python module names are used by
|
||||
swig to generate python import directives (SF bug 1297). The generated file
|
||||
"py2/pkg2/bar.py" has following lines:
|
||||
|
||||
import py2.pkg2.pkg3.pkg4.foo # [2]
|
||||
class Pkg2_Bar(py2.pkg2.pkg3.pkg4.foo.P1_S1_S2_Foo): # [3]
|
||||
|
||||
and it's not possible to import anything from py2.pkg2 subpackage, e.g.
|
||||
|
||||
import py2.pkg2
|
||||
|
||||
fails with the following exception:
|
||||
|
||||
Traceback (most recent call last):
|
||||
File "runme.py", line 3, in <module>
|
||||
import py2.pkg2
|
||||
File "py2/pkg2/__init__.py", line 4, in <module>
|
||||
from bar import Pkg2_Bar
|
||||
File "py2/pkg2/bar.py", line 71, in <module>
|
||||
class Pkg2_Bar(py2.pkg2.pkg3.pkg4.foo.Pkg4_Foo):
|
||||
AttributeError: 'module' object has no attribute 'pkg2'
|
||||
|
||||
It seems like during the import [1], the subpackage pkg2 is not yet fully
|
||||
initialized, so py2.pkg2 can't be used. The above exception is raised at
|
||||
line [3]. The problem disappears, for example, if we force swig to use relative
|
||||
package names.
|
||||
|
||||
The difference between this ('from_init3') case and the case
|
||||
'from_init2' is that here we import base class from module
|
||||
pyX.pkg2.pkg3.pkg4.foo, which is nested deeper than it was in
|
||||
'from_init2'. This is just to ensure, that two (and more) levels of
|
||||
subpackages get imported correctly by generated python code, i.e, not only
|
||||
'pkg3.foo' is handled properly (one-level subpackage) but the code works also
|
||||
for 'pkg3.pkg4.foo', and so on.
|
||||
|
||||
If everything works well, the package pyX.pkg2 shall load properly.
|
||||
|
||||
Unix:
|
||||
-----
|
||||
- Run make
|
||||
- Run the test as described above
|
||||
13
Examples/python/import_packages/from_init3/py2/Makefile
Normal file
13
Examples/python/import_packages/from_init3/py2/Makefile
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
TOP = ../../../..
|
||||
SWIGOPT =
|
||||
LIBS =
|
||||
|
||||
build:
|
||||
cd pkg2 && $(MAKE) SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' build
|
||||
|
||||
static:
|
||||
cd pkg2 && $(MAKE) SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' static
|
||||
|
||||
clean:
|
||||
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' python_clean
|
||||
cd pkg2 && $(MAKE) clean
|
||||
21
Examples/python/import_packages/from_init3/py2/pkg2/Makefile
Normal file
21
Examples/python/import_packages/from_init3/py2/pkg2/Makefile
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
TOP = ../../../../..
|
||||
SWIGEXE = $(TOP)/../swig
|
||||
SWIG_LIB_DIR = $(TOP)/../$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib
|
||||
SWIGOPT =
|
||||
LIBS =
|
||||
|
||||
build:
|
||||
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' \
|
||||
SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \
|
||||
SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' TARGET='bar' INTERFACE='bar.i' python_cpp
|
||||
cd pkg3 && $(MAKE) SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' build
|
||||
|
||||
static:
|
||||
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' \
|
||||
SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \
|
||||
SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' TARGET='bar' INTERFACE='bar.i' python_cpp
|
||||
cd pkg3 && $(MAKE) SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' static
|
||||
|
||||
clean:
|
||||
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' TARGET='bar' python_clean
|
||||
cd pkg3 && $(MAKE) clean
|
||||
|
|
@ -0,0 +1 @@
|
|||
from bar import Pkg2_Bar
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
#ifndef PY2_PKG2_HPP
|
||||
#define PY2_PKG2_HPP
|
||||
#include "../../py2/pkg2/pkg3/pkg4/foo.hpp"
|
||||
struct Pkg2_Bar : Pkg4_Foo {};
|
||||
#endif /* PY2_PKG2_HPP */
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
%module(package="py2.pkg2") bar
|
||||
%{
|
||||
#include "../../py2/pkg2/bar.hpp"
|
||||
%}
|
||||
%import "../../py2/pkg2/pkg3/pkg4/foo.i"
|
||||
%include "../../py2/pkg2/bar.hpp"
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
TOP = ../../../../../..
|
||||
SWIGOPT =
|
||||
LIBS =
|
||||
|
||||
build:
|
||||
cd pkg4 && $(MAKE) SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' build
|
||||
|
||||
static:
|
||||
cd pkg4 && $(MAKE) SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' static
|
||||
|
||||
clean:
|
||||
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' python_clean
|
||||
cd pkg4 && $(MAKE) clean
|
||||
|
|
@ -0,0 +1,18 @@
|
|||
TOP = ../../../../../../..
|
||||
SWIGEXE = $(TOP)/../swig
|
||||
SWIG_LIB_DIR = $(TOP)/../$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib
|
||||
SWIGOPT =
|
||||
LIBS =
|
||||
|
||||
build:
|
||||
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' \
|
||||
SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \
|
||||
SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' TARGET='foo' INTERFACE='foo.i' python_cpp
|
||||
|
||||
static:
|
||||
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' \
|
||||
SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \
|
||||
SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' TARGET='foo' INTERFACE='foo.i' python_cpp_static
|
||||
|
||||
clean:
|
||||
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' TARGET='foo' python_clean
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
#ifndef PY2_PKG2_PKG3_PKG4
|
||||
#define PY2_PKG2_PKG3_PKG4
|
||||
struct Pkg4_Foo {};
|
||||
#endif /* PY2_PKG2_PKG3_PKG4 */
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
%module(package="py2.pkg2.pkg3.pkg4") foo
|
||||
%{
|
||||
#include "../../../../py2/pkg2/pkg3/pkg4/foo.hpp"
|
||||
%}
|
||||
%include "../../../../py2/pkg2/pkg3/pkg4/foo.hpp"
|
||||
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Add a link
Reference in a new issue