Merge branch 'master' into C
This commit is contained in:
commit
f919896306
209 changed files with 3791 additions and 2243 deletions
|
|
@ -327,11 +327,11 @@ else
|
|||
endif
|
||||
PYTHON_SO = @PYTHON_SO@
|
||||
|
||||
# SWIG option for Python
|
||||
# SWIG option for Python3
|
||||
ifeq (,$(PY3))
|
||||
SWIGPYTHON = $(SWIG) -python
|
||||
SWIGOPTPY3 =
|
||||
else
|
||||
SWIGPYTHON = $(SWIG) -python -py3
|
||||
SWIGOPTPY3 = -py3
|
||||
endif
|
||||
|
||||
PEP8 = @PEP8@
|
||||
|
|
@ -342,7 +342,7 @@ PEP8_FLAGS = --ignore=E402,E501,E30,W291,W391
|
|||
# ----------------------------------------------------------------
|
||||
|
||||
python: $(SRCDIR_SRCS)
|
||||
$(SWIGPYTHON) $(SWIGOPT) -o $(ISRCS) $(INTERFACEPATH)
|
||||
$(SWIG) -python $(SWIGOPTPY3) $(SWIGOPT) -o $(ISRCS) $(INTERFACEPATH)
|
||||
$(CC) -c $(CCSHARED) $(CPPFLAGS) $(CFLAGS) $(ISRCS) $(SRCDIR_SRCS) $(INCLUDES) $(PYTHON_INCLUDE)
|
||||
$(LDSHARED) $(CFLAGS) $(LDFLAGS) $(OBJS) $(IOBJS) $(PYTHON_DLNK) $(LIBS) -o $(LIBPREFIX)_$(TARGET)$(PYTHON_SO)
|
||||
|
||||
|
|
@ -351,7 +351,7 @@ python: $(SRCDIR_SRCS)
|
|||
# -----------------------------------------------------------------
|
||||
|
||||
python_cpp: $(SRCDIR_SRCS)
|
||||
$(SWIGPYTHON) -c++ $(SWIGOPT) -o $(ICXXSRCS) $(INTERFACEPATH)
|
||||
$(SWIG) -python $(SWIGOPTPY3) -c++ $(SWIGOPT) -o $(ICXXSRCS) $(INTERFACEPATH)
|
||||
$(CXX) -c $(CCSHARED) $(CPPFLAGS) $(CXXFLAGS) $(ICXXSRCS) $(SRCDIR_SRCS) $(SRCDIR_CXXSRCS) $(INCLUDES) $(PYTHON_INCLUDE)
|
||||
$(CXXSHARED) $(CXXFLAGS) $(LDFLAGS) $(OBJS) $(IOBJS) $(PYTHON_DLNK) $(LIBS) $(CPP_DLLIBS) -o $(LIBPREFIX)_$(TARGET)$(PYTHON_SO)
|
||||
|
||||
|
|
@ -367,12 +367,12 @@ TKINTER =
|
|||
PYTHON_LIBOPTS = $(PYTHON_LINK) @LIBS@ $(TKINTER) $(SYSLIBS)
|
||||
|
||||
python_static: $(SRCDIR_SRCS)
|
||||
$(SWIGPYTHON) -lembed.i $(SWIGOPT) -o $(ISRCS) $(INTERFACEPATH)
|
||||
$(SWIG) -python $(SWIGOPTPY3) -lembed.i $(SWIGOPT) -o $(ISRCS) $(INTERFACEPATH)
|
||||
$(CC) $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) @LINKFORSHARED@ $(ISRCS) $(SRCDIR_SRCS) $(INCLUDES) \
|
||||
$(PYTHON_INCLUDE) $(LIBS) -L$(PYTHON_LIB) $(PYTHON_LIBOPTS) -o $(TARGET)
|
||||
|
||||
python_static_cpp: $(SRCDIR_SRCS)
|
||||
$(SWIGPYTHON) -c++ -lembed.i $(SWIGOPT) -o $(ICXXSRCS) $(INTERFACEPATH)
|
||||
$(SWIG) -python $(SWIGOPTPY3) -c++ -lembed.i $(SWIGOPT) -o $(ICXXSRCS) $(INTERFACEPATH)
|
||||
$(CXX) $(CPPFLAGS) $(CXXFLAGS) $(LDFLAGS) $(ICXXSRCS) $(SRCDIR_SRCS) $(SRCDIR_CXXSRCS) $(INCLUDES) \
|
||||
$(PYTHON_INCLUDE) $(LIBS) -L$(PYTHON_LIB) $(PYTHON_LIBOPTS) -o $(TARGET)
|
||||
|
||||
|
|
@ -429,7 +429,7 @@ python_clean:
|
|||
##################################################################
|
||||
|
||||
# Make sure these locate your Octave installation
|
||||
OCTAVE = OCTAVE_HISTFILE=/dev/null @OCTAVE@
|
||||
OCTAVE = @OCTAVE@
|
||||
OCTAVE_CXX = $(DEFS) @OCTAVE_CPPFLAGS@ @OCTAVE_CXXFLAGS@
|
||||
|
||||
# Extra Octave specific dynamic linking options
|
||||
|
|
@ -463,7 +463,7 @@ octave_cpp: $(SRCDIR_SRCS)
|
|||
# -----------------------------------------------------------------
|
||||
|
||||
octave_run:
|
||||
$(RUNTOOL) $(OCTAVE) $(OCTAVE_SCRIPT) $(RUNPIPE)
|
||||
OCTAVE_HISTFILE=/dev/null $(RUNTOOL) $(OCTAVE) $(OCTAVE_SCRIPT) $(RUNPIPE)
|
||||
|
||||
# -----------------------------------------------------------------
|
||||
# Version display
|
||||
|
|
@ -587,6 +587,7 @@ JAVASO =@JAVASO@
|
|||
JAVALDSHARED = @JAVALDSHARED@
|
||||
JAVACXXSHARED = @JAVACXXSHARED@
|
||||
JAVACFLAGS = @JAVACFLAGS@
|
||||
JAVAFLAGS = @JAVAFLAGS@
|
||||
JAVA = @JAVA@
|
||||
JAVAC = @JAVAC@ -d .
|
||||
|
||||
|
|
@ -620,7 +621,7 @@ java_compile: $(SRCDIR_SRCS)
|
|||
# -----------------------------------------------------------------
|
||||
|
||||
java_run:
|
||||
env LD_LIBRARY_PATH=$$PWD $(RUNTOOL) $(JAVA) $(RUNME) $(RUNPIPE)
|
||||
env LD_LIBRARY_PATH=$$PWD $(RUNTOOL) $(JAVA) $(JAVAFLAGS) $(RUNME) $(RUNPIPE)
|
||||
|
||||
# -----------------------------------------------------------------
|
||||
# Version display
|
||||
|
|
@ -1670,6 +1671,7 @@ R = R
|
|||
RCXXSRCS = $(INTERFACE:.i=_wrap.cpp) #Need to use _wrap.cpp for R build system as it does not understand _wrap.cxx
|
||||
RRSRC = $(INTERFACE:.i=.R)
|
||||
R_CFLAGS=-fPIC
|
||||
R_OPT = --slave --quiet --no-save --no-restore
|
||||
R_SCRIPT=$(SRCDIR)$(RUNME).R
|
||||
|
||||
# need to compile .cxx files outside of R build system to make sure that
|
||||
|
|
@ -1702,7 +1704,7 @@ endif
|
|||
# -----------------------------------------------------------------
|
||||
|
||||
r_run:
|
||||
$(RUNTOOL) $(R) CMD BATCH $(R_SCRIPT) $(RUNPIPE)
|
||||
$(RUNTOOL) $(R) $(R_OPT) -f $(R_SCRIPT) $(RUNPIPE)
|
||||
|
||||
# -----------------------------------------------------------------
|
||||
# Version display
|
||||
|
|
|
|||
|
|
@ -14,18 +14,19 @@ See the lua code for how they are called
|
|||
|
||||
// this adds some lua code directly into the module
|
||||
// warning: you need the example. prefix if you want it added into the module
|
||||
// addmittedly this code is a bit tedious, but its a one off effort
|
||||
// admittedly this code is a bit tedious, but its a one off effort
|
||||
%luacode {
|
||||
function example.sort_int2(t)
|
||||
local len=table.maxn(t) -- the len
|
||||
-- local len=table.maxn(t) -- the len - maxn deprecated in 5.3
|
||||
local len=0; for _ in pairs(t) do len=len+1 end
|
||||
local arr=example.new_int(len)
|
||||
for i=1,len do
|
||||
example.int_setitem(arr,i-1,t[i]) -- note: C index is one less then lua indea
|
||||
example.int_setitem(arr,i-1,t[i]) -- note: C index is one less then lua index
|
||||
end
|
||||
example.sort_int(arr,len) -- call the fn
|
||||
-- copy back
|
||||
for i=1,len do
|
||||
t[i]=example.int_getitem(arr,i-1) -- note: C index is one less then lua indea
|
||||
t[i]=example.int_getitem(arr,i-1) -- note: C index is one less then lua index
|
||||
end
|
||||
example.delete_int(arr) -- must delete it
|
||||
end
|
||||
|
|
|
|||
|
|
@ -10,11 +10,15 @@ import_packages_subdirs = \
|
|||
from_init3 \
|
||||
relativeimport1 \
|
||||
relativeimport2 \
|
||||
relativeimport3
|
||||
relativeimport3 \
|
||||
split_modules \
|
||||
namespace_pkg
|
||||
|
||||
|
||||
check: build
|
||||
if test "x$(SRCDIR)" != x; then \
|
||||
for file in `cd $(SRCDIR) && find . -type f -name __init__.py`; do \
|
||||
for file in `cd $(SRCDIR) && find . -type f -name "*.py"`; do \
|
||||
mkdir -p `dirname $$file`; \
|
||||
cp "${SRCDIR}$$file" "$$file" || exit 1; \
|
||||
done; \
|
||||
fi; \
|
||||
|
|
@ -35,7 +39,7 @@ static:
|
|||
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 \
|
||||
for file in `cd $(SRCDIR) && find . -type f -name "*.py"`; do \
|
||||
rm -f "$$file" || exit 1; \
|
||||
done; \
|
||||
fi; \
|
||||
|
|
|
|||
|
|
@ -1,2 +1,4 @@
|
|||
These are actually regression tests for SF bug #1297 (GH issue #7).
|
||||
See individual READMEs in subdirectories.
|
||||
The namespace_pkg is an example of python3's namespace packages.
|
||||
|
||||
See individual READMEs in subdirectories.
|
||||
17
Examples/python/import_packages/namespace_pkg/Makefile
Normal file
17
Examples/python/import_packages/namespace_pkg/Makefile
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
TOP = ../../..
|
||||
SWIGEXE = $(TOP)/../swig
|
||||
SWIG_LIB_DIR = $(TOP)/../$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib
|
||||
TARGET = robin
|
||||
INTERFACE = robin.i
|
||||
|
||||
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
|
||||
|
||||
clean:
|
||||
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' TARGET='$(TARGET)' python_clean
|
||||
rm -rf path1 path2 path3 path4.zip
|
||||
25
Examples/python/import_packages/namespace_pkg/README
Normal file
25
Examples/python/import_packages/namespace_pkg/README
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
This is an example (and test) of using swig generated modules in the context
|
||||
of python3's namespace packages:
|
||||
|
||||
https://www.python.org/dev/peps/pep-0420/
|
||||
|
||||
Consequently, this example requires python (3.3 or newer) to build and run.
|
||||
|
||||
This example creates a simple swig module named robin. The robin.py module
|
||||
has a companion C module named _robin.so. The robin module is tested in four
|
||||
ways:
|
||||
|
||||
1) As a non-package module (tested by nonpkg.py)
|
||||
|
||||
2) With robin.py and _robin.so in the brave package under the path1
|
||||
subdirectory. (tested by normal.py)
|
||||
|
||||
3) With robin.py in path2/brave and _robin.so in path3/brave
|
||||
(tested by split.py)
|
||||
|
||||
4) With robin.py contained in a zip file (path4.zip) as brave/robin.py and
|
||||
_robin.so found on the filesystem under path3/brave (tested by zipsplit.py)
|
||||
|
||||
Note: Using namespace packages with subpackages (such as brave.sir.robin) where
|
||||
robin.py is located in a zipfile requires python-3.5.1 or newer as
|
||||
python's zipimporter only worked with packages of depth 1 until then.
|
||||
5
Examples/python/import_packages/namespace_pkg/nonpkg.py
Normal file
5
Examples/python/import_packages/namespace_pkg/nonpkg.py
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
# import robin as a module in the global namespace
|
||||
|
||||
import robin
|
||||
|
||||
assert(robin.run() == "AWAY!")
|
||||
7
Examples/python/import_packages/namespace_pkg/normal.py
Normal file
7
Examples/python/import_packages/namespace_pkg/normal.py
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
import sys
|
||||
# Package brave found under one path
|
||||
sys.path.insert(0, 'path1')
|
||||
|
||||
from brave import robin
|
||||
|
||||
assert(robin.run() == "AWAY!")
|
||||
45
Examples/python/import_packages/namespace_pkg/nstest.py
Normal file
45
Examples/python/import_packages/namespace_pkg/nstest.py
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
import sys
|
||||
import os
|
||||
import shutil
|
||||
import zipfile
|
||||
|
||||
|
||||
def copyMods():
|
||||
dirs = ['path1', 'path2', 'path3']
|
||||
|
||||
# Clean out any old package paths
|
||||
for d in dirs:
|
||||
if os.path.isdir(d):
|
||||
shutil.rmtree(d)
|
||||
|
||||
for d in dirs:
|
||||
os.mkdir(d)
|
||||
os.mkdir(os.path.join(d, 'brave'))
|
||||
|
||||
shutil.copy('robin.py', os.path.join('path1', 'brave'))
|
||||
os.system('cp _robin.* ' + os.path.join('path1', 'brave'))
|
||||
|
||||
shutil.copy('robin.py', os.path.join('path2', 'brave'))
|
||||
os.system('cp _robin.* ' + os.path.join('path3', 'brave'))
|
||||
|
||||
mkzip()
|
||||
|
||||
def mkzip():
|
||||
zf = zipfile.ZipFile("path4.zip", "w")
|
||||
zf.writestr("brave/", b'')
|
||||
zf.write('robin.py', 'brave/robin.py')
|
||||
zf.close()
|
||||
|
||||
|
||||
def main():
|
||||
copyMods()
|
||||
|
||||
# Run each test with a separate interpreter
|
||||
os.system(sys.executable + " nonpkg.py")
|
||||
os.system(sys.executable + " normal.py")
|
||||
os.system(sys.executable + " split.py")
|
||||
os.system(sys.executable + " zipsplit.py")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
7
Examples/python/import_packages/namespace_pkg/robin.i
Normal file
7
Examples/python/import_packages/namespace_pkg/robin.i
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
%module robin
|
||||
|
||||
%inline %{
|
||||
const char *run(void) {
|
||||
return "AWAY!";
|
||||
}
|
||||
%}
|
||||
17
Examples/python/import_packages/namespace_pkg/runme.py
Normal file
17
Examples/python/import_packages/namespace_pkg/runme.py
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
# These examples rely on namespace packages. Don't
|
||||
# run them for old python interpreters.
|
||||
import sys
|
||||
import os.path
|
||||
|
||||
testname = os.path.basename(os.path.dirname(os.path.abspath(__file__)))
|
||||
print "Testing " + testname + " - namespace packages"
|
||||
|
||||
if sys.version_info < (3, 3, 0):
|
||||
print " Not importing nstest as Python version is < 3.3"
|
||||
sys.exit(0)
|
||||
|
||||
import nstest
|
||||
|
||||
print " Finished importing nstest"
|
||||
|
||||
nstest.main()
|
||||
9
Examples/python/import_packages/namespace_pkg/split.py
Normal file
9
Examples/python/import_packages/namespace_pkg/split.py
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
import sys
|
||||
# Package brave split into two paths.
|
||||
# path2/brave/robin.py and path3/brave/_robin.so
|
||||
sys.path.insert(0, 'path2')
|
||||
sys.path.insert(0, 'path3')
|
||||
|
||||
from brave import robin
|
||||
|
||||
assert(robin.run() == "AWAY!")
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
import sys
|
||||
# Package brave split into two paths.
|
||||
# brave/robin.py (in path4.zip) and path3/brave/_robin.so
|
||||
sys.path.insert(0, 'path4.zip')
|
||||
sys.path.insert(0, 'path3')
|
||||
|
||||
from brave import robin
|
||||
|
||||
assert(robin.run() == "AWAY!")
|
||||
26
Examples/python/import_packages/split_modules/Makefile
Normal file
26
Examples/python/import_packages/split_modules/Makefile
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
TOP = ../../..
|
||||
LIBS =
|
||||
|
||||
subdirs = vanilla vanilla_split
|
||||
|
||||
|
||||
check: build
|
||||
for s in $(subdirs); do \
|
||||
(cd $$s && $(MAKE) check); \
|
||||
done
|
||||
|
||||
build:
|
||||
for s in $(subdirs); do \
|
||||
(cd $$s && $(MAKE) SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' build); \
|
||||
done
|
||||
|
||||
static:
|
||||
for s in $(subdirs); do \
|
||||
(cd $$s && $(MAKE) SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' static); \
|
||||
done
|
||||
|
||||
clean:
|
||||
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' python_clean
|
||||
for s in $(subdirs); do \
|
||||
(cd $$s && $(MAKE) clean); \
|
||||
done
|
||||
7
Examples/python/import_packages/split_modules/README
Normal file
7
Examples/python/import_packages/split_modules/README
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
These examples/tests are for when the SWIG generated wrapper module is split
|
||||
between two packages. Specifically the pure python part is part of a package
|
||||
and the C/C++ part is not in any package at all. Historically SWIG has
|
||||
supported this sort of thing.
|
||||
|
||||
vanilla # "plane Jane" module both halves in pkg1
|
||||
vanilla_split # python 1/2 in pkg1 C 1/2 in global namespace
|
||||
|
|
@ -0,0 +1,18 @@
|
|||
TOP = ../../../..
|
||||
SWIGEXE = $(TOP)/../swig
|
||||
SWIG_LIB_DIR = $(TOP)/../$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib
|
||||
SWIGOPT =
|
||||
LIBS =
|
||||
|
||||
check: build
|
||||
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' python_run
|
||||
|
||||
build:
|
||||
cd pkg1 && $(MAKE) build
|
||||
|
||||
static:
|
||||
cd pkg1 && $(MAKE) static
|
||||
|
||||
clean:
|
||||
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' TARGET='foo' python_clean
|
||||
cd pkg1 && $(MAKE) -f $(TOP)/../Makefile SRCDIR='$(SRCDIR)' TARGET='foo' python_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 @@
|
|||
# killroy was here
|
||||
|
|
@ -0,0 +1,10 @@
|
|||
%module(package="pkg1") foo
|
||||
%{
|
||||
static unsigned count(void)
|
||||
{
|
||||
return 3;
|
||||
}
|
||||
%}
|
||||
|
||||
unsigned count(void);
|
||||
|
||||
|
|
@ -0,0 +1,10 @@
|
|||
import os.path
|
||||
|
||||
testname = os.path.basename(os.path.dirname(os.path.abspath(__file__)))
|
||||
print "Testing " + testname + " - split modules"
|
||||
|
||||
import pkg1.foo
|
||||
|
||||
print " Finished importing pkg1.foo"
|
||||
|
||||
assert(pkg1.foo.count() == 3)
|
||||
|
|
@ -0,0 +1,22 @@
|
|||
TOP = ../../../..
|
||||
SWIGEXE = $(TOP)/../swig
|
||||
SWIG_LIB_DIR = $(TOP)/../$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib
|
||||
SWIGOPT = -outdir pkg1
|
||||
LIBS =
|
||||
|
||||
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='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
|
||||
cd pkg1 && $(MAKE) -f $(TOP)/../Makefile SRCDIR='$(SRCDIR)' TARGET='foo' python_clean
|
||||
|
|
@ -0,0 +1,10 @@
|
|||
%module(package="pkg1") foo
|
||||
%{
|
||||
static unsigned count(void)
|
||||
{
|
||||
return 3;
|
||||
}
|
||||
%}
|
||||
|
||||
unsigned count(void);
|
||||
|
||||
|
|
@ -0,0 +1 @@
|
|||
# killroy was here
|
||||
|
|
@ -0,0 +1,10 @@
|
|||
import os.path
|
||||
|
||||
testname = os.path.basename(os.path.dirname(os.path.abspath(__file__)))
|
||||
print "Testing " + testname + " - split modules"
|
||||
|
||||
import pkg1.foo
|
||||
|
||||
print " Finished importing pkg1.foo"
|
||||
|
||||
assert(pkg1.foo.count() == 3)
|
||||
|
|
@ -68,6 +68,10 @@ TAscii *DigitsGlobalC;
|
|||
// Director test
|
||||
%feature("director");
|
||||
|
||||
#if defined(SWIGGO)
|
||||
%typemap(godirectorout) CharPtr, CCharPtr ""
|
||||
#endif
|
||||
|
||||
%inline %{
|
||||
struct DirectorTest {
|
||||
virtual UCharPtr UCharFunction(UCharPtr str) { return str; }
|
||||
|
|
|
|||
|
|
@ -87,7 +87,6 @@ CPP_TEST_BROKEN += \
|
|||
director_nested_class \
|
||||
exception_partial_info \
|
||||
extend_variable \
|
||||
li_std_vector_ptr \
|
||||
li_boost_shared_ptr_template \
|
||||
nested_private \
|
||||
overload_complicated \
|
||||
|
|
@ -174,7 +173,6 @@ CPP_TEST_CASES += \
|
|||
director_abstract \
|
||||
director_alternating \
|
||||
director_basic \
|
||||
director_property \
|
||||
director_binary_string \
|
||||
director_classes \
|
||||
director_classic \
|
||||
|
|
@ -189,12 +187,14 @@ CPP_TEST_CASES += \
|
|||
director_ignore \
|
||||
director_keywords \
|
||||
director_namespace_clash \
|
||||
director_nested \
|
||||
director_nspace \
|
||||
director_nspace_director_name_collision \
|
||||
director_nested \
|
||||
director_overload \
|
||||
director_overload2 \
|
||||
director_pass_by_value \
|
||||
director_primitives \
|
||||
director_property \
|
||||
director_protected \
|
||||
director_protected_overloaded \
|
||||
director_redefined \
|
||||
|
|
@ -307,6 +307,7 @@ CPP_TEST_CASES += \
|
|||
nested_class \
|
||||
nested_directors \
|
||||
nested_comment \
|
||||
nested_ignore \
|
||||
nested_scope \
|
||||
nested_template_base \
|
||||
nested_workaround \
|
||||
|
|
@ -362,6 +363,7 @@ CPP_TEST_CASES += \
|
|||
smart_pointer_const2 \
|
||||
smart_pointer_const_overload \
|
||||
smart_pointer_extend \
|
||||
smart_pointer_ignore \
|
||||
smart_pointer_member \
|
||||
smart_pointer_multi \
|
||||
smart_pointer_multi_typedef \
|
||||
|
|
@ -402,6 +404,7 @@ CPP_TEST_CASES += \
|
|||
template_default2 \
|
||||
template_default_arg \
|
||||
template_default_arg_overloaded \
|
||||
template_default_arg_overloaded_extend \
|
||||
template_default_arg_virtual_destructor \
|
||||
template_default_class_parms \
|
||||
template_default_class_parms_typedef \
|
||||
|
|
@ -584,6 +587,7 @@ CPP_STD_TEST_CASES += \
|
|||
li_std_vector \
|
||||
li_std_vector_enum \
|
||||
li_std_vector_member_var\
|
||||
li_std_vector_ptr \
|
||||
smart_pointer_inherit \
|
||||
template_typedef_fnc \
|
||||
template_type_namespace \
|
||||
|
|
@ -714,7 +718,7 @@ check-cpp: $(CPP_TEST_CASES:=.cpptest)
|
|||
check-cpp11: $(CPP11_TEST_CASES:=.cpptest)
|
||||
|
||||
check-failing-test = \
|
||||
$(MAKE) -s $1.$2 >/dev/null 2>/dev/null && echo "Failing test $t passed."
|
||||
$(MAKE) -s $1.$2 >/dev/null 2>/dev/null && echo "Failing test $1 passed."
|
||||
|
||||
check-failing:
|
||||
+-$(foreach t,$(FAILING_C_TESTS),$(call check-failing-test,$t,ctest);)
|
||||
|
|
|
|||
|
|
@ -3,6 +3,9 @@
|
|||
// %constant and struct
|
||||
|
||||
%inline %{
|
||||
#if defined(_MSC_VER)
|
||||
#pragma warning(disable : 4190) // warning C4190: 'result' has C-linkage specified, but returns UDT 'Type1' which is incompatible with C
|
||||
#endif
|
||||
struct Type1 {
|
||||
Type1(int val = 0) : val(val) {}
|
||||
int val;
|
||||
|
|
|
|||
|
|
@ -2,15 +2,6 @@
|
|||
|
||||
// Type aliasing seg fault : Github issue #424
|
||||
|
||||
%warnfilter(SWIGWARN_CPP11_ALIAS_DECLARATION) Target;
|
||||
%warnfilter(SWIGWARN_CPP11_ALIAS_DECLARATION) Int;
|
||||
%warnfilter(SWIGWARN_CPP11_ALIAS_DECLARATION) IntRef;
|
||||
%warnfilter(SWIGWARN_CPP11_ALIAS_DECLARATION) IntPtrRef;
|
||||
%warnfilter(SWIGWARN_CPP11_ALIAS_DECLARATION) IntRValueRef;
|
||||
%warnfilter(SWIGWARN_CPP11_ALIAS_DECLARATION) IntArray;
|
||||
%warnfilter(SWIGWARN_CPP11_ALIAS_DECLARATION) HalideTargetPtr1;
|
||||
%warnfilter(SWIGWARN_CPP11_ALIAS_DECLARATION) HalideTargetPtr2;
|
||||
|
||||
%inline %{
|
||||
namespace Halide {
|
||||
|
||||
|
|
@ -53,14 +44,69 @@ public:
|
|||
|
||||
|
||||
%inline %{
|
||||
using Int = int;
|
||||
using IntRef = int&;
|
||||
using IntPtrRef = int*&;
|
||||
using IntRValueRef = int&&;
|
||||
using IntArray = int[];
|
||||
|
||||
using HalideTargetPtr1 = Halide::Target*;
|
||||
namespace Halide {
|
||||
using HalideTargetPtr2 = Target*;
|
||||
}
|
||||
%}
|
||||
|
||||
// Define some types
|
||||
|
||||
%inline %{
|
||||
using Int = int;
|
||||
using IntPtr = Int*;
|
||||
using IntRef = Int&;
|
||||
using IntPtrRef = Int*&;
|
||||
using IntRValueRef = Int&&;
|
||||
using IntArray = Int[];
|
||||
%}
|
||||
|
||||
// Test that SWIG understands these new types
|
||||
|
||||
%callback("%s_cb");
|
||||
Int mult2(Int x);
|
||||
%nocallback;
|
||||
|
||||
%inline %{
|
||||
Int mult2(Int x) { return x * 2; }
|
||||
IntPtr allocate_int() { return new Int(12); }
|
||||
void free_int(int* ptr) { delete ptr; }
|
||||
void inplace_mult2(IntRef x) { x *= 2; }
|
||||
Int read_int(IntPtr ptr) { return *ptr; }
|
||||
|
||||
template <typename T> class Pair {
|
||||
public:
|
||||
using data_t = T;
|
||||
|
||||
data_t a, b;
|
||||
|
||||
Pair() : a(), b() { }
|
||||
Pair(data_t a, data_t b) : a(a), b(b) { }
|
||||
data_t first() { return a; }
|
||||
data_t second() { return b; }
|
||||
};
|
||||
%}
|
||||
|
||||
%template(int_pair) Pair<Int>;
|
||||
|
||||
%inline %{
|
||||
using PairInt = Pair<Int>;
|
||||
|
||||
class PairSubclass : public PairInt {
|
||||
public:
|
||||
PairSubclass(data_t a, data_t b) : PairInt(a, b) { }
|
||||
|
||||
using const_ref_data_t = const data_t&;
|
||||
};
|
||||
|
||||
PairSubclass::data_t plus1(PairSubclass::const_ref_data_t x) { return x + 1; }
|
||||
%}
|
||||
|
||||
// Test function pointers
|
||||
|
||||
%inline %{
|
||||
using callback_t = int(*)(int);
|
||||
|
||||
callback_t get_callback() { return mult2; }
|
||||
int call(callback_t func, int param) { return func(param); }
|
||||
%}
|
||||
|
|
|
|||
|
|
@ -6,6 +6,12 @@ The primary purpose of this testcase is to ensure that enums used along with the
|
|||
|
||||
%inline %{
|
||||
|
||||
#if __GNUC__ >= 5 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 8)
|
||||
/* for anonymous enums */
|
||||
/* dereferencing type-punned pointer will break strict-aliasing rules [-Werror=strict-aliasing] */
|
||||
#pragma GCC diagnostic ignored "-Wstrict-aliasing"
|
||||
#endif
|
||||
|
||||
enum SOME_ENUM {ENUM_ONE, ENUM_TWO};
|
||||
|
||||
struct StructWithEnums {
|
||||
|
|
|
|||
43
Examples/test-suite/csharp/director_pass_by_value_runme.cs
Normal file
43
Examples/test-suite/csharp/director_pass_by_value_runme.cs
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
using System;
|
||||
using director_pass_by_valueNamespace;
|
||||
|
||||
public class runme
|
||||
{
|
||||
private static void WaitForGC()
|
||||
{
|
||||
System.GC.Collect();
|
||||
System.GC.WaitForPendingFinalizers();
|
||||
System.Threading.Thread.Sleep(10);
|
||||
}
|
||||
|
||||
static void Main()
|
||||
{
|
||||
runme r = new runme();
|
||||
r.run();
|
||||
}
|
||||
|
||||
void run()
|
||||
{
|
||||
Caller caller = new Caller();
|
||||
caller.call_virtualMethod(new director_pass_by_value_Derived());
|
||||
{
|
||||
int countdown = 5;
|
||||
while (true) {
|
||||
WaitForGC();
|
||||
if (--countdown == 0)
|
||||
break;
|
||||
};
|
||||
}
|
||||
// bug was the passByVal 'global' object was destroyed after the call to virtualMethod had finished.
|
||||
int ret = runme.passByVal.getVal();
|
||||
if (ret != 0x12345678)
|
||||
throw new Exception("Bad return value, got " + ret.ToString("x"));
|
||||
}
|
||||
public static PassedByValue passByVal;
|
||||
}
|
||||
|
||||
class director_pass_by_value_Derived : DirectorPassByValueAbstractBase {
|
||||
public override void virtualMethod(PassedByValue pbv) {
|
||||
runme.passByVal = pbv;
|
||||
}
|
||||
}
|
||||
14
Examples/test-suite/default_args_c.i
Normal file
14
Examples/test-suite/default_args_c.i
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
%module default_args_c
|
||||
|
||||
/* Default arguments for C code */
|
||||
int foo1(int x = 42 || 3);
|
||||
int foo43(int x = 42 | 3);
|
||||
|
||||
%{
|
||||
int foo1(int x) {
|
||||
return x;
|
||||
}
|
||||
int foo43(int x) {
|
||||
return x;
|
||||
}
|
||||
%}
|
||||
30
Examples/test-suite/director_pass_by_value.i
Normal file
30
Examples/test-suite/director_pass_by_value.i
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
%module(directors="1") director_pass_by_value
|
||||
%director DirectorPassByValueAbstractBase;
|
||||
|
||||
%inline %{
|
||||
class PassedByValue {
|
||||
int val;
|
||||
public:
|
||||
PassedByValue() { val = 0x12345678; }
|
||||
int getVal() { return val; }
|
||||
};
|
||||
|
||||
int doSomething(int x) {
|
||||
int yy[256];
|
||||
yy[0] =0x9876;
|
||||
return yy[0];
|
||||
}
|
||||
|
||||
class DirectorPassByValueAbstractBase {
|
||||
public:
|
||||
virtual void virtualMethod(PassedByValue pbv) = 0;
|
||||
virtual ~DirectorPassByValueAbstractBase () {}
|
||||
};
|
||||
|
||||
class Caller {
|
||||
public:
|
||||
void call_virtualMethod(DirectorPassByValueAbstractBase &f) {
|
||||
f.virtualMethod(PassedByValue());
|
||||
}
|
||||
};
|
||||
%}
|
||||
|
|
@ -47,6 +47,12 @@
|
|||
|
||||
%inline %{
|
||||
|
||||
#if __GNUC__ >= 5 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 8)
|
||||
/* for anonymous enums */
|
||||
/* dereferencing type-punned pointer will break strict-aliasing rules [-Werror=strict-aliasing] */
|
||||
#pragma GCC diagnostic ignored "-Wstrict-aliasing"
|
||||
#endif
|
||||
|
||||
enum { AnonEnum1, AnonEnum2 = 100 };
|
||||
enum { ReallyAnInteger = 200 };
|
||||
//enum { AnonEnum3, AnonEnum4 } instance;
|
||||
|
|
|
|||
|
|
@ -12,6 +12,12 @@
|
|||
|
||||
%inline %{
|
||||
|
||||
#if __GNUC__ >= 5 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 8)
|
||||
/* for anonymous enums */
|
||||
/* dereferencing type-punned pointer will break strict-aliasing rules [-Werror=strict-aliasing] */
|
||||
#pragma GCC diagnostic ignored "-Wstrict-aliasing"
|
||||
#endif
|
||||
|
||||
typedef enum {
|
||||
CSP_ITERATION_FWD,
|
||||
CSP_ITERATION_BWD = 11
|
||||
|
|
|
|||
|
|
@ -1,4 +0,0 @@
|
|||
%module xxx
|
||||
|
||||
int foo(int x = 42 || 3);
|
||||
|
||||
|
|
@ -1,3 +0,0 @@
|
|||
%module xxx
|
||||
|
||||
int foo(int x, ...);
|
||||
19
Examples/test-suite/errors/cpp_inherit_ignored.i
Normal file
19
Examples/test-suite/errors/cpp_inherit_ignored.i
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
%module xxx
|
||||
|
||||
// Only non-ignored classes should warn about Ignored base classes
|
||||
%ignore ActualClass;
|
||||
%ignore ActualClassNoTemplates;
|
||||
|
||||
%{
|
||||
struct BaseClassNoTemplates {};
|
||||
%}
|
||||
%inline %{
|
||||
template<typename T>
|
||||
class TemplateClass {};
|
||||
|
||||
class ActualClass : public TemplateClass<int> {};
|
||||
class AktuelKlass : public TemplateClass<int> {};
|
||||
|
||||
class ActualClassNoTemplates : public BaseClassNoTemplates {};
|
||||
class AktuelKlassNoTemplates : public BaseClassNoTemplates {};
|
||||
%}
|
||||
3
Examples/test-suite/errors/cpp_inherit_ignored.stderr
Normal file
3
Examples/test-suite/errors/cpp_inherit_ignored.stderr
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
cpp_inherit_ignored.i:15: Warning 401: Nothing known about base class 'TemplateClass< int >'. Ignored.
|
||||
cpp_inherit_ignored.i:15: Warning 401: Maybe you forgot to instantiate 'TemplateClass< int >' using %template.
|
||||
cpp_inherit_ignored.i:18: Warning 401: Nothing known about base class 'BaseClassNoTemplates'. Ignored.
|
||||
|
|
@ -1,15 +0,0 @@
|
|||
%module xxx
|
||||
int foo(int x);
|
||||
int foo(double x);
|
||||
|
||||
class Foo {
|
||||
public:
|
||||
int bar(int);
|
||||
int bar(double);
|
||||
};
|
||||
|
||||
class Spam {
|
||||
public:
|
||||
Spam();
|
||||
Spam(int);
|
||||
};
|
||||
|
|
@ -1,7 +0,0 @@
|
|||
%module xxx
|
||||
|
||||
class foo {
|
||||
static const int BAR = 42;
|
||||
public:
|
||||
int blah(int x = BAR);
|
||||
};
|
||||
|
|
@ -1,8 +0,0 @@
|
|||
%module xxx
|
||||
|
||||
template<T> T blah(T x);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
@ -4,4 +4,4 @@ template<class T> T blah(T x) { };
|
|||
|
||||
%template(iblah) blah<int>;
|
||||
%template(iiblah) blah<int>;
|
||||
|
||||
// The second %template instantiation above should surely be ignored with a warning, but doesn't atm
|
||||
|
|
|
|||
|
|
@ -1,3 +0,0 @@
|
|||
cpp_using_type_aliasing.i:8: Warning 341: The 'using' keyword in type aliasing is not fully supported yet.
|
||||
cpp_using_type_aliasing.i:8: Warning 315: Nothing known about 'Okay< int >'.
|
||||
cpp_using_type_aliasing.i:8: Warning 315: Nothing known about 'Okay< int >'.
|
||||
|
|
@ -1,7 +0,0 @@
|
|||
%module xxx
|
||||
|
||||
#define foo(a,x) a x
|
||||
|
||||
#if foo
|
||||
#endif
|
||||
|
||||
|
|
@ -1,6 +1,9 @@
|
|||
%module exception_classname
|
||||
|
||||
%warnfilter(SWIGWARN_RUBY_WRONG_NAME);
|
||||
#ifdef SWIGPHP
|
||||
%rename(ExceptionClass) Exception;
|
||||
#endif
|
||||
|
||||
%inline %{
|
||||
class Exception {
|
||||
|
|
|
|||
|
|
@ -40,4 +40,14 @@ func main() {
|
|||
fmt.Println("got", a, "want", dwant)
|
||||
panic(a)
|
||||
}
|
||||
|
||||
c2 := go_inout.NewC2()
|
||||
pm := c2.M()
|
||||
want = map[string]interface{}{
|
||||
"ID": float64(1),
|
||||
}
|
||||
if !reflect.DeepEqual(*pm, want) {
|
||||
fmt.Println("for c2.M got", pm, "want", want)
|
||||
panic(pm)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,12 +1,19 @@
|
|||
package main
|
||||
|
||||
import . "./li_std_vector_ptr"
|
||||
import "fmt"
|
||||
|
||||
func check(val1 int, val2 int) {
|
||||
if val1 != val2 {
|
||||
panic(fmt.Sprintf("Values are not the same %d %d", val1, val2))
|
||||
}
|
||||
}
|
||||
func main() {
|
||||
ip1 := MakeIntPtr(11)
|
||||
ip2 := MakeIntPtr(22)
|
||||
vi := NewIntPtrVector()
|
||||
vi.Add(ip1)
|
||||
vi.Add(ip2)
|
||||
DisplayVector(vi)
|
||||
check(GetValueFromVector(vi, 0), 11)
|
||||
check(GetValueFromVector(vi, 1), 22)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@ struct RetStruct {
|
|||
|
||||
// Write a typemap that calls C++ by converting in and out of JSON.
|
||||
|
||||
%go_import("encoding/json", "bytes", "encoding/binary")
|
||||
%go_import("encoding/json", "bytes", "encoding/binary", "reflect", "unsafe")
|
||||
|
||||
%insert(go_header)
|
||||
%{
|
||||
|
|
@ -68,6 +68,26 @@ type In json.Marshaler
|
|||
}
|
||||
%}
|
||||
|
||||
%typemap(gotype) RetStruct* "*map[string]interface{}"
|
||||
|
||||
%typemap(imtype) RetStruct* "*string"
|
||||
|
||||
%typemap(out,fragment="AllocateString") RetStruct*
|
||||
%{
|
||||
$result = (_gostring_*)malloc(sizeof(_gostring_));
|
||||
*$result = Swig_AllocateString($1->str.data(), $1->str.length());
|
||||
%}
|
||||
|
||||
%typemap(goout,fragment="CopyString") RetStruct*
|
||||
%{
|
||||
defer Swig_free(uintptr(unsafe.Pointer($1)))
|
||||
var rm map[string]interface{}
|
||||
if err := json.Unmarshal([]byte(swigCopyString(*$1)), &rm); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
$result = &rm
|
||||
%}
|
||||
|
||||
%inline
|
||||
%{
|
||||
|
||||
|
|
@ -87,6 +107,10 @@ struct MyArray {
|
|||
std::vector<std::string> strings;
|
||||
};
|
||||
|
||||
void* Allocate(int n) {
|
||||
return new char[n];
|
||||
}
|
||||
|
||||
static uint64_t getuint64(const char* s) {
|
||||
uint64_t ret = 0;
|
||||
for (int i = 0; i < 8; i++, s++) {
|
||||
|
|
@ -121,7 +145,12 @@ static void putuint64(std::string *s, size_t off, uint64_t v) {
|
|||
buf.Write(b[:])
|
||||
buf.WriteString(s)
|
||||
}
|
||||
str := buf.String()
|
||||
bb := buf.Bytes()
|
||||
p := Allocate(len(bb))
|
||||
copy((*[1<<15]byte)(unsafe.Pointer(p))[:len(bb)], bb)
|
||||
var str string
|
||||
(*reflect.StringHeader)(unsafe.Pointer(&str)).Data = uintptr(unsafe.Pointer(p))
|
||||
(*reflect.StringHeader)(unsafe.Pointer(&str)).Len = len(bb)
|
||||
$result = &str
|
||||
}
|
||||
%}
|
||||
|
|
@ -197,3 +226,18 @@ void DoubleArray(MyArray* v) {
|
|||
}
|
||||
}
|
||||
%}
|
||||
|
||||
%inline
|
||||
%{
|
||||
class C1 {
|
||||
public:
|
||||
RetStruct* M() {
|
||||
RetStruct* r = new RetStruct;
|
||||
r->str = "{\"ID\":1}";
|
||||
return r;
|
||||
}
|
||||
};
|
||||
|
||||
class C2 : public C1 {
|
||||
};
|
||||
%}
|
||||
|
|
|
|||
|
|
@ -34,5 +34,5 @@ int inserted_wrapper(int i) { return inserted_header3(i); }
|
|||
|
||||
%init %{
|
||||
// %inserted code %init
|
||||
int inserted_init_value = inserted_wrapper(0);
|
||||
int SWIGUNUSED inserted_init_value = inserted_wrapper(0);
|
||||
%}
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@
|
|||
LANGUAGE = java
|
||||
JAVA = @JAVA@
|
||||
JAVAC = @JAVAC@
|
||||
JAVAFLAGS = -Xcheck:jni
|
||||
JAVAFLAGS = @JAVAFLAGS@
|
||||
SCRIPTSUFFIX = _runme.java
|
||||
|
||||
srcdir = @srcdir@
|
||||
|
|
|
|||
|
|
@ -140,7 +140,7 @@ public class director_classes_runme {
|
|||
Package packag = klass.getPackage();
|
||||
String simpleName = null;
|
||||
if (packag != null)
|
||||
simpleName = fullName.replaceAll(packag.getName() + ".", "");
|
||||
simpleName = fullName.replaceAll(packag.getName() + "\\.", "");
|
||||
else
|
||||
simpleName = fullName;
|
||||
return simpleName;
|
||||
|
|
|
|||
48
Examples/test-suite/java/director_pass_by_value_runme.java
Normal file
48
Examples/test-suite/java/director_pass_by_value_runme.java
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
|
||||
import director_pass_by_value.*;
|
||||
|
||||
public class director_pass_by_value_runme {
|
||||
|
||||
static {
|
||||
try {
|
||||
System.loadLibrary("director_pass_by_value");
|
||||
} catch (UnsatisfiedLinkError e) {
|
||||
System.err.println("Native code library failed to load. See the chapter on Dynamic Linking Problems in the SWIG Java documentation for help.\n" + e);
|
||||
System.exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
private static void WaitForGC() {
|
||||
System.gc();
|
||||
System.runFinalization();
|
||||
try {
|
||||
java.lang.Thread.sleep(10);
|
||||
} catch (java.lang.InterruptedException e) {
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String argv[]) {
|
||||
Caller caller = new Caller();
|
||||
caller.call_virtualMethod(new director_pass_by_value_Derived());
|
||||
{
|
||||
int countdown = 5;
|
||||
while (true) {
|
||||
WaitForGC();
|
||||
if (--countdown == 0)
|
||||
break;
|
||||
};
|
||||
}
|
||||
// bug was the passByVal 'global' object was destroyed after the call to virtualMethod had finished.
|
||||
int ret = director_pass_by_value_runme.passByVal.getVal();
|
||||
if (ret != 0x12345678)
|
||||
throw new RuntimeException("Bad return value, got " + Integer.toHexString(ret));
|
||||
}
|
||||
|
||||
static PassedByValue passByVal;
|
||||
}
|
||||
|
||||
class director_pass_by_value_Derived extends DirectorPassByValueAbstractBase {
|
||||
public void virtualMethod(PassedByValue pbv) {
|
||||
director_pass_by_value_runme.passByVal = pbv;
|
||||
}
|
||||
}
|
||||
19
Examples/test-suite/java/smart_pointer_ignore_runme.java
Normal file
19
Examples/test-suite/java/smart_pointer_ignore_runme.java
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
import smart_pointer_ignore.*;
|
||||
|
||||
public class smart_pointer_ignore_runme {
|
||||
|
||||
static {
|
||||
try {
|
||||
System.loadLibrary("smart_pointer_ignore");
|
||||
} catch (UnsatisfiedLinkError e) {
|
||||
System.err.println("Native code library failed to load. See the chapter on Dynamic Linking Problems in the SWIG Java documentation for help.\n" + e);
|
||||
System.exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String argv[]) {
|
||||
DerivedPtr d = smart_pointer_ignore.makeDerived();
|
||||
d.base();
|
||||
d.derived();
|
||||
}
|
||||
}
|
||||
|
|
@ -25,6 +25,8 @@ namespace boost {
|
|||
using std::array;
|
||||
}
|
||||
|
||||
%ignore std::array::fill; // Some older versions of boost don't have this function
|
||||
|
||||
%include <std_array.i>
|
||||
|
||||
%template(ArrayInt6) std::array<int, 6>;
|
||||
|
|
|
|||
|
|
@ -67,7 +67,7 @@ INTEGER bar_getter(Base<INTEGER>& foo) {
|
|||
// 2nd test - templates with default template parameters
|
||||
#if defined(SHARED_PTR_WRAPPERS_IMPLEMENTED)
|
||||
|
||||
%shared_ptr(Space::BaseDefault<short>)
|
||||
%shared_ptr(Space::BaseDefault<short, int>)
|
||||
%shared_ptr(Space::DerivedDefault<short>)
|
||||
%shared_ptr(Space::DerivedDefault2<short>)
|
||||
|
||||
|
|
|
|||
|
|
@ -130,3 +130,13 @@ namespace aa {
|
|||
std::vector< ::aa::Holder > vec1(std::vector< ::aa::Holder > x) { return x; }
|
||||
%}
|
||||
#endif
|
||||
|
||||
// exercising vectors of strings
|
||||
%inline %{
|
||||
std::vector<std::string> RevStringVec (const std::vector<std::string> &In)
|
||||
{
|
||||
std::vector<std::string> result(In);
|
||||
std::reverse(result.begin(), result.end());
|
||||
return(result);
|
||||
}
|
||||
%}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
// Bug 2359417
|
||||
// SF Bug 2359417
|
||||
%module li_std_vector_ptr
|
||||
|
||||
%include "std_vector.i"
|
||||
|
|
@ -15,16 +15,76 @@ double* makeDoublePtr(double v) {
|
|||
return new double(v);
|
||||
}
|
||||
|
||||
#if 1
|
||||
// pointer to pointer in the wrappers was preventing a vector of pointers from working
|
||||
int** makeIntPtrPtr(int* v) {
|
||||
return new int*(v);
|
||||
}
|
||||
#endif
|
||||
|
||||
void displayVector(std::vector<int *> vpi) {
|
||||
cout << "displayVector..." << endl;
|
||||
for (int i=0; i<vpi.size(); ++i)
|
||||
for (size_t i=0; i<vpi.size(); ++i)
|
||||
cout << *vpi[i] << endl;
|
||||
}
|
||||
int getValueFromVector(std::vector<int *> vpi, size_t index) {
|
||||
return *vpi[index];
|
||||
}
|
||||
%}
|
||||
|
||||
// A not exposed to wrappers
|
||||
%{
|
||||
struct A {
|
||||
int val;
|
||||
A(int val) : val(val) {}
|
||||
};
|
||||
%}
|
||||
|
||||
%template(APtrVector) std::vector<A *>;
|
||||
|
||||
%inline %{
|
||||
A *makeA(int val) { return new A(val); }
|
||||
int getVal(A* a) { return a->val; }
|
||||
int getVectorValueA(std::vector<A *> vpi, size_t index) {
|
||||
return vpi[index]->val;
|
||||
}
|
||||
%}
|
||||
|
||||
// B is fully exposed to wrappers
|
||||
%inline %{
|
||||
struct B {
|
||||
int val;
|
||||
B(int val = 0) : val(val) {}
|
||||
};
|
||||
%}
|
||||
|
||||
%template(BPtrVector) std::vector<B *>;
|
||||
|
||||
%inline %{
|
||||
B *makeB(int val) { return new B(val); }
|
||||
int getVal(B* b) { return b->val; }
|
||||
int getVectorValueB(std::vector<B *> vpi, size_t index) {
|
||||
return vpi[index]->val;
|
||||
}
|
||||
%}
|
||||
|
||||
// C is fully exposed to wrappers (includes code using B **)
|
||||
%inline %{
|
||||
struct C {
|
||||
int val;
|
||||
C(int val = 0) : val(val) {}
|
||||
};
|
||||
%}
|
||||
|
||||
%template(CPtrVector) std::vector<C *>;
|
||||
|
||||
%inline %{
|
||||
// pointer to pointer in the wrappers was preventing a vector of pointers from working
|
||||
C** makeCIntPtrPtr(C* v) {
|
||||
return new C*(v);
|
||||
}
|
||||
C *makeC(int val) { return new C(val); }
|
||||
int getVal(C* b) { return b->val; }
|
||||
int getVectorValueC(std::vector<C *> vpi, size_t index) {
|
||||
return vpi[index]->val;
|
||||
}
|
||||
%}
|
||||
|
||||
|
|
|
|||
|
|
@ -109,7 +109,11 @@ namespace test {
|
|||
#ifdef SWIGGO
|
||||
%typemap(gotype) string_class * "string"
|
||||
%typemap(in) string_class * {
|
||||
$1 = new string_class($input.p);
|
||||
char* buf = new char[$input.n + 1];
|
||||
memcpy(buf, $input.p, $input.n);
|
||||
buf[$input.n] = '\0';
|
||||
$1 = new string_class(buf);
|
||||
delete[] buf;
|
||||
}
|
||||
%typemap(freearg) string_class * {
|
||||
delete $1;
|
||||
|
|
|
|||
|
|
@ -13,6 +13,18 @@ Also tests reported error when a #define placed in a deeply embedded struct/unio
|
|||
%rename(InUnNamed) OuterStructNamed::Inner_union_named;
|
||||
#endif
|
||||
|
||||
#if defined(SWIG_JAVASCRIPT_V8)
|
||||
|
||||
%inline %{
|
||||
#if __GNUC__ >= 5 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 8)
|
||||
/* for nested C class wrappers compiled as C++ code */
|
||||
/* dereferencing type-punned pointer will break strict-aliasing rules [-Werror=strict-aliasing] */
|
||||
#pragma GCC diagnostic ignored "-Wstrict-aliasing"
|
||||
#endif
|
||||
%}
|
||||
|
||||
#endif
|
||||
|
||||
%inline %{
|
||||
|
||||
struct TestStruct {
|
||||
|
|
|
|||
|
|
@ -1,5 +1,17 @@
|
|||
%module nested_extend_c
|
||||
|
||||
#if defined(SWIG_JAVASCRIPT_V8)
|
||||
|
||||
%inline %{
|
||||
#if __GNUC__ >= 5 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 8)
|
||||
/* for nested C class wrappers compiled as C++ code */
|
||||
/* dereferencing type-punned pointer will break strict-aliasing rules [-Werror=strict-aliasing] */
|
||||
#pragma GCC diagnostic ignored "-Wstrict-aliasing"
|
||||
#endif
|
||||
%}
|
||||
|
||||
#endif
|
||||
|
||||
#if !defined(SWIGOCTAVE) && !defined(SWIG_JAVASCRIPT_V8)
|
||||
%extend hiA {
|
||||
hiA() {
|
||||
|
|
@ -98,5 +110,9 @@ typedef struct {
|
|||
static struct {
|
||||
int i;
|
||||
} THING;
|
||||
|
||||
int useThing() {
|
||||
return THING.i;
|
||||
}
|
||||
%}
|
||||
|
||||
|
|
|
|||
24
Examples/test-suite/nested_ignore.i
Normal file
24
Examples/test-suite/nested_ignore.i
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
%module nested_ignore
|
||||
%warnfilter(SWIGWARN_PARSE_NAMED_NESTED_CLASS) B::C::D;
|
||||
|
||||
%rename($ignore) B::C;
|
||||
|
||||
%inline %{
|
||||
namespace B {
|
||||
class C {
|
||||
public:
|
||||
struct D {
|
||||
};
|
||||
};
|
||||
|
||||
class E {
|
||||
public:
|
||||
typedef C::D D;
|
||||
};
|
||||
|
||||
struct F
|
||||
{
|
||||
const E::D foo(){ return E::D(); }
|
||||
};
|
||||
}
|
||||
%}
|
||||
|
|
@ -1,5 +1,17 @@
|
|||
%module nested_structs
|
||||
|
||||
#if defined(SWIG_JAVASCRIPT_V8)
|
||||
|
||||
%inline %{
|
||||
#if __GNUC__ >= 5 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 8)
|
||||
/* for nested C class wrappers compiled as C++ code */
|
||||
/* dereferencing type-punned pointer will break strict-aliasing rules [-Werror=strict-aliasing] */
|
||||
#pragma GCC diagnostic ignored "-Wstrict-aliasing"
|
||||
#endif
|
||||
%}
|
||||
|
||||
#endif
|
||||
|
||||
// bug #491476
|
||||
%inline %{
|
||||
struct Outer {
|
||||
|
|
|
|||
|
|
@ -78,6 +78,10 @@ see bottom for a set of possible tests
|
|||
%rename(OrOperator) operator ||;
|
||||
#endif
|
||||
|
||||
#if defined(SWIGPYTHON)
|
||||
%feature("python:slot", "tp_str", functype="reprfunc") Op::__str__;
|
||||
#endif
|
||||
|
||||
#ifdef SWIGD
|
||||
// Due to the way operator overloading is implemented in D1 and D2, the prefix
|
||||
// increment/decrement operators (D1) resp. the postfix ones (D2) are ignored.
|
||||
|
|
@ -94,8 +98,6 @@ see bottom for a set of possible tests
|
|||
#include <iso646.h> /* for named logical operator, eg 'operator or' */
|
||||
#endif
|
||||
|
||||
#include <assert.h>
|
||||
|
||||
class Op {
|
||||
public:
|
||||
int i;
|
||||
|
|
@ -114,11 +116,11 @@ public:
|
|||
return *this;
|
||||
}
|
||||
// +=,-=... are member fns
|
||||
void operator+=(const Op& o){ i+=o.i;}
|
||||
void operator-=(const Op& o){ i-=o.i;}
|
||||
void operator*=(const Op& o){ i*=o.i;}
|
||||
void operator/=(const Op& o){ i/=o.i;}
|
||||
void operator%=(const Op& o){ i%=o.i;}
|
||||
Op &operator+=(const Op& o){ i+=o.i; return *this; }
|
||||
Op &operator-=(const Op& o){ i-=o.i; return *this; }
|
||||
Op &operator*=(const Op& o){ i*=o.i; return *this; }
|
||||
Op &operator/=(const Op& o){ i/=o.i; return *this; }
|
||||
Op &operator%=(const Op& o){ i%=o.i; return *this; }
|
||||
// the +,-,*,... are friends
|
||||
// (just to make life harder)
|
||||
friend Op operator+(const Op& a,const Op& b){return Op(a.i+b.i);}
|
||||
|
|
@ -250,8 +252,8 @@ public:
|
|||
|
||||
|
||||
%{
|
||||
|
||||
#include <assert.h>
|
||||
#include <stdexcept>
|
||||
#define ASSERT(X) { if (!(X)) { throw std::runtime_error(#X); } }
|
||||
|
||||
void Op::sanity_check()
|
||||
{
|
||||
|
|
@ -263,66 +265,66 @@ void Op::sanity_check()
|
|||
Op dd=d; // assignment operator
|
||||
|
||||
// test equality
|
||||
assert(a!=b);
|
||||
assert(b==c);
|
||||
assert(a!=d);
|
||||
assert(d==dd);
|
||||
ASSERT(a!=b);
|
||||
ASSERT(b==c);
|
||||
ASSERT(a!=d);
|
||||
ASSERT(d==dd);
|
||||
|
||||
// test <
|
||||
assert(a<b);
|
||||
assert(a<=b);
|
||||
assert(b<=c);
|
||||
assert(b>=c);
|
||||
assert(b>d);
|
||||
assert(b>=d);
|
||||
ASSERT(a<b);
|
||||
ASSERT(a<=b);
|
||||
ASSERT(b<=c);
|
||||
ASSERT(b>=c);
|
||||
ASSERT(b>d);
|
||||
ASSERT(b>=d);
|
||||
|
||||
// test +=
|
||||
Op e=3;
|
||||
e+=d;
|
||||
assert(e==b);
|
||||
ASSERT(e==b);
|
||||
e-=c;
|
||||
assert(e==a);
|
||||
ASSERT(e==a);
|
||||
e=Op(1);
|
||||
e*=b;
|
||||
assert(e==c);
|
||||
ASSERT(e==c);
|
||||
e/=d;
|
||||
assert(e==d);
|
||||
ASSERT(e==d);
|
||||
e%=c;
|
||||
assert(e==d);
|
||||
ASSERT(e==d);
|
||||
|
||||
// test +
|
||||
Op f(1),g(1);
|
||||
assert(f+g==Op(2));
|
||||
assert(f-g==Op(0));
|
||||
assert(f*g==Op(1));
|
||||
assert(f/g==Op(1));
|
||||
assert(f%g==Op(0));
|
||||
ASSERT(f+g==Op(2));
|
||||
ASSERT(f-g==Op(0));
|
||||
ASSERT(f*g==Op(1));
|
||||
ASSERT(f/g==Op(1));
|
||||
ASSERT(f%g==Op(0));
|
||||
|
||||
// test unary operators
|
||||
assert(!a==true);
|
||||
assert(!b==false);
|
||||
assert(-a==a);
|
||||
assert(-b==Op(-5));
|
||||
ASSERT(!a==true);
|
||||
ASSERT(!b==false);
|
||||
ASSERT(-a==a);
|
||||
ASSERT(-b==Op(-5));
|
||||
|
||||
// test []
|
||||
Op h=3;
|
||||
assert(h[0]==3);
|
||||
assert(h[1]==0);
|
||||
ASSERT(h[0]==3);
|
||||
ASSERT(h[1]==0);
|
||||
h[0]=2; // set
|
||||
assert(h[0]==2);
|
||||
ASSERT(h[0]==2);
|
||||
h[1]=2; // ignored
|
||||
assert(h[0]==2);
|
||||
assert(h[1]==0);
|
||||
ASSERT(h[0]==2);
|
||||
ASSERT(h[1]==0);
|
||||
|
||||
// test ()
|
||||
Op i=3;
|
||||
assert(i()==3);
|
||||
assert(i(1)==4);
|
||||
assert(i(1,2)==6);
|
||||
ASSERT(i()==3);
|
||||
ASSERT(i(1)==4);
|
||||
ASSERT(i(1,2)==6);
|
||||
|
||||
// plus add some code to check the __str__ fn
|
||||
//assert(str(Op(1))=="Op(1)");
|
||||
//assert(str(Op(-3))=="Op(-3)");
|
||||
//ASSERT(str(Op(1))=="Op(1)");
|
||||
//ASSERT(str(Op(-3))=="Op(-3)");
|
||||
|
||||
// test ++ and --
|
||||
Op j(100);
|
||||
|
|
@ -330,36 +332,36 @@ void Op::sanity_check()
|
|||
{
|
||||
Op newOp = j++;
|
||||
int newInt = original++;
|
||||
assert(j.i == original);
|
||||
assert(newOp.i == newInt);
|
||||
ASSERT(j.i == original);
|
||||
ASSERT(newOp.i == newInt);
|
||||
}
|
||||
{
|
||||
Op newOp = j--;
|
||||
int newInt = original--;
|
||||
assert(j.i == original);
|
||||
assert(newOp.i == newInt);
|
||||
ASSERT(j.i == original);
|
||||
ASSERT(newOp.i == newInt);
|
||||
}
|
||||
{
|
||||
Op newOp = ++j;
|
||||
int newInt = ++original;
|
||||
assert(j.i == original);
|
||||
assert(newOp.i == newInt);
|
||||
ASSERT(j.i == original);
|
||||
ASSERT(newOp.i == newInt);
|
||||
}
|
||||
{
|
||||
Op newOp = --j;
|
||||
int newInt = --original;
|
||||
assert(j.i == original);
|
||||
assert(newOp.i == newInt);
|
||||
ASSERT(j.i == original);
|
||||
ASSERT(newOp.i == newInt);
|
||||
}
|
||||
|
||||
// cast operators
|
||||
Op k=3;
|
||||
int check_k = k;
|
||||
assert (check_k == 3);
|
||||
ASSERT (check_k == 3);
|
||||
|
||||
Op l=4;
|
||||
double check_l = l;
|
||||
assert (check_l == 4);
|
||||
ASSERT (check_l == 4);
|
||||
}
|
||||
|
||||
%}
|
||||
|
|
|
|||
20
Examples/test-suite/php/cpp_basic_runme.php
Normal file
20
Examples/test-suite/php/cpp_basic_runme.php
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
<?php
|
||||
|
||||
require "tests.php";
|
||||
require "cpp_basic.php";
|
||||
|
||||
// New functions
|
||||
check::functions(array(foo_func1,foo_func2,foo___str__,foosubsub___str__,bar_test,bar_testfoo,get_func1_ptr,get_func2_ptr,test_func_ptr,fl_window_show));
|
||||
// New classes
|
||||
check::classes(array(cpp_basic,Foo,FooSub,FooSubSub,Bar,Fl_Window));
|
||||
// New vars
|
||||
check::globals(array(foo_num,foo_func_ptr,bar_fptr,bar_fref,bar_fval,bar_cint,bar_global_fptr,bar_global_fref,bar_global_fval));
|
||||
|
||||
$f = new Foo(3);
|
||||
$f->func_ptr = get_func1_ptr();
|
||||
check::equal(test_func_ptr($f, 7), 2*7*3, "get_func1_ptr() didn't work");
|
||||
$f->func_ptr = get_func2_ptr();
|
||||
check::equal(test_func_ptr($f, 7), -7*3, "get_func2_ptr() didn't work");
|
||||
|
||||
check::done();
|
||||
?>
|
||||
24
Examples/test-suite/php/director_pass_by_value_runme.php
Normal file
24
Examples/test-suite/php/director_pass_by_value_runme.php
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
<?php
|
||||
|
||||
require "tests.php";
|
||||
require "director_pass_by_value.php";
|
||||
|
||||
$passByVal = null;
|
||||
|
||||
class director_pass_by_value_Derived extends DirectorPassByValueAbstractBase {
|
||||
function virtualMethod($b) {
|
||||
global $passByVal;
|
||||
$passByVal = $b;
|
||||
}
|
||||
}
|
||||
|
||||
# bug was the passByVal global object was destroyed after the call to virtualMethod had finished.
|
||||
$caller = new Caller();
|
||||
$caller->call_virtualMethod(new director_pass_by_value_Derived());
|
||||
$ret = $passByVal->getVal();
|
||||
if ($ret != 0x12345678) {
|
||||
check::fail("Bad return value, got " . dechex($ret));
|
||||
}
|
||||
|
||||
check::done();
|
||||
?>
|
||||
|
|
@ -35,8 +35,9 @@ class check {
|
|||
foreach($_original_functions[internal] as $func) unset($df[$func]);
|
||||
// Now chop out any get/set accessors
|
||||
foreach(array_keys($df) as $func)
|
||||
if ((GETSET && ereg('_[gs]et$',$func)) || ereg('^new_', $func)
|
||||
|| ereg('_(alter|get)_newobject$', $func))
|
||||
if ((GETSET && preg_match('/_[gs]et$/', $func)) ||
|
||||
preg_match('/^new_/', $func) ||
|
||||
preg_match('/_(alter|get)_newobject$/', $func))
|
||||
$extrags[]=$func;
|
||||
else $extra[]=$func;
|
||||
// $extra=array_keys($df);
|
||||
|
|
@ -52,7 +53,8 @@ class check {
|
|||
if (GETSET) {
|
||||
$_extra=array();
|
||||
foreach(check::get_extra_functions(false,1) as $global) {
|
||||
if (ereg('^(.*)_[sg]et$',$global,$match)) $_extra[$match[1]]=1;
|
||||
if (preg_match('/^(.*)_[sg]et$/', $global, $match))
|
||||
$_extra[$match[1]] = 1;
|
||||
}
|
||||
$extra=array_keys($_extra);
|
||||
} else {
|
||||
|
|
@ -61,7 +63,8 @@ class check {
|
|||
$df=array_flip(array_keys($GLOBALS));
|
||||
foreach($_original_globals as $func) unset($df[$func]);
|
||||
// MASK xxxx_LOADED__ variables
|
||||
foreach(array_keys($df) as $func) if (ereg('_LOADED__$',$func)) unset($df[$func]);
|
||||
foreach(array_keys($df) as $func)
|
||||
if (preg_match('/_LOADED__$/', $func)) unset($df[$func]);
|
||||
$extra=array_keys($df);
|
||||
}
|
||||
}
|
||||
|
|
@ -185,7 +188,8 @@ class check {
|
|||
}
|
||||
|
||||
function functionref($a,$type,$message) {
|
||||
if (! eregi("^_[a-f0-9]+$type$",$a)) return check::fail($message);
|
||||
if (! preg_match("/^_[a-f0-9]+$type$/i", $a))
|
||||
return check::fail($message);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
|
@ -196,7 +200,8 @@ class check {
|
|||
|
||||
function resource($a,$b,$message) {
|
||||
$resource=trim(check::var_dump($a));
|
||||
if (! eregi("^resource\([0-9]+\) of type \($b\)",$resource)) return check::fail($message);
|
||||
if (! preg_match("/^resource\([0-9]+\) of type \($b\)/i", $resource))
|
||||
return check::fail($message);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -102,6 +102,7 @@ ANOTHER_MACRO(int)
|
|||
void another_macro_checking(void) {
|
||||
struct Defined d;
|
||||
d.defined = 10;
|
||||
(void)d;
|
||||
thing(10);
|
||||
stuff(10);
|
||||
bumpf(10);
|
||||
|
|
|
|||
|
|
@ -58,6 +58,7 @@ CPP_TEST_CASES += \
|
|||
primitive_types \
|
||||
python_abstractbase \
|
||||
python_append \
|
||||
python_builtin \
|
||||
python_destructor_exception \
|
||||
python_director \
|
||||
python_docstring \
|
||||
|
|
|
|||
|
|
@ -15,11 +15,19 @@ def check(got, expected, expected_builtin=None, skip=False):
|
|||
def is_new_style_class(cls):
|
||||
return hasattr(cls, "__class__")
|
||||
|
||||
def is_fastproxy(module):
|
||||
return "new_instancemethod" in module
|
||||
|
||||
if not is_new_style_class(A):
|
||||
# Missing static methods make this hard to test... skip if -classic is
|
||||
# used!
|
||||
sys.exit(0)
|
||||
|
||||
if is_fastproxy(dir()):
|
||||
# Detect when -fastproxy is specified and skip test as it changes the function names making it
|
||||
# hard to test... skip until the number of options are reduced in SWIG-3.1 and autodoc is improved
|
||||
sys.exit(0)
|
||||
|
||||
# skip builtin check - the autodoc is missing, but it probably should not be
|
||||
skip = True
|
||||
|
||||
|
|
|
|||
32
Examples/test-suite/python/cpp11_type_aliasing_runme.py
Normal file
32
Examples/test-suite/python/cpp11_type_aliasing_runme.py
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
from cpp11_type_aliasing import *
|
||||
|
||||
if get_host_target().bits != 32:
|
||||
raise RuntimeError("get_host_target().bits should return 32")
|
||||
|
||||
if mult2(10) != 20:
|
||||
raise RuntimeError("mult2(10) should return 20")
|
||||
|
||||
int_ptr = allocate_int()
|
||||
inplace_mult2(int_ptr)
|
||||
if read_int(int_ptr) != 24:
|
||||
raise RuntimeError("read_int should return 24")
|
||||
free_int(int_ptr)
|
||||
|
||||
pair = PairSubclass(3, 4)
|
||||
if pair.first() != 3:
|
||||
raise RuntimeError("pair.first() should return 3")
|
||||
|
||||
if pair.second() != 4:
|
||||
raise RuntimeError("pair.second() should return 4")
|
||||
|
||||
if pair.a != 3:
|
||||
raise RuntimeError("pair.a should be 3")
|
||||
|
||||
if plus1(5) != 6:
|
||||
raise RuntimeError("plus1(5) should return 6")
|
||||
|
||||
if call(mult2_cb, 7) != 14:
|
||||
raise RuntimeError("call(mult2_cb, 7) should return 14")
|
||||
|
||||
if call(get_callback(), 7) != 14:
|
||||
raise RuntimeError("call(get_callback(), 7) should return 14")
|
||||
|
|
@ -14,4 +14,5 @@ else:
|
|||
StaticFunctionTest().static_func_2(1)
|
||||
StaticFunctionTest().static_func_3(1, 2)
|
||||
StaticMemberTest.static_int = 10
|
||||
assert StaticMemberTest.static_int == 10
|
||||
if not StaticMemberTest.static_int == 10:
|
||||
raise RuntimeError("static_int not 10")
|
||||
|
|
|
|||
6
Examples/test-suite/python/default_args_c_runme.py
Normal file
6
Examples/test-suite/python/default_args_c_runme.py
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
import default_args_c
|
||||
|
||||
if default_args_c.foo1() != 1:
|
||||
raise RuntimeError("failed")
|
||||
if default_args_c.foo43() != 43:
|
||||
raise RuntimeError("failed")
|
||||
13
Examples/test-suite/python/director_pass_by_value_runme.py
Normal file
13
Examples/test-suite/python/director_pass_by_value_runme.py
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
import director_pass_by_value
|
||||
|
||||
passByVal = None
|
||||
class director_pass_by_value_Derived(director_pass_by_value.DirectorPassByValueAbstractBase):
|
||||
def virtualMethod(self, b):
|
||||
global passByVal
|
||||
passByVal = b
|
||||
|
||||
# bug was the passByVal global object was destroyed after the call to virtualMethod had finished.
|
||||
director_pass_by_value.Caller().call_virtualMethod(director_pass_by_value_Derived())
|
||||
ret = passByVal.getVal();
|
||||
if ret != 0x12345678:
|
||||
raise RuntimeError("Bad return value, got " + hex(ret))
|
||||
|
|
@ -1,4 +1,5 @@
|
|||
import exception_classname
|
||||
|
||||
a = exception_classname.Exception()
|
||||
assert a.testfunc() == 42
|
||||
if a.testfunc() != 42:
|
||||
raise RuntimeError("Not 42!")
|
||||
|
|
|
|||
|
|
@ -8,9 +8,8 @@ if d.bar() != 2:
|
|||
raise RuntimeError
|
||||
if bar_getter(b) != 1:
|
||||
raise RuntimeError
|
||||
# Fix reverted in rev 12953
|
||||
# if bar_getter(d) != 2:
|
||||
# raise RuntimeError
|
||||
if bar_getter(d) != 2:
|
||||
raise RuntimeError
|
||||
|
||||
b = BaseDefaultInt()
|
||||
d = DerivedDefaultInt()
|
||||
|
|
@ -23,8 +22,11 @@ if d2.bar2() != 4:
|
|||
raise RuntimeError
|
||||
if bar2_getter(b) != 3:
|
||||
raise RuntimeError
|
||||
# Fix reverted in rev 12953
|
||||
# if bar2_getter(d) != 4:
|
||||
# raise RuntimeError
|
||||
# if bar2_getter(d2) != 4:
|
||||
# raise RuntimeError
|
||||
# SWIG fix reverted in Subversion rev 12953
|
||||
# Testcase has now been modified to mask the problem by providing the default parameter 'int' in:
|
||||
# %shared_ptr(Space::BaseDefault<short, int>)
|
||||
# If this is not done then d fails to convert to BaseDefault<short>&
|
||||
if bar2_getter(d) != 4:
|
||||
raise RuntimeError
|
||||
if bar2_getter(d2) != 4:
|
||||
raise RuntimeError
|
||||
|
|
|
|||
|
|
@ -1,7 +1,38 @@
|
|||
from li_std_vector_ptr import *
|
||||
|
||||
def check(val1, val2):
|
||||
if val1 != val2:
|
||||
raise RuntimeError("Values are not the same %s %s" % (val1, val2))
|
||||
ip1 = makeIntPtr(11)
|
||||
ip2 = makeIntPtr(22)
|
||||
|
||||
vi = IntPtrVector((ip1, ip2))
|
||||
displayVector(vi)
|
||||
check(getValueFromVector(vi, 0), 11)
|
||||
check(getValueFromVector(vi, 1), 22)
|
||||
|
||||
vA = APtrVector([makeA(33), makeA(34)])
|
||||
check(getVectorValueA(vA, 0), 33)
|
||||
|
||||
vB = BPtrVector([makeB(133), makeB(134)])
|
||||
check(getVectorValueB(vB, 0), 133)
|
||||
|
||||
vC = CPtrVector([makeC(1133), makeC(1134)])
|
||||
check(getVectorValueC(vC, 0), 1133)
|
||||
|
||||
|
||||
vA = [makeA(233), makeA(234)]
|
||||
check(getVectorValueA(vA, 0), 233)
|
||||
|
||||
vB = [makeB(333), makeB(334)]
|
||||
check(getVectorValueB(vB, 0), 333)
|
||||
|
||||
vC = [makeC(3333), makeC(3334)]
|
||||
check(getVectorValueC(vC, 0), 3333)
|
||||
|
||||
# mixed A and B should not be accepted
|
||||
vAB = [makeA(999), makeB(999)]
|
||||
try:
|
||||
check(getVectorValueA(vAB, 0), 999)
|
||||
raise RuntimeError("missed exception")
|
||||
except TypeError:
|
||||
pass
|
||||
|
|
|
|||
77
Examples/test-suite/python/operator_overload_runme.py
Normal file
77
Examples/test-suite/python/operator_overload_runme.py
Normal file
|
|
@ -0,0 +1,77 @@
|
|||
from operator_overload import *
|
||||
|
||||
# first check all the operators are implemented correctly from pure C++ code
|
||||
Op_sanity_check()
|
||||
|
||||
pop = Op(6)/Op(3)
|
||||
|
||||
# test routine:
|
||||
a=Op()
|
||||
b=Op(5)
|
||||
c=Op(b) # copy construct
|
||||
d=Op(2)
|
||||
dd=d # assignment operator
|
||||
|
||||
# test equality
|
||||
if not a!=b:
|
||||
raise RuntimeError("a!=b")
|
||||
if not b==c:
|
||||
raise RuntimeError("b==c")
|
||||
if not a!=d:
|
||||
raise RuntimeError("a!=d")
|
||||
if not d==dd:
|
||||
raise RuntimeError("d==dd")
|
||||
|
||||
# test <
|
||||
if not a<b:
|
||||
raise RuntimeError("a<b")
|
||||
if not a<=b:
|
||||
raise RuntimeError("a<=b")
|
||||
if not b<=c:
|
||||
raise RuntimeError("b<=c")
|
||||
if not b>=c:
|
||||
raise RuntimeError("b>=c")
|
||||
if not b>d:
|
||||
raise RuntimeError("b>d")
|
||||
if not b>=d:
|
||||
raise RuntimeError("b>=d")
|
||||
|
||||
# test +=
|
||||
e=Op(3)
|
||||
e+=d
|
||||
if not e==b:
|
||||
raise RuntimeError("e==b (%s==%s)" % (e.i, b.i))
|
||||
e-=c
|
||||
if not e==a:
|
||||
raise RuntimeError("e==a")
|
||||
e=Op(1)
|
||||
e*=b
|
||||
if not e==c:
|
||||
raise RuntimeError("e==c")
|
||||
e/=d
|
||||
if not e==d:
|
||||
raise RuntimeError("e==d")
|
||||
e%=c;
|
||||
if not e==d:
|
||||
raise RuntimeError("e==d")
|
||||
|
||||
# test +
|
||||
f=Op(1)
|
||||
g=Op(1)
|
||||
if not f+g==Op(2):
|
||||
raise RuntimeError("f+g==Op(2)")
|
||||
if not f-g==Op(0):
|
||||
raise RuntimeError("f-g==Op(0)")
|
||||
if not f*g==Op(1):
|
||||
raise RuntimeError("f*g==Op(1)")
|
||||
if not f/g==Op(1):
|
||||
raise RuntimeError("f/g==Op(1)")
|
||||
if not f%g==Op(0):
|
||||
raise RuntimeError("f%g==Op(0)")
|
||||
|
||||
# test unary operators
|
||||
if not -a==a:
|
||||
raise RuntimeError("-a==a")
|
||||
if not -b==Op(-5):
|
||||
raise RuntimeError("-b==Op(-5)")
|
||||
|
||||
|
|
@ -1,3 +1,4 @@
|
|||
#!/usr/bin/env python
|
||||
import operbool
|
||||
assert not operbool.Test()
|
||||
if operbool.Test():
|
||||
raise RuntimeError("operbool failed")
|
||||
|
|
|
|||
|
|
@ -6,6 +6,10 @@ from collections import *
|
|||
if is_python_builtin():
|
||||
exit(0)
|
||||
|
||||
# Python abc is only turned on when -py3 option is passed to SWIG
|
||||
if not is_swig_py3:
|
||||
exit(0)
|
||||
|
||||
assert issubclass(Mapii, MutableMapping)
|
||||
assert issubclass(Multimapii, MutableMapping)
|
||||
assert issubclass(IntSet, MutableSet)
|
||||
|
|
|
|||
81
Examples/test-suite/python/python_builtin_runme.py
Normal file
81
Examples/test-suite/python/python_builtin_runme.py
Normal file
|
|
@ -0,0 +1,81 @@
|
|||
from python_builtin import *
|
||||
|
||||
if is_python_builtin():
|
||||
# Test 0 for default tp_hash
|
||||
vs = ValueStruct(1234)
|
||||
h = hash(vs)
|
||||
d = dict()
|
||||
d[h] = "hi"
|
||||
if h not in d:
|
||||
raise RuntimeError("h should be in d")
|
||||
h2 = hash(ValueStruct.inout(vs))
|
||||
if h != h2:
|
||||
raise RuntimeError("default tp_hash not working")
|
||||
|
||||
# Test 1 for tp_hash
|
||||
if hash(SimpleValue(222)) != 222:
|
||||
raise RuntimeError("tp_hash not working")
|
||||
|
||||
# Test 2 for tp_hash
|
||||
try:
|
||||
# Was incorrectly raising: SystemError: error return without exception set
|
||||
h = hash(BadHashFunctionReturnType())
|
||||
raise RuntimeError("Missing TypeError")
|
||||
except TypeError:
|
||||
pass
|
||||
|
||||
# Test 3 for tp_hash
|
||||
passed = False
|
||||
try:
|
||||
h = hash(ExceptionHashFunction())
|
||||
except RuntimeError, e:
|
||||
passed = str(e).find("oops") != -1
|
||||
pass
|
||||
|
||||
if not passed:
|
||||
raise RuntimeError("did not catch exception in hash()")
|
||||
|
||||
# Test 4 for tp_dealloc (which is handled differently to other slots in the SWIG source)
|
||||
d = Dealloc1()
|
||||
if cvar.Dealloc1CalledCount != 0:
|
||||
raise RuntimeError("count should be 0")
|
||||
del d
|
||||
if cvar.Dealloc1CalledCount != 1:
|
||||
raise RuntimeError("count should be 1")
|
||||
|
||||
d = Dealloc2()
|
||||
if cvar.Dealloc2CalledCount != 0:
|
||||
raise RuntimeError("count should be 0")
|
||||
del d
|
||||
if cvar.Dealloc2CalledCount != 1:
|
||||
raise RuntimeError("count should be 1")
|
||||
|
||||
d = Dealloc3()
|
||||
if cvar.Dealloc3CalledCount != 0:
|
||||
raise RuntimeError("count should be 0")
|
||||
del d
|
||||
if cvar.Dealloc3CalledCount != 1:
|
||||
raise RuntimeError("count should be 1")
|
||||
|
||||
# Test 5 for python:compare feature
|
||||
m10 = MyClass(10)
|
||||
m20 = MyClass(20)
|
||||
m15 = MyClass(15)
|
||||
|
||||
if not m10 < m15:
|
||||
raise RuntimeError("m10 < m15")
|
||||
if not m10 < m20:
|
||||
raise RuntimeError("m10 < m20")
|
||||
if not m15 < m20:
|
||||
raise RuntimeError("m15 < m20")
|
||||
|
||||
if m10 > m15:
|
||||
raise RuntimeError("m10 > m15")
|
||||
if m10 > m20:
|
||||
raise RuntimeError("m10 > m20")
|
||||
if m15 > m20:
|
||||
raise RuntimeError("m15 > m20")
|
||||
|
||||
if MyClass.less_than_counts != 6:
|
||||
raise RuntimeError("python:compare feature not working")
|
||||
|
||||
|
|
@ -26,8 +26,10 @@ def test1():
|
|||
sys.stderr.flush()
|
||||
sys.stderr = stderr_saved
|
||||
|
||||
assert attributeErrorOccurred
|
||||
assert buffer.getvalue().count("I am the ClassWithThrowingDestructor dtor doing bad things") >= 1
|
||||
if not attributeErrorOccurred:
|
||||
raise RuntimeError("attributeErrorOccurred failed")
|
||||
if not buffer.getvalue().count("I am the ClassWithThrowingDestructor dtor doing bad things") >= 1:
|
||||
raise RuntimeError("ClassWithThrowingDestructor dtor doing bad things failed")
|
||||
|
||||
class VectorHolder(object):
|
||||
def __init__(self, v):
|
||||
|
|
|
|||
|
|
@ -0,0 +1,20 @@
|
|||
from template_default_arg_overloaded_extend import *
|
||||
|
||||
def check(flag):
|
||||
if not flag:
|
||||
raise RuntimeError("failed")
|
||||
|
||||
rs = ResultSet()
|
||||
|
||||
check(rs.go_get_method(0, SearchPoint()) == -1)
|
||||
check(rs.go_get_method(0, SearchPoint(), 100) == 100)
|
||||
|
||||
check(rs.go_get_template(0, SearchPoint()) == -2)
|
||||
check(rs.go_get_template(0, SearchPoint(), 100) == 100)
|
||||
|
||||
check(rs.over() == "over(int)")
|
||||
check(rs.over(10) == "over(int)")
|
||||
check(rs.over(SearchPoint()) == "over(giai2::SearchPoint, int)")
|
||||
check(rs.over(SearchPoint(), 10) == "over(giai2::SearchPoint, int)")
|
||||
check(rs.over(True, SearchPoint()) == "over(bool, gaia2::SearchPoint, int)")
|
||||
check(rs.over(True, SearchPoint(), 10) == "over(bool, gaia2::SearchPoint, int)")
|
||||
|
|
@ -13,11 +13,15 @@ if sys.version_info[0:2] >= (3, 1):
|
|||
if unicode_strings.non_utf8_std_string() != test_string:
|
||||
raise ValueError('Test comparison mismatch')
|
||||
|
||||
def check(s1, s2):
|
||||
if s1 != s2:
|
||||
raise RuntimeError("{} != {}".format(s1, s2))
|
||||
|
||||
# Testing SWIG_PYTHON_2_UNICODE flag which allows unicode strings to be passed to C
|
||||
if sys.version_info[0:2] < (3, 0):
|
||||
assert unicode_strings.charstring("hello1") == "hello1"
|
||||
assert unicode_strings.charstring(str(u"hello2")) == "hello2"
|
||||
assert unicode_strings.charstring(u"hello3") == "hello3"
|
||||
assert unicode_strings.charstring(unicode("hello4")) == "hello4"
|
||||
check(unicode_strings.charstring("hello1"), "hello1")
|
||||
check(unicode_strings.charstring(str(u"hello2")), "hello2")
|
||||
check(unicode_strings.charstring(u"hello3"), "hello3")
|
||||
check(unicode_strings.charstring(unicode("hello4")), "hello4")
|
||||
unicode_strings.charstring(u"hell\xb05")
|
||||
unicode_strings.charstring(u"hell\u00f66")
|
||||
|
|
|
|||
|
|
@ -24,3 +24,9 @@ bool is_python_builtin() { return true; }
|
|||
bool is_python_builtin() { return false; }
|
||||
#endif
|
||||
%}
|
||||
|
||||
#ifdef SWIGPYTHON_PY3 // set when using -py3
|
||||
#define is_swig_py3 1
|
||||
#else
|
||||
#define is_swig_py3 0
|
||||
#endif
|
||||
|
|
|
|||
138
Examples/test-suite/python_builtin.i
Normal file
138
Examples/test-suite/python_builtin.i
Normal file
|
|
@ -0,0 +1,138 @@
|
|||
// Test customizing slots when using the -builtin option
|
||||
|
||||
%module python_builtin
|
||||
|
||||
%inline %{
|
||||
#ifdef SWIGPYTHON_BUILTIN
|
||||
bool is_python_builtin() { return true; }
|
||||
#else
|
||||
bool is_python_builtin() { return false; }
|
||||
#endif
|
||||
%}
|
||||
|
||||
// Test 0 for default tp_hash
|
||||
%inline %{
|
||||
struct ValueStruct {
|
||||
int value;
|
||||
ValueStruct(int value) : value(value) {}
|
||||
static ValueStruct *inout(ValueStruct *v) {
|
||||
return v;
|
||||
}
|
||||
};
|
||||
%}
|
||||
|
||||
// Test 1 for tp_hash
|
||||
#if defined(SWIGPYTHON_BUILTIN)
|
||||
%feature("python:tp_hash") SimpleValue "SimpleValueHashFunction"
|
||||
#endif
|
||||
|
||||
%inline %{
|
||||
struct SimpleValue {
|
||||
int value;
|
||||
SimpleValue(int value) : value(value) {}
|
||||
};
|
||||
%}
|
||||
|
||||
%{
|
||||
#if PY_VERSION_HEX >= 0x03020000
|
||||
Py_hash_t SimpleValueHashFunction(PyObject *v)
|
||||
#else
|
||||
long SimpleValueHashFunction(PyObject *v)
|
||||
#endif
|
||||
{
|
||||
SwigPyObject *sobj = (SwigPyObject *) v;
|
||||
SimpleValue *p = (SimpleValue *)sobj->ptr;
|
||||
return p->value;
|
||||
}
|
||||
hashfunc test_hashfunc_cast() {
|
||||
return SimpleValueHashFunction;
|
||||
}
|
||||
%}
|
||||
|
||||
// Test 2 for tp_hash
|
||||
#if defined(SWIGPYTHON_BUILTIN)
|
||||
%feature("python:slot", "tp_hash", functype="hashfunc") BadHashFunctionReturnType::bad_hash_function;
|
||||
#endif
|
||||
|
||||
%inline %{
|
||||
struct BadHashFunctionReturnType {
|
||||
static const char * bad_hash_function() {
|
||||
return "bad hash function";
|
||||
}
|
||||
};
|
||||
%}
|
||||
|
||||
// Test 3 for tp_hash
|
||||
#if defined(SWIGPYTHON_BUILTIN)
|
||||
%feature("python:slot", "tp_hash", functype="hashfunc") ExceptionHashFunction::exception_hash_function;
|
||||
#endif
|
||||
|
||||
%catches(const char *) exception_hash_function;
|
||||
|
||||
%inline %{
|
||||
#if PY_VERSION_HEX < 0x03020000
|
||||
#define Py_hash_t long
|
||||
#endif
|
||||
struct ExceptionHashFunction {
|
||||
static Py_hash_t exception_hash_function() {
|
||||
throw "oops";
|
||||
}
|
||||
};
|
||||
%}
|
||||
|
||||
// Test 4 for tp_dealloc (which is handled differently to other slots in the SWIG source)
|
||||
#if defined(SWIGPYTHON_BUILTIN)
|
||||
%feature("python:tp_dealloc") Dealloc1 "Dealloc1Destroyer"
|
||||
%feature("python:tp_dealloc") Dealloc2 "Dealloc2Destroyer"
|
||||
%feature("python:slot", "tp_dealloc", functype="destructor") Dealloc3::Destroyer;
|
||||
#endif
|
||||
|
||||
%inline %{
|
||||
static int Dealloc1CalledCount = 0;
|
||||
static int Dealloc2CalledCount = 0;
|
||||
static int Dealloc3CalledCount = 0;
|
||||
|
||||
struct Dealloc1 {
|
||||
};
|
||||
struct Dealloc2 {
|
||||
~Dealloc2() {}
|
||||
};
|
||||
struct Dealloc3 {
|
||||
void Destroyer() {
|
||||
Dealloc3CalledCount++;
|
||||
delete this;
|
||||
}
|
||||
};
|
||||
%}
|
||||
|
||||
%{
|
||||
void Dealloc1Destroyer(PyObject *v) {
|
||||
SwigPyObject *sobj = (SwigPyObject *) v;
|
||||
Dealloc1 *p = (Dealloc1 *)sobj->ptr;
|
||||
delete p;
|
||||
Dealloc1CalledCount++;
|
||||
}
|
||||
void Dealloc2Destroyer(PyObject *v) {
|
||||
SwigPyObject *sobj = (SwigPyObject *) v;
|
||||
Dealloc2 *p = (Dealloc2 *)sobj->ptr;
|
||||
delete p;
|
||||
Dealloc2CalledCount++;
|
||||
}
|
||||
%}
|
||||
|
||||
// Test 5 for python:compare feature
|
||||
%feature("python:compare", "Py_LT") MyClass::lessThan;
|
||||
|
||||
%inline %{
|
||||
class MyClass {
|
||||
public:
|
||||
MyClass(int val = 0) : val(val) {}
|
||||
bool lessThan(const MyClass& other) const {
|
||||
less_than_counts++;
|
||||
return val < other.val;
|
||||
}
|
||||
int val;
|
||||
static int less_than_counts;
|
||||
};
|
||||
int MyClass::less_than_counts = 0;
|
||||
%}
|
||||
|
|
@ -5,7 +5,8 @@
|
|||
LANGUAGE = r
|
||||
SCRIPTSUFFIX = _runme.R
|
||||
WRAPSUFFIX = .R
|
||||
RUNR = R CMD BATCH --no-save --no-restore '--args $(SCRIPTDIR)'
|
||||
R_OPT = --quiet --no-save --no-restore
|
||||
RUNR = R CMD BATCH $(R_OPT) '--args $(SCRIPTDIR)'
|
||||
|
||||
srcdir = @srcdir@
|
||||
top_srcdir = @top_srcdir@
|
||||
|
|
@ -51,18 +52,17 @@ include $(srcdir)/../common.mk
|
|||
# check for syntactic correctness
|
||||
run_testcase = \
|
||||
if [ -f $(SCRIPTDIR)/$(SCRIPTPREFIX)$*$(SCRIPTSUFFIX) ]; then \
|
||||
env LD_LIBRARY_PATH=.:$$LD_LIBRARY_PATH PATH=.:"$$PATH" $(RUNTOOL) $(RUNR) $(SCRIPTDIR)/$(SCRIPTPREFIX)$*$(SCRIPTSUFFIX); \
|
||||
env LD_LIBRARY_PATH=.:$$LD_LIBRARY_PATH PATH=.:"$$PATH" $(RUNTOOL) $(RUNR) $(SCRIPTDIR)/$(SCRIPTPREFIX)$*$(SCRIPTSUFFIX) || (cat $(SCRIPTDIR)/$(SCRIPTPREFIX)$*$(SCRIPTSUFFIX)out ; false); \
|
||||
else \
|
||||
$(RUNTOOL) $(RUNR) ./$(SCRIPTPREFIX)$*$(WRAPSUFFIX); \
|
||||
$(RUNTOOL) $(RUNR) ./$(SCRIPTPREFIX)$*$(WRAPSUFFIX) || (cat ./$(SCRIPTPREFIX)$*$(WRAPSUFFIX)out ; false); \
|
||||
fi
|
||||
|
||||
run_multitestcase = \
|
||||
for f in `cat $(top_srcdir)/$(EXAMPLES)/$(TEST_SUITE)/$*.list` ; do \
|
||||
if [ -f $(SCRIPTDIR)/$(SCRIPTPREFIX)$${f}$(SCRIPTSUFFIX) ]; then \
|
||||
env LD_LIBRARY_PATH=.:$$LD_LIBRARY_PATH PATH=.:"$$PATH" \
|
||||
$(RUNTOOL) $(RUNR) $(SCRIPTDIR)/$(SCRIPTPREFIX)$${f}$(SCRIPTSUFFIX); \
|
||||
env LD_LIBRARY_PATH=.:$$LD_LIBRARY_PATH PATH=.:"$$PATH" $(RUNTOOL) $(RUNR) $(SCRIPTDIR)/$(SCRIPTPREFIX)$${f}$(SCRIPTSUFFIX) || (cat $(SCRIPTDIR)/$(SCRIPTPREFIX)$${f}$(SCRIPTSUFFIX)out ; false); \
|
||||
else \
|
||||
$(RUNTOOL) $(RUNR) ./$(SCRIPTPREFIX)$${f}$(WRAPSUFFIX); \
|
||||
$(RUNTOOL) $(RUNR) ./$(SCRIPTPREFIX)$${f}$(WRAPSUFFIX) || (cat ./$(SCRIPTPREFIX)$${f}$(WRAPSUFFIX)out ; false); \
|
||||
fi; \
|
||||
done
|
||||
# Clean
|
||||
|
|
|
|||
|
|
@ -9,6 +9,10 @@ testvec <- c(1, 2, 3)
|
|||
|
||||
unittest(half(testvec), testvec/2)
|
||||
unittest(average(testvec), mean(testvec))
|
||||
## string vector test
|
||||
vlen <- 13
|
||||
stringvec <- paste(letters[1:vlen], as.character(rnorm(vlen)))
|
||||
unittest(rev(stringvec), RevStringVec(stringvec))
|
||||
q(save="no")
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -30,7 +30,8 @@ CPP_TEST_CASES = \
|
|||
# stl_new
|
||||
|
||||
C_TEST_CASES += \
|
||||
li_cstring
|
||||
li_cstring \
|
||||
ruby_manual_proxy \
|
||||
|
||||
include $(srcdir)/../common.mk
|
||||
|
||||
|
|
|
|||
49
Examples/test-suite/ruby/ruby_manual_proxy_runme.rb
Normal file
49
Examples/test-suite/ruby/ruby_manual_proxy_runme.rb
Normal file
|
|
@ -0,0 +1,49 @@
|
|||
#!/usr/bin/env ruby
|
||||
#
|
||||
# The Subversion bindings use this manually written proxy class approach
|
||||
# to the Ruby bindings. Note that in C the struct svn_fs_t is an
|
||||
# opaque pointer and the Ruby FileSystem proxy class is hand written around it.
|
||||
# This testcase tests this and the C close function and subsequent error
|
||||
# handling.
|
||||
|
||||
require 'swig_assert'
|
||||
require 'ruby_manual_proxy'
|
||||
|
||||
module Svn
|
||||
module Fs
|
||||
module_function
|
||||
def create(path)
|
||||
f = Ruby_manual_proxy::svn_fs_create(path)
|
||||
return f
|
||||
end
|
||||
|
||||
FileSystem = SWIG::TYPE_p_svn_fs_t
|
||||
class FileSystem
|
||||
class << self
|
||||
def create(*args)
|
||||
Fs.create(*args)
|
||||
end
|
||||
end
|
||||
def path
|
||||
Ruby_manual_proxy::svn_fs_path(self)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
f = Svn::Fs::FileSystem.create("/tmp/myfile")
|
||||
path = f.path
|
||||
f.close
|
||||
begin
|
||||
# regression in swig-3.0.8 meant ObjectPreviouslyDeleted error was thrown instead
|
||||
path = f.path
|
||||
raise RuntimeError.new("IOError (1) not thrown")
|
||||
rescue IOError
|
||||
end
|
||||
|
||||
file = nil
|
||||
begin
|
||||
path = Ruby_manual_proxy::svn_fs_path(file)
|
||||
raise RuntimeError.new("IOError (2) not thrown")
|
||||
rescue IOError
|
||||
end
|
||||
66
Examples/test-suite/ruby_manual_proxy.i
Normal file
66
Examples/test-suite/ruby_manual_proxy.i
Normal file
|
|
@ -0,0 +1,66 @@
|
|||
%module ruby_manual_proxy
|
||||
|
||||
|
||||
%typemap(in, numinputs=0) SWIGTYPE ** ($*1_ltype temp) "$1 = &temp;";
|
||||
|
||||
%typemap(argout) SWIGTYPE **OUTPARAM {
|
||||
$result = SWIG_Ruby_AppendOutput($result, SWIG_NewPointerObj(*$1, $*1_descriptor, 0));
|
||||
}
|
||||
|
||||
%apply SWIGTYPE **OUTPARAM {
|
||||
svn_fs_t **
|
||||
};
|
||||
|
||||
%typemap(check) svn_fs_t * {
|
||||
if (!$1) {
|
||||
svn_swig_rb_raise_svn_fs_already_close();
|
||||
}
|
||||
}
|
||||
|
||||
%{
|
||||
typedef struct svn_fs_t {
|
||||
char path[256];
|
||||
} svn_fs_t;
|
||||
|
||||
void svn_fs_create(svn_fs_t **fs_p, const char *path) {
|
||||
svn_fs_t *fs = (svn_fs_t *)malloc(sizeof(svn_fs_t));
|
||||
strncpy(fs->path, path, 256);
|
||||
*fs_p = fs;
|
||||
}
|
||||
const char *svn_fs_path(svn_fs_t *fs) {
|
||||
return fs->path;
|
||||
}
|
||||
%}
|
||||
|
||||
typedef struct svn_fs_t svn_fs_t;
|
||||
void svn_fs_create(svn_fs_t **fs_p, const char *path);
|
||||
const char *svn_fs_path(svn_fs_t *fs);
|
||||
|
||||
%{
|
||||
static void svn_swig_rb_raise_svn_fs_already_close(void) {
|
||||
rb_raise(rb_eIOError, "already closed");
|
||||
}
|
||||
|
||||
static VALUE svn_fs_swig_rb_close(VALUE self) {
|
||||
if (!DATA_PTR(self)) {
|
||||
svn_swig_rb_raise_svn_fs_already_close();
|
||||
}
|
||||
|
||||
DATA_PTR(self) = NULL;
|
||||
|
||||
return Qnil;
|
||||
}
|
||||
|
||||
static VALUE svn_fs_swig_rb_closed(VALUE self) {
|
||||
return DATA_PTR(self) ? Qfalse : Qtrue;
|
||||
}
|
||||
%}
|
||||
|
||||
%insert("init") %{
|
||||
{
|
||||
VALUE cSvnfs;
|
||||
cSvnfs = rb_const_get(_mSWIG, rb_intern("TYPE_p_svn_fs_t"));
|
||||
rb_define_method(cSvnfs, "close",
|
||||
VALUEFUNC(svn_fs_swig_rb_close), 0);
|
||||
}
|
||||
%}
|
||||
|
|
@ -13,7 +13,6 @@ top_builddir = ../@top_builddir@
|
|||
|
||||
C_TEST_CASES += \
|
||||
scilab_consts \
|
||||
scilab_enums \
|
||||
scilab_identifier_name \
|
||||
|
||||
CPP_TEST_CASES += \
|
||||
|
|
@ -21,6 +20,7 @@ CPP_TEST_CASES += \
|
|||
primitive_types \
|
||||
scilab_li_matrix \
|
||||
scilab_multivalue \
|
||||
scilab_enums \
|
||||
scilab_pointer_conversion_functions \
|
||||
|
||||
CPP_STD_TEST_CASES += \
|
||||
|
|
|
|||
|
|
@ -24,4 +24,13 @@ checkEnum(TYPEDEF_ENUM_1_2, 22);
|
|||
checkEnum(TYPEDEF_ENUM_2_1, 31);
|
||||
checkEnum(TYPEDEF_ENUM_2_2, 32);
|
||||
|
||||
checkEnum(ENUM_REF_1, 1);
|
||||
checkEnum(ENUM_REF_2, 10);
|
||||
|
||||
checkEnum(clsEnum_CLS_ENUM_1, 100);
|
||||
checkEnum(clsEnum_CLS_ENUM_2, 101);
|
||||
|
||||
checkEnum(clsEnum_CLS_ENUM_REF_1, 101);
|
||||
checkEnum(clsEnum_CLS_ENUM_REF_2, 110);
|
||||
|
||||
exec("swigtest.quit", -1);
|
||||
|
|
|
|||
|
|
@ -35,4 +35,21 @@ typedef enum TYPEDEF_ENUM_2 {
|
|||
TYPEDEF_ENUM_2_2 = 32
|
||||
} TYPEDEF_ENUM_2;
|
||||
|
||||
enum ENUM_REF {
|
||||
ENUM_REF_1 = 1,
|
||||
ENUM_REF_2 = ENUM_REF_1 + 9
|
||||
};
|
||||
|
||||
class clsEnum {
|
||||
public:
|
||||
enum CLS_ENUM {
|
||||
CLS_ENUM_1 = 100,
|
||||
CLS_ENUM_2 = 101
|
||||
};
|
||||
enum CLS_ENUM_REF {
|
||||
CLS_ENUM_REF_1 = 101,
|
||||
CLS_ENUM_REF_2 = CLS_ENUM_REF_1 + 9
|
||||
};
|
||||
};
|
||||
|
||||
%}
|
||||
|
|
|
|||
33
Examples/test-suite/smart_pointer_ignore.i
Normal file
33
Examples/test-suite/smart_pointer_ignore.i
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
%module smart_pointer_ignore
|
||||
|
||||
|
||||
%ignore Derived;
|
||||
|
||||
%inline %{
|
||||
class Base {
|
||||
public:
|
||||
void base() {}
|
||||
};
|
||||
|
||||
class Derived : public Base {
|
||||
public:
|
||||
void derived() {}
|
||||
};
|
||||
|
||||
template <class T>
|
||||
class Ptr {
|
||||
public:
|
||||
Ptr(T *t) : ptr(t) {}
|
||||
T * operator->() const { return ptr; }
|
||||
private:
|
||||
T *ptr;
|
||||
};
|
||||
%}
|
||||
|
||||
%template(DerivedPtr) Ptr<Derived>;
|
||||
|
||||
%inline %{
|
||||
Ptr<Derived> makeDerived() {
|
||||
return Ptr<Derived>(new Derived());
|
||||
}
|
||||
%}
|
||||
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