From a615d8dd1d27bcd0df78c90c15fc8cce4290360e Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Tue, 20 Jul 2010 22:58:37 +0000 Subject: minor clarification about directors git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12163 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Doc/Manual/Java.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Doc/Manual/Java.html b/Doc/Manual/Java.html index f572ffa32..d014feef6 100644 --- a/Doc/Manual/Java.html +++ b/Doc/Manual/Java.html @@ -166,7 +166,7 @@ SWIG wraps C/C++ code using Java proxy classes and is very useful if you want to If only one or two JNI functions are needed then using SWIG may be overkill. SWIG enables a Java program to easily call into C/C++ code from Java. Historically, SWIG was not able to generate any code to call into Java code from C++. -However, SWIG now supports full cross language polymorphism and code is generated to call up from C++ to Java when wrapping C++ virtual methods. +However, SWIG now supports full cross language polymorphism and code is generated to call up from C++ to Java when wrapping C++ virtual methods via the director feature.

-- cgit v1.2.1 From 1f939323a4e0700172db875ebd3ef9c9a7b4c33a Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Thu, 22 Jul 2010 16:59:08 +0000 Subject: Fix PYTHONPATH value when running Python tests outside source directory. PYTHONPATH needs to include the current directory and not (just) the source directory as the SWIG-generated files are produced here and not under the source directory when the top build directory is different from it. git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12166 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Examples/test-suite/python/Makefile.in | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Examples/test-suite/python/Makefile.in b/Examples/test-suite/python/Makefile.in index 4938ddc27..a05542b70 100644 --- a/Examples/test-suite/python/Makefile.in +++ b/Examples/test-suite/python/Makefile.in @@ -117,7 +117,7 @@ VALGRIND_OPT += --suppressions=pythonswig.supp # Runs the testcase. A testcase is only run if # a file is found which has _runme.py (or _runme3.py for Python 3) appended after the testcase name. -run_python = env LD_LIBRARY_PATH=.:$$LD_LIBRARY_PATH PYTHONPATH=$(srcdir):$$PYTHONPATH $(RUNTOOL) $(PYTHON) $(srcdir)/$(SCRIPTPREFIX)$*$(SCRIPTSUFFIX) +run_python = env LD_LIBRARY_PATH=.:$$LD_LIBRARY_PATH PYTHONPATH=.:$(srcdir):$$PYTHONPATH $(RUNTOOL) $(PYTHON) $(srcdir)/$(SCRIPTPREFIX)$*$(SCRIPTSUFFIX) py2_runme = $(srcdir)/$(SCRIPTPREFIX)$*$(PY2SCRIPTSUFFIX) py3_runme = $(srcdir)/$(SCRIPTPREFIX)$*$(PY3SCRIPTSUFFIX) -- cgit v1.2.1 From ac5ddb03150577ab5d7f53bde0c1aa801e975855 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Thu, 22 Jul 2010 16:59:29 +0000 Subject: Make argument of DohWrite() const. Writing a buffer to a DOH object doesn't modify so it should be const. This allows the code using const pointers to pass them to DohWrite() without neither the casts nor gcc warnings. git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12167 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Source/DOH/base.c | 2 +- Source/DOH/doh.h | 2 +- Source/DOH/dohint.h | 2 +- Source/DOH/file.c | 2 +- Source/DOH/string.c | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Source/DOH/base.c b/Source/DOH/base.c index 36ceb7ae3..cfbd2bdc4 100644 --- a/Source/DOH/base.c +++ b/Source/DOH/base.c @@ -645,7 +645,7 @@ int DohRead(DOH *obj, void *buffer, int length) { * DohWrite() * ----------------------------------------------------------------------------- */ -int DohWrite(DOH *obj, void *buffer, int length) { +int DohWrite(DOH *obj, const void *buffer, int length) { DohBase *b = (DohBase *) obj; DohObjInfo *objinfo; if (DohCheck(obj)) { diff --git a/Source/DOH/doh.h b/Source/DOH/doh.h index 1ed196058..e46d103de 100644 --- a/Source/DOH/doh.h +++ b/Source/DOH/doh.h @@ -221,7 +221,7 @@ extern int DohDelslice(DOH *obj, int sindex, int eindex); /* File methods */ -extern int DohWrite(DOHFile * obj, void *buffer, int length); +extern int DohWrite(DOHFile * obj, const void *buffer, int length); extern int DohRead(DOHFile * obj, void *buffer, int length); extern int DohSeek(DOHFile * obj, long offset, int whence); extern long DohTell(DOHFile * obj); diff --git a/Source/DOH/dohint.h b/Source/DOH/dohint.h index 661bed075..3d812b849 100644 --- a/Source/DOH/dohint.h +++ b/Source/DOH/dohint.h @@ -43,7 +43,7 @@ typedef struct { /* File methods */ typedef struct { int (*doh_read) (DOH *obj, void *buffer, int nbytes); /* Read bytes */ - int (*doh_write) (DOH *obj, void *buffer, int nbytes); /* Write bytes */ + int (*doh_write) (DOH *obj, const void *buffer, int nbytes); /* Write bytes */ int (*doh_putc) (DOH *obj, int ch); /* Put character */ int (*doh_getc) (DOH *obj); /* Get character */ int (*doh_ungetc) (DOH *obj, int ch); /* Unget character */ diff --git a/Source/DOH/file.c b/Source/DOH/file.c index a9ee332bf..11482fa7f 100644 --- a/Source/DOH/file.c +++ b/Source/DOH/file.c @@ -67,7 +67,7 @@ static int File_read(DOH *fo, void *buffer, int len) { * File_write() * ----------------------------------------------------------------------------- */ -static int File_write(DOH *fo, void *buffer, int len) { +static int File_write(DOH *fo, const void *buffer, int len) { DohFile *f = (DohFile *) ObjData(fo); if (f->filep) { int ret = (int) fwrite(buffer, 1, len, f->filep); diff --git a/Source/DOH/string.c b/Source/DOH/string.c index bd36c4094..05ae6e963 100644 --- a/Source/DOH/string.c +++ b/Source/DOH/string.c @@ -419,7 +419,7 @@ static int String_read(DOH *so, void *buffer, int len) { /* ----------------------------------------------------------------------------- * int String_write() - Write data to a string * ----------------------------------------------------------------------------- */ -static int String_write(DOH *so, void *buffer, int len) { +static int String_write(DOH *so, const void *buffer, int len) { int newlen; String *s = (String *) ObjData(so); s->hashkey = -1; -- cgit v1.2.1 From f2a5ef0c57767d972edc583c66ef31cb32a53b1c Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Thu, 22 Jul 2010 16:59:45 +0000 Subject: Document advanced %rename capabilities. Document the possibility to apply %rename to all declarations or only those of a particular type. Also document extended format strings used with it and the functions which can be used in them. Also clarify that %ignore is basically just a %rename alias. git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12168 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Doc/Manual/SWIG.html | 194 +++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 188 insertions(+), 6 deletions(-) diff --git a/Doc/Manual/SWIG.html b/Doc/Manual/SWIG.html index d523bee77..e68003325 100644 --- a/Doc/Manual/SWIG.html +++ b/Doc/Manual/SWIG.html @@ -1661,6 +1661,7 @@ generate a warning message. Simply change the directives to %immutable;5.4.7 Renaming and ignoring declarations +

5.4.7.1 Simple renaming of specific identifiers

Normally, the name of a C declaration is used when that declaration is @@ -1741,12 +1742,6 @@ to add conditional compilation to the header. However, it should be stressed t declarations. If you need to remove a whole section of problematic code, the SWIG preprocessor should be used instead.

-

-More powerful variants of %rename and %ignore directives can be used to help -wrap C++ overloaded functions and methods or C++ methods which use default arguments. This is described in the -Ambiguity resolution and renaming section in the C++ chapter. -

-

Compatibility note: Older versions of SWIG provided a special %name directive for renaming declarations. For example: @@ -1763,6 +1758,193 @@ This directive is still supported, but it is deprecated and should probably be a directive is more powerful and better supports wrapping of raw header file information.

+

5.4.7.2 Advanced renaming support

+ +

+While writing %rename for specific declarations is simple enough, +sometimes the same renaming rule needs to be applied to many, maybe all, +identifiers in the SWIG input. For example, it may be necessary to apply some +transformation to all the names in the target language to better follow its +naming conventions, e.g. add a specific prefix to all the functions. Doing it +for each function is impractical so SWIG supports applying a renaming rule to +all declarations if the name of the identifier to be renamed is not specified: +

+ +
+
+%rename("myprefix_%s") ""; // print -> myprefix_print
+
+
+ +

+This also shows that the argument of %rename doesn't have to be a +literal string but can be a printf()-like format string. In the +simplest form, "%s" is replaced with the name of the original +declaration, as shown above. However this is not always enough and SWIG +provides extensions to the usual format string syntax to allow applying a +(SWIG-defined) function to the argument. For example, to wrap all C functions +do_something_long() as more Java-like doSomethingLong() you +can use the "lowercamelcase" extended format specifier like this: +

+ +
+
+%rename("%(lowercamelcase)s") ""; // foo_bar -> fooBar; FooBar -> fooBar
+
+
+ +

+Some functions can be parametrized, for example the "strip" one +strips the provided prefix from its argument. The prefix is specified as part +of the format string, following a colon after the function name: +

+
+%rename("%(strip:[wx])s") ""; // wxHello -> Hello; FooBar -> fooBar
+
+
+

+ +

+Here is the table summarizing all currently defined functions with an example +of applying each one (notice that some of them have two names, a shorter one +and a more descriptive one, but the two functions are otherwise equivalent): +

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
FunctionReturnsExample (in/out)
upper or uppercaseUpper-case version of the string.PrintPRINT
lower or lowercaseLower-case version of the string.Printprint
titleString with first letter capitalized and the rest in lower case.printPrint
firstuppercaseString with the first letter capitalized and the rest unchanged.printItPrintIt
firstlowercaseString with the first letter in lower case and the rest unchanged.PrintItprintIt
ctitle or camelcaseString with capitalized first letter and any letter following an + underscore (which are removed in the process) and rest in lower case.print_itPrintIt
lctitle or lowercamelcaseString with every letter following an underscore (which is removed in + the process) capitalized and rest, including the first letter, in lower + case.print_itprintIt
utitle or undercaseLower case string with underscores inserted before every upper-case + letter in the original string and any number not at the end of string. + Logically, this is the reverse of ccase.PrintItprint_it
schemifyString with all underscores replaced with dashes, resulting in more + Lispers/Schemers-pleasing name.print_itprint-it
strip:[prefix]String without the given prefix or the original string if it doesn't + start with this prefix. Note that square brackets should be used + literally, e.g. %rename("strip:[wx]")wxPrintPrint
command:cmdOutput of an external command cmd with the string passed to + it as input. Notice that this function is extremely slow compared to all + the other ones as it involves spawning a separate process and using it for + many declarations is not recommended. The cmd is not enclosed in + square brackets but must be terminated with a triple '<' sign, + e.g. %rename("command:tr -d aeiou <<<") + (nonsensical example removing all vowels)PrintPrnt
+ +

+As before, everything that was said above about %rename also applies to +%ignore. In fact, the latter is just a special case of the former and +ignoring an identifier is the same as renaming it to the special +"$ignore" value. So the following snippets +

+ +
+
+%ignore print;
+
+
+ +

+and +

+ +
+
+%rename("$ignore") print;
+
+
+ +

+are exactly equivalent and %rename can be used to selectively ignore +multiple declarations using the previously described matching possibilities. +

+ +

5.4.7.3 Limiting global renaming rules

+ +

+As explained in the previous sections, it is possible to either rename +individual declarations or apply a rename rule to all of them at once. In +practice, the latter is however rarely appropriate as there are always some +exceptions to the general rules. To deal with them, the scope of an unnamed +%rename can be limited using a second parameter. +

+ +

+The simplest possibility is to match the declaration type, for example: +

+
+
+%rename("%(title)s", %$isenumitem) "";
+
+
+

+will capitalize the names of all the enum elements but not change the case of +the other declarations. Similarly, %$isclass, %$isfunction +and %$isvariable can be used. Many other checks are possible and this +documentation is not exhaustive, see "%rename predicates" section of +Lib/swig.swg for the full list of supported match expressions. +

+ +

+Finally, even more powerful variants of %rename and %ignore directives can be used to help +wrap C++ overloaded functions and methods or C++ methods which use default arguments. This is described in the +Ambiguity resolution and renaming section in the C++ chapter. +

+ +

5.4.8 Default/optional arguments

-- cgit v1.2.1 From 6399502719dcc04c816536d7a4231e0164b4402f Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Thu, 22 Jul 2010 17:00:16 +0000 Subject: Add a check for PCRE library to configure. We use standard AX_PATH_GENERIC() macro from Autoconf archive to do the check to keep our own code as simple as possible. Notice that this script must be used, just adding the include and library directories to {C,LD}FLAGS is not enough, notably -DPCRE_STATIC which is output by pcre-config for static builds only is crucial. Also use LIBS instead of LDFLAGS to fix linking when using static libraries. Also note that this allows to pass PCRE_CONFIG variable value to configure to force the use of the specified script (and not the one first found in PATH), which is especially important when cross-compiling. Finally, PCRE is required by default now, --without-pcre must be explicitly used to build without it. git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12169 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Tools/config/ax_compare_version.m4 | 177 +++++++++++++++++++++++++++++++++++++ Tools/config/ax_path_generic.m4 | 142 +++++++++++++++++++++++++++++ configure.in | 26 +++++- 3 files changed, 344 insertions(+), 1 deletion(-) create mode 100644 Tools/config/ax_compare_version.m4 create mode 100644 Tools/config/ax_path_generic.m4 diff --git a/Tools/config/ax_compare_version.m4 b/Tools/config/ax_compare_version.m4 new file mode 100644 index 000000000..74dc0fdd9 --- /dev/null +++ b/Tools/config/ax_compare_version.m4 @@ -0,0 +1,177 @@ +# =========================================================================== +# http://www.gnu.org/software/autoconf-archive/ax_compare_version.html +# =========================================================================== +# +# SYNOPSIS +# +# AX_COMPARE_VERSION(VERSION_A, OP, VERSION_B, [ACTION-IF-TRUE], [ACTION-IF-FALSE]) +# +# DESCRIPTION +# +# This macro compares two version strings. Due to the various number of +# minor-version numbers that can exist, and the fact that string +# comparisons are not compatible with numeric comparisons, this is not +# necessarily trivial to do in a autoconf script. This macro makes doing +# these comparisons easy. +# +# The six basic comparisons are available, as well as checking equality +# limited to a certain number of minor-version levels. +# +# The operator OP determines what type of comparison to do, and can be one +# of: +# +# eq - equal (test A == B) +# ne - not equal (test A != B) +# le - less than or equal (test A <= B) +# ge - greater than or equal (test A >= B) +# lt - less than (test A < B) +# gt - greater than (test A > B) +# +# Additionally, the eq and ne operator can have a number after it to limit +# the test to that number of minor versions. +# +# eq0 - equal up to the length of the shorter version +# ne0 - not equal up to the length of the shorter version +# eqN - equal up to N sub-version levels +# neN - not equal up to N sub-version levels +# +# When the condition is true, shell commands ACTION-IF-TRUE are run, +# otherwise shell commands ACTION-IF-FALSE are run. The environment +# variable 'ax_compare_version' is always set to either 'true' or 'false' +# as well. +# +# Examples: +# +# AX_COMPARE_VERSION([3.15.7],[lt],[3.15.8]) +# AX_COMPARE_VERSION([3.15],[lt],[3.15.8]) +# +# would both be true. +# +# AX_COMPARE_VERSION([3.15.7],[eq],[3.15.8]) +# AX_COMPARE_VERSION([3.15],[gt],[3.15.8]) +# +# would both be false. +# +# AX_COMPARE_VERSION([3.15.7],[eq2],[3.15.8]) +# +# would be true because it is only comparing two minor versions. +# +# AX_COMPARE_VERSION([3.15.7],[eq0],[3.15]) +# +# would be true because it is only comparing the lesser number of minor +# versions of the two values. +# +# Note: The characters that separate the version numbers do not matter. An +# empty string is the same as version 0. OP is evaluated by autoconf, not +# configure, so must be a string, not a variable. +# +# The author would like to acknowledge Guido Draheim whose advice about +# the m4_case and m4_ifvaln functions make this macro only include the +# portions necessary to perform the specific comparison specified by the +# OP argument in the final configure script. +# +# LICENSE +# +# Copyright (c) 2008 Tim Toolan +# +# Copying and distribution of this file, with or without modification, are +# permitted in any medium without royalty provided the copyright notice +# and this notice are preserved. This file is offered as-is, without any +# warranty. + +#serial 11 + +dnl ######################################################################### +AC_DEFUN([AX_COMPARE_VERSION], [ + AC_REQUIRE([AC_PROG_AWK]) + + # Used to indicate true or false condition + ax_compare_version=false + + # Convert the two version strings to be compared into a format that + # allows a simple string comparison. The end result is that a version + # string of the form 1.12.5-r617 will be converted to the form + # 0001001200050617. In other words, each number is zero padded to four + # digits, and non digits are removed. + AS_VAR_PUSHDEF([A],[ax_compare_version_A]) + A=`echo "$1" | sed -e 's/\([[0-9]]*\)/Z\1Z/g' \ + -e 's/Z\([[0-9]]\)Z/Z0\1Z/g' \ + -e 's/Z\([[0-9]][[0-9]]\)Z/Z0\1Z/g' \ + -e 's/Z\([[0-9]][[0-9]][[0-9]]\)Z/Z0\1Z/g' \ + -e 's/[[^0-9]]//g'` + + AS_VAR_PUSHDEF([B],[ax_compare_version_B]) + B=`echo "$3" | sed -e 's/\([[0-9]]*\)/Z\1Z/g' \ + -e 's/Z\([[0-9]]\)Z/Z0\1Z/g' \ + -e 's/Z\([[0-9]][[0-9]]\)Z/Z0\1Z/g' \ + -e 's/Z\([[0-9]][[0-9]][[0-9]]\)Z/Z0\1Z/g' \ + -e 's/[[^0-9]]//g'` + + dnl # In the case of le, ge, lt, and gt, the strings are sorted as necessary + dnl # then the first line is used to determine if the condition is true. + dnl # The sed right after the echo is to remove any indented white space. + m4_case(m4_tolower($2), + [lt],[ + ax_compare_version=`echo "x$A +x$B" | sed 's/^ *//' | sort -r | sed "s/x${A}/false/;s/x${B}/true/;1q"` + ], + [gt],[ + ax_compare_version=`echo "x$A +x$B" | sed 's/^ *//' | sort | sed "s/x${A}/false/;s/x${B}/true/;1q"` + ], + [le],[ + ax_compare_version=`echo "x$A +x$B" | sed 's/^ *//' | sort | sed "s/x${A}/true/;s/x${B}/false/;1q"` + ], + [ge],[ + ax_compare_version=`echo "x$A +x$B" | sed 's/^ *//' | sort -r | sed "s/x${A}/true/;s/x${B}/false/;1q"` + ],[ + dnl Split the operator from the subversion count if present. + m4_bmatch(m4_substr($2,2), + [0],[ + # A count of zero means use the length of the shorter version. + # Determine the number of characters in A and B. + ax_compare_version_len_A=`echo "$A" | $AWK '{print(length)}'` + ax_compare_version_len_B=`echo "$B" | $AWK '{print(length)}'` + + # Set A to no more than B's length and B to no more than A's length. + A=`echo "$A" | sed "s/\(.\{$ax_compare_version_len_B\}\).*/\1/"` + B=`echo "$B" | sed "s/\(.\{$ax_compare_version_len_A\}\).*/\1/"` + ], + [[0-9]+],[ + # A count greater than zero means use only that many subversions + A=`echo "$A" | sed "s/\(\([[0-9]]\{4\}\)\{m4_substr($2,2)\}\).*/\1/"` + B=`echo "$B" | sed "s/\(\([[0-9]]\{4\}\)\{m4_substr($2,2)\}\).*/\1/"` + ], + [.+],[ + AC_WARNING( + [illegal OP numeric parameter: $2]) + ],[]) + + # Pad zeros at end of numbers to make same length. + ax_compare_version_tmp_A="$A`echo $B | sed 's/./0/g'`" + B="$B`echo $A | sed 's/./0/g'`" + A="$ax_compare_version_tmp_A" + + # Check for equality or inequality as necessary. + m4_case(m4_tolower(m4_substr($2,0,2)), + [eq],[ + test "x$A" = "x$B" && ax_compare_version=true + ], + [ne],[ + test "x$A" != "x$B" && ax_compare_version=true + ],[ + AC_WARNING([illegal OP parameter: $2]) + ]) + ]) + + AS_VAR_POPDEF([A])dnl + AS_VAR_POPDEF([B])dnl + + dnl # Execute ACTION-IF-TRUE / ACTION-IF-FALSE. + if test "$ax_compare_version" = "true" ; then + m4_ifvaln([$4],[$4],[:])dnl + m4_ifvaln([$5],[else $5])dnl + fi +]) dnl AX_COMPARE_VERSION diff --git a/Tools/config/ax_path_generic.m4 b/Tools/config/ax_path_generic.m4 new file mode 100644 index 000000000..4db2da11b --- /dev/null +++ b/Tools/config/ax_path_generic.m4 @@ -0,0 +1,142 @@ +# =========================================================================== +# http://www.gnu.org/software/autoconf-archive/ax_path_generic.html +# =========================================================================== +# +# SYNOPSIS +# +# AX_PATH_GENERIC(LIBRARY,[MINIMUM-VERSION,[SED-EXPR-EXTRACTOR]],[ACTION-IF-FOUND],[ACTION-IF-NOT-FOUND],[CONFIG-SCRIPTS],[CFLAGS-ARG],[LIBS-ARG]) +# +# DESCRIPTION +# +# Runs the LIBRARY-config script and defines LIBRARY_CFLAGS and +# LIBRARY_LIBS +# +# The script must support `--cflags' and `--libs' args. If MINIMUM-VERSION +# is specified, the script must also support the `--version' arg. If the +# `--with-library-[exec-]prefix' arguments to ./configure are given, it +# must also support `--prefix' and `--exec-prefix'. Prefereable use +# CONFIG-SCRIPTS as config script, CFLAGS-ARG instead of `--cflags` and +# LIBS-ARG instead of `--libs`, if given. +# +# The SED-EXPR-EXTRACTOR parameter representes the expression used in sed +# to extract the version number. Use it if your 'foo-config --version' +# dumps something like 'Foo library v1.0.0 (alfa)' instead of '1.0.0'. +# +# Example: +# +# AX_PATH_GENERIC(Foo, 1.0.0) +# +# would run `foo-config --version' and check that it is at least 1.0.0, if +# successful the following variables would be defined and substituted: +# +# FOO_CFLAGS to `foo-config --cflags` +# FOO_LIBS to `foo-config --libs` +# +# Example: +# +# AX_PATH_GENERIC([Bar],,,[ +# AC_MSG_ERROR([Cannot find Bar library]) +# ]) +# +# would check for bar-config program, defining and substituting the +# following variables: +# +# BAR_CFLAGS to `bar-config --cflags` +# BAR_LIBS to `bar-config --libs` +# +# This macro is a rearranged version of AC_PATH_GENERIC from Angus Lees. +# +# LICENSE +# +# Copyright (c) 2009 Francesco Salvestrini +# +# Copying and distribution of this file, with or without modification, are +# permitted in any medium without royalty provided the copyright notice +# and this notice are preserved. This file is offered as-is, without any +# warranty. + +#serial 10 + +AU_ALIAS([AC_PATH_GENERIC], [AX_PATH_GENERIC]) +AC_DEFUN([AX_PATH_GENERIC],[ + AC_REQUIRE([AC_PROG_SED]) + + dnl we're going to need uppercase and lowercase versions of the + dnl string `LIBRARY' + pushdef([UP], translit([$1], [a-z], [A-Z]))dnl + pushdef([DOWN], translit([$1], [A-Z], [a-z]))dnl + + AC_ARG_WITH(DOWN-prefix,[AS_HELP_STRING([--with-]DOWN[-prefix=PREFIX], [Prefix where $1 is installed (optional)])], + DOWN[]_config_prefix="$withval", DOWN[]_config_prefix="") + AC_ARG_WITH(DOWN-exec-prefix,[AS_HELP_STRING([--with-]DOWN[-exec-prefix=EPREFIX], [Exec prefix where $1 is installed (optional)])], + DOWN[]_config_exec_prefix="$withval", DOWN[]_config_exec_prefix="") + + AC_ARG_VAR(UP[]_CONFIG, [config script used for $1]) + AC_ARG_VAR(UP[]_CFLAGS, [CFLAGS used for $1]) + AC_ARG_VAR(UP[]_LIBS, [LIBS used for $1]) + + AS_IF([test x$DOWN[]_config_exec_prefix != x],[ + DOWN[]_config_args="$DOWN[]_config_args --exec-prefix=$DOWN[]_config_exec_prefix" + AS_IF([test x${UP[]_CONFIG+set} != xset],[ + UP[]_CONFIG=$DOWN[]_config_exec_prefix/bin/DOWN-config + ]) + ]) + AS_IF([test x$DOWN[]_config_prefix != x],[ + DOWN[]_config_args="$DOWN[]_config_args --prefix=$DOWN[]_config_prefix" + AS_IF([test x${UP[]_CONFIG+set} != xset],[ + UP[]_CONFIG=$DOWN[]_config_prefix/bin/DOWN-config + ]) + ]) + + AC_PATH_PROGS(UP[]_CONFIG,[$6 DOWN-config],[no]) + AS_IF([test "$UP[]_CONFIG" == "no"],[ + : + $5 + ],[ + dnl Get the CFLAGS from LIBRARY-config script + AS_IF([test x"$7" == x],[ + UP[]_CFLAGS="`$UP[]_CONFIG $DOWN[]_config_args --cflags`" + ],[ + UP[]_CFLAGS="`$UP[]_CONFIG $DOWN[]_config_args $7`" + ]) + + dnl Get the LIBS from LIBRARY-config script + AS_IF([test x"$8" == x],[ + UP[]_LIBS="`$UP[]_CONFIG $DOWN[]_config_args --libs`" + ],[ + UP[]_LIBS="`$UP[]_CONFIG $DOWN[]_config_args $8`" + ]) + + AS_IF([test x"$2" != x],[ + dnl Check for provided library version + AS_IF([test x"$3" != x],[ + dnl Use provided sed expression + DOWN[]_version="`$UP[]_CONFIG $DOWN[]_config_args --version | $SED -e $3`" + ],[ + DOWN[]_version="`$UP[]_CONFIG $DOWN[]_config_args --version | $SED -e 's/^\ *\(.*\)\ *$/\1/'`" + ]) + + AC_MSG_CHECKING([for $1 ($DOWN[]_version) >= $2]) + AX_COMPARE_VERSION($DOWN[]_version,[ge],[$2],[ + AC_MSG_RESULT([yes]) + + AC_SUBST(UP[]_CFLAGS) + AC_SUBST(UP[]_LIBS) + : + $4 + ],[ + AC_MSG_RESULT([no]) + : + $5 + ]) + ],[ + AC_SUBST(UP[]_CFLAGS) + AC_SUBST(UP[]_LIBS) + : + $4 + ]) + ]) + + popdef([UP]) + popdef([DOWN]) +]) diff --git a/configure.in b/configure.in index f08ad4615..e5e2752d9 100644 --- a/configure.in +++ b/configure.in @@ -49,7 +49,31 @@ else AC_CHECK_FUNC(popen, AC_DEFINE(HAVE_POPEN, 1, [Define if popen is available]), AC_MSG_NOTICE([Disabling popen])) fi -dnl Look for RxSpencer +dnl PCRE +AC_ARG_WITH([pcre], + [AS_HELP_STRING([--without-pcre], + [Disable support for regular expressions using PCRE])], + [], + [with_pcre=yes]) + +AS_IF([test "x$with_pcre" != xno], + [AX_PATH_GENERIC([pcre], + [], dnl Minimal version of PCRE we need -- accept any + [], dnl custom sed script for version parsing is not needed + [AC_DEFINE([HAVE_PCRE], [1], [Define if you have PCRE library]) + LIBS="$LIBS $PCRE_LIBS" + CPPFLAGS="$CPPFLAGS $PCRE_CFLAGS" + ], + [AC_MSG_FAILURE( + Can't find pcre-config script from PCRE (Perl Compatible Regular + Expressions) library package. You need to either download PCRE from + www.pcre.org and install it or use --without-pcre configure option to + disable regular expressions support in SWIG.) + ]) + ]) + + +dnl Look for RxSpencer AC_ARG_WITH(rxspencer, AS_HELP_STRING([--with-rxspencer], [Enable RxSpencer]), with_rxspencer="yes") if test x"${with_rxspencer}" = xyes ; then #check first for the header -- cgit v1.2.1 From c4e9043288e2136dd7ae9e0515ad79164ad00d95 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Thu, 22 Jul 2010 17:00:37 +0000 Subject: Add support for regex encoder for %rename. This allows to write %rename("%(regex:/pattern/subst/)s") to apply a regex-based replacement to a declaration name. git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12170 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- CHANGES.current | 12 ++++++ Doc/Manual/SWIG.html | 12 ++++++ Source/Swig/misc.c | 106 +++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 130 insertions(+) diff --git a/CHANGES.current b/CHANGES.current index 63af7206d..9954ae05b 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -9,6 +9,18 @@ Version 2.0.1 (in progress) Fix wrapping of function pointers and member function pointers when the function returns by reference. +2010-07-13: vadz + Add the new "regex" encoder that can be used in %rename, e.g. + + %rename("regex:/(\\w+)_(.*)/\\2/") ""; + + to remove any alphabetical prefix from all identifiers. The syntax + of the regular expressions is Perl-like and PCRE library + (http://www.pcre.org/) is used to implement this feature but notice + that backslashes need to be escaped as usual inside C strings. + + Original patch from Torsten Landschoff. + 2010-07-08: wsfulton Fix #3024875 - shared_ptr of classes with non-public destructors. This also fixes the "unref" feature when used on classes with non-public destructors. diff --git a/Doc/Manual/SWIG.html b/Doc/Manual/SWIG.html index e68003325..3fb1e86cc 100644 --- a/Doc/Manual/SWIG.html +++ b/Doc/Manual/SWIG.html @@ -1871,6 +1871,18 @@ and a more descriptive one, but the two functions are otherwise equivalent): literally, e.g. %rename("strip:[wx]") wxPrintPrint + + regex:/pattern/subst/ + String after (Perl-like) regex substitution operation. This function + allows to apply arbitrary regular expressions to the identifier names. The + pattern part is a regular expression in Perl syntax (as supported + by PCRE) and the subst string + can contain back-references introduced by '\' or, as backslashes need + to be escaped in C strings, rather by "\\". For example, to remove + any alphabetic prefix before an underscore you could use the following directive: + %rename("regex:/(\\w+)_(.*)/\\2/") + Prefix_PrintPrint + command:cmd Output of an external command cmd with the string passed to diff --git a/Source/Swig/misc.c b/Source/Swig/misc.c index f0a9155eb..b23a99b60 100644 --- a/Source/Swig/misc.c +++ b/Source/Swig/misc.c @@ -1214,6 +1214,111 @@ String *Swig_string_rxspencer(String *s) { } #endif +#ifdef HAVE_PCRE +#include + +static int split_regex_pattern_subst(String *s, String **pattern, String **subst, const char **input) +{ + const char *pats, *pate; + const char *subs, *sube; + + /* Locate the search pattern */ + const char *p = Char(s); + if (*p++ != '/') goto err_out; + pats = p; + p = strchr(p, '/'); + if (!p) goto err_out; + pate = p; + + /* Locate the substitution string */ + subs = ++p; + p = strchr(p, '/'); + if (!p) goto err_out; + sube = p; + + *pattern = NewStringWithSize(pats, pate - pats); + *subst = NewStringWithSize(subs, sube - subs); + *input = p + 1; + return 1; + +err_out: + Swig_error("SWIG", Getline(s), "Invalid regex substitution: '%s'.\n", s); + exit(1); +} + +String *replace_captures(const char *input, String *subst, int captures[]) +{ + String *result = NewStringEmpty(); + const char *p = Char(subst); + + while (*p) { + /* Copy part without substitutions */ + const char *q = strchr(p, '\\'); + if (!q) { + Write(result, p, strlen(p)); + break; + } + Write(result, p, q - p); + p = q + 1; + + /* Handle substitution */ + if (*p == '\0') { + Putc('\\', result); + } else if (isdigit(*p)) { + int group = *p++ - '0'; + int l = captures[group*2], r = captures[group*2 + 1]; + if (l != -1) { + Write(result, input + l, r - l); + } + } + } + + return result; +} + +/* ----------------------------------------------------------------------------- + * Swig_string_regex() + * + * Executes a regexp substitution. For example: + * + * Printf(stderr,"gsl%(regex:/GSL_.*_/\\1/)s","GSL_Hello_") -> gslHello + * ----------------------------------------------------------------------------- */ +String *Swig_string_regex(String *s) { + const int pcre_options = 0; + + String *res = 0; + pcre *compiled_pat = 0; + const char *pcre_error, *input; + int pcre_errorpos; + String *pattern = 0, *subst = 0; + int captures[30]; + + if (split_regex_pattern_subst(s, &pattern, &subst, &input)) { + compiled_pat = pcre_compile( + Char(pattern), pcre_options, &pcre_error, &pcre_errorpos, NULL); + if (!compiled_pat) { + Swig_error("SWIG", Getline(s), "PCRE compilation failed: '%s' in '%s':%i.\n", + pcre_error, Char(pattern), pcre_errorpos); + exit(1); + } + pcre_exec(compiled_pat, NULL, input, strlen(input), 0, 0, captures, 30); + res = replace_captures(input, subst, captures); + } + + DohDelete(pattern); + DohDelete(subst); + pcre_free(compiled_pat); + return res ? res : NewStringEmpty(); +} + +#else + +String *Swig_string_regex(String *s) { + Swig_error("SWIG", Getline(s), "PCRE regex support not enabled in this SWIG build.\n"); + exit(1); +} + +#endif /* ----------------------------------------------------------------------------- * Swig_init() @@ -1236,6 +1341,7 @@ void Swig_init() { DohEncoding("rxspencer", Swig_string_rxspencer); DohEncoding("schemify", Swig_string_schemify); DohEncoding("strip", Swig_string_strip); + DohEncoding("regex", Swig_string_regex); /* aliases for the case encoders */ DohEncoding("uppercase", Swig_string_upper); -- cgit v1.2.1 From 0b2561f300484470478849a3aa5e1cb9d91b3942 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Thu, 22 Jul 2010 17:00:59 +0000 Subject: Add a test case for the regex encoder inside %rename. Simple unit test checking that %rename("%(regex:...)") works as expected. git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12171 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Examples/test-suite/common.mk | 1 + .../test-suite/python/rename_pcre_encoder_runme.py | 8 ++++++++ Examples/test-suite/rename_pcre_encoder.i | 21 +++++++++++++++++++++ 3 files changed, 30 insertions(+) create mode 100644 Examples/test-suite/python/rename_pcre_encoder_runme.py create mode 100644 Examples/test-suite/rename_pcre_encoder.i diff --git a/Examples/test-suite/common.mk b/Examples/test-suite/common.mk index c1952543f..c7afb6647 100644 --- a/Examples/test-suite/common.mk +++ b/Examples/test-suite/common.mk @@ -284,6 +284,7 @@ CPP_TEST_CASES += \ rename4 \ rename_scope \ rename_strip_encoder \ + rename_pcre_encoder \ restrict_cplusplus \ return_const_value \ return_value_scope \ diff --git a/Examples/test-suite/python/rename_pcre_encoder_runme.py b/Examples/test-suite/python/rename_pcre_encoder_runme.py new file mode 100644 index 000000000..f06c3d25a --- /dev/null +++ b/Examples/test-suite/python/rename_pcre_encoder_runme.py @@ -0,0 +1,8 @@ +from rename_pcre_encoder import * + +s = SomeWidget() +a = AnotherWidget() +a.DoSomething() + +evt = wxEVTSomeEvent() +t = xUnchangedName() diff --git a/Examples/test-suite/rename_pcre_encoder.i b/Examples/test-suite/rename_pcre_encoder.i new file mode 100644 index 000000000..568a2a82d --- /dev/null +++ b/Examples/test-suite/rename_pcre_encoder.i @@ -0,0 +1,21 @@ +%module rename_pcre_encoder + +// strip the wx prefix from all identifiers except those starting with wxEVT +%rename("%(regex:/wx(?!EVT)(.*)/\\1/)s") ""; + +%inline %{ + +class wxSomeWidget { +}; + +struct wxAnotherWidget { + void wxDoSomething() {} +}; + +class wxEVTSomeEvent { +}; + +class xUnchangedName { +}; + +%} -- cgit v1.2.1 From 409ae85a745a68615778b0b5029b3ef933412f81 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Thu, 22 Jul 2010 17:01:16 +0000 Subject: Improve %rename(match) documentation. git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12172 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Doc/Manual/SWIG.html | 38 +++++++++++++++++++++++++++++++++++--- 1 file changed, 35 insertions(+), 3 deletions(-) diff --git a/Doc/Manual/SWIG.html b/Doc/Manual/SWIG.html index 3fb1e86cc..7ce49529a 100644 --- a/Doc/Manual/SWIG.html +++ b/Doc/Manual/SWIG.html @@ -1931,14 +1931,30 @@ As explained in the previous sections, it is possible to either rename individual declarations or apply a rename rule to all of them at once. In practice, the latter is however rarely appropriate as there are always some exceptions to the general rules. To deal with them, the scope of an unnamed -%rename can be limited using a second parameter. +%rename can be limited using subsequent match parameters. +They can be applied to any of the attributes associated by SWIG with the +declarations appearing in its input. One of them is the declaration name and

- +
+
+%rename("foo", match$name="bar") "";
+
+

-The simplest possibility is to match the declaration type, for example: +can be used to achieve the same effect as the simpler

+%rename("foo") bar;
+
+
+

+However match can also be applied to the declaration type, for +example match="class" restricts the match to class declarations only +(in C++) and match="enumitem" restricts it to the enum elements. SWIG +also provides convenience macros for such match expressions, for example +

+
 %rename("%(title)s", %$isenumitem) "";
 
@@ -1950,6 +1966,22 @@ documentation is not exhaustive, see "%rename predicates" section of Lib/swig.swg for the full list of supported match expressions.

+

+Another important feature of match is that it can be applied not +only to the declaration itself but also to its enclosing declaration. So +match$parentNode$name="SomeClass" would be true only for members of +the C++ class with the specified name. This can, of course, be combined with +more complicated matches making it possible to write +

+
+
+%rename("%(lower)s", match$parentNode$name="SomeClass", %$isenum) "";
+
+
+

+to rename all enums nested in the given class to lower case. +

+

Finally, even more powerful variants of %rename and %ignore directives can be used to help wrap C++ overloaded functions and methods or C++ methods which use default arguments. This is described in the -- cgit v1.2.1 From 48a2e0bdea237f658507650e6b7233205385d72a Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Thu, 22 Jul 2010 17:01:36 +0000 Subject: Correct top_{src,build}dir definitions in csharp and java test suite. The ".." artificially appended to these variables was enough to make the build work in the source directory but broke down when the build directory was different from the source one. Remove this hack and use absolute path to the build directory instead to ensure that it's still valid even when csharp/java makefiles invoke swig_and_compile_{c,cpp} macros from a subdirectory. git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12173 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Examples/test-suite/csharp/Makefile.in | 6 +++--- Examples/test-suite/java/Makefile.in | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Examples/test-suite/csharp/Makefile.in b/Examples/test-suite/csharp/Makefile.in index 5f50095a1..18718ffe8 100644 --- a/Examples/test-suite/csharp/Makefile.in +++ b/Examples/test-suite/csharp/Makefile.in @@ -8,8 +8,8 @@ INTERPRETER = @CSHARPCILINTERPRETER@ CSHARPPATHSEPARATOR = "@CSHARPPATHSEPARATOR@" CSHARPCYGPATH_W = @CSHARPCYGPATH_W@ srcdir = @srcdir@ -top_srcdir = @top_srcdir@/.. -top_builddir = @top_builddir@/.. +top_srcdir = @top_srcdir@ +top_builddir = $(abspath @top_builddir@) CPP_TEST_CASES = \ csharp_attributes \ @@ -66,7 +66,7 @@ setup = \ # Note C# uses LD_LIBRARY_PATH under Unix, PATH under Cygwin/Windows and SHLIB_PATH on HPUX. run_testcase = \ if [ -f $(srcdir)/$(SCRIPTPREFIX)$*$(SCRIPTSUFFIX) ]; then \ - $(MAKE) -f $*/$(top_builddir)/$(EXAMPLES)/Makefile \ + $(MAKE) -f $(top_builddir)/$(EXAMPLES)/Makefile \ CSHARPFLAGS='-nologo $(CSHARPFLAGSSPECIAL) -out:$*_runme.exe' \ CSHARPSRCS='`$(CSHARPCYGPATH_W) $(srcdir)/$(SCRIPTPREFIX)$*$(SCRIPTSUFFIX)` `find $* -name "*.cs" -exec $(CSHARPCYGPATH_W) "{}" \+`' csharp_compile && \ env LD_LIBRARY_PATH="$*:$$LD_LIBRARY_PATH" PATH="$*:$$PATH" SHLIB_PATH="$*:$$SHLIB_PATH" $(RUNTOOL) $(INTERPRETER) $*_runme.exe; \ diff --git a/Examples/test-suite/java/Makefile.in b/Examples/test-suite/java/Makefile.in index ba225f6e9..0fc8c0511 100644 --- a/Examples/test-suite/java/Makefile.in +++ b/Examples/test-suite/java/Makefile.in @@ -7,8 +7,8 @@ JAVA = java JAVAC = javac SCRIPTSUFFIX = _runme.java srcdir = @srcdir@ -top_srcdir = @top_srcdir@/.. -top_builddir = @top_builddir@/.. +top_srcdir = @top_srcdir@ +top_builddir = $(abspath @top_builddir@) C_TEST_CASES = \ java_lib_arrays \ -- cgit v1.2.1 From 70c5bb5a47d7380cf5b5371a2b84ad04f330053a Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Thu, 22 Jul 2010 17:02:10 +0000 Subject: Add support for "[not]regexmatch" and "regextarget" to %rename. "regexmatch" and "notregexmatch" can be used with anonymous %renames in the same way as "match" and "notmatch" while "regextarget" specifies that the argument of a non-anonymous %rename should be interpreted as a regular expression. Document the new functions. Also add a new unit test for %regex also testing regexmatch &c and provide test code for C# and Java verifying that it works as intended. git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12174 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- CHANGES.current | 18 +++++++ Doc/Manual/SWIG.html | 45 ++++++++++++++-- Examples/test-suite/common.mk | 1 + .../test-suite/csharp/rename_pcre_enum_runme.cs | 24 +++++++++ .../test-suite/java/rename_pcre_enum_runme.java | 26 +++++++++ Examples/test-suite/rename_pcre_enum.i | 49 +++++++++++++++++ Source/Swig/naming.c | 61 ++++++++++++++++++++-- 7 files changed, 216 insertions(+), 8 deletions(-) create mode 100644 Examples/test-suite/csharp/rename_pcre_enum_runme.cs create mode 100644 Examples/test-suite/java/rename_pcre_enum_runme.java create mode 100644 Examples/test-suite/rename_pcre_enum.i diff --git a/CHANGES.current b/CHANGES.current index 9954ae05b..8c8b426b1 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -9,6 +9,24 @@ Version 2.0.1 (in progress) Fix wrapping of function pointers and member function pointers when the function returns by reference. +2010-07-13: vadz + Add "regexmatch", "regextarget" and "notregexmatch" which can be + used to apply %rename directives to the declarations matching the + specified regular expression only. The first two can be used + interchangeably, both of the %renames below do the same thing: + + %rename("$ignore", regexmatch$name="Old$") ""; + %rename("$ignore", regextarget=1) "Old$"; + + (namely ignore the declarations having "Old" suffix). + + "notregexmatch" restricts the match to only the declarations which + do not match the regular expression, e.g. here is how to rename to + lower case versions all declarations except those consisting from + capital letters only: + + %rename("$(lower)s", notregexmatch$name="^[A-Z]+$") ""; + 2010-07-13: vadz Add the new "regex" encoder that can be used in %rename, e.g. diff --git a/Doc/Manual/SWIG.html b/Doc/Manual/SWIG.html index 7ce49529a..1d8f28f1c 100644 --- a/Doc/Manual/SWIG.html +++ b/Doc/Manual/SWIG.html @@ -1949,10 +1949,12 @@ can be used to achieve the same effect as the simpler

-However match can also be applied to the declaration type, for -example match="class" restricts the match to class declarations only -(in C++) and match="enumitem" restricts it to the enum elements. SWIG -also provides convenience macros for such match expressions, for example +and so is not very interesting on its own. However match can also be +applied to the declaration type, for example match="class" restricts +the match to class declarations only (in C++) and match="enumitem" +restricts it to the enum elements. SWIG also provides convenience macros for +such match expressions, for example +

 %rename("%(title)s", %$isenumitem) "";
@@ -1983,7 +1985,40 @@ to rename all enums nested in the given class to lower case.
 

-Finally, even more powerful variants of %rename and %ignore directives can be used to help +And in addition to literally matching some string with match you can +also use regexmatch or notregexmatchto match a string +against a regular expression. For example, to ignore all functions having +"Old" suffix you could use +

+
+
+%rename("$ignore", regexmatch$name="Old$") "";
+
+
+

+For simple cases like this, specifying the regular expression for the +declaration name directly can be preferable and can be done using +regextarget: +

+
+
+%rename("$ignore", regextarget=1) "Old$";
+
+
+ +

+As for notregexmatch, it restricts the match only to the strings not +matching the specified regular expression. So to rename to lower case versions +all declarations except those consisting from capital letters only: +

+
+
+%rename("$(lower)s", notregexmatch$name="^[A-Z]+$") "";
+
+
+ +

+Finally, variants of %rename and %ignore directives can be used to help wrap C++ overloaded functions and methods or C++ methods which use default arguments. This is described in the Ambiguity resolution and renaming section in the C++ chapter.

diff --git a/Examples/test-suite/common.mk b/Examples/test-suite/common.mk index c7afb6647..af9316656 100644 --- a/Examples/test-suite/common.mk +++ b/Examples/test-suite/common.mk @@ -285,6 +285,7 @@ CPP_TEST_CASES += \ rename_scope \ rename_strip_encoder \ rename_pcre_encoder \ + rename_pcre_enum \ restrict_cplusplus \ return_const_value \ return_value_scope \ diff --git a/Examples/test-suite/csharp/rename_pcre_enum_runme.cs b/Examples/test-suite/csharp/rename_pcre_enum_runme.cs new file mode 100644 index 000000000..0143eda33 --- /dev/null +++ b/Examples/test-suite/csharp/rename_pcre_enum_runme.cs @@ -0,0 +1,24 @@ +using System; +using rename_pcre_enumNamespace; + +public class runme { + static void Main() { + Foo foo = Foo.First; + if ( foo == Foo.Second ) + throw new Exception("Enum values should be different"); + + // Check that Foo_Max enum element was ignored. + int numFooEnumElements = Enum.GetValues(typeof(Foo)).Length; + if ( numFooEnumElements != 2 ) + throw new Exception(String.Format("Enum should have 2 elements, not {0}", + numFooEnumElements)); + + BoundaryCondition bc = BoundaryCondition.MaxMax; + if ( (int)bc != 2 ) + throw new Exception("Wrong enum value"); + + Colour c = Colour.red; + if ( c == Colour.blue ) + throw new Exception("Enum values should be different"); + } +} diff --git a/Examples/test-suite/java/rename_pcre_enum_runme.java b/Examples/test-suite/java/rename_pcre_enum_runme.java new file mode 100644 index 000000000..a8bfef46a --- /dev/null +++ b/Examples/test-suite/java/rename_pcre_enum_runme.java @@ -0,0 +1,26 @@ +import rename_pcre_enum.*; + +public class rename_pcre_enum_runme { + static { System.loadLibrary("rename_pcre_enum"); } + + public static void main(String argv[]) + { + Foo foo = Foo.First; + if ( foo == Foo.Second ) + throw new RuntimeException("Enum values should be different"); + + // Check that Foo_Max enum element was ignored. + int numFooEnumElements = Foo.values().length; + if ( numFooEnumElements != 2 ) + throw new RuntimeException(String.format("Enum should have 2 elements, not %d", + numFooEnumElements)); + + BoundaryCondition bc = BoundaryCondition.MaxMax; + if ( bc.ordinal() != 2 ) + throw new RuntimeException("Wrong enum value"); + + Colour c = Colour.red; + if ( c == Colour.blue ) + throw new RuntimeException("Enum values should be different"); + } +} diff --git a/Examples/test-suite/rename_pcre_enum.i b/Examples/test-suite/rename_pcre_enum.i new file mode 100644 index 000000000..1bb7c1b8b --- /dev/null +++ b/Examples/test-suite/rename_pcre_enum.i @@ -0,0 +1,49 @@ +%module rename_pcre_enum + +// This file is needed for proper enum support in C#/Java backends +#if defined(SWIGCSHARP) || defined(SWIGJAVA) +%include "enums.swg" +#endif + +// Apply a rule for renaming the enum elements to avoid the common prefixes +// redundant in C#/Java +%rename("%(regex:/([A-Z][a-z]+)+_(.*)/\\2/)s",%$isenumitem) ""; + +// Also don't export special end of enum markers which are often used in C++ +// code to just have a symbolic name for the number of enum elements but are +// not needed in target language. +%rename("$ignore", regexmatch$name="([A-Z][a-z]+)+_Max$",%$isenumitem) ""; + +// Test another way of doing the same thing with regextarget: +%rename("$ignore", %$isenumitem, regextarget=1) "([A-Z][a-z]+)+_Internal$"; + +// Apply this renaming rule to all enum elements that don't contain more than +// one capital letter. +%rename("%(lower)s", notregexmatch$name="[A-Z]\\w*[A-Z]", %$isenumitem) ""; + +%inline %{ + +// Foo_Internal and Foo_Max won't be exported. +enum Foo { + Foo_Internal = -1, + Foo_First, + Foo_Second, + Foo_Max +}; + +// All elements of this enum will be exported because they do not match the +// excluding regex. +enum BoundaryCondition { + BoundaryCondition_MinMax, + BoundaryCondition_MaxMin, + BoundaryCondition_MaxMax +}; + +// The elements of this enum will have lower-case names. +enum Colour { + Red, + Blue, + Green +}; + +%} diff --git a/Source/Swig/naming.c b/Source/Swig/naming.c index 07e42f2d4..44daf30c9 100644 --- a/Source/Swig/naming.c +++ b/Source/Swig/naming.c @@ -1062,10 +1062,13 @@ static void Swig_name_object_attach_keys(const char *keys[], Hash *nameobj) { const char **rkey; int isnotmatch = 0; int isrxsmatch = 0; + int isregexmatch = 0; if ((strncmp(ckey, "match", 5) == 0) || (isnotmatch = (strncmp(ckey, "notmatch", 8) == 0)) || (isrxsmatch = (strncmp(ckey, "rxsmatch", 8) == 0)) - || (isnotmatch = isrxsmatch = (strncmp(ckey, "notrxsmatch", 11) == 0))) { + || (isregexmatch = (strncmp(ckey, "regexmatch", 10) == 0)) + || (isnotmatch = isrxsmatch = (strncmp(ckey, "notrxsmatch", 11) == 0)) + || (isnotmatch = isregexmatch = (strncmp(ckey, "notregexmatch", 13) == 0))) { Hash *mi = NewHash(); List *attrlist = Swig_make_attrlist(ckey); if (!matchlist) @@ -1080,6 +1083,8 @@ static void Swig_name_object_attach_keys(const char *keys[], Hash *nameobj) { SetFlag(mi, "notmatch"); if (isrxsmatch) SetFlag(mi, "rxsmatch"); + if (isregexmatch) + SetFlag(mi, "regexmatch"); Delete(attrlist); Append(matchlist, mi); Delete(mi); @@ -1155,6 +1160,51 @@ static DOH *Swig_get_lattr(Node *n, List *lattr) { return res; } +#ifdef HAVE_PCRE +#include + +int Swig_name_regexmatch_value(Node *n, String *pattern, String *s) { + pcre *compiled_pat; + const char *err; + int errpos; + int rc; + + compiled_pat = pcre_compile(Char(pattern), 0, &err, &errpos, NULL); + if (!compiled_pat) { + Swig_error("SWIG", Getline(n), + "Invalid regex \"%s\": compilation failed at %d: %s\n", + Char(pattern), errpos, err); + exit(1); + } + + rc = pcre_exec(compiled_pat, NULL, Char(s), Len(s), 0, 0, NULL, 0); + pcre_free(compiled_pat); + + if (rc == PCRE_ERROR_NOMATCH) + return 0; + + if (rc < 0 ) { + Swig_error("SWIG", Getline(n), + "Matching \"%s\" against regex \"%s\" failed: %d\n", + Char(s), Char(pattern), rc); + exit(1); + } + + return 1; +} + +#else /* !HAVE_PCRE */ + +int Swig_name_regexmatch_value(Node *n, String *pattern, String *s) { + (void)pattern; + (void)s; + Swig_error("SWIG", Getline(n), + "PCRE regex matching is not available in this SWIG build.\n"); + exit(1); +} + +#endif /* HAVE_PCRE/!HAVE_PCRE */ + #if defined(HAVE_RXSPENCER) #include #include @@ -1228,6 +1278,7 @@ int Swig_name_match_nameobj(Hash *rn, Node *n) { String *nval = Swig_get_lattr(n, lattr); int notmatch = GetFlag(mi, "notmatch"); int rxsmatch = GetFlag(mi, "rxsmatch"); + int regexmatch = GetFlag(mi, "regexmatch"); #ifdef SWIG_DEBUG Printf(stdout, "mi %d %s re %d not %d \n", i, nval, notmatch, rxsmatch); if (rxsmatch) { @@ -1238,6 +1289,7 @@ int Swig_name_match_nameobj(Hash *rn, Node *n) { if (nval) { String *kwval = Getattr(mi, "value"); match = rxsmatch ? Swig_name_rxsmatch_value(kwval, nval) + : regexmatch ? Swig_name_regexmatch_value(n, kwval, nval) : Swig_name_match_value(kwval, nval); #ifdef SWIG_DEBUG Printf(stdout, "val %s %s %d %d \n", nval, kwval, match, ilen); @@ -1278,6 +1330,7 @@ Hash *Swig_name_nameobj_lget(List *namelist, Node *n, String *prefix, String *na String *sname = 0; int fullname = GetFlag(rn, "fullname"); int rxstarget = GetFlag(rn, "rxstarget"); + int regextarget = GetFlag(rn, "regextarget"); if (sfmt) { if (fullname && prefix) { String *pname = NewStringf("%s::%s", prefix, name); @@ -1294,7 +1347,9 @@ Hash *Swig_name_nameobj_lget(List *namelist, Node *n, String *prefix, String *na DohIncref(name); } } - match = rxstarget ? Swig_name_rxsmatch_value(tname, sname) : Swig_name_match_value(tname, sname); + match = rxstarget ? Swig_name_rxsmatch_value(tname, sname) + : regextarget ? Swig_name_regexmatch_value(n, tname, sname) + : Swig_name_match_value(tname, sname); Delete(sname); } else { match = 1; @@ -1393,7 +1448,7 @@ void Swig_name_rename_add(String *prefix, String *name, SwigType *decl, Hash *ne ParmList *declparms = declaratorparms; - const char *rename_keys[] = { "fullname", "sourcefmt", "targetfmt", "continue", "rxstarget", 0 }; + const char *rename_keys[] = { "fullname", "sourcefmt", "targetfmt", "continue", "rxstarget", "regextarget", 0 }; Swig_name_object_attach_keys(rename_keys, newname); /* Add the name */ -- cgit v1.2.1 From 587d8435211cddb1389733c462a7d1d02af17fea Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Thu, 22 Jul 2010 17:02:35 +0000 Subject: Remove old experimental rxspencer encoder and rxsmatch function. They are replaced with the new, officially supported PCRE-based regex and regexmatch. git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12175 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- CHANGES.current | 11 ++++ Examples/test-suite/enum_rename.i | 2 +- Examples/test-suite/rename_camel.i | 4 +- Source/Swig/misc.c | 107 ------------------------------------- Source/Swig/naming.c | 56 ++----------------- configure.in | 18 ------- 6 files changed, 17 insertions(+), 181 deletions(-) diff --git a/CHANGES.current b/CHANGES.current index 8c8b426b1..6cd13990c 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -9,6 +9,17 @@ Version 2.0.1 (in progress) Fix wrapping of function pointers and member function pointers when the function returns by reference. +2010-07-13: vadz + Removed support for the old experimental "rxspencer" encoder and + "[not]rxsmatch" in %rename (see the 01/16/2006 entry). The new and + officially supported "regex" encoder and "[not]regexmatch" checks + should be used instead (see the two previous entries). Please + replace "%(rxspencer:[pat][subst])s" with "%(regex:/pat/subst/)s" + when upgrading. Notice that you will also need to replace the back- + references of form "@1" with the more standard "\\1" and may need to + adjust your regular expressions syntax as the new regex encoder uses + Perl-compatible syntax and not (extended) POSIX syntax as the old one. + 2010-07-13: vadz Add "regexmatch", "regextarget" and "notregexmatch" which can be used to apply %rename directives to the declarations matching the diff --git a/Examples/test-suite/enum_rename.i b/Examples/test-suite/enum_rename.i index 455826f8b..0cab4d0d8 100644 --- a/Examples/test-suite/enum_rename.i +++ b/Examples/test-suite/enum_rename.i @@ -2,7 +2,7 @@ %warnfilter(SWIGWARN_PARSE_REDEFINED) S_May; -// %rename with rxspencer can do the equivalent of these two renames, which was resulting in uncompileable code +// %rename using regex can do the equivalent of these two renames, which was resulting in uncompileable code %rename(May) M_May; %rename(May) S_May; diff --git a/Examples/test-suite/rename_camel.i b/Examples/test-suite/rename_camel.i index 54f06f967..970bb9215 100644 --- a/Examples/test-suite/rename_camel.i +++ b/Examples/test-suite/rename_camel.i @@ -33,7 +33,7 @@ %rename(awk_cmd) ""; -%rename("%(title)s",rxsmatch$parentNode$type="enum .*") ""; +%rename("%(title)s",regexmatch$parentNode$type="enum .*") ""; %inline { @@ -59,7 +59,7 @@ } -%rename("%(lowercase)s",sourcefmt="%(rxspencer:[GSL_(.*)][@1])s",%$isfunction) ""; +%rename("%(lowercase)s",sourcefmt="%(regex:/GSL_(.*)/\\1/)s",%$isfunction) ""; %inline { void GSL_Hello() {} } diff --git a/Source/Swig/misc.c b/Source/Swig/misc.c index b23a99b60..14470485e 100644 --- a/Source/Swig/misc.c +++ b/Source/Swig/misc.c @@ -1108,112 +1108,6 @@ String *Swig_string_strip(String *s) { } -/* ----------------------------------------------------------------------------- - * Swig_string_rxspencer() - * - * Executes a regexp substitution via the RxSpencer library. For example: - * - * Printf(stderr,"gsl%(rxspencer:[GSL_.*_][@1])s","GSL_Hello_") -> gslHello - * ----------------------------------------------------------------------------- */ -#if defined(HAVE_RXSPENCER) -#include -#include -#define USE_RXSPENCER -#endif - -const char *skip_delim(char pb, char pe, const char *ce) { - int end = 0; - int lb = 0; - while (!end && *ce != '\0') { - if (*ce == pb) { - ++lb; - } - if (*ce == pe) { - if (!lb) { - end = 1; - --ce; - } else { - --lb; - } - } - ++ce; - } - return end ? ce : 0; -} - - -#if defined(USE_RXSPENCER) -String *Swig_string_rxspencer(String *s) { - String *res = 0; - if (Len(s)) { - const char *cs = Char(s); - const char *cb; - const char *ce; - if (*cs == '[') { - int retval; - regex_t compiled; - cb = ++cs; - ce = skip_delim('[', ']', cb); - if (ce) { - char bregexp[512]; - strncpy(bregexp, cb, ce - cb); - bregexp[ce - cb] = '\0'; - ++ce; - retval = regcomp(&compiled, bregexp, REG_EXTENDED); - if (retval == 0) { - cs = ce; - if (*cs == '[') { - cb = ++cs; - ce = skip_delim('[', ']', cb); - if (ce) { - const char *cvalue = ce + 1; - int nsub = (int) compiled.re_nsub + 1; - regmatch_t *pmatch = (regmatch_t *) malloc(sizeof(regmatch_t) * (nsub)); - retval = regexec(&compiled, cvalue, nsub, pmatch, 0); - if (retval != REG_NOMATCH) { - char *spos = 0; - res = NewStringWithSize(cb, ce - cb); - spos = Strchr(res, '@'); - while (spos) { - char cd = *(++spos); - if (isdigit(cd)) { - char arg[8]; - size_t len; - int i = cd - '0'; - sprintf(arg, "@%d", i); - if (i < nsub && (len = pmatch[i].rm_eo - pmatch[i].rm_so)) { - char value[256]; - strncpy(value, cvalue + pmatch[i].rm_so, len); - value[len] = 0; - Replaceall(res, arg, value); - } else { - Replaceall(res, arg, ""); - } - spos = Strchr(res, '@'); - } else if (cd == '@') { - spos = strchr(spos + 1, '@'); - } - } - } - free(pmatch); - } - } - } - regfree(&compiled); - } - } - } - if (!res) - res = NewStringEmpty(); - return res; -} -#else -String *Swig_string_rxspencer(String *s) { - (void) s; - return NewStringEmpty(); -} -#endif - #ifdef HAVE_PCRE #include @@ -1338,7 +1232,6 @@ void Swig_init() { DohEncoding("typecode", Swig_string_typecode); DohEncoding("mangle", Swig_string_emangle); DohEncoding("command", Swig_string_command); - DohEncoding("rxspencer", Swig_string_rxspencer); DohEncoding("schemify", Swig_string_schemify); DohEncoding("strip", Swig_string_strip); DohEncoding("regex", Swig_string_regex); diff --git a/Source/Swig/naming.c b/Source/Swig/naming.c index 44daf30c9..5bf42f7cc 100644 --- a/Source/Swig/naming.c +++ b/Source/Swig/naming.c @@ -1061,13 +1061,10 @@ static void Swig_name_object_attach_keys(const char *keys[], Hash *nameobj) { if (ckey) { const char **rkey; int isnotmatch = 0; - int isrxsmatch = 0; int isregexmatch = 0; if ((strncmp(ckey, "match", 5) == 0) || (isnotmatch = (strncmp(ckey, "notmatch", 8) == 0)) - || (isrxsmatch = (strncmp(ckey, "rxsmatch", 8) == 0)) || (isregexmatch = (strncmp(ckey, "regexmatch", 10) == 0)) - || (isnotmatch = isrxsmatch = (strncmp(ckey, "notrxsmatch", 11) == 0)) || (isnotmatch = isregexmatch = (strncmp(ckey, "notregexmatch", 13) == 0))) { Hash *mi = NewHash(); List *attrlist = Swig_make_attrlist(ckey); @@ -1075,14 +1072,8 @@ static void Swig_name_object_attach_keys(const char *keys[], Hash *nameobj) { matchlist = NewList(); Setattr(mi, "value", Getattr(kw, "value")); Setattr(mi, "attrlist", attrlist); -#ifdef SWIG_DEBUG - if (isrxsmatch) - Printf(stdout, "rxsmatch to use: %s %s %s\n", ckey, Getattr(kw, "value"), attrlist); -#endif if (isnotmatch) SetFlag(mi, "notmatch"); - if (isrxsmatch) - SetFlag(mi, "rxsmatch"); if (isregexmatch) SetFlag(mi, "regexmatch"); Delete(attrlist); @@ -1205,37 +1196,6 @@ int Swig_name_regexmatch_value(Node *n, String *pattern, String *s) { #endif /* HAVE_PCRE/!HAVE_PCRE */ -#if defined(HAVE_RXSPENCER) -#include -#include -#define USE_RXSPENCER -#endif - -#if defined(USE_RXSPENCER) -int Swig_name_rxsmatch_value(String *mvalue, String *value) { - int match = 0; - char *cvalue = Char(value); - char *cmvalue = Char(mvalue); - regex_t compiled; - int retval = regcomp(&compiled, cmvalue, REG_EXTENDED | REG_NOSUB); - if (retval != 0) - return 0; - retval = regexec(&compiled, cvalue, 0, 0, 0); - match = (retval == REG_NOMATCH) ? 0 : 1; -#ifdef SWIG_DEBUG - Printf(stdout, "rxsmatch_value: %s %s %d\n", cvalue, cmvalue, match); -#endif - regfree(&compiled); - return match; -} -#else -int Swig_name_rxsmatch_value(String *mvalue, String *value) { - (void) mvalue; - (void) value; - return 0; -} -#endif - int Swig_name_match_value(String *mvalue, String *value) { #if defined(SWIG_USE_SIMPLE_MATCHOR) int match = 0; @@ -1277,19 +1237,11 @@ int Swig_name_match_nameobj(Hash *rn, Node *n) { List *lattr = Getattr(mi, "attrlist"); String *nval = Swig_get_lattr(n, lattr); int notmatch = GetFlag(mi, "notmatch"); - int rxsmatch = GetFlag(mi, "rxsmatch"); int regexmatch = GetFlag(mi, "regexmatch"); -#ifdef SWIG_DEBUG - Printf(stdout, "mi %d %s re %d not %d \n", i, nval, notmatch, rxsmatch); - if (rxsmatch) { - Printf(stdout, "rxsmatch %s\n", lattr); - } -#endif match = 0; if (nval) { String *kwval = Getattr(mi, "value"); - match = rxsmatch ? Swig_name_rxsmatch_value(kwval, nval) - : regexmatch ? Swig_name_regexmatch_value(n, kwval, nval) + match = regexmatch ? Swig_name_regexmatch_value(n, kwval, nval) : Swig_name_match_value(kwval, nval); #ifdef SWIG_DEBUG Printf(stdout, "val %s %s %d %d \n", nval, kwval, match, ilen); @@ -1329,7 +1281,6 @@ Hash *Swig_name_nameobj_lget(List *namelist, Node *n, String *prefix, String *na String *sfmt = Getattr(rn, "sourcefmt"); String *sname = 0; int fullname = GetFlag(rn, "fullname"); - int rxstarget = GetFlag(rn, "rxstarget"); int regextarget = GetFlag(rn, "regextarget"); if (sfmt) { if (fullname && prefix) { @@ -1347,8 +1298,7 @@ Hash *Swig_name_nameobj_lget(List *namelist, Node *n, String *prefix, String *na DohIncref(name); } } - match = rxstarget ? Swig_name_rxsmatch_value(tname, sname) - : regextarget ? Swig_name_regexmatch_value(n, tname, sname) + match = regextarget ? Swig_name_regexmatch_value(n, tname, sname) : Swig_name_match_value(tname, sname); Delete(sname); } else { @@ -1448,7 +1398,7 @@ void Swig_name_rename_add(String *prefix, String *name, SwigType *decl, Hash *ne ParmList *declparms = declaratorparms; - const char *rename_keys[] = { "fullname", "sourcefmt", "targetfmt", "continue", "rxstarget", "regextarget", 0 }; + const char *rename_keys[] = { "fullname", "sourcefmt", "targetfmt", "continue", "regextarget", 0 }; Swig_name_object_attach_keys(rename_keys, newname); /* Add the name */ diff --git a/configure.in b/configure.in index e5e2752d9..1a6b37b57 100644 --- a/configure.in +++ b/configure.in @@ -73,24 +73,6 @@ AS_IF([test "x$with_pcre" != xno], ]) -dnl Look for RxSpencer -AC_ARG_WITH(rxspencer, AS_HELP_STRING([--with-rxspencer], [Enable RxSpencer]), with_rxspencer="yes") -if test x"${with_rxspencer}" = xyes ; then -#check first for the header - AC_CHECK_HEADER(rxspencer/regex.h,with_rxspencer="yes",with_rxspencer="no") - if test x"${with_rxspencer}" = xyes ; then -# now check for the library - AC_CHECK_LIB(rxspencer, regcomp,with_rxspencer="yes",with_rxspencer="no") - fi - if test x"${with_rxspencer}" = xyes ; then -# library and header are available - AC_DEFINE(HAVE_RXSPENCER, 1,[Define if rxspencer is available]) - LIBS="$LIBS -lrxspencer" - else - AC_MSG_NOTICE([RxSpencer not found. Obtain it at http://arglist.com/regex or http://gnuwin32.sourceforge.net/packages.html]) - fi -fi - dnl CCache AC_ARG_ENABLE([ccache], AS_HELP_STRING([--disable-ccache], [disable building and installation of ccache-swig executable (default enabled)]), [enable_ccache=$enableval], [enable_ccache=yes]) AC_MSG_CHECKING([whether to enable ccache-swig]) -- cgit v1.2.1 From 89a7ab06856f3f0d7e879d6c3df9c6db85792d6b Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Thu, 22 Jul 2010 17:02:55 +0000 Subject: Include the values of configurable options in `swig -version`. Show the value of important compilation options in swig -version output. Currently there is just one such option, for PCRE use, but more may be added in the future. git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12176 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Source/Modules/main.cxx | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/Source/Modules/main.cxx b/Source/Modules/main.cxx index f0e941f22..3f2008d7d 100644 --- a/Source/Modules/main.cxx +++ b/Source/Modules/main.cxx @@ -622,7 +622,14 @@ void SWIG_getoptions(int argc, char *argv[]) { } else if (strcmp(argv[i], "-version") == 0) { fprintf(stdout, "\nSWIG Version %s\n", Swig_package_version()); fprintf(stdout, "\nCompiled with %s [%s]\n", SWIG_CXX, SWIG_PLATFORM); - fprintf(stdout, "Please see %s for reporting bugs and further information\n", PACKAGE_BUGREPORT); + fprintf(stdout, "\nConfigured options: %cpcre\n", +#ifdef HAVE_PCRE + '+' +#else + '-' +#endif + ); + fprintf(stdout, "\nPlease see %s for reporting bugs and further information\n", PACKAGE_BUGREPORT); SWIG_exit(EXIT_SUCCESS); } else if (strcmp(argv[i], "-copyright") == 0) { fprintf(stdout, "\nSWIG Version %s\n", Swig_package_version()); -- cgit v1.2.1 From d2ad66a9a9aec4ed7bf96af716a8f87a57eb7a45 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Fri, 23 Jul 2010 07:17:15 +0000 Subject: remove duplicate definition of %$isextend git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12178 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Lib/swig.swg | 1 - 1 file changed, 1 deletion(-) diff --git a/Lib/swig.swg b/Lib/swig.swg index ec903533c..4ec3d35e6 100644 --- a/Lib/swig.swg +++ b/Lib/swig.swg @@ -269,7 +269,6 @@ static int NAME(TYPE x) { %define %$isaccess "match"="access" %enddef %define %$isclass "match"="class","notmatch$template$templatetype"="class" %enddef %define %$isextend "match"="extend" %enddef -%define %$isextend "match"="extend" %enddef %define %$isconstructor "match"="constructor" %enddef %define %$isdestructor "match"="destructor" %enddef %define %$isnamespace "match"="namespace" %enddef -- cgit v1.2.1 From f6346b3df1252b9745164d1759fab32e9e1cbea4 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Fri, 23 Jul 2010 07:21:46 +0000 Subject: minor edits in %rename sections git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12179 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Doc/Manual/SWIG.html | 48 ++++++++++++++++++++++++------------------------ 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/Doc/Manual/SWIG.html b/Doc/Manual/SWIG.html index 1d8f28f1c..4ea55621e 100644 --- a/Doc/Manual/SWIG.html +++ b/Doc/Manual/SWIG.html @@ -1765,7 +1765,7 @@ While writing %rename for specific declarations is simple enough, sometimes the same renaming rule needs to be applied to many, maybe all, identifiers in the SWIG input. For example, it may be necessary to apply some transformation to all the names in the target language to better follow its -naming conventions, e.g. add a specific prefix to all the functions. Doing it +naming conventions, like adding a specific prefix to all wrapped functions. Doing it individually for each function is impractical so SWIG supports applying a renaming rule to all declarations if the name of the identifier to be renamed is not specified:

@@ -1799,28 +1799,28 @@ strips the provided prefix from its argument. The prefix is specified as part of the format string, following a colon after the function name:
-%rename("%(strip:[wx])s") ""; // wxHello -> Hello; FooBar -> fooBar
+%rename("%(strip:[wx])s") ""; // wxHello -> Hello; FooBar -> FooBar
 

-Here is the table summarizing all currently defined functions with an example -of applying each one (notice that some of them have two names, a shorter one -and a more descriptive one, but the two functions are otherwise equivalent): +Below is the table summarizing all currently defined functions with an example +of applying each one. Note that some of them have two names, a shorter one +and a more descriptive one, but the two functions are otherwise equivalent:

- - + + - - + + @@ -1839,23 +1839,23 @@ and a more descriptive one, but the two functions are otherwise equivalent): - + - + - - + + Logically, this is the reverse of camelcase. @@ -1933,7 +1933,7 @@ practice, the latter is however rarely appropriate as there are always some exceptions to the general rules. To deal with them, the scope of an unnamed %rename can be limited using subsequent match parameters. They can be applied to any of the attributes associated by SWIG with the -declarations appearing in its input. One of them is the declaration name and +declarations appearing in its input. For example:

@@ -1965,7 +1965,7 @@ will capitalize the names of all the enum elements but not change the case of
 the other declarations. Similarly, %$isclass, %$isfunction
 and %$isvariable can be used. Many other checks are possible and this
 documentation is not exhaustive, see "%rename predicates" section of
-Lib/swig.swg for the full list of supported match expressions.
+swig.swg for the full list of supported match expressions.
 

@@ -1985,10 +1985,10 @@ to rename all enums nested in the given class to lower case.

-And in addition to literally matching some string with match you can -also use regexmatch or notregexmatchto match a string +In addition to literally matching some string with match you can +also use regexmatch or notregexmatch to match a string against a regular expression. For example, to ignore all functions having -"Old" suffix you could use +"Old" as a suffix you could use

@@ -1997,7 +1997,7 @@ against a regular expression. For example, to ignore all functions having
 

For simple cases like this, specifying the regular expression for the -declaration name directly can be preferable and can be done using +declaration name directly can be preferable and can also be done using regextarget:

@@ -2008,8 +2008,8 @@ declaration name directly can be preferable and can be done using

As for notregexmatch, it restricts the match only to the strings not -matching the specified regular expression. So to rename to lower case versions -all declarations except those consisting from capital letters only: +matching the specified regular expression. So to rename all declarations to lower case +except those consisting of capital letters only:

@@ -2187,7 +2187,7 @@ normally, just use the original function name such as add().
 

SWIG provides a number of extensions to standard C printf formatting that may be useful in this context. For instance, the following -variation installs the callbacks as all upper-case constants such as +variation installs the callbacks as all upper case constants such as ADD, SUB, and MUL:

@@ -2201,7 +2201,7 @@ int mul(int,int);

-A format string of "%(lower)s" converts all characters to lower-case. +A format string of "%(lower)s" converts all characters to lower case. A string of "%(title)s" capitalizes the first character and converts the rest to lower case.

-- cgit v1.2.1 From c6c2c87e2ac9a9816ab056c1b90b1d9f119e0526 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Fri, 23 Jul 2010 07:23:10 +0000 Subject: Add message about whether pcre is enabled or not git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12180 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- configure.in | 2 ++ 1 file changed, 2 insertions(+) diff --git a/configure.in b/configure.in index 1a6b37b57..1e51956d9 100644 --- a/configure.in +++ b/configure.in @@ -56,6 +56,8 @@ AC_ARG_WITH([pcre], [], [with_pcre=yes]) +AC_MSG_CHECKING([whether to enable PCRE support]) +AC_MSG_RESULT([$with_pcre]) AS_IF([test "x$with_pcre" != xno], [AX_PATH_GENERIC([pcre], [], dnl Minimal version of PCRE we need -- accept any -- cgit v1.2.1 From af96789c14eb45eb874996a603eb8a1eab960244 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Fri, 23 Jul 2010 19:34:17 +0000 Subject: Minor comment changes and html changes git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12181 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- CHANGES.current | 4 +++- Doc/Manual/Contents.html | 5 +++++ Doc/Manual/SWIG.html | 23 ++++++++++++++++------- Source/Swig/misc.c | 2 +- 4 files changed, 25 insertions(+), 9 deletions(-) diff --git a/CHANGES.current b/CHANGES.current index 6cd13990c..3dc3556a1 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -20,6 +20,8 @@ Version 2.0.1 (in progress) adjust your regular expressions syntax as the new regex encoder uses Perl-compatible syntax and not (extended) POSIX syntax as the old one. + *** POTENTIAL INCOMPATIBILITY *** + 2010-07-13: vadz Add "regexmatch", "regextarget" and "notregexmatch" which can be used to apply %rename directives to the declarations matching the @@ -36,7 +38,7 @@ Version 2.0.1 (in progress) lower case versions all declarations except those consisting from capital letters only: - %rename("$(lower)s", notregexmatch$name="^[A-Z]+$") ""; + %rename("$(lowercase)s", notregexmatch$name="^[A-Z]+$") ""; 2010-07-13: vadz Add the new "regex" encoder that can be used in %rename, e.g. diff --git a/Doc/Manual/Contents.html b/Doc/Manual/Contents.html index 66bf41264..ec99a6511 100644 --- a/Doc/Manual/Contents.html +++ b/Doc/Manual/Contents.html @@ -152,6 +152,11 @@
  • Arrays
  • Creating read-only variables
  • Renaming and ignoring declarations +
  • Default/optional arguments
  • Pointers to functions and callbacks diff --git a/Doc/Manual/SWIG.html b/Doc/Manual/SWIG.html index 4ea55621e..32fbe3815 100644 --- a/Doc/Manual/SWIG.html +++ b/Doc/Manual/SWIG.html @@ -44,6 +44,11 @@
  • Arrays
  • Creating read-only variables
  • Renaming and ignoring declarations +
  • Default/optional arguments
  • Pointers to functions and callbacks @@ -1661,7 +1666,9 @@ generate a warning message. Simply change the directives to %immutable;5.4.7 Renaming and ignoring declarations -

    5.4.7.1 Simple renaming of specific identifiers

    + +

    5.4.7.1 Simple renaming of specific identifiers

    +

    Normally, the name of a C declaration is used when that declaration is @@ -1758,7 +1765,8 @@ This directive is still supported, but it is deprecated and should probably be a directive is more powerful and better supports wrapping of raw header file information.

    -

    5.4.7.2 Advanced renaming support

    +

    5.4.7.2 Advanced renaming support

    +

    While writing %rename for specific declarations is simple enough, @@ -1797,12 +1805,12 @@ can use the "lowercamelcase" extended format specifier like this: Some functions can be parametrized, for example the "strip" one strips the provided prefix from its argument. The prefix is specified as part of the format string, following a colon after the function name: +

     %rename("%(strip:[wx])s") ""; // wxHello -> Hello; FooBar -> FooBar
     
    -

    Below is the table summarizing all currently defined functions with an example @@ -1924,7 +1932,8 @@ are exactly equivalent and %rename can be used to selectively ignore multiple declarations using the previously described matching possibilities.

    -

    5.4.7.3 Limiting global renaming rules

    +

    5.4.7.3 Limiting global renaming rules

    +

    As explained in the previous sections, it is possible to either rename @@ -1977,7 +1986,7 @@ more complicated matches making it possible to write

    -%rename("%(lower)s", match$parentNode$name="SomeClass", %$isenum) "";
    +%rename("%(lowercase)s", match$parentNode$name="SomeClass", %$isenum) "";
     

    @@ -2193,7 +2202,7 @@ variation installs the callbacks as all upper case constants such as

     /* Some callback functions */
    -%callback("%(upper)s");
    +%callback("%(uppercase)s");
     int add(int,int);
     int sub(int,int);
     int mul(int,int);
    @@ -2201,7 +2210,7 @@ int mul(int,int);
     

    -A format string of "%(lower)s" converts all characters to lower case. +A format string of "%(lowercase)s" converts all characters to lower case. A string of "%(title)s" capitalizes the first character and converts the rest to lower case.

    diff --git a/Source/Swig/misc.c b/Source/Swig/misc.c index 14470485e..b3c647546 100644 --- a/Source/Swig/misc.c +++ b/Source/Swig/misc.c @@ -1173,7 +1173,7 @@ String *replace_captures(const char *input, String *subst, int captures[]) /* ----------------------------------------------------------------------------- * Swig_string_regex() * - * Executes a regexp substitution. For example: + * Executes a regular expression substitution. For example: * * Printf(stderr,"gsl%(regex:/GSL_.*_/\\1/)s","GSL_Hello_") -> gslHello * ----------------------------------------------------------------------------- */ -- cgit v1.2.1 From 70b4d1231743911806b8a9625926187ce914560b Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Wed, 28 Jul 2010 05:53:17 +0000 Subject: Restore in source and out of source builds for the test-suite. Note that configure must be invoked using a relative path for out of source builds git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12186 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- CHANGES.current | 7 +++++++ Examples/test-suite/csharp/Makefile.in | 6 +++--- Examples/test-suite/java/Makefile.in | 4 ++-- 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/CHANGES.current b/CHANGES.current index 3dc3556a1..8fbb9a47f 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -5,6 +5,13 @@ See the RELEASENOTES file for a summary of changes in each release. Version 2.0.1 (in progress) =========================== +2010-07-28: wsfulton + Restore configuring out of source for the test-suite since it broke in 1.3.37. + As previously, if running 'make check-test-suite' out of source, it needs to be + done by invoking configure with a relative path. Invoking configure with an + absolute path will not work. Running the full 'make check' still needs to be + done in the source tree. + 2010-07-16: wsfulton Fix wrapping of function pointers and member function pointers when the function returns by reference. diff --git a/Examples/test-suite/csharp/Makefile.in b/Examples/test-suite/csharp/Makefile.in index 18718ffe8..48731f82b 100644 --- a/Examples/test-suite/csharp/Makefile.in +++ b/Examples/test-suite/csharp/Makefile.in @@ -8,8 +8,8 @@ INTERPRETER = @CSHARPCILINTERPRETER@ CSHARPPATHSEPARATOR = "@CSHARPPATHSEPARATOR@" CSHARPCYGPATH_W = @CSHARPCYGPATH_W@ srcdir = @srcdir@ -top_srcdir = @top_srcdir@ -top_builddir = $(abspath @top_builddir@) +top_srcdir = ../@top_srcdir@ +top_builddir = ../@top_builddir@ CPP_TEST_CASES = \ csharp_attributes \ @@ -66,7 +66,7 @@ setup = \ # Note C# uses LD_LIBRARY_PATH under Unix, PATH under Cygwin/Windows and SHLIB_PATH on HPUX. run_testcase = \ if [ -f $(srcdir)/$(SCRIPTPREFIX)$*$(SCRIPTSUFFIX) ]; then \ - $(MAKE) -f $(top_builddir)/$(EXAMPLES)/Makefile \ + $(MAKE) -f $*/$(top_builddir)/$(EXAMPLES)/Makefile \ CSHARPFLAGS='-nologo $(CSHARPFLAGSSPECIAL) -out:$*_runme.exe' \ CSHARPSRCS='`$(CSHARPCYGPATH_W) $(srcdir)/$(SCRIPTPREFIX)$*$(SCRIPTSUFFIX)` `find $* -name "*.cs" -exec $(CSHARPCYGPATH_W) "{}" \+`' csharp_compile && \ env LD_LIBRARY_PATH="$*:$$LD_LIBRARY_PATH" PATH="$*:$$PATH" SHLIB_PATH="$*:$$SHLIB_PATH" $(RUNTOOL) $(INTERPRETER) $*_runme.exe; \ diff --git a/Examples/test-suite/java/Makefile.in b/Examples/test-suite/java/Makefile.in index 0fc8c0511..1ba888fc1 100644 --- a/Examples/test-suite/java/Makefile.in +++ b/Examples/test-suite/java/Makefile.in @@ -7,8 +7,8 @@ JAVA = java JAVAC = javac SCRIPTSUFFIX = _runme.java srcdir = @srcdir@ -top_srcdir = @top_srcdir@ -top_builddir = $(abspath @top_builddir@) +top_srcdir = ../@top_srcdir@ +top_builddir = ../@top_builddir@ C_TEST_CASES = \ java_lib_arrays \ -- cgit v1.2.1 From 024ed6ce2a3191c57c5c030dd133bf0e9e2a1971 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sat, 14 Aug 2010 14:12:23 +0000 Subject: Fix bug in applying regex replacement to non-matching strings. We didn't handle pcre_exec() return code properly and so the replacement could be still done even if there was no match if the replacement part contained anything else than back-references (in this, the only tested so far, case the replacement was still done but the result turned out to be empty and the calling code assumed the regex didn't match). Do check for PCRE_ERROR_NOMATCH now and also give an error message if another error unexpectedly occurred. Add a test case for the bug that was fixed. git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12187 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Examples/test-suite/rename_pcre_encoder.i | 7 ++++++- Source/Swig/misc.c | 13 +++++++++++-- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/Examples/test-suite/rename_pcre_encoder.i b/Examples/test-suite/rename_pcre_encoder.i index 568a2a82d..1bee1dca8 100644 --- a/Examples/test-suite/rename_pcre_encoder.i +++ b/Examples/test-suite/rename_pcre_encoder.i @@ -3,9 +3,14 @@ // strip the wx prefix from all identifiers except those starting with wxEVT %rename("%(regex:/wx(?!EVT)(.*)/\\1/)s") ""; +// Replace "Set" prefix with "put" in all functions +%rename("%(regex:/^Set(.*)/put\\1/)s", %$isfunction) ""; + %inline %{ -class wxSomeWidget { +struct wxSomeWidget { + void SetBorderWidth(int); + void SetSize(int, int); }; struct wxAnotherWidget { diff --git a/Source/Swig/misc.c b/Source/Swig/misc.c index b3c647546..2105f0c51 100644 --- a/Source/Swig/misc.c +++ b/Source/Swig/misc.c @@ -1188,6 +1188,8 @@ String *Swig_string_regex(String *s) { int captures[30]; if (split_regex_pattern_subst(s, &pattern, &subst, &input)) { + int rc; + compiled_pat = pcre_compile( Char(pattern), pcre_options, &pcre_error, &pcre_errorpos, NULL); if (!compiled_pat) { @@ -1195,8 +1197,15 @@ String *Swig_string_regex(String *s) { pcre_error, Char(pattern), pcre_errorpos); exit(1); } - pcre_exec(compiled_pat, NULL, input, strlen(input), 0, 0, captures, 30); - res = replace_captures(input, subst, captures); + rc = pcre_exec(compiled_pat, NULL, input, strlen(input), 0, 0, captures, 30); + if (rc >= 0) { + res = replace_captures(input, subst, captures); + } + else if (rc != PCRE_ERROR_NOMATCH) { + Swig_error("SWIG", Getline(s), "PCRE execution failed: error %d while matching \"%s\" in \"%s\".\n", + rc, Char(pattern), input); + exit(1); + } } DohDelete(pattern); -- cgit v1.2.1 From 9b097847158aea3429cdf555dd40961133bffb52 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sat, 14 Aug 2010 14:12:39 +0000 Subject: Add more regex function usage examples in %rename section. Mention the examples from the test suite and the change log file in the manual as well. git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12188 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Doc/Manual/SWIG.html | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/Doc/Manual/SWIG.html b/Doc/Manual/SWIG.html index 32fbe3815..bdd0edb8b 100644 --- a/Doc/Manual/SWIG.html +++ b/Doc/Manual/SWIG.html @@ -1904,6 +1904,28 @@ and a more descriptive one, but the two functions are otherwise equivalent:
  • FunctionReturnsExample (in/out)
    upper or uppercaseUpper-case version of the string.uppercase or upperUpper case version of the string. PrintPRINT
    lower or lowercaseLower-case version of the string.lowercase or lowerLower case version of the string. Printprint
    PrintItprintIt
    ctitle or camelcasecamelcase or ctitle String with capitalized first letter and any letter following an underscore (which are removed in the process) and rest in lower case. print_itPrintIt
    lctitle or lowercamelcaselowercamelcase or lctitle String with every letter following an underscore (which is removed in the process) capitalized and rest, including the first letter, in lower case. print_itprintIt
    utitle or undercaseLower case string with underscores inserted before every upper-case + undercase or utitleLower case string with underscores inserted before every upper case letter in the original string and any number not at the end of string. - Logically, this is the reverse of ccase. PrintItprint_it
    +

    +The most general function of all of the above ones (not counting +command which is even more powerful in principle but which should +generally be avoided because of performance considerations) is the +regex one. Here are some more examples of its use: +

    +
    +// Strip the wx prefix from all identifiers except those starting with wxEVT
    +%rename("%(regex:/wx(?!EVT)(.*)/\\1/)s") ""; // wxSomeWidget -> SomeWidget
    +                                             // wxEVT_PAINT -> wxEVT_PAINT
    +
    +// Apply a rule for renaming the enum elements to avoid the common prefixes
    +// which are redundant in C#/Java
    +%rename("%(regex:/^([A-Z][a-z]+)+_(.*)/\\2/)s", %$isenumitem) ""; // Colour_Red -> Red
    +
    +// Remove all "Set/Get" prefixes.
    +%rename("%(regex:/^(Set|Get)(.*)/\\2/)s") ""; // SetValue -> Value
    +                                              // GetValue -> Value
    +
    +
    +

    +

    As before, everything that was said above about %rename also applies to %ignore. In fact, the latter is just a special case of the former and -- cgit v1.2.1 From 1c8618d6355f3d246dd7b7b986454672d1092430 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Tue, 17 Aug 2010 18:40:14 +0000 Subject: Modified patch from Torsten Landschoff for fixing make distclean when the target languages that have no examples are detected - the default target was erroneously being run for clean and check of the examples git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12189 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- CHANGES.current | 4 ++++ Makefile.in | 4 +++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/CHANGES.current b/CHANGES.current index 8fbb9a47f..d24f6c312 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -5,6 +5,10 @@ See the RELEASENOTES file for a summary of changes in each release. Version 2.0.1 (in progress) =========================== +2010-08-17: wsfulton + Fix make distclean when some of the more obscure languages are detected by + configure - fixes from Torsten Landschoff. + 2010-07-28: wsfulton Restore configuring out of source for the test-suite since it broke in 1.3.37. As previously, if running 'make check-test-suite' out of source, it needs to be diff --git a/Makefile.in b/Makefile.in index 180ad3451..e1f06d0c5 100644 --- a/Makefile.in +++ b/Makefile.in @@ -160,7 +160,7 @@ clisp_examples := uffi_examples := cffi_examples := r_examples :=$(shell sed '/^\#/d' $(srcdir)/Examples/r/check.list) -go_examples :=$(shell sed '/^\#/d' $(srcdir)/Examples/go/check.list) +go_examples :=$(shell sed '/^\#/d' $(srcdir)/Examples/go/check.list) # all examples check-%-examples : @@ -170,6 +170,8 @@ check-%-examples : fi @if $(skip-$*); then \ echo skipping $* $(ACTION); \ + elif test -z "$($(strip $*_examples))"; then \ + echo empty $* $(ACTION); \ else \ $(MAKE) -k -s $($*_examples:=.actionexample) LANGUAGE=$* ACTION=$(ACTION); \ fi -- cgit v1.2.1 From 8f8804b7a1b949786c6366494786efb14ea8713a Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Tue, 17 Aug 2010 19:10:14 +0000 Subject: Fix corner case marshalling of doubles - errno was not being correctly set before calling strtod - patch from Justin Vallon git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12190 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- CHANGES.current | 4 ++++ Lib/perl5/perlprimtypes.swg | 1 + 2 files changed, 5 insertions(+) diff --git a/CHANGES.current b/CHANGES.current index d24f6c312..e4022a642 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -5,6 +5,10 @@ See the RELEASENOTES file for a summary of changes in each release. Version 2.0.1 (in progress) =========================== +2010-08-17: wsfulton + [Perl] Fix corner case marshalling of doubles - errno was not being correctly + set before calling strtod - patch from Justin Vallon. + 2010-08-17: wsfulton Fix make distclean when some of the more obscure languages are detected by configure - fixes from Torsten Landschoff. diff --git a/Lib/perl5/perlprimtypes.swg b/Lib/perl5/perlprimtypes.swg index ae7bb3886..f2a614030 100644 --- a/Lib/perl5/perlprimtypes.swg +++ b/Lib/perl5/perlprimtypes.swg @@ -311,6 +311,7 @@ SWIG_AsVal_dec(double)(SV *obj, double *val) const char *nptr = SvPV_nolen(obj); if (nptr) { char *endptr; + errno = 0; double v = strtod(nptr, &endptr); if (errno == ERANGE) { errno = 0; -- cgit v1.2.1 From 69af82caa4c0207cdc150f92cac1f0498ea91928 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Thu, 26 Aug 2010 18:06:02 +0000 Subject: Fix __LINE__ and __FILE__ expansion. Mostly this did not work at all. git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12192 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- CHANGES.current | 6 ++- Examples/test-suite/common.mk | 1 + .../test-suite/java/preproc_line_file_runme.java | 41 ++++++++++++++++++ Examples/test-suite/preproc_line_file.i | 33 +++++++++++++++ Source/Preprocessor/cpp.c | 48 ++++++++++++++++------ 5 files changed, 116 insertions(+), 13 deletions(-) create mode 100644 Examples/test-suite/java/preproc_line_file_runme.java create mode 100644 Examples/test-suite/preproc_line_file.i diff --git a/CHANGES.current b/CHANGES.current index e4022a642..aaaf2254b 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -5,9 +5,13 @@ See the RELEASENOTES file for a summary of changes in each release. Version 2.0.1 (in progress) =========================== +2010-08-26: wsfulton + Fix __LINE__ and __FILE__ expansion reported by Camille Gillot. Mostly this + did not work at all. + 2010-08-17: wsfulton [Perl] Fix corner case marshalling of doubles - errno was not being correctly - set before calling strtod - patch from Justin Vallon. + set before calling strtod - patch from Justin Vallon - SF Bug #3038936. 2010-08-17: wsfulton Fix make distclean when some of the more obscure languages are detected by diff --git a/Examples/test-suite/common.mk b/Examples/test-suite/common.mk index af9316656..e385b11dd 100644 --- a/Examples/test-suite/common.mk +++ b/Examples/test-suite/common.mk @@ -486,6 +486,7 @@ C_TEST_CASES += \ overload_extendc \ preproc \ preproc_constants_c \ + preproc_line_file \ ret_by_value \ simple_array \ sizeof_pointer \ diff --git a/Examples/test-suite/java/preproc_line_file_runme.java b/Examples/test-suite/java/preproc_line_file_runme.java new file mode 100644 index 000000000..6550e4a78 --- /dev/null +++ b/Examples/test-suite/java/preproc_line_file_runme.java @@ -0,0 +1,41 @@ +import preproc_line_file.*; + +public class preproc_line_file_runme { + + static { + try { + System.loadLibrary("preproc_line_file"); + } 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[]) throws Throwable + { + int myline = preproc_line_file.MYLINE; + int myline_adjusted = preproc_line_file.MYLINE_ADJUSTED; + if (myline != 4) + throw new RuntimeException("preproc failure"); + if (myline + 100 + 1 != myline_adjusted) + throw new RuntimeException("preproc failure"); + + String myfile = preproc_line_file.MYFILE; + String myfile_adjusted = preproc_line_file.MYFILE_ADJUSTED; + if (!(myfile.equals("../../../../Examples/test-suite/preproc_line_file.i") || myfile.equals("..\\..\\..\\..\\Examples\\test-suite\\preproc_line_file.i"))) + throw new RuntimeException("preproc failure"); + + if (!(myfile_adjusted.equals("../../../../Examples/test-suite/preproc_line_file.i.bak") || myfile_adjusted.equals("..\\..\\..\\..\\Examples\\test-suite\\preproc_line_file.i.bak"))) + throw new RuntimeException("preproc failure"); + + if (!preproc_line_file.MY_STRINGNUM_A.equals("my15")) + throw new RuntimeException("preproc failed MY_STRINGNUM_A"); + + if (!preproc_line_file.MY_STRINGNUM_B.equals("my16")) + throw new RuntimeException("preproc failed MY_STRINGNUM_B"); + + int myline2 = preproc_line_file.MYLINE2; + if (myline2 != 23) + throw new RuntimeException("preproc failure"); + } +} diff --git a/Examples/test-suite/preproc_line_file.i b/Examples/test-suite/preproc_line_file.i new file mode 100644 index 000000000..11465e0d0 --- /dev/null +++ b/Examples/test-suite/preproc_line_file.i @@ -0,0 +1,33 @@ +%module preproc_line_file +%javaconst(1); +// Test __LINE__ and __FILE__ (don't change line numbers in here else runtime tests will need modifying) +#define MYLINE __LINE__ +#define MYLINE_ADJUSTED __LINE__ + 100 + +#define MYFILE __FILE__ +#define MYFILE_ADJUSTED __FILE__ ".bak" + + +#define STRINGNUM_HELP(a,b) #a#b +#define STRINGNUM(a,b) STRINGNUM_HELP(a,b) +#define STRINGNUM_UNIQUE(a) STRINGNUM(a,__LINE__) + +#define MY_STRINGNUM_A STRINGNUM_UNIQUE(my) +#define MY_STRINGNUM_B STRINGNUM_UNIQUE(my) + + +#define NUMBER_HELP(a,b) a##b +#define NUMBER(a,b) NUMBER_HELP(a,b) +#define NUMBER_UNIQUE(a) NUMBER(a,__LINE__) + +#define MYLINE2 __LINE__ + +/* +TODO: __LINE__ is wrong +struct Struct { + static const int line_num = __LINE__; +}; +const int NUMBER_UNIQUE(thing) = 0; +const int NUMBER_UNIQUE(thingamebob) = 0; +#define MYLINE3 __LINE__ +*/ diff --git a/Source/Preprocessor/cpp.c b/Source/Preprocessor/cpp.c index 5dd320994..63e6ab547 100644 --- a/Source/Preprocessor/cpp.c +++ b/Source/Preprocessor/cpp.c @@ -33,6 +33,9 @@ static Hash *included_files = 0; static List *dependencies = 0; static Scanner *id_scan = 0; static int error_as_warning = 0; /* Understand the cpp #error directive as a special #warning */ +static int macro_level = 0; +static int macro_start_line = 0; +static const String * macro_start_file = 0; /* Test a character to see if it starts an identifier */ #define isidentifier(c) ((isalpha(c)) || (c == '_') || (c == '$')) @@ -40,7 +43,7 @@ static int error_as_warning = 0; /* Understand the cpp #error directive as a spe /* Test a character to see if it valid in an identifier (after the first letter) */ #define isidchar(c) ((isalnum(c)) || (c == '_') || (c == '$')) -DOH *Preprocessor_replace(DOH *); +static DOH *Preprocessor_replace(DOH *); /* Skip whitespace */ static void skip_whitespace(String *s, String *out) { @@ -499,6 +502,10 @@ Hash *Preprocessor_define(const_String_or_char_ptr _str, int swigmacro) { Setattr(macro, kpp_varargs, "1"); } } + Setline(macrovalue, line); + Setfile(macrovalue, file); + Setline(macroname, line); + Setfile(macroname, file); Setattr(macro, kpp_value, macrovalue); Setline(macro, line); Setfile(macro, file); @@ -710,6 +717,14 @@ static String *expand_macro(String *name, List *args) { macro = Getattr(symbols, name); if (!macro) return 0; + + if (macro_level == 0) { + /* Store the start of the macro should the macro contain __LINE__ and __FILE__ for expansion */ + macro_start_line = Getline(args); + macro_start_file = Getfile(args); + } + macro_level++; + if (Getattr(macro, kpp_expanded)) { ns = NewStringEmpty(); Append(ns, name); @@ -725,6 +740,7 @@ static String *expand_macro(String *name, List *args) { if (i) Putc(')', ns); } + macro_level--; return ns; } @@ -764,11 +780,13 @@ static String *expand_macro(String *name, List *args) { Swig_error(Getfile(args), Getline(args), "Macro '%s' expects 1 argument\n", name); else Swig_error(Getfile(args), Getline(args), "Macro '%s' expects no arguments\n", name); + macro_level--; return 0; } /* If the macro expects arguments, but none were supplied, we leave it in place */ if (!args && (margs) && Len(margs) > 0) { + macro_level--; return NewString(name); } @@ -922,6 +940,7 @@ static String *expand_macro(String *name, List *args) { Delete(e); e = f; } + macro_level--; Delete(temp); Delete(tempa); return e; @@ -954,7 +973,7 @@ List *evaluate_args(List *x) { /* #define SWIG_PUT_BUFF */ -DOH *Preprocessor_replace(DOH *s) { +static DOH *Preprocessor_replace(DOH *s) { DOH *ns, *symbols, *m; int c, i, state = 0; @@ -999,7 +1018,7 @@ DOH *Preprocessor_replace(DOH *s) { if (Equal(kpp_defined, id)) { int lenargs = 0; DOH *args = 0; - /* See whether or not a paranthesis has been used */ + /* See whether or not a parenthesis has been used */ skip_whitespace(s, 0); c = Getc(s); if (c == '(') { @@ -1042,22 +1061,19 @@ DOH *Preprocessor_replace(DOH *s) { Delete(args); state = 0; break; - } - if (Equal(kpp_LINE, id)) { - Printf(ns, "%d", Getline(s)); + } else if (Equal(kpp_LINE, id)) { + Printf(ns, "%d", macro_level > 0 ? macro_start_line : Getline(s)); state = 0; break; - } - if (Equal(kpp_FILE, id)) { - String *fn = Copy(Getfile(s)); + } else if (Equal(kpp_FILE, id)) { + String *fn = Copy(macro_level > 0 ? macro_start_file : Getfile(s)); Replaceall(fn, "\\", "\\\\"); Printf(ns, "\"%s\"", fn); Delete(fn); state = 0; break; - } - /* See if the macro is defined in the preprocessor symbol table */ - if ((m = Getattr(symbols, id))) { + } else if ((m = Getattr(symbols, id))) { + /* See if the macro is defined in the preprocessor symbol table */ DOH *args = 0; DOH *e; /* See if the macro expects arguments */ @@ -1123,6 +1139,13 @@ DOH *Preprocessor_replace(DOH *s) { /* See if this is the special "defined" macro */ if (Equal(kpp_defined, id)) { Swig_error(Getfile(s), Getline(s), "No arguments given to defined()\n"); + } else if (Equal(kpp_LINE, id)) { + Printf(ns, "%d", macro_level > 0 ? macro_start_line : Getline(s)); + } else if (Equal(kpp_FILE, id)) { + String *fn = Copy(macro_level > 0 ? macro_start_file : Getfile(s)); + Replaceall(fn, "\\", "\\\\"); + Printf(ns, "\"%s\"", fn); + Delete(fn); } else if ((m = Getattr(symbols, id))) { DOH *e; /* Yes. There is a macro here */ @@ -1457,6 +1480,7 @@ String *Preprocessor_parse(String *s) { m = Preprocessor_define(value, 0); if ((m) && !(Getattr(m, kpp_args))) { v = Copy(Getattr(m, kpp_value)); + copy_location(m, v); if (Len(v)) { Swig_error_silent(1); v1 = Preprocessor_replace(v); -- cgit v1.2.1 From 13d18e4c3f094f7464530d205faae71c2da47a86 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Thu, 26 Aug 2010 18:18:11 +0000 Subject: Fix test for non Java langs git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12193 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Examples/test-suite/preproc_line_file.i | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Examples/test-suite/preproc_line_file.i b/Examples/test-suite/preproc_line_file.i index 11465e0d0..9da137e94 100644 --- a/Examples/test-suite/preproc_line_file.i +++ b/Examples/test-suite/preproc_line_file.i @@ -1,5 +1,5 @@ %module preproc_line_file -%javaconst(1); + // Test __LINE__ and __FILE__ (don't change line numbers in here else runtime tests will need modifying) #define MYLINE __LINE__ #define MYLINE_ADJUSTED __LINE__ + 100 -- cgit v1.2.1 From 5a6443ebcfaf0865b347d24704b3acb06b4f20d9 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Sun, 29 Aug 2010 22:11:03 +0000 Subject: Fix some more instances of __LINE__ and __FILE__ numbering git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12194 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- .../test-suite/java/preproc_line_file_runme.java | 12 ++++++++-- Examples/test-suite/preproc_line_file.i | 27 ++++++++++++++-------- Source/Preprocessor/cpp.c | 12 ++++------ 3 files changed, 33 insertions(+), 18 deletions(-) diff --git a/Examples/test-suite/java/preproc_line_file_runme.java b/Examples/test-suite/java/preproc_line_file_runme.java index 6550e4a78..e390b0c19 100644 --- a/Examples/test-suite/java/preproc_line_file_runme.java +++ b/Examples/test-suite/java/preproc_line_file_runme.java @@ -34,8 +34,16 @@ public class preproc_line_file_runme { if (!preproc_line_file.MY_STRINGNUM_B.equals("my16")) throw new RuntimeException("preproc failed MY_STRINGNUM_B"); - int myline2 = preproc_line_file.MYLINE2; - if (myline2 != 23) + if (preproc_line_file.getThing27() != -1) + throw new RuntimeException("preproc failure"); + + if (preproc_line_file.getThing28() != -2) + throw new RuntimeException("preproc failure"); + + if (preproc_line_file.MYLINE2 != 30) + throw new RuntimeException("preproc failure"); + + if (SillyStruct.LINE_NUMBER != 41) throw new RuntimeException("preproc failure"); } } diff --git a/Examples/test-suite/preproc_line_file.i b/Examples/test-suite/preproc_line_file.i index 9da137e94..1a75be83a 100644 --- a/Examples/test-suite/preproc_line_file.i +++ b/Examples/test-suite/preproc_line_file.i @@ -1,6 +1,6 @@ %module preproc_line_file -// Test __LINE__ and __FILE__ (don't change line numbers in here else runtime tests will need modifying) +// Test __LINE__ and __FILE__ (don't change line numbering in here else runtime tests will need modifying) #define MYLINE __LINE__ #define MYLINE_ADJUSTED __LINE__ + 100 @@ -20,14 +20,23 @@ #define NUMBER(a,b) NUMBER_HELP(a,b) #define NUMBER_UNIQUE(a) NUMBER(a,__LINE__) +%{ +const int thing27 = -1; +const int thing28 = -2; +%} +const int NUMBER_UNIQUE(thing) = -1; /* resolves to thing27 */ +const int NUMBER_UNIQUE(thing) = -2; /* resolves to thing28 */ + #define MYLINE2 __LINE__ -/* -TODO: __LINE__ is wrong -struct Struct { - static const int line_num = __LINE__; +%javaconst(1); +%{ +struct SillyStruct { + int num; + /* static const int line_num = __LINE__; */ +}; +%} +struct SillyStruct { + int num; + static const int LINE_NUMBER = __LINE__; /* This is a C test case, but we can still use a C++ feature to wrap a constant to test __LINE__ here */ }; -const int NUMBER_UNIQUE(thing) = 0; -const int NUMBER_UNIQUE(thingamebob) = 0; -#define MYLINE3 __LINE__ -*/ diff --git a/Source/Preprocessor/cpp.c b/Source/Preprocessor/cpp.c index 63e6ab547..32f3a3bd4 100644 --- a/Source/Preprocessor/cpp.c +++ b/Source/Preprocessor/cpp.c @@ -353,8 +353,6 @@ Hash *Preprocessor_define(const_String_or_char_ptr _str, int swigmacro) { break; } } else { - /*Swig_error(Getfile(str),Getline(str),"Illegal character in macro name\n"); - goto macro_error; */ Ungetc(c, str); break; } @@ -1287,8 +1285,8 @@ String *Preprocessor_parse(String *s) { case 0: /* Initial state - in first column */ /* Look for C preprocessor directives. Otherwise, go directly to state 1 */ if (c == '#') { - add_chunk(ns, chunk, allow); copy_location(s, chunk); + add_chunk(ns, chunk, allow); cpp_lines = 1; state = 40; } else if (isspace(c)) { @@ -1682,8 +1680,8 @@ String *Preprocessor_parse(String *s) { /* %{,%} block */ if (c == '{') { start_line = Getline(s); - add_chunk(ns, chunk, allow); copy_location(s, chunk); + add_chunk(ns, chunk, allow); Putc('%', chunk); Putc(c, chunk); state = 105; @@ -1759,8 +1757,8 @@ String *Preprocessor_parse(String *s) { s1 = cpp_include(fn, sysfile); if (s1) { char *dirname; - add_chunk(ns, chunk, allow); copy_location(s, chunk); + add_chunk(ns, chunk, allow); Printf(ns, "%sfile%s \"%s\" [\n", decl, opt, Swig_filename_escape(Swig_last_file())); if (Equal(decl, kpp_dimport)) { push_imported(); @@ -1793,8 +1791,8 @@ String *Preprocessor_parse(String *s) { } else if (Equal(decl, kpp_ddefine)) { /* Got a define directive */ dlevel++; - add_chunk(ns, chunk, allow); copy_location(s, chunk); + add_chunk(ns, chunk, allow); Clear(value); copy_location(s, value); state = 150; @@ -1868,8 +1866,8 @@ String *Preprocessor_parse(String *s) { if ((state >= 30) && (state < 40)) { Swig_error(Getfile(s), -1, "Unterminated comment starting on line %d\n", start_line); } - add_chunk(ns, chunk, allow); copy_location(s, chunk); + add_chunk(ns, chunk, allow); /* DelScope(scp); */ Delete(decl); -- cgit v1.2.1 From 31b5f36b741f2eaaa44c52d0e21cd6598e8cc73f Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Sun, 29 Aug 2010 23:32:49 +0000 Subject: Fix line number and file name reporting for some macro preprocessor warnings. The line number of the macro argument has been corrected and the line number of the start of the macro instead of one past the end is used. Some examples: file.h:11: Error: Illegal macro argument name '..' file.h:19: Error: Macro 'DUPLICATE' redefined, file.h:15: Error: previous definition of 'DUPLICATE'. file.h:25: Error: Variable-length macro argument must be last parameter file.h:32: Error: Illegal character in macro argument name file.i:37: Error: Macro 'SIT' expects 2 arguments Code used for testing: // file.h %define SIT(ax,b) abc( %enddef %define MISSING_DOT1(a, b, ..) xxx %enddef %define MISSING_DOT2(..) xxx %enddef %define DUPLICATE(a,b) abc %enddef %define DUPLICATE(b) xxx %enddef %define VARARGS_WRONG(a, x, ..., b) xxx %enddef %define BAD_ARGNAME( a, b{c ) xxx %enddef SIT(1) git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12195 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Source/Preprocessor/cpp.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/Source/Preprocessor/cpp.c b/Source/Preprocessor/cpp.c index 32f3a3bd4..38a52dc3f 100644 --- a/Source/Preprocessor/cpp.c +++ b/Source/Preprocessor/cpp.c @@ -337,7 +337,7 @@ Hash *Preprocessor_define(const_String_or_char_ptr _str, int swigmacro) { Putc(c, argstr); } if (c != ')') { - Swig_error(Getfile(str), Getline(str), "Missing \')\' in macro parameters\n"); + Swig_error(Getfile(argstr), Getline(argstr), "Missing \')\' in macro parameters\n"); goto macro_error; } break; @@ -372,10 +372,10 @@ Hash *Preprocessor_define(const_String_or_char_ptr _str, int swigmacro) { argname = NewStringEmpty(); while ((c = Getc(argstr)) != EOF) { if (c == ',') { - varargname = Macro_vararg_name(argname, str); + varargname = Macro_vararg_name(argname, argstr); if (varargname) { Delete(varargname); - Swig_error(Getfile(str), Getline(str), "Variable-length macro argument must be last parameter\n"); + Swig_error(Getfile(argstr), Getline(argstr), "Variable length macro argument must be last parameter\n"); } else { Append(arglist, argname); } @@ -385,13 +385,13 @@ Hash *Preprocessor_define(const_String_or_char_ptr _str, int swigmacro) { Putc(c, argname); } else if (!(isspace(c) || (c == '\\'))) { Delete(argname); - Swig_error(Getfile(str), Getline(str), "Illegal character in macro argument name\n"); + Swig_error(Getfile(argstr), Getline(argstr), "Illegal character in macro argument name\n"); goto macro_error; } } if (Len(argname)) { /* Check for varargs */ - varargname = Macro_vararg_name(argname, str); + varargname = Macro_vararg_name(argname, argstr); if (varargname) { Append(arglist, varargname); Delete(varargname); @@ -513,7 +513,7 @@ Hash *Preprocessor_define(const_String_or_char_ptr _str, int swigmacro) { symbols = Getattr(cpp, kpp_symbols); if ((m1 = Getattr(symbols, macroname))) { if (!Checkattr(m1, kpp_value, macrovalue)) { - Swig_error(Getfile(str), Getline(str), "Macro '%s' redefined,\n", macroname); + Swig_error(Getfile(macroname), Getline(macroname), "Macro '%s' redefined,\n", macroname); Swig_error(Getfile(m1), Getline(m1), "previous definition of '%s'.\n", macroname); goto macro_error; } -- cgit v1.2.1 From 41bc29c9f0b09247e34d9a3f6314975f0bd8d7e5 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Tue, 31 Aug 2010 06:02:10 +0000 Subject: Add missing changes documentation for rev 12195 git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12196 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- CHANGES.current | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/CHANGES.current b/CHANGES.current index aaaf2254b..90391fbfb 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -5,9 +5,20 @@ See the RELEASENOTES file for a summary of changes in each release. Version 2.0.1 (in progress) =========================== +2010-08-30: wsfulton + Fix line number and file name reporting for some macro preprocessor warnings. + The line number of the macro argument has been corrected and the line number + of the start of the macro instead of one past the end is used. Some examples: + file.h:11: Error: Illegal macro argument name '..' + file.h:19: Error: Macro 'DUPLICATE' redefined, + file.h:15: Error: previous definition of 'DUPLICATE'. + file.h:25: Error: Variable-length macro argument must be last parameter + file.h:32: Error: Illegal character in macro argument name + file.i:37: Error: Macro 'SIT' expects 2 arguments + 2010-08-26: wsfulton Fix __LINE__ and __FILE__ expansion reported by Camille Gillot. Mostly this - did not work at all. + did not work at all. Also fixes SF #2822822. 2010-08-17: wsfulton [Perl] Fix corner case marshalling of doubles - errno was not being correctly -- cgit v1.2.1 From aa728ece671c7e135d6d6dc7ab299dc6bfc78308 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Wed, 1 Sep 2010 21:06:10 +0000 Subject: Fix __LINE__ and __FILE__ expansion in macros with no arguments git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12197 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Examples/test-suite/java/preproc_line_file_runme.java | 3 +++ Examples/test-suite/preproc_line_file.i | 10 ++++++++++ Source/Preprocessor/cpp.c | 16 ++++++++++------ 3 files changed, 23 insertions(+), 6 deletions(-) diff --git a/Examples/test-suite/java/preproc_line_file_runme.java b/Examples/test-suite/java/preproc_line_file_runme.java index e390b0c19..7200e4a53 100644 --- a/Examples/test-suite/java/preproc_line_file_runme.java +++ b/Examples/test-suite/java/preproc_line_file_runme.java @@ -45,5 +45,8 @@ public class preproc_line_file_runme { if (SillyStruct.LINE_NUMBER != 41) throw new RuntimeException("preproc failure"); + + if (SillyMacroClass.LINE_NUM != 45) + throw new RuntimeException("preproc failure"); } } diff --git a/Examples/test-suite/preproc_line_file.i b/Examples/test-suite/preproc_line_file.i index 1a75be83a..2ef43b017 100644 --- a/Examples/test-suite/preproc_line_file.i +++ b/Examples/test-suite/preproc_line_file.i @@ -40,3 +40,13 @@ struct SillyStruct { int num; static const int LINE_NUMBER = __LINE__; /* This is a C test case, but we can still use a C++ feature to wrap a constant to test __LINE__ here */ }; + +#define SILLY_CLASS struct SillyMacroClass { int num; static const int LINE_NUM = __LINE__; }; +SILLY_CLASS + +%{ +#define SILLY_CLASS struct SillyMacroClass { int num; }; +SILLY_CLASS +%} + + diff --git a/Source/Preprocessor/cpp.c b/Source/Preprocessor/cpp.c index 38a52dc3f..f044e344c 100644 --- a/Source/Preprocessor/cpp.c +++ b/Source/Preprocessor/cpp.c @@ -699,9 +699,12 @@ static String *get_options(String *str) { * * Perform macro expansion and return a new string. Returns NULL if some sort * of error occurred. + * name - name of the macro + * args - arguments passed to the macro + * line_file - only used for line/file name when reporting errors * ----------------------------------------------------------------------------- */ -static String *expand_macro(String *name, List *args) { +static String *expand_macro(String *name, List *args, String *line_file) { String *ns; DOH *symbols, *macro, *margs, *mvalue, *temp, *tempa, *e; int i, l; @@ -718,8 +721,8 @@ static String *expand_macro(String *name, List *args) { if (macro_level == 0) { /* Store the start of the macro should the macro contain __LINE__ and __FILE__ for expansion */ - macro_start_line = Getline(args); - macro_start_file = Getfile(args); + macro_start_line = Getline(args ? args : line_file); + macro_start_file = Getfile(args ? args : line_file); } macro_level++; @@ -1085,7 +1088,7 @@ static DOH *Preprocessor_replace(DOH *s) { } else { args = 0; } - e = expand_macro(id, args); + e = expand_macro(id, args, s); if (e) { Append(ns, e); } @@ -1151,8 +1154,9 @@ static DOH *Preprocessor_replace(DOH *s) { /* if (Getattr(m,"args")) { Swig_error(Getfile(id),Getline(id),"Macro arguments expected.\n"); } */ - e = expand_macro(id, 0); - Append(ns, e); + e = expand_macro(id, 0, s); + if (e) + Append(ns, e); Delete(e); } else { Append(ns, id); -- cgit v1.2.1 From 1e6ed0843fdc303abffab1e117b062e6c26de4fa Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Wed, 1 Sep 2010 21:11:09 +0000 Subject: minor clarification in test comment git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12198 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Examples/test-suite/varargs.i | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Examples/test-suite/varargs.i b/Examples/test-suite/varargs.i index 41e4903f0..c7931fed2 100644 --- a/Examples/test-suite/varargs.i +++ b/Examples/test-suite/varargs.i @@ -1,4 +1,5 @@ -// Tests SWIG's *default* handling of varargs. The default behavior is to simply ignore the varargs. +// Tests SWIG's *default* handling of varargs (function varargs, not preprocessor varargs). +// The default behavior is to simply ignore the varargs. %module varargs %varargs(int mode = 0) test_def; -- cgit v1.2.1 From a44f83cf0538c48c47ebae71545269fa0fa04a64 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Fri, 3 Sep 2010 06:03:48 +0000 Subject: Fix line numbers in error and warning messages which were accumulately one less than they should have been after parsing each %include/%import - bug introduced in swig-1.3.32. Also fix line numbers in error and warning messages when new line characters appear between the %include / %import statement and the filename. git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12199 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- CHANGES.current | 12 ++++++++++-- Source/CParse/parser.y | 2 +- Source/Preprocessor/cpp.c | 13 ++++++++----- 3 files changed, 19 insertions(+), 8 deletions(-) diff --git a/CHANGES.current b/CHANGES.current index 90391fbfb..7213a66c0 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -5,10 +5,18 @@ See the RELEASENOTES file for a summary of changes in each release. Version 2.0.1 (in progress) =========================== +2010-09-02: wsfulton + Fix line numbers in error and warning messages which were accumulately one + less than they should have been after parsing each %include/%import - bug + introduced in swig-1.3.32. Also fix line numbers in error and warning messages + when new line characters appear between the %include / %import statement and + the filename. + 2010-08-30: wsfulton Fix line number and file name reporting for some macro preprocessor warnings. The line number of the macro argument has been corrected and the line number - of the start of the macro instead of one past the end is used. Some examples: + of the start of the macro instead of one past the end of the macro is used. + Some examples: file.h:11: Error: Illegal macro argument name '..' file.h:19: Error: Macro 'DUPLICATE' redefined, file.h:15: Error: previous definition of 'DUPLICATE'. @@ -50,7 +58,7 @@ Version 2.0.1 (in progress) adjust your regular expressions syntax as the new regex encoder uses Perl-compatible syntax and not (extended) POSIX syntax as the old one. - *** POTENTIAL INCOMPATIBILITY *** + *** POTENTIAL INCOMPATIBILITY *** 2010-07-13: vadz Add "regexmatch", "regextarget" and "notregexmatch" which can be diff --git a/Source/CParse/parser.y b/Source/CParse/parser.y index 6e41fa565..f0df6684d 100644 --- a/Source/CParse/parser.y +++ b/Source/CParse/parser.y @@ -2121,7 +2121,7 @@ include_directive: includetype options string LBRACKET { } interface RBRACKET { String *mname = 0; $$ = $6; - scanner_set_location($1.filename,$1.line); + scanner_set_location($1.filename,$1.line+1); if (strcmp($1.type,"include") == 0) set_nodeType($$,"include"); if (strcmp($1.type,"import") == 0) { mname = $2 ? Getattr($2,"module") : 0; diff --git a/Source/Preprocessor/cpp.c b/Source/Preprocessor/cpp.c index f044e344c..83ccdfca9 100644 --- a/Source/Preprocessor/cpp.c +++ b/Source/Preprocessor/cpp.c @@ -642,7 +642,6 @@ static String *get_filename(String *str, int *sysfile) { String *fn; int c; - skip_whitespace(str, 0); fn = NewStringEmpty(); copy_location(str, fn); c = Getc(str); @@ -668,9 +667,7 @@ static String *get_filename(String *str, int *sysfile) { } static String *get_options(String *str) { - int c; - skip_whitespace(str, 0); c = Getc(str); if (c == '(') { String *opt; @@ -1648,8 +1645,8 @@ String *Preprocessor_parse(String *s) { pop_imported(); } Delete(s2); + Delete(s1); } - Delete(s1); Delete(fn); } } else if (Equal(id, kpp_pragma)) { @@ -1749,6 +1746,8 @@ String *Preprocessor_parse(String *s) { /* Got some kind of file inclusion directive */ if (allow) { DOH *s1, *s2, *fn, *opt; + String *options_whitespace = NewString(""); + String *filename_whitespace = NewString(""); int sysfile = 0; if (Equal(decl, kpp_dextern)) { @@ -1756,14 +1755,16 @@ String *Preprocessor_parse(String *s) { Clear(decl); Append(decl, "%%import"); } + skip_whitespace(s, options_whitespace); opt = get_options(s); + skip_whitespace(s, filename_whitespace); fn = get_filename(s, &sysfile); s1 = cpp_include(fn, sysfile); if (s1) { char *dirname; copy_location(s, chunk); add_chunk(ns, chunk, allow); - Printf(ns, "%sfile%s \"%s\" [\n", decl, opt, Swig_filename_escape(Swig_last_file())); + Printf(ns, "%sfile%s%s%s\"%s\" [\n", decl, options_whitespace, opt, filename_whitespace, Swig_filename_escape(Swig_last_file())); if (Equal(decl, kpp_dimport)) { push_imported(); } @@ -1787,6 +1788,8 @@ String *Preprocessor_parse(String *s) { Delete(s1); } Delete(fn); + Delete(filename_whitespace); + Delete(options_whitespace); } state = 1; } else if (Equal(decl, kpp_dline)) { -- cgit v1.2.1 From 45601f24b4209b1f00b6897a01afc3ecfcf07b40 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Fri, 3 Sep 2010 17:47:12 +0000 Subject: Fix line numbers in error and warning messages for preprocessor messages within %inline. Also fixes __LINE__ within %inline git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12200 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- CHANGES.current | 9 ++++++++ .../test-suite/java/preproc_line_file_runme.java | 16 +++++++++++-- Examples/test-suite/preproc_line_file.i | 26 ++++++++++++++++++++++ Source/CParse/parser.y | 3 +-- 4 files changed, 50 insertions(+), 4 deletions(-) diff --git a/CHANGES.current b/CHANGES.current index 7213a66c0..6d5cc9327 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -5,6 +5,15 @@ See the RELEASENOTES file for a summary of changes in each release. Version 2.0.1 (in progress) =========================== +2010-09-02: wsfulton + Fix line numbers in error and warning messages for preprocessor messages within + %inline, for example: + + %inline %{ + #define FOOBAR 1 + #define FOOBAR "hi" + %} + 2010-09-02: wsfulton Fix line numbers in error and warning messages which were accumulately one less than they should have been after parsing each %include/%import - bug diff --git a/Examples/test-suite/java/preproc_line_file_runme.java b/Examples/test-suite/java/preproc_line_file_runme.java index 7200e4a53..8119824e9 100644 --- a/Examples/test-suite/java/preproc_line_file_runme.java +++ b/Examples/test-suite/java/preproc_line_file_runme.java @@ -11,6 +11,8 @@ public class preproc_line_file_runme { } } + public static String FILENAME_WINDOWS = "..\\..\\..\\..\\Examples\\test-suite\\preproc_line_file.i"; + public static String FILENAME_UNIX = "../../../../Examples/test-suite/preproc_line_file.i"; public static void main(String argv[]) throws Throwable { int myline = preproc_line_file.MYLINE; @@ -22,10 +24,10 @@ public class preproc_line_file_runme { String myfile = preproc_line_file.MYFILE; String myfile_adjusted = preproc_line_file.MYFILE_ADJUSTED; - if (!(myfile.equals("../../../../Examples/test-suite/preproc_line_file.i") || myfile.equals("..\\..\\..\\..\\Examples\\test-suite\\preproc_line_file.i"))) + if (!(myfile.equals(FILENAME_UNIX) || myfile.equals(FILENAME_WINDOWS))) throw new RuntimeException("preproc failure"); - if (!(myfile_adjusted.equals("../../../../Examples/test-suite/preproc_line_file.i.bak") || myfile_adjusted.equals("..\\..\\..\\..\\Examples\\test-suite\\preproc_line_file.i.bak"))) + if (!(myfile_adjusted.equals(FILENAME_UNIX + ".bak") || myfile_adjusted.equals(FILENAME_WINDOWS + ".bak"))) throw new RuntimeException("preproc failure"); if (!preproc_line_file.MY_STRINGNUM_A.equals("my15")) @@ -48,5 +50,15 @@ public class preproc_line_file_runme { if (SillyMacroClass.LINE_NUM != 45) throw new RuntimeException("preproc failure"); + + if (SillyMultipleMacroStruct.LINE_NUM != 70) + throw new RuntimeException("preproc failure"); + + if (preproc_line_file.INLINE_LINE != 76) + throw new RuntimeException("preproc failure"); + + String inlineFile = preproc_line_file.INLINE_FILE; + if (!(inlineFile.equals(FILENAME_UNIX) || inlineFile.equals(FILENAME_WINDOWS))) + throw new RuntimeException("preproc failure"); } } diff --git a/Examples/test-suite/preproc_line_file.i b/Examples/test-suite/preproc_line_file.i index 2ef43b017..5b75d0a20 100644 --- a/Examples/test-suite/preproc_line_file.i +++ b/Examples/test-suite/preproc_line_file.i @@ -50,3 +50,29 @@ SILLY_CLASS %} +%inline %{ +#ifdef SWIG +%define BODY + int num; + static const int LINE_NUM = __LINE__; +%enddef +%define KLASS(NAME) +struct NAME { + BODY +}; +%enddef +#else +#define KLASS(NAME) \ +struct NAME { \ + int num; \ +}; +#endif +KLASS(SillyMultipleMacroStruct) +%} + +%inline %{ + +#define INLINE_FILE __FILE__ +#define INLINE_LINE __LINE__ +%} + diff --git a/Source/CParse/parser.y b/Source/CParse/parser.y index f0df6684d..09ed9bcf2 100644 --- a/Source/CParse/parser.y +++ b/Source/CParse/parser.y @@ -2176,15 +2176,14 @@ inline_directive : INLINE HBLOCK { String *cpps; if (Namespaceprefix) { Swig_error(cparse_file, cparse_start_line, "%%inline directive inside a namespace is disallowed.\n"); - $$ = 0; } else { $$ = new_node("insert"); Setattr($$,"code",$2); /* Need to run through the preprocessor */ + Seek($2,0,SEEK_SET); Setline($2,cparse_start_line); Setfile($2,cparse_file); - Seek($2,0,SEEK_SET); cpps = Preprocessor_parse($2); start_inline(Char(cpps), cparse_start_line); Delete($2); -- cgit v1.2.1 From 197c8e899d8d3bf16bf696728cfe8edcd7829a8f Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Fri, 3 Sep 2010 18:44:01 +0000 Subject: Fix erroneous line numbers in argument count error messages for macro expansions git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12201 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- CHANGES.current | 10 ++++++++++ Source/Preprocessor/cpp.c | 6 +++--- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/CHANGES.current b/CHANGES.current index 6d5cc9327..c09ff3409 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -5,6 +5,16 @@ See the RELEASENOTES file for a summary of changes in each release. Version 2.0.1 (in progress) =========================== +2010-09-03: wsfulton + Fix erroneous line numbers in error messages for macro expansions, for example, + the error message now points to instantation of the macro, ie the last line here: + + #define MACRO2(a, b) + + #define MACRO1(NAME) MACRO2(NAME,2,3) + + MACRO1(abc) + 2010-09-02: wsfulton Fix line numbers in error and warning messages for preprocessor messages within %inline, for example: diff --git a/Source/Preprocessor/cpp.c b/Source/Preprocessor/cpp.c index 83ccdfca9..16a9ce1d3 100644 --- a/Source/Preprocessor/cpp.c +++ b/Source/Preprocessor/cpp.c @@ -773,11 +773,11 @@ static String *expand_macro(String *name, List *args, String *line_file) { /* If there are arguments, see if they match what we were given */ if (args && (margs) && (Len(margs) != Len(args))) { if (Len(margs) > (1 + isvarargs)) - Swig_error(Getfile(args), Getline(args), "Macro '%s' expects %d arguments\n", name, Len(margs) - isvarargs); + Swig_error(macro_start_file, macro_start_line, "Macro '%s' expects %d arguments\n", name, Len(margs) - isvarargs); else if (Len(margs) == (1 + isvarargs)) - Swig_error(Getfile(args), Getline(args), "Macro '%s' expects 1 argument\n", name); + Swig_error(macro_start_file, macro_start_line, "Macro '%s' expects 1 argument\n", name); else - Swig_error(Getfile(args), Getline(args), "Macro '%s' expects no arguments\n", name); + Swig_error(macro_start_file, macro_start_line, "Macro '%s' expects no arguments\n", name); macro_level--; return 0; } -- cgit v1.2.1 From 04c3e6b7d33663b8976251a6a6a48421c7227d19 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Mon, 6 Sep 2010 17:30:18 +0000 Subject: Fix line numbering for 'Unterminated call invoking macro' error git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12202 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- .../test-suite/errors/pp_macro_defined_unterminated.i | 6 ++++++ Source/Preprocessor/cpp.c | 17 +++++++++-------- 2 files changed, 15 insertions(+), 8 deletions(-) create mode 100644 Examples/test-suite/errors/pp_macro_defined_unterminated.i diff --git a/Examples/test-suite/errors/pp_macro_defined_unterminated.i b/Examples/test-suite/errors/pp_macro_defined_unterminated.i new file mode 100644 index 000000000..bc44d07c6 --- /dev/null +++ b/Examples/test-suite/errors/pp_macro_defined_unterminated.i @@ -0,0 +1,6 @@ +%module xxx + + +#if defined(a +#endif + diff --git a/Source/Preprocessor/cpp.c b/Source/Preprocessor/cpp.c index 16a9ce1d3..b4866ee9c 100644 --- a/Source/Preprocessor/cpp.c +++ b/Source/Preprocessor/cpp.c @@ -325,6 +325,7 @@ Hash *Preprocessor_define(const_String_or_char_ptr _str, int swigmacro) { /* Now look for a macro name */ macroname = NewStringEmpty(); + copy_location(str, macroname); while ((c = Getc(str)) != EOF) { if (c == '(') { argstr = NewStringEmpty(); @@ -360,6 +361,7 @@ Hash *Preprocessor_define(const_String_or_char_ptr _str, int swigmacro) { if (!swigmacro) skip_whitespace(str, 0); macrovalue = NewStringEmpty(); + copy_location(str, macrovalue); while ((c = Getc(str)) != EOF) { Putc(c, macrovalue); } @@ -500,10 +502,6 @@ Hash *Preprocessor_define(const_String_or_char_ptr _str, int swigmacro) { Setattr(macro, kpp_varargs, "1"); } } - Setline(macrovalue, line); - Setfile(macrovalue, file); - Setline(macroname, line); - Setfile(macroname, file); Setattr(macro, kpp_value, macrovalue); Setline(macro, line); Setfile(macro, file); @@ -556,7 +554,7 @@ void Preprocessor_undef(const_String_or_char_ptr str) { * Isolates macro arguments and returns them in a list. For each argument, * leading and trailing whitespace is stripped (ala K&R, pg. 230). * ----------------------------------------------------------------------------- */ -static List *find_args(String *s) { +static List *find_args(String *s, int ismacro, String *macro_name) { List *args; String *str; int c, level; @@ -627,7 +625,10 @@ static List *find_args(String *s) { c = Getc(s); } unterm: - Swig_error(Getfile(args), Getline(args), "Unterminated macro call.\n"); + if (ismacro) + Swig_error(Getfile(args), Getline(args), "Unterminated call invoking macro '%s'\n", macro_name); + else + Swig_error(Getfile(args), Getline(args), "Unterminated call to '%s'\n", macro_name); return args; } @@ -1021,7 +1022,7 @@ static DOH *Preprocessor_replace(DOH *s) { c = Getc(s); if (c == '(') { Ungetc(c, s); - args = find_args(s); + args = find_args(s, 0, kpp_defined); } else if (isidchar(c)) { DOH *arg = NewStringEmpty(); args = NewList(); @@ -1077,7 +1078,7 @@ static DOH *Preprocessor_replace(DOH *s) { /* See if the macro expects arguments */ if (Getattr(m, kpp_args)) { /* Yep. We need to go find the arguments and do a substitution */ - args = find_args(s); + args = find_args(s, 1, id); if (!Len(args)) { Delete(args); args = 0; -- cgit v1.2.1 From b0609c3be210925c543633ec558cde312e3d2fc4 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Mon, 6 Sep 2010 18:10:43 +0000 Subject: Add some more preprocessor tests git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12203 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Examples/test-suite/errors/make.sh | 7 ++++++- Examples/test-suite/errors/pp_deprecated.i | 9 +++++++++ Examples/test-suite/errors/pp_illegal_argument.i | 20 ++++++++++++++++++++ Examples/test-suite/errors/pp_pragma.i | 6 ++++++ Examples/test-suite/errors/pp_variable_args.i | 10 ++++++++++ 5 files changed, 51 insertions(+), 1 deletion(-) create mode 100644 Examples/test-suite/errors/pp_deprecated.i create mode 100644 Examples/test-suite/errors/pp_illegal_argument.i create mode 100644 Examples/test-suite/errors/pp_pragma.i create mode 100644 Examples/test-suite/errors/pp_variable_args.i diff --git a/Examples/test-suite/errors/make.sh b/Examples/test-suite/errors/make.sh index ae38ca879..e50fd22dc 100755 --- a/Examples/test-suite/errors/make.sh +++ b/Examples/test-suite/errors/make.sh @@ -24,9 +24,12 @@ c_missing_semi c_redefine c_varargs c_varargs_neg -nomodule +nomodule pp_badeval +pp_deprecated pp_defined +pp_macro_defined_unterminated +pp_illegal_argument pp_macro_args pp_macro_badchar pp_macro_nargs @@ -39,9 +42,11 @@ pp_missing_enddef pp_missing_endif pp_missing_file pp_missing_rblock +pp_pragma pp_unterm_char pp_unterm_comment pp_unterm_string +pp_variable_args swig_apply_nargs swig_identifier swig_insert_bad diff --git a/Examples/test-suite/errors/pp_deprecated.i b/Examples/test-suite/errors/pp_deprecated.i new file mode 100644 index 000000000..68f81317b --- /dev/null +++ b/Examples/test-suite/errors/pp_deprecated.i @@ -0,0 +1,9 @@ +%module xxx + + +%extern ext; + +#warning Print this warning + +#error This is an error + diff --git a/Examples/test-suite/errors/pp_illegal_argument.i b/Examples/test-suite/errors/pp_illegal_argument.i new file mode 100644 index 000000000..13ffa4559 --- /dev/null +++ b/Examples/test-suite/errors/pp_illegal_argument.i @@ -0,0 +1,20 @@ +%module xxx + + +%define MISSING_DOT1(a, +b, +..) +xxx +%enddef + +%define MISSING_DOT2(..) +xxx +%enddef + +%define BAD_ARGNAME( +a, +b{c +) +xxx +%enddef + diff --git a/Examples/test-suite/errors/pp_pragma.i b/Examples/test-suite/errors/pp_pragma.i new file mode 100644 index 000000000..8d928690c --- /dev/null +++ b/Examples/test-suite/errors/pp_pragma.i @@ -0,0 +1,6 @@ +%module xxx + + +#pragma SWIG rubbish() + + diff --git a/Examples/test-suite/errors/pp_variable_args.i b/Examples/test-suite/errors/pp_variable_args.i new file mode 100644 index 000000000..c5f72fff9 --- /dev/null +++ b/Examples/test-suite/errors/pp_variable_args.i @@ -0,0 +1,10 @@ +%module xxx + + +%define VARARGS_WRONG(a, +x, +..., + b) +xxx +%enddef + -- cgit v1.2.1 From 46bd4a26c673babd36a551191c596cac300d8992 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Mon, 6 Sep 2010 18:12:13 +0000 Subject: Add expected error/warning messages log git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12204 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Examples/test-suite/errors/expected.log | 241 ++++++++++++++++++++++++++++++++ 1 file changed, 241 insertions(+) create mode 100644 Examples/test-suite/errors/expected.log diff --git a/Examples/test-suite/errors/expected.log b/Examples/test-suite/errors/expected.log new file mode 100644 index 000000000..ff56d9b2b --- /dev/null +++ b/Examples/test-suite/errors/expected.log @@ -0,0 +1,241 @@ +SWIG error and warning test. opts= +----------------------------------------------------------- + +:::::::::::::::::::::::::::::::: c_bad_name.i ::::::::::::::::::::::::::::::::::: +c_bad_name.i:3: Warning 121: %name is deprecated. Use %rename instead. +c_bad_name.i:3: Error: Missing argument to %name directive. + +:::::::::::::::::::::::::::::::: c_bad_native.i ::::::::::::::::::::::::::::::::::: +c_bad_native.i:3: Error: %native declaration 'foo' is not a function. + +:::::::::::::::::::::::::::::::: c_class.i ::::::::::::::::::::::::::::::::::: +c_class.i:3: Warning 301: class keyword used, but not in C++ mode. + +:::::::::::::::::::::::::::::::: c_default_error.i ::::::::::::::::::::::::::::::::::: + +:::::::::::::::::::::::::::::::: c_deprecated.i ::::::::::::::::::::::::::::::::::: +c_deprecated.i:3: Warning 102: %val directive deprecated (ignored). +c_deprecated.i:3: Warning 103: %out directive deprecated (ignored). + +:::::::::::::::::::::::::::::::: c_empty_char.i ::::::::::::::::::::::::::::::::::: +c_empty_char.i:3: Error: Empty character constant +0 + +:::::::::::::::::::::::::::::::: c_enum_badvalue.i ::::::::::::::::::::::::::::::::::: +c_enum_badvalue.i:6: Error: Type error. Expecting an integral type + +:::::::::::::::::::::::::::::::: c_extra_rblock.i ::::::::::::::::::::::::::::::::::: +c_extra_rblock.i:5: Error: Syntax error in input(1). + +:::::::::::::::::::::::::::::::: c_extra_rbrace.i ::::::::::::::::::::::::::::::::::: +c_extra_rbrace.i:5: Error: Syntax error. Extraneous '}' + +:::::::::::::::::::::::::::::::: c_extra_unsigned.i ::::::::::::::::::::::::::::::::::: +c_extra_unsigned.i:3: Error: Extra unsigned specifier. +c_extra_unsigned.i:4: Error: Extra signed specifier. +c_extra_unsigned.i:5: Error: Extra signed specifier. + +:::::::::::::::::::::::::::::::: c_insert_missing.i ::::::::::::::::::::::::::::::::::: +c_insert_missing.i:3: Error: Couldn't find 'missing_file.i'. + +:::::::::::::::::::::::::::::::: c_long_short.i ::::::::::::::::::::::::::::::::::: +c_long_short.i:3: Error: Extra long specifier. +c_long_short.i:4: Error: Extra short specifier. +c_long_short.i:5: Error: Extra long specifier. +c_long_short.i:6: Error: Extra short specifier. + +:::::::::::::::::::::::::::::::: c_missing_rbrace.i ::::::::::::::::::::::::::::::::::: +:168430090: Error: Missing '}'. Reached end of input. +c_missing_rbrace.i:3: Error: Syntax error in input(1). + +:::::::::::::::::::::::::::::::: c_missing_semi.i ::::::::::::::::::::::::::::::::::: +c_missing_semi.i:3: Error: Syntax error in input(1). + +:::::::::::::::::::::::::::::::: c_redefine.i ::::::::::::::::::::::::::::::::::: +c_redefine.i:4: Warning 302: Identifier 'foo' redefined (ignored), +c_redefine.i:3: Warning 302: previous definition of 'foo'. +c_redefine.i:8: Warning 302: Identifier 'bar' redefined (ignored), +c_redefine.i:6: Warning 302: previous definition of 'bar'. +c_redefine.i:14: Warning 322: Redundant redeclaration of 'bar' (Renamed from 'spam'), +c_redefine.i:6: Warning 322: previous declaration of 'bar'. + +:::::::::::::::::::::::::::::::: c_varargs.i ::::::::::::::::::::::::::::::::::: + +:::::::::::::::::::::::::::::::: c_varargs_neg.i ::::::::::::::::::::::::::::::::::: +c_varargs_neg.i:3: Error: Argument count in %varargs must be positive. + +:::::::::::::::::::::::::::::::: nomodule.i ::::::::::::::::::::::::::::::::::: +No module name specified using %module or -module. + +:::::::::::::::::::::::::::::::: pp_badeval.i ::::::::::::::::::::::::::::::::::: +pp_badeval.i:4: Warning 202: Could not evaluate 'FOO==4+' +pp_badeval.i:4: Warning 202: Error: 'Expected an expression' + +:::::::::::::::::::::::::::::::: pp_deprecated.i ::::::::::::::::::::::::::::::::::: +pp_deprecated.i:4: Warning 101: %extern is deprecated. Use %import instead. +pp_deprecated.i:4: Error: Unable to find 'ext;' +pp_deprecated.i:6: Warning 204: CPP #warning, Print this warning +pp_deprecated.i:8: Error: CPP #error "This is an error". Use the -cpperraswarn option to continue swig processing. + +:::::::::::::::::::::::::::::::: pp_defined.i ::::::::::::::::::::::::::::::::::: +pp_defined.i:6: Error: No arguments given to defined() +pp_defined.i:6: Warning 202: Could not evaluate 'defined' +pp_defined.i:6: Warning 202: Error: 'Expected an expression' + +:::::::::::::::::::::::::::::::: pp_macro_defined_unterminated.i ::::::::::::::::::::::::::::::::::: +pp_macro_defined_unterminated.i:4: Error: Unterminated call to 'defined' + +:::::::::::::::::::::::::::::::: pp_illegal_argument.i ::::::::::::::::::::::::::::::::::: +pp_illegal_argument.i:6: Error: Illegal macro argument name '..' +pp_illegal_argument.i:10: Error: Illegal macro argument name '..' +pp_illegal_argument.i:16: Error: Illegal character in macro argument name + +:::::::::::::::::::::::::::::::: pp_macro_args.i ::::::::::::::::::::::::::::::::::: + +:::::::::::::::::::::::::::::::: pp_macro_badchar.i ::::::::::::::::::::::::::::::::::: +pp_macro_badchar.i:4: Error: Illegal character in macro argument name + +:::::::::::::::::::::::::::::::: pp_macro_nargs.i ::::::::::::::::::::::::::::::::::: +pp_macro_nargs.i:7: Error: Macro 'foo' expects 2 arguments +pp_macro_nargs.i:8: Error: Macro 'foo' expects 2 arguments +pp_macro_nargs.i:10: Error: Macro 'bar' expects 1 argument +pp_macro_nargs.i:11: Error: Macro 'spam' expects no arguments + +:::::::::::::::::::::::::::::::: pp_macro_redef.i ::::::::::::::::::::::::::::::::::: +pp_macro_redef.i:4: Error: Macro 'foo' redefined, +pp_macro_redef.i:3: Error: previous definition of 'foo'. +pp_macro_redef.i:7: Error: Macro 'foo' redefined, +pp_macro_redef.i:3: Error: previous definition of 'foo'. + +:::::::::::::::::::::::::::::::: pp_macro_rparen.i ::::::::::::::::::::::::::::::::::: +pp_macro_rparen.i:3: Error: Missing ')' in macro parameters + +:::::::::::::::::::::::::::::::: pp_macro_unterminated.i ::::::::::::::::::::::::::::::::::: +pp_macro_unterminated.i:5: Error: Unterminated call invoking macro 'foo' + +:::::::::::::::::::::::::::::::: pp_misplaced_elif.i ::::::::::::::::::::::::::::::::::: +pp_misplaced_elif.i:4: Error: Misplaced #elif. +pp_misplaced_elif.i:6: Error: Extraneous #endif. + +:::::::::::::::::::::::::::::::: pp_misplaced_else.i ::::::::::::::::::::::::::::::::::: +pp_misplaced_else.i:4: Error: Misplaced #else. +pp_misplaced_else.i:6: Error: Extraneous #endif. + +:::::::::::::::::::::::::::::::: pp_missing_enddef.i ::::::::::::::::::::::::::::::::::: +pp_missing_enddef.i:EOF: Error: Missing %enddef for macro starting on line 3 + +:::::::::::::::::::::::::::::::: pp_missing_endif.i ::::::::::::::::::::::::::::::::::: +pp_missing_endif.i:EOF: Error: Missing #endif for conditional starting on line 3 + +:::::::::::::::::::::::::::::::: pp_missing_file.i ::::::::::::::::::::::::::::::::::: +pp_missing_file.i:3: Error: Unable to find 'missing_filename.i' + +:::::::::::::::::::::::::::::::: pp_missing_rblock.i ::::::::::::::::::::::::::::::::::: +pp_missing_rblock.i:EOF: Error: Unterminated %{ ... %} block starting on line 3 + +:::::::::::::::::::::::::::::::: pp_pragma.i ::::::::::::::::::::::::::::::::::: +pp_pragma.i:4: Error: Unknown SWIG pragma: rubbish() + +:::::::::::::::::::::::::::::::: pp_unterm_char.i ::::::::::::::::::::::::::::::::::: +pp_unterm_char.i:EOF: Error: Unterminated character constant starting at line 4 + +:::::::::::::::::::::::::::::::: pp_unterm_comment.i ::::::::::::::::::::::::::::::::::: +pp_unterm_comment.i:EOF: Error: Unterminated comment starting on line 3 + +:::::::::::::::::::::::::::::::: pp_unterm_string.i ::::::::::::::::::::::::::::::::::: +pp_unterm_string.i:EOF: Error: Unterminated string constant starting at line 4 + +:::::::::::::::::::::::::::::::: pp_variable_args.i ::::::::::::::::::::::::::::::::::: +pp_variable_args.i:6: Error: Variable length macro argument must be last parameter + +:::::::::::::::::::::::::::::::: swig_apply_nargs.i ::::::::::::::::::::::::::::::::::: +swig_apply_nargs.i:6: Error: Can't apply (char *str,int len) to (int x). Number of arguments don't match. + +:::::::::::::::::::::::::::::::: swig_identifier.i ::::::::::::::::::::::::::::::::::: +swig_identifier.i:5: Warning 503: Can't wrap 'foo bar' unless renamed to a valid identifier. + +:::::::::::::::::::::::::::::::: swig_insert_bad.i ::::::::::::::::::::::::::::::::::: +swig_insert_bad.i:5: Error: Unknown target 'foobar' for %insert directive. + +:::::::::::::::::::::::::::::::: swig_typemap_copy.i ::::::::::::::::::::::::::::::::::: +swig_typemap_copy.i:3: Error: Can't copy typemap (in) blah = int + +:::::::::::::::::::::::::::::::: swig_typemap_old.i ::::::::::::::::::::::::::::::::::: +swig_typemap_old.i:6: Warning 450: Deprecated typemap feature ($source/$target). +swig_typemap_old.i:6: Warning 450: The use of $source and $target in a typemap declaration is deprecated. +For typemaps related to argument input (in,ignore,default,arginit,check), replace +$source by $input and $target by $1. For typemaps related to return values (out, +argout,ret,except), replace $source by $1 and $target by $result. See the file +Doc/Manual/Typemaps.html for complete details. + +:::::::::::::::::::::::::::::::: cpp_bad_extern.i ::::::::::::::::::::::::::::::::::: +cpp_bad_extern.i:5: Warning 313: Unrecognized extern type "INTERCAL". +cpp_bad_extern.i:7: Warning 313: Unrecognized extern type "INTERCAL". + +:::::::::::::::::::::::::::::::: cpp_extend_redefine.i ::::::::::::::::::::::::::::::::::: +cpp_extend_redefine.i:9: Warning 302: Identifier 'bar' redefined by %extend (ignored), +cpp_extend_redefine.i:5: Warning 302: %extend definition of 'bar'. +cpp_extend_redefine.i:14: Warning 322: Redundant redeclaration of 'spam', +cpp_extend_redefine.i:10: Warning 322: previous declaration of 'spam'. + +:::::::::::::::::::::::::::::::: cpp_extend_undefined.i ::::::::::::::::::::::::::::::::::: +cpp_extend_undefined.i:6: Warning 303: %extend defined for an undeclared class foo. + +:::::::::::::::::::::::::::::::: cpp_inline_namespace.i ::::::::::::::::::::::::::::::::::: +cpp_inline_namespace.i:4: Error: %inline directive inside a namespace is disallowed. + +:::::::::::::::::::::::::::::::: cpp_missing_rtemplate.i ::::::::::::::::::::::::::::::::::: +cpp_missing_rtemplate.i:4: Error: Syntax error in input(1). + +:::::::::::::::::::::::::::::::: cpp_namespace_alias.i ::::::::::::::::::::::::::::::::::: +cpp_namespace_alias.i:8: Warning 308: Namespace alias 'B' not allowed here. Assuming 'blah' + +:::::::::::::::::::::::::::::::: cpp_namespace_aliasnot.i ::::::::::::::::::::::::::::::::::: +cpp_namespace_aliasnot.i:4: Error: 'blah' is not a namespace + +:::::::::::::::::::::::::::::::: cpp_namespace_aliasundef.i ::::::::::::::::::::::::::::::::::: +cpp_namespace_aliasundef.i:3: Error: Unknown namespace 'blah' + +:::::::::::::::::::::::::::::::: cpp_nested.i ::::::::::::::::::::::::::::::::::: +cpp_nested.i:6: Warning 325: Nested class not currently supported (Bar ignored) +cpp_nested.i:12: Warning 325: Nested class not currently supported (Grok ignored) + +:::::::::::::::::::::::::::::::: cpp_no_access.i ::::::::::::::::::::::::::::::::::: +cpp_no_access.i:3: Warning 319: No access specifier given for base class foo (ignored). + +:::::::::::::::::::::::::::::::: cpp_nobase.i ::::::::::::::::::::::::::::::::::: +cpp_nobase.i:3: Warning 401: Nothing known about base class 'Bar'. Ignored. +cpp_nobase.i:6: Warning 401: Nothing known about base class 'Bar< int >'. Ignored. +cpp_nobase.i:6: Warning 401: Maybe you forgot to instantiate 'Bar< int >' using %template. + +:::::::::::::::::::::::::::::::: cpp_overload.i ::::::::::::::::::::::::::::::::::: + +:::::::::::::::::::::::::::::::: cpp_private_defvalue.i ::::::::::::::::::::::::::::::::::: + +:::::::::::::::::::::::::::::::: cpp_private_inherit.i ::::::::::::::::::::::::::::::::::: +cpp_private_inherit.i:6: Warning 309: private inheritance ignored. +cpp_private_inherit.i:9: Warning 309: protected inheritance ignored. + +:::::::::::::::::::::::::::::::: cpp_template_argname.i ::::::::::::::::::::::::::::::::::: + +:::::::::::::::::::::::::::::::: cpp_template_nargs.i ::::::::::::::::::::::::::::::::::: +cpp_template_nargs.i:5: Error: Template 'blah' undefined. +cpp_template_nargs.i:6: Error: Template 'blah' undefined. + +:::::::::::::::::::::::::::::::: cpp_template_not.i ::::::::::::::::::::::::::::::::::: +cpp_template_not.i:5: Error: 'blah' is not defined as a template. (cdecl) + +:::::::::::::::::::::::::::::::: cpp_template_partial.i ::::::::::::::::::::::::::::::::::: +cpp_template_partial.i:3: Warning 317: Specialization of non-template 'vector'. + +:::::::::::::::::::::::::::::::: cpp_template_repeat.i ::::::::::::::::::::::::::::::::::: + +:::::::::::::::::::::::::::::::: cpp_template_undef.i ::::::::::::::::::::::::::::::::::: +cpp_template_undef.i:3: Error: Template 'blah' undefined. + +:::::::::::::::::::::::::::::::: cpp_using_not.i ::::::::::::::::::::::::::::::::::: +cpp_using_not.i:4: Error: 'blah' is not a namespace. + +:::::::::::::::::::::::::::::::: cpp_using_undef.i ::::::::::::::::::::::::::::::::::: +cpp_using_undef.i:4: Error: Nothing known about namespace 'foo' +cpp_using_undef.i:3: Warning 315: Nothing known about 'foo::bar'. -- cgit v1.2.1 From b2e2cb8f6607ae29ef78e59390aa05c4ab354440 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Mon, 6 Sep 2010 18:25:22 +0000 Subject: Add test for line number reporting for multiple macro expansions git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12205 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Examples/test-suite/errors/make.sh | 1 + Examples/test-suite/errors/pp_macro_expansion.i | 10 ++++++++++ 2 files changed, 11 insertions(+) create mode 100644 Examples/test-suite/errors/pp_macro_expansion.i diff --git a/Examples/test-suite/errors/make.sh b/Examples/test-suite/errors/make.sh index e50fd22dc..3b58d6ab0 100755 --- a/Examples/test-suite/errors/make.sh +++ b/Examples/test-suite/errors/make.sh @@ -32,6 +32,7 @@ pp_macro_defined_unterminated pp_illegal_argument pp_macro_args pp_macro_badchar +pp_macro_expansion pp_macro_nargs pp_macro_redef pp_macro_rparen diff --git a/Examples/test-suite/errors/pp_macro_expansion.i b/Examples/test-suite/errors/pp_macro_expansion.i new file mode 100644 index 000000000..e23a0da01 --- /dev/null +++ b/Examples/test-suite/errors/pp_macro_expansion.i @@ -0,0 +1,10 @@ +%module xxx + +/* Test line number reporting for multiple macro expansions */ + +#define MACRO2(a, b) + +#define MACRO1(NAME) MACRO2(NAME,2,3) + +MACRO1(abc) + -- cgit v1.2.1 From 547019e0d457fe9427ff716737b8fdb82eab1cd8 Mon Sep 17 00:00:00 2001 From: Olly Betts Date: Wed, 8 Sep 2010 00:54:31 +0000 Subject: Change HTML to be more suitable for human edits. git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12207 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Doc/Manual/Ruby.html | 249 +++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 201 insertions(+), 48 deletions(-) diff --git a/Doc/Manual/Ruby.html b/Doc/Manual/Ruby.html index b61ded8e5..736b6137d 100644 --- a/Doc/Manual/Ruby.html +++ b/Doc/Manual/Ruby.html @@ -1,30 +1,11 @@ - - - - - - - - - - - - - - SWIG and Ruby - - - - - - +

    33 SWIG and Ruby

    @@ -255,7 +236,9 @@ header file. This file is usually contained in a directory such as

    -
    /usr/lib/ruby/1.8/x86_64-linux-gnu/ruby.h
    /usr/local/lib/ruby/1.6/i686-linux/ruby.h
    +
    /usr/lib/ruby/1.8/x86_64-linux-gnu/ruby.h
    +/usr/local/lib/ruby/1.6/i686-linux/ruby.h
    +
    @@ -276,7 +259,10 @@ installed, you can run Ruby to find out. For example:

    -
    $ ruby -e 'puts $:.join("\n")'
    /usr/local/lib/ruby/site_ruby/1.6 /usr/local/lib/ruby/site_ruby/1.6/i686-linux
    /usr/local/lib/ruby/site_ruby /usr/local/lib/ruby/1.6 /usr/local/lib/ruby/1.6/i686-linux .
    +
    $ ruby -e 'puts $:.join("\n")'
    +/usr/local/lib/ruby/site_ruby/1.6 /usr/local/lib/ruby/site_ruby/1.6/i686-linux
    +/usr/local/lib/ruby/site_ruby /usr/local/lib/ruby/1.6 /usr/local/lib/ruby/1.6/i686-linux .
    +
    @@ -324,16 +310,7 @@ looks like the following:

    - - - -
    require 'mkmf'
    create_makefile('example')
    - - - - -
    @@ -401,7 +378,12 @@ can add this:

    -
    open("Makefile", "a") { |mf|
    puts <<EOM
    # Your make rules go here
    EOM
    }
    +
    open("Makefile", "a") { |mf|
    + puts <<EOM
    + # Your make rules go here
    + EOM
    +}
    +
    @@ -424,7 +406,10 @@ operating system would look something like this:

    -
    $ swig -ruby example.i
    $ gcc -c example.c
    $ gcc -c example_wrap.c -I/usr/local/lib/ruby/1.6/i686-linux
    $ gcc -shared example.o example_wrap.o -o example.so +
    $ swig -ruby example.i
    +$ gcc -c example.c
    +$ gcc -c example_wrap.c -I/usr/local/lib/ruby/1.6/i686-linux 
    +$ gcc -shared example.o example_wrap.o -o example.so
     
    @@ -456,7 +441,12 @@ module is imported by requiring the etc feature:

    -
    # The feature name begins with a lowercase letter...
    require 'etc'

    # ... but the module name begins with an uppercase letter
    puts "Your login name: #{Etc.getlogin}"
    +
    # The feature name begins with a lowercase letter...
    +require 'etc'
    +
    +# ... but the module name begins with an uppercase letter
    +puts "Your login name: #{Etc.getlogin}"
    +
    @@ -2733,7 +2723,7 @@ i
    ->> [3, 4, 5 ]
    +>> [3, 4, 5 ]
    @@ -10098,7 +10088,38 @@ classes is:

    -
    /* File RubyOwnershipExample.i */

    %module RubyOwnershipExample

    %{
    #include "RubyOwnershipExample.h"
    %}

    class Foo
    {
    public:
    Foo();
    ~Foo();
    };

    class Bar
    {
    Foo *foo_;
    public:
    Bar();
    ~Bar();
    Foo* get_foo();

    %newobject get_new_foo;
    Foo* get_new_foo();

    %apply SWIGTYPE *DISOWN {Foo *foo};
    void set_foo(Foo *foo);
    %clear Foo *foo;
    };

    +
    /* File RubyOwnershipExample.i */
    +
    +%module RubyOwnershipExample
    +
    +%{
    +#include "RubyOwnershipExample.h"
    +%}
    +
    +class Foo
    +{
    +public:
    + Foo();
    + ~Foo();
    +};
    +
    +class Bar
    +{
    + Foo *foo_;
    +public:
    + Bar();
    + ~Bar();
    + Foo* get_foo();
    +
    + %newobject get_new_foo;
    + Foo* get_new_foo();
    +
    + %apply SWIGTYPE *DISOWN {Foo *foo};
    + void set_foo(Foo *foo);
    + %clear Foo *foo;
    +};
    +
    +
    @@ -10165,7 +10186,35 @@ class library models a zoo and the animals it contains.

    -
    $ irb
    irb(main):001:0> require 'example'
    => true

    irb(main):002:0> tiger1 = Example::Animal.new("tiger1")
    => #<Example::Animal:0x2be3820>

    irb(main):004:0> tiger1.get_name()
    => "tiger1"

    irb(main):003:0> zoo = Example::Zoo.new()
    => #<Example::Zoo:0x2be0a60>

    irb(main):006:0> zoo.add_animal(tiger)
    => nil

    irb(main):007:0> zoo.get_num_animals()
    => 1

    irb(main):007:0> tiger2 = zoo.remove_animal(0)
    => #<Example::Animal:0x2bd4a18>

    irb(main):008:0> tiger2.get_name()
    => "tiger1"

    irb(main):009:0> tiger1.equal?(tiger2)
    => false

    +
    $ irb
    +irb(main):001:0> require 'example'
    +=> true
    +
    +irb(main):002:0> tiger1 = Example::Animal.new("tiger1")
    +=> #<Example::Animal:0x2be3820>
    +
    +irb(main):004:0> tiger1.get_name()
    +=> "tiger1"
    +
    +irb(main):003:0> zoo = Example::Zoo.new()
    +=> #<Example::Zoo:0x2be0a60>
    +
    +irb(main):006:0> zoo.add_animal(tiger)
    +=> nil
    +
    +irb(main):007:0> zoo.get_num_animals()
    +=> 1
    +
    +irb(main):007:0> tiger2 = zoo.remove_animal(0)
    +=> #<Example::Animal:0x2bd4a18>
    +
    +irb(main):008:0> tiger2.get_name()
    +=> "tiger1"
    +
    +irb(main):009:0> tiger1.equal?(tiger2)
    +=> false
    +
    +
    @@ -10192,7 +10241,16 @@ the same underlying C++ object. This can cause problems. For example:
    -
    irb(main):010:0> tiger1 = nil
    => nil

    irb(main):011:0> GC.start
    => nil

    irb(main):012:0> tiger2.get_name()
    (irb):12: [BUG] Segmentation fault

    +
    irb(main):010:0> tiger1 = nil
    +=> nil
    +
    +irb(main):011:0> GC.start
    +=> nil
    +
    +irb(main):012:0> tiger2.get_name()
    +(irb):12: [BUG] Segmentation fault
    +
    +
    @@ -10251,7 +10309,7 @@ class-by-class basis if needed. To fix the example above:

    -
    %module example

    %{
    #include "example.h"
    %}

    /* Tell SWIG that create_animal creates a new object */
    %newobject Zoo::create_animal;

    /* Tell SWIG to keep track of mappings between C/C++ structs/classes. */
    %trackobjects;

    %include "example.h"
    +
    %module example

    %{
    #include "example.h"
    %}

    /* Tell SWIG that create_animal creates a new object */
    %newobject Zoo::create_animal;

    /* Tell SWIG to keep track of mappings between C/C++ structs/classes. */
    %trackobjects;

    %include "example.h"
    @@ -10282,7 +10340,7 @@ class-by-class basis if needed. To fix the example above:

    -
    $ irb
    irb(main):001:0> require 'example'
    => true

    irb(main):002:0> tiger1 = Example::Animal.new("tiger1")
    => #<Example::Animal:0x2be37d8>

    irb(main):003:0> zoo = Example::Zoo.new()
    => #<Example::Zoo:0x2be0a18>

    irb(main):004:0> zoo.add_animal(tiger1)
    => nil

    irb(main):006:0> tiger2 = zoo.remove_animal(0)
    => #<Example::Animal:0x2be37d8>

    irb(main):007:0> tiger1.equal?(tiger2)
    => true

    irb(main):008:0> tiger1 = nil
    => nil

    irb(main):009:0> GC.start
    => nil

    irb(main):010:0> tiger.get_name()
    => "tiger1"
    irb(main):011:0>

    +
    $ irb
    irb(main):001:0> require 'example'
    => true

    irb(main):002:0> tiger1 = Example::Animal.new("tiger1")
    => #<Example::Animal:0x2be37d8>

    irb(main):003:0> zoo = Example::Zoo.new()
    => #<Example::Zoo:0x2be0a18>

    irb(main):004:0> zoo.add_animal(tiger1)
    => nil

    irb(main):006:0> tiger2 = zoo.remove_animal(0)
    => #<Example::Animal:0x2be37d8>

    irb(main):007:0> tiger1.equal?(tiger2)
    => true

    irb(main):008:0> tiger1 = nil
    => nil

    irb(main):009:0> GC.start
    => nil

    irb(main):010:0> tiger.get_name()
    => "tiger1"
    irb(main):011:0>

    @@ -10359,7 +10417,7 @@ has problems. For example:
    -
    $ irb
    irb(main):001:0> require 'example'
    => true

    irb(main):002:0> tiger1 = Example::Animal.new("tiger1")
    => #<Example::Animal:0x2bea6a8>

    irb(main):003:0> zoo = Example::Zoo.new()
    => #<Example::Zoo:0x2be7960>

    irb(main):004:0> zoo.add_animal(tiger1)
    => nil

    irb(main):007:0> tiger1 = nil
    => nil

    irb(main):007:0> GC.start
    => nil

    irb(main):005:0> tiger2 = zoo.get_animal(0)
    (irb):12: [BUG] Segmentation fault
    +
    $ irb
    irb(main):001:0> require 'example'
    => true

    irb(main):002:0> tiger1 = Example::Animal.new("tiger1")
    => #<Example::Animal:0x2bea6a8>

    irb(main):003:0> zoo = Example::Zoo.new()
    => #<Example::Zoo:0x2be7960>

    irb(main):004:0> zoo.add_animal(tiger1)
    => nil

    irb(main):007:0> tiger1 = nil
    => nil

    irb(main):007:0> GC.start
    => nil

    irb(main):005:0> tiger2 = zoo.get_animal(0)
    (irb):12: [BUG] Segmentation fault
    @@ -10407,7 +10465,7 @@ implementation is:

    -
    %module example

    %{
    #include "example.h"
    %}

    /* Keep track of mappings between C/C++ structs/classes
    and Ruby objects so we can implement a mark function. */
    %trackobjects;

    /* Specify the mark function */
    %markfunc Zoo "mark_Zoo";

    %include "example.h"

    %header %{

    static void mark_Zoo(void* ptr) {
    Zoo* zoo = (Zoo*) ptr;

    /* Loop over each object and tell the garbage collector
    that we are holding a reference to them. */
    int count = zoo->get_num_animals();

    for(int i = 0; i < count; ++i) {
    Animal* animal = zoo->get_animal(i);
    VALUE object = SWIG_RubyInstanceFor(animal);

    if (object != Qnil) {
    rb_gc_mark(object);
    }
    }
    }
    %}

    +
    %module example

    %{
    #include "example.h"
    %}

    /* Keep track of mappings between C/C++ structs/classes
    and Ruby objects so we can implement a mark function. */
    %trackobjects;

    /* Specify the mark function */
    %markfunc Zoo "mark_Zoo";

    %include "example.h"

    %header %{

    static void mark_Zoo(void* ptr) {
    Zoo* zoo = (Zoo*) ptr;

    /* Loop over each object and tell the garbage collector
    that we are holding a reference to them. */
    int count = zoo->get_num_animals();

    for(int i = 0; i < count; ++i) {
    Animal* animal = zoo->get_animal(i);
    VALUE object = SWIG_RubyInstanceFor(animal);

    if (object != Qnil) {
    rb_gc_mark(object);
    }
    }
    }
    %}

    @@ -10436,7 +10494,7 @@ test suite.

    -
    $ irb
    irb(main):002:0> tiger1=Example::Animal.new("tiger1")
    => #<Example::Animal:0x2be3bf8>

    irb(main):003:0> Example::Zoo.new()
    => #<Example::Zoo:0x2be1780>

    irb(main):004:0> zoo = Example::Zoo.new()
    => #<Example::Zoo:0x2bde9c0>

    irb(main):005:0> zoo.add_animal(tiger1)
    => nil

    irb(main):009:0> tiger1 = nil
    => nil

    irb(main):010:0> GC.start
    => nil
    irb(main):014:0> tiger2 = zoo.get_animal(0)
    => #<Example::Animal:0x2be3bf8>

    irb(main):015:0> tiger2.get_name()
    => "tiger1"
    irb(main):016:0>

    +
    $ irb
    irb(main):002:0> tiger1=Example::Animal.new("tiger1")
    => #<Example::Animal:0x2be3bf8>

    irb(main):003:0> Example::Zoo.new()
    => #<Example::Zoo:0x2be1780>

    irb(main):004:0> zoo = Example::Zoo.new()
    => #<Example::Zoo:0x2bde9c0>

    irb(main):005:0> zoo.add_animal(tiger1)
    => nil

    irb(main):009:0> tiger1 = nil
    => nil

    irb(main):010:0> GC.start
    => nil
    irb(main):014:0> tiger2 = zoo.get_animal(0)
    => #<Example::Animal:0x2be3bf8>

    irb(main):015:0> tiger2.get_name()
    => "tiger1"
    irb(main):016:0>

    @@ -10512,14 +10570,22 @@ directive, let's slightly change our example. Assume that the zoo object is responsible for freeing animal that it contains. This means that the Zoo::add_animal function should be marked with a DISOWN typemap -and the destructor should be updated as below::

    +and the destructor should be updated as below:

    -
    Zoo::~Zoo() {
    IterType iter = this->animals.begin();
    IterType end = this->animals.end();

    for(iter; iter != end; ++iter) {
    Animal* animal = *iter;
    delete animal;
    }
    }
    +
    Zoo::~Zoo() {
    + IterType iter = this->animals.begin();
    + IterType end = this->animals.end();
    +
    + for(iter; iter != end; ++iter) {
    + Animal* animal = *iter;
    + delete animal;
    + }
    +}
    @@ -10538,7 +10604,29 @@ and the destructor should be updated as below::

    -
    $irb
    irb(main):002:0> require 'example'
    => true

    irb(main):003:0> zoo = Example::Zoo.new()
    => #<Example::Zoo:0x2be0fe8>

    irb(main):005:0> tiger1 = Example::Animal.new("tiger1")
    => #<Example::Animal:0x2bda760>

    irb(main):006:0> zoo.add_animal(tiger1)
    => nil

    irb(main):007:0> zoo = nil
    => nil

    irb(main):008:0> GC.start
    => nil

    irb(main):009:0> tiger1.get_name()
    (irb):12: [BUG] Segmentation fault

    +
    $irb
    +irb(main):002:0> require 'example'
    +=> true
    +
    +irb(main):003:0> zoo = Example::Zoo.new()
    +=> #<Example::Zoo:0x2be0fe8>
    +
    +irb(main):005:0> tiger1 = Example::Animal.new("tiger1")
    +=> #<Example::Animal:0x2bda760>
    +
    +irb(main):006:0> zoo.add_animal(tiger1)
    +=> nil
    +
    +irb(main):007:0> zoo = nil
    +=> nil
    +
    +irb(main):008:0> GC.start
    +=> nil
    +
    +irb(main):009:0> tiger1.get_name()
    +(irb):12: [BUG] Segmentation fault
    +
    +
    @@ -10571,7 +10659,49 @@ existing Ruby object to the destroyed C++ object and raise an exception.
    -
    %module example

    %{
    #include "example.h"
    %}

    /* Specify that ownership is transferred to the zoo
    when calling add_animal */
    %apply SWIGTYPE *DISOWN { Animal* animal };

    /* Track objects */
    %trackobjects;

    /* Specify the mark function */
    %freefunc Zoo "free_Zoo";

    %include "example.h"

    %header %{
    static void free_Zoo(void* ptr) {
    Zoo* zoo = (Zoo*) ptr;

    /* Loop over each animal */
    int count = zoo->get_num_animals();

    for(int i = 0; i < count; ++i) {
    /* Get an animal */
    Animal* animal = zoo->get_animal(i);

    /* Unlink the Ruby object from the C++ object */
    SWIG_RubyUnlinkObjects(animal);

    /* Now remove the tracking for this animal */
    SWIG_RubyRemoveTracking(animal);
    }

    /* Now call SWIG_RubyRemoveTracking for the zoo */
    SWIG_RubyRemoveTracking(ptr);

    /* Now free the zoo which will free the animals it contains */
    delete zoo;
    }
    %}
    +
    %module example
    +
    +%{
    +#include "example.h"
    +%}
    +
    +/* Specify that ownership is transferred to the zoo
    +	when calling add_animal */
    +%apply SWIGTYPE *DISOWN { Animal* animal };
    +
    +/* Track objects */
    +%trackobjects;
    +
    +/* Specify the mark function */
    +%freefunc Zoo "free_Zoo";
    +
    +%include "example.h"
    +
    +%header %{
    + static void free_Zoo(void* ptr) {
    + Zoo* zoo = (Zoo*) ptr;
    +
    + /* Loop over each animal */
    + int count = zoo->get_num_animals();
    +
    + for(int i = 0; i < count; ++i) {
    + /* Get an animal */
    + Animal* animal = zoo->get_animal(i);
    +
    + /* Unlink the Ruby object from the C++ object */
    + SWIG_RubyUnlinkObjects(animal);
    +
    + /* Now remove the tracking for this animal */
    + SWIG_RubyRemoveTracking(animal);
    + }
    +
    + /* Now call SWIG_RubyRemoveTracking for the zoo */
    + SWIG_RubyRemoveTracking(ptr);
    + 
    + /* Now free the zoo which will free the animals it contains */
    + delete zoo;
    + }
    +%} 
    @@ -10590,7 +10720,30 @@ existing Ruby object to the destroyed C++ object and raise an exception.
    -
    $irb
    irb(main):002:0> require 'example'
    => true

    irb(main):003:0> zoo = Example::Zoo.new()
    => #<Example::Zoo:0x2be0fe8>

    irb(main):005:0> tiger1 = Example::Animal.new("tiger1")
    => #<Example::Animal:0x2bda760>

    irb(main):006:0> zoo.add_animal(tiger1)
    => nil

    irb(main):007:0> zoo = nil
    => nil

    irb(main):008:0> GC.start
    => nil

    irb(main):009:0> tiger1.get_name()
    RuntimeError: This Animal * already released
    from (irb):10:in `get_name'
    from (irb):10
    irb(main):011:0>
    +
    $irb
    +irb(main):002:0> require 'example'
    +=> true
    +
    +irb(main):003:0> zoo = Example::Zoo.new()
    +=> #<Example::Zoo:0x2be0fe8>
    +
    +irb(main):005:0> tiger1 = Example::Animal.new("tiger1")
    +=> #<Example::Animal:0x2bda760>
    +
    +irb(main):006:0> zoo.add_animal(tiger1)
    +=> nil
    +
    +irb(main):007:0> zoo = nil
    +=> nil
    +
    +irb(main):008:0> GC.start
    +=> nil
    +
    +irb(main):009:0> tiger1.get_name()
    +RuntimeError: This Animal * already released
    + from (irb):10:in `get_name'
    + from (irb):10
    +irb(main):011:0>
    -- cgit v1.2.1 From a25ccbf58b5d45a5916cf81821659c1730f0e793 Mon Sep 17 00:00:00 2001 From: Olly Betts Date: Wed, 8 Sep 2010 02:40:56 +0000 Subject: [PHP] Fix handling of OUTPUT typemaps (Patch from Ryan in SF#3058394). git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12208 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- CHANGES.current | 3 +++ Examples/php/cpointer/runme.php | 26 ++++++++++++++------------ Source/Modules/php.cxx | 4 +++- 3 files changed, 20 insertions(+), 13 deletions(-) diff --git a/CHANGES.current b/CHANGES.current index c09ff3409..b480728d7 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -5,6 +5,9 @@ See the RELEASENOTES file for a summary of changes in each release. Version 2.0.1 (in progress) =========================== +2010-09-08: olly + [PHP] Fix handling of OUTPUT typemaps (Patch from Ryan in SF#3058394). + 2010-09-03: wsfulton Fix erroneous line numbers in error messages for macro expansions, for example, the error message now points to instantation of the macro, ie the last line here: diff --git a/Examples/php/cpointer/runme.php b/Examples/php/cpointer/runme.php index 48f0ad631..22e8a681a 100644 --- a/Examples/php/cpointer/runme.php +++ b/Examples/php/cpointer/runme.php @@ -6,40 +6,42 @@ print "Testing the pointer library\n"; - $a = new_intp(); - $b = new_intp(); - $c = new_intp(); - intp_assign($a,37); - intp_assign($b,42); + $a = example::new_intp(); + $b = example::new_intp(); + $c = example::new_intp(); + example::intp_assign($a,37); + example::intp_assign($b,42); print " a = $a\n"; print " b = $b\n"; print " c = $c\n"; # Call the add() function wuth some pointers - add($a,$b,$c); + example::add($a,$b,$c); # Now get the result - $r = intp_value($c); + $r = example::intp_value($c); print " 37 + 42 = $r\n"; # Clean up the pointers - delete_intp($a); - delete_intp($b); - delete_intp($c); + example::delete_intp($a); + example::delete_intp($b); + example::delete_intp($c); # Now try the typemap library # This should be much easier. Now how it is no longer # necessary to manufacture pointers. print "Trying the typemap library\n"; - $r = sub(37,42); + $r = example::sub(37,42); print " 37 - 42 = $r\n"; # Now try the version with multiple return values # print "Testing multiple return values\n"; - # ($q,$r) = divide(42,37); + # $a = example::divide(42,37); + # $q = $a[0] + # $r = $a[1] # print " 42/37 = $q remainder $r\n"; ?> diff --git a/Source/Modules/php.cxx b/Source/Modules/php.cxx index 365fcd370..89204d7bf 100644 --- a/Source/Modules/php.cxx +++ b/Source/Modules/php.cxx @@ -915,8 +915,10 @@ public: } /* Insert argument output code */ + bool hasargout = false; for (i = 0, p = l; p; i++) { if ((tm = Getattr(p, "tmap:argout"))) { + hasargout = true; Replaceall(tm, "$source", Getattr(p, "lname")); // Replaceall(tm,"$input",Getattr(p,"lname")); Replaceall(tm, "$target", "return_value"); @@ -1663,7 +1665,7 @@ public: } } Printf(output, "%s", prepare); - } else if (Cmp(d, "void") == 0) { + } else if (Cmp(d, "void") == 0 && !hasargout) { if (Cmp(invoke, "$r") != 0) Printf(output, "\t\t%s;\n", invoke); } else if (is_class(d)) { -- cgit v1.2.1 From 52819796ca8c9c36175c48a9a0f454376e5b2185 Mon Sep 17 00:00:00 2001 From: Olly Betts Date: Wed, 8 Sep 2010 02:43:32 +0000 Subject: Fix a couple of typos git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12209 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- CHANGES.current | 4 ++-- Examples/test-suite/preproc_line_file.i | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/CHANGES.current b/CHANGES.current index b480728d7..660e73eeb 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -10,7 +10,7 @@ Version 2.0.1 (in progress) 2010-09-03: wsfulton Fix erroneous line numbers in error messages for macro expansions, for example, - the error message now points to instantation of the macro, ie the last line here: + the error message now points to instantiation of the macro, ie the last line here: #define MACRO2(a, b) @@ -28,7 +28,7 @@ Version 2.0.1 (in progress) %} 2010-09-02: wsfulton - Fix line numbers in error and warning messages which were accumulately one + Fix line numbers in error and warning messages which were cumulatively one less than they should have been after parsing each %include/%import - bug introduced in swig-1.3.32. Also fix line numbers in error and warning messages when new line characters appear between the %include / %import statement and diff --git a/Examples/test-suite/preproc_line_file.i b/Examples/test-suite/preproc_line_file.i index 5b75d0a20..e8ca47cbc 100644 --- a/Examples/test-suite/preproc_line_file.i +++ b/Examples/test-suite/preproc_line_file.i @@ -29,11 +29,11 @@ const int NUMBER_UNIQUE(thing) = -2; /* resolves to thing28 */ #define MYLINE2 __LINE__ +#ifdef SWIGJAVA %javaconst(1); +#endif %{ -struct SillyStruct { - int num; - /* static const int line_num = __LINE__; */ +struct SillyStruct { int num; /* static const int line_num = __LINE__; */ }; %} struct SillyStruct { -- cgit v1.2.1 From f6cd7912e324cdf2633a3e4e0c626a26f627be96 Mon Sep 17 00:00:00 2001 From: Olly Betts Date: Wed, 8 Sep 2010 02:45:23 +0000 Subject: Revert change inadvertently included in previous commit. git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12210 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Examples/test-suite/preproc_line_file.i | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Examples/test-suite/preproc_line_file.i b/Examples/test-suite/preproc_line_file.i index e8ca47cbc..5b75d0a20 100644 --- a/Examples/test-suite/preproc_line_file.i +++ b/Examples/test-suite/preproc_line_file.i @@ -29,11 +29,11 @@ const int NUMBER_UNIQUE(thing) = -2; /* resolves to thing28 */ #define MYLINE2 __LINE__ -#ifdef SWIGJAVA %javaconst(1); -#endif %{ -struct SillyStruct { int num; /* static const int line_num = __LINE__; */ +struct SillyStruct { + int num; + /* static const int line_num = __LINE__; */ }; %} struct SillyStruct { -- cgit v1.2.1 From 122bc852f98500360c9d7d920bf3bee220085770 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Fri, 10 Sep 2010 06:08:45 +0000 Subject: Fix #2149523 - Incorrect line number reporting in errors after parsing macros. Remove extraneous extra line in preprocessed output which would sometimes lead to error/warning messages two lines after the end of the file git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12211 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- CHANGES.current | 9 +++++ Examples/test-suite/errors/make.sh | 6 ++- Examples/test-suite/errors/pp_constant.i | 43 ++++++++++++++++++++++ .../errors/pp_macro_inline_unterminated.i | 11 ++++++ Source/Preprocessor/cpp.c | 11 ++---- Source/Swig/include.c | 2 + 6 files changed, 73 insertions(+), 9 deletions(-) create mode 100644 Examples/test-suite/errors/pp_constant.i create mode 100644 Examples/test-suite/errors/pp_macro_inline_unterminated.i diff --git a/CHANGES.current b/CHANGES.current index 660e73eeb..227f5218c 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -5,6 +5,15 @@ See the RELEASENOTES file for a summary of changes in each release. Version 2.0.1 (in progress) =========================== +2010-09-10: wsfulton + Remove extraneous extra line in preprocessed output after including files + which would sometimes lead to error/warning messages two lines after the + end of the file. + +2010-09-10: wsfulton + Fix #2149523 - Incorrect line number reporting in errors after parsing macros + containing C++ comments. + 2010-09-08: olly [PHP] Fix handling of OUTPUT typemaps (Patch from Ryan in SF#3058394). diff --git a/Examples/test-suite/errors/make.sh b/Examples/test-suite/errors/make.sh index 3b58d6ab0..45c5c1733 100755 --- a/Examples/test-suite/errors/make.sh +++ b/Examples/test-suite/errors/make.sh @@ -26,13 +26,15 @@ c_varargs c_varargs_neg nomodule pp_badeval -pp_deprecated +pp_constant pp_defined -pp_macro_defined_unterminated +pp_deprecated pp_illegal_argument pp_macro_args pp_macro_badchar +pp_macro_defined_unterminated pp_macro_expansion +pp_macro_inline_unterminated pp_macro_nargs pp_macro_redef pp_macro_rparen diff --git a/Examples/test-suite/errors/pp_constant.i b/Examples/test-suite/errors/pp_constant.i new file mode 100644 index 000000000..84846f1c5 --- /dev/null +++ b/Examples/test-suite/errors/pp_constant.i @@ -0,0 +1,43 @@ +%module xxx + +/* Test preprocessor comments and their effect on line number reporting on later errors */ + +#define A1 1234 +#define A2 1234 /*C comment*/ +#define A3 1234 + +%constant int aaa=; + +#define B1 1234 +#define B2 1234 //C++ comment +#define B3 1234 + +%constant int bbb=; + +#define C1 1234 +#define C2 1234 /*multiline +C +comment */ +#define C3 1234 + +%constant int ccc=; + +#define D1 1234 +#define /*C Comment*/ D2 1234 +#define D3 1234 + +%constant int ddd=; + +#define E1 1234 +#/*C comment*/define E2 1234 +#define E3 1234 + +%constant int eee=; + +#define F1 1234 +#define F2 1234 \ +// C comment +#define F3 1234 + +%constant int fff=; + diff --git a/Examples/test-suite/errors/pp_macro_inline_unterminated.i b/Examples/test-suite/errors/pp_macro_inline_unterminated.i new file mode 100644 index 000000000..67de0942c --- /dev/null +++ b/Examples/test-suite/errors/pp_macro_inline_unterminated.i @@ -0,0 +1,11 @@ +%module xxx + +%define foo(a,x) +int ii; +%enddef + +%inline %{ +struct Struct { +foo(2, +}; +%} diff --git a/Source/Preprocessor/cpp.c b/Source/Preprocessor/cpp.c index b4866ee9c..bb56c21d2 100644 --- a/Source/Preprocessor/cpp.c +++ b/Source/Preprocessor/cpp.c @@ -1445,15 +1445,14 @@ String *Preprocessor_parse(String *s) { state = 43; } break; - case 46: + case 46: /* in C++ comment */ if (c == '\n') { Ungetc(c, s); - cpp_lines++; state = 50; } else Putc(c, comment); break; - case 47: + case 47: /* in C comment */ if (c == '*') state = 48; else @@ -1638,7 +1637,7 @@ String *Preprocessor_parse(String *s) { } s2 = Preprocessor_parse(s1); addline(ns, s2, allow); - Append(ns, "\n]"); + Append(ns, "]"); if (dirname) { Swig_pop_directory(); } @@ -1784,7 +1783,7 @@ String *Preprocessor_parse(String *s) { pop_imported(); } addline(ns, s2, allow); - Append(ns, "\n]"); + Append(ns, "]"); Delete(s2); Delete(s1); } @@ -1845,7 +1844,6 @@ String *Preprocessor_parse(String *s) { Seek(value, 0, SEEK_SET); Preprocessor_define(value, 1); } - /* Putc('\n',ns); */ addline(ns, value, 0); state = 0; } @@ -1884,6 +1882,5 @@ String *Preprocessor_parse(String *s) { Delete(comment); Delete(chunk); - /* fprintf(stderr,"cpp: %d\n", Len(Getattr(cpp,"symbols"))); */ return ns; } diff --git a/Source/Swig/include.c b/Source/Swig/include.c index baae44bb8..e3f256901 100644 --- a/Source/Swig/include.c +++ b/Source/Swig/include.c @@ -221,6 +221,8 @@ String *Swig_read_file(FILE *f) { Append(str, buffer); } len = Len(str); + /* Add a newline if not present on last line -- the preprocessor seems to + * rely on \n and not EOF terminating lines */ if (len) { char *cstr = Char(str); if (cstr[len - 1] != '\n') { -- cgit v1.2.1 From e3092a6150860764792767d375d22ec9ced2d54f Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Fri, 10 Sep 2010 06:40:42 +0000 Subject: Remove java specifics from testcase git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12212 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Examples/test-suite/java/preproc_line_file_runme.java | 8 ++++---- Examples/test-suite/preproc_line_file.i | 11 +++++++++++ 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/Examples/test-suite/java/preproc_line_file_runme.java b/Examples/test-suite/java/preproc_line_file_runme.java index 8119824e9..9b47ae4bd 100644 --- a/Examples/test-suite/java/preproc_line_file_runme.java +++ b/Examples/test-suite/java/preproc_line_file_runme.java @@ -45,16 +45,16 @@ public class preproc_line_file_runme { if (preproc_line_file.MYLINE2 != 30) throw new RuntimeException("preproc failure"); - if (SillyStruct.LINE_NUMBER != 41) + if (SillyStruct.LINE_NUMBER != 52) throw new RuntimeException("preproc failure"); - if (SillyMacroClass.LINE_NUM != 45) + if (SillyMacroClass.LINE_NUM != 56) throw new RuntimeException("preproc failure"); - if (SillyMultipleMacroStruct.LINE_NUM != 70) + if (SillyMultipleMacroStruct.LINE_NUM != 81) throw new RuntimeException("preproc failure"); - if (preproc_line_file.INLINE_LINE != 76) + if (preproc_line_file.INLINE_LINE != 87) throw new RuntimeException("preproc failure"); String inlineFile = preproc_line_file.INLINE_FILE; diff --git a/Examples/test-suite/preproc_line_file.i b/Examples/test-suite/preproc_line_file.i index 5b75d0a20..e28259e76 100644 --- a/Examples/test-suite/preproc_line_file.i +++ b/Examples/test-suite/preproc_line_file.i @@ -29,7 +29,18 @@ const int NUMBER_UNIQUE(thing) = -2; /* resolves to thing28 */ #define MYLINE2 __LINE__ +#if defined (SWIGJAVA) %javaconst(1); +#elif defined(SWIGCSHARP) +%csconst(1); +#else +%ignore LINE_NUMBER; +%ignore LINE_NUM; +/* spare space */ + + +#endif + %{ struct SillyStruct { int num; -- cgit v1.2.1 From 4435fe4f4adec4c04d6c1df1949dfc3080d85fd4 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Fri, 10 Sep 2010 23:39:03 +0000 Subject: Update expected error/warning results since last commit git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12213 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Examples/test-suite/errors/expected.log | 29 ++++++++++++++++++++++------- 1 file changed, 22 insertions(+), 7 deletions(-) diff --git a/Examples/test-suite/errors/expected.log b/Examples/test-suite/errors/expected.log index ff56d9b2b..fa8114aad 100644 --- a/Examples/test-suite/errors/expected.log +++ b/Examples/test-suite/errors/expected.log @@ -71,19 +71,24 @@ No module name specified using %module or -module. pp_badeval.i:4: Warning 202: Could not evaluate 'FOO==4+' pp_badeval.i:4: Warning 202: Error: 'Expected an expression' -:::::::::::::::::::::::::::::::: pp_deprecated.i ::::::::::::::::::::::::::::::::::: -pp_deprecated.i:4: Warning 101: %extern is deprecated. Use %import instead. -pp_deprecated.i:4: Error: Unable to find 'ext;' -pp_deprecated.i:6: Warning 204: CPP #warning, Print this warning -pp_deprecated.i:8: Error: CPP #error "This is an error". Use the -cpperraswarn option to continue swig processing. +:::::::::::::::::::::::::::::::: pp_constant.i ::::::::::::::::::::::::::::::::::: +pp_constant.i:9: Warning 305: Bad constant value (ignored). +pp_constant.i:15: Warning 305: Bad constant value (ignored). +pp_constant.i:23: Warning 305: Bad constant value (ignored). +pp_constant.i:29: Warning 305: Bad constant value (ignored). +pp_constant.i:35: Warning 305: Bad constant value (ignored). +pp_constant.i:42: Warning 305: Bad constant value (ignored). :::::::::::::::::::::::::::::::: pp_defined.i ::::::::::::::::::::::::::::::::::: pp_defined.i:6: Error: No arguments given to defined() pp_defined.i:6: Warning 202: Could not evaluate 'defined' pp_defined.i:6: Warning 202: Error: 'Expected an expression' -:::::::::::::::::::::::::::::::: pp_macro_defined_unterminated.i ::::::::::::::::::::::::::::::::::: -pp_macro_defined_unterminated.i:4: Error: Unterminated call to 'defined' +:::::::::::::::::::::::::::::::: pp_deprecated.i ::::::::::::::::::::::::::::::::::: +pp_deprecated.i:4: Warning 101: %extern is deprecated. Use %import instead. +pp_deprecated.i:4: Error: Unable to find 'ext;' +pp_deprecated.i:6: Warning 204: CPP #warning, Print this warning +pp_deprecated.i:8: Error: CPP #error "This is an error". Use the -cpperraswarn option to continue swig processing. :::::::::::::::::::::::::::::::: pp_illegal_argument.i ::::::::::::::::::::::::::::::::::: pp_illegal_argument.i:6: Error: Illegal macro argument name '..' @@ -95,6 +100,16 @@ pp_illegal_argument.i:16: Error: Illegal character in macro argument name :::::::::::::::::::::::::::::::: pp_macro_badchar.i ::::::::::::::::::::::::::::::::::: pp_macro_badchar.i:4: Error: Illegal character in macro argument name +:::::::::::::::::::::::::::::::: pp_macro_defined_unterminated.i ::::::::::::::::::::::::::::::::::: +pp_macro_defined_unterminated.i:4: Error: Unterminated call to 'defined' + +:::::::::::::::::::::::::::::::: pp_macro_expansion.i ::::::::::::::::::::::::::::::::::: +pp_macro_expansion.i:9: Error: Macro 'MACRO2' expects 2 arguments + +:::::::::::::::::::::::::::::::: pp_macro_inline_unterminated.i ::::::::::::::::::::::::::::::::::: +pp_macro_inline_unterminated.i:9: Error: Unterminated call invoking macro 'foo' +pp_macro_inline_unterminated.i:12: Error: Syntax error in input(3). + :::::::::::::::::::::::::::::::: pp_macro_nargs.i ::::::::::::::::::::::::::::::::::: pp_macro_nargs.i:7: Error: Macro 'foo' expects 2 arguments pp_macro_nargs.i:8: Error: Macro 'foo' expects 2 arguments -- cgit v1.2.1 From f82811dbcd135f37544d20d75354efe70f5d548d Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Fri, 10 Sep 2010 23:44:27 +0000 Subject: Fix incorrect line number reporting in errors/warnings after parsing macro invocations with parameters given over more than one line. git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12214 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- CHANGES.current | 4 +++ Examples/test-suite/errors/expected.log | 6 ++++ Examples/test-suite/errors/make.sh | 1 + .../errors/pp_macro_expansion_multiline.i | 32 ++++++++++++++++++++++ Source/Preprocessor/cpp.c | 7 +++++ 5 files changed, 50 insertions(+) create mode 100644 Examples/test-suite/errors/pp_macro_expansion_multiline.i diff --git a/CHANGES.current b/CHANGES.current index 227f5218c..20c0a6b0a 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -5,6 +5,10 @@ See the RELEASENOTES file for a summary of changes in each release. Version 2.0.1 (in progress) =========================== +2010-09-11: wsfulton + Fix incorrect line number reporting in errors/warnings after parsing + macro invocations with parameters given over more than one line. + 2010-09-10: wsfulton Remove extraneous extra line in preprocessed output after including files which would sometimes lead to error/warning messages two lines after the diff --git a/Examples/test-suite/errors/expected.log b/Examples/test-suite/errors/expected.log index fa8114aad..56e10a066 100644 --- a/Examples/test-suite/errors/expected.log +++ b/Examples/test-suite/errors/expected.log @@ -106,6 +106,12 @@ pp_macro_defined_unterminated.i:4: Error: Unterminated call to 'defined' :::::::::::::::::::::::::::::::: pp_macro_expansion.i ::::::::::::::::::::::::::::::::::: pp_macro_expansion.i:9: Error: Macro 'MACRO2' expects 2 arguments +:::::::::::::::::::::::::::::::: pp_macro_expansion_multiline.i ::::::::::::::::::::::::::::::::::: +pp_macro_expansion_multiline.i:13: Warning 509: Overloaded method foo(int const *) effectively ignored, +pp_macro_expansion_multiline.i:12: Warning 509: as it is shadowed by foo(int *). +pp_macro_expansion_multiline.i:31: Warning 509: Overloaded method bar(int const *) effectively ignored, +pp_macro_expansion_multiline.i:30: Warning 509: as it is shadowed by bar(int *). + :::::::::::::::::::::::::::::::: pp_macro_inline_unterminated.i ::::::::::::::::::::::::::::::::::: pp_macro_inline_unterminated.i:9: Error: Unterminated call invoking macro 'foo' pp_macro_inline_unterminated.i:12: Error: Syntax error in input(3). diff --git a/Examples/test-suite/errors/make.sh b/Examples/test-suite/errors/make.sh index 45c5c1733..0fb3e14a4 100755 --- a/Examples/test-suite/errors/make.sh +++ b/Examples/test-suite/errors/make.sh @@ -34,6 +34,7 @@ pp_macro_args pp_macro_badchar pp_macro_defined_unterminated pp_macro_expansion +pp_macro_expansion_multiline pp_macro_inline_unterminated pp_macro_nargs pp_macro_redef diff --git a/Examples/test-suite/errors/pp_macro_expansion_multiline.i b/Examples/test-suite/errors/pp_macro_expansion_multiline.i new file mode 100644 index 000000000..b0777de60 --- /dev/null +++ b/Examples/test-suite/errors/pp_macro_expansion_multiline.i @@ -0,0 +1,32 @@ +%module xxx +// Testing macros split over multiple lines - ensure the warning message for the ignored functions contain the correct line numbering + +#define MYMACRO(NAME, A, B, C) void NAME(int A, int B, int C); + +MYMACRO(funk, x, +y, + +z +) + +void foo(int *); +void foo(const int *); + +%define MYSWIGMACRO(A, B, C) +MYMACRO(funk1, + AA, + BB, + CC) +MYMACRO(funk2, + AA, + BB, + CC) +%enddef + +MYSWIGMACRO(xx, + yy, + zz) + +void bar(int *); +void bar(const int *); + diff --git a/Source/Preprocessor/cpp.c b/Source/Preprocessor/cpp.c index bb56c21d2..23896fc50 100644 --- a/Source/Preprocessor/cpp.c +++ b/Source/Preprocessor/cpp.c @@ -1075,10 +1075,14 @@ static DOH *Preprocessor_replace(DOH *s) { /* See if the macro is defined in the preprocessor symbol table */ DOH *args = 0; DOH *e; + int macro_additional_lines = 0; /* See if the macro expects arguments */ if (Getattr(m, kpp_args)) { /* Yep. We need to go find the arguments and do a substitution */ + int line = Getline(s); args = find_args(s, 1, id); + macro_additional_lines = Getline(s) - line; + assert(macro_additional_lines >= 0); if (!Len(args)) { Delete(args); args = 0; @@ -1090,6 +1094,9 @@ static DOH *Preprocessor_replace(DOH *s) { if (e) { Append(ns, e); } + while (macro_additional_lines--) { + Putc('\n', ns); + } Delete(e); Delete(args); } else { -- cgit v1.2.1 From efb9090a87d557b4fe244485aa0756f944a765f5 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Sat, 11 Sep 2010 11:02:18 +0000 Subject: Fix correct line number reporting in errors/warnings when a macro definition ends with '/' and it is not the end of a C comment - swig.swg has some of these macro definitions. git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12215 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- CHANGES.current | 4 ++++ Examples/test-suite/errors/expected.log | 2 ++ Examples/test-suite/errors/pp_constant.i | 7 +++++++ Examples/test-suite/java/preproc_line_file_runme.java | 4 ++++ Examples/test-suite/preproc_line_file.i | 6 ++++++ Source/Preprocessor/cpp.c | 1 - 6 files changed, 23 insertions(+), 1 deletion(-) diff --git a/CHANGES.current b/CHANGES.current index 20c0a6b0a..64770055f 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -5,6 +5,10 @@ See the RELEASENOTES file for a summary of changes in each release. Version 2.0.1 (in progress) =========================== +2010-09-11: wsfulton + Fix incorrect line number reporting in errors/warnings when a macro + definition ends with '/' and it is not the end of a C comment. + 2010-09-11: wsfulton Fix incorrect line number reporting in errors/warnings after parsing macro invocations with parameters given over more than one line. diff --git a/Examples/test-suite/errors/expected.log b/Examples/test-suite/errors/expected.log index 56e10a066..1fd592f04 100644 --- a/Examples/test-suite/errors/expected.log +++ b/Examples/test-suite/errors/expected.log @@ -78,6 +78,8 @@ pp_constant.i:23: Warning 305: Bad constant value (ignored). pp_constant.i:29: Warning 305: Bad constant value (ignored). pp_constant.i:35: Warning 305: Bad constant value (ignored). pp_constant.i:42: Warning 305: Bad constant value (ignored). +pp_constant.i:46: Warning 305: Bad constant value (ignored). +pp_constant.i:49: Warning 305: Bad constant value (ignored). :::::::::::::::::::::::::::::::: pp_defined.i ::::::::::::::::::::::::::::::::::: pp_defined.i:6: Error: No arguments given to defined() diff --git a/Examples/test-suite/errors/pp_constant.i b/Examples/test-suite/errors/pp_constant.i index 84846f1c5..2be108e83 100644 --- a/Examples/test-suite/errors/pp_constant.i +++ b/Examples/test-suite/errors/pp_constant.i @@ -41,3 +41,10 @@ comment */ %constant int fff=; +// Test macro ending in /, that is not a C comment terminator +#define G1 1234 +#define G2 1234 / +#define G3 1234 + +%constant int ggg=; + diff --git a/Examples/test-suite/java/preproc_line_file_runme.java b/Examples/test-suite/java/preproc_line_file_runme.java index 9b47ae4bd..c29cef680 100644 --- a/Examples/test-suite/java/preproc_line_file_runme.java +++ b/Examples/test-suite/java/preproc_line_file_runme.java @@ -60,5 +60,9 @@ public class preproc_line_file_runme { String inlineFile = preproc_line_file.INLINE_FILE; if (!(inlineFile.equals(FILENAME_UNIX) || inlineFile.equals(FILENAME_WINDOWS))) throw new RuntimeException("preproc failure"); + + if (Slash.LINE_NUM != 93) + throw new RuntimeException("preproc failure"); + } } diff --git a/Examples/test-suite/preproc_line_file.i b/Examples/test-suite/preproc_line_file.i index e28259e76..353aa999f 100644 --- a/Examples/test-suite/preproc_line_file.i +++ b/Examples/test-suite/preproc_line_file.i @@ -87,3 +87,9 @@ KLASS(SillyMultipleMacroStruct) #define INLINE_LINE __LINE__ %} +#define MACRO_END_WITH_SLASH ABCD/ + +%inline %{ +KLASS(Slash) +%} + diff --git a/Source/Preprocessor/cpp.c b/Source/Preprocessor/cpp.c index 23896fc50..0e8c3fb84 100644 --- a/Source/Preprocessor/cpp.c +++ b/Source/Preprocessor/cpp.c @@ -1444,7 +1444,6 @@ String *Preprocessor_parse(String *s) { else if (c == '\n') { Putc('/', value); Ungetc(c, s); - cpp_lines++; state = 50; } else { Putc('/', value); -- cgit v1.2.1 From a26d6188a701ab8d17cca306cbe869a12d22e1c7 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sat, 11 Sep 2010 11:44:08 +0000 Subject: Work around autoconf 2.60 requirement due to use of AC_PROG_SED. We currently require autoconf 2.58 only but AC_PROG_SED used by AX_PATH_GENERIC internally is only defined by autoconf 2.60. To avoid requiring a newer autoconf version just for this macro, predefine it as just "sed" for the old versions. This fixes the build with autoconf 2.58. git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12216 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- configure.in | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/configure.in b/configure.in index 1e51956d9..856d02d4a 100644 --- a/configure.in +++ b/configure.in @@ -3,7 +3,11 @@ dnl The macros which aren't shipped with the autotools are stored in the dnl Tools/config directory in .m4 files. AC_INIT([swig],[2.0.1],[http://www.swig.org]) + +dnl NB: When this requirement is increased to 2.60 or later, AC_PROG_SED +dnl definition below can be removed AC_PREREQ(2.58) + AC_CONFIG_SRCDIR([Source/Swig/swig.h]) AC_CONFIG_AUX_DIR([Tools/config]) AC_CONFIG_HEADERS([Source/Include/swigconfig.h]) @@ -50,6 +54,11 @@ AC_CHECK_FUNC(popen, AC_DEFINE(HAVE_POPEN, 1, [Define if popen is available]), A fi dnl PCRE + +dnl AX_PATH_GENERIC() relies on AC_PROG_SED() but it is defined only in +dnl autoconf 2.60 so trivially predefine it ourselves for the older versions +m4_ifdef([AC_PROG_SED],, [AC_DEFUN([AC_PROG_SED], [AC_PATH_PROG([SED], sed)])]) + AC_ARG_WITH([pcre], [AS_HELP_STRING([--without-pcre], [Disable support for regular expressions using PCRE])], -- cgit v1.2.1 From f89181d4c8eba9384f904688940c0cb65f62f7d0 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sat, 11 Sep 2010 11:44:26 +0000 Subject: Fix the rename_pcre_encoder unit test for Python. Due to a bug in the way %rename() directives without a name currently work, the second %rename in rename_pcre_encoder.i overrides the first one and the function wxDoSomething() is not renamed to DoSomething() any more. Remove the test for this renaming that doesn't work to at least let the rest of the test to pass. Also test that SetXXX() functions from the .i file really are renamed to putXXX() as expected. git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12217 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Examples/test-suite/python/rename_pcre_encoder_runme.py | 2 ++ Examples/test-suite/rename_pcre_encoder.i | 6 +++--- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/Examples/test-suite/python/rename_pcre_encoder_runme.py b/Examples/test-suite/python/rename_pcre_encoder_runme.py index f06c3d25a..ed7ca48b1 100644 --- a/Examples/test-suite/python/rename_pcre_encoder_runme.py +++ b/Examples/test-suite/python/rename_pcre_encoder_runme.py @@ -1,6 +1,8 @@ from rename_pcre_encoder import * s = SomeWidget() +s.putBorderWidth(3) +s.putSize(4, 5) a = AnotherWidget() a.DoSomething() diff --git a/Examples/test-suite/rename_pcre_encoder.i b/Examples/test-suite/rename_pcre_encoder.i index 1bee1dca8..c90af164d 100644 --- a/Examples/test-suite/rename_pcre_encoder.i +++ b/Examples/test-suite/rename_pcre_encoder.i @@ -9,12 +9,12 @@ %inline %{ struct wxSomeWidget { - void SetBorderWidth(int); - void SetSize(int, int); + void SetBorderWidth(int) {} + void SetSize(int, int) {} }; struct wxAnotherWidget { - void wxDoSomething() {} + void DoSomething() {} }; class wxEVTSomeEvent { -- cgit v1.2.1 From c0fe7400d2a4fa334558c73be3a6f1f2dd0f0bf7 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Tue, 14 Sep 2010 06:34:57 +0000 Subject: Fix undefined behaviour with Ruby and autodoc generation git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12218 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Source/Modules/ruby.cxx | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/Source/Modules/ruby.cxx b/Source/Modules/ruby.cxx index bcdfd69d3..3887d8a98 100644 --- a/Source/Modules/ruby.cxx +++ b/Source/Modules/ruby.cxx @@ -121,6 +121,7 @@ public: /* flags for the make_autodoc function */ enum autodoc_t { + AUTODOC_NOTSET, AUTODOC_CLASS, AUTODOC_CTOR, AUTODOC_DTOR, @@ -580,6 +581,9 @@ private: case AUTODOC_SETTER: Printf(doc, " Document-method: %s.%s=\n\n", full_name, symname); break; + case AUTODOC_NOTSET: + assert(0); + break; } } @@ -608,6 +612,9 @@ private: if (type) Printf(doc, " -> %s", type); break; } + case AUTODOC_NOTSET: + assert(0); + break; default: break; } @@ -665,6 +672,9 @@ private: if (type) Printf(doc, " -> %s", type); break; } + case AUTODOC_NOTSET: + assert(0); + break; } } @@ -698,6 +708,9 @@ private: case AUTODOC_SETTER: Printf(doc, "Set new value for attribute.\n"); break; + case AUTODOC_NOTSET: + assert(0); + break; } } @@ -762,6 +775,7 @@ public: modvar = 0; feature = 0; prefix = 0; + last_mode = AUTODOC_NOTSET, last_autodoc = NewString(""); current = NO_CPP; classes = 0; -- cgit v1.2.1 From cfcad4ab696deb4af525a7f8a8ee9a97d8d9af1b Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Tue, 14 Sep 2010 18:50:04 +0000 Subject: Fix/Workaround unexpected call to Hash_str() when running make director_protected_overloaded.cpptest and director_using.cpptest git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12219 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Source/Swig/tree.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Source/Swig/tree.c b/Source/Swig/tree.c index c76ac958e..e66670c7c 100644 --- a/Source/Swig/tree.c +++ b/Source/Swig/tree.c @@ -291,10 +291,10 @@ void Swig_require(const char *ns, Node *n, ...) { if (view) { if (Strcmp(view, ns) != 0) { Setattr(n, NewStringf("%s:view", ns), view); - Setattr(n, "view", ns); + Setattr(n, "view", NewString(ns)); } } else { - Setattr(n, "view", ns); + Setattr(n, "view", NewString(ns)); } } } @@ -337,10 +337,10 @@ void Swig_save(const char *ns, Node *n, ...) { if (view) { if (Strcmp(view, ns) != 0) { Setattr(n, NewStringf("%s:view", ns), view); - Setattr(n, "view", ns); + Setattr(n, "view", NewString(ns)); } } else { - Setattr(n, "view", ns); + Setattr(n, "view", NewString(ns)); } } } -- cgit v1.2.1 From a202bf98183f8ef66d83d3c75e22078bcfdc4922 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Tue, 14 Sep 2010 18:52:18 +0000 Subject: Fix undefined behaviour git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12220 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Source/Modules/ruby.cxx | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/Source/Modules/ruby.cxx b/Source/Modules/ruby.cxx index 3887d8a98..bcdfd69d3 100644 --- a/Source/Modules/ruby.cxx +++ b/Source/Modules/ruby.cxx @@ -121,7 +121,6 @@ public: /* flags for the make_autodoc function */ enum autodoc_t { - AUTODOC_NOTSET, AUTODOC_CLASS, AUTODOC_CTOR, AUTODOC_DTOR, @@ -581,9 +580,6 @@ private: case AUTODOC_SETTER: Printf(doc, " Document-method: %s.%s=\n\n", full_name, symname); break; - case AUTODOC_NOTSET: - assert(0); - break; } } @@ -612,9 +608,6 @@ private: if (type) Printf(doc, " -> %s", type); break; } - case AUTODOC_NOTSET: - assert(0); - break; default: break; } @@ -672,9 +665,6 @@ private: if (type) Printf(doc, " -> %s", type); break; } - case AUTODOC_NOTSET: - assert(0); - break; } } @@ -708,9 +698,6 @@ private: case AUTODOC_SETTER: Printf(doc, "Set new value for attribute.\n"); break; - case AUTODOC_NOTSET: - assert(0); - break; } } @@ -775,7 +762,6 @@ public: modvar = 0; feature = 0; prefix = 0; - last_mode = AUTODOC_NOTSET, last_autodoc = NewString(""); current = NO_CPP; classes = 0; -- cgit v1.2.1 From d1e66431613ad092aa91770f52a2a2e5dede5a23 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Wed, 15 Sep 2010 20:17:11 +0000 Subject: Expand the family of debug print functions for displaying DOH types. Provide gdb support for calling these. Document improved debugging experience. git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12221 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- CHANGES.current | 5 ++ Doc/Devel/internals.html | 164 ++++++++++++++++++++++++++++++++++++++++------- Doc/Devel/tree.html | 35 +++++++--- Source/DOH/doh.h | 4 ++ Source/DOH/hash.c | 53 ++++++++++++--- Source/DOH/list.c | 2 +- Source/Modules/lang.cxx | 2 +- Source/Modules/swigmod.h | 9 ++- Source/Modules/utils.cxx | 113 ++++++++++++++++++++++++++++++++ Source/Swig/error.c | 35 ++++++++++ Source/Swig/misc.c | 1 - Source/Swig/swig.h | 4 +- Tools/swig.gdb | 41 ++++++++++++ 13 files changed, 421 insertions(+), 47 deletions(-) create mode 100644 Tools/swig.gdb diff --git a/CHANGES.current b/CHANGES.current index 64770055f..ff5b40fb6 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -5,6 +5,11 @@ See the RELEASENOTES file for a summary of changes in each release. Version 2.0.1 (in progress) =========================== +2010-09-15: wsfulton + A much improved debugging of SWIG source experience is now available and + documented in the "Debugging SWIG" section in the Doc/Devel/internals.html + file, including a swig.dbg support file for the gdb debugger. + 2010-09-11: wsfulton Fix incorrect line number reporting in errors/warnings when a macro definition ends with '/' and it is not the end of a C comment. diff --git a/Doc/Devel/internals.html b/Doc/Devel/internals.html index 6ac3947f7..d24869d10 100644 --- a/Doc/Devel/internals.html +++ b/Doc/Devel/internals.html @@ -7,11 +7,6 @@

    SWIG Internals Manual

    -Thien-Thi Nguyen
    - -

    -David M. Beazley
    -

    @@ -45,6 +40,9 @@ David M. Beazley
  • 5. C/C++ Wrapper Support Functions
  • 6. Symbol Naming Guidelines for Generated C/C++ Code
  • 7. Debugging SWIG + @@ -1015,15 +1013,139 @@ In the past SWIG has generated many symbols which flout the standard especially

    7. Debugging SWIG

    -Warning. Debugging SWIG is for the very patient. + +

    +The DOH types used in the SWIG source code are all typedefined to void. +Consequently, it is impossible for debuggers to automatically extract any information about DOH objects. +The easiest approach to debugging and viewing the contents of DOH objects is to make a call into one of the family of SWIG print functions from the debugger. +The "Debugging Functions" section in SWIG Parse Tree Handling lists them. +It is sometimes easier to debug by placing a few calls to these functions in code of interest and recompile, especially if your debugger cannot easily make calls into functions within a debugged binary. +

    + +

    +The SWIG distribution comes with some additional support for the gdb debugger in the Tools/swig.gdb file. +Follow the instructions in this file for 'installing'. +This support file provides an easy way to call into some of the family of SWIG print functions via additional user-defined gdb commands. +Some usage of the swigprint and locswigprint user-defined commands are demonstrated below. +

    + +

    +More often than not, a parse tree node needs to be examined. +The session below displays the node n in one of the Java language module wrapper functions. +The swigprint method is used to show the symbol name (symname - a DOH String type) and the node (n - a DOH Hash type). +

    +
    +
    +Breakpoint 1, JAVA::functionWrapper (this=0x97ea5f0, n=0xb7d2afc8) at Modules/java.cxx:799
    +799	    String *symname = Getattr(n, "sym:name");
    +(gdb) next
    +800	    SwigType *t = Getattr(n, "type");
    +(gdb) swigprint symname
    +Shape_x_set
    +(gdb) swigprint n
    +Hash(0xb7d2afc8) {
    +  'membervariableHandler:view' : variableHandler, 
    +  'feature:except' : 0, 
    +  'name' : x, 
    +  'ismember' : 1, 
    +  'sym:symtab' : Hash(0xb7d2aca8) {......}, 
    +  'nodeType' : cdecl, 
    +  'nextSibling' : Hash(0xb7d2af98) {.............}, 
    +  'kind' : variable, 
    +  'variableHandler:feature:immutable' : <Object 'VoidObj' at 0xb7cfa008>, 
    +  'sym:name' : Shape_x_set, 
    +  'view' : membervariableHandler, 
    +  'membervariableHandler:sym:name' : x, 
    +  'membervariableHandler:type' : double, 
    +  'membervariableHandler:parms' : <Object 'VoidObj' at 0xb7cfa008>, 
    +  'parentNode' : Hash(0xb7d2abc8) {..............................}, 
    +  'feature:java:enum' : typesafe, 
    +  'access' : public, 
    +  'parms' : Hash(0xb7cb9408) {......}, 
    +  'wrap:action' : if (arg1) (arg1)->x = arg2;, 
    +  'type' : void, 
    +  'memberset' : 1, 
    +  'sym:overname' : __SWIG_0, 
    +  'membervariableHandler:name' : x, 
    +}
    +
    +
    +

    +Note that all the attributes in the Hash are shown, including the 'sym:name' attribute which was assigned to the symname variable. +

    -The DOH types are all typedefined to void. -Consequently, it is impossible for debuggers to extract any information about DOH objects. -Most debuggers will be able to display useful variable information when an object is cast to the appropriate type. -Below are some tips for displaying some of the DOH objects. -Be sure to compile with compiler optimisations turned off before attempting the casts shown in a debugger window else they are unlikely to work. -Even displaying the underlying string in a String* doesn't work straight off in all debuggers due to the multiple definition of String as a struct and a void. +

    +Hash types can be shown either expanded or collapsed. +When a Hash is shown expanded, all the attributes are displayed along with their values, otherwise a '.' replaces each attribute when collapsed. +Therefore a count of the dots provides the number of attributes within an unexpanded Hash. +Below shows the 'parms' Hash being displayed with the default Hash expansion of 1, then with 2 provided as the second argument to swigprint to expand to two Hash levels in order to view the contents of the collapsed 'nextSibling' Hash. +

    + +
    +
    +(gdb) swigprint 0xb7cb9408
    +Hash(0xb7cb9408) {
    +  'name' : self, 
    +  'type' : p.Shape, 
    +  'self' : 1, 
    +  'nextSibling' : Hash(0xb7cb9498) {...}, 
    +  'hidden' : 1, 
    +  'nodeType' : parm, 
    +}
    +(gdb) swigprint 0xb7cb9408 2
    +Hash(0xb7cb9408) {
    +  'name' : self, 
    +  'type' : p.Shape, 
    +  'self' : 1, 
    +  'nextSibling' : Hash(0xb7cb9498) {
    +    'name' : x, 
    +    'type' : double, 
    +    'nodeType' : parm, 
    +  }, 
    +  'hidden' : 1, 
    +  'nodeType' : parm, 
    +}
    +
    +
    + +

    +The same Hash can also be displayed with file and line location information via the locswigprint command. +

    + +
    +
    +(gdb) locswigprint 0xb7cb9408
    +example.h:11: [Hash(0xb7cb9408) {
    +Hash(0xb7cb9408) {
    +  'name' : self, 
    +  'type' : p.Shape, 
    +  'self' : 1, 
    +  'nextSibling' : Hash(0xb7cb9498) {...}, 
    +  'hidden' : 1, 
    +  'nodeType' : parm, 
    +}]
    +
    +
    + +

    +Tip: Commands in gdb can be shortened with whatever makes them unique and can be command completed with the tab key. +Thus swigprint can usually be shortened to sw and locswigprint to loc. +The help for each command can also be obtained within the debugging session, for example, 'help swigprint'. +

    + +

    +The sub-section below gives pointers for debugging DOH objects using casts and provides an insight into why it can be hard to debug SWIG without the family of print functions. +

    + + +

    7.1 Debugging DOH Types The Hard Way

    + +The DOH types used in SWIG are all typedefined to void and hence the lack of type information for inspecting types within a debugger. +Most debuggers will however be able to display useful variable information when an object is cast to the appropriate type. +Getting at the underlying C string within DOH types is cumbersome, but possible with appropriate casts. +The casts below can be used in a debugger windows, but be sure to compile with compiler optimisations turned off before attempting the casts else they are unlikely to work. +Even displaying the underlying string in a String * doesn't work straight off in all debuggers due to the multiple definitions of String as a struct and a void.

    Below are a list of common SWIG types. @@ -1033,36 +1155,30 @@ With each is the cast that can be used in the debugger to extract the underlying

  • String *s;
  • -
    -(struct String *)((DohBase *)s)->data +(struct String *)((DohBase *)s)->data
    The underlying char * string can be displayed with
    -(*(struct String *)(((DohBase *)s)->data)).str +(*(struct String *)(((DohBase *)s)->data)).str

  • SwigType *t;
  • -
    -(struct String *)((DohBase *)t)->data +(struct String *)((DohBase *)t)->data
    The underlying char * string can be displayed with
    -(*(struct String *)(((DohBase *)t)->data)).str +(*(struct String *)(((DohBase *)t)->data)).str

  • const_String_or_char_ptr sc;
  • Either
    -(*(struct String *)(((DohBase *)sc)->data)).str +(*(struct String *)(((DohBase *)sc)->data)).str
    or
    -(char *)sc +(char *)sc
    will work depending on whether the underlying type is really a String * or char *. -

    -Please also read the Debugging Functions section in SWIG Parse Tree Handling for the Swig_print_node(), Swig_print_tree() and Swig_print_tags() functions for displaying node contents. It is often easier to place a few calls to these functions in code of interest and recompile than use the debugger. -

    -
    Copyright (C) 1999-2010 SWIG Development Team. diff --git a/Doc/Devel/tree.html b/Doc/Devel/tree.html index 43ad191f6..db3c6fee4 100644 --- a/Doc/Devel/tree.html +++ b/Doc/Devel/tree.html @@ -6,13 +6,6 @@

    SWIG Parse Tree Handling

    - -

    -David M. Beazley
    -dave-swig@dabeaz.com
    -December, 2006
    - -

    Introduction

    @@ -210,7 +203,33 @@ This function restores a node to the state it was in prior to the last Swig_

    Debugging Functions

    -The following functions are used to help debug SWIG parse trees. +

    +The following functions can be used to help debug any SWIG DOH object. +

    + +void Swig_print(DOH *object, int count = -1) + +
    +Prints to stdout a string representation of any DOH type. +The number of nested Hash types to expand is set by count (default is 1 if count<0). See Swig_set_max_hash_expand() to change default. +
    +
    +
    + +void Swig_print_with_location(DOH *object, int count = -1) + +
    +Prints to stdout a string representation of any DOH type, within [] brackets +for Hash and List types, prefixed by line and file information. +The number of nested Hash types to expand is set by count (default is 1 if count<0). See Swig_set_max_hash_expand() to change default. +
    +
    +
    + + +

    +The following functions can be used to help debug SWIG parse trees. +

    void Swig_print_tags(Node *node, String_or_char *prefix) diff --git a/Source/DOH/doh.h b/Source/DOH/doh.h index e46d103de..6fa352547 100644 --- a/Source/DOH/doh.h +++ b/Source/DOH/doh.h @@ -267,6 +267,8 @@ extern int DohIsSequence(const DOH *obj); extern int DohIsString(const DOH *obj); extern int DohIsFile(const DOH *obj); +extern void DohSetMaxHashExpand(int count); +extern int DohGetMaxHashExpand(void); extern void DohSetmark(DOH *obj, int x); extern int DohGetmark(DOH *obj); @@ -424,6 +426,8 @@ extern void DohMemoryDebug(void); #define SplitLines DohSplitLines #define Setmark DohSetmark #define Getmark DohGetmark +#define SetMaxHashExpand DohSetMaxHashExpand +#define GetMaxHashExpand DohGetMaxHashExpand #define None DohNone #define Call DohCall #define First DohFirst diff --git a/Source/DOH/hash.c b/Source/DOH/hash.c index 87f8e3c40..48afd2e54 100644 --- a/Source/DOH/hash.c +++ b/Source/DOH/hash.c @@ -42,6 +42,7 @@ typedef struct KeyValue { } KeyValue; static KeyValue *root = 0; +static int max_expand = 1; /* Find or create a key in the interned key table */ static DOH *find_key(DOH *doh_c) { @@ -378,6 +379,26 @@ static DOH *Hash_keys(DOH *so) { return keys; } +/* ----------------------------------------------------------------------------- + * DohSetMaxHashExpand() + * + * Controls how many Hash objects are displayed in full in Hash_str + * ----------------------------------------------------------------------------- */ + +void DohSetMaxHashExpand(int count) { + max_expand = count; +} + +/* ----------------------------------------------------------------------------- + * DohGetMaxHashExpand() + * + * Returns how many Hash objects are displayed in full in Hash_str + * ----------------------------------------------------------------------------- */ + +int DohGetMaxHashExpand(void) { + return max_expand; +} + /* ----------------------------------------------------------------------------- * Hash_str() * @@ -388,7 +409,8 @@ static DOH *Hash_str(DOH *ho) { int i, j; HashNode *n; DOH *s; - static int indent = 4; + static int expanded = 0; + static const char *tab = " "; Hash *h = (Hash *) ObjData(ho); s = NewStringEmpty(); @@ -396,22 +418,35 @@ static DOH *Hash_str(DOH *ho) { Printf(s, "Hash(0x%x)", ho); return s; } + if (expanded >= max_expand) { + /* replace each hash attribute with a '.' */ + Printf(s, "Hash(0x%x) {", ho); + for (i = 0; i < h->hashsize; i++) { + n = h->hashtable[i]; + while (n) { + Putc('.', s); + n = n->next; + } + } + Putc('}', s); + return s; + } ObjSetMark(ho, 1); - Printf(s, "Hash {\n"); + Printf(s, "Hash(0x%x) {\n", ho); for (i = 0; i < h->hashsize; i++) { n = h->hashtable[i]; while (n) { - for (j = 0; j < indent; j++) - Putc(' ', s); - indent += 4; + for (j = 0; j < expanded + 1; j++) + Printf(s, tab); + expanded += 1; Printf(s, "'%s' : %s, \n", n->key, n->object); - indent -= 4; + expanded -= 1; n = n->next; } } - for (j = 0; j < (indent - 4); j++) - Putc(' ', s); - Printf(s, "}\n"); + for (j = 0; j < expanded; j++) + Printf(s, tab); + Printf(s, "}"); ObjSetMark(ho, 0); return s; } diff --git a/Source/DOH/list.c b/Source/DOH/list.c index a08cadb5a..d5b532409 100644 --- a/Source/DOH/list.c +++ b/Source/DOH/list.c @@ -252,7 +252,7 @@ static DOH *List_str(DOH *lo) { if ((i + 1) < l->nitems) Printf(s, ", "); } - Printf(s, " ]\n"); + Printf(s, " ]"); ObjSetMark(lo, 0); return s; } diff --git a/Source/Modules/lang.cxx b/Source/Modules/lang.cxx index e28fcbb89..6ec0463fa 100644 --- a/Source/Modules/lang.cxx +++ b/Source/Modules/lang.cxx @@ -52,7 +52,7 @@ extern "C" { return all_protected_mode; } void Language_replace_special_variables(String *method, String *tm, Parm *parm) { - Language::instance()->replaceSpecialVariables(method, tm, parm); + Language::instance()->replaceSpecialVariables(method, tm, parm); } } diff --git a/Source/Modules/swigmod.h b/Source/Modules/swigmod.h index b0b488d6f..d3074105f 100644 --- a/Source/Modules/swigmod.h +++ b/Source/Modules/swigmod.h @@ -380,9 +380,15 @@ void Wrapper_fast_dispatch_mode_set(int); void Wrapper_cast_dispatch_mode_set(int); void Wrapper_naturalvar_mode_set(int); - void clean_overloaded(Node *n); +extern "C" { + const char *Swig_to_string(DOH *object, int count = -1); + const char *Swig_to_string_with_location(DOH *object, int count = -1); + void Swig_print(DOH *object, int count = -1); + void Swig_print_with_location(DOH *object, int count = -1); +} + /* Contracts */ void Swig_contracts(Node *n); @@ -395,5 +401,4 @@ void Swig_browser(Node *n, int); void Swig_default_allocators(Node *n); void Swig_process_types(Node *n); - #endif diff --git a/Source/Modules/utils.cxx b/Source/Modules/utils.cxx index 3fe7a2709..13a504bcf 100644 --- a/Source/Modules/utils.cxx +++ b/Source/Modules/utils.cxx @@ -100,3 +100,116 @@ void clean_overloaded(Node *n) { Delattr(n, "sym:overloaded"); } } + +/* ----------------------------------------------------------------------------- + * Swig_set_max_hash_expand() + * + * Controls how many Hash objects are displayed when displaying nested Hash objects. + * Makes DohSetMaxHashExpand an externally callable function (for debugger). + * ----------------------------------------------------------------------------- */ + +void Swig_set_max_hash_expand(int count) { + SetMaxHashExpand(count); +} + +extern "C" { + +/* ----------------------------------------------------------------------------- + * Swig_get_max_hash_expand() + * + * Returns how many Hash objects are displayed when displaying nested Hash objects. + * Makes DohGetMaxHashExpand an externally callable function (for debugger). + * ----------------------------------------------------------------------------- */ + +int Swig_get_max_hash_expand() { + return GetMaxHashExpand(); +} + +/* ----------------------------------------------------------------------------- + * Swig_to_doh_string() + * + * DOH version of Swig_to_string() + * ----------------------------------------------------------------------------- */ + +static String *Swig_to_doh_string(DOH *object, int count) { + int old_count = Swig_get_max_hash_expand(); + if (count >= 0) + Swig_set_max_hash_expand(count); + + String *debug_string = object ? NewStringf("%s", object) : NewString("NULL"); + + Swig_set_max_hash_expand(old_count); + return debug_string; +} + +/* ----------------------------------------------------------------------------- + * Swig_to_doh_string_with_location() + * + * DOH version of Swig_to_string_with_location() + * ----------------------------------------------------------------------------- */ + +static String *Swig_to_doh_string_with_location(DOH *object, int count) { + int old_count = Swig_get_max_hash_expand(); + if (count >= 0) + Swig_set_max_hash_expand(count); + + String *debug_string = Swig_stringify_with_location(object); + + Swig_set_max_hash_expand(old_count); + return debug_string; +} + +/* ----------------------------------------------------------------------------- + * Swig_to_string() + * + * Swig debug - return C string representation of any DOH type. + * Nested Hash types expand count is value of Swig_get_max_hash_expand when count<0 + * Note: leaks memory. + * ----------------------------------------------------------------------------- */ + +const char *Swig_to_string(DOH *object, int count) { + return Char(Swig_to_doh_string(object, count)); +} + +/* ----------------------------------------------------------------------------- + * Swig_to_string_with_location() + * + * Swig debug - return C string representation of any DOH type, within [] brackets + * for Hash and List types, prefixed by line and file information. + * Nested Hash types expand count is value of Swig_get_max_hash_expand when count<0 + * Note: leaks memory. + * ----------------------------------------------------------------------------- */ + +const char *Swig_to_string_with_location(DOH *object, int count) { + return Char(Swig_to_doh_string_with_location(object, count)); +} + +/* ----------------------------------------------------------------------------- + * Swig_print() + * + * Swig debug - display string representation of any DOH type. + * Nested Hash types expand count is value of Swig_get_max_hash_expand when count<0 + * ----------------------------------------------------------------------------- */ + +void Swig_print(DOH *object, int count) { + String *output = Swig_to_doh_string(object, count); + Printf(stdout, "%s\n", output); + Delete(output); +} + +/* ----------------------------------------------------------------------------- + * Swig_to_string_with_location() + * + * Swig debug - display string representation of any DOH type, within [] brackets + * for Hash and List types, prefixed by line and file information. + * Nested Hash types expand count is value of Swig_get_max_hash_expand when count<0 + * ----------------------------------------------------------------------------- */ + +void Swig_print_with_location(DOH *object, int count) { + String *output = Swig_to_doh_string_with_location(object, count); + Printf(stdout, "%s\n", output); + Delete(output); +} + +} // extern "C" + diff --git a/Source/Swig/error.c b/Source/Swig/error.c index fa82ad8d9..5dfcf605b 100644 --- a/Source/Swig/error.c +++ b/Source/Swig/error.c @@ -284,6 +284,41 @@ static String *format_filename(const_String_or_char_ptr filename) { return formatted_filename; } +/* ----------------------------------------------------------------------------- + * Swig_stringify_with_location() + * + * Return a string representation of any DOH object with line and file location + * information in the appropriate error message format. The string representation + * is enclosed within [] brackets after the line and file information. + * ----------------------------------------------------------------------------- */ + +String *Swig_stringify_with_location(DOH *object) { + String *str = NewStringEmpty(); + + if (!init_fmt) + Swig_error_msg_format(DEFAULT_ERROR_MSG_FORMAT); + + if (object) { + int line = Getline(object); + String *formatted_filename = format_filename(Getfile(object)); + if (line > 0) { + Printf(str, diag_line_fmt, formatted_filename, line); + } else { + Printf(str, diag_eof_fmt, formatted_filename); + } + if (Len(object) == 0) { + Printf(str, "[EMPTY]"); + } else { + Printf(str, "[%s]", object); + } + Delete(formatted_filename); + } else { + Printf(str, "[NULL]"); + } + + return str; +} + /* ----------------------------------------------------------------------------- * Swig_diagnostic() * diff --git a/Source/Swig/misc.c b/Source/Swig/misc.c index 2105f0c51..a57c7cf33 100644 --- a/Source/Swig/misc.c +++ b/Source/Swig/misc.c @@ -527,7 +527,6 @@ String *Swig_string_schemify(String *s) { return ns; } - /* ----------------------------------------------------------------------------- * Swig_string_typecode() * diff --git a/Source/Swig/swig.h b/Source/Swig/swig.h index f90a5ffb1..021c5611f 100644 --- a/Source/Swig/swig.h +++ b/Source/Swig/swig.h @@ -319,7 +319,6 @@ extern int ParmList_is_compactdefargs(ParmList *p); extern String *Swig_string_lower(String *s); extern String *Swig_string_upper(String *s); extern String *Swig_string_title(String *s); - extern void Swig_init(void); extern int Swig_value_wrapper_mode(int mode); @@ -334,6 +333,7 @@ extern int ParmList_is_compactdefargs(ParmList *p); extern int Swig_warn_count(void); extern void Swig_error_msg_format(ErrorMessageFormat format); extern void Swig_diagnostic(const_String_or_char_ptr filename, int line, const char *fmt, ...); + extern String *Swig_stringify_with_location(DOH *object); /* --- C Wrappers --- */ extern String *Swig_cparm_name(Parm *p, int i); @@ -408,6 +408,8 @@ extern int ParmList_is_compactdefargs(ParmList *p); extern void Wrapper_director_protected_mode_set(int); extern void Wrapper_all_protected_mode_set(int); extern void Language_replace_special_variables(String *method, String *tm, Parm *parm); + extern void Swig_print(DOH *object, int count); + extern void Swig_print_with_location(DOH *object, int count); /* -- template init -- */ diff --git a/Tools/swig.gdb b/Tools/swig.gdb new file mode 100644 index 000000000..195032955 --- /dev/null +++ b/Tools/swig.gdb @@ -0,0 +1,41 @@ +# User-defined commands for easier debugging of SWIG in gdb +# +# This file can be "included" into your main .gdbinit file using: +# source swig.gdb +# or otherwise paste the contents into .gdbinit +# +# Note all user defined commands can be seen using: +# (gdb) show user +# The documentation for each command can be easily viewed, for example: +# (gdb) help swigprint + +define swigprint + if ($argc == 2) + set $expand_count = $arg1 + else + set $expand_count = -1 + end + call Swig_print($arg0, $expand_count) +end +document swigprint +Displays any SWIG DOH object +Usage: swigprint swigobject [hashexpandcount] + swigobject - The object to display. + hashexpandcount - Number of nested Hash types to expand (default is 1). See Swig_set_max_hash_expand() to change default. +end + + +define locswigprint + if ($argc == 2) + set $expand_count = $arg1 + else + set $expand_count = -1 + end + call Swig_print_with_location($arg0, $expand_count) +end +document locswigprint +Displays any SWIG DOH object prefixed with file and line location +Usage: locswigprint swigobject [hashexpandcount] + swigobject - The object to display. + hashexpandcount - Number of nested Hash types to expand (default is 1). See Swig_set_max_hash_expand() to change default. +end -- cgit v1.2.1 From 8b31a92f6168b1bb1e17ca64aebbe6e29c5fc24a Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Wed, 15 Sep 2010 22:26:34 +0000 Subject: Add missing typemap debug options to docs git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12222 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Doc/Manual/Extending.html | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Doc/Manual/Extending.html b/Doc/Manual/Extending.html index c554d9f05..072f28963 100644 --- a/Doc/Manual/Extending.html +++ b/Doc/Manual/Extending.html @@ -3609,6 +3609,8 @@ There are various command line options which can aid debugging a SWIG interface -debug-top <n> - Display entire parse tree at stages 1-4, <n> is a csv list of stages -debug-typedef - Display information about the types and typedefs in the interface -debug-typemap - Display information for debugging typemaps +-debug-tmsearch - Display typemap search debugging information +-debug-tmused - Display typemaps used debugging information

    -- cgit v1.2.1 From b01277a19be53421d66f800c942e5b8663100a46 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Sat, 18 Sep 2010 01:14:21 +0000 Subject: Various inherited class warning/error line number fixes git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12223 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- CHANGES.current | 4 +++ Examples/test-suite/errors/cpp_inherit.i | 47 ++++++++++++++++++++++++++++++++ Examples/test-suite/errors/expected.log | 24 ++++++++++++++-- Examples/test-suite/errors/make.sh | 1 + Source/CParse/cscanner.c | 6 ++-- Source/CParse/parser.y | 40 ++++++++++++++++----------- Source/Modules/typepass.cxx | 17 ++++++------ 7 files changed, 108 insertions(+), 31 deletions(-) create mode 100644 Examples/test-suite/errors/cpp_inherit.i diff --git a/CHANGES.current b/CHANGES.current index ff5b40fb6..d98b99f1a 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -5,6 +5,10 @@ See the RELEASENOTES file for a summary of changes in each release. Version 2.0.1 (in progress) =========================== +2010-09-18: wsfulton + More file and line error/warning reporting fixes for various inherited + class problems. + 2010-09-15: wsfulton A much improved debugging of SWIG source experience is now available and documented in the "Debugging SWIG" section in the Doc/Devel/internals.html diff --git a/Examples/test-suite/errors/cpp_inherit.i b/Examples/test-suite/errors/cpp_inherit.i new file mode 100644 index 000000000..fdc77d1d5 --- /dev/null +++ b/Examples/test-suite/errors/cpp_inherit.i @@ -0,0 +1,47 @@ +%module xxx + +%inline %{ +struct A5; +int A6; +template struct A7 +{ +}; +template struct A8 +{ +}; + +struct A0 +: + public A1 + , + A2, + private A3 + , + private A4 + , + A5 + , + A6 + , + A7 + , + protected A8 +{ +}; + +struct A1 +{ +}; + +class B1 {}; + +class B0 : + B1, + B2 +{ +}; + +struct Recursive : Recursive +{ +}; +%} diff --git a/Examples/test-suite/errors/expected.log b/Examples/test-suite/errors/expected.log index 1fd592f04..7cbce4c30 100644 --- a/Examples/test-suite/errors/expected.log +++ b/Examples/test-suite/errors/expected.log @@ -207,6 +207,24 @@ cpp_extend_undefined.i:6: Warning 303: %extend defined for an undeclared class f :::::::::::::::::::::::::::::::: cpp_inline_namespace.i ::::::::::::::::::::::::::::::::::: cpp_inline_namespace.i:4: Error: %inline directive inside a namespace is disallowed. +:::::::::::::::::::::::::::::::: cpp_inherit.i ::::::::::::::::::::::::::::::::::: +cpp_inherit.i:18: Warning 309: private inheritance from base 'A3' (ignored). +cpp_inherit.i:20: Warning 309: private inheritance from base 'A4' (ignored). +cpp_inherit.i:28: Warning 309: protected inheritance from base 'A8< double >' (ignored). +cpp_inherit.i:39: Warning 319: No access specifier given for base class 'B1' (ignored). +cpp_inherit.i:40: Warning 319: No access specifier given for base class 'B2< int >' (ignored). +cpp_inherit.i:15: Warning 401: Base class 'A1' undefined. +cpp_inherit.i:33: Warning 401: 'A1' must be defined before it is used as a base class. +cpp_inherit.i:17: Warning 401: Nothing known about base class 'A2'. Ignored. +cpp_inherit.i:22: Warning 402: Base class 'A5' is incomplete. +cpp_inherit.i:4: Warning 402: Only forward declaration 'A5' was found. +cpp_inherit.i:24: Error: 'A6' is not a valid base class. +cpp_inherit.i:5: Error: See definition of 'A6'. +cpp_inherit.i:24: Warning 401: Nothing known about base class 'A6'. Ignored. +cpp_inherit.i:26: Warning 401: Nothing known about base class 'A7< int >'. Ignored. +cpp_inherit.i:26: Warning 401: Maybe you forgot to instantiate 'A7< int >' using %template. +cpp_inherit.i:45: Warning 323: Recursive scope inheritance of 'Recursive'. + :::::::::::::::::::::::::::::::: cpp_missing_rtemplate.i ::::::::::::::::::::::::::::::::::: cpp_missing_rtemplate.i:4: Error: Syntax error in input(1). @@ -224,7 +242,7 @@ cpp_nested.i:6: Warning 325: Nested class not currently supported (Bar ignored) cpp_nested.i:12: Warning 325: Nested class not currently supported (Grok ignored) :::::::::::::::::::::::::::::::: cpp_no_access.i ::::::::::::::::::::::::::::::::::: -cpp_no_access.i:3: Warning 319: No access specifier given for base class foo (ignored). +cpp_no_access.i:3: Warning 319: No access specifier given for base class 'foo' (ignored). :::::::::::::::::::::::::::::::: cpp_nobase.i ::::::::::::::::::::::::::::::::::: cpp_nobase.i:3: Warning 401: Nothing known about base class 'Bar'. Ignored. @@ -236,8 +254,8 @@ cpp_nobase.i:6: Warning 401: Maybe you forgot to instantiate 'Bar< int >' using :::::::::::::::::::::::::::::::: cpp_private_defvalue.i ::::::::::::::::::::::::::::::::::: :::::::::::::::::::::::::::::::: cpp_private_inherit.i ::::::::::::::::::::::::::::::::::: -cpp_private_inherit.i:6: Warning 309: private inheritance ignored. -cpp_private_inherit.i:9: Warning 309: protected inheritance ignored. +cpp_private_inherit.i:6: Warning 309: private inheritance from base 'Foo' (ignored). +cpp_private_inherit.i:9: Warning 309: protected inheritance from base 'Foo' (ignored). :::::::::::::::::::::::::::::::: cpp_template_argname.i ::::::::::::::::::::::::::::::::::: diff --git a/Examples/test-suite/errors/make.sh b/Examples/test-suite/errors/make.sh index 0fb3e14a4..0a81254f4 100755 --- a/Examples/test-suite/errors/make.sh +++ b/Examples/test-suite/errors/make.sh @@ -64,6 +64,7 @@ cpp_bad_extern cpp_extend_redefine cpp_extend_undefined cpp_inline_namespace +cpp_inherit cpp_missing_rtemplate cpp_namespace_alias cpp_namespace_aliasnot diff --git a/Source/CParse/cscanner.c b/Source/CParse/cscanner.c index f88841c09..7d848878c 100644 --- a/Source/CParse/cscanner.c +++ b/Source/CParse/cscanner.c @@ -791,7 +791,7 @@ int yylex(void) { if (strcmp(yytext, "typename") == 0) return (TYPENAME); if (strcmp(yytext, "template") == 0) { - yylval.ivalue = cparse_line; + yylval.intvalue = cparse_line; return (TEMPLATE); } if (strcmp(yytext, "delete") == 0) { @@ -833,7 +833,7 @@ int yylex(void) { return (SIZEOF); if (strcmp(yytext, "typedef") == 0) { - yylval.ivalue = 0; + yylval.intvalue = 0; return (TYPEDEF); } @@ -875,7 +875,7 @@ int yylex(void) { if (strcmp(yytext, "%constant") == 0) return (CONSTANT); if (strcmp(yytext, "%typedef") == 0) { - yylval.ivalue = 1; + yylval.intvalue = 1; return (TYPEDEF); } if (strcmp(yytext, "%native") == 0) diff --git a/Source/CParse/parser.y b/Source/CParse/parser.y index 09ed9bcf2..d792021c6 100644 --- a/Source/CParse/parser.y +++ b/Source/CParse/parser.y @@ -1628,7 +1628,7 @@ static void tag_nodes(Node *n, const_String_or_char_ptr attrname, DOH *value) { String *str; Parm *p; ParmList *pl; - int ivalue; + int intvalue; Node *node; }; @@ -1639,7 +1639,7 @@ static void tag_nodes(Node *n, const_String_or_char_ptr attrname, DOH *value) { %token INCLUDE IMPORT INSERT %token CHARCONST %token NUM_INT NUM_FLOAT NUM_UNSIGNED NUM_LONG NUM_ULONG NUM_LONGLONG NUM_ULONGLONG NUM_BOOL -%token TYPEDEF +%token TYPEDEF %token TYPE_INT TYPE_UNSIGNED TYPE_SHORT TYPE_LONG TYPE_FLOAT TYPE_DOUBLE TYPE_CHAR TYPE_WCHAR TYPE_VOID TYPE_SIGNED TYPE_BOOL TYPE_COMPLEX TYPE_TYPEDEF TYPE_RAW TYPE_NON_ISO_INT8 TYPE_NON_ISO_INT16 TYPE_NON_ISO_INT32 TYPE_NON_ISO_INT64 %token LPAREN RPAREN COMMA SEMI EXTERN INIT LBRACE RBRACE PERIOD %token CONST_QUAL VOLATILE REGISTER STRUCT UNION EQUAL SIZEOF MODULE LBRACKET RBRACKET @@ -1657,7 +1657,7 @@ static void tag_nodes(Node *n, const_String_or_char_ptr attrname, DOH *value) { %token QUESTIONMARK %token TYPES PARMS %token NONID DSTAR DCNOT -%token TEMPLATE +%token TEMPLATE %token OPERATOR %token COPERATOR %token PARSETYPE PARSEPARM PARSEPARMS @@ -1728,7 +1728,7 @@ static void tag_nodes(Node *n, const_String_or_char_ptr attrname, DOH *value) { %type string stringnum ; %type template_parms; %type cpp_end cpp_vend; -%type rename_namewarn; +%type rename_namewarn; %type type_specifier primitive_type_list ; %type fname stringtype; %type featattr; @@ -4540,7 +4540,8 @@ cpp_protection_decl : PUBLIC COLON { ------------------------------------------------------------ */ cpp_nested : storage_class cpptype idcolon inherit LBRACE { - cparse_start_line = cparse_line; skip_balanced('{','}'); + cparse_start_line = cparse_line; + skip_balanced('{','}'); $$ = NewString(scanner_ccode); /* copied as initializers overwrite scanner_ccode */ } cpp_opt_declarators { $$ = 0; @@ -4565,7 +4566,8 @@ cpp_nested : storage_class cpptype idcolon inherit LBRACE { ------------------------------------------------------------ */ | storage_class cpptype inherit LBRACE { - cparse_start_line = cparse_line; skip_balanced('{','}'); + cparse_start_line = cparse_line; + skip_balanced('{','}'); $$ = NewString(scanner_ccode); /* copied as initializers overwrite scanner_ccode */ } cpp_opt_declarators { $$ = 0; @@ -5883,28 +5885,34 @@ base_list : base_specifier { } ; -base_specifier : opt_virtual idcolon { +base_specifier : opt_virtual { + $$ = cparse_line; + } idcolon { $$ = NewHash(); Setfile($$,cparse_file); - Setline($$,cparse_line); - Setattr($$,"name",$2); + Setline($$,$2); + Setattr($$,"name",$3); + Setfile($3,cparse_file); + Setline($3,$2); if (last_cpptype && (Strcmp(last_cpptype,"struct") != 0)) { Setattr($$,"access","private"); - Swig_warning(WARN_PARSE_NO_ACCESS,cparse_file,cparse_line, - "No access specifier given for base class %s (ignored).\n",$2); + Swig_warning(WARN_PARSE_NO_ACCESS, Getfile($$), Getline($$), "No access specifier given for base class '%s' (ignored).\n", SwigType_namestr($3)); } else { Setattr($$,"access","public"); } } - | opt_virtual access_specifier opt_virtual idcolon { + | opt_virtual access_specifier { + $$ = cparse_line; + } opt_virtual idcolon { $$ = NewHash(); Setfile($$,cparse_file); - Setline($$,cparse_line); - Setattr($$,"name",$4); + Setline($$,$3); + Setattr($$,"name",$5); + Setfile($5,cparse_file); + Setline($5,$3); Setattr($$,"access",$2); if (Strcmp($2,"public") != 0) { - Swig_warning(WARN_PARSE_PRIVATE_INHERIT, cparse_file, - cparse_line,"%s inheritance ignored.\n", $2); + Swig_warning(WARN_PARSE_PRIVATE_INHERIT, Getfile($$), Getline($$), "%s inheritance from base '%s' (ignored).\n", $2, SwigType_namestr($5)); } } ; diff --git a/Source/Modules/typepass.cxx b/Source/Modules/typepass.cxx index e0e06d54e..438b66617 100644 --- a/Source/Modules/typepass.cxx +++ b/Source/Modules/typepass.cxx @@ -175,10 +175,10 @@ class TypePass:private Dispatcher { } } if (Strcmp(nodeType(bcls), "classforward") != 0) { - Swig_error(Getfile(cls), Getline(cls), "'%s' does not have a valid base class.\n", Getattr(cls, "name")); - Swig_error(Getfile(bcls), Getline(bcls), "'%s' is not a valid base class.\n", SwigType_namestr(bname)); + Swig_error(Getfile(bname), Getline(bname), "'%s' is not a valid base class.\n", SwigType_namestr(bname)); + Swig_error(Getfile(bcls), Getline(bcls), "See definition of '%s'.\n", SwigType_namestr(bname)); } else { - Swig_warning(WARN_TYPE_INCOMPLETE, Getfile(cls), Getline(cls), "Base class '%s' is incomplete.\n", SwigType_namestr(bname)); + Swig_warning(WARN_TYPE_INCOMPLETE, Getfile(bname), Getline(bname), "Base class '%s' is incomplete.\n", SwigType_namestr(bname)); Swig_warning(WARN_TYPE_INCOMPLETE, Getfile(bcls), Getline(bcls), "Only forward declaration '%s' was found.\n", SwigType_namestr(bname)); clsforward = 1; } @@ -189,7 +189,7 @@ class TypePass:private Dispatcher { ilist = alist = NewList(); Append(ilist, bcls); } else { - Swig_warning(WARN_TYPE_UNDEFINED_CLASS, Getfile(cls), Getline(cls), "Base class '%s' undefined.\n", SwigType_namestr(bname)); + Swig_warning(WARN_TYPE_UNDEFINED_CLASS, Getfile(bname), Getline(bname), "Base class '%s' undefined.\n", SwigType_namestr(bname)); Swig_warning(WARN_TYPE_UNDEFINED_CLASS, Getfile(bcls), Getline(bcls), "'%s' must be defined before it is used as a base class.\n", SwigType_namestr(bname)); } } @@ -202,10 +202,9 @@ class TypePass:private Dispatcher { if (!bcls) { if (!clsforward) { if (ispublic && !Getmeta(bname, "already_warned")) { - Swig_warning(WARN_TYPE_UNDEFINED_CLASS, Getfile(cls), Getline(cls), "Nothing known about base class '%s'. Ignored.\n", SwigType_namestr(bname)); + Swig_warning(WARN_TYPE_UNDEFINED_CLASS, Getfile(bname), Getline(bname), "Nothing known about base class '%s'. Ignored.\n", SwigType_namestr(bname)); if (Strchr(bname, '<')) { - Swig_warning(WARN_TYPE_UNDEFINED_CLASS, Getfile(cls), Getline(cls), "Maybe you forgot to instantiate '%s' using %%template.\n", - SwigType_namestr(bname)); + Swig_warning(WARN_TYPE_UNDEFINED_CLASS, Getfile(bname), Getline(bname), "Maybe you forgot to instantiate '%s' using %%template.\n", SwigType_namestr(bname)); } Setmeta(bname, "already_warned", "1"); } @@ -259,7 +258,7 @@ class TypePass:private Dispatcher { Delete(bsmart); Delete(smart); } else { - Swig_error(Getfile(first), Getline(first), "Invalid type (%s) in 'smartptr' feature for class %s.\n", smartptr, clsname); + Swig_error(Getfile(first), Getline(first), "Invalid type (%s) in 'smartptr' feature for class %s.\n", SwigType_namestr(smartptr), SwigType_namestr(clsname)); } } if (!importmode) { @@ -275,7 +274,7 @@ class TypePass:private Dispatcher { Symtab *st = Getattr(cls, "symtab"); Symtab *bst = Getattr(bclass, "symtab"); if (st == bst) { - Swig_warning(WARN_PARSE_REC_INHERITANCE, Getfile(cls), Getline(cls), "Recursive scope inheritance of '%s'.\n", Getattr(cls, "name")); + Swig_warning(WARN_PARSE_REC_INHERITANCE, Getfile(cls), Getline(cls), "Recursive scope inheritance of '%s'.\n", SwigType_namestr(Getattr(cls, "name"))); continue; } Symtab *s = Swig_symbol_current(); -- cgit v1.2.1 From 6c094629cbd6df08a20c68656a487965b7072d30 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Mon, 20 Sep 2010 19:11:55 +0000 Subject: File and line number corrections for warnings WARN_JAVA_MULTIPLE_INHERITANCE WARN_MODULA3_MULTIPLE_INHERITANCE WARN_CSHARP_MULTIPLE_INHERITANCE and errors 'The javabase typemap for proxy' 'No methodname attribute...' 'No methodmodifiers attribute...' 'The csbase typemap for proxy...' git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12224 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Source/Modules/csharp.cxx | 16 ++++++++-------- Source/Modules/java.cxx | 18 ++++++++---------- Source/Modules/modula3.cxx | 11 ++++------- 3 files changed, 20 insertions(+), 25 deletions(-) diff --git a/Source/Modules/csharp.cxx b/Source/Modules/csharp.cxx index 8ffd9768a..e0c4a4332 100644 --- a/Source/Modules/csharp.cxx +++ b/Source/Modules/csharp.cxx @@ -1640,10 +1640,10 @@ public: base = Next(base); continue; } - String *proxyclassname = SwigType_str(Getattr(n, "classtypeobj"), 0); - String *baseclassname = SwigType_str(Getattr(base.item, "name"), 0); - Swig_warning(WARN_CSHARP_MULTIPLE_INHERITANCE, input_file, line_number, - "Warning for %s proxy: Base %s ignored. Multiple inheritance is not supported in C#.\n", proxyclassname, baseclassname); + String *proxyclassname = Getattr(n, "classtypeobj"); + String *baseclassname = Getattr(base.item, "name"); + Swig_warning(WARN_CSHARP_MULTIPLE_INHERITANCE, Getfile(n), Getline(n), + "Warning for %s proxy: Base %s ignored. Multiple inheritance is not supported in Java.\n", SwigType_namestr(proxyclassname), SwigType_namestr(baseclassname)); base = Next(base); } } @@ -1661,9 +1661,9 @@ public: Delete(baseclass); baseclass = NULL; if (purebase_notderived) - Swig_error(input_file, line_number, "The csbase typemap for proxy %s must contain just one of the 'replace' or 'notderived' attributes.\n", typemap_lookup_type); + Swig_error(Getfile(n), Getline(n), "The csbase typemap for proxy %s must contain just one of the 'replace' or 'notderived' attributes.\n", typemap_lookup_type); } else if (Len(pure_baseclass) > 0 && Len(baseclass) > 0) { - Swig_warning(WARN_CSHARP_MULTIPLE_INHERITANCE, input_file, line_number, + Swig_warning(WARN_CSHARP_MULTIPLE_INHERITANCE, Getfile(n), Getline(n), "Warning for %s proxy: Base %s ignored. Multiple inheritance is not supported in C#. " "Perhaps you need one of the 'replace' or 'notderived' attributes in the csbase typemap?\n", typemap_lookup_type, pure_baseclass); } @@ -1704,10 +1704,10 @@ public: } if (tm && *Char(tm)) { if (!destruct_methodname) { - Swig_error(input_file, line_number, "No methodname attribute defined in csdestruct%s typemap for %s\n", (derived ? "_derived" : ""), proxy_class_name); + Swig_error(Getfile(n), Getline(n), "No methodname attribute defined in csdestruct%s typemap for %s\n", (derived ? "_derived" : ""), proxy_class_name); } if (!destruct_methodmodifiers) { - Swig_error(input_file, line_number, + Swig_error(Getfile(n), Getline(n), "No methodmodifiers attribute defined in csdestruct%s typemap for %s.\n", (derived ? "_derived" : ""), proxy_class_name); } } diff --git a/Source/Modules/java.cxx b/Source/Modules/java.cxx index 4a6abd569..c8769a876 100644 --- a/Source/Modules/java.cxx +++ b/Source/Modules/java.cxx @@ -1714,10 +1714,10 @@ public: base = Next(base); continue; } - String *proxyclassname = SwigType_str(Getattr(n, "classtypeobj"), 0); - String *baseclassname = SwigType_str(Getattr(base.item, "name"), 0); - Swig_warning(WARN_JAVA_MULTIPLE_INHERITANCE, input_file, line_number, - "Warning for %s proxy: Base %s ignored. Multiple inheritance is not supported in Java.\n", proxyclassname, baseclassname); + String *proxyclassname = Getattr(n, "classtypeobj"); + String *baseclassname = Getattr(base.item, "name"); + Swig_warning(WARN_JAVA_MULTIPLE_INHERITANCE, Getfile(n), Getline(n), + "Warning for %s proxy: Base %s ignored. Multiple inheritance is not supported in Java.\n", SwigType_namestr(proxyclassname), SwigType_namestr(baseclassname)); base = Next(base); } } @@ -1735,9 +1735,9 @@ public: Delete(baseclass); baseclass = NULL; if (purebase_notderived) - Swig_error(input_file, line_number, "The javabase typemap for proxy %s must contain just one of the 'replace' or 'notderived' attributes.\n", typemap_lookup_type); + Swig_error(Getfile(n), Getline(n), "The javabase typemap for proxy %s must contain just one of the 'replace' or 'notderived' attributes.\n", typemap_lookup_type); } else if (Len(pure_baseclass) > 0 && Len(baseclass) > 0) { - Swig_warning(WARN_JAVA_MULTIPLE_INHERITANCE, input_file, line_number, + Swig_warning(WARN_JAVA_MULTIPLE_INHERITANCE, Getfile(n), Getline(n), "Warning for %s proxy: Base %s ignored. Multiple inheritance is not supported in Java. " "Perhaps you need one of the 'replace' or 'notderived' attributes in the csbase typemap?\n", typemap_lookup_type, pure_baseclass); } @@ -1772,12 +1772,10 @@ public: } if (tm && *Char(tm)) { if (!destruct_methodname) { - Swig_error(input_file, line_number, - "No methodname attribute defined in javadestruct%s typemap for %s\n", (derived ? "_derived" : ""), proxy_class_name); + Swig_error(Getfile(n), Getline(n), "No methodname attribute defined in javadestruct%s typemap for %s\n", (derived ? "_derived" : ""), proxy_class_name); } if (!destruct_methodmodifiers) { - Swig_error(input_file, line_number, - "No methodmodifiers attribute defined in javadestruct%s typemap for %s.\n", (derived ? "_derived" : ""), proxy_class_name); + Swig_error(Getfile(n), Getline(n), "No methodmodifiers attribute defined in javadestruct%s typemap for %s.\n", (derived ? "_derived" : ""), proxy_class_name); } } // Emit the finalize and delete methods diff --git a/Source/Modules/modula3.cxx b/Source/Modules/modula3.cxx index edd6690ce..ede63f802 100644 --- a/Source/Modules/modula3.cxx +++ b/Source/Modules/modula3.cxx @@ -2222,8 +2222,7 @@ MODULA3(): } base = Next(base); if (base.item != NIL) { - Swig_warning(WARN_MODULA3_MULTIPLE_INHERITANCE, input_file, - line_number, + Swig_warning(WARN_MODULA3_MULTIPLE_INHERITANCE, Getfile(n), Getline(n), "Warning for %s proxy: Base %s ignored. Multiple inheritance is not supported in Modula 3.\n", classDeclarationName, Getattr(base.item, "name")); } @@ -2236,8 +2235,7 @@ MODULA3(): // Inheritance from pure Modula 3 classes const String *pure_baseclass = typemapLookup(n, "m3base", classDeclarationName, WARN_NONE); if (hasContent(pure_baseclass) && hasContent(baseclass)) { - Swig_warning(WARN_MODULA3_MULTIPLE_INHERITANCE, input_file, - line_number, + Swig_warning(WARN_MODULA3_MULTIPLE_INHERITANCE, Getfile(n), Getline(n), "Warning for %s proxy: Base %s ignored. Multiple inheritance is not supported in Modula 3.\n", classDeclarationName, pure_baseclass); } // Pure Modula 3 interfaces @@ -2273,7 +2271,7 @@ MODULA3(): destruct_methodname = Getattr(attributes, "tmap:m3destruct:methodname"); } if (!destruct_methodname) { - Swig_error(input_file, line_number, "No methodname attribute defined in m3destruct%s typemap for %s\n", (derived ? "_derived" : ""), proxy_class_name); + Swig_error(Getfile(n), Getline(n), "No methodname attribute defined in m3destruct%s typemap for %s\n", (derived ? "_derived" : ""), proxy_class_name); } // Emit the Finalize and Dispose methods if (tm) { @@ -2466,8 +2464,7 @@ MODULA3(): Append(baseclassname, Getattr(base.item, "sym:name")); base = Next(base); if (base.item != NIL) { - Swig_warning(WARN_MODULA3_MULTIPLE_INHERITANCE, input_file, - line_number, + Swig_warning(WARN_MODULA3_MULTIPLE_INHERITANCE, input_file, line_number, "Warning for %s proxy: Base %s ignored. Multiple inheritance is not supported in Modula 3.\n", proxy_class_name, Getattr(base.item, "name")); } -- cgit v1.2.1 From 1e051820ec601ca34bbd8abc4926193319708e3e Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Tue, 21 Sep 2010 06:07:06 +0000 Subject: Line/file reporting corrections for warnings: WARN_RUBY_MULTIPLE_INHERITANCE, WARN_TYPE_UNDEFINED_CLASS, WARN_MODULA3_MULTIPLE_INHERITANCE git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12225 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Source/Modules/modula3.cxx | 2 +- Source/Modules/python.cxx | 2 +- Source/Modules/ruby.cxx | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Source/Modules/modula3.cxx b/Source/Modules/modula3.cxx index ede63f802..45ceba1a4 100644 --- a/Source/Modules/modula3.cxx +++ b/Source/Modules/modula3.cxx @@ -2464,7 +2464,7 @@ MODULA3(): Append(baseclassname, Getattr(base.item, "sym:name")); base = Next(base); if (base.item != NIL) { - Swig_warning(WARN_MODULA3_MULTIPLE_INHERITANCE, input_file, line_number, + Swig_warning(WARN_MODULA3_MULTIPLE_INHERITANCE, Getfile(n), Getline(n), "Warning for %s proxy: Base %s ignored. Multiple inheritance is not supported in Modula 3.\n", proxy_class_name, Getattr(base.item, "name")); } diff --git a/Source/Modules/python.cxx b/Source/Modules/python.cxx index fed5205e1..b807cc627 100644 --- a/Source/Modules/python.cxx +++ b/Source/Modules/python.cxx @@ -2866,7 +2866,7 @@ public: bool ignore = GetFlag(b.item, "feature:ignore") ? true : false; if (!bname || ignore) { if (!bname && !ignore) { - Swig_warning(WARN_TYPE_UNDEFINED_CLASS, input_file, line_number, + Swig_warning(WARN_TYPE_UNDEFINED_CLASS, Getfile(n), Getline(n), "Base class '%s' ignored - unknown module name for base. Either import the appropriate module interface file or specify the name of the module in the %%import directive.\n", SwigType_namestr(Getattr(b.item, "name"))); } b = Next(b); diff --git a/Source/Modules/ruby.cxx b/Source/Modules/ruby.cxx index bcdfd69d3..ab1210a79 100644 --- a/Source/Modules/ruby.cxx +++ b/Source/Modules/ruby.cxx @@ -2395,7 +2395,7 @@ public: } String *proxyclassname = SwigType_str(Getattr(n, "classtypeobj"), 0); String *baseclassname = SwigType_str(Getattr(base.item, "name"), 0); - Swig_warning(WARN_RUBY_MULTIPLE_INHERITANCE, input_file, line_number, + Swig_warning(WARN_RUBY_MULTIPLE_INHERITANCE, Getfile(n), Getline(n), "Warning for %s proxy: Base %s ignored. Multiple inheritance is not supported in Ruby.\n", proxyclassname, baseclassname); base = Next(base); } -- cgit v1.2.1 From ea9275ca08756f6cf886d6f083ee94eda3b57156 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Tue, 21 Sep 2010 18:09:20 +0000 Subject: html fixes git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12226 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Doc/Manual/Ruby.html | 2 +- Doc/Manual/SWIG.html | 3 ++- Doc/Manual/chapters | 1 - 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Doc/Manual/Ruby.html b/Doc/Manual/Ruby.html index 736b6137d..bda2af60c 100644 --- a/Doc/Manual/Ruby.html +++ b/Doc/Manual/Ruby.html @@ -5,7 +5,7 @@ - +

    33 SWIG and Ruby

    diff --git a/Doc/Manual/SWIG.html b/Doc/Manual/SWIG.html index bdd0edb8b..52b9db339 100644 --- a/Doc/Manual/SWIG.html +++ b/Doc/Manual/SWIG.html @@ -1909,6 +1909,8 @@ The most general function of all of the above ones (not counting command which is even more powerful in principle but which should generally be avoided because of performance considerations) is the regex one. Here are some more examples of its use: +

    +
     // Strip the wx prefix from all identifiers except those starting with wxEVT
    @@ -1924,7 +1926,6 @@ generally be avoided because of performance considerations) is the
                                                   // GetValue -> Value
     
    -

    As before, everything that was said above about %rename also applies to diff --git a/Doc/Manual/chapters b/Doc/Manual/chapters index cd399996b..014029c74 100644 --- a/Doc/Manual/chapters +++ b/Doc/Manual/chapters @@ -34,4 +34,3 @@ Ruby.html Tcl.html R.html Extending.html - -- cgit v1.2.1 From 31af118c41b44a74244613b4eb8e54d06d5cee6a Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Fri, 24 Sep 2010 22:13:13 +0000 Subject: Move Swig_locator from scanner.c to cscanner.c. Fix file and line error/warning reporting fixes where SWIG macros are used within {} braces (where the preprocessor expands macros), for example macros within %inline {...} and %fragment(...) {...} and nested structs. Basically anything that results ina call to skip_balanced() in the parser/preprocessor. git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12227 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- CHANGES.current | 6 + Examples/test-suite/errors/cpp_macro_locator.i | 103 ++++++++++++++++ Examples/test-suite/errors/expected.log | 23 ++++ Examples/test-suite/errors/make.sh | 1 + Source/CParse/cscanner.c | 99 +-------------- Source/Swig/scanner.c | 159 +++++++++++++++++++++++-- Source/Swig/swigscan.h | 2 +- 7 files changed, 284 insertions(+), 109 deletions(-) create mode 100644 Examples/test-suite/errors/cpp_macro_locator.i diff --git a/CHANGES.current b/CHANGES.current index d98b99f1a..a227d8e66 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -5,6 +5,12 @@ See the RELEASENOTES file for a summary of changes in each release. Version 2.0.1 (in progress) =========================== +2010-09-24: wsfulton + More file and line error/warning reporting fixes where SWIG macros + are used within {} braces (where the preprocessor expands macros), + for example macros within %inline {...} and %fragment(...) {...} + and nested structs. + 2010-09-18: wsfulton More file and line error/warning reporting fixes for various inherited class problems. diff --git a/Examples/test-suite/errors/cpp_macro_locator.i b/Examples/test-suite/errors/cpp_macro_locator.i new file mode 100644 index 000000000..bd441a121 --- /dev/null +++ b/Examples/test-suite/errors/cpp_macro_locator.i @@ -0,0 +1,103 @@ +%module xxx + +// Test the SWIG preprocessor locator effects on reporting line numbers in warnings when processing SWIG (multiline) macros + +// The ignored overloaded methods warnings should have the correct line number reporting +// {} blocks are tested, where the preprocessor expands the macros + +%define CLASSMACRO(KLASS) +class KLASS +{ +public: + KLASS() {} + void methodX(int *) {} + void methodX(const int *) {} +}; +%enddef + +%{ +#define CLASSMACRO(KLASS) \ +class KLASS \ +{ \ +public: \ + KLASS() {} \ + void methodX(int *) {} \ + void methodX(const int *) {} \ +}; +%} + +%{ +#define VARIABLEMACRO(NAME) double NAME; +struct Outer { + struct Inner { + VARIABLEMACRO(MyInnerVar) + }; +}; +void overload1(int *) {} +void overload1(const int *) {} +void overload2(int *) {} +void overload2(const int *) {} +void overload3(int *) {} +void overload3(const int *) {} +%} + +%define VARIABLEMACRO(NAME) +double NAME; +%enddef +struct Outer { + struct Inner { + VARIABLEMACRO(MyInnerVar) + }; +}; +void overload1(int *) {} +void overload1(const int *) {} + +%fragment("FragmentMethod", "header") { +void fragmentMethod() { +} +VARIABLEMACRO(fragVar) +} +void overload2(int *) {} +void overload2(const int *) {} + +%inline { +CLASSMACRO(Klass1) +} +#warning inline warning message one +void overload3(int *) {} +void overload3(const int *) {} + +%{ +struct Classic { + Classic() { + VARIABLEMACRO(inconstructor) + } + double value; +}; +void overload4(int *) {} +void overload4(const int *) {} +void overload5(int *) {} +void overload5(const int *) {} +%} + +struct Classic { + Classic() { + VARIABLEMACRO(inconstructor) + } + double value; +}; +void overload4(int *) {} +void overload4(const int *) {} + +%inline { +void overloadinline1(int *) {} +void overloadinline1(const int *) {} +CLASSMACRO(Klass2) +#warning an inline warning message 2 +void overloadinline2(int *) {} +void overloadinline2(const int *) {} +} +void overload5(int *) {} +void overload5(const int *) {} + + diff --git a/Examples/test-suite/errors/expected.log b/Examples/test-suite/errors/expected.log index 7cbce4c30..06942064f 100644 --- a/Examples/test-suite/errors/expected.log +++ b/Examples/test-suite/errors/expected.log @@ -225,6 +225,29 @@ cpp_inherit.i:26: Warning 401: Nothing known about base class 'A7< int >'. Ignor cpp_inherit.i:26: Warning 401: Maybe you forgot to instantiate 'A7< int >' using %template. cpp_inherit.i:45: Warning 323: Recursive scope inheritance of 'Recursive'. +:::::::::::::::::::::::::::::::: cpp_macro_locator.i ::::::::::::::::::::::::::::::::::: +cpp_macro_locator.i:66: Warning 204: CPP #warning, inline warning message one +cpp_macro_locator.i:96: Warning 204: CPP #warning, an inline warning message 2 +cpp_macro_locator.i:50: Warning 325: Nested struct not currently supported (Inner ignored) +cpp_macro_locator.i:53: Warning 509: Overloaded method overload1(int const *) effectively ignored, +cpp_macro_locator.i:52: Warning 509: as it is shadowed by overload1(int *). +cpp_macro_locator.i:61: Warning 509: Overloaded method overload2(int const *) effectively ignored, +cpp_macro_locator.i:60: Warning 509: as it is shadowed by overload2(int *). +cpp_macro_locator.i:64: Warning 509: Overloaded method Klass1::methodX(int const *) effectively ignored, +cpp_macro_locator.i:64: Warning 509: as it is shadowed by Klass1::methodX(int *). +cpp_macro_locator.i:68: Warning 509: Overloaded method overload3(int const *) effectively ignored, +cpp_macro_locator.i:67: Warning 509: as it is shadowed by overload3(int *). +cpp_macro_locator.i:90: Warning 509: Overloaded method overload4(int const *) effectively ignored, +cpp_macro_locator.i:89: Warning 509: as it is shadowed by overload4(int *). +cpp_macro_locator.i:94: Warning 509: Overloaded method overloadinline1(int const *) effectively ignored, +cpp_macro_locator.i:93: Warning 509: as it is shadowed by overloadinline1(int *). +cpp_macro_locator.i:95: Warning 509: Overloaded method Klass2::methodX(int const *) effectively ignored, +cpp_macro_locator.i:95: Warning 509: as it is shadowed by Klass2::methodX(int *). +cpp_macro_locator.i:98: Warning 509: Overloaded method overloadinline2(int const *) effectively ignored, +cpp_macro_locator.i:97: Warning 509: as it is shadowed by overloadinline2(int *). +cpp_macro_locator.i:101: Warning 509: Overloaded method overload5(int const *) effectively ignored, +cpp_macro_locator.i:100: Warning 509: as it is shadowed by overload5(int *). + :::::::::::::::::::::::::::::::: cpp_missing_rtemplate.i ::::::::::::::::::::::::::::::::::: cpp_missing_rtemplate.i:4: Error: Syntax error in input(1). diff --git a/Examples/test-suite/errors/make.sh b/Examples/test-suite/errors/make.sh index 0a81254f4..52d6c8967 100755 --- a/Examples/test-suite/errors/make.sh +++ b/Examples/test-suite/errors/make.sh @@ -65,6 +65,7 @@ cpp_extend_redefine cpp_extend_undefined cpp_inline_namespace cpp_inherit +cpp_macro_locator cpp_missing_rtemplate cpp_namespace_alias cpp_namespace_aliasnot diff --git a/Source/CParse/cscanner.c b/Source/CParse/cscanner.c index 7d848878c..bf684c4cc 100644 --- a/Source/CParse/cscanner.c +++ b/Source/CParse/cscanner.c @@ -45,8 +45,6 @@ static int num_brace = 0; static int last_brace = 0; static int last_id = 0; static int rename_active = 0; -static int expanding_macro = 0; -static int follow_locators = 0; /* ----------------------------------------------------------------------------- * Swig_cparse_cplusplus() @@ -56,101 +54,6 @@ void Swig_cparse_cplusplus(int v) { cparse_cplusplus = v; } -/* ---------------------------------------------------------------------- - * locator() - * - * Support for locator strings. These are strings of the form - * @SWIG:filename,line,id@ emitted by the SWIG preprocessor. They - * are primarily used for macro line number reporting - * ---------------------------------------------------------------------- */ - -typedef struct Locator { - String *filename; - int line_number; - struct Locator *next; -} Locator; - -static Locator *locs = 0; - -/* we just use the locator to mark when active/deactive the linecounting */ - -static void scanner_locator(String *loc) { - if (!follow_locators) { - if (Equal(loc, "/*@SWIG@*/")) { - /* End locator. */ - if (expanding_macro) - --expanding_macro; - } else { - /* Begin locator. */ - ++expanding_macro; - } - /* Freeze line number processing in Scanner */ - Scanner_freeze_line(scan,expanding_macro); - } else { - int c; - Locator *l; - Seek(loc, 7, SEEK_SET); - c = Getc(loc); - if (c == '@') { - /* Empty locator. We pop the last location off */ - if (locs) { - Scanner_set_location(scan,locs->filename,locs->line_number); - cparse_file = locs->filename; - cparse_line = locs->line_number; - l = locs->next; - free(locs); - locs = l; - } - return; - } - - /* We're going to push a new location */ - l = (Locator *) malloc(sizeof(Locator)); - l->filename = cparse_file; - l->line_number = cparse_line; - l->next = locs; - locs = l; - - /* Now, parse the new location out of the locator string */ - { - String *fn = NewStringEmpty(); - /* Putc(c, fn); */ - - while ((c = Getc(loc)) != EOF) { - if ((c == '@') || (c == ',')) - break; - Putc(c, fn); - } - cparse_file = Swig_copy_string(Char(fn)); - Clear(fn); - cparse_line = 1; - /* Get the line number */ - while ((c = Getc(loc)) != EOF) { - if ((c == '@') || (c == ',')) - break; - Putc(c, fn); - } - cparse_line = atoi(Char(fn)); - Clear(fn); - - /* Get the rest of it */ - while ((c = Getc(loc)) != EOF) { - if (c == '@') - break; - Putc(c, fn); - } - /* Swig_diagnostic(cparse_file, cparse_line, "Scanner_set_location\n"); */ - Scanner_set_location(scan,cparse_file,cparse_line); - Delete(fn); - } - } -} - -void Swig_cparse_follow_locators(int v) { - follow_locators = v; -} - - /* ---------------------------------------------------------------------------- * scanner_init() * @@ -432,7 +335,7 @@ static int yylook(void) { String *cmt = Scanner_text(scan); char *loc = Char(cmt); if ((strncmp(loc,"/*@SWIG",7) == 0) && (loc[Len(cmt)-3] == '@')) { - scanner_locator(cmt); + Scanner_locator(scan, cmt); } } break; diff --git a/Source/Swig/scanner.c b/Source/Swig/scanner.c index 9b5b35f96..0cdadaa7f 100644 --- a/Source/Swig/scanner.c +++ b/Source/Swig/scanner.c @@ -20,6 +20,7 @@ char cvsroot_scanner_c[] = "$Id$"; #include extern String *cparse_file; +extern int cparse_line; extern int cparse_cplusplus; extern int cparse_start_line; @@ -38,6 +39,13 @@ struct Scanner { int freeze_line; /* Suspend line number updates */ }; +typedef struct Locator { + String *filename; + int line_number; + struct Locator *next; +} Locator; +static int follow_locators = 0; + /* ----------------------------------------------------------------------------- * NewScanner() * @@ -230,8 +238,7 @@ static void set_error(Scanner *s, int line, const_String_or_char_ptr msg) { * Returns error information (if any) * ----------------------------------------------------------------------------- */ -String * -Scanner_errmsg(Scanner *s) { +String *Scanner_errmsg(Scanner *s) { return s->error; } @@ -241,13 +248,12 @@ Scanner_errline(Scanner *s) { } /* ----------------------------------------------------------------------------- - * Scanner_freeze_line() + * freeze_line() * * Freezes the current line number. * ----------------------------------------------------------------------------- */ -void -Scanner_freeze_line(Scanner *s, int val) { +static void freeze_line(Scanner *s, int val) { s->freeze_line = val; } @@ -1153,6 +1159,7 @@ int Scanner_skip_balanced(Scanner * s, int startchar, int endchar) { int l; int state = 0; char temp[2] = { 0, 0 }; + String *locator = 0; l = s->line; temp[0] = (char) startchar; Clear(s->text); @@ -1162,6 +1169,7 @@ int Scanner_skip_balanced(Scanner * s, int startchar, int endchar) { Append(s->text, temp); while (num_levels > 0) { if ((c = nextchar(s)) == 0) { + Delete(locator); return -1; } switch (state) { @@ -1195,17 +1203,25 @@ int Scanner_skip_balanced(Scanner * s, int startchar, int endchar) { else state = 11; break; - case 12: + case 12: /* first character inside C comment */ if (c == '*') + state = 14; + else if (c == '@') + state = 40; + else state = 13; break; case 13: if (c == '*') - state = 13; + state = 14; + break; + case 14: /* possible end of C comment */ + if (c == '*') + state = 14; else if (c == '/') state = 0; else - state = 12; + state = 13; break; case 20: if (c == '\"') @@ -1225,10 +1241,43 @@ int Scanner_skip_balanced(Scanner * s, int startchar, int endchar) { case 31: state = 30; break; + /* 40-45 SWIG locator checks - a C comment with contents starting: @SWIG */ + case 40: + state = (c == 'S') ? 41 : (c == '*') ? 14 : 13; + break; + case 41: + state = (c == 'W') ? 42 : (c == '*') ? 14 : 13; + break; + case 42: + state = (c == 'I') ? 43 : (c == '*') ? 14 : 13; + break; + case 43: + state = (c == 'G') ? 44 : (c == '*') ? 14 : 13; + if (c == 'G') { + Delete(locator); + locator = NewString("/*@SWIG"); + } + break; + case 44: + if (c == '*') + state = 45; + Putc(c, locator); + break; + case 45: /* end of SWIG locator in C comment */ + if (c == '/') { + state = 0; + Putc(c, locator); + Scanner_locator(s, locator); + } else { + /* malformed locator */ + state = (c == '*') ? 14 : 13; + } + break; default: break; } } + Delete(locator); return 0; } @@ -1239,8 +1288,98 @@ int Scanner_skip_balanced(Scanner * s, int startchar, int endchar) { * operator. * ----------------------------------------------------------------------------- */ -int -Scanner_isoperator(int tokval) { +int Scanner_isoperator(int tokval) { if (tokval >= 100) return 1; return 0; } + +/* ---------------------------------------------------------------------- + * locator() + * + * Support for locator strings. These are strings of the form + * @SWIG:filename,line,id@ emitted by the SWIG preprocessor. They + * are primarily used for macro line number reporting. + * We just use the locator to mark when to activate/deactivate linecounting. + * ---------------------------------------------------------------------- */ + + +void Scanner_locator(Scanner *s, String *loc) { + static Locator *locs = 0; + static int expanding_macro = 0; + + if (!follow_locators) { + if (Equal(loc, "/*@SWIG@*/")) { + /* End locator. */ + if (expanding_macro) + --expanding_macro; + } else { + /* Begin locator. */ + ++expanding_macro; + } + /* Freeze line number processing in Scanner */ + freeze_line(s,expanding_macro); + } else { + int c; + Locator *l; + Seek(loc, 7, SEEK_SET); + c = Getc(loc); + if (c == '@') { + /* Empty locator. We pop the last location off */ + if (locs) { + Scanner_set_location(s, locs->filename, locs->line_number); + cparse_file = locs->filename; + cparse_line = locs->line_number; + l = locs->next; + free(locs); + locs = l; + } + return; + } + + /* We're going to push a new location */ + l = (Locator *) malloc(sizeof(Locator)); + l->filename = cparse_file; + l->line_number = cparse_line; + l->next = locs; + locs = l; + + /* Now, parse the new location out of the locator string */ + { + String *fn = NewStringEmpty(); + /* Putc(c, fn); */ + + while ((c = Getc(loc)) != EOF) { + if ((c == '@') || (c == ',')) + break; + Putc(c, fn); + } + cparse_file = Swig_copy_string(Char(fn)); + Clear(fn); + cparse_line = 1; + /* Get the line number */ + while ((c = Getc(loc)) != EOF) { + if ((c == '@') || (c == ',')) + break; + Putc(c, fn); + } + cparse_line = atoi(Char(fn)); + Clear(fn); + + /* Get the rest of it */ + while ((c = Getc(loc)) != EOF) { + if (c == '@') + break; + Putc(c, fn); + } + /* Swig_diagnostic(cparse_file, cparse_line, "Scanner_set_location\n"); */ + Scanner_set_location(s, cparse_file, cparse_line); + Delete(fn); + } + } +} + +void Swig_cparse_follow_locators(int v) { + follow_locators = v; +} + + diff --git a/Source/Swig/swigscan.h b/Source/Swig/swigscan.h index b07812fbe..a2d5911bd 100644 --- a/Source/Swig/swigscan.h +++ b/Source/Swig/swigscan.h @@ -30,7 +30,7 @@ extern void Scanner_idstart(Scanner *, const char *idchar); extern String *Scanner_errmsg(Scanner *); extern int Scanner_errline(Scanner *); extern int Scanner_isoperator(int tokval); -extern void Scanner_freeze_line(Scanner *s, int val); +extern void Scanner_locator(Scanner *, String *loc); /* Note: Tokens in range 100+ are for C/C++ operators */ -- cgit v1.2.1 From e1ddf0ea3a778bf5bac48009004f2a4a7ac9d9ea Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Sat, 25 Sep 2010 17:08:13 +0000 Subject: Apply SF patch #3075150 - Java directors using static variables in named namespace git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12228 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- CHANGES.current | 4 ++++ Source/Modules/java.cxx | 6 ++++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/CHANGES.current b/CHANGES.current index a227d8e66..2767abb7a 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -5,6 +5,10 @@ See the RELEASENOTES file for a summary of changes in each release. Version 2.0.1 (in progress) =========================== +2010-09-25: wsfulton + Apply SF patch #3075150 - Java directors using static variables in + named namespace. + 2010-09-24: wsfulton More file and line error/warning reporting fixes where SWIG macros are used within {} braces (where the preprocessor expands macros), diff --git a/Source/Modules/java.cxx b/Source/Modules/java.cxx index c8769a876..1d4e522c6 100644 --- a/Source/Modules/java.cxx +++ b/Source/Modules/java.cxx @@ -3324,8 +3324,10 @@ public: } Printf(f_runtime, "namespace Swig {\n"); - Printf(f_runtime, " static jclass jclass_%s = NULL;\n", imclass_name); - Printf(f_runtime, " static jmethodID director_methids[%d];\n", n_methods); + Printf(f_runtime, " namespace {\n"); + Printf(f_runtime, " jclass jclass_%s = NULL;\n", imclass_name); + Printf(f_runtime, " jmethodID director_methids[%d];\n", n_methods); + Printf(f_runtime, " }\n"); Printf(f_runtime, "}\n"); Printf(w->def, "SWIGEXPORT void JNICALL Java_%s%s_%s(JNIEnv *jenv, jclass jcls) {", jnipackage, jni_imclass_name, swig_module_init_jni); -- cgit v1.2.1 From 5437d71d73569400cc2f544a7934f2c768efa8f5 Mon Sep 17 00:00:00 2001 From: Olly Betts Date: Mon, 27 Sep 2010 01:16:29 +0000 Subject: [Python] Improve error message given when a parameter of the wrong type is passed to an overloaded method (SF#3027355). git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12229 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Source/Modules/python.cxx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/Modules/python.cxx b/Source/Modules/python.cxx index b807cc627..80f2e68df 100644 --- a/Source/Modules/python.cxx +++ b/Source/Modules/python.cxx @@ -1799,7 +1799,7 @@ public: } while ((sibl = Getattr(sibl, "sym:nextSibling"))); Append(f->code, "fail:\n"); Printf(f->code, "SWIG_SetErrorMsg(PyExc_NotImplementedError," - "\"Wrong number of arguments for overloaded function '%s'.\\n\"" "\n\" Possible C/C++ prototypes are:\\n\"%s);\n", symname, protoTypes); + "\"Wrong number or type of arguments for overloaded function '%s'.\\n\"" "\n\" Possible C/C++ prototypes are:\\n\"%s);\n", symname, protoTypes); Append(f->code, "return NULL;\n"); Delete(protoTypes); } -- cgit v1.2.1 From 40e64b14f148b3d58dc13cca7df59a0193926e68 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Mon, 27 Sep 2010 05:40:14 +0000 Subject: Allocate warnings 700-799 for languages modules. Note 900-999 was and is documented as reserved for user defined warnings. git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12230 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Doc/Manual/Warnings.html | 2 +- Source/Include/swigwarn.h | 10 +++++++--- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/Doc/Manual/Warnings.html b/Doc/Manual/Warnings.html index 96e35902a..4bbf18205 100644 --- a/Doc/Manual/Warnings.html +++ b/Doc/Manual/Warnings.html @@ -515,7 +515,7 @@ example.i(4) : Syntax error in input.

  • 519. %template() contains no name. Template method ignored: declaration -

    14.9.6 Language module specific (800-899)

    +

    14.9.6 Language module specific (700-899)

      diff --git a/Source/Include/swigwarn.h b/Source/Include/swigwarn.h index 46f5b79a5..5db30e6e9 100644 --- a/Source/Include/swigwarn.h +++ b/Source/Include/swigwarn.h @@ -196,11 +196,16 @@ /* -- Reserved (600-799) -- */ -/* -- Language module specific warnings (800 - 999) -- */ +/* -- Language module specific warnings (700 - 899) -- */ + +/* Feel free to claim any number in this space that's not currently being used. Just make sure you + add an entry here */ #define WARN_RUBY_WRONG_NAME 801 #define WARN_RUBY_MULTIPLE_INHERITANCE 802 +/* please leave 800-809 free for Ruby */ + #define WARN_JAVA_TYPEMAP_JNI_UNDEF 810 #define WARN_JAVA_TYPEMAP_JTYPE_UNDEF 811 #define WARN_JAVA_TYPEMAP_JSTYPE_UNDEF 812 @@ -262,7 +267,6 @@ /* please leave 890-899 free for Go */ -/* Feel free to claim any number in this space that's not currently being used. Just make sure you - add an entry here */ +/* -- User defined warnings (900 - 999) -- */ #endif -- cgit v1.2.1 From 8a05a236124fc511d8559a37fa36d5aa96b9b818 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Tue, 28 Sep 2010 06:36:42 +0000 Subject: Apply patch from Tomas Dirvanauskas for std::map wrappers to avoid throwing exceptions with normal usage of iterators. git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12231 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- CHANGES.current | 4 ++++ Lib/csharp/std_map.i | 24 +++++++++++++----------- 2 files changed, 17 insertions(+), 11 deletions(-) diff --git a/CHANGES.current b/CHANGES.current index 2767abb7a..b0647a336 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -5,6 +5,10 @@ See the RELEASENOTES file for a summary of changes in each release. Version 2.0.1 (in progress) =========================== +2010-09-28: wsfulton + [C#] Apply patch from Tomas Dirvanauskas for std::map wrappers to avoid + throwing exceptions with normal usage of iterators. + 2010-09-25: wsfulton Apply SF patch #3075150 - Java directors using static variables in named namespace. diff --git a/Lib/csharp/std_map.i b/Lib/csharp/std_map.i index 2db6ddf5b..a4bf02397 100644 --- a/Lib/csharp/std_map.i +++ b/Lib/csharp/std_map.i @@ -67,12 +67,13 @@ public System.Collections.Generic.ICollection<$typemap(cstype, K)> Keys { get { System.Collections.Generic.ICollection<$typemap(cstype, K)> keys = new System.Collections.Generic.List<$typemap(cstype, K)>(); - IntPtr iter = create_iterator_begin(); - try { - while (true) { + int size = this.Count; + if (size > 0) { + IntPtr iter = create_iterator_begin(); + for (int i = 0; i < size; i++) { keys.Add(get_next_key(iter)); } - } catch (ArgumentOutOfRangeException) { + destroy_iterator(iter); } return keys; } @@ -258,7 +259,7 @@ return false; } - // create_iterator_begin() and get_next_key() work together to provide a collection of keys to C# + // create_iterator_begin(), get_next_key() and destroy_iterator work together to provide a collection of keys to C# %apply void *VOID_INT_PTR { std::map< K, T >::iterator *create_iterator_begin } %apply void *VOID_INT_PTR { std::map< K, T >::iterator *swigiterator } @@ -266,15 +267,15 @@ return new std::map< K, T >::iterator($self->begin()); } - const key_type& get_next_key(std::map< K, T >::iterator *swigiterator) throw (std::out_of_range) { + const key_type& get_next_key(std::map< K, T >::iterator *swigiterator) { std::map< K, T >::iterator iter = *swigiterator; - if (iter == $self->end()) { - delete swigiterator; - throw std::out_of_range("no more map elements"); - } - (*swigiterator)++; + swigiterator++; return (*iter).first; } + + void destroy_iterator(std::map< K, T >::iterator *swigiterator) { + delete swigiterator; + } } @@ -285,6 +286,7 @@ %csmethodmodifiers std::map::setitem "private" %csmethodmodifiers std::map::create_iterator_begin "private" %csmethodmodifiers std::map::get_next_key "private" +%csmethodmodifiers std::map::destroy_iterator "private" // Default implementation namespace std { -- cgit v1.2.1 From 5ff65533190a31afd5d5fdcf1c485c4ed3a3c376 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Tue, 28 Sep 2010 17:37:33 +0000 Subject: testcase warning suppression git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12232 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Examples/test-suite/constant_pointers.i | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Examples/test-suite/constant_pointers.i b/Examples/test-suite/constant_pointers.i index 7d46cdb31..394c0e5ec 100644 --- a/Examples/test-suite/constant_pointers.i +++ b/Examples/test-suite/constant_pointers.i @@ -6,6 +6,8 @@ This testcase primarily test constant pointers, eg int* const. Only a getter is %warnfilter(SWIGWARN_TYPEMAP_SWIGTYPELEAK); /* memory leak when setting a ptr/ref variable */ %warnfilter(SWIGWARN_GO_NAME_CONFLICT); /* Ignoring 'Foo' due to Go name ('Foo') conflict with 'foo' */ +%warnfilter(SWIGWARN_TYPEMAP_SWIGTYPELEAK_MSG); /* Setting a pointer/reference variable may leak memory. */ + %inline %{ -- cgit v1.2.1 From 9f41fa27cb9eee42c0fc003139ce9a6fdc485031 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Tue, 28 Sep 2010 17:56:48 +0000 Subject: remove latin-1 characters git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12233 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Doc/Manual/Java.html | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Doc/Manual/Java.html b/Doc/Manual/Java.html index d014feef6..d32a7fb9a 100644 --- a/Doc/Manual/Java.html +++ b/Doc/Manual/Java.html @@ -363,7 +363,7 @@ To load your shared native library module in Java, simply use Java's System. public class runme { static { -  System.loadLibrary("example"); +  System.loadLibrary("example"); } public static void main(String argv[]) { @@ -6234,7 +6234,7 @@ public class runme { static { try { -  System.loadLibrary("example"); +  System.loadLibrary("example"); } catch (UnsatisfiedLinkError e) { System.err.println("Native code library failed to load. " + e); System.exit(1); @@ -6453,7 +6453,7 @@ public class runme { static { try { -  System.loadLibrary("example"); +  System.loadLibrary("example"); } catch (UnsatisfiedLinkError e) { System.err.println("Native code library failed to load. " + e); System.exit(1); -- cgit v1.2.1 From 83f17b43ce2049cc1a36237d7930d0507c46cbc6 Mon Sep 17 00:00:00 2001 From: Olly Betts Date: Fri, 1 Oct 2010 03:16:56 +0000 Subject: Add entry corresponding to r12229 which I failed to commit before. git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12234 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- CHANGES.current | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGES.current b/CHANGES.current index b0647a336..a281023b6 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -9,6 +9,10 @@ Version 2.0.1 (in progress) [C#] Apply patch from Tomas Dirvanauskas for std::map wrappers to avoid throwing exceptions with normal usage of iterators. +2010-09-27: olly + [Python] Improve error message given when a parameter of the wrong + type is passed to an overloaded method (SF#3027355). + 2010-09-25: wsfulton Apply SF patch #3075150 - Java directors using static variables in named namespace. -- cgit v1.2.1 From c636855bcc31ae71e8303cbfad46466508707a1c Mon Sep 17 00:00:00 2001 From: Olly Betts Date: Fri, 1 Oct 2010 04:01:08 +0000 Subject: [Python] Allow reinitialisation to work with an embedded Python interpreter (patch from Jim Carroll in SF#3075178). git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12235 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- CHANGES.current | 4 ++++ Lib/python/pyrun.swg | 6 +++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/CHANGES.current b/CHANGES.current index a281023b6..c2d2d52f2 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -5,6 +5,10 @@ See the RELEASENOTES file for a summary of changes in each release. Version 2.0.1 (in progress) =========================== +2010-10-01: olly + [Python] Allow reinitialisation to work with an embedded Python + interpreter (patch from Jim Carroll in SF#3075178). + 2010-09-28: wsfulton [C#] Apply patch from Tomas Dirvanauskas for std::map wrappers to avoid throwing exceptions with normal usage of iterators. diff --git a/Lib/python/pyrun.swg b/Lib/python/pyrun.swg index d46628551..5043e6ec0 100644 --- a/Lib/python/pyrun.swg +++ b/Lib/python/pyrun.swg @@ -979,10 +979,13 @@ _SWIG_This(void) return SWIG_Python_str_FromChar("this"); } +static PyObject *swig_this = NULL; + SWIGRUNTIME PyObject * SWIG_This(void) { - static PyObject *SWIG_STATIC_POINTER(swig_this) = _SWIG_This(); + if (swig_this == NULL) + swig_this = _SWIG_This(); return swig_this; } @@ -1413,6 +1416,7 @@ SWIG_Python_DestroyModule(void *vptr) } } Py_DECREF(SWIG_This()); + swig_this = NULL; } SWIGRUNTIME void -- cgit v1.2.1 From 045066e802dd3c56e0e3c6e91fb078ecc75a8d42 Mon Sep 17 00:00:00 2001 From: Olly Betts Date: Fri, 1 Oct 2010 04:17:55 +0000 Subject: Fix typo in comment git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12236 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Lib/ruby/rubyerrors.swg | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Lib/ruby/rubyerrors.swg b/Lib/ruby/rubyerrors.swg index e2564980f..434544bc9 100644 --- a/Lib/ruby/rubyerrors.swg +++ b/Lib/ruby/rubyerrors.swg @@ -9,7 +9,7 @@ /* Define custom exceptions for errors that do not map to existing Ruby exceptions. Note this only works for C++ since a global cannot be - initialized by a funtion in C. For C, fallback to rb_eRuntimeError.*/ + initialized by a function in C. For C, fallback to rb_eRuntimeError.*/ SWIGINTERN VALUE getNullReferenceError(void) { -- cgit v1.2.1 From eaada32f264f828ec326f4c91f5c1a73399a8897 Mon Sep 17 00:00:00 2001 From: Olly Betts Date: Fri, 1 Oct 2010 04:42:29 +0000 Subject: [Ruby] Avoid segfault when a method node has no parentNode (SF#3034054). git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12237 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- CHANGES.current | 4 ++++ Source/Modules/ruby.cxx | 11 +++++++++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/CHANGES.current b/CHANGES.current index c2d2d52f2..d3c8c21d0 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -5,6 +5,10 @@ See the RELEASENOTES file for a summary of changes in each release. Version 2.0.1 (in progress) =========================== +2010-10-01: olly + [Ruby] Avoid segfault when a method node has no parentNode + (SF#3034054). + 2010-10-01: olly [Python] Allow reinitialisation to work with an embedded Python interpreter (patch from Jim Carroll in SF#3075178). diff --git a/Source/Modules/ruby.cxx b/Source/Modules/ruby.cxx index ab1210a79..8461b8bef 100644 --- a/Source/Modules/ruby.cxx +++ b/Source/Modules/ruby.cxx @@ -2054,8 +2054,15 @@ public: // Construct real method name String* methodName = NewString(""); - if ( isMethod ) - Printv( methodName, Getattr(parentNode(sibl),"sym:name"), ".", NIL ); + if ( isMethod ) { + // Sometimes a method node has no parent (SF#3034054). + // This value is used in an exception message, so just skip the class + // name in this case so at least we don't segfault. This is probably + // just working around a problem elsewhere though. + Node *parent_node = parentNode(sibl); + if (parent_node) + Printv( methodName, Getattr(parent_node,"sym:name"), ".", NIL ); + } Append( methodName, Getattr(sibl,"sym:name" ) ); if ( isCtor ) Append( methodName, ".new" ); -- cgit v1.2.1 From db6bf51067db6beb701f4e9f5b25e14acf360c2d Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Fri, 1 Oct 2010 22:46:22 +0000 Subject: Add pcre-build.sh script for easier building of pcre and configuring with SWIG if PCRE not installed git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12238 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- README | 3 +++ Tools/mkwindows.sh | 14 ++++++++++++-- Tools/pcre-build.sh | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++++ configure.in | 30 +++++++++++++++++++++++++----- 4 files changed, 93 insertions(+), 7 deletions(-) create mode 100755 Tools/pcre-build.sh diff --git a/README b/README index 3c6ee27a0..b5379d84d 100644 --- a/README +++ b/README @@ -57,6 +57,9 @@ You must use GNU `make' to build SWIG. http://www.gnu.org/software/make/ +PCRE needs to be installed on your system to build SWIG. The configure +script will provide instructions for obtaining PCRE if it cannot be found. + To build and install SWIG, simply type the following: % ./configure diff --git a/Tools/mkwindows.sh b/Tools/mkwindows.sh index 869fce01a..6042361b3 100755 --- a/Tools/mkwindows.sh +++ b/Tools/mkwindows.sh @@ -43,7 +43,7 @@ else if test x$zip = x; then zip=zip fi - extraconfigureoptions="--host=i586-mingw32msvc --build=i686-linux CXXFLAGS=-O2 CFLAGS=-O2" + extraconfigureoptions="--host=i586-mingw32msvc --build=i686-linux" else if test "$cygwin"; then echo "Building native Windows executable on Cygwin" @@ -61,6 +61,13 @@ fi swigbasename=swig-$version swigwinbasename=swigwin-$version tarball=$swigbasename.tar.gz +pcre_tarball=`ls pcre-*.tar.*` + +if ! test -f "$pcre_tarball"; then + echo "Could not find PCRE tarball. Please download a PCRE source tarball from http://www.pcre.org" + echo "and place in the same directory as the SWIG tarball." + exit 1 +fi if test -f "$tarball"; then builddir=build-$version @@ -78,8 +85,11 @@ if test -f "$tarball"; then mv $swigbasename $swigwinbasename tar -zxf ../$tarball cd $swigbasename + (cd ../.. && cp $pcre_tarball $builddir/$swigbasename) + echo Running: Tools/pcre-build.sh $extraconfigureoptions CFLAGS="$compileflags" CXXFLAGS="$compileflags" + ./Tools/pcre-build.sh $extraconfigureoptions CFLAGS="$compileflags" CXXFLAGS="$compileflags" || exit 1 echo Running: ./configure $extraconfigureoptions CFLAGS="$compileflags" CXXFLAGS="$compileflags" - ./configure $extraconfigureoptions CFLAGS="$compileflags" CXXFLAGS="$compileflags" + ./configure $extraconfigureoptions CFLAGS="$compileflags" CXXFLAGS="$compileflags" || exit 1 echo "Compiling (quietly)..." make > build.log echo "Simple check to see if swig.exe runs..." diff --git a/Tools/pcre-build.sh b/Tools/pcre-build.sh new file mode 100755 index 000000000..876a58a7e --- /dev/null +++ b/Tools/pcre-build.sh @@ -0,0 +1,53 @@ +#!/bin/sh + +pcre_subdir=pcre/pcre-swig-install +pcre_install_dir=`pwd`/$pcre_subdir + +usage() { + echo "Helper script to build PCRE as a static library from a tarball just for use during the" + echo "SWIG build. It does not install PCRE for global use on your system." + echo "Usage: pcre-build.sh [--help] [args]" + echo " args - optional additional arguments passed on to the PCRE configure script (leave out" + echo " unless you are an expert at configure)" + echo " --help - Display this help information." + echo "Instructions:" + echo " - Download the latest PCRE source tarball from http://www.pcre.org and place in the" + echo " directory that you will configure and build SWIG." + echo " - Run this script in the same directory that you intend to configure and build SWIG in." + echo " - Afterwards run the SWIG configure scrip which will then find and use the PCRE static" + echo " libraries in the $pcre_subdir subdirectory." + exit 0 +} + +bail() { + echo $1 >&2 + exit 1 +} + +if test "$1" = "-h" -o "$1" = "-help" -o "$1" = "--help" ; then + usage +fi + +if test -f "pcre-build.sh" ; then + echo "Error: this script should not be run in the Tools directory" >&2 + echo "" + usage +fi + +echo "Looking for PCRE tarball..." +rm -rf pcre +pcre_tarball=`ls pcre-*.tar.*` +test -f "$pcre_tarball" || bail "Could not find tarball" + +echo "Extracting tarball: $pcre_tarball" +tar -xf $pcre_tarball || bail "Could not untar $pcre_tarball" +pcre_dir=`echo $pcre_tarball | sed -e "s/\.tar.*//"` +echo "Configuring PCRE in directory: pcre" +mv $pcre_dir pcre || bail "Could not create pcre directory" +cd pcre && ./configure --prefix=$pcre_install_dir --disable-shared $* || bail "PCRE configure failed" +echo "Building PCRE..." +make -s || bail "Could not build PCRE" +echo "Installing PCRE locally to $pcre_install_dir..." +make -s install || bail "Could not install PCRE" +echo "" +echo "The SWIG configure script can now be run, whereupon PCRE will automatically be detected and used from $pcre_install_dir/bin/pcre-config." diff --git a/configure.in b/configure.in index 856d02d4a..2976aca66 100644 --- a/configure.in +++ b/configure.in @@ -67,6 +67,19 @@ AC_ARG_WITH([pcre], AC_MSG_CHECKING([whether to enable PCRE support]) AC_MSG_RESULT([$with_pcre]) + +dnl To make configuring easier, check for a locally built PCRE using the Tools/pcre-build.sh script +if test x"${with_pcre}" = xyes ; then + AC_MSG_CHECKING([whether to use local PCRE]) + local_pcre_config=no + if test -z $PCRE_CONFIG; then + if test -f `pwd`/pcre/pcre-swig-install/bin/pcre-config; then + PCRE_CONFIG=`pwd`/pcre/pcre-swig-install/bin/pcre-config + local_pcre_config=$PCRE_CONFIG + fi + fi + AC_MSG_RESULT([$local_pcre_config]) +fi AS_IF([test "x$with_pcre" != xno], [AX_PATH_GENERIC([pcre], [], dnl Minimal version of PCRE we need -- accept any @@ -75,11 +88,18 @@ AS_IF([test "x$with_pcre" != xno], LIBS="$LIBS $PCRE_LIBS" CPPFLAGS="$CPPFLAGS $PCRE_CFLAGS" ], - [AC_MSG_FAILURE( - Can't find pcre-config script from PCRE (Perl Compatible Regular - Expressions) library package. You need to either download PCRE from - www.pcre.org and install it or use --without-pcre configure option to - disable regular expressions support in SWIG.) + [AC_MSG_FAILURE([ + Can't find pcre-config script from PCRE (Perl Compatible Regular Expressions) + library package. This dependency is needed for configure to complete, + Either: + - Install the PCRE developer package on your system (preferred approach). + - Download the PCRE source tarball, build and install on your system + as you would for any package built from source distribution. + - Use the Tools/pcre-build.sh script to build PCRE just for SWIG to statically + link against. Run 'Tools/pcre-build.sh --help' for instructions. + (quite easy and does not require privileges to install PCRE on your system) + - Use configure --without-pcre to disable regular expressions support in SWIG + (not recommended).]) ]) ]) -- cgit v1.2.1 From 766ed8db375f47ef0ed4751bcd28eba31e40f3d7 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Fri, 1 Oct 2010 23:52:46 +0000 Subject: Add -pcreversion option to display PCRE version information git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12239 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- CHANGES.current | 3 +++ Doc/Manual/SWIG.html | 1 + Source/Modules/main.cxx | 7 +++++++ Source/Swig/misc.c | 8 ++++++++ Source/Swig/swig.h | 1 + 5 files changed, 20 insertions(+) diff --git a/CHANGES.current b/CHANGES.current index d3c8c21d0..f312793e4 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -5,6 +5,9 @@ See the RELEASENOTES file for a summary of changes in each release. Version 2.0.1 (in progress) =========================== +2010-10-01: wsfulton + Add -pcreversion option to display PCRE version information. + 2010-10-01: olly [Ruby] Avoid segfault when a method node has no parentNode (SF#3034054). diff --git a/Doc/Manual/SWIG.html b/Doc/Manual/SWIG.html index 52b9db339..23a5e1643 100644 --- a/Doc/Manual/SWIG.html +++ b/Doc/Manual/SWIG.html @@ -147,6 +147,7 @@ can be obtained by typing swig -help or swig -o outfile Name of output file -outcurrentdir Set default output dir to current dir instead of input file's path -outdir dir Set language specific files output directory +-pcreversion Display PCRE version information -swiglib Show location of SWIG library -version Show SWIG version number diff --git a/Source/Modules/main.cxx b/Source/Modules/main.cxx index 3f2008d7d..95327018d 100644 --- a/Source/Modules/main.cxx +++ b/Source/Modules/main.cxx @@ -129,6 +129,7 @@ static const char *usage3 = (const char *) "\ -oh - Set name of the output header file to \n\ -outcurrentdir - Set default output dir to current dir instead of input file's path\n\ -outdir - Set language specific files output directory to \n\ + -pcreversion - Display PCRE version information\n\ -small - Compile in virtual elimination & compact mode\n\ -swiglib - Report location of SWIG library and exit\n\ -templatereduce - Reduce all the typedefs in templates\n\ @@ -515,6 +516,12 @@ void SWIG_getoptions(int argc, char *argv[]) { } else if (strcmp(argv[i], "-nodirprot") == 0) { Wrapper_director_protected_mode_set(0); Swig_mark_arg(i); + } else if (strcmp(argv[i], "-pcreversion") == 0) { + String *version = Swig_pcre_version(); + Printf(stdout, "%s\n", version); + Delete(version); + Swig_mark_arg(i); + SWIG_exit(EXIT_SUCCESS); } else if (strcmp(argv[i], "-small") == 0) { Wrapper_compact_print_mode_set(1); Wrapper_virtual_elimination_mode_set(1); diff --git a/Source/Swig/misc.c b/Source/Swig/misc.c index a57c7cf33..73510b513 100644 --- a/Source/Swig/misc.c +++ b/Source/Swig/misc.c @@ -1213,6 +1213,10 @@ String *Swig_string_regex(String *s) { return res ? res : NewStringEmpty(); } +String *Swig_pcre_version(void) { + return NewStringf("PCRE Version: %s", pcre_version()); +} + #else String *Swig_string_regex(String *s) { @@ -1220,6 +1224,10 @@ String *Swig_string_regex(String *s) { exit(1); } +String *Swig_pcre_version(void) { + return NewStringf("PCRE not used"); +} + #endif /* ----------------------------------------------------------------------------- diff --git a/Source/Swig/swig.h b/Source/Swig/swig.h index 021c5611f..0194664fc 100644 --- a/Source/Swig/swig.h +++ b/Source/Swig/swig.h @@ -319,6 +319,7 @@ extern int ParmList_is_compactdefargs(ParmList *p); extern String *Swig_string_lower(String *s); extern String *Swig_string_upper(String *s); extern String *Swig_string_title(String *s); + extern String *Swig_pcre_version(void); extern void Swig_init(void); extern int Swig_value_wrapper_mode(int mode); -- cgit v1.2.1 From 3219746776bb1bcb9f46f895c68040303f0d4b33 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Sun, 3 Oct 2010 13:12:00 +0000 Subject: Apply patch #3066958 from Mikael Johansson to fix default smart pointer handling when the smart pointer contains both a const and non-const operator->. git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12240 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- CHANGES.current | 4 + Examples/test-suite/common.mk | 1 + .../java/smart_pointer_const_overload_runme.java | 99 +++++++++++++++++ .../python/smart_pointer_const_overload_runme.py | 123 +++++++++++++++++++++ Examples/test-suite/smart_pointer_const_overload.i | 74 +++++++++++++ Source/Modules/allocate.cxx | 6 +- Source/Modules/lang.cxx | 7 +- Source/Swig/cwrap.c | 40 +++++-- Source/Swig/swig.h | 1 + 9 files changed, 343 insertions(+), 12 deletions(-) create mode 100644 Examples/test-suite/java/smart_pointer_const_overload_runme.java create mode 100644 Examples/test-suite/python/smart_pointer_const_overload_runme.py create mode 100644 Examples/test-suite/smart_pointer_const_overload.i diff --git a/CHANGES.current b/CHANGES.current index f312793e4..18694e492 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -5,6 +5,10 @@ See the RELEASENOTES file for a summary of changes in each release. Version 2.0.1 (in progress) =========================== +2010-10-03: wsfulton + Apply patch #3066958 from Mikael Johansson to fix default smart pointer + handling when the smart pointer contains both a const and non-const operator->. + 2010-10-01: wsfulton Add -pcreversion option to display PCRE version information. diff --git a/Examples/test-suite/common.mk b/Examples/test-suite/common.mk index e385b11dd..026612db5 100644 --- a/Examples/test-suite/common.mk +++ b/Examples/test-suite/common.mk @@ -294,6 +294,7 @@ CPP_TEST_CASES += \ sizet \ smart_pointer_const \ smart_pointer_const2 \ + smart_pointer_const_overload \ smart_pointer_extend \ smart_pointer_member \ smart_pointer_multi \ diff --git a/Examples/test-suite/java/smart_pointer_const_overload_runme.java b/Examples/test-suite/java/smart_pointer_const_overload_runme.java new file mode 100644 index 000000000..bb4ae2c8f --- /dev/null +++ b/Examples/test-suite/java/smart_pointer_const_overload_runme.java @@ -0,0 +1,99 @@ +import smart_pointer_const_overload.*; + +public class smart_pointer_const_overload_runme { + static int CONST_ACCESS = 1; + static int MUTABLE_ACCESS = 2; + + static { + System.loadLibrary("smart_pointer_const_overload"); + } + + public static void test(Bar b, Foo f) { + Assert(f.getX() == 0); + + // Test member variable get + Assert(b.getX() == 0); + Assert(f.getAccess() == CONST_ACCESS); + + // Test member variable set + b.setX(1); + Assert(f.getX() == 1); + Assert(f.getAccess() == MUTABLE_ACCESS); + + // Test const method + Assert(b.getx() == 1); + Assert(f.getAccess() == CONST_ACCESS); + + // Test mutable method + b.setx(2); + + Assert(f.getX() == 2); + Assert(f.getAccess() == MUTABLE_ACCESS); + + // Test extended const method + Assert(b.getx2() == 2); + Assert(f.getAccess() == CONST_ACCESS); + + // Test extended mutable method + b.setx2(3); + + Assert(f.getX() == 3); + Assert(f.getAccess() == MUTABLE_ACCESS); + + // Test static method + b.stat(); + + Assert(f.getAccess() == CONST_ACCESS); + + // Test const member + f.setAccess(MUTABLE_ACCESS); + + Assert(b.getY() == 0); + Assert(f.getAccess() == CONST_ACCESS); + + // Test get through mutable pointer to const member + f.setAccess(MUTABLE_ACCESS); + + Assert(smart_pointer_const_overload.get_int(b.getYp()) == 0); + Assert(f.getAccess() == CONST_ACCESS); + + // Test get through const pointer to mutable member + f.setX(4); + f.setAccess(MUTABLE_ACCESS); + + Assert(smart_pointer_const_overload.get_int(b.getXp()) == 4); + Assert(f.getAccess() == CONST_ACCESS); + + // Test set through const pointer to mutable member + f.setAccess(MUTABLE_ACCESS); + smart_pointer_const_overload.set_int(b.getXp(), 5); + + Assert(f.getX() == 5); + Assert(f.getAccess() == CONST_ACCESS); + + // Test set pointer to const member + b.setYp(smart_pointer_const_overload.new_int(6)); + + Assert(f.getY() == 0); + Assert(smart_pointer_const_overload.get_int(f.getYp()) == 6); + Assert(f.getAccess() == MUTABLE_ACCESS); + + smart_pointer_const_overload.delete_int(f.getYp()); + } + + public static void main(String argv[]) { + Foo f = new Foo(); + Bar b = new Bar(f); + + //Foo f2 = new Foo(); + //Bar b2 = new Bar2(f2); + + test(b, f); + //test(b2, f2); + } + + public static void Assert(boolean b) { + if (!b) + throw new RuntimeException("Assertion failed"); + } +} diff --git a/Examples/test-suite/python/smart_pointer_const_overload_runme.py b/Examples/test-suite/python/smart_pointer_const_overload_runme.py new file mode 100644 index 000000000..f1be315a5 --- /dev/null +++ b/Examples/test-suite/python/smart_pointer_const_overload_runme.py @@ -0,0 +1,123 @@ +from smart_pointer_const_overload import * + +CONST_ACCESS = 1 +MUTABLE_ACCESS = 2 + +def test(b, f): + if f.x != 0: + raise RuntimeError + + # Test member variable get + if b.x != 0: + raise RuntimeError + + if f.access != CONST_ACCESS: + raise RuntimeError + + # Test member variable set + b.x = 1 + + if f.x != 1: + raise RuntimeError + + if f.access != MUTABLE_ACCESS: + raise RuntimeError + + # Test const method + if b.getx() != 1: + raise RuntimeError + + if f.access != CONST_ACCESS: + raise RuntimeError + + # Test mutable method + b.setx(2) + + if f.x != 2: + raise RuntimeError + + if f.access != MUTABLE_ACCESS: + raise RuntimeError + + # Test extended const method + if b.getx2() != 2: + raise RuntimeError + + if f.access != CONST_ACCESS: + raise RuntimeError + + # Test extended mutable method + b.setx2(3) + + if f.x != 3: + raise RuntimeError + + if f.access != MUTABLE_ACCESS: + raise RuntimeError + + # Test static method + b.stat() + + if f.access != CONST_ACCESS: + raise RuntimeError + + # Test const member + f.access = MUTABLE_ACCESS + + if b.y != 0: + raise RuntimeError + + if f.access != CONST_ACCESS: + raise RuntimeError + + # Test get through mutable pointer to const member + f.access = MUTABLE_ACCESS + + if get_int(b.yp) != 0: + raise RuntimeError + + if f.access != CONST_ACCESS: + raise RuntimeError + + # Test get through const pointer to mutable member + f.x = 4 + f.access = MUTABLE_ACCESS + + if get_int(b.xp) != 4: + raise RuntimeError + + if f.access != CONST_ACCESS: + raise RuntimeError + + # Test set through const pointer to mutable member + f.access = MUTABLE_ACCESS + set_int(b.xp, 5) + + if f.x != 5: + raise RuntimeError + + if f.access != CONST_ACCESS: + raise RuntimeError + + # Test set pointer to const member + b.yp = new_int(6) + + if f.y != 0: + raise RuntimeError + + if get_int(f.yp) != 6: + raise RuntimeError + + if f.access != MUTABLE_ACCESS: + raise RuntimeError + + delete_int(f.yp); + +f = Foo() +b = Bar(f) + +f2 = Foo() +b2 = Bar2(f2) + +test(b, f) +test(b2, f2) diff --git a/Examples/test-suite/smart_pointer_const_overload.i b/Examples/test-suite/smart_pointer_const_overload.i new file mode 100644 index 000000000..e3b000b52 --- /dev/null +++ b/Examples/test-suite/smart_pointer_const_overload.i @@ -0,0 +1,74 @@ +%module smart_pointer_const_overload + +%warnfilter(SWIGWARN_LANG_OVERLOAD_IGNORED) Bar::operator->; // Overloaded method Bar::operator ->() ignored +%warnfilter(SWIGWARN_LANG_OVERLOAD_IGNORED) Bar2::operator->; // Overloaded method Bar2::operator ->() ignored + +%inline %{ +int CONST_ACCESS = 1; +int MUTABLE_ACCESS = 2; + +int *new_int(int ivalue) { + int *i = (int *) malloc(sizeof(ivalue)); + *i = ivalue; + return i; +} + +int get_int(int *i) { + return *i; +} + +void set_int(int *i, int ivalue) { + *i = ivalue; +} + +void delete_int(int *i) { + free(i); +} + +struct Foo { + int x; + int * const xp; + const int y; + const int *yp; + int access; + Foo() : x(0), xp(&x), y(0), yp(&y), access(0) { } + int getx() const { return x; } + void setx(int x_) { x = x_; } + static void stat() {} +}; +%} + +%extend Foo { + int getx2() const { return self->x; } + void setx2(int x_) { self->x = x_; } +}; + +%inline %{ +class Bar { + Foo *f; +public: + Bar(Foo *f) : f(f) { } + const Foo *operator->() const { + f->access = CONST_ACCESS; + return f; + } + Foo *operator->() { + f->access = MUTABLE_ACCESS; + return f; + } +}; + +class Bar2 { + Foo *f; +public: + Bar2(Foo *f) : f(f) { } + Foo *operator->() { + f->access = MUTABLE_ACCESS; + return f; + } + const Foo *operator->() const { + f->access = CONST_ACCESS; + return f; + } +}; +%} diff --git a/Source/Modules/allocate.cxx b/Source/Modules/allocate.cxx index 2e05fd190..31f7c20ae 100644 --- a/Source/Modules/allocate.cxx +++ b/Source/Modules/allocate.cxx @@ -824,9 +824,12 @@ Allocate(): int isconst = 0; Delete(SwigType_pop(type)); if (SwigType_isconst(type)) { - isconst = 1; + isconst = !Getattr(inclass, "allocate:smartpointermutable"); Setattr(inclass, "allocate:smartpointerconst", "1"); } + else { + Setattr(inclass, "allocate:smartpointermutable", "1"); + } List *methods = smart_pointer_methods(sc, 0, isconst); Setattr(inclass, "allocate:smartpointer", methods); Setattr(inclass, "allocate:smartpointerbase", base); @@ -834,7 +837,6 @@ Allocate(): /* Hmmm. The return value is not a pointer. If the type is a value or reference. We're going to chase it to see if another operator->() can be found */ - if ((SwigType_check_decl(type, "")) || (SwigType_check_decl(type, "r."))) { Node *nn = Swig_symbol_clookup((char *) "operator ->", Getattr(sc, "symtab")); if (nn) { diff --git a/Source/Modules/lang.cxx b/Source/Modules/lang.cxx index 6ec0463fa..0110b6ea1 100644 --- a/Source/Modules/lang.cxx +++ b/Source/Modules/lang.cxx @@ -1344,7 +1344,7 @@ int Language::variableHandler(Node *n) { Swig_save("variableHandler", n, "feature:immutable", NIL); if (SmartPointer) { /* If a smart-pointer and it's a constant access, we have to set immutable */ - if (Getattr(CurrentClass, "allocate:smartpointerconst")) { + if (!Getattr(CurrentClass, "allocate:smartpointermutable")) { SetFlag(n, "feature:immutable"); } } @@ -1391,7 +1391,7 @@ int Language::membervariableHandler(Node *n) { int assignable = is_assignable(n); if (SmartPointer) { - if (Getattr(CurrentClass, "allocate:smartpointerconst")) { + if (!Getattr(CurrentClass, "allocate:smartpointermutable")) { assignable = 0; } } @@ -2443,6 +2443,9 @@ int Language::classHandler(Node *n) { List *methods = Getattr(n, "allocate:smartpointer"); cplus_mode = PUBLIC; SmartPointer = CWRAP_SMART_POINTER; + if (Getattr(n, "allocate:smartpointerconst") && Getattr(n, "allocate:smartpointermutable")) { + SmartPointer |= CWRAP_SMART_POINTER_OVERLOAD; + } Iterator c; for (c = First(methods); c.item; c = Next(c)) { emit_one(c.item); diff --git a/Source/Swig/cwrap.c b/Source/Swig/cwrap.c index b8812563e..799d434a6 100644 --- a/Source/Swig/cwrap.c +++ b/Source/Swig/cwrap.c @@ -783,15 +783,32 @@ int Swig_add_extension_code(Node *n, const String *function_name, ParmList *parm * ----------------------------------------------------------------------------- */ int Swig_MethodToFunction(Node *n, const_String_or_char_ptr nspace, String *classname, int flags, SwigType *director_type, int is_director) { - String *name, *qualifier; + String *name; ParmList *parms; SwigType *type; Parm *p; String *self = 0; - - /* If smart pointer, change self dereferencing */ + int is_smart_pointer_overload = 0; + String *qualifier = Getattr(n, "qualifier"); + + /* If smart pointer without const overload or mutable method, change self dereferencing */ if (flags & CWRAP_SMART_POINTER) { - self = NewString("(*this)->"); + if (flags & CWRAP_SMART_POINTER_OVERLOAD) { + String *cname = Getattr(n, "classname") ? Getattr(n, "classname") : classname; + if (qualifier && strncmp(Char(qualifier), "q(const)", 8) == 0) { + self = NewString("(*(this))->"); + is_smart_pointer_overload = 1; + } + else if (Cmp(Getattr(n, "storage"), "static") == 0) { + self = NewStringf("(*(%s const *)this)->", cname); + is_smart_pointer_overload = 1; + } + else { + self = NewString("(*this)->"); + } + } else { + self = NewString("(*this)->"); + } } /* If node is a member template expansion, we don't allow added code */ @@ -799,7 +816,6 @@ int Swig_MethodToFunction(Node *n, const_String_or_char_ptr nspace, String *clas flags &= ~(CWRAP_EXTEND); name = Getattr(n, "name"); - qualifier = Getattr(n, "qualifier"); parms = CopyParmList(nonvoid_parms(Getattr(n, "parms"))); type = NewString(classname); @@ -921,10 +937,16 @@ int Swig_MethodToFunction(Node *n, const_String_or_char_ptr nspace, String *clas if (Cmp(Getattr(n, "storage"), "static") != 0) { String *pname = Swig_cparm_name(pp, i); - String *ctname = SwigType_namestr(cname); - String *fadd = NewStringf("(%s*)(%s)->operator ->()", ctname, pname); + String *ctname = SwigType_namestr(cname); + String *fadd = 0; + if (is_smart_pointer_overload) { + fadd = NewStringf("(%s const *)((%s const *)%s)->operator ->()", ctname, classname, pname); + } + else { + fadd = NewStringf("(%s*)(%s)->operator ->()", ctname, pname); + } Append(func, fadd); - Delete(ctname); + Delete(ctname); Delete(fadd); Delete(pname); pp = nextSibling(pp); @@ -1310,6 +1332,8 @@ int Swig_MembergetToFunction(Node *n, String *classname, int flags) { Node *sn = Getattr(n, "cplus:staticbase"); String *base = Getattr(sn, "name"); self = NewStringf("%s::", base); + } else if (flags & CWRAP_SMART_POINTER_OVERLOAD) { + self = NewStringf("(*(%s const *)this)->", classname); } else { self = NewString("(*this)->"); } diff --git a/Source/Swig/swig.h b/Source/Swig/swig.h index 0194664fc..8058216c3 100644 --- a/Source/Swig/swig.h +++ b/Source/Swig/swig.h @@ -370,6 +370,7 @@ extern int ParmList_is_compactdefargs(ParmList *p); #define CWRAP_DIRECTOR_ONE_CALL 0x08 #define CWRAP_DIRECTOR_TWO_CALLS 0x10 #define CWRAP_ALL_PROTECTED_ACCESS 0x20 +#define CWRAP_SMART_POINTER_OVERLOAD 0x40 /* --- Director Helpers --- */ extern Node *Swig_methodclass(Node *n); -- cgit v1.2.1 From 70c9dc5dcc532b104861962c170b2bf94ac2fd57 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Sun, 3 Oct 2010 15:01:24 +0000 Subject: Fix warning running under Go git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12241 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Examples/test-suite/constant_pointers.i | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Examples/test-suite/constant_pointers.i b/Examples/test-suite/constant_pointers.i index 394c0e5ec..388970c4d 100644 --- a/Examples/test-suite/constant_pointers.i +++ b/Examples/test-suite/constant_pointers.i @@ -5,7 +5,6 @@ This testcase primarily test constant pointers, eg int* const. Only a getter is %module constant_pointers %warnfilter(SWIGWARN_TYPEMAP_SWIGTYPELEAK); /* memory leak when setting a ptr/ref variable */ -%warnfilter(SWIGWARN_GO_NAME_CONFLICT); /* Ignoring 'Foo' due to Go name ('Foo') conflict with 'foo' */ %warnfilter(SWIGWARN_TYPEMAP_SWIGTYPELEAK_MSG); /* Setting a pointer/reference variable may leak memory. */ @@ -52,7 +51,7 @@ public: private: MemberVariablesTest& operator=(const MemberVariablesTest&); }; -void foo(const int *const i) {} +void foofunction(const int *const i) {} typedef int *typedef1, typedef2, *const typedef3; int int1, int2=2, *int3, *const int4 = &GlobalInt; -- cgit v1.2.1 From 378ce60b495f2a8fba61cc5034ed072d434b2d55 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Sun, 3 Oct 2010 15:08:03 +0000 Subject: Lua warning fix since previous commit changed max to maximum git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12242 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Examples/test-suite/wrapmacro.i | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Examples/test-suite/wrapmacro.i b/Examples/test-suite/wrapmacro.i index bd5e48b15..4d2cd67be 100644 --- a/Examples/test-suite/wrapmacro.i +++ b/Examples/test-suite/wrapmacro.i @@ -1,7 +1,7 @@ %module wrapmacro #ifdef SWIGLUA // lua only has one numeric type, so some overloads shadow each other creating warnings -%warnfilter(SWIGWARN_LANG_OVERLOAD_SHADOW) SWIGMACRO_max; +%warnfilter(SWIGWARN_LANG_OVERLOAD_SHADOW) SWIGMACRO_maximum; #endif /* Testing technique for wrapping macros */ -- cgit v1.2.1 From 77a45b263102a22bb6d854760e8ecef32f956d1e Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Sun, 3 Oct 2010 16:42:22 +0000 Subject: visual c++ warning fixes git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12243 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Source/Modules/go.cxx | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/Source/Modules/go.cxx b/Source/Modules/go.cxx index f62586b92..4b1d05b92 100644 --- a/Source/Modules/go.cxx +++ b/Source/Modules/go.cxx @@ -1945,7 +1945,7 @@ private: String *ty = NewString(Getattr(ni, "type")); SwigType_push(ty, Getattr(ni, "decl")); String *fullty = SwigType_typedef_resolve_all(ty); - bool is_function = SwigType_isfunction(fullty); + bool is_function = SwigType_isfunction(fullty) ? true : false; Delete(ty); Delete(fullty); @@ -2426,7 +2426,7 @@ private: * ------------------------------------------------------------ */ int classDirectorConstructor(Node *n) { - bool is_ignored = GetFlag(n, "feature:ignore"); + bool is_ignored = GetFlag(n, "feature:ignore") ? true : false; String *name = Getattr(n, "sym:name"); if (!name) { @@ -2667,7 +2667,7 @@ private: return SWIG_OK; } - bool is_ignored = GetFlag(n, "feature:ignore"); + bool is_ignored = GetFlag(n, "feature:ignore") ? true : false; if (!is_ignored) { String *fnname = NewString("DeleteDirector"); @@ -2781,7 +2781,7 @@ private: int classDirectorMethod(Node *n, Node *parent, String *super) { (void) super; - bool is_ignored = GetFlag(n, "feature:ignore"); + bool is_ignored = GetFlag(n, "feature:ignore") ? true : false; bool is_pure_virtual = (Cmp(Getattr(n, "storage"), "virtual") == 0 && Cmp(Getattr(n, "value"), "0") == 0); // We don't need explicit calls. @@ -2869,7 +2869,7 @@ private: * ------------------------------------------------------------ */ int oneClassDirectorMethod(Node *n, Node *parent) { - bool is_ignored = GetFlag(n, "feature:ignore"); + bool is_ignored = GetFlag(n, "feature:ignore") ? true : false; bool is_pure_virtual = (Cmp(Getattr(n, "storage"), "virtual") == 0 && Cmp(Getattr(n, "value"), "0") == 0); String *name = Getattr(n, "sym:name"); @@ -3782,7 +3782,7 @@ private: int num_required = emit_num_required(pi); int num_arguments = emit_num_arguments(pi); - bool varargs = emit_isvarargs(pi); + bool varargs = emit_isvarargs(pi) ? true : false; if (varargs) { Printf(f_go_wrappers, "\tif argc >= %d {\n", num_required); @@ -4138,7 +4138,7 @@ private: n1, name, n2); return false; } - bool r = addSymbol(name, n, scope); + bool r = addSymbol(name, n, scope) ? true : false; assert(r); return true; } -- cgit v1.2.1 From c7b4336a6cb9e22bd779c9cad7cd02839927343e Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Sun, 3 Oct 2010 16:47:30 +0000 Subject: add missing return to testcase git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12244 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Examples/test-suite/csharp_attributes.i | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Examples/test-suite/csharp_attributes.i b/Examples/test-suite/csharp_attributes.i index bca595d9a..f679d8c08 100644 --- a/Examples/test-suite/csharp_attributes.i +++ b/Examples/test-suite/csharp_attributes.i @@ -56,7 +56,7 @@ double MoreStations::WestonSuperMare = 0.0; %inline %{ struct YetMoreStations { - virtual int Slough(int x) {} + virtual int Slough(int x) { return x; } virtual ~YetMoreStations() {} }; %} -- cgit v1.2.1 From 22dd2292cadd62b0e8d88fc89da584efcfceb5d2 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Sun, 3 Oct 2010 16:58:51 +0000 Subject: Fix for compiling as C code git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12245 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Lib/perl5/perlprimtypes.swg | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Lib/perl5/perlprimtypes.swg b/Lib/perl5/perlprimtypes.swg index f2a614030..86a78c5bf 100644 --- a/Lib/perl5/perlprimtypes.swg +++ b/Lib/perl5/perlprimtypes.swg @@ -311,8 +311,9 @@ SWIG_AsVal_dec(double)(SV *obj, double *val) const char *nptr = SvPV_nolen(obj); if (nptr) { char *endptr; + double v; errno = 0; - double v = strtod(nptr, &endptr); + v = strtod(nptr, &endptr); if (errno == ERANGE) { errno = 0; return SWIG_OverflowError; -- cgit v1.2.1 From 61e9073e0777c7b2d35c9a1d4591058755ee9590 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Sun, 3 Oct 2010 20:47:45 +0000 Subject: Add missing return value in testcase git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12246 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Examples/test-suite/return_const_value.i | 1 + 1 file changed, 1 insertion(+) diff --git a/Examples/test-suite/return_const_value.i b/Examples/test-suite/return_const_value.i index 473878521..6be5760c1 100644 --- a/Examples/test-suite/return_const_value.i +++ b/Examples/test-suite/return_const_value.i @@ -42,6 +42,7 @@ public: _ptr = f._ptr; _own = f._own; f._own = 0; + return *this; } ~Foo_ptr() { -- cgit v1.2.1 From 22a12bf08fab301446fe9bfeea6ada9a6a47570e Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Mon, 4 Oct 2010 05:34:54 +0000 Subject: Add 2.0.1 release notes git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12247 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- ANNOUNCE | 2 +- CHANGES.current | 4 ++-- Doc/Manual/SWIG.html | 3 ++- Doc/Manual/Sections.html | 2 +- README | 2 +- RELEASENOTES | 9 +++++++++ 6 files changed, 16 insertions(+), 6 deletions(-) diff --git a/ANNOUNCE b/ANNOUNCE index ad3e8f8d6..d14a77042 100644 --- a/ANNOUNCE +++ b/ANNOUNCE @@ -1,4 +1,4 @@ -*** ANNOUNCE: SWIG 2.0.1 (in progress) *** +*** ANNOUNCE: SWIG 2.0.1 (4 October 2010) *** http://www.swig.org diff --git a/CHANGES.current b/CHANGES.current index 18694e492..9b02c475f 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -2,8 +2,8 @@ This file contains the changes for the current release. See the CHANGES file for changes in older releases. See the RELEASENOTES file for a summary of changes in each release. -Version 2.0.1 (in progress) -=========================== +Version 2.0.1 (4 October 2010) +============================== 2010-10-03: wsfulton Apply patch #3066958 from Mikael Johansson to fix default smart pointer diff --git a/Doc/Manual/SWIG.html b/Doc/Manual/SWIG.html index 23a5e1643..e45fc5f9f 100644 --- a/Doc/Manual/SWIG.html +++ b/Doc/Manual/SWIG.html @@ -1885,7 +1885,8 @@ and a more descriptive one, but the two functions are otherwise equivalent: String after (Perl-like) regex substitution operation. This function allows to apply arbitrary regular expressions to the identifier names. The pattern part is a regular expression in Perl syntax (as supported - by PCRE) and the subst string + by the Perl Compatible Regular Expressions (PCRE)) + library and the subst string can contain back-references introduced by '\' or, as backslashes need to be escaped in C strings, rather by "\\". For example, to remove any alphabetic prefix before an underscore you could use the following directive: diff --git a/Doc/Manual/Sections.html b/Doc/Manual/Sections.html index 8693adc07..74d821b17 100644 --- a/Doc/Manual/Sections.html +++ b/Doc/Manual/Sections.html @@ -6,7 +6,7 @@

      SWIG-2.0 Documentation

      -Last update : SWIG-2.0.1 (in progress) +Last update : SWIG-2.0.1 (4 October 2010)

      Sections

      diff --git a/README b/README index b5379d84d..085fafd7e 100644 --- a/README +++ b/README @@ -1,6 +1,6 @@ SWIG (Simplified Wrapper and Interface Generator) -Version: 2.0.1 (in progress) +Version: 2.0.1 (4 October 2010) Tagline: SWIG is a compiler that integrates C and C++ with languages including Perl, Python, Tcl, Ruby, PHP, Java, Ocaml, Lua, diff --git a/RELEASENOTES b/RELEASENOTES index 5f41df04f..e8ff30285 100644 --- a/RELEASENOTES +++ b/RELEASENOTES @@ -5,6 +5,15 @@ and CHANGES files. Release Notes ============= +SWIG-2.0.1 summary: +- New language module: Go +- New regular expression (regex) encoder for renaming symbols based on + the Perl Compatible Regular Expressions (PCRE) library. +- Numerous fixes in reporting file and line numbers in error and warning + messages. +- Various bug fixes and improvements in the C#, Lua, Perl, PHP, Ruby + and Python language modules. + SWIG-2.0.0 summary: - License changes, see LICENSE file and http://www.swig.org/legal.html. - Much better nested class/struct support. -- cgit v1.2.1 From 2e28d85e5dd71cb75388ca6a93df459ac3db1105 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Mon, 4 Oct 2010 05:36:49 +0000 Subject: Warning section doc update git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12248 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Doc/Manual/Contents.html | 2 +- Doc/Manual/Warnings.html | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Doc/Manual/Contents.html b/Doc/Manual/Contents.html index ec99a6511..5b18d38de 100644 --- a/Doc/Manual/Contents.html +++ b/Doc/Manual/Contents.html @@ -494,7 +494,7 @@
    • C/C++ Parser (300-399)
    • Types and typemaps (400-499)
    • Code generation (500-599) -
    • Language module specific (800-899) +
    • Language module specific (700-899)
    • User defined (900-999)
  • History diff --git a/Doc/Manual/Warnings.html b/Doc/Manual/Warnings.html index 4bbf18205..2c71b6a31 100644 --- a/Doc/Manual/Warnings.html +++ b/Doc/Manual/Warnings.html @@ -25,7 +25,7 @@
  • C/C++ Parser (300-399)
  • Types and typemaps (400-499)
  • Code generation (500-599) -
  • Language module specific (800-899) +
  • Language module specific (700-899)
  • User defined (900-999)
  • History -- cgit v1.2.1 From 197b25147e120dc5403a2f948707e4362d463488 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Mon, 4 Oct 2010 05:46:42 +0000 Subject: html fixes git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12249 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Doc/Manual/SWIG.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Doc/Manual/SWIG.html b/Doc/Manual/SWIG.html index e45fc5f9f..e51e55986 100644 --- a/Doc/Manual/SWIG.html +++ b/Doc/Manual/SWIG.html @@ -1881,7 +1881,7 @@ and a more descriptive one, but the two functions are otherwise equivalent: wxPrintPrint - regex:/pattern/subst/ + regex:/pattern/subst/ String after (Perl-like) regex substitution operation. This function allows to apply arbitrary regular expressions to the identifier names. The pattern part is a regular expression in Perl syntax (as supported -- cgit v1.2.1 From eff2a7f9e9f22b4c47a82a16386a4edc8b84e52e Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Mon, 4 Oct 2010 06:10:41 +0000 Subject: dependency fix for the .book files generation git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12250 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Doc/Manual/Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Doc/Manual/Makefile b/Doc/Manual/Makefile index 69d361f07..2e50b7767 100644 --- a/Doc/Manual/Makefile +++ b/Doc/Manual/Makefile @@ -38,13 +38,13 @@ generate: swightml.book swigpdf.book htmldoc --batch swigpdf.book || true python fixstyle.py SWIGDocumentation.html -swigpdf.book: +swigpdf.book chapters Sections.html: echo "#HTMLDOC 1.8.24" > swigpdf.book echo -t pdf13 -f SWIGDocumentation.pdf $(HTMLDOC_OPTIONS) --stylesheet style.css >> swigpdf.book echo "Sections.html" >> swigpdf.book cat chapters >> swigpdf.book -swightml.book: +swightml.book chapters Sections.html: echo "#HTMLDOC 1.8.24" > swightml.book echo -t html -f SWIGDocumentation.html $(HTMLDOC_OPTIONS) >> swightml.book echo "Sections.html" >> swightml.book -- cgit v1.2.1 From 13f861220a0dc8c12512f8bf82c07083b53812f6 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Mon, 4 Oct 2010 06:15:53 +0000 Subject: dependency fix for the .book files generation git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12251 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Doc/Manual/Makefile | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Doc/Manual/Makefile b/Doc/Manual/Makefile index 2e50b7767..011261e76 100644 --- a/Doc/Manual/Makefile +++ b/Doc/Manual/Makefile @@ -15,7 +15,7 @@ # Note the # and " are escaped HTMLDOC_OPTIONS = "--book --toclevels 4 --no-numbered --toctitle \"Table of Contents\" --title --titleimage swig16.png --linkcolor \#0000ff --linkstyle underline --size Universal --left 0.50in --right 0.50in --top 0.50in --bottom 0.50in --header .t. --footer h.1 --nup 1 --tocheader .t. --tocfooter ..i --portrait --color --no-pscommands --no-xrxcomments --compression=1 --jpeg=0 --fontsize 10.0 --fontspacing 1.2 --headingfont Helvetica --bodyfont Times --headfootsize 10.0 --headfootfont Helvetica --charset iso-8859-1 --links --no-embedfonts --pagemode outline --pagelayout single --firstpage c1 --pageeffect none --pageduration 10 --effectduration 1.0 --no-encryption --permissions all --owner-password \"\" --user-password \"\" --browserwidth 680" -.PHONY: maketoc check generate all clean validate test +.PHONY: maketoc check generate all maintainer-clean validate test all: maketoc check generate @@ -38,13 +38,13 @@ generate: swightml.book swigpdf.book htmldoc --batch swigpdf.book || true python fixstyle.py SWIGDocumentation.html -swigpdf.book chapters Sections.html: +swigpdf.book: chapters Sections.html echo "#HTMLDOC 1.8.24" > swigpdf.book echo -t pdf13 -f SWIGDocumentation.pdf $(HTMLDOC_OPTIONS) --stylesheet style.css >> swigpdf.book echo "Sections.html" >> swigpdf.book cat chapters >> swigpdf.book -swightml.book chapters Sections.html: +swightml.book: chapters Sections.html echo "#HTMLDOC 1.8.24" > swightml.book echo -t html -f SWIGDocumentation.html $(HTMLDOC_OPTIONS) >> swightml.book echo "Sections.html" >> swightml.book -- cgit v1.2.1 From 29b4dbdac1098bbdaf1500a3eb8fb677c0f99db5 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Mon, 4 Oct 2010 06:16:21 +0000 Subject: Not all languages were not in alphabetical order git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12252 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Doc/Manual/Contents.html | 36 ++++----- Doc/Manual/R.html | 16 ++-- Doc/Manual/Ruby.html | 196 +++++++++++++++++++++++------------------------ Doc/Manual/Sections.html | 6 +- Doc/Manual/Tcl.html | 92 +++++++++++----------- Doc/Manual/chapters | 2 +- 6 files changed, 174 insertions(+), 174 deletions(-) diff --git a/Doc/Manual/Contents.html b/Doc/Manual/Contents.html index 5b18d38de..f4fdb9d24 100644 --- a/Doc/Manual/Contents.html +++ b/Doc/Manual/Contents.html @@ -1360,7 +1360,23 @@ -

    33 SWIG and Ruby

    +

    33 SWIG and R

    + + + + + +

    34 SWIG and Ruby

    @@ -1494,7 +1510,7 @@
    -

    34 SWIG and Tcl

    +

    35 SWIG and Tcl

    @@ -1560,22 +1576,6 @@
    -

    35 SWIG and R

    - - - - -

    36 Extending SWIG to support new languages

    diff --git a/Doc/Manual/R.html b/Doc/Manual/R.html index ceea32146..679718400 100644 --- a/Doc/Manual/R.html +++ b/Doc/Manual/R.html @@ -6,7 +6,7 @@ -

    35 SWIG and R

    +

    33 SWIG and R

      @@ -33,7 +33,7 @@ compile and run an R interface to QuantLib running on Mandriva Linux with gcc. The R bindings also work on Microsoft Windows using Visual C++.

      -

      35.1 Bugs

      +

      33.1 Bugs

      @@ -45,7 +45,7 @@ Currently the following features are not implemented or broken:

    • C Array wrappings
    -

    35.2 Using R and SWIG

    +

    33.2 Using R and SWIG

    @@ -119,7 +119,7 @@ Without it, inheritance of wrapped objects may fail. These two files can be loaded in any order

    -

    35.3 Precompiling large R files

    +

    33.3 Precompiling large R files

    In cases where the R file is large, one make save a lot of loading @@ -137,7 +137,7 @@ will save a large amount of loading time. -

    35.4 General policy

    +

    33.4 General policy

    @@ -146,7 +146,7 @@ wrapping over the underlying functions and rely on the R type system to provide R syntax.

    -

    35.5 Language conventions

    +

    33.5 Language conventions

    @@ -155,7 +155,7 @@ and [ are overloaded to allow for R syntax (one based indices and slices)

    -

    35.6 C++ classes

    +

    33.6 C++ classes

    @@ -167,7 +167,7 @@ keep track of the pointer object which removes the necessity for a lot of the proxy class baggage you see in other languages.

    -

    35.7 Enumerations

    +

    33.7 Enumerations

    diff --git a/Doc/Manual/Ruby.html b/Doc/Manual/Ruby.html index bda2af60c..a08f497d5 100644 --- a/Doc/Manual/Ruby.html +++ b/Doc/Manual/Ruby.html @@ -7,7 +7,7 @@ -

    33 SWIG and Ruby

    +

    34 SWIG and Ruby

      @@ -148,7 +148,7 @@ -

      33.1 Preliminaries

      +

      34.1 Preliminaries

      SWIG 1.3 is known to work with Ruby versions 1.6 and later. @@ -171,7 +171,7 @@ of Ruby.

      -

      33.1.1 Running SWIG

      +

      34.1.1 Running SWIG

      To build a Ruby module, run SWIG using the -ruby @@ -225,7 +225,7 @@ to compile this file and link it with the rest of your program.

      -

      33.1.2 Getting the right header files

      +

      34.1.2 Getting the right header files

      In order to compile the wrapper code, the compiler needs the ruby.h @@ -274,7 +274,7 @@ installed, you can run Ruby to find out. For example:

      -

      33.1.3 Compiling a dynamic module

      +

      34.1.3 Compiling a dynamic module

      Ruby extension modules are typically compiled into shared @@ -428,7 +428,7 @@ manual pages for your compiler and linker to determine the correct set of options. You might also check the SWIG Wiki for additional information.

      -

      33.1.4 Using your module

      +

      34.1.4 Using your module

      Ruby module names must be capitalized, @@ -488,7 +488,7 @@ begins with:

      -

      33.1.5 Static linking

      +

      34.1.5 Static linking

      An alternative approach to dynamic linking is to rebuild the @@ -509,7 +509,7 @@ finally rebuilding Ruby.

      -

      33.1.6 Compilation of C++ extensions

      +

      34.1.6 Compilation of C++ extensions

      On most machines, C++ extension modules should be linked @@ -561,7 +561,7 @@ extension, e.g.

      -

      33.2 Building Ruby Extensions under Windows 95/NT

      +

      34.2 Building Ruby Extensions under Windows 95/NT

      Building a SWIG extension to Ruby under Windows 95/NT is @@ -600,7 +600,7 @@ files.

      -

      33.2.1 Running SWIG from Developer Studio

      +

      34.2.1 Running SWIG from Developer Studio

      If you are developing your application within Microsoft @@ -742,7 +742,7 @@ directory, then run the Ruby script from the DOS/Command prompt:

      -

      33.3 The Ruby-to-C/C++ Mapping

      +

      34.3 The Ruby-to-C/C++ Mapping

      This section describes the basics of how SWIG maps C or C++ @@ -752,7 +752,7 @@ declarations in your SWIG interface files to Ruby constructs.

      -

      33.3.1 Modules

      +

      34.3.1 Modules

      The SWIG %module directive specifies @@ -921,7 +921,7 @@ Ruby's built-in names.

      -

      33.3.2 Functions

      +

      34.3.2 Functions

      Global functions are wrapped as Ruby module methods. For @@ -984,7 +984,7 @@ module that can be used like so:

      -

      33.3.3 Variable Linking

      +

      34.3.3 Variable Linking

      C/C++ global variables are wrapped as a pair of singleton @@ -1084,7 +1084,7 @@ effect until it is explicitly disabled using %mutable. -

      33.3.4 Constants

      +

      34.3.4 Constants

      C/C++ constants are wrapped as module constants initialized @@ -1128,7 +1128,7 @@ constant values, e.g.

      -

      33.3.5 Pointers

      +

      34.3.5 Pointers

      "Opaque" pointers to arbitrary C/C++ types (i.e. types that @@ -1180,7 +1180,7 @@ the Ruby nil object.

      -

      33.3.6 Structures

      +

      34.3.6 Structures

      C/C++ structs are wrapped as Ruby classes, with accessor @@ -1355,7 +1355,7 @@ pointers. For example,

      -

      33.3.7 C++ classes

      +

      34.3.7 C++ classes

      Like structs, C++ classes are wrapped by creating a new Ruby @@ -1441,7 +1441,7 @@ class. -

      33.3.8 C++ Inheritance

      +

      34.3.8 C++ Inheritance

      The SWIG type-checker is fully aware of C++ inheritance. @@ -1672,7 +1672,7 @@ Typing").

      -

      33.3.9 C++ Overloaded Functions

      +

      34.3.9 C++ Overloaded Functions

      C++ overloaded functions, methods, and constructors are @@ -1872,7 +1872,7 @@ and C++" chapter for more information about overloading.

      -

      33.3.10 C++ Operators

      +

      34.3.10 C++ Operators

      For the most part, overloaded operators are handled @@ -1953,7 +1953,7 @@ on operator overloading.

      -

      33.3.11 C++ namespaces

      +

      34.3.11 C++ namespaces

      SWIG is aware of C++ namespaces, but namespace names do not @@ -2029,7 +2029,7 @@ identical symbol names, well, then you get what you deserve.

      -

      33.3.12 C++ templates

      +

      34.3.12 C++ templates

      C++ templates don't present a huge problem for SWIG. However, @@ -2073,7 +2073,7 @@ directive. For example:

      -

      33.3.13 C++ Standard Template Library (STL)

      +

      34.3.13 C++ Standard Template Library (STL)

      On a related note, the standard SWIG library contains a @@ -2326,7 +2326,7 @@ chapter.

      -

      33.3.14 C++ STL Functors

      +

      34.3.14 C++ STL Functors

      Some containers in the STL allow you to modify their default @@ -2526,7 +2526,7 @@ b
      -

      33.3.15 C++ STL Iterators

      +

      34.3.15 C++ STL Iterators

      The STL is well known for the use of iterators.  There @@ -2737,7 +2737,7 @@ i
      -

      33.3.16 C++ Smart Pointers

      +

      34.3.16 C++ Smart Pointers

      In certain C++ programs, it is common to use classes that @@ -2862,7 +2862,7 @@ method. For example:

      -

      33.3.17 Cross-Language Polymorphism

      +

      34.3.17 Cross-Language Polymorphism

      SWIG's Ruby module supports cross-language polymorphism @@ -2875,7 +2875,7 @@ using this feature with Ruby.

      -

      33.3.17.1 Exception Unrolling

      +

      34.3.17.1 Exception Unrolling

      Whenever a C++ director class routes one of its virtual @@ -2913,7 +2913,7 @@ caught here and a C++ exception is raised in its place.

      -

      33.4 Naming

      +

      34.4 Naming

      Ruby has several common naming conventions. Constants are @@ -3009,7 +3009,7 @@ planned to become the default option in future releases.

      -

      33.4.1 Defining Aliases

      +

      34.4.1 Defining Aliases

      It's a fairly common practice in the Ruby built-ins and @@ -3101,7 +3101,7 @@ Features") for more details).

      -

      33.4.2 Predicate Methods

      +

      34.4.2 Predicate Methods

      Ruby methods that return a boolean value and end in a @@ -3190,7 +3190,7 @@ Features") for more details).

      -

      33.4.3 Bang Methods

      +

      34.4.3 Bang Methods

      Ruby methods that modify an object in-place and end in an @@ -3254,7 +3254,7 @@ Features") for more details).

      -

      33.4.4 Getters and Setters

      +

      34.4.4 Getters and Setters

      Often times a C++ library will expose properties through @@ -3324,7 +3324,7 @@ methods to be exposed in Ruby as value and value=. -

      33.5 Input and output parameters

      +

      34.5 Input and output parameters

      A common problem in some C programs is handling parameters @@ -3575,10 +3575,10 @@ of %apply

      -

      33.6 Exception handling

      +

      34.6 Exception handling

      -

      33.6.1 Using the %exception directive

      +

      34.6.1 Using the %exception directive

      The SWIG %exception directive can be @@ -3673,7 +3673,7 @@ Features for more examples.

      -

      33.6.2 Handling Ruby Blocks

      +

      34.6.2 Handling Ruby Blocks

      One of the highlights of Ruby and most of its standard library @@ -3854,7 +3854,7 @@ RUBY_YIELD_SELF );

      For more information on typemaps, see Typemaps.

      -

      33.6.3 Raising exceptions

      +

      34.6.3 Raising exceptions

      There are three ways to raise exceptions from C++ code to @@ -4615,7 +4615,7 @@ the built-in Ruby exception types.

      -

      33.6.4 Exception classes

      +

      34.6.4 Exception classes

      Starting with SWIG 1.3.28, the Ruby module supports the %exceptionclass @@ -4673,7 +4673,7 @@ providing for a more natural integration between C++ code and Ruby code.

      -

      33.7 Typemaps

      +

      34.7 Typemaps

      This section describes how you can modify SWIG's default @@ -4696,7 +4696,7 @@ of the primitive C-Ruby interface.

      -

      33.7.1 What is a typemap?

      +

      34.7.1 What is a typemap?

      A typemap is nothing more than a code generation rule that is @@ -4958,7 +4958,7 @@ to be used as follows (notice how the length parameter is omitted):

      -

      33.7.2 Typemap scope

      +

      34.7.2 Typemap scope

      Once defined, a typemap remains in effect for all of the @@ -5006,7 +5006,7 @@ where the class itself is defined. For example:

      -

      33.7.3 Copying a typemap

      +

      34.7.3 Copying a typemap

      A typemap is copied by using assignment. For example:

      @@ -5108,7 +5108,7 @@ rules as for -

      33.7.4 Deleting a typemap

      +

      34.7.4 Deleting a typemap

      A typemap can be deleted by simply defining no code. For @@ -5160,7 +5160,7 @@ typemaps immediately after the clear operation.

      -

      33.7.5 Placement of typemaps

      +

      34.7.5 Placement of typemaps

      Typemap declarations can be declared in the global scope, @@ -5244,7 +5244,7 @@ string -

      33.7.6 Ruby typemaps

      +

      34.7.6 Ruby typemaps

      The following list details all of the typemap methods that @@ -5254,7 +5254,7 @@ can be used by the Ruby module:

      -

      33.7.6.1  "in" typemap

      +

      34.7.6.1  "in" typemap

      Converts Ruby objects to input @@ -5497,7 +5497,7 @@ arguments to be specified. For example:

      -

      33.7.6.2 "typecheck" typemap

      +

      34.7.6.2 "typecheck" typemap

      The "typecheck" typemap is used to support overloaded @@ -5538,7 +5538,7 @@ on "Typemaps and Overloading."

      -

      33.7.6.3  "out" typemap

      +

      34.7.6.3  "out" typemap

      Converts return value of a C function @@ -5770,7 +5770,7 @@ version of the C datatype matched by the typemap. -

      33.7.6.4 "arginit" typemap

      +

      34.7.6.4 "arginit" typemap

      The "arginit" typemap is used to set the initial value of a @@ -5795,7 +5795,7 @@ applications. For example:

      -

      33.7.6.5 "default" typemap

      +

      34.7.6.5 "default" typemap

      The "default" typemap is used to turn an argument into a @@ -5837,7 +5837,7 @@ default argument wrapping.

      -

      33.7.6.6 "check" typemap

      +

      34.7.6.6 "check" typemap

      The "check" typemap is used to supply value checking code @@ -5861,7 +5861,7 @@ arguments have been converted. For example:

      -

      33.7.6.7 "argout" typemap

      +

      34.7.6.7 "argout" typemap

      The "argout" typemap is used to return values from arguments. @@ -6019,7 +6019,7 @@ some function like SWIG_Ruby_AppendOutput.

      -

      33.7.6.8 "freearg" typemap

      +

      34.7.6.8 "freearg" typemap

      The "freearg" typemap is used to cleanup argument data. It is @@ -6055,7 +6055,7 @@ abort prematurely.

      -

      33.7.6.9 "newfree" typemap

      +

      34.7.6.9 "newfree" typemap

      The "newfree" typemap is used in conjunction with the %newobject @@ -6086,7 +6086,7 @@ ownership and %newobject for further details.

      -

      33.7.6.10 "memberin" typemap

      +

      34.7.6.10 "memberin" typemap

      The "memberin" typemap is used to copy data from an @@ -6119,7 +6119,7 @@ other objects.

      -

      33.7.6.11 "varin" typemap

      +

      34.7.6.11 "varin" typemap

      The "varin" typemap is used to convert objects in the target @@ -6130,7 +6130,7 @@ This is implementation specific.

      -

      33.7.6.12 "varout" typemap

      +

      34.7.6.12 "varout" typemap

      The "varout" typemap is used to convert a C/C++ object to an @@ -6141,7 +6141,7 @@ This is implementation specific.

      -

      33.7.6.13 "throws" typemap

      +

      34.7.6.13 "throws" typemap

      The "throws" typemap is only used when SWIG parses a C++ @@ -6200,7 +6200,7 @@ handling with %exception section.

      -

      33.7.6.14 directorin typemap

      +

      34.7.6.14 directorin typemap

      Converts C++ objects in director @@ -6454,7 +6454,7 @@ referring to the class itself. -

      33.7.6.15 directorout typemap

      +

      34.7.6.15 directorout typemap

      Converts Ruby objects in director @@ -6714,7 +6714,7 @@ exception.
      -

      33.7.6.16 directorargout typemap

      +

      34.7.6.16 directorargout typemap

      Output argument processing in director @@ -6954,7 +6954,7 @@ referring to the instance of the class itself -

      33.7.6.17 ret typemap

      +

      34.7.6.17 ret typemap

      Cleanup of function return values @@ -6964,7 +6964,7 @@ referring to the instance of the class itself -

      33.7.6.18 globalin typemap

      +

      34.7.6.18 globalin typemap

      Setting of C global variables @@ -6974,7 +6974,7 @@ referring to the instance of the class itself -

      33.7.7 Typemap variables

      +

      34.7.7 Typemap variables

      @@ -7084,7 +7084,7 @@ being created.

    -

    33.7.8 Useful Functions

    +

    34.7.8 Useful Functions

    When you write a typemap, you usually have to work directly @@ -7108,7 +7108,7 @@ across multiple languages.

    -

    33.7.8.1 C Datatypes to Ruby Objects

    +

    34.7.8.1 C Datatypes to Ruby Objects

    @@ -7164,7 +7164,7 @@ SWIG_From_float(float) -

    33.7.8.2 Ruby Objects to C Datatypes

    +

    34.7.8.2 Ruby Objects to C Datatypes

    Here, while the Ruby versions return the value directly, the SWIG @@ -7253,7 +7253,7 @@ Ruby_Format_TypeError( "$1_name", "$1_type","$symname", $argnum, $input -

    33.7.8.3 Macros for VALUE

    +

    34.7.8.3 Macros for VALUE

    RSTRING_LEN(str)

    @@ -7316,7 +7316,7 @@ Ruby_Format_TypeError( "$1_name", "$1_type","$symname", $argnum, $input -

    33.7.8.4 Exceptions

    +

    34.7.8.4 Exceptions

    void rb_raise(VALUE exception, const char *fmt, @@ -7483,7 +7483,7 @@ arguments are interpreted as with printf().

    -

    33.7.8.5 Iterators

    +

    34.7.8.5 Iterators

    void rb_iter_break()

    @@ -7585,7 +7585,7 @@ VALUE), VALUE value)

    -

    33.7.9 Typemap Examples

    +

    34.7.9 Typemap Examples

    This section includes a few examples of typemaps. For more @@ -7596,7 +7596,7 @@ directory.

    -

    33.7.10 Converting a Ruby array to a char **

    +

    34.7.10 Converting a Ruby array to a char **

    A common problem in many C programs is the processing of @@ -7651,7 +7651,7 @@ after the execution of the C function.

    -

    33.7.11 Collecting arguments in a hash

    +

    34.7.11 Collecting arguments in a hash

    Ruby's solution to the "keyword arguments" capability of some @@ -7930,7 +7930,7 @@ directory of the SWIG distribution.

    -

    33.7.12 Pointer handling

    +

    34.7.12 Pointer handling

    Occasionally, it might be necessary to convert pointer values @@ -8029,7 +8029,7 @@ For example:

    -

    33.7.12.1 Ruby Datatype Wrapping

    +

    34.7.12.1 Ruby Datatype Wrapping

    VALUE Data_Wrap_Struct(VALUE class, void @@ -8080,7 +8080,7 @@ and assigns that pointer to ptr.

    -

    33.7.13 Example: STL Vector to Ruby Array

    +

    34.7.13 Example: STL Vector to Ruby Array

    Another use for macros and type maps is to create a Ruby array @@ -8189,7 +8189,7 @@ the C++ Standard Template Library.
    -

    33.8 Docstring Features

    +

    34.8 Docstring Features

    @@ -8250,7 +8250,7 @@ generate ri documentation from a c wrap file, you could do:

    -

    33.8.1 Module docstring

    +

    34.8.1 Module docstring

    @@ -8301,7 +8301,7 @@ macro. For example: -

    33.8.2 %feature("autodoc")

    +

    34.8.2 %feature("autodoc")

    Since SWIG does know everything about the function it wraps, @@ -8330,7 +8330,7 @@ feature, described below. -

    33.8.2.1 %feature("autodoc", "0")

    +

    34.8.2.1 %feature("autodoc", "0")

    @@ -8378,7 +8378,7 @@ Then Ruby code like this will be generated: -

    33.8.2.2 %feature("autodoc", "1")

    +

    34.8.2.2 %feature("autodoc", "1")

    @@ -8410,7 +8410,7 @@ this: -

    33.8.2.3 %feature("autodoc", "2")

    +

    34.8.2.3 %feature("autodoc", "2")

    @@ -8426,7 +8426,7 @@ this: -

    33.8.2.4 %feature("autodoc", "3")

    +

    34.8.2.4 %feature("autodoc", "3")

    @@ -8454,7 +8454,7 @@ this: -

    33.8.2.5 %feature("autodoc", "docstring")

    +

    34.8.2.5 %feature("autodoc", "docstring")

    @@ -8482,7 +8482,7 @@ generated string. For example: -

    33.8.3 %feature("docstring")

    +

    34.8.3 %feature("docstring")

    @@ -8497,10 +8497,10 @@ docstring and they are output together.

    -

    33.9 Advanced Topics

    +

    34.9 Advanced Topics

    -

    33.9.1 Operator overloading

    +

    34.9.1 Operator overloading

    SWIG allows operator overloading with, by using the %extend @@ -9517,7 +9517,7 @@ parses the expression a != b as !(a == b). -

    33.9.2 Creating Multi-Module Packages

    +

    34.9.2 Creating Multi-Module Packages

    The chapter on Working @@ -9698,7 +9698,7 @@ initialized:

    -

    33.9.3 Specifying Mixin Modules

    +

    34.9.3 Specifying Mixin Modules

    The Ruby language doesn't support multiple inheritance, but @@ -9796,7 +9796,7 @@ Features") for more details).

    -

    33.10 Memory Management

    +

    34.10 Memory Management

    One of the most common issues in generating SWIG bindings for @@ -9843,7 +9843,7 @@ understanding of how the underlying library manages memory.

    -

    33.10.1 Mark and Sweep Garbage Collector

    +

    34.10.1 Mark and Sweep Garbage Collector

    Ruby uses a mark and sweep garbage collector. When the garbage @@ -9891,7 +9891,7 @@ this memory.

    -

    33.10.2 Object Ownership

    +

    34.10.2 Object Ownership

    As described above, memory management depends on clearly @@ -10149,7 +10149,7 @@ public: -

    33.10.3 Object Tracking

    +

    34.10.3 Object Tracking

    The remaining parts of this section will use the class library @@ -10400,7 +10400,7 @@ methods.

    -

    33.10.4 Mark Functions

    +

    34.10.4 Mark Functions

    With a bit more testing, we see that our class library still @@ -10518,7 +10518,7 @@ test suite.

    -

    33.10.5 Free Functions

    +

    34.10.5 Free Functions

    By default, SWIG creates a "free" function that is called when @@ -10768,7 +10768,7 @@ been freed, and thus raises a runtime exception.

    -

    33.10.6 Embedded Ruby and the C++ Stack

    +

    34.10.6 Embedded Ruby and the C++ Stack

    As has been said, the Ruby GC runs and marks objects before diff --git a/Doc/Manual/Sections.html b/Doc/Manual/Sections.html index 74d821b17..05282f40c 100644 --- a/Doc/Manual/Sections.html +++ b/Doc/Manual/Sections.html @@ -19,7 +19,7 @@ Last update : SWIG-2.0.1 (4 October 2010)

  • SWIG Basics (Read this!)
  • SWIG and C++
  • The SWIG preprocessor
  • -
  • The SWIG Library
  • +
  • The SWIG library
  • Argument handling
  • Typemaps
  • Customization features
  • @@ -39,8 +39,8 @@ Last update : SWIG-2.0.1 (4 October 2010)
  • Go support
  • Guile support
  • Java support
  • -
  • Lua support
  • Common Lisp support
  • +
  • Lua support
  • Modula3 support
  • MzScheme support
  • Ocaml support
  • @@ -49,8 +49,8 @@ Last update : SWIG-2.0.1 (4 October 2010)
  • PHP support
  • Pike support
  • Python support
  • -
  • Ruby support
  • R support
  • +
  • Ruby support
  • Tcl support
  • diff --git a/Doc/Manual/Tcl.html b/Doc/Manual/Tcl.html index d47dae5de..7a4a85de9 100644 --- a/Doc/Manual/Tcl.html +++ b/Doc/Manual/Tcl.html @@ -6,7 +6,7 @@ -

    34 SWIG and Tcl

    +

    35 SWIG and Tcl

      @@ -83,7 +83,7 @@ Tcl 8.0 or a later release. Earlier releases of SWIG supported Tcl 7.x, but this is no longer supported.

      -

      34.1 Preliminaries

      +

      35.1 Preliminaries

      @@ -109,7 +109,7 @@ build a Tcl extension module. To finish building the module, you need to compile this file and link it with the rest of your program.

      -

      34.1.1 Getting the right header files

      +

      35.1.1 Getting the right header files

      @@ -127,7 +127,7 @@ this is the case, you should probably make a symbolic link so that tcl.h -

      34.1.2 Compiling a dynamic module

      +

      35.1.2 Compiling a dynamic module

      @@ -162,7 +162,7 @@ The name of the module is specified using the %module directive or the -module command line option.

      -

      34.1.3 Static linking

      +

      35.1.3 Static linking

      @@ -228,7 +228,7 @@ minimal in most situations (and quite frankly not worth the extra hassle in the opinion of this author).

      -

      34.1.4 Using your module

      +

      35.1.4 Using your module

      @@ -356,7 +356,7 @@ to the default system configuration (this requires root access and you will need the man pages).

      -

      34.1.5 Compilation of C++ extensions

      +

      35.1.5 Compilation of C++ extensions

      @@ -439,7 +439,7 @@ erratic program behavior. If working with lots of software components, you might want to investigate using a more formal standard such as COM.

      -

      34.1.6 Compiling for 64-bit platforms

      +

      35.1.6 Compiling for 64-bit platforms

      @@ -466,7 +466,7 @@ also introduce problems on platforms that support more than one linking standard (e.g., -o32 and -n32 on Irix).

      -

      34.1.7 Setting a package prefix

      +

      35.1.7 Setting a package prefix

      @@ -485,7 +485,7 @@ option will append the prefix to the name when creating a command and call it "Foo_bar".

      -

      34.1.8 Using namespaces

      +

      35.1.8 Using namespaces

      @@ -507,7 +507,7 @@ When the -namespace option is used, objects in the module are always accessed with the namespace name such as Foo::bar.

      -

      34.2 Building Tcl/Tk Extensions under Windows 95/NT

      +

      35.2 Building Tcl/Tk Extensions under Windows 95/NT

      @@ -518,7 +518,7 @@ covers the process of using SWIG with Microsoft Visual C++. although the procedure may be similar with other compilers.

      -

      34.2.1 Running SWIG from Developer Studio

      +

      35.2.1 Running SWIG from Developer Studio

      @@ -576,7 +576,7 @@ MSDOS > tclsh80 %

    -

    34.2.2 Using NMAKE

    +

    35.2.2 Using NMAKE

    @@ -639,7 +639,7 @@ to get you started. With a little practice, you'll be making lots of Tcl extensions.

    -

    34.3 A tour of basic C/C++ wrapping

    +

    35.3 A tour of basic C/C++ wrapping

    @@ -650,7 +650,7 @@ classes. This section briefly covers the essential aspects of this wrapping.

    -

    34.3.1 Modules

    +

    35.3.1 Modules

    @@ -684,7 +684,7 @@ To fix this, supply an extra argument to load like this: -

    34.3.2 Functions

    +

    35.3.2 Functions

    @@ -709,7 +709,7 @@ like you think it does: % -

    34.3.3 Global variables

    +

    35.3.3 Global variables

    @@ -789,7 +789,7 @@ extern char *path; // Read-only (due to %immutable) -

    34.3.4 Constants and enums

    +

    35.3.4 Constants and enums

    @@ -873,7 +873,7 @@ When an identifier name is given, it is used to perform an implicit hash-table l conversion. This allows the global statement to be omitted.

    -

    34.3.5 Pointers

    +

    35.3.5 Pointers

    @@ -969,7 +969,7 @@ C-style cast may return a bogus result whereas as the C++-style cast will return None if the conversion can't be performed.

    -

    34.3.6 Structures

    +

    35.3.6 Structures

    @@ -1251,7 +1251,7 @@ Note: Tcl only destroys the underlying object if it has ownership. See the memory management section that appears shortly.

    -

    34.3.7 C++ classes

    +

    35.3.7 C++ classes

    @@ -1318,7 +1318,7 @@ In Tcl, the static member is accessed as follows: -

    34.3.8 C++ inheritance

    +

    35.3.8 C++ inheritance

    @@ -1367,7 +1367,7 @@ For instance: It is safe to use multiple inheritance with SWIG.

    -

    34.3.9 Pointers, references, values, and arrays

    +

    35.3.9 Pointers, references, values, and arrays

    @@ -1421,7 +1421,7 @@ to hold the result and a pointer is returned (Tcl will release this memory when the return value is garbage collected).

    -

    34.3.10 C++ overloaded functions

    +

    35.3.10 C++ overloaded functions

    @@ -1544,7 +1544,7 @@ first declaration takes precedence. Please refer to the "SWIG and C++" chapter for more information about overloading.

    -

    34.3.11 C++ operators

    +

    35.3.11 C++ operators

    @@ -1646,7 +1646,7 @@ There are ways to make this operator appear as part of the class using the % Keep reading.

    -

    34.3.12 C++ namespaces

    +

    35.3.12 C++ namespaces

    @@ -1710,7 +1710,7 @@ utilizes thousands of small deeply nested namespaces each with identical symbol names, well, then you get what you deserve.

    -

    34.3.13 C++ templates

    +

    35.3.13 C++ templates

    @@ -1762,7 +1762,7 @@ More details can be found in the SWIG and C++ -

    34.3.14 C++ Smart Pointers

    +

    35.3.14 C++ Smart Pointers

    @@ -1846,7 +1846,7 @@ simply use the __deref__() method. For example: -

    34.4 Further details on the Tcl class interface

    +

    35.4 Further details on the Tcl class interface

    @@ -1859,7 +1859,7 @@ of low-level details were omitted. This section provides a brief overview of how the proxy classes work.

    -

    34.4.1 Proxy classes

    +

    35.4.1 Proxy classes

    @@ -1924,7 +1924,7 @@ function. This allows objects to be encapsulated objects that look a lot like as shown in the last section.

    -

    34.4.2 Memory management

    +

    35.4.2 Memory management

    @@ -2112,7 +2112,7 @@ typemaps--an advanced topic discussed later.

    -

    34.5 Input and output parameters

    +

    35.5 Input and output parameters

    @@ -2300,7 +2300,7 @@ set c [lindex $dim 1] -

    34.6 Exception handling

    +

    35.6 Exception handling

    @@ -2434,7 +2434,7 @@ Since SWIG's exception handling is user-definable, you are not limited to C++ ex See the chapter on "Customization Features" for more examples.

    -

    34.7 Typemaps

    +

    35.7 Typemaps

    @@ -2451,7 +2451,7 @@ Typemaps are only used if you want to change some aspect of the primitive C-Tcl interface.

    -

    34.7.1 What is a typemap?

    +

    35.7.1 What is a typemap?

    @@ -2568,7 +2568,7 @@ parameter is omitted): -

    34.7.2 Tcl typemaps

    +

    35.7.2 Tcl typemaps

    @@ -2706,7 +2706,7 @@ Initialize an argument to a value before any conversions occur. Examples of these methods will appear shortly.

    -

    34.7.3 Typemap variables

    +

    35.7.3 Typemap variables

    @@ -2777,7 +2777,7 @@ properly assigned. The Tcl name of the wrapper function being created. -

    34.7.4 Converting a Tcl list to a char **

    +

    35.7.4 Converting a Tcl list to a char **

    @@ -2839,7 +2839,7 @@ argv[2] = Larry 3 -

    34.7.5 Returning values in arguments

    +

    35.7.5 Returning values in arguments

    @@ -2881,7 +2881,7 @@ result, a Tcl function using these typemaps will work like this : % -

    34.7.6 Useful functions

    +

    35.7.6 Useful functions

    @@ -2958,7 +2958,7 @@ int Tcl_IsShared(Tcl_Obj *obj); -

    34.7.7 Standard typemaps

    +

    35.7.7 Standard typemaps

    @@ -3042,7 +3042,7 @@ work) -

    34.7.8 Pointer handling

    +

    35.7.8 Pointer handling

    @@ -3118,7 +3118,7 @@ For example: -

    34.8 Turning a SWIG module into a Tcl Package.

    +

    35.8 Turning a SWIG module into a Tcl Package.

    @@ -3190,7 +3190,7 @@ As a final note, most SWIG examples do not yet use the to use the load command instead.

    -

    34.9 Building new kinds of Tcl interfaces (in Tcl)

    +

    35.9 Building new kinds of Tcl interfaces (in Tcl)

    @@ -3289,7 +3289,7 @@ danger of blowing something up (although it is easily accomplished with an out of bounds array access).

    -

    34.9.1 Proxy classes

    +

    35.9.1 Proxy classes

    @@ -3410,7 +3410,7 @@ short, but clever Tcl script can be combined with SWIG to do many interesting things.

    -

    34.10 Tcl/Tk Stubs

    +

    35.10 Tcl/Tk Stubs

    diff --git a/Doc/Manual/chapters b/Doc/Manual/chapters index 014029c74..e918e234a 100644 --- a/Doc/Manual/chapters +++ b/Doc/Manual/chapters @@ -30,7 +30,7 @@ Perl5.html Php.html Pike.html Python.html +R.html Ruby.html Tcl.html -R.html Extending.html -- cgit v1.2.1 From 0d49656a54ebb80d488b1d60c702b10c857b3340 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Mon, 4 Oct 2010 18:44:38 +0000 Subject: minor tweak to release notes git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12253 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- RELEASENOTES | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/RELEASENOTES b/RELEASENOTES index e8ff30285..e07b8a14a 100644 --- a/RELEASENOTES +++ b/RELEASENOTES @@ -6,7 +6,7 @@ Release Notes ============= SWIG-2.0.1 summary: -- New language module: Go +- Go language added to list of supported languages. - New regular expression (regex) encoder for renaming symbols based on the Perl Compatible Regular Expressions (PCRE) library. - Numerous fixes in reporting file and line numbers in error and warning -- cgit v1.2.1 From 2e4cff569953a1eefd4e47d80ca1b1e10afd643b Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Mon, 4 Oct 2010 19:16:12 +0000 Subject: minor tweak to release notes git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12254 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- RELEASENOTES | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/RELEASENOTES b/RELEASENOTES index e07b8a14a..829cd4d03 100644 --- a/RELEASENOTES +++ b/RELEASENOTES @@ -6,7 +6,7 @@ Release Notes ============= SWIG-2.0.1 summary: -- Go language added to list of supported languages. +- Support for the Go language has been added. - New regular expression (regex) encoder for renaming symbols based on the Perl Compatible Regular Expressions (PCRE) library. - Numerous fixes in reporting file and line numbers in error and warning -- cgit v1.2.1 From 9b3d2ec9b0c7a02b9e85058821cb820057544851 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Mon, 4 Oct 2010 19:30:15 +0000 Subject: Add missing Go language CHANGES entry git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12255 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- CHANGES.current | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGES.current b/CHANGES.current index 9b02c475f..bbaf8443a 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -175,6 +175,9 @@ Version 2.0.1 (4 October 2010) Fix #3024875 - shared_ptr of classes with non-public destructors. This also fixes the "unref" feature when used on classes with non-public destructors. +2010-06-17: ianlancetaylor + [Go] Add the Go language module. + 2010-06-10: wsfulton [Lua] Fix SWIG_lua_isnilstring multiply defined when using multiple modules and wrapping strings. Patch from 'Number Cruncher'. -- cgit v1.2.1 From aabd75f3d83b365850e3c1c4fa77a471b2231914 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Mon, 4 Oct 2010 19:30:53 +0000 Subject: New major contributors git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12256 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- COPYRIGHT | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/COPYRIGHT b/COPYRIGHT index 40d09a1d6..1e5d080d4 100644 --- a/COPYRIGHT +++ b/COPYRIGHT @@ -42,7 +42,7 @@ Past SWIG developers and major contributors include: Tiger Feng (songyanf@cs.uchicago.edu) (SWIG core) Mark Rose (mrose@stm.lbl.gov) (Directors) Jonah Beckford (beckford@usermail.com) (CHICKEN) - Ahmon Dancy (dancy@franz.com) (Allegro CL) + Ahmon Dancy (dancy@franz.com) (Allegro CL) Dirk Gerrits (Allegro CL) Neil Cawse (C#) Harco de Hilster (Java) @@ -55,6 +55,8 @@ Past SWIG developers and major contributors include: Mark Gossage (mark@gossage.cjb.net) (Lua) Gonzalo Garramuno (ggarra@advancedsl.com.ar) (Ruby, Ruby's UTL) John Lenz (Guile, MzScheme updates, Chicken module, runtime system) + Ian Lance Taylor (Go) + Vadim Zeitlin (PCRE) Past contributors include: James Michael DuPont, Clark McGrew, Dustin Mitchell, Ian Cooke, Catalin Dumitrescu, Baran -- cgit v1.2.1 From a56ee9cb1bcdea85480e2678aff97c14c9aa1856 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Tue, 5 Oct 2010 06:11:50 +0000 Subject: Bump version to 2.0.2 and move CHANGES.current to CHANGES git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12260 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- ANNOUNCE | 2 +- CHANGES | 189 +++++++++++++++++++++++++++++++++++++++++++++++ CHANGES.current | 189 +---------------------------------------------- Doc/Manual/Sections.html | 2 +- README | 2 +- configure.in | 2 +- 6 files changed, 195 insertions(+), 191 deletions(-) diff --git a/ANNOUNCE b/ANNOUNCE index d14a77042..cdf246e07 100644 --- a/ANNOUNCE +++ b/ANNOUNCE @@ -1,4 +1,4 @@ -*** ANNOUNCE: SWIG 2.0.1 (4 October 2010) *** +*** ANNOUNCE: SWIG 2.0.2 (in progress) *** http://www.swig.org diff --git a/CHANGES b/CHANGES index f243ff7c6..bf5e20da1 100644 --- a/CHANGES +++ b/CHANGES @@ -3,6 +3,195 @@ SWIG (Simplified Wrapper and Interface Generator) See the CHANGES.current file for changes in the current version. See the RELEASENOTES file for a summary of changes in each release. +Version 2.0.1 (4 October 2010) +============================== + +2010-10-03: wsfulton + Apply patch #3066958 from Mikael Johansson to fix default smart pointer + handling when the smart pointer contains both a const and non-const operator->. + +2010-10-01: wsfulton + Add -pcreversion option to display PCRE version information. + +2010-10-01: olly + [Ruby] Avoid segfault when a method node has no parentNode + (SF#3034054). + +2010-10-01: olly + [Python] Allow reinitialisation to work with an embedded Python + interpreter (patch from Jim Carroll in SF#3075178). + +2010-09-28: wsfulton + [C#] Apply patch from Tomas Dirvanauskas for std::map wrappers to avoid + throwing exceptions with normal usage of iterators. + +2010-09-27: olly + [Python] Improve error message given when a parameter of the wrong + type is passed to an overloaded method (SF#3027355). + +2010-09-25: wsfulton + Apply SF patch #3075150 - Java directors using static variables in + named namespace. + +2010-09-24: wsfulton + More file and line error/warning reporting fixes where SWIG macros + are used within {} braces (where the preprocessor expands macros), + for example macros within %inline {...} and %fragment(...) {...} + and nested structs. + +2010-09-18: wsfulton + More file and line error/warning reporting fixes for various inherited + class problems. + +2010-09-15: wsfulton + A much improved debugging of SWIG source experience is now available and + documented in the "Debugging SWIG" section in the Doc/Devel/internals.html + file, including a swig.dbg support file for the gdb debugger. + +2010-09-11: wsfulton + Fix incorrect line number reporting in errors/warnings when a macro + definition ends with '/' and it is not the end of a C comment. + +2010-09-11: wsfulton + Fix incorrect line number reporting in errors/warnings after parsing + macro invocations with parameters given over more than one line. + +2010-09-10: wsfulton + Remove extraneous extra line in preprocessed output after including files + which would sometimes lead to error/warning messages two lines after the + end of the file. + +2010-09-10: wsfulton + Fix #2149523 - Incorrect line number reporting in errors after parsing macros + containing C++ comments. + +2010-09-08: olly + [PHP] Fix handling of OUTPUT typemaps (Patch from Ryan in SF#3058394). + +2010-09-03: wsfulton + Fix erroneous line numbers in error messages for macro expansions, for example, + the error message now points to instantiation of the macro, ie the last line here: + + #define MACRO2(a, b) + + #define MACRO1(NAME) MACRO2(NAME,2,3) + + MACRO1(abc) + +2010-09-02: wsfulton + Fix line numbers in error and warning messages for preprocessor messages within + %inline, for example: + + %inline %{ + #define FOOBAR 1 + #define FOOBAR "hi" + %} + +2010-09-02: wsfulton + Fix line numbers in error and warning messages which were cumulatively one + less than they should have been after parsing each %include/%import - bug + introduced in swig-1.3.32. Also fix line numbers in error and warning messages + when new line characters appear between the %include / %import statement and + the filename. + +2010-08-30: wsfulton + Fix line number and file name reporting for some macro preprocessor warnings. + The line number of the macro argument has been corrected and the line number + of the start of the macro instead of one past the end of the macro is used. + Some examples: + file.h:11: Error: Illegal macro argument name '..' + file.h:19: Error: Macro 'DUPLICATE' redefined, + file.h:15: Error: previous definition of 'DUPLICATE'. + file.h:25: Error: Variable-length macro argument must be last parameter + file.h:32: Error: Illegal character in macro argument name + file.i:37: Error: Macro 'SIT' expects 2 arguments + +2010-08-26: wsfulton + Fix __LINE__ and __FILE__ expansion reported by Camille Gillot. Mostly this + did not work at all. Also fixes SF #2822822. + +2010-08-17: wsfulton + [Perl] Fix corner case marshalling of doubles - errno was not being correctly + set before calling strtod - patch from Justin Vallon - SF Bug #3038936. + +2010-08-17: wsfulton + Fix make distclean when some of the more obscure languages are detected by + configure - fixes from Torsten Landschoff. + +2010-07-28: wsfulton + Restore configuring out of source for the test-suite since it broke in 1.3.37. + As previously, if running 'make check-test-suite' out of source, it needs to be + done by invoking configure with a relative path. Invoking configure with an + absolute path will not work. Running the full 'make check' still needs to be + done in the source tree. + +2010-07-16: wsfulton + Fix wrapping of function pointers and member function pointers when the function + returns by reference. + +2010-07-13: vadz + Removed support for the old experimental "rxspencer" encoder and + "[not]rxsmatch" in %rename (see the 01/16/2006 entry). The new and + officially supported "regex" encoder and "[not]regexmatch" checks + should be used instead (see the two previous entries). Please + replace "%(rxspencer:[pat][subst])s" with "%(regex:/pat/subst/)s" + when upgrading. Notice that you will also need to replace the back- + references of form "@1" with the more standard "\\1" and may need to + adjust your regular expressions syntax as the new regex encoder uses + Perl-compatible syntax and not (extended) POSIX syntax as the old one. + + *** POTENTIAL INCOMPATIBILITY *** + +2010-07-13: vadz + Add "regexmatch", "regextarget" and "notregexmatch" which can be + used to apply %rename directives to the declarations matching the + specified regular expression only. The first two can be used + interchangeably, both of the %renames below do the same thing: + + %rename("$ignore", regexmatch$name="Old$") ""; + %rename("$ignore", regextarget=1) "Old$"; + + (namely ignore the declarations having "Old" suffix). + + "notregexmatch" restricts the match to only the declarations which + do not match the regular expression, e.g. here is how to rename to + lower case versions all declarations except those consisting from + capital letters only: + + %rename("$(lowercase)s", notregexmatch$name="^[A-Z]+$") ""; + +2010-07-13: vadz + Add the new "regex" encoder that can be used in %rename, e.g. + + %rename("regex:/(\\w+)_(.*)/\\2/") ""; + + to remove any alphabetical prefix from all identifiers. The syntax + of the regular expressions is Perl-like and PCRE library + (http://www.pcre.org/) is used to implement this feature but notice + that backslashes need to be escaped as usual inside C strings. + + Original patch from Torsten Landschoff. + +2010-07-08: wsfulton + Fix #3024875 - shared_ptr of classes with non-public destructors. This also fixes + the "unref" feature when used on classes with non-public destructors. + +2010-06-17: ianlancetaylor + [Go] Add the Go language module. + +2010-06-10: wsfulton + [Lua] Fix SWIG_lua_isnilstring multiply defined when using multiple + modules and wrapping strings. Patch from 'Number Cruncher'. + +2010-06-10: olly + [PHP] Fix directors to correctly call a method with has a + different name in PHP to C++ (we were always using the C++ name + in this case). + +2010-06-03: wsfulton + Fix uncompileable code when %rename results in two enum items + with the same name. Reported by Vadim Zeitlin. + Version 2.0.0 (2 June 2010) =========================== diff --git a/CHANGES.current b/CHANGES.current index bbaf8443a..26977a25d 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -2,191 +2,6 @@ This file contains the changes for the current release. See the CHANGES file for changes in older releases. See the RELEASENOTES file for a summary of changes in each release. -Version 2.0.1 (4 October 2010) -============================== +Version 2.0.2 (in progress) +=========================== -2010-10-03: wsfulton - Apply patch #3066958 from Mikael Johansson to fix default smart pointer - handling when the smart pointer contains both a const and non-const operator->. - -2010-10-01: wsfulton - Add -pcreversion option to display PCRE version information. - -2010-10-01: olly - [Ruby] Avoid segfault when a method node has no parentNode - (SF#3034054). - -2010-10-01: olly - [Python] Allow reinitialisation to work with an embedded Python - interpreter (patch from Jim Carroll in SF#3075178). - -2010-09-28: wsfulton - [C#] Apply patch from Tomas Dirvanauskas for std::map wrappers to avoid - throwing exceptions with normal usage of iterators. - -2010-09-27: olly - [Python] Improve error message given when a parameter of the wrong - type is passed to an overloaded method (SF#3027355). - -2010-09-25: wsfulton - Apply SF patch #3075150 - Java directors using static variables in - named namespace. - -2010-09-24: wsfulton - More file and line error/warning reporting fixes where SWIG macros - are used within {} braces (where the preprocessor expands macros), - for example macros within %inline {...} and %fragment(...) {...} - and nested structs. - -2010-09-18: wsfulton - More file and line error/warning reporting fixes for various inherited - class problems. - -2010-09-15: wsfulton - A much improved debugging of SWIG source experience is now available and - documented in the "Debugging SWIG" section in the Doc/Devel/internals.html - file, including a swig.dbg support file for the gdb debugger. - -2010-09-11: wsfulton - Fix incorrect line number reporting in errors/warnings when a macro - definition ends with '/' and it is not the end of a C comment. - -2010-09-11: wsfulton - Fix incorrect line number reporting in errors/warnings after parsing - macro invocations with parameters given over more than one line. - -2010-09-10: wsfulton - Remove extraneous extra line in preprocessed output after including files - which would sometimes lead to error/warning messages two lines after the - end of the file. - -2010-09-10: wsfulton - Fix #2149523 - Incorrect line number reporting in errors after parsing macros - containing C++ comments. - -2010-09-08: olly - [PHP] Fix handling of OUTPUT typemaps (Patch from Ryan in SF#3058394). - -2010-09-03: wsfulton - Fix erroneous line numbers in error messages for macro expansions, for example, - the error message now points to instantiation of the macro, ie the last line here: - - #define MACRO2(a, b) - - #define MACRO1(NAME) MACRO2(NAME,2,3) - - MACRO1(abc) - -2010-09-02: wsfulton - Fix line numbers in error and warning messages for preprocessor messages within - %inline, for example: - - %inline %{ - #define FOOBAR 1 - #define FOOBAR "hi" - %} - -2010-09-02: wsfulton - Fix line numbers in error and warning messages which were cumulatively one - less than they should have been after parsing each %include/%import - bug - introduced in swig-1.3.32. Also fix line numbers in error and warning messages - when new line characters appear between the %include / %import statement and - the filename. - -2010-08-30: wsfulton - Fix line number and file name reporting for some macro preprocessor warnings. - The line number of the macro argument has been corrected and the line number - of the start of the macro instead of one past the end of the macro is used. - Some examples: - file.h:11: Error: Illegal macro argument name '..' - file.h:19: Error: Macro 'DUPLICATE' redefined, - file.h:15: Error: previous definition of 'DUPLICATE'. - file.h:25: Error: Variable-length macro argument must be last parameter - file.h:32: Error: Illegal character in macro argument name - file.i:37: Error: Macro 'SIT' expects 2 arguments - -2010-08-26: wsfulton - Fix __LINE__ and __FILE__ expansion reported by Camille Gillot. Mostly this - did not work at all. Also fixes SF #2822822. - -2010-08-17: wsfulton - [Perl] Fix corner case marshalling of doubles - errno was not being correctly - set before calling strtod - patch from Justin Vallon - SF Bug #3038936. - -2010-08-17: wsfulton - Fix make distclean when some of the more obscure languages are detected by - configure - fixes from Torsten Landschoff. - -2010-07-28: wsfulton - Restore configuring out of source for the test-suite since it broke in 1.3.37. - As previously, if running 'make check-test-suite' out of source, it needs to be - done by invoking configure with a relative path. Invoking configure with an - absolute path will not work. Running the full 'make check' still needs to be - done in the source tree. - -2010-07-16: wsfulton - Fix wrapping of function pointers and member function pointers when the function - returns by reference. - -2010-07-13: vadz - Removed support for the old experimental "rxspencer" encoder and - "[not]rxsmatch" in %rename (see the 01/16/2006 entry). The new and - officially supported "regex" encoder and "[not]regexmatch" checks - should be used instead (see the two previous entries). Please - replace "%(rxspencer:[pat][subst])s" with "%(regex:/pat/subst/)s" - when upgrading. Notice that you will also need to replace the back- - references of form "@1" with the more standard "\\1" and may need to - adjust your regular expressions syntax as the new regex encoder uses - Perl-compatible syntax and not (extended) POSIX syntax as the old one. - - *** POTENTIAL INCOMPATIBILITY *** - -2010-07-13: vadz - Add "regexmatch", "regextarget" and "notregexmatch" which can be - used to apply %rename directives to the declarations matching the - specified regular expression only. The first two can be used - interchangeably, both of the %renames below do the same thing: - - %rename("$ignore", regexmatch$name="Old$") ""; - %rename("$ignore", regextarget=1) "Old$"; - - (namely ignore the declarations having "Old" suffix). - - "notregexmatch" restricts the match to only the declarations which - do not match the regular expression, e.g. here is how to rename to - lower case versions all declarations except those consisting from - capital letters only: - - %rename("$(lowercase)s", notregexmatch$name="^[A-Z]+$") ""; - -2010-07-13: vadz - Add the new "regex" encoder that can be used in %rename, e.g. - - %rename("regex:/(\\w+)_(.*)/\\2/") ""; - - to remove any alphabetical prefix from all identifiers. The syntax - of the regular expressions is Perl-like and PCRE library - (http://www.pcre.org/) is used to implement this feature but notice - that backslashes need to be escaped as usual inside C strings. - - Original patch from Torsten Landschoff. - -2010-07-08: wsfulton - Fix #3024875 - shared_ptr of classes with non-public destructors. This also fixes - the "unref" feature when used on classes with non-public destructors. - -2010-06-17: ianlancetaylor - [Go] Add the Go language module. - -2010-06-10: wsfulton - [Lua] Fix SWIG_lua_isnilstring multiply defined when using multiple - modules and wrapping strings. Patch from 'Number Cruncher'. - -2010-06-10: olly - [PHP] Fix directors to correctly call a method with has a - different name in PHP to C++ (we were always using the C++ name - in this case). - -2010-06-03: wsfulton - Fix uncompileable code when %rename results in two enum items - with the same name. Reported by Vadim Zeitlin. diff --git a/Doc/Manual/Sections.html b/Doc/Manual/Sections.html index 05282f40c..855244790 100644 --- a/Doc/Manual/Sections.html +++ b/Doc/Manual/Sections.html @@ -6,7 +6,7 @@

    SWIG-2.0 Documentation

    -Last update : SWIG-2.0.1 (4 October 2010) +Last update : SWIG-2.0.2 (in progress)

    Sections

    diff --git a/README b/README index 085fafd7e..975870626 100644 --- a/README +++ b/README @@ -1,6 +1,6 @@ SWIG (Simplified Wrapper and Interface Generator) -Version: 2.0.1 (4 October 2010) +Version: 2.0.2 (in progress) Tagline: SWIG is a compiler that integrates C and C++ with languages including Perl, Python, Tcl, Ruby, PHP, Java, Ocaml, Lua, diff --git a/configure.in b/configure.in index 2976aca66..36337b41d 100644 --- a/configure.in +++ b/configure.in @@ -2,7 +2,7 @@ dnl Process this file with autoconf to produce a configure script. dnl The macros which aren't shipped with the autotools are stored in the dnl Tools/config directory in .m4 files. -AC_INIT([swig],[2.0.1],[http://www.swig.org]) +AC_INIT([swig],[2.0.2],[http://www.swig.org]) dnl NB: When this requirement is increased to 2.60 or later, AC_PROG_SED dnl definition below can be removed -- cgit v1.2.1 From a4a56acd33cae770a6aacba0df72a6147b611aa1 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Thu, 7 Oct 2010 06:06:12 +0000 Subject: dos to unix fileformatting git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12261 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Lib/csharp/wchar.i | 204 ++++++++++++++++++++++++++--------------------------- 1 file changed, 102 insertions(+), 102 deletions(-) diff --git a/Lib/csharp/wchar.i b/Lib/csharp/wchar.i index f02c09a53..1d95edded 100644 --- a/Lib/csharp/wchar.i +++ b/Lib/csharp/wchar.i @@ -1,102 +1,102 @@ -/* ----------------------------------------------------------------------------- - * wchar.i - * - * Typemaps for the wchar_t type - * These are mapped to a C# String and are passed around by value. - * - * Support code for wide strings can be turned off by defining SWIG_CSHARP_NO_WSTRING_HELPER - * - * ----------------------------------------------------------------------------- */ - -#if !defined(SWIG_CSHARP_NO_WSTRING_HELPER) -#if !defined(SWIG_CSHARP_WSTRING_HELPER_) -#define SWIG_CSHARP_WSTRING_HELPER_ -%insert(runtime) %{ -/* Callback for returning strings to C# without leaking memory */ -typedef void * (SWIGSTDCALL* SWIG_CSharpWStringHelperCallback)(const wchar_t *); -static SWIG_CSharpWStringHelperCallback SWIG_csharp_wstring_callback = NULL; -%} - -%pragma(csharp) imclasscode=%{ - protected class SWIGWStringHelper { - - public delegate string SWIGWStringDelegate(IntPtr message); - static SWIGWStringDelegate wstringDelegate = new SWIGWStringDelegate(CreateWString); - - [DllImport("$dllimport", EntryPoint="SWIGRegisterWStringCallback_$module")] - public static extern void SWIGRegisterWStringCallback_$module(SWIGWStringDelegate wstringDelegate); - - static string CreateWString([MarshalAs(UnmanagedType.LPWStr)]IntPtr cString) { - return System.Runtime.InteropServices.Marshal.PtrToStringUni(cString); - } - - static SWIGWStringHelper() { - SWIGRegisterWStringCallback_$module(wstringDelegate); - } - } - - static protected SWIGWStringHelper swigWStringHelper = new SWIGWStringHelper(); -%} - -%insert(runtime) %{ -#ifdef __cplusplus -extern "C" -#endif -SWIGEXPORT void SWIGSTDCALL SWIGRegisterWStringCallback_$module(SWIG_CSharpWStringHelperCallback callback) { - SWIG_csharp_wstring_callback = callback; -} -%} -#endif // SWIG_CSHARP_WSTRING_HELPER_ -#endif // SWIG_CSHARP_NO_WSTRING_HELPER - - -// wchar_t -%typemap(ctype) wchar_t "wchar_t" -%typemap(imtype) wchar_t "char" -%typemap(cstype) wchar_t "char" - -%typemap(csin) wchar_t "$csinput" -%typemap(csout, excode=SWIGEXCODE) wchar_t { - char ret = $imcall;$excode - return ret; - } -%typemap(csvarin, excode=SWIGEXCODE2) wchar_t %{ - set { - $imcall;$excode - } %} -%typemap(csvarout, excode=SWIGEXCODE2) wchar_t %{ - get { - char ret = $imcall;$excode - return ret; - } %} - -%typemap(in) wchar_t %{ $1 = ($1_ltype)$input; %} -%typemap(out) wchar_t %{ $result = (wchar_t)$1; %} - -%typemap(typecheck) wchar_t = char; - -// wchar_t * -%typemap(ctype) wchar_t * "wchar_t *" -%typemap(imtype, inattributes="[MarshalAs(UnmanagedType.LPWStr)]", out="IntPtr" ) wchar_t * "string" -%typemap(cstype) wchar_t * "string" - -%typemap(csin) wchar_t * "$csinput" -%typemap(csout, excode=SWIGEXCODE) wchar_t * { - string ret = System.Runtime.InteropServices.Marshal.PtrToStringUni($imcall);$excode - return ret; - } -%typemap(csvarin, excode=SWIGEXCODE2) wchar_t * %{ - set { - $imcall;$excode - } %} -%typemap(csvarout, excode=SWIGEXCODE2) wchar_t * %{ - get { - string ret = $imcall;$excode - return ret; - } %} - -%typemap(in) wchar_t * %{ $1 = ($1_ltype)$input; %} -%typemap(out) wchar_t * %{ $result = (wchar_t *)$1; %} - -%typemap(typecheck) wchar_t * = char *; - +/* ----------------------------------------------------------------------------- + * wchar.i + * + * Typemaps for the wchar_t type + * These are mapped to a C# String and are passed around by value. + * + * Support code for wide strings can be turned off by defining SWIG_CSHARP_NO_WSTRING_HELPER + * + * ----------------------------------------------------------------------------- */ + +#if !defined(SWIG_CSHARP_NO_WSTRING_HELPER) +#if !defined(SWIG_CSHARP_WSTRING_HELPER_) +#define SWIG_CSHARP_WSTRING_HELPER_ +%insert(runtime) %{ +/* Callback for returning strings to C# without leaking memory */ +typedef void * (SWIGSTDCALL* SWIG_CSharpWStringHelperCallback)(const wchar_t *); +static SWIG_CSharpWStringHelperCallback SWIG_csharp_wstring_callback = NULL; +%} + +%pragma(csharp) imclasscode=%{ + protected class SWIGWStringHelper { + + public delegate string SWIGWStringDelegate(IntPtr message); + static SWIGWStringDelegate wstringDelegate = new SWIGWStringDelegate(CreateWString); + + [DllImport("$dllimport", EntryPoint="SWIGRegisterWStringCallback_$module")] + public static extern void SWIGRegisterWStringCallback_$module(SWIGWStringDelegate wstringDelegate); + + static string CreateWString([MarshalAs(UnmanagedType.LPWStr)]IntPtr cString) { + return System.Runtime.InteropServices.Marshal.PtrToStringUni(cString); + } + + static SWIGWStringHelper() { + SWIGRegisterWStringCallback_$module(wstringDelegate); + } + } + + static protected SWIGWStringHelper swigWStringHelper = new SWIGWStringHelper(); +%} + +%insert(runtime) %{ +#ifdef __cplusplus +extern "C" +#endif +SWIGEXPORT void SWIGSTDCALL SWIGRegisterWStringCallback_$module(SWIG_CSharpWStringHelperCallback callback) { + SWIG_csharp_wstring_callback = callback; +} +%} +#endif // SWIG_CSHARP_WSTRING_HELPER_ +#endif // SWIG_CSHARP_NO_WSTRING_HELPER + + +// wchar_t +%typemap(ctype) wchar_t "wchar_t" +%typemap(imtype) wchar_t "char" +%typemap(cstype) wchar_t "char" + +%typemap(csin) wchar_t "$csinput" +%typemap(csout, excode=SWIGEXCODE) wchar_t { + char ret = $imcall;$excode + return ret; + } +%typemap(csvarin, excode=SWIGEXCODE2) wchar_t %{ + set { + $imcall;$excode + } %} +%typemap(csvarout, excode=SWIGEXCODE2) wchar_t %{ + get { + char ret = $imcall;$excode + return ret; + } %} + +%typemap(in) wchar_t %{ $1 = ($1_ltype)$input; %} +%typemap(out) wchar_t %{ $result = (wchar_t)$1; %} + +%typemap(typecheck) wchar_t = char; + +// wchar_t * +%typemap(ctype) wchar_t * "wchar_t *" +%typemap(imtype, inattributes="[MarshalAs(UnmanagedType.LPWStr)]", out="IntPtr" ) wchar_t * "string" +%typemap(cstype) wchar_t * "string" + +%typemap(csin) wchar_t * "$csinput" +%typemap(csout, excode=SWIGEXCODE) wchar_t * { + string ret = System.Runtime.InteropServices.Marshal.PtrToStringUni($imcall);$excode + return ret; + } +%typemap(csvarin, excode=SWIGEXCODE2) wchar_t * %{ + set { + $imcall;$excode + } %} +%typemap(csvarout, excode=SWIGEXCODE2) wchar_t * %{ + get { + string ret = $imcall;$excode + return ret; + } %} + +%typemap(in) wchar_t * %{ $1 = ($1_ltype)$input; %} +%typemap(out) wchar_t * %{ $result = (wchar_t *)$1; %} + +%typemap(typecheck) wchar_t * = char *; + -- cgit v1.2.1 From c9ede7e62278085ce4560f8ff1ff227d11e6d4a6 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Wed, 13 Oct 2010 05:48:59 +0000 Subject: Fix unary scope operator (::) (global scope) regression introduced in 2.0.0. The mangled symbol names were incorrect, sometimes resulting in types being incorrectly treated as opaque types. git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12264 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- CHANGES.current | 4 +++ Examples/test-suite/global_namespace.i | 22 ++++++++++++ .../test-suite/java/global_namespace_runme.java | 34 ++++++++++++++++-- .../test-suite/python/global_namespace_runme.py | 40 ++++++++++++++++++++++ Source/Swig/stype.c | 11 +++--- 5 files changed, 104 insertions(+), 7 deletions(-) create mode 100644 Examples/test-suite/python/global_namespace_runme.py diff --git a/CHANGES.current b/CHANGES.current index 26977a25d..2a9de5cf1 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -5,3 +5,7 @@ See the RELEASENOTES file for a summary of changes in each release. Version 2.0.2 (in progress) =========================== +2010-10-12: wsfulton + Fix unary scope operator (::) (global scope) regression introduced in 2.0.0, reported by + Ben Walker. The mangled symbol names were incorrect, sometimes resulting in types being + incorrectly treated as opaque types. diff --git a/Examples/test-suite/global_namespace.i b/Examples/test-suite/global_namespace.i index 7b575614f..37195c76b 100644 --- a/Examples/test-suite/global_namespace.i +++ b/Examples/test-suite/global_namespace.i @@ -58,3 +58,25 @@ struct TheEnumMethods { } %} +%inline %{ +Klass1 getKlass1A() { return ::Klass1(); } +::Klass1 getKlass1B() { return ::Klass1(); } + +Klass2 getKlass2A() { return ::Klass2(); } +::Klass2 getKlass2B() { return ::Klass2(); } + +Klass3 getKlass3A() { return ::Klass3(); } +::Klass3 getKlass3B() { return ::Klass3(); } + +Klass4 getKlass4A() { return ::Klass4(); } +::Klass4 getKlass4B() { return ::Klass4(); } + +Klass5 getKlass5A() { return ::Klass5(); } +::Klass5 getKlass5B() { return ::Klass5(); } + +Klass6 getKlass6A() { return ::Klass6(); } +::Klass6 getKlass6B() { return ::Klass6(); } + +Klass7 getKlass7A() { return ::Klass7(); } +::Klass7 getKlass7B() { return ::Klass7(); } +%} diff --git a/Examples/test-suite/java/global_namespace_runme.java b/Examples/test-suite/java/global_namespace_runme.java index faab7d4ba..205e149b0 100644 --- a/Examples/test-suite/java/global_namespace_runme.java +++ b/Examples/test-suite/java/global_namespace_runme.java @@ -13,8 +13,38 @@ public class global_namespace_runme { public static void main(String argv[]) { - KlassMethods.methodA(new Klass1(), new Klass2(), new Klass3(), new Klass4(), new Klass5(), new Klass6(), new Klass7()); - KlassMethods.methodB(new Klass1(), new Klass2(), new Klass3(), new Klass4(), new Klass5(), new Klass6(), new Klass7()); + Klass1 k1 = new Klass1(); + Klass2 k2 = new Klass2(); + Klass3 k3 = new Klass3(); + Klass4 k4 = new Klass4(); + Klass5 k5 = new Klass5(); + Klass6 k6 = new Klass6(); + Klass7 k7 = new Klass7(); + + KlassMethods.methodA(k1, k2, k3, k4, k5, k6, k7); + KlassMethods.methodB(k1, k2, k3, k4, k5, k6, k7); + + k1 = global_namespace.getKlass1A(); + k2 = global_namespace.getKlass2A(); + k3 = global_namespace.getKlass3A(); + k4 = global_namespace.getKlass4A(); + k5 = global_namespace.getKlass5A(); + k6 = global_namespace.getKlass6A(); + k7 = global_namespace.getKlass7A(); + + KlassMethods.methodA(k1, k2, k3, k4, k5, k6, k7); + KlassMethods.methodB(k1, k2, k3, k4, k5, k6, k7); + + k1 = global_namespace.getKlass1B(); + k2 = global_namespace.getKlass2B(); + k3 = global_namespace.getKlass3B(); + k4 = global_namespace.getKlass4B(); + k5 = global_namespace.getKlass5B(); + k6 = global_namespace.getKlass6B(); + k7 = global_namespace.getKlass7B(); + + KlassMethods.methodA(k1, k2, k3, k4, k5, k6, k7); + KlassMethods.methodB(k1, k2, k3, k4, k5, k6, k7); XYZMethods.methodA(new XYZ1(), new XYZ2(), new XYZ3(), new XYZ4(), new XYZ5(), new XYZ6(), new XYZ7()); XYZMethods.methodB(new XYZ1(), new XYZ2(), new XYZ3(), new XYZ4(), new XYZ5(), new XYZ6(), new XYZ7()); diff --git a/Examples/test-suite/python/global_namespace_runme.py b/Examples/test-suite/python/global_namespace_runme.py new file mode 100644 index 000000000..b64e75ca1 --- /dev/null +++ b/Examples/test-suite/python/global_namespace_runme.py @@ -0,0 +1,40 @@ +from global_namespace import * + +k1 = Klass1() +k2 = Klass2() +k3 = Klass3() +k4 = Klass4() +k5 = Klass5() +k6 = Klass6() +k7 = Klass7() + +KlassMethods.methodA(k1, k2, k3, k4, k5, k6, k7) +KlassMethods.methodB(k1, k2, k3, k4, k5, k6, k7) + +k1 = getKlass1A() +k2 = getKlass2A() +k3 = getKlass3A() +k4 = getKlass4A() +k5 = getKlass5A() +k6 = getKlass6A() +k7 = getKlass7A() + +KlassMethods.methodA(k1, k2, k3, k4, k5, k6, k7) +KlassMethods.methodB(k1, k2, k3, k4, k5, k6, k7) + +k1 = getKlass1B() +k2 = getKlass2B() +k3 = getKlass3B() +k4 = getKlass4B() +k5 = getKlass5B() +k6 = getKlass6B() +k7 = getKlass7B() + +KlassMethods.methodA(k1, k2, k3, k4, k5, k6, k7) +KlassMethods.methodB(k1, k2, k3, k4, k5, k6, k7) + +XYZMethods.methodA(XYZ1(), XYZ2(), XYZ3(), XYZ4(), XYZ5(), XYZ6(), XYZ7()) +XYZMethods.methodB(XYZ1(), XYZ2(), XYZ3(), XYZ4(), XYZ5(), XYZ6(), XYZ7()) + +TheEnumMethods.methodA(theenum1, theenum2, theenum3) +TheEnumMethods.methodA(theenum1, theenum2, theenum3) diff --git a/Source/Swig/stype.c b/Source/Swig/stype.c index dd2aea688..a13f87cfc 100644 --- a/Source/Swig/stype.c +++ b/Source/Swig/stype.c @@ -906,8 +906,9 @@ String *SwigType_manglestr_default(SwigType *s) { String *result = 0; String *base = 0; SwigType *lt; - SwigType *sr = SwigType_typedef_qualified(s); - SwigType *ss = SwigType_typedef_resolve_all(sr); + SwigType *sr = SwigType_typedef_resolve_all(s); + SwigType *sq = SwigType_typedef_qualified(sr); + SwigType *ss = SwigType_remove_global_scope_prefix(sq); s = ss; @@ -917,7 +918,6 @@ String *SwigType_manglestr_default(SwigType *s) { ss = ty; s = ss; } - Delete(sr); lt = SwigType_ltype(s); result = SwigType_prefix(lt); @@ -966,8 +966,9 @@ String *SwigType_manglestr_default(SwigType *s) { Insert(result, 0, "_"); Delete(lt); Delete(base); - if (ss) - Delete(ss); + Delete(ss); + Delete(sq); + Delete(sr); return result; } -- cgit v1.2.1 From 9eaf5ba1be143ea16eb7bfc096122be3c7bead19 Mon Sep 17 00:00:00 2001 From: Olly Betts Date: Thu, 14 Oct 2010 05:13:09 +0000 Subject: [PHP] Allow compilation on non-conforming Microsoft C++ compilers which don't accept: return function_returning_void(); Reported by Frank Vanden Berghen on the SWIG mailing list. git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12265 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- CHANGES.current | 5 +++++ Source/Modules/php.cxx | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/CHANGES.current b/CHANGES.current index 2a9de5cf1..5a7493206 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -5,6 +5,11 @@ See the RELEASENOTES file for a summary of changes in each release. Version 2.0.2 (in progress) =========================== +2010-10-14: olly + [PHP] Allow compilation on non-conforming Microsoft C++ compilers + which don't accept: return function_returning_void(); + Reported by Frank Vanden Berghen on the SWIG mailing list. + 2010-10-12: wsfulton Fix unary scope operator (::) (global scope) regression introduced in 2.0.0, reported by Ben Walker. The mangled symbol names were incorrect, sometimes resulting in types being diff --git a/Source/Modules/php.cxx b/Source/Modules/php.cxx index 89204d7bf..05f2082c2 100644 --- a/Source/Modules/php.cxx +++ b/Source/Modules/php.cxx @@ -666,7 +666,7 @@ public: /* We have an extra 'this' parameter. */ SetFlag(n, "wrap:this"); } - String *dispatch = Swig_overload_dispatch(n, "return %s(INTERNAL_FUNCTION_PARAM_PASSTHRU);", &maxargs); + String *dispatch = Swig_overload_dispatch(n, "%s(INTERNAL_FUNCTION_PARAM_PASSTHRU); return;", &maxargs); /* Generate a dispatch wrapper for all overloaded functions */ -- cgit v1.2.1 From 2453aee4e7345c28df8baca801b1f1c69b9810b5 Mon Sep 17 00:00:00 2001 From: Sylvestre Ledru Date: Thu, 14 Oct 2010 12:43:15 +0000 Subject: 2010-10-14: Sylvestre Ledru Fails the configure if cannot find a yacc implementation (like bison) git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12269 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- CHANGES.current | 4 ++++ configure.in | 14 ++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/CHANGES.current b/CHANGES.current index 5a7493206..a5f149421 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -14,3 +14,7 @@ Version 2.0.2 (in progress) Fix unary scope operator (::) (global scope) regression introduced in 2.0.0, reported by Ben Walker. The mangled symbol names were incorrect, sometimes resulting in types being incorrectly treated as opaque types. + +2010-10-14: Sylvestre Ledru + Fails the configure if cannot find a yacc implementation + (like bison) diff --git a/configure.in b/configure.in index 36337b41d..7f584e5d6 100644 --- a/configure.in +++ b/configure.in @@ -122,6 +122,20 @@ echo "Note : None of the following packages are required for users to compile an echo "" AC_PROG_YACC +echo "YACC $YACC" +if test -z "$YACC"; then + AC_MSG_ERROR([No implementation of Yacc (bison, yacc) detected.]) +fi +# Actually, AC_PROG_YACC is lying. It sometimes put yacc into $YACC even it +# hasn't been able to find it. +# AC_CHECK_PROG(YACC_PRESENT, $YACC, AC_MSG_ERROR([No implementation of Yacc (bison, yacc) detected. Please install it (package bison)]) ) + +AC_CHECK_PROG(yacc_present, $YACC, "yes","no") +if test "x$yacc_present" != "xyes"; then + AC_MSG_ERROR([No implementation of Yacc (bison, yacc) detected. Please install it (package bison)]) +fi + + AC_PROG_RANLIB AC_CHECK_PROGS(AR, ar aal, ar) AC_SUBST(AR) -- cgit v1.2.1 From 98441fc6ad6d6097c98baf28b54c7059045806b6 Mon Sep 17 00:00:00 2001 From: Joseph Wang Date: Sun, 17 Oct 2010 07:33:58 +0000 Subject: [R] Fix failure in overloaded functions which was breaking QuantLib-SWIG git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12282 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- CHANGES.current | 4 ++++ Source/Modules/r.cxx | 14 +++++++++++++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/CHANGES.current b/CHANGES.current index a5f149421..65489354c 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -5,6 +5,10 @@ See the RELEASENOTES file for a summary of changes in each release. Version 2.0.2 (in progress) =========================== +2010-10-17: drjoe + [R] Fix failure in overloaded functions which was breaking + QuantLib-SWIG + 2010-10-14: olly [PHP] Allow compilation on non-conforming Microsoft C++ compilers which don't accept: return function_returning_void(); diff --git a/Source/Modules/r.cxx b/Source/Modules/r.cxx index 749797c78..61cbcdd79 100644 --- a/Source/Modules/r.cxx +++ b/Source/Modules/r.cxx @@ -1603,6 +1603,16 @@ void R::dispatchFunction(Node *n) { j == 0 ? "" : " && ", j+1); } + else if (DohStrcmp(tm,"integer")==0) { + Printf(f->code, "%s(is.integer(argv[[%d]]) || is.numeric(argv[[%d]]))", + j == 0 ? "" : " && ", + j+1, j+1); + } + else if (DohStrcmp(tm,"character")==0) { + Printf(f->code, "%sis.character(argv[[%d]])", + j == 0 ? "" : " && ", + j+1); + } else { Printf(f->code, "%sextends(argtypes[%d], '%s')", j == 0 ? "" : " && ", @@ -1617,7 +1627,9 @@ void R::dispatchFunction(Node *n) { } } if (cur_args != -1) { - Printv(f->code, "}", NIL); + Printf(f->code, "} else {\n" + "stop(\"cannot find overloaded function for %s\");\n" + "}", sfname); } Printv(f->code, ";\nf(...)", NIL); Printv(f->code, ";\n}", NIL); -- cgit v1.2.1 From f77ccd81d5c0b09ba0d99833e60945edf381f2f5 Mon Sep 17 00:00:00 2001 From: Joseph Wang Date: Sun, 17 Oct 2010 09:35:34 +0000 Subject: [R] Improve error message for missing argtypes git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12283 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Source/Modules/r.cxx | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Source/Modules/r.cxx b/Source/Modules/r.cxx index 61cbcdd79..8eb784c68 100644 --- a/Source/Modules/r.cxx +++ b/Source/Modules/r.cxx @@ -1628,7 +1628,8 @@ void R::dispatchFunction(Node *n) { } if (cur_args != -1) { Printf(f->code, "} else {\n" - "stop(\"cannot find overloaded function for %s\");\n" + "stop(\"cannot find overloaded function for %s with argtypes (\"," + "toString(argtypes),\")\");\n" "}", sfname); } Printv(f->code, ";\nf(...)", NIL); -- cgit v1.2.1 From 383230d734280c8cbd8ca159d30fe5677134883d Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Mon, 18 Oct 2010 18:59:57 +0000 Subject: minor clarification about %{ %} blocks git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12284 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Doc/Manual/Introduction.html | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Doc/Manual/Introduction.html b/Doc/Manual/Introduction.html index 3bac9484e..24579d946 100644 --- a/Doc/Manual/Introduction.html +++ b/Doc/Manual/Introduction.html @@ -195,9 +195,9 @@ extern int my_mod(int n, int m);

    The interface file contains ANSI C function prototypes and variable declarations. The %module directive defines the name of the -module that will be created by SWIG. The %{,%} block -provides a location for inserting additional code such as C header -files or additional C declarations. +module that will be created by SWIG. The %{ %} block +provides a location for inserting additional code, such as C header +files or additional C declarations, into the generated C wrapper code.

    2.3.2 The swig command

    -- cgit v1.2.1 From 28e277f8c59322fd1041bb3cc68c5ed779bff407 Mon Sep 17 00:00:00 2001 From: Olly Betts Date: Tue, 19 Oct 2010 06:31:31 +0000 Subject: Fix typo "the the" -> "the" git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12285 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Lib/octave/octcontainer.swg | 3 +-- Lib/python/pycontainer.swg | 3 +-- Lib/ruby/rubycontainer.swg | 3 +-- Source/Swig/cwrap.c | 2 +- Source/Swig/stype.c | 2 +- 5 files changed, 5 insertions(+), 8 deletions(-) diff --git a/Lib/octave/octcontainer.swg b/Lib/octave/octcontainer.swg index 6613fcfff..4f14ccef1 100644 --- a/Lib/octave/octcontainer.swg +++ b/Lib/octave/octcontainer.swg @@ -4,8 +4,7 @@ * Octave cell <-> C++ container wrapper * * This wrapper, and its iterator, allows a general use (and reuse) of - * the the mapping between C++ and Octave, thanks to the C++ - * templates. + * the mapping between C++ and Octave, thanks to the C++ templates. * * Of course, it needs the C++ compiler to support templates, but * since we will use this wrapper with the STL containers, that should diff --git a/Lib/python/pycontainer.swg b/Lib/python/pycontainer.swg index efca86cf1..40506e15b 100644 --- a/Lib/python/pycontainer.swg +++ b/Lib/python/pycontainer.swg @@ -4,8 +4,7 @@ * Python sequence <-> C++ container wrapper * * This wrapper, and its iterator, allows a general use (and reuse) of - * the the mapping between C++ and Python, thanks to the C++ - * templates. + * the mapping between C++ and Python, thanks to the C++ templates. * * Of course, it needs the C++ compiler to support templates, but * since we will use this wrapper with the STL containers, that should diff --git a/Lib/ruby/rubycontainer.swg b/Lib/ruby/rubycontainer.swg index fa4b619f9..f643e84b3 100644 --- a/Lib/ruby/rubycontainer.swg +++ b/Lib/ruby/rubycontainer.swg @@ -4,8 +4,7 @@ * Ruby sequence <-> C++ container wrapper * * This wrapper, and its iterator, allows a general use (and reuse) of - * the the mapping between C++ and Ruby, thanks to the C++ - * templates. + * the mapping between C++ and Ruby, thanks to the C++ templates. * * Of course, it needs the C++ compiler to support templates, but * since we will use this wrapper with the STL containers, that should diff --git a/Source/Swig/cwrap.c b/Source/Swig/cwrap.c index 799d434a6..28401f89f 100644 --- a/Source/Swig/cwrap.c +++ b/Source/Swig/cwrap.c @@ -216,7 +216,7 @@ int Swig_cargs(Wrapper *w, ParmList *p) { SwigType_del_reference(tvalue); tycode = SwigType_type(tvalue); if (tycode != T_USER) { - /* plain primitive type, we copy the the def value */ + /* plain primitive type, we copy the def value */ String *lstr = SwigType_lstr(tvalue, defname); defvalue = NewStringf("%s = %s", lstr, qvalue); Delete(lstr); diff --git a/Source/Swig/stype.c b/Source/Swig/stype.c index a13f87cfc..742b6232a 100644 --- a/Source/Swig/stype.c +++ b/Source/Swig/stype.c @@ -366,7 +366,7 @@ SwigType *SwigType_default_create(SwigType *ty) { * SwigType_default_create() before calling this function. * * Example deductions (matching the examples described in SwigType_default_create), - * where the the most specialized matches are highest in the list: + * where the most specialized matches are highest in the list: * * a(ANY).a(ANY).SWIGTYPE * a(ANY).a().SWIGTYPE -- cgit v1.2.1 From 43794d90cdcaa6a4c477ef331c37e3076951c800 Mon Sep 17 00:00:00 2001 From: Sylvestre Ledru Date: Fri, 29 Oct 2010 10:22:03 +0000 Subject: Revert of commit 12269 see: http://sourceforge.net/mailarchive/forum.php?thread_name=4CC08FAA.5050009%40fultondesigns.co.uk&forum_name=swig-devel git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12286 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- CHANGES.current | 4 ---- configure.in | 14 -------------- 2 files changed, 18 deletions(-) diff --git a/CHANGES.current b/CHANGES.current index 65489354c..ebfb2cb81 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -18,7 +18,3 @@ Version 2.0.2 (in progress) Fix unary scope operator (::) (global scope) regression introduced in 2.0.0, reported by Ben Walker. The mangled symbol names were incorrect, sometimes resulting in types being incorrectly treated as opaque types. - -2010-10-14: Sylvestre Ledru - Fails the configure if cannot find a yacc implementation - (like bison) diff --git a/configure.in b/configure.in index 7f584e5d6..36337b41d 100644 --- a/configure.in +++ b/configure.in @@ -122,20 +122,6 @@ echo "Note : None of the following packages are required for users to compile an echo "" AC_PROG_YACC -echo "YACC $YACC" -if test -z "$YACC"; then - AC_MSG_ERROR([No implementation of Yacc (bison, yacc) detected.]) -fi -# Actually, AC_PROG_YACC is lying. It sometimes put yacc into $YACC even it -# hasn't been able to find it. -# AC_CHECK_PROG(YACC_PRESENT, $YACC, AC_MSG_ERROR([No implementation of Yacc (bison, yacc) detected. Please install it (package bison)]) ) - -AC_CHECK_PROG(yacc_present, $YACC, "yes","no") -if test "x$yacc_present" != "xyes"; then - AC_MSG_ERROR([No implementation of Yacc (bison, yacc) detected. Please install it (package bison)]) -fi - - AC_PROG_RANLIB AC_CHECK_PROGS(AR, ar aal, ar) AC_SUBST(AR) -- cgit v1.2.1 From 77b87aa9196c226b8625218b8608b5696b335d06 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Thu, 11 Nov 2010 19:30:44 +0000 Subject: typo fix in help message git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12288 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Source/Modules/python.cxx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/Modules/python.cxx b/Source/Modules/python.cxx index 80f2e68df..6d5f500a4 100644 --- a/Source/Modules/python.cxx +++ b/Source/Modules/python.cxx @@ -130,7 +130,7 @@ static const char *usage2 = (char *) "\ -nofastproxy - Use traditional proxy mechanism for member methods (default) \n\ -nofastquery - Use traditional query mechanism for types (default) \n\ -noh - Don't generate the output header file\n\ - -nomodern - Don't use modern python features which are not back compatible \n\ + -nomodern - Don't use modern python features which are not backwards compatible \n\ -nomodernargs - Use classic ParseTuple/CallFunction methods to pack/unpack the function arguments (default) \n"; static const char *usage3 = (char *) "\ -noolddefs - Don't emit the old method definitions even when using fastproxy (default) \n\ -- cgit v1.2.1 From 580f2549582602399553fded9e12bca6f9746143 Mon Sep 17 00:00:00 2001 From: Ian Lance Taylor Date: Fri, 12 Nov 2010 16:43:03 +0000 Subject: Update for recent runtime name changes (a better mechanism is clearly needed here). git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12290 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Lib/go/cdata.i | 4 ++-- Lib/go/goruntime.swg | 12 ++++++------ Source/Modules/go.cxx | 6 +++--- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/Lib/go/cdata.i b/Lib/go/cdata.i index decf297c1..6cfdffea1 100644 --- a/Lib/go/cdata.i +++ b/Lib/go/cdata.i @@ -59,8 +59,8 @@ void _swig_gc_makegobyteslice(void *a, int32 n) { cgocallback(·_swig_internal_makegobyteslice, a, n); } void ·_swig_allocategobyteslice(byte *data, int32 len, swigcdata ret) { - ret.data = mal(len); - mcpy(ret.data, data, len); + ret.data = runtime·mal(len); + runtime·mcpy(ret.data, data, len); ret.len = len; FLUSH(&ret); } diff --git a/Lib/go/goruntime.swg b/Lib/go/goruntime.swg index 057f81d01..6cde68f55 100644 --- a/Lib/go/goruntime.swg +++ b/Lib/go/goruntime.swg @@ -109,23 +109,23 @@ static void _swig_gopanic(const char *p) { extern void ·_swig_internal_allocate(void); #pragma dynexport _swig_gc_allocate _swig_gc_allocate void _swig_gc_allocate(void *a, int32 n) { - cgocallback(·_swig_internal_allocate, a, n); + runtime·cgocallback(·_swig_internal_allocate, a, n); } void ·_swig_allocatememory(int32 len, byte *ret) { - ret = mal(len); + ret = runtime·mal(len); FLUSH(&ret); } extern void ·_swig_internal_makegostring(void); #pragma dynexport _swig_gc_makegostring _swig_gc_makegostring void _swig_gc_makegostring(void *a, int32 n) { - cgocallback(·_swig_internal_makegostring, a, n); + runtime·cgocallback(·_swig_internal_makegostring, a, n); } void ·_swig_allocatestring(byte *p, int32 l, String ret) { - ret.str = mal(l+1); - mcpy(ret.str, p, l); + ret.str = runtime·mal(l+1); + runtime·mcpy(ret.str, p, l); ret.len = l; FLUSH(&ret); } @@ -133,7 +133,7 @@ void ·_swig_allocatestring(byte *p, int32 l, String ret) { extern void ·_swig_internal_gopanic(void); #pragma dynexport _swig_gc_gopanic _swig_gc_gopanic void _swig_gc_gopanic(void *a, int32 n) { - cgocallback(·_swig_internal_gopanic, a, n); + runtime·cgocallback(·_swig_internal_gopanic, a, n); } %} diff --git a/Source/Modules/go.cxx b/Source/Modules/go.cxx index 4b1d05b92..d3de53f8f 100644 --- a/Source/Modules/go.cxx +++ b/Source/Modules/go.cxx @@ -1068,7 +1068,7 @@ private: Delete(parm_size); Printv(f->code, "{\n", NULL); - Printv(f->code, "\tcgocall(", wname, ", &p);\n", NULL); + Printv(f->code, "\truntime\xc2\xb7" "cgocall(", wname, ", &p);\n", NULL); Printv(f->code, "}\n", NULL); Printv(f->code, "\n", NULL); @@ -2749,7 +2749,7 @@ private: Printv(f_gc_wrappers, "void\n", NULL); Printv(f_gc_wrappers, wname, "(void *a, int32 n)\n", NULL); Printv(f_gc_wrappers, "{\n", NULL); - Printv(f_gc_wrappers, "\tcgocallback(\xc2\xb7", go_name, ", a, n);\n", NULL); + Printv(f_gc_wrappers, "\truntime\xc2\xb7" "cgocallback(\xc2\xb7", go_name, ", a, n);\n", NULL); Printv(f_gc_wrappers, "}\n\n", NULL); } else { Printv(f_c_directors, " ", wname, "(go_val);\n", NULL); @@ -3475,7 +3475,7 @@ private: Printv(f_gc_wrappers, "void\n", NULL); Printv(f_gc_wrappers, callback_wname, "(void *a, int32 n)\n", NULL); Printv(f_gc_wrappers, "{\n", NULL); - Printv(f_gc_wrappers, "\tcgocallback(\xc2\xb7", callback_name, ", a, n);\n", NULL); + Printv(f_gc_wrappers, "\truntime\xc2\xb7" "cgocallback(\xc2\xb7", callback_name, ", a, n);\n", NULL); Printv(f_gc_wrappers, "}\n\n", NULL); } else { if (SwigType_type(result) != T_VOID) { -- cgit v1.2.1 From e30befd13806fb89c1591c56a7a66a5c24d1a14e Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Tue, 16 Nov 2010 14:08:50 +0000 Subject: Correct explanation of how to match on class name in %rename. Replace incorrect documentation of $parentNode from %rename discussion: it advised using match$parentNode but this doesn't work because the parent node is not yet set when %rename is parsed. Document the "fullname" attribute of %rename which can be used to restrict the match to the given full name of a declaration only. git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12291 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Doc/Manual/SWIG.html | 24 ++++++++---------------- 1 file changed, 8 insertions(+), 16 deletions(-) diff --git a/Doc/Manual/SWIG.html b/Doc/Manual/SWIG.html index e51e55986..b8e3e2260 100644 --- a/Doc/Manual/SWIG.html +++ b/Doc/Manual/SWIG.html @@ -2002,22 +2002,6 @@ documentation is not exhaustive, see "%rename predicates" section of swig.swg for the full list of supported match expressions.

    -

    -Another important feature of match is that it can be applied not -only to the declaration itself but also to its enclosing declaration. So -match$parentNode$name="SomeClass" would be true only for members of -the C++ class with the specified name. This can, of course, be combined with -more complicated matches making it possible to write -

    -
    -
    -%rename("%(lowercase)s", match$parentNode$name="SomeClass", %$isenum) "";
    -
    -
    -

    -to rename all enums nested in the given class to lower case. -

    -

    In addition to literally matching some string with match you can also use regexmatch or notregexmatch to match a string @@ -2039,6 +2023,14 @@ declaration name directly can be preferable and can also be done using %rename("$ignore", regextarget=1) "Old$"; +Notice that the check is done only against the name of the declaration +itself, if you need to match the full name of a C++ declaration you +must use fullname attribute: +

    +
    +%rename("$ignore", regextarget=1, fullname=1) "NameSpace::ClassName::.*Old$";
    +
    +

    As for notregexmatch, it restricts the match only to the strings not -- cgit v1.2.1 From 953c4abacaad7c8cab4eb5c5f87e5164c7e414c8 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Tue, 16 Nov 2010 14:09:09 +0000 Subject: Use rename list and not hash for renames with regextarget attribute. Renames which are regular expressions can't be put in the regex hash as they don't literally match the real declarations names. Instead, put them in the rename list against which we will match the declarations names later. git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12292 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Source/Swig/naming.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/Swig/naming.c b/Source/Swig/naming.c index 5bf42f7cc..70744586c 100644 --- a/Source/Swig/naming.c +++ b/Source/Swig/naming.c @@ -1110,7 +1110,7 @@ void Swig_name_nameobj_add(Hash *name_hash, List *name_list, String *prefix, Str } if (!nname || !Len(nname) || Getattr(nameobj, "fullname") || /* any of these options trigger a 'list' nameobj */ - Getattr(nameobj, "sourcefmt") || Getattr(nameobj, "matchlist")) { + Getattr(nameobj, "sourcefmt") || Getattr(nameobj, "matchlist") || Getattr(nameobj, "regextarget")) { if (decl) Setattr(nameobj, "decl", decl); if (nname && Len(nname)) -- cgit v1.2.1 From f6cab0170abdb69b1ac562b223d101bf55e5700f Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Tue, 16 Nov 2010 14:09:39 +0000 Subject: Ignore non-matching regex renames when searching renames list. Skip over %renames with non-matching %(regex)s expansion when looking for the one to apply to the given name. This allows to have multiple anonymous renames using regex as now the first _matching_ one will be used instead of always using the first one and ignoring all the rest of them. Extend unit tests to verify that applying two anonymous %renames does work as expected. git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12293 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- CHANGES.current | 10 ++++++++++ Examples/test-suite/csharp/rename_pcre_encoder_runme.cs | 12 ++++++++++++ Examples/test-suite/java/rename_pcre_encoder_runme.java | 14 ++++++++++++++ Examples/test-suite/python/rename_pcre_encoder_runme.py | 3 +++ Examples/test-suite/rename_pcre_encoder.i | 9 +++++++-- Source/Swig/naming.c | 8 +++++++- 6 files changed, 53 insertions(+), 3 deletions(-) create mode 100644 Examples/test-suite/csharp/rename_pcre_encoder_runme.cs create mode 100644 Examples/test-suite/java/rename_pcre_encoder_runme.java diff --git a/CHANGES.current b/CHANGES.current index ebfb2cb81..f18011e1a 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -5,6 +5,16 @@ See the RELEASENOTES file for a summary of changes in each release. Version 2.0.2 (in progress) =========================== +2010-11-12: vadz + Fix handling of multiple regex-using %renames attached to the same + declaration. For example, now + + %rename("%(regex/^Set(.*)/put\\1/)s") ""; + %rename("%(regex/^Get(.*)/get\\1/)s") ""; + + works as expected whereas before only the last anonymous rename was + taken into account. + 2010-10-17: drjoe [R] Fix failure in overloaded functions which was breaking QuantLib-SWIG diff --git a/Examples/test-suite/csharp/rename_pcre_encoder_runme.cs b/Examples/test-suite/csharp/rename_pcre_encoder_runme.cs new file mode 100644 index 000000000..f6289e7e2 --- /dev/null +++ b/Examples/test-suite/csharp/rename_pcre_encoder_runme.cs @@ -0,0 +1,12 @@ +using System; +using rename_pcre_encoderNamespace; + +public class runme { + static void Main() { + SomeWidget w = new SomeWidget(); + w.putBorderWidth(17); + if ( w.getBorderWidth() != 17 ) + throw new Exception(String.Format("Border with should be 17, not {0}", + w.getBorderWidth())); + } +} diff --git a/Examples/test-suite/java/rename_pcre_encoder_runme.java b/Examples/test-suite/java/rename_pcre_encoder_runme.java new file mode 100644 index 000000000..cb843338b --- /dev/null +++ b/Examples/test-suite/java/rename_pcre_encoder_runme.java @@ -0,0 +1,14 @@ +import rename_pcre_encoder.*; + +public class rename_pcre_encoder_runme { + static { System.loadLibrary("rename_pcre_encoder"); } + + public static void main(String argv[]) + { + SomeWidget w = new SomeWidget(); + w.putBorderWidth(17); + if ( w.getBorderWidth() != 17 ) + throw new RuntimeException(String.format("Border with should be 17, not %d", + w.getBorderWidth())); + } +} diff --git a/Examples/test-suite/python/rename_pcre_encoder_runme.py b/Examples/test-suite/python/rename_pcre_encoder_runme.py index ed7ca48b1..1186703a0 100644 --- a/Examples/test-suite/python/rename_pcre_encoder_runme.py +++ b/Examples/test-suite/python/rename_pcre_encoder_runme.py @@ -2,6 +2,9 @@ from rename_pcre_encoder import * s = SomeWidget() s.putBorderWidth(3) +if s.getBorderWidth() != 3: + raise RuntimeError("Border should be 3, not %d" % (s.getBorderWidth(),)) + s.putSize(4, 5) a = AnotherWidget() a.DoSomething() diff --git a/Examples/test-suite/rename_pcre_encoder.i b/Examples/test-suite/rename_pcre_encoder.i index c90af164d..66f30c7bc 100644 --- a/Examples/test-suite/rename_pcre_encoder.i +++ b/Examples/test-suite/rename_pcre_encoder.i @@ -3,14 +3,19 @@ // strip the wx prefix from all identifiers except those starting with wxEVT %rename("%(regex:/wx(?!EVT)(.*)/\\1/)s") ""; -// Replace "Set" prefix with "put" in all functions +// Replace "Set" and "Get" prefixes with "put" and "get" respectively. %rename("%(regex:/^Set(.*)/put\\1/)s", %$isfunction) ""; +%rename("%(regex:/^Get(.*)/get\\1/)s", %$isfunction) ""; %inline %{ struct wxSomeWidget { - void SetBorderWidth(int) {} + void SetBorderWidth(int width) { m_width = width; } + int GetBorderWidth() const { return m_width; } + void SetSize(int, int) {} + + int m_width; }; struct wxAnotherWidget { diff --git a/Source/Swig/naming.c b/Source/Swig/naming.c index 70744586c..6beecc130 100644 --- a/Source/Swig/naming.c +++ b/Source/Swig/naming.c @@ -1302,7 +1302,13 @@ Hash *Swig_name_nameobj_lget(List *namelist, Node *n, String *prefix, String *na : Swig_name_match_value(tname, sname); Delete(sname); } else { - match = 1; + /* Applying the renaming rule may fail if it contains a %(regex)s expression that doesn't match the given name. */ + String *sname = NewStringf(Getattr(rn, "name"), name); + if (sname) { + if (Len(sname)) + match = 1; + Delete(sname); + } } } if (match) { -- cgit v1.2.1 From ee1c2f3ef086080a54cf5aec99f8b46e3f4d910d Mon Sep 17 00:00:00 2001 From: David Nadlinger Date: Thu, 18 Nov 2010 00:15:13 +0000 Subject: Renamed 'immutable' test-case to 'immutable_values'. This is a part of the pending merge of the D module, where 'immutable' is a keyword (and thus not a valid module name). git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12294 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Examples/test-suite/common.mk | 2 +- Examples/test-suite/immutable.i | 20 -------------------- Examples/test-suite/immutable_values.i | 20 ++++++++++++++++++++ 3 files changed, 21 insertions(+), 21 deletions(-) delete mode 100644 Examples/test-suite/immutable.i create mode 100644 Examples/test-suite/immutable_values.i diff --git a/Examples/test-suite/common.mk b/Examples/test-suite/common.mk index 026612db5..05d2f80c8 100644 --- a/Examples/test-suite/common.mk +++ b/Examples/test-suite/common.mk @@ -466,7 +466,7 @@ C_TEST_CASES += \ extern_declaration \ funcptr \ function_typedef \ - immutable \ + immutable_values \ inctest \ integers \ keyword_rename \ diff --git a/Examples/test-suite/immutable.i b/Examples/test-suite/immutable.i deleted file mode 100644 index ff5081e9c..000000000 --- a/Examples/test-suite/immutable.i +++ /dev/null @@ -1,20 +0,0 @@ -// test to make sure setters are not generated for constants - -%module immutable - - -%immutable; -%mutable; - -%inline %{ -#define ABC -11 -enum count {Zero, One, Two}; %} - - -%clearimmutable; - -%inline %{ -#define XYZ -22 -enum backwards {Tre=3, Duo=2, Uno=1}; -%} - diff --git a/Examples/test-suite/immutable_values.i b/Examples/test-suite/immutable_values.i new file mode 100644 index 000000000..1c1978661 --- /dev/null +++ b/Examples/test-suite/immutable_values.i @@ -0,0 +1,20 @@ +// test to make sure setters are not generated for constants + +%module immutable_values + + +%immutable; +%mutable; + +%inline %{ +#define ABC -11 +enum count {Zero, One, Two}; %} + + +%clearimmutable; + +%inline %{ +#define XYZ -22 +enum backwards {Tre=3, Duo=2, Uno=1}; +%} + -- cgit v1.2.1 From 0fb77ce2068128e02217cdddd6a388e6c6d30d9f Mon Sep 17 00:00:00 2001 From: David Nadlinger Date: Thu, 18 Nov 2010 00:15:41 +0000 Subject: Renamed 'template' test-case to 'template_basic'. This is a part of the pending merge of the D module, where 'template' is a keyword (and thus not a valid module name). git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12295 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Examples/test-suite/common.mk | 2 +- Examples/test-suite/template.i | 52 ------------------------------------ Examples/test-suite/template_basic.i | 52 ++++++++++++++++++++++++++++++++++++ 3 files changed, 53 insertions(+), 53 deletions(-) delete mode 100644 Examples/test-suite/template.i create mode 100644 Examples/test-suite/template_basic.i diff --git a/Examples/test-suite/common.mk b/Examples/test-suite/common.mk index 05d2f80c8..f0fe4af1c 100644 --- a/Examples/test-suite/common.mk +++ b/Examples/test-suite/common.mk @@ -318,11 +318,11 @@ CPP_TEST_CASES += \ struct_initialization_cpp \ struct_value \ symbol_clash \ - template \ template_arg_replace \ template_arg_scope \ template_arg_typename \ template_array_numeric \ + template_basic \ template_base_template \ template_classes \ template_const_ref \ diff --git a/Examples/test-suite/template.i b/Examples/test-suite/template.i deleted file mode 100644 index d2c7a91ed..000000000 --- a/Examples/test-suite/template.i +++ /dev/null @@ -1,52 +0,0 @@ -/* File : example.i */ -%module "template" - -%warnfilter(SWIGWARN_RUBY_WRONG_NAME) vector; /* Ruby, wrong class name */ -%warnfilter(SWIGWARN_RUBY_WRONG_NAME) vector; /* Ruby, wrong class name */ -%warnfilter(SWIGWARN_RUBY_WRONG_NAME) vector; /* Ruby, wrong class name */ - -/* Let's just grab the original header file here */ - -%{ -#ifdef max -#undef max -#endif -%} - -%inline %{ - -template T max(const T a, const T b) { return a>b ? a : b; } - -template class vector { - T *v; - int sz; - public: - vector(int _sz) { - v = new T[_sz]; - sz = _sz; - } - T &get(int index) { - return v[index]; - } - void set(int index, T &val) { - v[index] = val; - } - // This really doesn't do anything except test const handling - void testconst(const T x) { } -}; - -%} - -/* Now instantiate some specific template declarations */ - -%template(maxint) max; -%template(maxdouble) max; -%template(vecint) vector; -%template(vecdouble) vector; - -/* Now try to break constness */ - -%template(maxintp) max; -%template(vecintp) vector; - - diff --git a/Examples/test-suite/template_basic.i b/Examples/test-suite/template_basic.i new file mode 100644 index 000000000..570392bf6 --- /dev/null +++ b/Examples/test-suite/template_basic.i @@ -0,0 +1,52 @@ +/* File: template_basic.i */ +%module "template_basic" + +%warnfilter(SWIGWARN_RUBY_WRONG_NAME) vector; /* Ruby, wrong class name */ +%warnfilter(SWIGWARN_RUBY_WRONG_NAME) vector; /* Ruby, wrong class name */ +%warnfilter(SWIGWARN_RUBY_WRONG_NAME) vector; /* Ruby, wrong class name */ + +/* Let's just grab the original header file here */ + +%{ +#ifdef max +#undef max +#endif +%} + +%inline %{ + +template T max(const T a, const T b) { return a>b ? a : b; } + +template class vector { + T *v; + int sz; + public: + vector(int _sz) { + v = new T[_sz]; + sz = _sz; + } + T &get(int index) { + return v[index]; + } + void set(int index, T &val) { + v[index] = val; + } + // This really doesn't do anything except test const handling + void testconst(const T x) { } +}; + +%} + +/* Now instantiate some specific template declarations */ + +%template(maxint) max; +%template(maxdouble) max; +%template(vecint) vector; +%template(vecdouble) vector; + +/* Now try to break constness */ + +%template(maxintp) max; +%template(vecintp) vector; + + -- cgit v1.2.1 From 4d09774cefd745dc6a0e38db0a3ab320d79c992c Mon Sep 17 00:00:00 2001 From: David Nadlinger Date: Thu, 18 Nov 2010 00:16:02 +0000 Subject: Minor rename in the 'smart_pointer_templatemethods' test-case to avoid special casing for D. This is a part of the pending merge of the D module, where 'Object' is a keyword. git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12296 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Examples/test-suite/smart_pointer_templatemethods.i | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/Examples/test-suite/smart_pointer_templatemethods.i b/Examples/test-suite/smart_pointer_templatemethods.i index 7baa6386a..f79bbcc9d 100644 --- a/Examples/test-suite/smart_pointer_templatemethods.i +++ b/Examples/test-suite/smart_pointer_templatemethods.i @@ -1,4 +1,3 @@ - %module smart_pointer_templatemethods %inline %{ @@ -29,21 +28,21 @@ public: void DisposeObjekt (void) {} }; -class Object +class Objct { public: - Object () {} - virtual ~Object () {} + Objct () {} + virtual ~Objct () {} template Ptr QueryInterface (InterfaceId iid) const { return Ptr(); } - void DisposeObject (void) {} + void DisposeObjct (void) {} }; #ifdef SWIG -%template(PtrObject) Ptr; +%template(PtrObjct) Ptr; %template(PtrInt) Ptr; %template(ObjektInt) Objekt; %template(PtrObjektInt) Ptr >; -%template(QueryInterfaceObject) Object::QueryInterface; +%template(QueryInterfaceObjct) Objct::QueryInterface; #endif }; // namespace -- cgit v1.2.1 From 2070812f09468e17b6a1e027dcaa6b5ae3774570 Mon Sep 17 00:00:00 2001 From: David Nadlinger Date: Thu, 18 Nov 2010 00:16:23 +0000 Subject: Minor rename in the 'operbool' test-case to avoid special casing for D. This is a part of the pending merge of the D module, where a method having the same name as the module would lead to ambiguities. git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12297 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Examples/test-suite/operbool.i | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Examples/test-suite/operbool.i b/Examples/test-suite/operbool.i index 793c0174e..ee8c889e9 100644 --- a/Examples/test-suite/operbool.i +++ b/Examples/test-suite/operbool.i @@ -1,6 +1,6 @@ %module operbool -%rename(operbool) operator bool(); +%rename(operator_bool) operator bool(); %inline %{ class Test { -- cgit v1.2.1 From a355d2d46af56c655816c37f24bb59fa6bade43f Mon Sep 17 00:00:00 2001 From: David Nadlinger Date: Thu, 18 Nov 2010 00:17:37 +0000 Subject: Added special cases to the test-suite as required for D. This is a part of the pending merge of the D module. git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12298 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Examples/test-suite/abstract_virtual.i | 6 +++-- Examples/test-suite/contract.i | 7 +++++- Examples/test-suite/default_constructor.i | 6 +++-- Examples/test-suite/dynamic_cast.i | 13 ++++++++--- Examples/test-suite/enums.i | 5 +++++ Examples/test-suite/evil_diamond.i | 3 ++- Examples/test-suite/evil_diamond_ns.i | 3 ++- Examples/test-suite/evil_diamond_prop.i | 1 + Examples/test-suite/import_nomodule.i | 8 +++---- Examples/test-suite/inherit_target_language.i | 8 ++++++- Examples/test-suite/li_boost_shared_ptr.i | 2 +- Examples/test-suite/li_boost_shared_ptr_bits.i | 2 +- Examples/test-suite/li_std_combinations.i | 2 +- Examples/test-suite/minherit2.i | 29 ++++++++++++++++++++++--- Examples/test-suite/multiple_inheritance.i | 6 +++-- Examples/test-suite/namespace_class.i | 4 ++++ Examples/test-suite/preproc_line_file.i | 4 ++-- Examples/test-suite/pure_virtual.i | 5 +++-- Examples/test-suite/samename.i | 2 +- Examples/test-suite/special_variable_macros.i | 14 ++++++++++++ Examples/test-suite/static_const_member.i | 3 +++ Examples/test-suite/template_enum.i | 4 ++++ Examples/test-suite/template_inherit_abstract.i | 5 +++-- Examples/test-suite/typemap_namespace.i | 9 +++++++- Examples/test-suite/typemap_out_optimal.i | 6 ++++- Examples/test-suite/typemap_subst.i | 4 ++-- Examples/test-suite/using_composition.i | 9 +++++--- Examples/test-suite/using_extend.i | 3 ++- Examples/test-suite/using_namespace.i | 3 ++- 29 files changed, 137 insertions(+), 39 deletions(-) diff --git a/Examples/test-suite/abstract_virtual.i b/Examples/test-suite/abstract_virtual.i index 2e4d105b1..d8372c936 100644 --- a/Examples/test-suite/abstract_virtual.i +++ b/Examples/test-suite/abstract_virtual.i @@ -2,10 +2,12 @@ %warnfilter(SWIGWARN_JAVA_MULTIPLE_INHERITANCE, SWIGWARN_CSHARP_MULTIPLE_INHERITANCE, - SWIGWARN_PHP_MULTIPLE_INHERITANCE) D; /* C#, Java, PHP multiple inheritance */ + SWIGWARN_D_MULTIPLE_INHERITANCE, + SWIGWARN_PHP_MULTIPLE_INHERITANCE) D; /* C#, D, Java, PHP multiple inheritance */ %warnfilter(SWIGWARN_JAVA_MULTIPLE_INHERITANCE, SWIGWARN_CSHARP_MULTIPLE_INHERITANCE, - SWIGWARN_PHP_MULTIPLE_INHERITANCE) E; /* C#, Java, PHP multiple inheritance */ + SWIGWARN_D_MULTIPLE_INHERITANCE, + SWIGWARN_PHP_MULTIPLE_INHERITANCE) E; /* C#, D, Java, PHP multiple inheritance */ %inline %{ #if defined(_MSC_VER) diff --git a/Examples/test-suite/contract.i b/Examples/test-suite/contract.i index b979ef19e..0ad7e8e7c 100644 --- a/Examples/test-suite/contract.i +++ b/Examples/test-suite/contract.i @@ -3,12 +3,17 @@ %warnfilter(SWIGWARN_RUBY_MULTIPLE_INHERITANCE, SWIGWARN_JAVA_MULTIPLE_INHERITANCE, SWIGWARN_CSHARP_MULTIPLE_INHERITANCE, - SWIGWARN_PHP_MULTIPLE_INHERITANCE) C; /* Ruby, C#, Java, PHP multiple inheritance */ + SWIGWARN_D_MULTIPLE_INHERITANCE, + SWIGWARN_PHP_MULTIPLE_INHERITANCE) C; /* Ruby, C#, D, Java, PHP multiple inheritance */ #ifdef SWIGCSHARP %ignore B::bar; // otherwise get a warning: `C.bar' no suitable methods found to override #endif +#ifdef SWIGD +%ignore B::bar; // Prevents getting an error that C.bar does not override any function because multiple inheritance is not supported. +#endif + %contract test_preassert(int a, int b) { require: a > 0; diff --git a/Examples/test-suite/default_constructor.i b/Examples/test-suite/default_constructor.i index ff22c7834..091adff20 100644 --- a/Examples/test-suite/default_constructor.i +++ b/Examples/test-suite/default_constructor.i @@ -5,11 +5,13 @@ %warnfilter(SWIGWARN_JAVA_MULTIPLE_INHERITANCE, SWIGWARN_CSHARP_MULTIPLE_INHERITANCE, - SWIGWARN_PHP_MULTIPLE_INHERITANCE) EB; /* C#, Java, PHP multiple inheritance */ + SWIGWARN_D_MULTIPLE_INHERITANCE, + SWIGWARN_PHP_MULTIPLE_INHERITANCE) EB; /* C#, D, Java, PHP multiple inheritance */ %warnfilter(SWIGWARN_JAVA_MULTIPLE_INHERITANCE, SWIGWARN_CSHARP_MULTIPLE_INHERITANCE, - SWIGWARN_PHP_MULTIPLE_INHERITANCE) AD; /* C#, Java, PHP multiple inheritance */ + SWIGWARN_D_MULTIPLE_INHERITANCE, + SWIGWARN_PHP_MULTIPLE_INHERITANCE) AD; /* C#, D, Java, PHP multiple inheritance */ %warnfilter(SWIGWARN_LANG_FRIEND_IGNORE) F; /* friend function */ diff --git a/Examples/test-suite/dynamic_cast.i b/Examples/test-suite/dynamic_cast.i index ccbaa5b47..17850985a 100644 --- a/Examples/test-suite/dynamic_cast.i +++ b/Examples/test-suite/dynamic_cast.i @@ -1,7 +1,7 @@ /* File : example.i */ %module dynamic_cast -#if !defined(SWIGJAVA) && !defined(SWIGCSHARP) && !defined(SWIGGO) +#if !defined(SWIGJAVA) && !defined(SWIGCSHARP) && !defined(SWIGGO) && !defined(SWIGD) %apply SWIGTYPE *DYNAMIC { Foo * }; #endif @@ -17,7 +17,7 @@ public: }; %} -#if defined(SWIGJAVA) || defined(SWIGCSHARP) || defined(SWIGGO) +#if defined(SWIGJAVA) || defined(SWIGCSHARP) || defined(SWIGGO) || defined(SWIGD) %typemap(out) Foo *blah { Bar *downcast = dynamic_cast($1); *(Bar **)&$result = downcast; @@ -37,6 +37,13 @@ public: } #endif +#if defined(SWIGD) +%typemap(dout, excode=SWIGEXCODE) Foo * { + Bar ret = new Bar($wcall, $owner);$excode + return ret; +} +#endif + #if defined(SWIGGO) %insert(go_runtime) %{ func FooToBar(f Foo) Bar { @@ -62,7 +69,7 @@ char *do_test(Bar *b) { } %} -#if !defined(SWIGJAVA) && !defined(SWIGCSHARP) && !defined(SWIGGO) +#if !defined(SWIGJAVA) && !defined(SWIGCSHARP) && !defined(SWIGGO) && !defined(SWIGD) // A general purpose function for dynamic casting of a Foo * %{ static swig_type_info * diff --git a/Examples/test-suite/enums.i b/Examples/test-suite/enums.i index 5632b5e97..14c6efbba 100644 --- a/Examples/test-suite/enums.i +++ b/Examples/test-suite/enums.i @@ -58,6 +58,11 @@ typedef struct _Foo { %warnfilter(SWIGWARN_RUBY_WRONG_NAME) _iFoo; +#ifdef SWIGD +/* Work around missing support for proper char quoting due to parser shortcomings. */ +%dconstvalue("'a'") _iFoo::Char; +#endif + #ifndef __cplusplus %inline %{ typedef struct _iFoo diff --git a/Examples/test-suite/evil_diamond.i b/Examples/test-suite/evil_diamond.i index 7b2e9152f..a8d48b30b 100644 --- a/Examples/test-suite/evil_diamond.i +++ b/Examples/test-suite/evil_diamond.i @@ -6,7 +6,8 @@ %warnfilter(SWIGWARN_RUBY_WRONG_NAME, SWIGWARN_JAVA_MULTIPLE_INHERITANCE, SWIGWARN_CSHARP_MULTIPLE_INHERITANCE, - SWIGWARN_PHP_MULTIPLE_INHERITANCE) spam; // Ruby, wrong class name - C# & Java, PHP multiple inheritance + SWIGWARN_D_MULTIPLE_INHERITANCE, + SWIGWARN_PHP_MULTIPLE_INHERITANCE) spam; // Ruby, wrong class name - C#, D & Java, PHP multiple inheritance %inline %{ diff --git a/Examples/test-suite/evil_diamond_ns.i b/Examples/test-suite/evil_diamond_ns.i index 515044007..0227b31ee 100644 --- a/Examples/test-suite/evil_diamond_ns.i +++ b/Examples/test-suite/evil_diamond_ns.i @@ -6,7 +6,8 @@ %warnfilter(SWIGWARN_RUBY_WRONG_NAME, SWIGWARN_JAVA_MULTIPLE_INHERITANCE, SWIGWARN_CSHARP_MULTIPLE_INHERITANCE, - SWIGWARN_PHP_MULTIPLE_INHERITANCE) Blah::spam; // Ruby, wrong class name - C# & Java, PHP multiple inheritance + SWIGWARN_D_MULTIPLE_INHERITANCE, + SWIGWARN_PHP_MULTIPLE_INHERITANCE) Blah::spam; // Ruby, wrong class name - C#, D & Java, PHP multiple inheritance %inline %{ namespace Blah { diff --git a/Examples/test-suite/evil_diamond_prop.i b/Examples/test-suite/evil_diamond_prop.i index 804ea66b4..2dac6eab7 100644 --- a/Examples/test-suite/evil_diamond_prop.i +++ b/Examples/test-suite/evil_diamond_prop.i @@ -6,6 +6,7 @@ %warnfilter(SWIGWARN_RUBY_WRONG_NAME, SWIGWARN_JAVA_MULTIPLE_INHERITANCE, SWIGWARN_CSHARP_MULTIPLE_INHERITANCE, + SWIGWARN_D_MULTIPLE_INHERITANCE, SWIGWARN_PHP_MULTIPLE_INHERITANCE) spam; // Ruby, wrong class name - C# & Java, PHP multiple inheritance %inline %{ diff --git a/Examples/test-suite/import_nomodule.i b/Examples/test-suite/import_nomodule.i index a1ba9ad7a..4fd5cbf65 100644 --- a/Examples/test-suite/import_nomodule.i +++ b/Examples/test-suite/import_nomodule.i @@ -8,16 +8,16 @@ %import "import_nomodule.h" -#if !defined(SWIGJAVA) && !defined(SWIGRUBY) && !defined(SWIGCSHARP) +#if !defined(SWIGJAVA) && !defined(SWIGRUBY) && !defined(SWIGCSHARP) && !defined(SWIGD) /** * The proxy class does not have Bar derived from Foo, yet an instance of Bar * can successfully be passed to a proxy function taking a Foo pointer (for some * language modules). * - * This violation of the type system is not possible in Java and C# due to static - * type checking. It's also not (currently) possible in Ruby, but this may be - * fixable (needs more investigation). + * This violation of the type system is not possible in Java, C# and D due to + * static type checking. It's also not (currently) possible in Ruby, but this may + * be fixable (needs more investigation). */ %newobject create_Foo; diff --git a/Examples/test-suite/inherit_target_language.i b/Examples/test-suite/inherit_target_language.i index 20fb93fda..88801f3f6 100644 --- a/Examples/test-suite/inherit_target_language.i +++ b/Examples/test-suite/inherit_target_language.i @@ -1,4 +1,4 @@ -// Test using a target language specified base class, primarily for Java/C# and possibly other single inheritance languages +// Test using a target language specified base class, primarily for Java/C#/D and possibly other single inheritance languages // Note the multiple inheritance warnings don't appear because of the two techniques used in here: typemaps and %ignore @@ -6,6 +6,8 @@ #if defined(SWIGJAVA) # define csbase javabase +#elif defined(SWIGD) +# define csbase dbase #endif %pragma(csharp) moduleimports=%{ @@ -20,6 +22,10 @@ class TargetLanguageBase { public void targetLanguageBaseMethod() {} }; class TargetLanguageBase2 { public void targetLanguageBase2Method() {} }; %} +%pragma(d) globalproxyimports=%{ +private class TargetLanguageBase { public void targetLanguageBaseMethod() {} }; +private class TargetLanguageBase2 { public void targetLanguageBase2Method() {} }; +%} %typemap(csbase) SWIGTYPE "TargetLanguageBase" diff --git a/Examples/test-suite/li_boost_shared_ptr.i b/Examples/test-suite/li_boost_shared_ptr.i index f92df23a9..fc51e7b5a 100644 --- a/Examples/test-suite/li_boost_shared_ptr.i +++ b/Examples/test-suite/li_boost_shared_ptr.i @@ -34,7 +34,7 @@ # define SWIG_SHARED_PTR_NAMESPACE SwigBoost #endif -#if defined(SWIGJAVA) || defined(SWIGCSHARP) || defined(SWIGPYTHON) +#if defined(SWIGJAVA) || defined(SWIGCSHARP) || defined(SWIGPYTHON) || defined(SWIGD) #define SHARED_PTR_WRAPPERS_IMPLEMENTED #endif diff --git a/Examples/test-suite/li_boost_shared_ptr_bits.i b/Examples/test-suite/li_boost_shared_ptr_bits.i index 610edb4b4..2232b6cf6 100644 --- a/Examples/test-suite/li_boost_shared_ptr_bits.i +++ b/Examples/test-suite/li_boost_shared_ptr_bits.i @@ -1,6 +1,6 @@ %module li_boost_shared_ptr_bits -#if defined(SWIGJAVA) || defined(SWIGCSHARP) || defined(SWIGPYTHON) +#if defined(SWIGJAVA) || defined(SWIGCSHARP) || defined(SWIGPYTHON) || defined(SWIGD) #define SHARED_PTR_WRAPPERS_IMPLEMENTED #endif diff --git a/Examples/test-suite/li_std_combinations.i b/Examples/test-suite/li_std_combinations.i index 9acc8f23d..57f945bcd 100644 --- a/Examples/test-suite/li_std_combinations.i +++ b/Examples/test-suite/li_std_combinations.i @@ -14,7 +14,7 @@ %template(VectorVectorString) std::vector< std::vector >; %template(PairIntPairIntString) std::pair< int, std::pair >; -#if defined(SWIGCSHARP) +#if defined(SWIGCSHARP) || defined(SWIGD) // Checks macro containing a type with a comma SWIG_STD_VECTOR_ENHANCED(std::pair< double, std::string >) #endif diff --git a/Examples/test-suite/minherit2.i b/Examples/test-suite/minherit2.i index 1bca4fc48..7d470d30e 100644 --- a/Examples/test-suite/minherit2.i +++ b/Examples/test-suite/minherit2.i @@ -1,16 +1,18 @@ %module minherit2 -// A multiple inheritance example, mainly for Java and C#. -// The example shows how it is possible to turn C++ abstract base classes into Java/C# interface. +// A multiple inheritance example, mainly for Java, C# and D. +// The example shows how it is possible to turn C++ abstract base classes into +// Java/C#/D interfaces. // In the future, all this trouble might be more automated. %warnfilter(SWIGWARN_JAVA_MULTIPLE_INHERITANCE, SWIGWARN_CSHARP_MULTIPLE_INHERITANCE, + SWIGWARN_D_MULTIPLE_INHERITANCE, SWIGWARN_RUBY_MULTIPLE_INHERITANCE, SWIGWARN_PHP_MULTIPLE_INHERITANCE) RemoteMpe; -#if defined(SWIGJAVA) || defined(SWIGCSHARP) +#if defined(SWIGJAVA) || defined(SWIGCSHARP) || defined(SWIGD) #if defined(SWIGCSHARP) #define javaclassmodifiers csclassmodifiers @@ -22,6 +24,21 @@ #define javabase csbase #endif +#if defined(SWIGD) +#define javaclassmodifiers dclassmodifiers +#define javabody dbody +#define javafinalize ddestructor +#define javadestruct ddispose +#define javaout dout +#define javainterfaces dinterfaces +#define javabase dbase + +%typemap(dimports) RemoteMpe %{ +$importtype(IRemoteSyncIO) +$importtype(IRemoteAsyncIO) +%} +#endif + // Modify multiple inherited base classes into inheriting interfaces %typemap(javainterfaces) RemoteMpe "IRemoteSyncIO, IRemoteAsyncIO"; %typemap(javabase, replace="1") RemoteMpe ""; @@ -51,6 +68,12 @@ // Features are inherited by derived classes, so override this %csmethodmodifiers RemoteMpe::syncmethod "public" %csmethodmodifiers RemoteMpe::asyncmethod "public" +#elif defined(SWIGD) +%dmethodmodifiers IRemoteSyncIO::syncmethod ""; +%dmethodmodifiers IRemoteAsyncIO::asyncmethod ""; +// Features are inherited by derived classes, so override this +%dmethodmodifiers RemoteMpe::syncmethod "public" +%dmethodmodifiers RemoteMpe::asyncmethod "public" #endif #endif diff --git a/Examples/test-suite/multiple_inheritance.i b/Examples/test-suite/multiple_inheritance.i index 1fc68eef9..044345020 100644 --- a/Examples/test-suite/multiple_inheritance.i +++ b/Examples/test-suite/multiple_inheritance.i @@ -5,11 +5,13 @@ It tests basic multiple inheritance */ %warnfilter(SWIGWARN_JAVA_MULTIPLE_INHERITANCE, SWIGWARN_CSHARP_MULTIPLE_INHERITANCE, - SWIGWARN_PHP_MULTIPLE_INHERITANCE) FooBar; /* C#, Java, PHP multiple inheritance */ + SWIGWARN_D_MULTIPLE_INHERITANCE, + SWIGWARN_PHP_MULTIPLE_INHERITANCE) FooBar; /* C#, D, Java, PHP multiple inheritance */ %warnfilter(SWIGWARN_JAVA_MULTIPLE_INHERITANCE, SWIGWARN_CSHARP_MULTIPLE_INHERITANCE, - SWIGWARN_PHP_MULTIPLE_INHERITANCE) FooBarSpam; /* C#, Java, PHP multiple inheritance */ + SWIGWARN_D_MULTIPLE_INHERITANCE, + SWIGWARN_PHP_MULTIPLE_INHERITANCE) FooBarSpam; /* C#, D, Java, PHP multiple inheritance */ %inline %{ diff --git a/Examples/test-suite/namespace_class.i b/Examples/test-suite/namespace_class.i index 7dc9139cd..aea5362d1 100644 --- a/Examples/test-suite/namespace_class.i +++ b/Examples/test-suite/namespace_class.i @@ -2,6 +2,10 @@ %warnfilter(SWIGWARN_PARSE_NAMED_NESTED_CLASS) Ala::Ola; +#ifdef SWIGD +%warnfilter(SWIGWARN_IGNORE_OPERATOR_LT); +#endif + %inline %{ template void foobar(T t) {} namespace test { diff --git a/Examples/test-suite/preproc_line_file.i b/Examples/test-suite/preproc_line_file.i index 353aa999f..91ff2133e 100644 --- a/Examples/test-suite/preproc_line_file.i +++ b/Examples/test-suite/preproc_line_file.i @@ -33,12 +33,12 @@ const int NUMBER_UNIQUE(thing) = -2; /* resolves to thing28 */ %javaconst(1); #elif defined(SWIGCSHARP) %csconst(1); +#elif defined(SWIGD) +%dnativeconst; #else %ignore LINE_NUMBER; %ignore LINE_NUM; /* spare space */ - - #endif %{ diff --git a/Examples/test-suite/pure_virtual.i b/Examples/test-suite/pure_virtual.i index 5bda283cf..9e345e2a4 100644 --- a/Examples/test-suite/pure_virtual.i +++ b/Examples/test-suite/pure_virtual.i @@ -9,7 +9,8 @@ %warnfilter(SWIGWARN_JAVA_MULTIPLE_INHERITANCE, SWIGWARN_CSHARP_MULTIPLE_INHERITANCE, - SWIGWARN_PHP_MULTIPLE_INHERITANCE) E; /* C#, Java, PHP multiple inheritance */ + SWIGWARN_D_MULTIPLE_INHERITANCE, + SWIGWARN_PHP_MULTIPLE_INHERITANCE) E; /* C#, D, Java, PHP multiple inheritance */ %nodefaultctor C; %nodefaultdtor C; @@ -65,7 +66,7 @@ public: %} /* Fill in method from AA. This class should be constructable */ -#ifdef SWIGCSHARP +#if defined(SWIGCSHARP) || defined(SWIGD) %ignore F::method2(); // Work around for lack of multiple inheritance support - base AA is ignored. #endif diff --git a/Examples/test-suite/samename.i b/Examples/test-suite/samename.i index 819cb4abd..cc03995bc 100644 --- a/Examples/test-suite/samename.i +++ b/Examples/test-suite/samename.i @@ -1,6 +1,6 @@ %module samename -#if !(defined(SWIGCSHARP) || defined(SWIGJAVA)) +#if !(defined(SWIGCSHARP) || defined(SWIGJAVA) || defined(SWIGD)) class samename { public: void do_something() { diff --git a/Examples/test-suite/special_variable_macros.i b/Examples/test-suite/special_variable_macros.i index c168b4747..45eab0507 100644 --- a/Examples/test-suite/special_variable_macros.i +++ b/Examples/test-suite/special_variable_macros.i @@ -165,6 +165,20 @@ namespace Space { return new $typemap(jstype, Space::RenameMe)( new $typemap(jstype, Name)(s) ); } %} +#elif defined(SWIGD) +#if (SWIG_D_VERSION == 1) +%typemap(dcode) Space::RenameMe %{ + public static NewName factory(char[] s) { + return new $typemap(dptype, Space::RenameMe)( new $typemap(dptype, Name)(s) ); + } +%} +#else +%typemap(dcode) Space::RenameMe %{ + public static NewName factory(string s) { + return new $typemap(dptype, Space::RenameMe)( new $typemap(dptype, Name)(s) ); + } +%} +#endif #endif %rename(NewName) Space::RenameMe; diff --git a/Examples/test-suite/static_const_member.i b/Examples/test-suite/static_const_member.i index 3db60b4c2..945e28490 100644 --- a/Examples/test-suite/static_const_member.i +++ b/Examples/test-suite/static_const_member.i @@ -11,6 +11,9 @@ #elif SWIGCSHARP %csconst(1) EN; %csconst(1) CHARTEST; +#elif SWIGD +%dnativeconst EN; +%dnativeconst CHARTEST; #endif %inline %{ diff --git a/Examples/test-suite/template_enum.i b/Examples/test-suite/template_enum.i index 0d6fbf5b9..f36d5dc40 100644 --- a/Examples/test-suite/template_enum.i +++ b/Examples/test-suite/template_enum.i @@ -13,6 +13,10 @@ public: %template(foo_i) foo; %template(foo_d) foo; +#ifdef SWIGD +// Workaround for the D module which uses the literal value in the generated wrapper code. +%dconstvalue("3") Manta::ColorSpace::NumComponents; +#endif %inline { diff --git a/Examples/test-suite/template_inherit_abstract.i b/Examples/test-suite/template_inherit_abstract.i index 2f83433a5..87c921eab 100644 --- a/Examples/test-suite/template_inherit_abstract.i +++ b/Examples/test-suite/template_inherit_abstract.i @@ -4,7 +4,8 @@ %warnfilter(SWIGWARN_JAVA_MULTIPLE_INHERITANCE, SWIGWARN_CSHARP_MULTIPLE_INHERITANCE, - SWIGWARN_PHP_MULTIPLE_INHERITANCE) oss::Module; /* C#, Java, PHP multiple inheritance */ + SWIGWARN_D_MULTIPLE_INHERITANCE, + SWIGWARN_PHP_MULTIPLE_INHERITANCE) oss::Module; /* C#, D, Java, PHP multiple inheritance */ %inline %{ @@ -56,7 +57,7 @@ namespace oss %inline %{ namespace oss { -#if defined(SWIG) && defined(SWIGCSHARP) +#if defined(SWIG) && (defined(SWIGCSHARP) || defined(SWIGD)) %ignore HModule::get(); // Work around for lack of multiple inheritance support - base ModuleBase is ignored. #endif struct test : HModule diff --git a/Examples/test-suite/typemap_namespace.i b/Examples/test-suite/typemap_namespace.i index 6614e0372..5a198b554 100644 --- a/Examples/test-suite/typemap_namespace.i +++ b/Examples/test-suite/typemap_namespace.i @@ -28,9 +28,16 @@ namespace Foo { #endif #ifdef SWIGGO %typemap(gotype) Str1 * = char *; +#endif +#ifdef SWIGD + %typemap(cwtype) Str1 * = char *; + %typemap(dwtype) Str1 * = char *; + %typemap(dptype) Str1 * = char *; + %typemap(din) Str1 * = char *; + %typemap(dout) Str1 * = char *; #endif %typemap(in) Str1 * = char *; -#if !(defined(SWIGCSHARP) || defined(SWIGLUA) || defined(SWIGPHP) || defined(SWIGMZSCHEME) || defined(SWIGOCAML) || defined(SWIGGO)) +#if !(defined(SWIGCSHARP) || defined(SWIGLUA) || defined(SWIGPHP) || defined(SWIGMZSCHEME) || defined(SWIGOCAML) || defined(SWIGGO) || defined(SWIGD)) %typemap(freearg) Str1 * = char *; #endif %typemap(typecheck) Str1 * = char *; diff --git a/Examples/test-suite/typemap_out_optimal.i b/Examples/test-suite/typemap_out_optimal.i index 23cd2ad3f..d707ed2d5 100644 --- a/Examples/test-suite/typemap_out_optimal.i +++ b/Examples/test-suite/typemap_out_optimal.i @@ -2,7 +2,7 @@ %module typemap_out_optimal // Just the following languages tested -#if defined (SWIGCSHARP) +#if defined (SWIGCSHARP) || defined (SWIGD) %typemap(out, optimal="1") SWIGTYPE %{ $result = new $1_ltype((const $1_ltype &)$1); %} @@ -18,6 +18,10 @@ %ignore XX::operator=; +#ifdef SWIGD +%rename(trace) XX::debug; +#endif + %inline %{ #include using namespace std; diff --git a/Examples/test-suite/typemap_subst.i b/Examples/test-suite/typemap_subst.i index 1b1f8a3f4..91ac62020 100644 --- a/Examples/test-suite/typemap_subst.i +++ b/Examples/test-suite/typemap_subst.i @@ -61,8 +61,8 @@ $1 = ($ltype) temp; } -/* Java, C# and Go modules don't use SWIG's runtime type system */ -#if !defined(SWIGJAVA) && !defined(SWIGCSHARP) && !defined(SWIGGO) +/* Java, C#, Go and D modules don't use SWIG's runtime type system */ +#if !defined(SWIGJAVA) && !defined(SWIGCSHARP) && !defined(SWIGGO) && !defined(SWIGD) %inline %{ void foo(const struct xyzzy **TEST) {} %} diff --git a/Examples/test-suite/using_composition.i b/Examples/test-suite/using_composition.i index bd0f712b5..052412b5f 100644 --- a/Examples/test-suite/using_composition.i +++ b/Examples/test-suite/using_composition.i @@ -2,13 +2,16 @@ %warnfilter(SWIGWARN_JAVA_MULTIPLE_INHERITANCE, SWIGWARN_CSHARP_MULTIPLE_INHERITANCE, - SWIGWARN_PHP_MULTIPLE_INHERITANCE) FooBar; // C#, Java, PHP multiple inheritance + SWIGWARN_D_MULTIPLE_INHERITANCE, + SWIGWARN_PHP_MULTIPLE_INHERITANCE) FooBar; // C#, D, Java, PHP multiple inheritance %warnfilter(SWIGWARN_JAVA_MULTIPLE_INHERITANCE, SWIGWARN_CSHARP_MULTIPLE_INHERITANCE, - SWIGWARN_PHP_MULTIPLE_INHERITANCE) FooBar2; // C#, Java, PHP multiple inheritance + SWIGWARN_D_MULTIPLE_INHERITANCE, + SWIGWARN_PHP_MULTIPLE_INHERITANCE) FooBar2; // C#, D, Java, PHP multiple inheritance %warnfilter(SWIGWARN_JAVA_MULTIPLE_INHERITANCE, SWIGWARN_CSHARP_MULTIPLE_INHERITANCE, - SWIGWARN_PHP_MULTIPLE_INHERITANCE) FooBar3; // C#, Java, PHP multiple inheritance + SWIGWARN_D_MULTIPLE_INHERITANCE, + SWIGWARN_PHP_MULTIPLE_INHERITANCE) FooBar3; // C#, D, Java, PHP multiple inheritance #ifdef SWIGLUA // lua only has one numeric type, so some overloads shadow each other creating warnings %warnfilter(SWIGWARN_LANG_OVERLOAD_SHADOW) blah; #endif diff --git a/Examples/test-suite/using_extend.i b/Examples/test-suite/using_extend.i index e14cc28e8..c52f65c23 100644 --- a/Examples/test-suite/using_extend.i +++ b/Examples/test-suite/using_extend.i @@ -2,7 +2,8 @@ %warnfilter(SWIGWARN_JAVA_MULTIPLE_INHERITANCE, SWIGWARN_CSHARP_MULTIPLE_INHERITANCE, - SWIGWARN_PHP_MULTIPLE_INHERITANCE) FooBar; // C#, Java, PHP multiple inheritance + SWIGWARN_D_MULTIPLE_INHERITANCE, + SWIGWARN_PHP_MULTIPLE_INHERITANCE) FooBar; // C#, D, Java, PHP multiple inheritance #ifdef SWIGLUA // lua only has one numeric type, so some overloads shadow each other creating warnings %warnfilter(SWIGWARN_LANG_OVERLOAD_SHADOW) blah; #endif diff --git a/Examples/test-suite/using_namespace.i b/Examples/test-suite/using_namespace.i index ce02e9a87..1119b46f7 100644 --- a/Examples/test-suite/using_namespace.i +++ b/Examples/test-suite/using_namespace.i @@ -5,7 +5,8 @@ %warnfilter(SWIGWARN_JAVA_MULTIPLE_INHERITANCE, SWIGWARN_CSHARP_MULTIPLE_INHERITANCE, - SWIGWARN_PHP_MULTIPLE_INHERITANCE) Hi; // C#, Java, PHP multiple inheritance + SWIGWARN_D_MULTIPLE_INHERITANCE, + SWIGWARN_PHP_MULTIPLE_INHERITANCE) Hi; // C#, D, Java, PHP multiple inheritance %inline %{ namespace hello -- cgit v1.2.1 From 03aefbc6e95d094a6de231e1f5264c0946e209a3 Mon Sep 17 00:00:00 2001 From: David Nadlinger Date: Thu, 18 Nov 2010 00:24:02 +0000 Subject: Added support for the D programming languge. It is still a bit rough around some edges, particularly with regard to multi-threading and operator overloading, and there are some documentation bits missing, but it should be fine for basic use. The test-suite should build and run fine with the current versions of DMD, LDC and Tango (at least) on Linux x86_64 and Mac OS X 10.6. git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12299 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Doc/Manual/D.html | 401 ++ Doc/Manual/Sections.html | 1 + Doc/Manual/chapters | 1 + Examples/Makefile.in | 89 +- Examples/d/callback/Makefile | 28 + Examples/d/callback/d1/runme.d | 36 + Examples/d/callback/d2/runme.d | 36 + Examples/d/callback/example.cxx | 4 + Examples/d/callback/example.h | 24 + Examples/d/callback/example.i | 13 + Examples/d/check.list | 9 + Examples/d/class/Makefile | 28 + Examples/d/class/d1/runme.d | 58 + Examples/d/class/d2/runme.d | 58 + Examples/d/class/example.cxx | 28 + Examples/d/class/example.h | 34 + Examples/d/class/example.i | 10 + Examples/d/constants/Makefile | 28 + Examples/d/constants/d1/runme.d | 28 + Examples/d/constants/d2/runme.d | 28 + Examples/d/constants/example.d | 23 + Examples/d/constants/example.i | 32 + Examples/d/enum/Makefile | 28 + Examples/d/enum/d1/runme.d | 28 + Examples/d/enum/d2/runme.d | 28 + Examples/d/enum/example.cxx | 37 + Examples/d/enum/example.h | 13 + Examples/d/enum/example.i | 11 + Examples/d/extend/Makefile | 28 + Examples/d/extend/d1/runme.d | 75 + Examples/d/extend/d2/runme.d | 75 + Examples/d/extend/example.cxx | 4 + Examples/d/extend/example.h | 56 + Examples/d/extend/example.i | 14 + Examples/d/funcptr/Makefile | 28 + Examples/d/funcptr/d1/runme.d | 34 + Examples/d/funcptr/d2/runme.d | 34 + Examples/d/funcptr/example.c | 19 + Examples/d/funcptr/example.h | 9 + Examples/d/funcptr/example.i | 16 + Examples/d/simple/Makefile | 28 + Examples/d/simple/d1/runme.d | 27 + Examples/d/simple/d2/runme.d | 27 + Examples/d/simple/example.c | 18 + Examples/d/simple/example.i | 7 + Examples/d/variables/Makefile | 28 + Examples/d/variables/d1/runme.d | 71 + Examples/d/variables/d2/runme.d | 71 + Examples/d/variables/example.c | 91 + Examples/d/variables/example.h | 6 + Examples/d/variables/example.i | 49 + Examples/test-suite/d/Makefile.in | 80 + Examples/test-suite/d/README | 7 + Examples/test-suite/d/aggregate_runme.1.d | 25 + Examples/test-suite/d/aggregate_runme.2.d | 25 + Examples/test-suite/d/allprotected_runme.1.d | 65 + Examples/test-suite/d/allprotected_runme.2.d | 65 + Examples/test-suite/d/apply_strings_runme.1.d | 12 + Examples/test-suite/d/apply_strings_runme.2.d | 12 + Examples/test-suite/d/bools_runme.1.d | 20 + Examples/test-suite/d/bools_runme.2.d | 20 + Examples/test-suite/d/catches_runme.1.d | 33 + Examples/test-suite/d/catches_runme.2.d | 33 + Examples/test-suite/d/char_strings_runme.1.d | 151 + Examples/test-suite/d/char_strings_runme.2.d | 123 + Examples/test-suite/d/constover_runme.1.d | 31 + Examples/test-suite/d/constover_runme.2.d | 16 + Examples/test-suite/d/d_nativepointers_runme.1.d | 23 + Examples/test-suite/d/d_nativepointers_runme.2.d | 23 + Examples/test-suite/d/default_args_runme.1.d | 127 + Examples/test-suite/d/default_args_runme.2.d | 84 + .../test-suite/d/default_constructor_runme.1.d | 30 + .../test-suite/d/default_constructor_runme.2.d | 25 + Examples/test-suite/d/director_basic_runme.1.d | 59 + Examples/test-suite/d/director_basic_runme.2.d | 46 + Examples/test-suite/d/director_classes_runme.1.d | 168 + Examples/test-suite/d/director_classes_runme.2.d | 169 + Examples/test-suite/d/director_classic_runme.1.d | 207 + Examples/test-suite/d/director_classic_runme.2.d | 202 + Examples/test-suite/d/director_ignore_runme.1.d | 39 + Examples/test-suite/d/director_ignore_runme.2.d | 38 + .../test-suite/d/director_primitives_runme.1.d | 122 + .../test-suite/d/director_primitives_runme.2.d | 123 + Examples/test-suite/d/director_protected_runme.1.d | 50 + Examples/test-suite/d/director_protected_runme.2.d | 36 + Examples/test-suite/d/director_string_runme.1.d | 46 + Examples/test-suite/d/director_string_runme.2.d | 42 + Examples/test-suite/d/enum_thorough_runme.1.d | 424 ++ Examples/test-suite/d/enum_thorough_runme.2.d | 425 ++ .../test-suite/d/inherit_target_language_runme.1.d | 29 + .../test-suite/d/inherit_target_language_runme.2.d | 29 + Examples/test-suite/d/li_attribute_runme.1.d | 75 + Examples/test-suite/d/li_attribute_runme.2.d | 58 + .../d/li_boost_shared_ptr_bits_runme.1.d | 21 + .../d/li_boost_shared_ptr_bits_runme.2.d | 19 + .../test-suite/d/li_boost_shared_ptr_runme.1.d | 604 +++ .../test-suite/d/li_boost_shared_ptr_runme.2.d | 602 +++ Examples/test-suite/d/li_std_except_runme.1.d | 40 + Examples/test-suite/d/li_std_except_runme.2.d | 34 + Examples/test-suite/d/li_std_string_runme.1.d | 97 + Examples/test-suite/d/li_std_string_runme.2.d | 86 + Examples/test-suite/d/li_std_vector_runme.1.d | 219 + Examples/test-suite/d/li_std_vector_runme.2.d | 207 + Examples/test-suite/d/li_typemaps_runme.1.d | 94 + Examples/test-suite/d/li_typemaps_runme.2.d | 91 + Examples/test-suite/d/long_long_runme.1.d | 35 + Examples/test-suite/d/long_long_runme.2.d | 32 + Examples/test-suite/d/member_pointer_runme.1.d | 43 + Examples/test-suite/d/member_pointer_runme.2.d | 42 + .../test-suite/d/overload_complicated_runme.1.d | 50 + .../test-suite/d/overload_complicated_runme.2.d | 34 + Examples/test-suite/d/overload_template_runme.1.d | 146 + Examples/test-suite/d/overload_template_runme.2.d | 80 + Examples/test-suite/d/pointer_reference_runme.1.d | 13 + Examples/test-suite/d/pointer_reference_runme.2.d | 14 + .../test-suite/d/preproc_constants_c_runme.1.d | 63 + .../test-suite/d/preproc_constants_c_runme.2.d | 63 + Examples/test-suite/d/preproc_constants_runme.1.d | 62 + Examples/test-suite/d/preproc_constants_runme.2.d | 62 + Examples/test-suite/d/sizet_runme.1.d | 15 + Examples/test-suite/d/sizet_runme.2.d | 14 + Examples/test-suite/d/sneaky1_runme.1.d | 21 + Examples/test-suite/d/sneaky1_runme.2.d | 11 + .../test-suite/d/special_variable_macros_runme.1.d | 39 + .../test-suite/d/special_variable_macros_runme.2.d | 21 + Examples/test-suite/d/threads_runme.1.d | 70 + Examples/test-suite/d/threads_runme.2.d | 55 + Examples/test-suite/d/throw_exception_runme.1.d | 30 + Examples/test-suite/d/throw_exception_runme.2.d | 30 + Examples/test-suite/d/typemap_namespace_runme.1.d | 13 + Examples/test-suite/d/typemap_namespace_runme.2.d | 9 + .../test-suite/d/typemap_out_optimal_runme.1.d | 9 + .../test-suite/d/typemap_out_optimal_runme.2.d | 9 + Examples/test-suite/d/varargs_runme.1.d | 20 + Examples/test-suite/d/varargs_runme.2.d | 13 + Examples/test-suite/d/virtual_poly_runme.1.d | 27 + Examples/test-suite/d/virtual_poly_runme.2.d | 22 + Examples/test-suite/d_nativepointers.i | 18 + Lib/allkw.swg | 1 + Lib/d/boost_shared_ptr.i | 201 + Lib/d/carrays.i | 111 + Lib/d/cpointer.i | 171 + Lib/d/d.swg | 46 + Lib/d/dclassgen.swg | 172 + Lib/d/ddirectives.swg | 11 + Lib/d/denums.swg | 60 + Lib/d/dexception.swg | 30 + Lib/d/dhead.swg | 310 ++ Lib/d/director.swg | 46 + Lib/d/dkw.swg | 126 + Lib/d/dmemberfunctionpointers.swg | 92 + Lib/d/doperators.swg | 77 + Lib/d/dprimitives.swg | 158 + Lib/d/dstrings.swg | 80 + Lib/d/dswigtype.swg | 177 + Lib/d/dvoid.swg | 18 + Lib/d/std_common.i | 5 + Lib/d/std_deque.i | 1 + Lib/d/std_except.i | 30 + Lib/d/std_map.i | 59 + Lib/d/std_pair.i | 34 + Lib/d/std_shared_ptr.i | 2 + Lib/d/std_string.i | 98 + Lib/d/std_vector.i | 591 +++ Lib/d/stl.i | 12 + Lib/d/typemaps.i | 298 ++ Lib/d/wrapperloader.swg | 303 ++ Lib/exception.i | 36 +- Lib/std_except.i | 2 +- Lib/swig.swg | 4 +- Makefile.in | 17 +- Source/Include/swigwarn.h | 21 +- Source/Makefile.am | 1 + Source/Modules/d.cxx | 4359 ++++++++++++++++++++ Source/Modules/swigmain.cxx | 2 + configure.in | 43 + 176 files changed, 16449 insertions(+), 29 deletions(-) create mode 100644 Doc/Manual/D.html create mode 100644 Examples/d/callback/Makefile create mode 100644 Examples/d/callback/d1/runme.d create mode 100644 Examples/d/callback/d2/runme.d create mode 100644 Examples/d/callback/example.cxx create mode 100644 Examples/d/callback/example.h create mode 100644 Examples/d/callback/example.i create mode 100644 Examples/d/check.list create mode 100644 Examples/d/class/Makefile create mode 100644 Examples/d/class/d1/runme.d create mode 100644 Examples/d/class/d2/runme.d create mode 100644 Examples/d/class/example.cxx create mode 100644 Examples/d/class/example.h create mode 100644 Examples/d/class/example.i create mode 100644 Examples/d/constants/Makefile create mode 100644 Examples/d/constants/d1/runme.d create mode 100644 Examples/d/constants/d2/runme.d create mode 100644 Examples/d/constants/example.d create mode 100644 Examples/d/constants/example.i create mode 100644 Examples/d/enum/Makefile create mode 100644 Examples/d/enum/d1/runme.d create mode 100644 Examples/d/enum/d2/runme.d create mode 100644 Examples/d/enum/example.cxx create mode 100644 Examples/d/enum/example.h create mode 100644 Examples/d/enum/example.i create mode 100644 Examples/d/extend/Makefile create mode 100644 Examples/d/extend/d1/runme.d create mode 100644 Examples/d/extend/d2/runme.d create mode 100644 Examples/d/extend/example.cxx create mode 100644 Examples/d/extend/example.h create mode 100644 Examples/d/extend/example.i create mode 100644 Examples/d/funcptr/Makefile create mode 100644 Examples/d/funcptr/d1/runme.d create mode 100644 Examples/d/funcptr/d2/runme.d create mode 100644 Examples/d/funcptr/example.c create mode 100644 Examples/d/funcptr/example.h create mode 100644 Examples/d/funcptr/example.i create mode 100644 Examples/d/simple/Makefile create mode 100644 Examples/d/simple/d1/runme.d create mode 100644 Examples/d/simple/d2/runme.d create mode 100644 Examples/d/simple/example.c create mode 100644 Examples/d/simple/example.i create mode 100644 Examples/d/variables/Makefile create mode 100644 Examples/d/variables/d1/runme.d create mode 100644 Examples/d/variables/d2/runme.d create mode 100644 Examples/d/variables/example.c create mode 100644 Examples/d/variables/example.h create mode 100644 Examples/d/variables/example.i create mode 100644 Examples/test-suite/d/Makefile.in create mode 100644 Examples/test-suite/d/README create mode 100644 Examples/test-suite/d/aggregate_runme.1.d create mode 100644 Examples/test-suite/d/aggregate_runme.2.d create mode 100644 Examples/test-suite/d/allprotected_runme.1.d create mode 100644 Examples/test-suite/d/allprotected_runme.2.d create mode 100644 Examples/test-suite/d/apply_strings_runme.1.d create mode 100644 Examples/test-suite/d/apply_strings_runme.2.d create mode 100644 Examples/test-suite/d/bools_runme.1.d create mode 100644 Examples/test-suite/d/bools_runme.2.d create mode 100644 Examples/test-suite/d/catches_runme.1.d create mode 100644 Examples/test-suite/d/catches_runme.2.d create mode 100644 Examples/test-suite/d/char_strings_runme.1.d create mode 100644 Examples/test-suite/d/char_strings_runme.2.d create mode 100644 Examples/test-suite/d/constover_runme.1.d create mode 100644 Examples/test-suite/d/constover_runme.2.d create mode 100644 Examples/test-suite/d/d_nativepointers_runme.1.d create mode 100644 Examples/test-suite/d/d_nativepointers_runme.2.d create mode 100644 Examples/test-suite/d/default_args_runme.1.d create mode 100644 Examples/test-suite/d/default_args_runme.2.d create mode 100644 Examples/test-suite/d/default_constructor_runme.1.d create mode 100644 Examples/test-suite/d/default_constructor_runme.2.d create mode 100644 Examples/test-suite/d/director_basic_runme.1.d create mode 100644 Examples/test-suite/d/director_basic_runme.2.d create mode 100644 Examples/test-suite/d/director_classes_runme.1.d create mode 100644 Examples/test-suite/d/director_classes_runme.2.d create mode 100644 Examples/test-suite/d/director_classic_runme.1.d create mode 100644 Examples/test-suite/d/director_classic_runme.2.d create mode 100644 Examples/test-suite/d/director_ignore_runme.1.d create mode 100644 Examples/test-suite/d/director_ignore_runme.2.d create mode 100644 Examples/test-suite/d/director_primitives_runme.1.d create mode 100644 Examples/test-suite/d/director_primitives_runme.2.d create mode 100644 Examples/test-suite/d/director_protected_runme.1.d create mode 100644 Examples/test-suite/d/director_protected_runme.2.d create mode 100644 Examples/test-suite/d/director_string_runme.1.d create mode 100644 Examples/test-suite/d/director_string_runme.2.d create mode 100644 Examples/test-suite/d/enum_thorough_runme.1.d create mode 100644 Examples/test-suite/d/enum_thorough_runme.2.d create mode 100644 Examples/test-suite/d/inherit_target_language_runme.1.d create mode 100644 Examples/test-suite/d/inherit_target_language_runme.2.d create mode 100644 Examples/test-suite/d/li_attribute_runme.1.d create mode 100644 Examples/test-suite/d/li_attribute_runme.2.d create mode 100644 Examples/test-suite/d/li_boost_shared_ptr_bits_runme.1.d create mode 100644 Examples/test-suite/d/li_boost_shared_ptr_bits_runme.2.d create mode 100644 Examples/test-suite/d/li_boost_shared_ptr_runme.1.d create mode 100644 Examples/test-suite/d/li_boost_shared_ptr_runme.2.d create mode 100644 Examples/test-suite/d/li_std_except_runme.1.d create mode 100644 Examples/test-suite/d/li_std_except_runme.2.d create mode 100644 Examples/test-suite/d/li_std_string_runme.1.d create mode 100644 Examples/test-suite/d/li_std_string_runme.2.d create mode 100644 Examples/test-suite/d/li_std_vector_runme.1.d create mode 100644 Examples/test-suite/d/li_std_vector_runme.2.d create mode 100644 Examples/test-suite/d/li_typemaps_runme.1.d create mode 100644 Examples/test-suite/d/li_typemaps_runme.2.d create mode 100644 Examples/test-suite/d/long_long_runme.1.d create mode 100644 Examples/test-suite/d/long_long_runme.2.d create mode 100644 Examples/test-suite/d/member_pointer_runme.1.d create mode 100644 Examples/test-suite/d/member_pointer_runme.2.d create mode 100644 Examples/test-suite/d/overload_complicated_runme.1.d create mode 100644 Examples/test-suite/d/overload_complicated_runme.2.d create mode 100644 Examples/test-suite/d/overload_template_runme.1.d create mode 100644 Examples/test-suite/d/overload_template_runme.2.d create mode 100644 Examples/test-suite/d/pointer_reference_runme.1.d create mode 100644 Examples/test-suite/d/pointer_reference_runme.2.d create mode 100644 Examples/test-suite/d/preproc_constants_c_runme.1.d create mode 100644 Examples/test-suite/d/preproc_constants_c_runme.2.d create mode 100644 Examples/test-suite/d/preproc_constants_runme.1.d create mode 100644 Examples/test-suite/d/preproc_constants_runme.2.d create mode 100644 Examples/test-suite/d/sizet_runme.1.d create mode 100644 Examples/test-suite/d/sizet_runme.2.d create mode 100644 Examples/test-suite/d/sneaky1_runme.1.d create mode 100644 Examples/test-suite/d/sneaky1_runme.2.d create mode 100644 Examples/test-suite/d/special_variable_macros_runme.1.d create mode 100644 Examples/test-suite/d/special_variable_macros_runme.2.d create mode 100644 Examples/test-suite/d/threads_runme.1.d create mode 100644 Examples/test-suite/d/threads_runme.2.d create mode 100644 Examples/test-suite/d/throw_exception_runme.1.d create mode 100644 Examples/test-suite/d/throw_exception_runme.2.d create mode 100644 Examples/test-suite/d/typemap_namespace_runme.1.d create mode 100644 Examples/test-suite/d/typemap_namespace_runme.2.d create mode 100644 Examples/test-suite/d/typemap_out_optimal_runme.1.d create mode 100644 Examples/test-suite/d/typemap_out_optimal_runme.2.d create mode 100644 Examples/test-suite/d/varargs_runme.1.d create mode 100644 Examples/test-suite/d/varargs_runme.2.d create mode 100644 Examples/test-suite/d/virtual_poly_runme.1.d create mode 100644 Examples/test-suite/d/virtual_poly_runme.2.d create mode 100644 Examples/test-suite/d_nativepointers.i create mode 100644 Lib/d/boost_shared_ptr.i create mode 100644 Lib/d/carrays.i create mode 100644 Lib/d/cpointer.i create mode 100644 Lib/d/d.swg create mode 100644 Lib/d/dclassgen.swg create mode 100644 Lib/d/ddirectives.swg create mode 100644 Lib/d/denums.swg create mode 100644 Lib/d/dexception.swg create mode 100644 Lib/d/dhead.swg create mode 100644 Lib/d/director.swg create mode 100644 Lib/d/dkw.swg create mode 100644 Lib/d/dmemberfunctionpointers.swg create mode 100644 Lib/d/doperators.swg create mode 100644 Lib/d/dprimitives.swg create mode 100644 Lib/d/dstrings.swg create mode 100644 Lib/d/dswigtype.swg create mode 100644 Lib/d/dvoid.swg create mode 100644 Lib/d/std_common.i create mode 100644 Lib/d/std_deque.i create mode 100644 Lib/d/std_except.i create mode 100644 Lib/d/std_map.i create mode 100644 Lib/d/std_pair.i create mode 100644 Lib/d/std_shared_ptr.i create mode 100644 Lib/d/std_string.i create mode 100644 Lib/d/std_vector.i create mode 100644 Lib/d/stl.i create mode 100644 Lib/d/typemaps.i create mode 100644 Lib/d/wrapperloader.swg create mode 100644 Source/Modules/d.cxx diff --git a/Doc/Manual/D.html b/Doc/Manual/D.html new file mode 100644 index 000000000..2b563788f --- /dev/null +++ b/Doc/Manual/D.html @@ -0,0 +1,401 @@ + + + +SWIG and D + + + + +

    20 SWIG and D

    + + + + + + +

    20.1 Introduction

    + + +

    From the D Programming Language web site: »D is a systems programming language. Its focus is on combining the power and high performance of C and C++ with the programmer productivity of modern languages like Ruby and Python. […] The D language is statically typed and compiles directly to machine code.« As such, it is not very surprising that D is able to directly interface with C libraries. Why would a SWIG module for D be needed then in the first place?

    + +

    Well, besides the obvious downside that the C header files have to be manually converted to D modules for this to work, there is one major inconvenience with this approach: D code usually is on a higher abstraction level than C, and many of the features that make D interesting are simply not available when dealing with C libraries, requiring you e.g. to manually convert strings between pointers to \0-terminated char arrays and D char arrays, making the algorithms from the D2 standard library unusable with C arrays and data structures, and so on.

    + +

    While these issues can be worked around relatively easy by hand-coding a thin wrapper layer around the C library in question, there is another issue where writing wrapper code per hand is not feasible: C++ libraries. D did not support interfacing to C++ in version 1 at all, and even if extern(C++) has been added to D2, the support is still very limited, and a custom wrapper layer is still required in many cases.

    + +

    To help addressing these issues, the SWIG C# module has been forked to support D. Is has evolved quite a lot since then, but there are still many similarities, so if you do not find what you are looking for on this page, it might be worth having a look at the chapter on C# (and also on Java, since the C# module was in turn forked from it).

    + + +

    20.2 Command line invocation

    + + +

    To activate the D module, pass the -d option to SWIG at the command line. The same standard command line switches as with any other language module are available, plus the following D specific ones:

    + +
    +
    -splitproxy
    +
    +

    By default, SWIG generates two D modules: the proxy module, named like the source module (either specified via the %module directive or via the module command line switch), which contains all the proxy classes, functions, enums, etc., and the wrap module (named like the proxy module, but suffixed with _wrap), which contains all the extern(C) function declarations and other private parts only used internally by the proxy module.

    +

    If the split proxy mode is enabled by passing this switch at the command line, all proxy classes and enums are emitted to their own D module instead. The main proxy module only contains free functions and constants in this case.

    +
    + +
    -package <pkg>
    +
    +

    By default, the proxy D modules and the wrap D module are written to the root package. Using this option, you can specify another target package instead.

    +
    + +
    -wrapperlibrary <wl>
    +
    +

    The code SWIG generates to dynamically load the C/C++ wrapper layer looks for a library called $module_wrap, just like the wrap D module is. With this switch, you can override the name of the file the wrapper code loads at runtime (the lib prefix and the suffix for shared libraries are appended automatically, depending on the OS).

    +

    This might especially be useful if you want to invoke SWIG several times on separate modules, but compile the resulting code into a single shared library.

    +
    +
    + + +

    20.3 Typemaps

    + + +

    20.3.1 C# <-> D name comparison

    + + +
    + ctype                  <->  cwtype
    + imtype                 <->  dwtype
    + cstype                 <->  dptype
    + csin                   <->  din
    + csout                  <->  dout
    + csdirectorin           <->  ddirectorin
    + csdirectorout          <->  ddirectorout
    + csinterfaces           <->  dinterfaces
    + csinterfaces_derived   <->  dinterfaces_derived
    + csbase                 <->  dbase
    + csclassmodifiers       <->  dclassmodifiers
    + cscode                 <->  dcode
    + csimports              <->  dimports
    + csbody                 <->  dbody
    + csfinalize             <->  ddestructor
    + csdestruct             <->  ddispose
    + csdestruct_derived     <->  ddispose_derived
    +
    + + +

    20.3.2 cwtype, dwtype, dptype

    + + +

    Mapping of types between the C/C++ library, the C/C++ library wrapper exposing the C functions, the D wrapper module importing these functions and the D proxy code.

    + +

    The cwtype typemap is used to determine the types to use in the C wrapper functions. The types from the dwtype typemap are used in the extern(C) declarations of these functions in the D wrap module. The dptype typemap contains the D types used in the D proxy module/class.

    + + +

    20.3.3 in, out, directorin, directorout

    + + +

    Used for converting between the types for C/C++ and D when generating the code for the wrapper functions (on the C++ side).

    + +

    The code from the in typemap is used to convert arguments to the C wrapper function to the type used in the wrapped code (cwtype->original C++ type), the out typemap is utilized to convert values from the wrapped code to wrapper function return types (original C++ type->cwtype).

    + +

    The directorin typemap is used to convert parameters to the type used in the D director callback function, its return value is processed by directorout (see below).

    + + +

    20.3.4 din, dout, ddirectorin, ddirectorout

    + + +

    Typemaps for code generation in D proxy and type wrapper classes.

    + +

    The din typemap is used for converting function parameter types from the type used in the proxy module or class to the type used in the D wrap module (the $dinput macro is replaced).

    + +

    The dout typemap is used for converting function return values from the return type used in the wrap D module to the type returned by the proxy function. The $excode special variable in dout typemaps is replaced by the excode typemap attribute code if the method can throw any exceptions from unmanaged code, otherwise by nothing (the $wcall and $owner macros are replaced).

    + +

    The code from the ddirectorin and ddirectorout typemaps is used for conversion in director callback functions. Arguments are converted to the type used in the proxy class method they are calling by using the code from ddirectorin, the proxy class method return value is converted to the type the C++ code expects via the ddirectorout typemap (the $dpcall and $winput macros are replaced).

    + +

    The full chain of type conversions when a director callback is invoked looks like this:

    + +
          type CPPClass::method(type a)
    +        ↑                     ↓
    +   <directorout>         <directorin>
    +        ↑                     ↓
    +     cwtype methodCallback(cwtype a)    C++
    + ::::::::::::::::::::::::::::::::::::::::::
    +     dwtype methodCallback(dwtype a)    D
    +        ↑                     ↓
    +  <ddirectorout>       <ddirectorin>
    +        ↑                     ↓
    +      dptype DClass.method(dptype a)
    + + +

    20.3.5 typecheck typemaps

    + + +

    Because, unlike many scripting languages supported by SWIG, D does not need any dynamic dispatch helper to access an overloaded function, the purpose of these is merely to issue a warning for overloaded C++ functions that cannot be overloaded in D (as more than one C++ type maps to a single D type).

    + + +

    20.3.6 Code injection typemaps

    + + +

    These typemaps are used for generating the skeleton of proxy classes for C++ types.

    + +

    By overriding dbase, dinterfaces or dinterfaces_derived, the inheritance chain of the generated proxy class for a type can be modified. dclassmodifiers allows you to add any custom modifiers around the class keyword.

    + +

    Using dcode and dimports, you can specify additional D code which will be emitted into the class body respectively the imports section of the D module the class is written to.

    + +

    dconstructor, ddestructor, ddispose and ddispose_derived are used to generate the class constructor, destructor and dispose() method, respectively. The auxiliary code for handling the pointer to the C++ object is stored in dbody and dbody_derived. You can override them for specific types.

    + + +

    20.3.7 Special variable macros

    + + +

    The standard SWIG special variables are available for use within typemaps as described in the Typemaps documentation, for example $1, $input, $result etc.

    + +

    When generating D wrappers, a few additional macros are available:

    +
    +
    $dclassname (C#: $csclassname)
    +
    +

    This special variable works similar to $n_type in that it returns the name of a type – it expands to the D proxy class name of the type being wrapped. If the type does not have an associated proxy class, it expands to the type wrapper class name, for example, SWIGTYPE_p_p_SomeCppClass is generated when wrapping SomeCppClass **.

    +

    There are two other variants available, $&dclassname and $*dclassname. The former adds a level of indirection, while the latter removes one. For instance, when wrapping Foo **, $*dclassname would be replaced by the proxy class name corresponding to Foo *.

    +
    + +
    $null
    +

    In code inserted into the generated C/C++ wrapper functions, this variable is replaced by either 0 or nothing at all, depending on whether the function has a return value or not. It can be used to bail out early e.g. in case of errors (return $null;).

    + +
    $dinput (C#: $csinput)
    +
    +

    This variable is used in din typemaps and is replaced by the expression which is to be passed to C/C++.

    +

    For example, this input

    +
    +%typemap(din) SomeClass * "SomeClass.getCPointer($dinput)"
    +
    +%inline %{
    +  class SomeClass {};
    +  void foo(SomeClass *arg);
    +%}
    +

    leads to the following D proxy code being generated:

    +
    +void foo(SomeClass arg) {
    +  example_wrap.foo(SomeClass.getCPointer(arg));
    +}
    + +
    $wcall and $owner (C#: $imcall)
    +
    +

    These variables are used in dout typemaps. $wcall contains the call to the wrapper layer which provides the value to be used, and $owner signals if the caller is responsible for managing the object lifetime (that is, if the called method is a constructor or has been marked via %newobject).

    +

    Consider the following example:

    +
    +%typemap(dout) SomeClass * {
    +  return new SomeClass($wcall, $owner);
    +}
    +
    +%inline %{
    +  class SomeClass;
    +  SomeClass *foo();
    +
    +  %newobject bar();
    +  SomeClass *bar();
    +%}
    +

    The code generated for foo() and bar() looks like this:

    +
    +SomeClass foo() {
    +  return new SomeClass(example_wrap.foo(), false);
    +}
    +
    +SomeClass bar() {
    +  return new SomeClass(example_wrap.bar(), true);
    +}
    +
    +
    + +
    $dpcall and $winput (C#: $cscall, $iminput)
    +

    These variables are used in the director-specific typemaps ddirectorin and ddirectorout. They are more or less the reverse of the $wcall and $dinput macros: $dpcall contains the invocation of the D proxy method of which the return value is to be passed back to C++, $winput contains the parameter value from C++.

    + +
    $excode
    +

    This variable is used in dout and dconstructor typemaps and is filled with the contents of the excode typemap attribute if an exception could be thrown from the C++ side. See the C# documentation for details.

    + +
    $dbaseclass
    +

    Currently for internal use only, it contains the D name of the C++ base class (if any) inside proxy classes.

    + +
    $directorconnect
    +
    +

    This macro is only valid inside the dconstructor typemap and contains the value of the dconstructor typemap attribute if the currently wrapped class has directors enabled.

    +

    This is how the default dconstructor typemap looks like (you usually do not want to specify a custom one):

    +
    +%typemap(dconstructor, excode=SWIGEXCODE,directorconnect="\n  swigDirectorConnect();") SWIGTYPE {
    +  this($wcall, true);$excode$directorconnect
    +}
    +
    +
    + +
    $importtype(SomeDType)
    +
    +

    This macro is used in the dimports typemap if a dependency on another D type generated by SWIG is added by a custom typemap.

    +

    Consider the following code snippet:

    +
    +%typemap(dinterfaces) SomeClass "AnInterface, AnotherInterface";
    +
    +

    This causes SWIG to add AnInterface and AnotherInterface to the base class list of SomeClass:

    +
    +class SomeClass : AnInterface, AnotherInterface {
    +  …
    +}
    +
    +

    For this to work, AnInterface and AnotherInterface have to be in scope. If SWIG is not in split proxy mode, this is already the case, but it it is, they have to be added to the import list via the dimports typemap. Additionally, the import statement depends on the package SWIG is configured to emit the modules to.

    +

    The $importtype macro helps you to elegantly solve this problem:

    +
    +%typemap(dimports) RemoteMpe %{
    +$importtype(AnInterface)
    +$importtype(AnotherInterface)
    +%}
    +
    +

    If SWIG is in split proxy mode, it expands to an import statement for the specified type, to nothing if not.

    +
    + +
    $module
    +

    Expands to the name of the main proxy D module.

    + +
    $wrapdmodule
    +

    Contains the fully qualified name of the wrap D module.

    +
    + + +

    20.4 %features

    + + +

    The D module defines a number of directives which modify the SWIG features set globally or for a specific declaration:

    + + +
    +
    %dnativeconst and %dconstvalue(value)
    +
    +

    Out of the box, SWIG generates accessor methods for C #defines and C++ constants. The %dnativeconst directive enables wrapping these constants as D manifest constants (const in D1, enum in D2).

    +

    For this to work, the C/C++ code for the constant value must directly compile as D code, though. If this is not the case, you can manually override the expression written to the D wrapper using the %dconstvalue directive, passing the new value as parameter.

    +

    For enums, again %dconstvalue can be used to override the value of an enum item if the initializer should not compile in D.

    +
    + +
    %dmethodmodifiers
    +
    +

    This directive can be used to override the modifiers for a proxy function. For instance, you could make a public C++ member function private in D like this:

    +
    +%dmethodmodifiers A::foo "private";
    +
    +%inline %{
    +struct A {
    +  void foo();
    +};
    +%}
    +
    +
    +
    + + +

    20.5 Pragmas

    + + +

    There are a few SWIG pragmas specific to the D module, which you can use to influence the D code SWIG generates:

    + +
    +
    %pragma(d) wrapdmodulecode
    +

    The passed text (D code) is copied verbatim to the wrap D module. For example, it can be (and is, internally) used to emit additional private helper code for the use by proxy typemaps.

    + +
    %pragma(d) wrapdmoduleimports
    +

    Additional code to be emitted to the imports section of the wrap D module (the $importtype macro can be used here). You probably want to use this in conjunction with the wrapdmodulecode pragma.

    + +
    %pragma(d) proxydmodulecode
    +

    Just like proxydmodulecode, the argument is copied to the proxy D module (if SWIG is in split proxy mode, it is emitted to the main proxy D module only).

    + +
    %pragma(d) globalproxyimports
    +
    +

    The D module currently does not support specifying dependencies on external modules (e.g. from the standard library) for the D typemaps. To add the import statements to the proxy modules (resp. to all proxy modules if in split proxy mode), you can use the globalproxyimports directive.

    +

    For example:

    +
    +%typemap(din) char[] "($dinput ? tango.stdc.stringz.toStringz($dinput) : null)"
    +%pragma(d) globalproxyimports = "static import tango.stdc.stringz;";
    +
    +
    + +
    %pragma(d) wrapperloadercode
    +
    +

    The D code for loading the wrapper library (it is copied to the wrap D module). The $wrapperloaderbindcode variable is replaced by the list of commands for binding the functions from the wrapper library to the symbols in the wrap D module.

    +

    Each time this pragma is specified, the previous value is overwritten.

    +
    + +
    %pragma(d) wrapperloaderbindcommand
    +
    +

    The D command to use for binding the wrapper functions from the C/C++ library to the symbols in the wrap D module. The $function variable contains the name of the D function in the wrap module, the $symbol variable is replaced by the name of the symbol in the library.

    +

    Each time this pragma is specified, the previous value is overwritten.

    +
    +
    + + +

    20.6 D Exceptions

    + + +

    Out of the box, C++ exceptions are fundamentally incompatible to their equivalent in the D world and cannot simply be propagated to a calling D method. There is, however, an easy way to solve this problem: Just catch the exception in the C/C++ wrapper layer, pass the contents to D, and make the wrapper code rethrow the exception in the D world.

    + +

    The implementation details of this are a bit crude, but the SWIG D module automatically takes care of this, as long as it is able to detect that an exception could potentially be thrown (e.g. because the C++ method has a throw(…) exception specification).

    + +

    As this feature is implemented in exactly the same way it is for C#, please see the C# documentation for a more detailed explanation.

    + + +

    20.7 D Directors

    + + +

    When the directors feature is activated, SWIG generates extra code on both the C++ and the D side to enable cross-language polymorphism. Essentially, this means that if you subclass a proxy class in D, C++ code can access any overridden virtual methods just as if you created a derived class in C++.

    + +

    There is no D specific documentation yet, but the way the feature is implemented is very similar to how it is done in Java and C#. +

    + + +

    20.8 Other features

    + + +

    The nspace feature of SWIG is not yet supported for D – all class modules are written to the same package, regardless of which C++ namespace they are in.

    + +

    Support of pointers to primitive types.

    + + +

    20.9 D Typemap examples

    + + +

    There are no D-specific typemap examples yet. However, with the above name comparison table, you should be able to get an idea what can be done by looking at the corresponding C# section.

    + + + +

    20.10 Work in progress and planned features

    + + +

    There are a couple of features which are not implemented yet, but would be very useful and might be added in the near future:

    + +
      +
    • Static linking: Currently, the C wrapper code is compiled into a dynamic library, out of which the symbol addresses are looked up at runtime by the D part. If statically linking the different languages into one binary was supported, a tool-chain capable of performing IPO at link time could inline the wrapping code, effectively reducing the overhead for simple calls to zero.
    • +
    • C array handling: Many data structures in some C/C++ libraries contain array containing of a pointer to the first element and the element count. Currently, one must manually writing wrapper code to be able to access these from D. It should be possible to add a set of SWIG macros to semi-automatically generate conversion code.
    • +
    • Operator overloading: Currently, operator overloading is supported only to a very limited extent – many C++ operators are just ignored with a warning. The problem here is that the way D handles operator overloading differs quite a lot from the way C++ does it, both syntactically and semantically, and even more so since the advent of template-based operator overloading in D2.
    • +
    + +

    Some generated code might also be a bit rough around the edges, particularly in the following areas:

    + +
      +
    • Memory management: Although the currently generated wrapper code works fine with regard to the GC for the test-suite, there might be issues coming up in real-world multi-threaded usage.
    • +
    • D2 support: Originally, the module has been developed for the use with D1, D2/Phobos support has been added in later. The basic features should work equally well for both, but there could be issues concerning const-correctness etc.
    • +
    + + + + + diff --git a/Doc/Manual/Sections.html b/Doc/Manual/Sections.html index 855244790..a44571992 100644 --- a/Doc/Manual/Sections.html +++ b/Doc/Manual/Sections.html @@ -52,6 +52,7 @@ Last update : SWIG-2.0.2 (in progress)
  • R support
  • Ruby support
  • Tcl support
  • +
  • D support
  • Developer Documentation

    diff --git a/Doc/Manual/chapters b/Doc/Manual/chapters index e918e234a..924c8cfde 100644 --- a/Doc/Manual/chapters +++ b/Doc/Manual/chapters @@ -17,6 +17,7 @@ CCache.html Allegrocl.html CSharp.html Chicken.html +D.html Go.html Guile.html Java.html diff --git a/Examples/Makefile.in b/Examples/Makefile.in index 582c75f29..5d5590311 100644 --- a/Examples/Makefile.in +++ b/Examples/Makefile.in @@ -69,7 +69,7 @@ IOBJS = $(IWRAP:.i=.@OBJEXT@) CPP_DLLIBS = #-L/usr/local/lib/gcc-lib/sparc-sun-solaris2.5.1/2.7.2 \ -L/usr/local/lib -lg++ -lstdc++ -lgcc -# Solaris workshop 5.0 +# Solaris workshop 5.0 # CPP_DLLIBS = -L/opt/SUNWspro/lib -lCrun # Symbols used for using shared libraries @@ -159,7 +159,7 @@ tcl_cpp: $(SRCS) # ----------------------------------------------------------------- tcl_clean: - rm -f *_wrap* *~ .~* mytclsh@EXEEXT@ + rm -f *_wrap* *~ .~* mytclsh@EXEEXT@ rm -f core @EXTRA_CLEAN@ rm -f *.@OBJEXT@ *@SO@ @@ -296,9 +296,9 @@ python_static_cpp: $(SRCS) $(CXX) $(CFLAGS) $(ICXXSRCS) $(SRCS) $(CXXSRCS) $(INCLUDES) \ $(PYTHON_INCLUDE) $(LIBS) -L$(PYTHON_LIB) $(PYTHON_LIBOPTS) -o $(TARGET) -# ----------------------------------------------------------------- +# ----------------------------------------------------------------- # Running a Python example -# ----------------------------------------------------------------- +# ----------------------------------------------------------------- ifeq (,$(PY3)) PYSCRIPT = runme.py @@ -313,7 +313,7 @@ python_run: $(PYSCRIPT) runme3.py: runme.py cp $< $@ - $(PY2TO3) -w $@ >/dev/null 2>&1 + $(PY2TO3) -w $@ >/dev/null 2>&1 # ----------------------------------------------------------------- # Cleaning the python examples @@ -332,7 +332,7 @@ python_clean: # Make sure these locate your Octave installation OCTAVE_INCLUDE= $(DEFS) @OCTAVEEXT@ -OCTAVE_LIB = +OCTAVE_LIB = # Extra Octave specific dynamic linking options OCTAVE_DLNK = @OCTAVEDYNAMICLINKING@ @@ -548,14 +548,14 @@ mzscheme: $(SRCS) mzscheme_cpp: $(SRCS) $(SWIG) -mzscheme -c++ $(SWIGOPT) $(INTERFACEPATH) $(COMPILETOOL) $(MZC) `echo $(INCLUDES) | sed 's/-I/++ccf -I/g'` --cc $(ICXXSRCS) $(SRCS) $(CXXSRCS) - $(CXXSHARED) $(CFLAGS) -o $(LIBPREFIX)$(TARGET)$(MZSCHEME_SO) $(OBJS) $(IOBJS) $(MZDYNOBJ) $(CPP_DLLIBS) + $(CXXSHARED) $(CFLAGS) -o $(LIBPREFIX)$(TARGET)$(MZSCHEME_SO) $(OBJS) $(IOBJS) $(MZDYNOBJ) $(CPP_DLLIBS) # ----------------------------------------------------------------- # Cleaning the mzscheme examples # ----------------------------------------------------------------- mzscheme_clean: - rm -f *_wrap* *~ .~* + rm -f *_wrap* *~ .~* rm -f core @EXTRA_CLEAN@ rm -f *.@OBJEXT@ *@SO@ @@ -643,7 +643,7 @@ ocaml_static_cpp: $(SRCS) $(INTERFACE:%.i=%.cmo) \ $(PROGFILE:%.ml=%.cmo) \ $(INTERFACE:%.i=%_wrap.@OBJEXT@) $(OBJS) \ - -cclib "$(LIBS)" -cc '$(CXX)' + -cclib "$(LIBS)" -cc '$(CXX)' ocaml_static_cpp_toplevel: $(SRCS) $(OCAMLCORE) @@ -661,7 +661,7 @@ ocaml_static_cpp_toplevel: $(SRCS) -g -ccopt -g -cclib -g -custom -o $(TARGET)_top \ $(INTERFACE:%.i=%.cmo) \ $(INTERFACE:%.i=%_wrap.@OBJEXT@) $(OBJS) \ - -cclib "$(LIBS)" -cc '$(CXX)' + -cclib "$(LIBS)" -cc '$(CXX)' ocaml_dynamic_cpp: $(SRCS) $(OCAMLCORE) @@ -844,7 +844,7 @@ pike_cpp_static: $(SRCS) # ----------------------------------------------------------------- pike_clean: - rm -f *_wrap* *~ .~* mypike@EXEEXT@ + rm -f *_wrap* *~ .~* mypike@EXEEXT@ rm -f core @EXTRA_CLEAN@ rm -f *.@OBJEXT@ *@SO@ @@ -861,7 +861,7 @@ CHICKEN_CFLAGS = @CHICKENOPTS@ CHICKENOPTS = -quiet CHICKEN_MAIN = -# SWIG produces $(ISRCS) (the C wrapper file) +# SWIG produces $(ISRCS) (the C wrapper file) # and $(CHICKEN_GENERATED_SCHEME) (the Scheme wrapper file): CHICKEN_GENERATED_SCHEME = $(INTERFACE:.i=.scm) CHICKEN_COMPILED_SCHEME = $(INTERFACE:.i=_chicken.c) @@ -1053,12 +1053,12 @@ lua_clean: allegrocl: $(SRCS) $(SWIG) -allegrocl -cwrap $(SWIGOPT) $(INTERFACEPATH) - $(CC) -c $(CCSHARED) $(CFLAGS) $(ISRCS) $(INCLUDES) $(SRCS) + $(CC) -c $(CCSHARED) $(CFLAGS) $(ISRCS) $(INCLUDES) $(SRCS) $(LDSHARED) $(CFLAGS) $(OBJS) $(IOBJS) $(LIBS) -o $(LIBPREFIX)$(TARGET)$(SO) allegrocl_cpp: $(SRCS) $(SWIG) -c++ -allegrocl $(SWIGOPT) $(INTERFACEPATH) - $(CXX) -c $(CCSHARED) $(CFLAGS) $(ICXXSRCS) $(SRCS) $(CXXSRCS) $(INCLUDES) + $(CXX) -c $(CCSHARED) $(CFLAGS) $(ICXXSRCS) $(SRCS) $(CXXSRCS) $(INCLUDES) $(CXXSHARED) $(CFLAGS) $(OBJS) $(IOBJS) $(LIBS) $(CPP_DLLIBS) -o $(LIBPREFIX)$(TARGET)$(SO) allegrocl_clean: @@ -1087,12 +1087,12 @@ clisp_clean: cffi: $(SRCS) $(SWIG) -cffi $(SWIGOPT) $(INTERFACEPATH) -# $(CC) -c $(CCSHARED) $(CFLAGS) $(ISRCS) $(INCLUDES) $(SRCS) +# $(CC) -c $(CCSHARED) $(CFLAGS) $(ISRCS) $(INCLUDES) $(SRCS) # $(LDSHARED) $(CFLAGS) $(OBJS) $(IOBJS) $(LIBS) -o $(LIBPREFIX)$(TARGET)$(SO) cffi_cpp: $(SRCS) $(SWIG) -c++ -cffi $(SWIGOPT) $(INTERFACEPATH) - $(CXX) -c $(CCSHARED) $(CFLAGS) $(ICXXSRCS) $(SRCS) $(CXXSRCS) $(INCLUDES) + $(CXX) -c $(CCSHARED) $(CFLAGS) $(ICXXSRCS) $(SRCS) $(CXXSRCS) $(INCLUDES) $(CXXSHARED) $(CFLAGS) $(OBJS) $(IOBJS) $(LIBS) $(CPP_DLLIBS) -o $(LIBPREFIX)$(TARGET)$(SO) cffi_clean: @@ -1106,12 +1106,12 @@ cffi_clean: uffi: $(SRCS) $(SWIG) -uffi $(SWIGOPT) $(INTERFACEPATH) -# $(CC) -c $(CCSHARED) $(CFLAGS) $(ISRCS) $(INCLUDES) $(SRCS) +# $(CC) -c $(CCSHARED) $(CFLAGS) $(ISRCS) $(INCLUDES) $(SRCS) # $(LDSHARED) $(CFLAGS) $(OBJS) $(IOBJS) $(LIBS) -o $(LIBPREFIX)$(TARGET)$(SO) uffi_cpp: $(SRCS) $(SWIG) -c++ -uffi $(SWIGOPT) $(INTERFACEPATH) -# $(CXX) -c $(CCSHARED) $(CFLAGS) $(ICXXSRCS) $(SRCS) $(CXXSRCS) $(INCLUDES) +# $(CXX) -c $(CCSHARED) $(CFLAGS) $(ICXXSRCS) $(SRCS) $(CXXSRCS) $(INCLUDES) # $(CXXSHARED) $(CFLAGS) $(OBJS) $(IOBJS) $(LIBS) $(CPP_DLLIBS) -o $(LIBPREFIX)$(TARGET)$(SO) uffi_clean: @@ -1212,3 +1212,56 @@ go_clean: rm -f *_wrap* *_gc* .~* runme rm -f core @EXTRA_CLEAN@ rm -f *.@OBJEXT@ *.[568] *.a *@SO@ + +################################################################## +##### D ###### +################################################################## + +DLIBPREFIX = @DLIBPREFIX@ + +ifeq (2,$(D_VERSION)) + SWIGD = $(SWIG) -d -d2 + DCOMPILER = @D2COMPILER@ +else + SWIGD = $(SWIG) -d + DCOMPILER = @D1COMPILER@ +endif + +ifeq (dmd,$(DCOMPILER)) + # DMD is 32bit only by now + CFLAGS += -m32 +endif + +# ---------------------------------------------------------------- +# Build a dynamically loadable D wrapper for a C module +# ---------------------------------------------------------------- + +d: $(SRCS) + $(SWIGD) $(SWIGOPT) $(INTERFACEPATH) + $(CC) -c $(CCSHARED) $(CFLAGS) $(EXTRA_CFLAGS) $(SRCS) $(ISRCS) $(INCLUDES) + $(LDSHARED) $(CFLAGS) $(EXTRA_LDFLAGS) $(OBJS) $(IOBJS) $(LIBS) -o $(DLIBPREFIX)$(TARGET)$(SO) + +# ---------------------------------------------------------------- +# Build a dynamically loadable D wrapper for a C++ module +# ---------------------------------------------------------------- + +d_cpp: $(SRCS) + $(SWIGD) -c++ $(SWIGOPT) $(INTERFACEPATH) + $(CXX) -c $(CCSHARED) $(CFLAGS) $(EXTRA_CFLAGS) $(SRCS) $(CXXSRCS) $(ICXXSRCS) $(INCLUDES) + $(CXXSHARED) $(CFLAGS) $(EXTRA_LDFLAGS) $(OBJS) $(IOBJS) $(LIBS) $(CPP_DLLIBS) -o $(DLIBPREFIX)$(TARGET)$(SO) + +# ---------------------------------------------------------------- +# Compile D files +# ---------------------------------------------------------------- + +d_compile: $(SRCS) + $(COMPILETOOL) $(DCOMPILER) $(DFLAGS) $(DSRCS) + +# ----------------------------------------------------------------- +# Clean the D examples +# ----------------------------------------------------------------- + +d_clean: + rm -f *_wrap* *~ .~* runme runme.exe `find . -name \*.d | grep -v runme.d` + rm -f core @EXTRA_CLEAN@ + rm -f *.@OBJEXT@ *@SO@ diff --git a/Examples/d/callback/Makefile b/Examples/d/callback/Makefile new file mode 100644 index 000000000..bc16dd0fc --- /dev/null +++ b/Examples/d/callback/Makefile @@ -0,0 +1,28 @@ +ifeq (2,$(D_VERSION)) + WORKING_DIR = d2/ +else + WORKING_DIR = d1/ +endif + +TOP = ../../.. +SWIG = $(TOP)/../preinst-swig +EXTRA_CFLAGS = -I../ ../example.cxx example_wrap.cxx +EXTRA_LDFLAGS = example.o example_wrap.o +TARGET = example_wrap +SWIGOPT = +DSRCS = *.d +DFLAGS = -ofrunme + + +all:: d + +d:: + cd $(WORKING_DIR); \ + $(MAKE) -f $(TOP)/Makefile EXTRA_CFLAGS='$(EXTRA_CFLAGS)' EXTRA_LDFLAGS='$(EXTRA_LDFLAGS)' SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT) -outcurrentdir ../example.i' TARGET='$(TARGET)' d_cpp; \ + $(MAKE) -f $(TOP)/Makefile DSRCS='$(DSRCS)' DFLAGS='$(DFLAGS)' d_compile + +clean:: + cd $(WORKING_DIR); \ + $(MAKE) -f $(TOP)/Makefile d_clean + +check: all diff --git a/Examples/d/callback/d1/runme.d b/Examples/d/callback/d1/runme.d new file mode 100644 index 000000000..e34e09603 --- /dev/null +++ b/Examples/d/callback/d1/runme.d @@ -0,0 +1,36 @@ +module runme; + +import tango.io.Stdout; +import example; + +public class DCallback : Callback { + public override void run() { + Stdout( "DCallback.run()" ).newline; + } +} + +void main() { + auto caller = new Caller(); + + Stdout( "Adding and calling a normal C++ callback" ).newline; + Stdout( "----------------------------------------" ).newline; + { + scope auto callback = new Callback(); + caller.setCallback(callback); + caller.call(); + caller.resetCallback(); + } + + Stdout.newline; + Stdout( "Adding and calling a D callback" ).newline; + Stdout( "-------------------------------" ).newline; + { + scope auto callback = new DCallback(); + caller.setCallback(callback); + caller.call(); + caller.resetCallback(); + } + + Stdout.newline; + Stdout( "D exit" ).newline; +} diff --git a/Examples/d/callback/d2/runme.d b/Examples/d/callback/d2/runme.d new file mode 100644 index 000000000..88ffcdefd --- /dev/null +++ b/Examples/d/callback/d2/runme.d @@ -0,0 +1,36 @@ +module runme; + +import std.stdio; +import example; + +public class DCallback : Callback { + public override void run() { + writeln( "DCallback.run()" ); + } +} + +void main() { + auto caller = new Caller(); + + writeln( "Adding and calling a normal C++ callback" ); + writeln( "----------------------------------------" ); + { + scope auto callback = new Callback(); + caller.setCallback(callback); + caller.call(); + caller.resetCallback(); + } + + writeln(); + writeln( "Adding and calling a D callback" ); + writeln( "-------------------------------" ); + { + scope auto callback = new DCallback(); + caller.setCallback(callback); + caller.call(); + caller.resetCallback(); + } + + writeln(); + writeln( "D exit" ); +} diff --git a/Examples/d/callback/example.cxx b/Examples/d/callback/example.cxx new file mode 100644 index 000000000..450d75608 --- /dev/null +++ b/Examples/d/callback/example.cxx @@ -0,0 +1,4 @@ +/* File : example.cxx */ + +#include "example.h" + diff --git a/Examples/d/callback/example.h b/Examples/d/callback/example.h new file mode 100644 index 000000000..38d25a043 --- /dev/null +++ b/Examples/d/callback/example.h @@ -0,0 +1,24 @@ +/* File : example.h */ + +#include +#include + +class Callback { +public: + virtual ~Callback() { std::cout << "Callback::~Callback()" << std:: endl; } + virtual void run() { std::cout << "Callback::run()" << std::endl; } +}; + + +class Caller { +private: + Callback *_callback; +public: + Caller(): _callback(0) {} + ~Caller() { delCallback(); } + void delCallback() { delete _callback; _callback = 0; } + void setCallback(Callback *cb) { delCallback(); _callback = cb; } + void resetCallback() { _callback = 0; } + void call() { if (_callback) _callback->run(); } +}; + diff --git a/Examples/d/callback/example.i b/Examples/d/callback/example.i new file mode 100644 index 000000000..90beda01a --- /dev/null +++ b/Examples/d/callback/example.i @@ -0,0 +1,13 @@ +/* File : example.i */ +%module(directors="1") example +%{ +#include "example.h" +%} + +%include "std_string.i" + +/* turn on director wrapping Callback */ +%feature("director") Callback; + +%include "example.h" + diff --git a/Examples/d/check.list b/Examples/d/check.list new file mode 100644 index 000000000..010e7bbfc --- /dev/null +++ b/Examples/d/check.list @@ -0,0 +1,9 @@ +# See top-level Makefile.in. +callback +class +constants +enum +extend +funcptr +simple +variables diff --git a/Examples/d/class/Makefile b/Examples/d/class/Makefile new file mode 100644 index 000000000..bc16dd0fc --- /dev/null +++ b/Examples/d/class/Makefile @@ -0,0 +1,28 @@ +ifeq (2,$(D_VERSION)) + WORKING_DIR = d2/ +else + WORKING_DIR = d1/ +endif + +TOP = ../../.. +SWIG = $(TOP)/../preinst-swig +EXTRA_CFLAGS = -I../ ../example.cxx example_wrap.cxx +EXTRA_LDFLAGS = example.o example_wrap.o +TARGET = example_wrap +SWIGOPT = +DSRCS = *.d +DFLAGS = -ofrunme + + +all:: d + +d:: + cd $(WORKING_DIR); \ + $(MAKE) -f $(TOP)/Makefile EXTRA_CFLAGS='$(EXTRA_CFLAGS)' EXTRA_LDFLAGS='$(EXTRA_LDFLAGS)' SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT) -outcurrentdir ../example.i' TARGET='$(TARGET)' d_cpp; \ + $(MAKE) -f $(TOP)/Makefile DSRCS='$(DSRCS)' DFLAGS='$(DFLAGS)' d_compile + +clean:: + cd $(WORKING_DIR); \ + $(MAKE) -f $(TOP)/Makefile d_clean + +check: all diff --git a/Examples/d/class/d1/runme.d b/Examples/d/class/d1/runme.d new file mode 100644 index 000000000..b0c4263a2 --- /dev/null +++ b/Examples/d/class/d1/runme.d @@ -0,0 +1,58 @@ +// This example illustrates how C++ classes can be used from D using SWIG. +// The D class gets mapped onto the C++ class and behaves as if it is a D class. +module runme; + +import tango.io.Stdout; +import example; + +void main() { + // ----- Object creation ----- + + Stdout( "Creating some objects:" ).newline; + + { + scope Square s = new Square(10); + scope Circle c = new Circle(10); + + // ----- Access a static member ----- + Stdout.format( "{} shapes were created.", Shape.nshapes ).newline; + + // ----- Member data access ----- + + // Notice how we can do this using functions specific to + // the 'Circle' class. + c.x = 20; + c.y = 30; + + // Now use the same functions in the base class + Shape shape = s; + shape.x = -10; + shape.y = 5; + + Stdout( "\nHere is their current position:" ).newline; + Stdout.format( " Circle = ( {}, {} )", c.x, c.y ).newline; + Stdout.format( " Square = ( {}, {} )", s.x, s.y ).newline; + + // ----- Call some methods ----- + + Stdout( "\nHere are some properties of the shapes:" ).newline; + Shape[] shapes = [ cast(Shape) c, cast(Shape) s ]; + foreach ( currentShape; shapes ) + { + Stdout.format( " {}", currentShape.classinfo.name ).newline; + Stdout.format( " area = {}", currentShape.area() ).newline; + Stdout.format( " perimeter = {}", currentShape.perimeter() ).newline; + } + + // Notice how the area() and perimeter() functions really + // invoke the appropriate virtual method on each object. + + // ----- Delete everything ----- + Stdout( "\nGuess I'll clean up now:" ).newline; + // Note: when this using scope is exited the D destructors are called which + // in turn call the C++ destructors. + } + + Stdout.format( "{} shapes remain", Shape.nshapes ).newline; + Stdout( "\nGoodbye!" ).newline; +} diff --git a/Examples/d/class/d2/runme.d b/Examples/d/class/d2/runme.d new file mode 100644 index 000000000..2e86c5fc7 --- /dev/null +++ b/Examples/d/class/d2/runme.d @@ -0,0 +1,58 @@ +// This example illustrates how C++ classes can be used from D using SWIG. +// The D class gets mapped onto the C++ class and behaves as if it is a D class. +module runme; + +import std.stdio; +import example; + +void main() { + // ----- Object creation ----- + + writeln( "Creating some objects:" ); + + { + scope Square s = new Square(10); + scope Circle c = new Circle(10); + + // ----- Access a static member ----- + writefln( "%s shapes were created.", Shape.nshapes ); + + // ----- Member data access ----- + + // Notice how we can do this using functions specific to + // the 'Circle' class. + c.x = 20; + c.y = 30; + + // Now use the same functions in the base class + Shape shape = s; + shape.x = -10; + shape.y = 5; + + writeln( "\nHere is their current position:" ); + writefln( " Circle = ( %s, %s )", c.x, c.y ); + writefln( " Square = ( %s, %s )", s.x, s.y ); + + // ----- Call some methods ----- + + writeln( "\nHere are some properties of the shapes:" ); + Shape[] shapes = [ cast(Shape) c, cast(Shape) s ]; + foreach ( currentShape; shapes ) + { + writefln( " %s", currentShape.classinfo.name ); + writefln( " area = %s", currentShape.area() ); + writefln( " perimeter = %s", currentShape.perimeter() ); + } + + // Notice how the area() and perimeter() functions really + // invoke the appropriate virtual method on each object. + + // ----- Delete everything ----- + writeln( "\nGuess I'll clean up now:" ); + // Note: when this using scope is exited the D destructors are called which + // in turn call the C++ destructors. + } + + writefln( "%s shapes remain", Shape.nshapes ); + writeln( "\nGoodbye!" ); +} diff --git a/Examples/d/class/example.cxx b/Examples/d/class/example.cxx new file mode 100644 index 000000000..1e8e203dd --- /dev/null +++ b/Examples/d/class/example.cxx @@ -0,0 +1,28 @@ +/* File : example.c */ + +#include "example.h" +#define M_PI 3.14159265358979323846 + +/* Move the shape to a new location */ +void Shape::move(double dx, double dy) { + x += dx; + y += dy; +} + +int Shape::nshapes = 0; + +double Circle::area(void) { + return M_PI*radius*radius; +} + +double Circle::perimeter(void) { + return 2*M_PI*radius; +} + +double Square::area(void) { + return width*width; +} + +double Square::perimeter(void) { + return 4*width; +} diff --git a/Examples/d/class/example.h b/Examples/d/class/example.h new file mode 100644 index 000000000..0d4527e92 --- /dev/null +++ b/Examples/d/class/example.h @@ -0,0 +1,34 @@ +/* File : example.h */ + +class Shape { +public: + Shape() { + nshapes++; + } + virtual ~Shape() { + nshapes--; + }; + double x, y; + void move(double dx, double dy); + virtual double area(void) = 0; + virtual double perimeter(void) = 0; + static int nshapes; +}; + +class Circle : public Shape { +private: + double radius; +public: + Circle(double r) : radius(r) { }; + virtual double area(void); + virtual double perimeter(void); +}; + +class Square : public Shape { +private: + double width; +public: + Square(double w) : width(w) { }; + virtual double area(void); + virtual double perimeter(void); +}; diff --git a/Examples/d/class/example.i b/Examples/d/class/example.i new file mode 100644 index 000000000..75700b305 --- /dev/null +++ b/Examples/d/class/example.i @@ -0,0 +1,10 @@ +/* File : example.i */ +%module example + +%{ +#include "example.h" +%} + +/* Let's just grab the original header file here */ +%include "example.h" + diff --git a/Examples/d/constants/Makefile b/Examples/d/constants/Makefile new file mode 100644 index 000000000..ce17134ec --- /dev/null +++ b/Examples/d/constants/Makefile @@ -0,0 +1,28 @@ +ifeq (2,$(D_VERSION)) + WORKING_DIR = d2/ +else + WORKING_DIR = d1/ +endif + +TOP = ../../.. +SWIG = $(TOP)/../preinst-swig +EXTRA_CFLAGS = -I../ example_wrap.c +EXTRA_LDFLAGS = example_wrap.o +TARGET = example_wrap +SWIGOPT = +DSRCS = *.d +DFLAGS = -ofrunme + + +all:: d + +d:: + cd $(WORKING_DIR); \ + $(MAKE) -f $(TOP)/Makefile EXTRA_CFLAGS='$(EXTRA_CFLAGS)' EXTRA_LDFLAGS='$(EXTRA_LDFLAGS)' SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT) -outcurrentdir ../example.i' TARGET='$(TARGET)' d; \ + $(MAKE) -f $(TOP)/Makefile DSRCS='$(DSRCS)' DFLAGS='$(DFLAGS)' d_compile + +clean:: + cd $(WORKING_DIR); \ + $(MAKE) -f $(TOP)/Makefile d_clean + +check: all diff --git a/Examples/d/constants/d1/runme.d b/Examples/d/constants/d1/runme.d new file mode 100644 index 000000000..47362cbf3 --- /dev/null +++ b/Examples/d/constants/d1/runme.d @@ -0,0 +1,28 @@ +module runme; + +import tango.io.Stdout; +static import example; + +void main() { + Stdout.formatln("ICONST = {} (should be 42)", example.ICONST); + Stdout.formatln("FCONST = {} (should be 2.18)", example.FCONST); + Stdout.formatln("CCONST = {} (should be 'x')", example.CCONST); + Stdout.formatln("CCONST2 = {} (this should be on a new line)", example.CCONST2); + Stdout.formatln("SCONST = {} (should be 'Hello World')", example.SCONST); + Stdout.formatln("SCONST2 = {} (should be '\"Hello World\"')", example.SCONST2); + Stdout.formatln("EXPR = {} (should be 48.55)", example.EXPR); + Stdout.formatln("iconst = {} (should be 37)", example.iconst); + Stdout.formatln("fconst = {} (should be 3.14)", example.fconst); + + static if (is(typeof(example.EXTERN))) { + Stdout.formatln("EXTERN should not be defined, but is: {}.", example.EXTERN ); + } else { + Stdout.formatln("EXTERN isn't defined (good)"); + } + + static if (is(typeof(example.FOO))) { + Stdout.formatln("FOO should not be defined, but is: {}.", example.FOO); + } else { + Stdout.formatln("FOO isn't defined (good)"); + } +} diff --git a/Examples/d/constants/d2/runme.d b/Examples/d/constants/d2/runme.d new file mode 100644 index 000000000..4be510d16 --- /dev/null +++ b/Examples/d/constants/d2/runme.d @@ -0,0 +1,28 @@ +module runme; + +import std.stdio; +static import example; + +void main() { + writefln("ICONST = %s (should be 42)", example.ICONST); + writefln("FCONST = %s (should be 2.1828)", example.FCONST); + writefln("CCONST = %s (should be 'x')", example.CCONST); + writefln("CCONST2 = %s (this should be on a new line)", example.CCONST2); + writefln("SCONST = %s (should be 'Hello World')", example.SCONST); + writefln("SCONST2 = %s (should be '\"Hello World\"')", example.SCONST2); + writefln("EXPR = %s (should be 48.5484)", example.EXPR); + writefln("iconst = %s (should be 37)", example.iconst); + writefln("fconst = %s (should be 3.14)", example.fconst); + + static if (is(typeof(example.EXTERN))) { + writefln("EXTERN should not be defined, but is: %s.", example.EXTERN ); + } else { + writeln("EXTERN isn't defined (good)"); + } + + static if (is(typeof(example.FOO))) { + writefln("FOO should not be defined, but is: %s.", example.FOO); + } else { + writeln("FOO isn't defined (good)"); + } +} diff --git a/Examples/d/constants/example.d b/Examples/d/constants/example.d new file mode 100644 index 000000000..7448d0ad9 --- /dev/null +++ b/Examples/d/constants/example.d @@ -0,0 +1,23 @@ +/* ---------------------------------------------------------------------------- + * This file was automatically generated by SWIG (http://www.swig.org). + * Version 1.3.41 + * + * Do not make changes to this file unless you know what you are doing--modify + * the SWIG interface file instead. + * ----------------------------------------------------------------------------- */ + +module example; + +static import example_wrap; + +static import tango.stdc.stringz; + +public const int ICONST = 42; +public const double FCONST = 2.1828; +public const char CCONST = 'x'; +public const char CCONST2 = '\n'; +public const char[] SCONST = "Hello World"; +public const char[] SCONST2 = "\"Hello World\""; +public const double EXPR = 42+3*(2.1828); +public const int iconst = 37; +public const double fconst = 3.14; diff --git a/Examples/d/constants/example.i b/Examples/d/constants/example.i new file mode 100644 index 000000000..5eb541919 --- /dev/null +++ b/Examples/d/constants/example.i @@ -0,0 +1,32 @@ +/* File : example.i */ +%module example + +/* Force the generated D code to use the C constant values rather than + retrieving them at runtime. You can also try disabling the feature and + compare the generated code. */ +%dnativeconst; + + +/* A few preprocessor macros */ + +#define ICONST 42 +#define FCONST 2.1828 +#define CCONST 'x' +#define CCONST2 '\n' +#define SCONST "Hello World" +#define SCONST2 "\"Hello World\"" + +/* This should work just fine */ +#define EXPR ICONST + 3*(FCONST) + +/* This shouldn't do anything */ +#define EXTERN extern + +/* Neither should this (BAR isn't defined) */ +#define FOO (ICONST + BAR) + + +/* The following directives also produce constants */ + +%constant int iconst = 37; +%constant double fconst = 3.14; diff --git a/Examples/d/enum/Makefile b/Examples/d/enum/Makefile new file mode 100644 index 000000000..bc16dd0fc --- /dev/null +++ b/Examples/d/enum/Makefile @@ -0,0 +1,28 @@ +ifeq (2,$(D_VERSION)) + WORKING_DIR = d2/ +else + WORKING_DIR = d1/ +endif + +TOP = ../../.. +SWIG = $(TOP)/../preinst-swig +EXTRA_CFLAGS = -I../ ../example.cxx example_wrap.cxx +EXTRA_LDFLAGS = example.o example_wrap.o +TARGET = example_wrap +SWIGOPT = +DSRCS = *.d +DFLAGS = -ofrunme + + +all:: d + +d:: + cd $(WORKING_DIR); \ + $(MAKE) -f $(TOP)/Makefile EXTRA_CFLAGS='$(EXTRA_CFLAGS)' EXTRA_LDFLAGS='$(EXTRA_LDFLAGS)' SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT) -outcurrentdir ../example.i' TARGET='$(TARGET)' d_cpp; \ + $(MAKE) -f $(TOP)/Makefile DSRCS='$(DSRCS)' DFLAGS='$(DFLAGS)' d_compile + +clean:: + cd $(WORKING_DIR); \ + $(MAKE) -f $(TOP)/Makefile d_clean + +check: all diff --git a/Examples/d/enum/d1/runme.d b/Examples/d/enum/d1/runme.d new file mode 100644 index 000000000..d986986d1 --- /dev/null +++ b/Examples/d/enum/d1/runme.d @@ -0,0 +1,28 @@ +module runme; + +import tango.io.Stdout; +import example; + +void main() { + Stdout( "Printing out some enum values:" ).newline; + Stdout(" color:").newline; + Stdout.formatln(" {} = {}", color.RED, cast(int)color.RED); + Stdout.formatln(" {} = {}", color.BLUE, cast(int)color.BLUE); + Stdout.formatln(" {} = {}", color.GREEN, cast(int)color.GREEN); + + Stdout("\n Foo.speed:").newline; + Stdout.formatln(" Foo.{} = {}", Foo.speed.IMPULSE, cast(int)Foo.speed.IMPULSE); + Stdout.formatln(" Foo.{} = {}", Foo.speed.WARP, cast(int)Foo.speed.WARP); + Stdout.formatln(" Foo.{} = {}", Foo.speed.LUDICROUS , cast(int)Foo.speed.LUDICROUS); + + Stdout("\nTesting use of enums with functions:").newline; + example.enum_test(color.RED, Foo.speed.IMPULSE); + example.enum_test(color.BLUE, Foo.speed.WARP); + example.enum_test(color.GREEN, Foo.speed.LUDICROUS); + + Stdout( "\nTesting use of enum with class method:" ).newline; + scope f = new Foo(); + f.enum_test(Foo.speed.IMPULSE); + f.enum_test(Foo.speed.WARP); + f.enum_test(Foo.speed.LUDICROUS); +} diff --git a/Examples/d/enum/d2/runme.d b/Examples/d/enum/d2/runme.d new file mode 100644 index 000000000..acaec8ae8 --- /dev/null +++ b/Examples/d/enum/d2/runme.d @@ -0,0 +1,28 @@ +module runme; + +import std.stdio; +import example; + +void main() { + writeln( "Printing out some enum values:" ); + writeln(" color:"); + writefln(" %s = %s", color.RED, cast(int)color.RED); + writefln(" %s = %s", color.BLUE, cast(int)color.BLUE); + writefln(" %s = %s", color.GREEN, cast(int)color.GREEN); + + writeln("\n Foo.speed:"); + writefln(" Foo.%s = %s", Foo.speed.IMPULSE, cast(int)Foo.speed.IMPULSE); + writefln(" Foo.%s = %s", Foo.speed.WARP, cast(int)Foo.speed.WARP); + writefln(" Foo.%s = %s", Foo.speed.LUDICROUS , cast(int)Foo.speed.LUDICROUS); + + writeln("\nTesting use of enums with functions:"); + example.enum_test(color.RED, Foo.speed.IMPULSE); + example.enum_test(color.BLUE, Foo.speed.WARP); + example.enum_test(color.GREEN, Foo.speed.LUDICROUS); + + writeln( "\nTesting use of enum with class method:" ); + scope f = new Foo(); + f.enum_test(Foo.speed.IMPULSE); + f.enum_test(Foo.speed.WARP); + f.enum_test(Foo.speed.LUDICROUS); +} diff --git a/Examples/d/enum/example.cxx b/Examples/d/enum/example.cxx new file mode 100644 index 000000000..df7bb6328 --- /dev/null +++ b/Examples/d/enum/example.cxx @@ -0,0 +1,37 @@ +/* File : example.cxx */ + +#include "example.h" +#include + +void Foo::enum_test(speed s) { + if (s == IMPULSE) { + printf("IMPULSE speed\n"); + } else if (s == WARP) { + printf("WARP speed\n"); + } else if (s == LUDICROUS) { + printf("LUDICROUS speed\n"); + } else { + printf("Unknown speed\n"); + } +} + +void enum_test(color c, Foo::speed s) { + if (c == RED) { + printf("color = RED, "); + } else if (c == BLUE) { + printf("color = BLUE, "); + } else if (c == GREEN) { + printf("color = GREEN, "); + } else { + printf("color = Unknown color!, "); + } + if (s == Foo::IMPULSE) { + printf("speed = IMPULSE speed\n"); + } else if (s == Foo::WARP) { + printf("speed = WARP speed\n"); + } else if (s == Foo::LUDICROUS) { + printf("speed = LUDICROUS speed\n"); + } else { + printf("speed = Unknown speed!\n"); + } +} diff --git a/Examples/d/enum/example.h b/Examples/d/enum/example.h new file mode 100644 index 000000000..9119cd9fc --- /dev/null +++ b/Examples/d/enum/example.h @@ -0,0 +1,13 @@ +/* File : example.h */ + +enum color { RED, BLUE, GREEN }; + +class Foo { + public: + Foo() { } + enum speed { IMPULSE=10, WARP=20, LUDICROUS=30 }; + void enum_test(speed s); +}; + +void enum_test(color c, Foo::speed s); + diff --git a/Examples/d/enum/example.i b/Examples/d/enum/example.i new file mode 100644 index 000000000..23ee8a822 --- /dev/null +++ b/Examples/d/enum/example.i @@ -0,0 +1,11 @@ +/* File : example.i */ +%module example + +%{ +#include "example.h" +%} + +/* Let's just grab the original header file here */ + +%include "example.h" + diff --git a/Examples/d/extend/Makefile b/Examples/d/extend/Makefile new file mode 100644 index 000000000..bc16dd0fc --- /dev/null +++ b/Examples/d/extend/Makefile @@ -0,0 +1,28 @@ +ifeq (2,$(D_VERSION)) + WORKING_DIR = d2/ +else + WORKING_DIR = d1/ +endif + +TOP = ../../.. +SWIG = $(TOP)/../preinst-swig +EXTRA_CFLAGS = -I../ ../example.cxx example_wrap.cxx +EXTRA_LDFLAGS = example.o example_wrap.o +TARGET = example_wrap +SWIGOPT = +DSRCS = *.d +DFLAGS = -ofrunme + + +all:: d + +d:: + cd $(WORKING_DIR); \ + $(MAKE) -f $(TOP)/Makefile EXTRA_CFLAGS='$(EXTRA_CFLAGS)' EXTRA_LDFLAGS='$(EXTRA_LDFLAGS)' SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT) -outcurrentdir ../example.i' TARGET='$(TARGET)' d_cpp; \ + $(MAKE) -f $(TOP)/Makefile DSRCS='$(DSRCS)' DFLAGS='$(DFLAGS)' d_compile + +clean:: + cd $(WORKING_DIR); \ + $(MAKE) -f $(TOP)/Makefile d_clean + +check: all diff --git a/Examples/d/extend/d1/runme.d b/Examples/d/extend/d1/runme.d new file mode 100644 index 000000000..96501d1a4 --- /dev/null +++ b/Examples/d/extend/d1/runme.d @@ -0,0 +1,75 @@ +/// This file illustrates the cross language polymorphism using directors. +module runme; + +import example; +import tango.io.Stdout; + +// CEO class, which overrides Employee.getPosition(). +class CEO : Manager { +public: + this( char[] name ) { + super( name ); + } + + override char[] getPosition() { + return "CEO"; + } + + // Public method to stop the SWIG proxy base class from thinking it owns the underlying C++ memory. + void disownMemory() { + swigCMemOwn = false; + } +} + +void main() { + // Create an instance of CEO, a class derived from the D proxy of the + // underlying C++ class. The calls to getName() and getPosition() are standard, + // the call to getTitle() uses the director wrappers to call CEO.getPosition(). + + auto e = new CEO( "Alice" ); + Stdout.formatln( "{} is a {}.", e.getName(), e.getPosition() ); + Stdout.formatln( "Just call her '{}'.", e.getTitle() ); + Stdout( "----------------------" ).newline; + + { + // Create a new EmployeeList instance. This class does not have a C++ + // director wrapper, but can be used freely with other classes that do. + scope auto list = new EmployeeList(); + + // EmployeeList owns its items, so we must surrender ownership of objects we add. + e.disownMemory(); + list.addEmployee(e); + Stdout( "----------------------" ).newline; + + // Now we access the first four items in list (three are C++ objects that + // EmployeeList's constructor adds, the last is our CEO). The virtual + // methods of all these instances are treated the same. For items 0, 1, and + // 2, all methods resolve in C++. For item 3, our CEO, getTitle calls + // getPosition which resolves in D. The call to getPosition is + // slightly different, however, because of the overidden getPosition() call, since + // now the object reference has been "laundered" by passing through + // EmployeeList as an Employee*. Previously, D resolved the call + // immediately in CEO, but now D thinks the object is an instance of + // class Employee. So the call passes through the + // Employee proxy class and on to the C wrappers and C++ director, + // eventually ending up back at the D CEO implementation of getPosition(). + // The call to getTitle() for item 3 runs the C++ Employee::getTitle() + // method, which in turn calls getPosition(). This virtual method call + // passes down through the C++ director class to the D implementation + // in CEO. All this routing takes place transparently. + + Stdout( "(position, title) for items 0-3:" ).newline; + Stdout.formatln( " {}, '{}'", list.getItem(0).getPosition(), list.getItem(0).getTitle() ); + Stdout.formatln( " {}, '{}'", list.getItem(1).getPosition(), list.getItem(1).getTitle() ); + Stdout.formatln( " {}, '{}'", list.getItem(2).getPosition(), list.getItem(2).getTitle() ); + Stdout.formatln( " {}, '{}'", list.getItem(3).getPosition(), list.getItem(3).getTitle() ); + Stdout( "----------------------" ).newline; + + // All Employees will be destroyed when the EmployeeList goes out of scope, + // including the CEO instance. + } + Stdout( "----------------------" ).newline; + + // All done. + Stdout( "Exiting cleanly from D code." ).newline; +} diff --git a/Examples/d/extend/d2/runme.d b/Examples/d/extend/d2/runme.d new file mode 100644 index 000000000..1ea6dfd21 --- /dev/null +++ b/Examples/d/extend/d2/runme.d @@ -0,0 +1,75 @@ +/// This file illustrates the cross language polymorphism using directors. +module runme; + +import std.stdio; +import example; + +// CEO class, which overrides Employee.getPosition(). +class CEO : Manager { +public: + this( string name ) { + super( name ); + } + + override string getPosition() const { + return "CEO"; + } + + // Public method to stop the SWIG proxy base class from thinking it owns the underlying C++ memory. + void disownMemory() { + swigCMemOwn = false; + } +} + +void main() { + // Create an instance of CEO, a class derived from the D proxy of the + // underlying C++ class. The calls to getName() and getPosition() are standard, + // the call to getTitle() uses the director wrappers to call CEO.getPosition(). + + auto e = new CEO( "Alice" ); + writefln( "%s is a %s.", e.getName(), e.getPosition() ); + writefln( "Just call her '%s'.", e.getTitle() ); + writeln( "----------------------" ); + + { + // Create a new EmployeeList instance. This class does not have a C++ + // director wrapper, but can be used freely with other classes that do. + scope auto list = new EmployeeList(); + + // EmployeeList owns its items, so we must surrender ownership of objects we add. + e.disownMemory(); + list.addEmployee(e); + writeln( "----------------------" ); + + // Now we access the first four items in list (three are C++ objects that + // EmployeeList's constructor adds, the last is our CEO). The virtual + // methods of all these instances are treated the same. For items 0, 1, and + // 2, all methods resolve in C++. For item 3, our CEO, getTitle calls + // getPosition which resolves in D. The call to getPosition is + // slightly different, however, because of the overidden getPosition() call, since + // now the object reference has been "laundered" by passing through + // EmployeeList as an Employee*. Previously, D resolved the call + // immediately in CEO, but now D thinks the object is an instance of + // class Employee. So the call passes through the + // Employee proxy class and on to the C wrappers and C++ director, + // eventually ending up back at the D CEO implementation of getPosition(). + // The call to getTitle() for item 3 runs the C++ Employee::getTitle() + // method, which in turn calls getPosition(). This virtual method call + // passes down through the C++ director class to the D implementation + // in CEO. All this routing takes place transparently. + + writeln( "(position, title) for items 0-3:" ); + writefln( " %s, '%s'", list.getItem(0).getPosition(), list.getItem(0).getTitle() ); + writefln( " %s, '%s'", list.getItem(1).getPosition(), list.getItem(1).getTitle() ); + writefln( " %s, '%s'", list.getItem(2).getPosition(), list.getItem(2).getTitle() ); + writefln( " %s, '%s'", list.getItem(3).getPosition(), list.getItem(3).getTitle() ); + writeln( "----------------------" ); + + // All Employees will be destroyed when the EmployeeList goes out of scope, + // including the CEO instance. + } + writeln( "----------------------" ); + + // All done. + writeln( "Exiting cleanly from D code." ); +} diff --git a/Examples/d/extend/example.cxx b/Examples/d/extend/example.cxx new file mode 100644 index 000000000..450d75608 --- /dev/null +++ b/Examples/d/extend/example.cxx @@ -0,0 +1,4 @@ +/* File : example.cxx */ + +#include "example.h" + diff --git a/Examples/d/extend/example.h b/Examples/d/extend/example.h new file mode 100644 index 000000000..7ad93fbc1 --- /dev/null +++ b/Examples/d/extend/example.h @@ -0,0 +1,56 @@ +/* File : example.h */ + +#include +#include +#include +#include +#include + +class Employee { +private: + std::string name; +public: + Employee(const char* n): name(n) {} + 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); } +}; + + +class Manager: public Employee { +public: + Manager(const char* n): Employee(n) {} + virtual std::string getPosition() const { return "Manager"; } +}; + + +class EmployeeList { + std::vector list; +public: + EmployeeList() { + list.push_back(new Employee("Bob")); + list.push_back(new Employee("Jane")); + list.push_back(new Manager("Ted")); + } + void addEmployee(Employee *p) { + list.push_back(p); + std::cout << "New employee added. Current employees are:" << std::endl; + std::vector::iterator i; + for (i=list.begin(); i!=list.end(); i++) { + std::cout << " " << (*i)->getTitle() << std::endl; + } + } + const Employee *getItem(int i) { + return list[i]; + } + ~EmployeeList() { + std::vector::iterator i; + std::cout << "~EmployeeList, deleting " << list.size() << " employees." << std::endl; + for (i=list.begin(); i!=list.end(); i++) { + delete *i; + } + std::cout << "~EmployeeList empty." << std::endl; + } +}; + diff --git a/Examples/d/extend/example.i b/Examples/d/extend/example.i new file mode 100644 index 000000000..0647e1319 --- /dev/null +++ b/Examples/d/extend/example.i @@ -0,0 +1,14 @@ +/* File : example.i */ +%module(directors="1") example +%{ +#include "example.h" +%} + +%include "std_string.i" + +/* turn on director wrapping for Manager */ +%feature("director") Employee; +%feature("director") Manager; + +%include "example.h" + diff --git a/Examples/d/funcptr/Makefile b/Examples/d/funcptr/Makefile new file mode 100644 index 000000000..616102926 --- /dev/null +++ b/Examples/d/funcptr/Makefile @@ -0,0 +1,28 @@ +ifeq (2,$(D_VERSION)) + WORKING_DIR = d2/ +else + WORKING_DIR = d1/ +endif + +TOP = ../../.. +SWIG = $(TOP)/../preinst-swig +EXTRA_CFLAGS = -I../ ../example.c example_wrap.c +EXTRA_LDFLAGS = example.o example_wrap.o +TARGET = example_wrap +SWIGOPT = +DSRCS = *.d +DFLAGS = -ofrunme + + +all:: d + +d:: + cd $(WORKING_DIR); \ + $(MAKE) -f $(TOP)/Makefile EXTRA_CFLAGS='$(EXTRA_CFLAGS)' EXTRA_LDFLAGS='$(EXTRA_LDFLAGS)' EXTRA_LDFLAGS='$(EXTRA_LDFLAGS)' SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT) -outcurrentdir ../example.i' TARGET='$(TARGET)' d; \ + $(MAKE) -f $(TOP)/Makefile DSRCS='$(DSRCS)' DFLAGS='$(DFLAGS)' d_compile + +clean:: + cd $(WORKING_DIR); \ + $(MAKE) -f $(TOP)/Makefile d_clean + +check: all diff --git a/Examples/d/funcptr/d1/runme.d b/Examples/d/funcptr/d1/runme.d new file mode 100644 index 000000000..2947602a5 --- /dev/null +++ b/Examples/d/funcptr/d1/runme.d @@ -0,0 +1,34 @@ +module runme; + +import tango.io.Stdout; +static import example; + +extern(C) int add(int a, int b) { + return a + b; +} + +extern(C) int sub(int a, int b) { + return a - b; +} + +extern(C) int mul(int a, int b) { + return a * b; +} + +void main() { + int a = 37; + int b = 42; + + Stdout( "a = " )( a ).newline; + Stdout( "b = " )( b ).newline; + + Stdout( "Trying some C callback functions:" ).newline; + Stdout( " ADD(a,b) = " )( example.do_op( a, b, example.ADD ) ).newline; + Stdout( " SUB(a,b) = " )( example.do_op( a, b, example.SUB ) ).newline; + Stdout( " MUL(a,b) = " )( example.do_op( a, b, example.MUL ) ).newline; + + Stdout( "Now the same with callback functions defined in D:" ).newline; + Stdout( " add(a,b) = " )( example.do_op( a, b, &add ) ).newline; + Stdout( " sub(a,b) = " )( example.do_op( a, b, &sub ) ).newline; + Stdout( " mul(a,b) = " )( example.do_op( a, b, &mul ) ).newline; +} diff --git a/Examples/d/funcptr/d2/runme.d b/Examples/d/funcptr/d2/runme.d new file mode 100644 index 000000000..929911d6c --- /dev/null +++ b/Examples/d/funcptr/d2/runme.d @@ -0,0 +1,34 @@ +module runme; + +import std.stdio; +static import example; + +extern(C) int add(int a, int b) { + return a + b; +} + +extern(C) int sub(int a, int b) { + return a - b; +} + +extern(C) int mul(int a, int b) { + return a * b; +} + +void main() { + int a = 37; + int b = 42; + + writefln( "a = %s", a ); + writefln( "b = %s", b ); + + writeln( "Trying some C callback functions:" ); + writefln( " ADD(a,b) = %s", example.do_op( a, b, example.ADD ) ); + writefln( " SUB(a,b) = %s", example.do_op( a, b, example.SUB ) ); + writefln( " MUL(a,b) = %s", example.do_op( a, b, example.MUL ) ); + + writeln( "Now the same with callback functions defined in D:" ); + writefln( " add(a,b) = %s", example.do_op( a, b, &add ) ); + writefln( " sub(a,b) = %s", example.do_op( a, b, &sub ) ); + writefln( " mul(a,b) = %s", example.do_op( a, b, &mul ) ); +} diff --git a/Examples/d/funcptr/example.c b/Examples/d/funcptr/example.c new file mode 100644 index 000000000..5c4a3dabf --- /dev/null +++ b/Examples/d/funcptr/example.c @@ -0,0 +1,19 @@ +/* File : example.c */ + +int do_op(int a, int b, int (*op)(int,int)) { + return (*op)(a,b); +} + +int add(int a, int b) { + return a+b; +} + +int sub(int a, int b) { + return a-b; +} + +int mul(int a, int b) { + return a*b; +} + +int (*funcvar)(int,int) = add; diff --git a/Examples/d/funcptr/example.h b/Examples/d/funcptr/example.h new file mode 100644 index 000000000..9936e24fc --- /dev/null +++ b/Examples/d/funcptr/example.h @@ -0,0 +1,9 @@ +/* file: example.h */ + +extern int do_op(int,int, int (*op)(int,int)); +extern int add(int,int); +extern int sub(int,int); +extern int mul(int,int); + +extern int (*funcvar)(int,int); + diff --git a/Examples/d/funcptr/example.i b/Examples/d/funcptr/example.i new file mode 100644 index 000000000..8b3bef678 --- /dev/null +++ b/Examples/d/funcptr/example.i @@ -0,0 +1,16 @@ +/* File : example.i */ +%module example +%{ +#include "example.h" +%} + +/* Wrap a function taking a pointer to a function */ +extern int do_op(int a, int b, int (*op)(int, int)); + +/* Now install a bunch of "ops" as constants */ +%constant int (*ADD)(int,int) = add; +%constant int (*SUB)(int,int) = sub; +%constant int (*MUL)(int,int) = mul; + +extern int (*funcvar)(int,int); + diff --git a/Examples/d/simple/Makefile b/Examples/d/simple/Makefile new file mode 100644 index 000000000..312e6a9e9 --- /dev/null +++ b/Examples/d/simple/Makefile @@ -0,0 +1,28 @@ +ifeq (2,$(D_VERSION)) + WORKING_DIR = d2/ +else + WORKING_DIR = d1/ +endif + +TOP = ../../.. +SWIG = $(TOP)/../preinst-swig +EXTRA_CFLAGS = -I../ ../example.c example_wrap.c +EXTRA_LDFLAGS = example.o example_wrap.o +TARGET = example_wrap +SWIGOPT = +DSRCS = *.d +DFLAGS = -ofrunme + + +all:: d + +d:: + cd $(WORKING_DIR); \ + $(MAKE) -f $(TOP)/Makefile EXTRA_CFLAGS='$(EXTRA_CFLAGS)' EXTRA_LDFLAGS='$(EXTRA_LDFLAGS)' SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT) -outcurrentdir ../example.i' TARGET='$(TARGET)' d; \ + $(MAKE) -f $(TOP)/Makefile DSRCS='$(DSRCS)' DFLAGS='$(DFLAGS)' d_compile + +clean:: + cd $(WORKING_DIR); \ + $(MAKE) -f $(TOP)/Makefile d_clean + +check: all diff --git a/Examples/d/simple/d1/runme.d b/Examples/d/simple/d1/runme.d new file mode 100644 index 000000000..1293f1839 --- /dev/null +++ b/Examples/d/simple/d1/runme.d @@ -0,0 +1,27 @@ +module runme; + +import tango.io.Stdout; +static import example; + +void main() { + /* + * Call our gcd() function. + */ + int x = 42; + int y = 105; + int g = example.gcd( x, y ); + Stdout.format( "The gcd of {} and {} is {}.", x, y, g ).newline; + + /* + * Manipulate the Foo global variable. + */ + + // Output its current value + Stdout.format( "Foo = {}", example.Foo ).newline; + + // Change its value + example.Foo = 3.1415926; + + // See if the change took effect + Stdout.format( "Foo = {}", example.Foo ).newline; +} diff --git a/Examples/d/simple/d2/runme.d b/Examples/d/simple/d2/runme.d new file mode 100644 index 000000000..7f278923b --- /dev/null +++ b/Examples/d/simple/d2/runme.d @@ -0,0 +1,27 @@ +module runme; + +import std.stdio; +static import example; + +void main() { + /* + * Call our gcd() function. + */ + int x = 42; + int y = 105; + int g = example.gcd(x, y); + writefln("The gcd of %s and %s is %s.", x, y, g); + + /* + * Manipulate the Foo global variable. + */ + + // Output its current value + writefln("Foo = %s", example.Foo); + + // Change its value + example.Foo = 3.1415926; + + // See if the change took effect + writefln("Foo = %s", example.Foo); +} diff --git a/Examples/d/simple/example.c b/Examples/d/simple/example.c new file mode 100644 index 000000000..1c2af789c --- /dev/null +++ b/Examples/d/simple/example.c @@ -0,0 +1,18 @@ +/* File : example.c */ + +/* A global variable */ +double Foo = 3.0; + +/* Compute the greatest common divisor of positive integers */ +int gcd(int x, int y) { + int g; + g = y; + while (x > 0) { + g = x; + x = y % x; + y = g; + } + return g; +} + + diff --git a/Examples/d/simple/example.i b/Examples/d/simple/example.i new file mode 100644 index 000000000..24093b9bf --- /dev/null +++ b/Examples/d/simple/example.i @@ -0,0 +1,7 @@ +/* File : example.i */ +%module example + +%inline %{ +extern int gcd(int x, int y); +extern double Foo; +%} diff --git a/Examples/d/variables/Makefile b/Examples/d/variables/Makefile new file mode 100644 index 000000000..312e6a9e9 --- /dev/null +++ b/Examples/d/variables/Makefile @@ -0,0 +1,28 @@ +ifeq (2,$(D_VERSION)) + WORKING_DIR = d2/ +else + WORKING_DIR = d1/ +endif + +TOP = ../../.. +SWIG = $(TOP)/../preinst-swig +EXTRA_CFLAGS = -I../ ../example.c example_wrap.c +EXTRA_LDFLAGS = example.o example_wrap.o +TARGET = example_wrap +SWIGOPT = +DSRCS = *.d +DFLAGS = -ofrunme + + +all:: d + +d:: + cd $(WORKING_DIR); \ + $(MAKE) -f $(TOP)/Makefile EXTRA_CFLAGS='$(EXTRA_CFLAGS)' EXTRA_LDFLAGS='$(EXTRA_LDFLAGS)' SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT) -outcurrentdir ../example.i' TARGET='$(TARGET)' d; \ + $(MAKE) -f $(TOP)/Makefile DSRCS='$(DSRCS)' DFLAGS='$(DFLAGS)' d_compile + +clean:: + cd $(WORKING_DIR); \ + $(MAKE) -f $(TOP)/Makefile d_clean + +check: all diff --git a/Examples/d/variables/d1/runme.d b/Examples/d/variables/d1/runme.d new file mode 100644 index 000000000..35c896bdc --- /dev/null +++ b/Examples/d/variables/d1/runme.d @@ -0,0 +1,71 @@ +// This example illustrates global variable access from C#. +module runme; + +import tango.io.Stdout; +static import example; + +void main() { + // Try to set the values of some global variables + example.ivar = 42; + example.svar = -31000; + example.lvar = 65537; + example.uivar = 123456; + example.usvar = 61000; + example.ulvar = 654321; + example.scvar = -13; + example.ucvar = 251; + example.cvar = 'S'; + example.fvar = 3.14159f; + example.dvar = 2.1828; + example.strvar = "Hello World"; + example.iptrvar = example.new_int(37); + example.ptptr = example.new_Point(37,42); + example.name = "Bill"; + + // Now print out the values of the variables + Stdout.formatln( "Variables (printed from D):" ); + Stdout.formatln( "ivar = {}", example.ivar ); + Stdout.formatln( "svar = {}", example.svar ); + Stdout.formatln( "lvar = {}", example.lvar ); + Stdout.formatln( "uivar = {}", example.uivar ); + Stdout.formatln( "usvar = {}", example.usvar ); + Stdout.formatln( "ulvar = {}", example.ulvar ); + Stdout.formatln( "scvar = {}", example.scvar ); + Stdout.formatln( "ucvar = {}", example.ucvar ); + Stdout.formatln( "fvar = {}", example.fvar ); + Stdout.formatln( "dvar = {}", example.dvar ); + Stdout.formatln( "cvar = {}", example.cvar ); + Stdout.formatln( "strvar = {}", example.strvar ); + Stdout.formatln( "cstrvar = {}", example.cstrvar ); + Stdout.formatln( "iptrvar = {}", example.iptrvar ); + Stdout.formatln( "name = {}", example.name ); + Stdout.formatln( "ptptr = {} {}", example.ptptr, example.Point_print(example.ptptr) ); + Stdout.formatln( "pt = {} {}", example.pt, example.Point_print(example.pt) ); + Stdout.formatln( "status = {}", example.status ); + + Stdout.formatln( "\nVariables (printed from the C library):" ); + example.print_vars(); + + Stdout.formatln( "\nNow I'm going to try and modify some read only variables:" ); + Stdout.formatln( "Checking that the read only variables are readonly..." ); + + Stdout( " 'path'..." ); + static if ( is( typeof( example.path = "a" ) ) ) + Stdout.formatln("Oh dear, this variable is not read only!"); + else + Stdout.formatln("Good."); + + Stdout( " 'status'..." ); + static if ( is( typeof( example.status = 2 ) ) ) + Stdout.formatln("Oh dear, this variable is not read only!"); + else + Stdout.formatln("Good."); + + Stdout.formatln( "\nI'm going to try and update a structure variable:" ); + + example.pt = example.ptptr; + + Stdout( "The new value is " ).flush; + example.pt_print(); + Stdout.formatln( "You should see the value {}", example.Point_print(example.ptptr) ); +} diff --git a/Examples/d/variables/d2/runme.d b/Examples/d/variables/d2/runme.d new file mode 100644 index 000000000..f80b81819 --- /dev/null +++ b/Examples/d/variables/d2/runme.d @@ -0,0 +1,71 @@ +// This example illustrates global variable access from C#. +module runme; + +import std.stdio; +static import example; + +void main() { + // Try to set the values of some global variables + example.ivar = 42; + example.svar = -31000; + example.lvar = 65537; + example.uivar = 123456; + example.usvar = 61000; + example.ulvar = 654321; + example.scvar = -13; + example.ucvar = 251; + example.cvar = 'S'; + example.fvar = 3.14159f; + example.dvar = 2.1828; + example.strvar = "Hello World"; + example.iptrvar = example.new_int(37); + example.ptptr = example.new_Point(37,42); + example.name = "Bill"; + + // Now print out the values of the variables + writefln( "Variables (printed from D):" ); + writefln( "ivar = %s", example.ivar ); + writefln( "svar = %s", example.svar ); + writefln( "lvar = %s", example.lvar ); + writefln( "uivar = %s", example.uivar ); + writefln( "usvar = %s", example.usvar ); + writefln( "ulvar = %s", example.ulvar ); + writefln( "scvar = %s", example.scvar ); + writefln( "ucvar = %s", example.ucvar ); + writefln( "fvar = %s", example.fvar ); + writefln( "dvar = %s", example.dvar ); + writefln( "cvar = %s", example.cvar ); + writefln( "strvar = %s", example.strvar ); + writefln( "cstrvar = %s", example.cstrvar ); + writefln( "iptrvar = %s", example.iptrvar ); + writefln( "name = %s", example.name ); + writefln( "ptptr = %s %s", example.ptptr, example.Point_print(example.ptptr) ); + writefln( "pt = %s %s", example.pt, example.Point_print(example.pt) ); + writefln( "status = %s", example.status ); + + writefln( "\nVariables (printed from the C library):" ); + example.print_vars(); + + writefln( "\nNow I'm going to try and modify some read only variables:" ); + writefln( "Checking that the read only variables are readonly..." ); + + writeln( " 'path'..." ); + static if ( is( typeof( example.path = "a" ) ) ) + writefln("Oh dear, this variable is not read only!"); + else + writefln("Good."); + + writeln( " 'status'..." ); + static if ( is( typeof( example.status = 2 ) ) ) + writefln("Oh dear, this variable is not read only!"); + else + writefln("Good."); + + writefln( "\nI'm going to try and update a structure variable:" ); + + example.pt = example.ptptr; + + write( "The new value is " ); + example.pt_print(); + writefln( "You should see the value %s", example.Point_print(example.ptptr) ); +} diff --git a/Examples/d/variables/example.c b/Examples/d/variables/example.c new file mode 100644 index 000000000..1bf9c120f --- /dev/null +++ b/Examples/d/variables/example.c @@ -0,0 +1,91 @@ +/* File : example.c */ + +/* I'm a file containing some C global variables */ + +/* Deal with Microsoft's attempt at deprecating C standard runtime functions */ +#if !defined(SWIG_NO_CRT_SECURE_NO_DEPRECATE) && defined(_MSC_VER) +# define _CRT_SECURE_NO_DEPRECATE +#endif + +#include +#include +#include "example.h" + +int ivar = 0; +short svar = 0; +long lvar = 0; +unsigned int uivar = 0; +unsigned short usvar = 0; +unsigned long ulvar = 0; +signed char scvar = 0; +unsigned char ucvar = 0; +char cvar = 0; +float fvar = 0; +double dvar = 0; +char *strvar = 0; +const char cstrvar[] = "Goodbye"; +int *iptrvar = 0; +char name[256] = "Dave"; +char path[256] = "/home/beazley"; + + +/* Global variables involving a structure */ +Point *ptptr = 0; +Point pt = { 10, 20 }; + +/* A variable that we will make read-only in the interface */ +int status = 1; + +/* A debugging function to print out their values */ + +void print_vars() { + printf("ivar = %d\n", ivar); + printf("svar = %d\n", svar); + printf("lvar = %ld\n", lvar); + printf("uivar = %u\n", uivar); + printf("usvar = %u\n", usvar); + printf("ulvar = %lu\n", ulvar); + printf("scvar = %d\n", scvar); + printf("ucvar = %u\n", ucvar); + printf("fvar = %g\n", fvar); + printf("dvar = %g\n", dvar); + printf("cvar = %c\n", cvar); + printf("strvar = %s\n", strvar ? strvar : "(null)"); + printf("cstrvar = %s\n", cstrvar ? cstrvar : "(null)"); + printf("iptrvar = %p\n", iptrvar); + printf("name = %s\n", name); + printf("ptptr = %p (%d, %d)\n", ptptr, ptptr ? ptptr->x : 0, ptptr ? ptptr->y : 0); + printf("pt = (%d, %d)\n", pt.x, pt.y); + printf("status = %d\n", status); +} + +/* A function to create an integer (to test iptrvar) */ + +int *new_int(int value) { + int *ip = (int *) malloc(sizeof(int)); + *ip = value; + return ip; +} + +/* A function to create a point */ + +Point *new_Point(int x, int y) { + Point *p = (Point *) malloc(sizeof(Point)); + p->x = x; + p->y = y; + return p; +} + +char * Point_print(Point *p) { + static char buffer[256]; + if (p) { + sprintf(buffer,"(%d, %d)", p->x,p->y); + } else { + sprintf(buffer,"null"); + } + return buffer; +} + +void pt_print() { + printf("(%d, %d)\n", pt.x, pt.y); +} diff --git a/Examples/d/variables/example.h b/Examples/d/variables/example.h new file mode 100644 index 000000000..0f7e89594 --- /dev/null +++ b/Examples/d/variables/example.h @@ -0,0 +1,6 @@ +/* File: example.h */ + +typedef struct { + int x,y; +} Point; + diff --git a/Examples/d/variables/example.i b/Examples/d/variables/example.i new file mode 100644 index 000000000..591b871ed --- /dev/null +++ b/Examples/d/variables/example.i @@ -0,0 +1,49 @@ +/* File : example.i */ +%module example +%{ +#include "example.h" +%} + +/* Some global variable declarations */ +%inline %{ +extern int ivar; +extern short svar; +extern long lvar; +extern unsigned int uivar; +extern unsigned short usvar; +extern unsigned long ulvar; +extern signed char scvar; +extern unsigned char ucvar; +extern char cvar; +extern float fvar; +extern double dvar; +extern char *strvar; +extern const char cstrvar[]; +extern int *iptrvar; +extern char name[256]; + +extern Point *ptptr; +extern Point pt; +%} + + +/* Some read-only variables */ + +%immutable; + +%inline %{ +extern int status; +extern char path[256]; +%} + +%mutable; + +/* Some helper functions to make it easier to test */ +%inline %{ +extern void print_vars(); +extern int *new_int(int value); +extern Point *new_Point(int x, int y); +extern char *Point_print(Point *p); +extern void pt_print(); +%} + diff --git a/Examples/test-suite/d/Makefile.in b/Examples/test-suite/d/Makefile.in new file mode 100644 index 000000000..2e9eb827f --- /dev/null +++ b/Examples/test-suite/d/Makefile.in @@ -0,0 +1,80 @@ +####################################################################### +# Makefile for D test-suite +####################################################################### + +LANGUAGE = d +srcdir = @srcdir@ +top_srcdir = ../@top_srcdir@ +top_builddir = ../@top_builddir@ + +ifeq (2,$(D_VERSION)) + VERSIONSUFFIX = .2 +else + VERSIONSUFFIX = .1 +endif + +TESTSUFFIX = _runme$(VERSIONSUFFIX).d + +CPP_TEST_CASES = \ + d_nativepointers \ + exception_partial_info + +include $(srcdir)/../common.mk + +# Override some variables from common.mk: + +TARGETSUFFIX = _wrap + +SWIGOPT+=-splitproxy -package $* + +# Rules for the different types of tests +%.cpptest: + $(setup) + +(cd $*$(VERSIONSUFFIX) && $(swig_and_compile_cpp)) + +$(run_testcase) + +%.ctest: + $(setup) + +(cd $*$(VERSIONSUFFIX) && $(swig_and_compile_c)) + +$(run_testcase) + +%.multicpptest: + $(setup) + +(cd $*$(VERSIONSUFFIX) && $(swig_and_compile_multi_cpp)) + +$(run_testcase) + +# Makes a directory for the testcase if it does not exist +setup = \ + if [ -f $(srcdir)/$(TESTPREFIX)$*$(TESTSUFFIX) ]; then \ + echo "$(ACTION)ing testcase $* (with run test) under $(LANGUAGE)" ; \ + else \ + echo "$(ACTION)ing testcase $* under $(LANGUAGE)" ; \ + fi; \ + if [ ! -d $*$(VERSIONSUFFIX) ]; then \ + mkdir $*$(VERSIONSUFFIX); \ + fi; \ + if [ ! -d $*$(VERSIONSUFFIX)/$* ]; then \ + mkdir $*$(VERSIONSUFFIX)/$*; \ + fi + +# Compiles D files then runs the testcase. A testcase is only run if +# a file is found which has _runme.d appended after the testcase name. +run_testcase = \ + if [ -f $(srcdir)/$(TESTPREFIX)$*$(TESTSUFFIX) ]; then \ + cd $*$(VERSIONSUFFIX) && \ + $(MAKE) -f $(top_builddir)/$(EXAMPLES)/Makefile \ + DFLAGS='-of$*_runme' \ + DSRCS='../$(srcdir)/$(TESTPREFIX)$*$(TESTSUFFIX) $*/*.d' d_compile && \ + env LD_LIBRARY_PATH=".:$$LD_LIBRARY_PATH" $(RUNTOOL) ./$*_runme; \ + else \ + cd $*$(VERSIONSUFFIX) && \ + $(MAKE) -f $(top_builddir)/$(EXAMPLES)/Makefile \ + DFLAGS='-c' \ + DSRCS='$*/*.d' d_compile && cd .. ; \ + fi + +# Clean: remove testcase directories +%.clean: + @if [ -d $* ]; then \ + rm -rf $*; \ + fi diff --git a/Examples/test-suite/d/README b/Examples/test-suite/d/README new file mode 100644 index 000000000..bb5372882 --- /dev/null +++ b/Examples/test-suite/d/README @@ -0,0 +1,7 @@ +D language module testsuite +--------------------------- + +Please see ../README for the common readme file. + +By default the D1 version is built, set D_VERSION=2 (in the environment or at +the make command line) to run it for D2 instead. diff --git a/Examples/test-suite/d/aggregate_runme.1.d b/Examples/test-suite/d/aggregate_runme.1.d new file mode 100644 index 000000000..a00d34c25 --- /dev/null +++ b/Examples/test-suite/d/aggregate_runme.1.d @@ -0,0 +1,25 @@ +module aggregate_runme; + +import aggregate.aggregate; + +void main() { + // Confirm that move() returns correct results under normal use. + int result = move(UP); + if (result != UP) throw new Exception("UP failed"); + + result = move(DOWN); + if (result != DOWN) throw new Exception("DOWN failed"); + + result = move(LEFT); + if (result != LEFT) throw new Exception("LEFT failed"); + + result = move(RIGHT); + if (result != RIGHT) throw new Exception("RIGHT failed"); + + // Confirm that move() raises an exception when the contract is violated. + try { + move(0); + throw new Exception("0 test failed"); + } + catch (Exception e) {} +} diff --git a/Examples/test-suite/d/aggregate_runme.2.d b/Examples/test-suite/d/aggregate_runme.2.d new file mode 100644 index 000000000..a00d34c25 --- /dev/null +++ b/Examples/test-suite/d/aggregate_runme.2.d @@ -0,0 +1,25 @@ +module aggregate_runme; + +import aggregate.aggregate; + +void main() { + // Confirm that move() returns correct results under normal use. + int result = move(UP); + if (result != UP) throw new Exception("UP failed"); + + result = move(DOWN); + if (result != DOWN) throw new Exception("DOWN failed"); + + result = move(LEFT); + if (result != LEFT) throw new Exception("LEFT failed"); + + result = move(RIGHT); + if (result != RIGHT) throw new Exception("RIGHT failed"); + + // Confirm that move() raises an exception when the contract is violated. + try { + move(0); + throw new Exception("0 test failed"); + } + catch (Exception e) {} +} diff --git a/Examples/test-suite/d/allprotected_runme.1.d b/Examples/test-suite/d/allprotected_runme.1.d new file mode 100644 index 000000000..82a180e66 --- /dev/null +++ b/Examples/test-suite/d/allprotected_runme.1.d @@ -0,0 +1,65 @@ +module allprotected_runme; + +import allprotected.Klass; +import allprotected.ProtectedBase; + +void main() { + auto mpb = new MyProtectedBase("MyProtectedBase"); + mpb.accessProtected(); +} + +class MyProtectedBase : ProtectedBase { +public: + this(char[] name) { + super(name); + } + + void accessProtected() { + char[] s = virtualMethod(); + if (s != "ProtectedBase") + throw new Exception("Failed"); + + Klass k = instanceMethod(new Klass("xyz")); + if (k.getName() != "xyz") + throw new Exception("Failed"); + + k = instanceOverloaded(new Klass("xyz")); + if (k.getName() != "xyz") + throw new Exception("Failed"); + + k = instanceOverloaded(new Klass("xyz"), "abc"); + if (k.getName() != "abc") + throw new Exception("Failed"); + + k = staticMethod(new Klass("abc")); + if (k.getName() != "abc") + throw new Exception("Failed"); + + k = staticOverloaded(new Klass("xyz")); + if (k.getName() != "xyz") + throw new Exception("Failed"); + + k = staticOverloaded(new Klass("xyz"), "abc"); + if (k.getName() != "abc") + throw new Exception("Failed"); + + instanceMemberVariable = 30; + int i = instanceMemberVariable; + if (i != 30) + throw new Exception("Failed"); + + staticMemberVariable = 40; + i = staticMemberVariable; + if (i != 40) + throw new Exception("Failed"); + + i = staticConstMemberVariable; + if (i != 20) + throw new Exception("Failed"); + + anEnum = ProtectedBase.AnEnum.EnumVal1; + ProtectedBase.AnEnum ae = anEnum; + if (ae != ProtectedBase.AnEnum.EnumVal1) + throw new Exception("Failed"); + } +} diff --git a/Examples/test-suite/d/allprotected_runme.2.d b/Examples/test-suite/d/allprotected_runme.2.d new file mode 100644 index 000000000..799230291 --- /dev/null +++ b/Examples/test-suite/d/allprotected_runme.2.d @@ -0,0 +1,65 @@ +module allprotected_runme; + +import allprotected.Klass; +import allprotected.ProtectedBase; + +void main() { + auto mpb = new MyProtectedBase("MyProtectedBase"); + mpb.accessProtected(); +} + +class MyProtectedBase : ProtectedBase { +public: + this(string name) { + super(name); + } + + void accessProtected() { + string s = virtualMethod(); + if (s != "ProtectedBase") + throw new Exception("Failed"); + + Klass k = instanceMethod(new Klass("xyz")); + if (k.getName() != "xyz") + throw new Exception("Failed"); + + k = instanceOverloaded(new Klass("xyz")); + if (k.getName() != "xyz") + throw new Exception("Failed"); + + k = instanceOverloaded(new Klass("xyz"), "abc"); + if (k.getName() != "abc") + throw new Exception("Failed"); + + k = staticMethod(new Klass("abc")); + if (k.getName() != "abc") + throw new Exception("Failed"); + + k = staticOverloaded(new Klass("xyz")); + if (k.getName() != "xyz") + throw new Exception("Failed"); + + k = staticOverloaded(new Klass("xyz"), "abc"); + if (k.getName() != "abc") + throw new Exception("Failed"); + + instanceMemberVariable = 30; + int i = instanceMemberVariable; + if (i != 30) + throw new Exception("Failed"); + + staticMemberVariable = 40; + i = staticMemberVariable; + if (i != 40) + throw new Exception("Failed"); + + i = staticConstMemberVariable; + if (i != 20) + throw new Exception("Failed"); + + anEnum = ProtectedBase.AnEnum.EnumVal1; + ProtectedBase.AnEnum ae = anEnum; + if (ae != ProtectedBase.AnEnum.EnumVal1) + throw new Exception("Failed"); + } +} diff --git a/Examples/test-suite/d/apply_strings_runme.1.d b/Examples/test-suite/d/apply_strings_runme.1.d new file mode 100644 index 000000000..960caa4ca --- /dev/null +++ b/Examples/test-suite/d/apply_strings_runme.1.d @@ -0,0 +1,12 @@ +module apply_strings_runme; + +import apply_strings.apply_strings; + +const char[] TEST_MESSAGE = "A message from target language to the C++ world and back again."; + +void main() { + if (UCharFunction(TEST_MESSAGE) != TEST_MESSAGE) throw new Exception("UCharFunction failed"); + if (SCharFunction(TEST_MESSAGE) != TEST_MESSAGE) throw new Exception("SCharFunction failed"); + auto pChar = CharFunction(null); + if (pChar !is null) throw new Exception("CharFunction failed"); +} diff --git a/Examples/test-suite/d/apply_strings_runme.2.d b/Examples/test-suite/d/apply_strings_runme.2.d new file mode 100644 index 000000000..86183f8a3 --- /dev/null +++ b/Examples/test-suite/d/apply_strings_runme.2.d @@ -0,0 +1,12 @@ +module apply_strings_runme; + +import apply_strings.apply_strings; + +enum string TEST_MESSAGE = "A message from target language to the C++ world and back again."; + +void main() { + if (UCharFunction(TEST_MESSAGE) != TEST_MESSAGE) throw new Exception("UCharFunction failed"); + if (SCharFunction(TEST_MESSAGE) != TEST_MESSAGE) throw new Exception("SCharFunction failed"); + auto pChar = CharFunction(null); + if (pChar !is null) throw new Exception("CharFunction failed"); +} diff --git a/Examples/test-suite/d/bools_runme.1.d b/Examples/test-suite/d/bools_runme.1.d new file mode 100644 index 000000000..f501b0762 --- /dev/null +++ b/Examples/test-suite/d/bools_runme.1.d @@ -0,0 +1,20 @@ +/// This is the bool runtime testcase. It checks that the C++ bool type works. +module bools_runme; + +import bools.bools; + +void main() { + bool t = true; + bool f = false; + + check_bo(f); + check_bo(t); +} + +void check_bo(bool input) { + for (int i = 0; i < 1000; ++i) { + if (bo(input) != input) { + throw new Exception("Runtime test check_bo failed."); + } + } +} diff --git a/Examples/test-suite/d/bools_runme.2.d b/Examples/test-suite/d/bools_runme.2.d new file mode 100644 index 000000000..f501b0762 --- /dev/null +++ b/Examples/test-suite/d/bools_runme.2.d @@ -0,0 +1,20 @@ +/// This is the bool runtime testcase. It checks that the C++ bool type works. +module bools_runme; + +import bools.bools; + +void main() { + bool t = true; + bool f = false; + + check_bo(f); + check_bo(t); +} + +void check_bo(bool input) { + for (int i = 0; i < 1000; ++i) { + if (bo(input) != input) { + throw new Exception("Runtime test check_bo failed."); + } + } +} diff --git a/Examples/test-suite/d/catches_runme.1.d b/Examples/test-suite/d/catches_runme.1.d new file mode 100644 index 000000000..55b18132d --- /dev/null +++ b/Examples/test-suite/d/catches_runme.1.d @@ -0,0 +1,33 @@ +module catches_runme; + +import catches.catches; + +void main() { + test({ test_catches(1); }, "C++ int exception thrown, value: 1"); + test({ test_catches(2); }, "two"); + test({ test_catches(3); }, "C++ ThreeException const & exception thrown"); + + test({ test_exception_specification(1); }, "C++ int exception thrown, value: 1"); + test({ test_exception_specification(2); }, "unknown exception"); + test({ test_exception_specification(3); }, "unknown exception"); + + test({ test_catches_all(1); }, "unknown exception"); +} + +void test(void delegate() command, char[] expectedMessage) { + bool didntThrow; + try { + command(); + didntThrow = true; + } catch (Exception e) { + if (e.msg != expectedMessage) { + throw new Exception("Failed to propagate C++ exception. Expected '" ~ + expectedMessage ~ "', but received '" ~ e.msg ~ "'."); + } + } + + if (didntThrow) { + throw new Exception("Failed to propagate C++ exception. Expected '" ~ + expectedMessage ~ "', but no exception was thrown."); + } +} diff --git a/Examples/test-suite/d/catches_runme.2.d b/Examples/test-suite/d/catches_runme.2.d new file mode 100644 index 000000000..508558485 --- /dev/null +++ b/Examples/test-suite/d/catches_runme.2.d @@ -0,0 +1,33 @@ +module catches_runme; + +import catches.catches; + +void main() { + test({ test_catches(1); }, "C++ int exception thrown, value: 1"); + test({ test_catches(2); }, "two"); + test({ test_catches(3); }, "C++ ThreeException const & exception thrown"); + + test({ test_exception_specification(1); }, "C++ int exception thrown, value: 1"); + test({ test_exception_specification(2); }, "unknown exception"); + test({ test_exception_specification(3); }, "unknown exception"); + + test({ test_catches_all(1); }, "unknown exception"); +} + +void test(void delegate() command, string expectedMessage) { + bool didntThrow; + try { + command(); + didntThrow = true; + } catch (Exception e) { + if (e.msg != expectedMessage) { + throw new Exception("Failed to propagate C++ exception. Expected '" ~ + expectedMessage ~ "', but received '" ~ e.msg ~ "'."); + } + } + + if (didntThrow) { + throw new Exception("Failed to propagate C++ exception. Expected '" ~ + expectedMessage ~ "', but no exception was thrown."); + } +} diff --git a/Examples/test-suite/d/char_strings_runme.1.d b/Examples/test-suite/d/char_strings_runme.1.d new file mode 100644 index 000000000..cde6fe0f7 --- /dev/null +++ b/Examples/test-suite/d/char_strings_runme.1.d @@ -0,0 +1,151 @@ +module char_strings_runme; + +import tango.text.convert.Integer; +import char_strings.char_strings; + +const char[] CPLUSPLUS_MSG = "A message from the deep dark world of C++, where anything is possible."; +const char[] OTHERLAND_MSG = "Little message from the safe world."; + +void main() { + const uint count = 10000; + uint i = 0; + + // get functions + for (i=0; i