diff options
author | William S Fulton <wsf@fultondesigns.co.uk> | 2011-01-17 21:12:35 +0000 |
---|---|---|
committer | William S Fulton <wsf@fultondesigns.co.uk> | 2011-01-17 21:12:35 +0000 |
commit | 3d7799fe0d519c05817392678974555c09b629c6 (patch) | |
tree | f751f75ffb58dbe8268d6e01bd7d86b8a3761b78 | |
parent | ef3644f052850c970b107961562204d9321a23a6 (diff) | |
download | swig-3d7799fe0d519c05817392678974555c09b629c6.tar.gz |
New warning when the smartptr feature is missing in some classes in an inheritance chain. Errors test-suite now uses Python instead of Tcl as testing language
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12395 626c5289-ae23-0410-ae9c-e8d60b6d4f22
-rw-r--r-- | CHANGES.current | 9 | ||||
-rw-r--r-- | Doc/Manual/Library.html | 61 | ||||
-rw-r--r-- | Doc/Manual/Warnings.html | 1 | ||||
-rw-r--r-- | Examples/test-suite/errors/cpp_shared_ptr.i | 29 | ||||
-rw-r--r-- | Examples/test-suite/errors/expected.log | 6 | ||||
-rwxr-xr-x | Examples/test-suite/errors/make.sh | 5 | ||||
-rw-r--r-- | Source/Include/swigwarn.h | 1 | ||||
-rw-r--r-- | Source/Modules/typepass.cxx | 5 |
8 files changed, 104 insertions, 13 deletions
diff --git a/CHANGES.current b/CHANGES.current index 20524df69..57b639421 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.2 (in progress) =========================== +2010-01-17: wsfulton + New warning for smart pointers if only some of the classes in the inheritance + chain are marked as smart pointer, eg, %shared_ptr should be used for all classes + in an inheritance hierarchy, so this new warning highlights code where this is + not the case. + + example.i:12: Warning 520: Base class 'A' of 'B' is not similarly marked as a smart pointer. + example.i:16: Warning 520: Derived class 'C' of 'B' is not similarly marked as a smart pointer. + 2010-01-14: wsfulton Added some missing multi-argument typemaps: (char *STRING, size_t LENGTH) and (char *STRING, int LENGTH). Documentation for this updated. Java patch from diff --git a/Doc/Manual/Library.html b/Doc/Manual/Library.html index 31f8c47b7..02b8e53bd 100644 --- a/Doc/Manual/Library.html +++ b/Doc/Manual/Library.html @@ -1803,28 +1803,67 @@ struct DerivedIntValue : IntValue { </div> <p> -Note that if the <tt>%shared_ptr</tt> macro is omitted for any class in the inheritance hierarchy, it will -result in a C++ compiler error. -For example if the above <tt>%shared_ptr(DerivedIntValue)</tt> is omitted, the following is typical of the compiler error that will result: +A shared_ptr of the derived class can now be passed to a method where the base is expected in the target language, just as it can in C++: +</p> + +<div class="targetlang"> +<pre> +DerivedIntValue div = new DerivedIntValue(5678); +int val3 = example.extractValue(div); +int val4 = example.extractValueSmart(div); +</pre> +</div> + +<p> +If the <tt>%shared_ptr</tt> macro is omitted for any class in the inheritance hierarchy, SWIG will warn about this and the generated code may or may not result in a C++ compilation error. +For example, the following input: +</p> + +<div class="code"> +<pre> +%include "boost_shared_ptr.i" +%shared_ptr(Parent); + +%inline %{ + #include <boost/shared_ptr.hpp> + struct GrandParent { + virtual ~GrandParent() {} + }; + + struct Parent : GrandParent { + virtual ~Parent() {} + }; + + struct Child : Parent { + virtual ~Child() {} + }; +%} +</pre> +</div> + +<p> +warns about the missing smart pointer information: </p> <div class="shell"> <pre> -example_wrap.cxx: In function 'void Java_exampleJNI_delete_1DerivedIntValue(JNIEnv*, -_jclass*, jlong)': -example_wrap.cxx:3169: error: 'smartarg1' was not declared in this scope +example.i:12: Warning 520: Base class 'GrandParent' of 'Parent' is not similarly marked as a smart pointer. +example.i:16: Warning 520: Derived class 'Child' of 'Parent' is not similarly marked as a smart pointer. </pre> </div> <p> -A shared_ptr of the derived class can now be passed to a method where the base is expected in the target language, just as it can in C++: +Adding the missing <tt>%shared_ptr</tt> macros will fix this: </p> -<div class="targetlang"> +<div class="code"> <pre> -DerivedIntValue div = new DerivedIntValue(5678); -int val3 = example.extractValue(div); -int val4 = example.extractValueSmart(div); +%include "boost_shared_ptr.i" +%shared_ptr(GrandParent); +%shared_ptr(Parent); +%shared_ptr(Child); + +... as before ... </pre> </div> diff --git a/Doc/Manual/Warnings.html b/Doc/Manual/Warnings.html index 2c71b6a31..325bf2f5f 100644 --- a/Doc/Manual/Warnings.html +++ b/Doc/Manual/Warnings.html @@ -513,6 +513,7 @@ example.i(4) : Syntax error in input. <li>517. <li>518. Portability warning: File <em>file1</em> will be overwritten by <em>file2</em> on case insensitive filesystems such as Windows' FAT32 and NTFS unless the class/module name is renamed. <li>519. %template() contains no name. Template method ignored: <em>declaration</em> +<li>520. <em>Base/Derived</em> class '<em>classname1</em>' of '<em>classname2</em>' is not similarly marked as a smart pointer. </ul> <H3><a name="Warnings_nn15"></a>14.9.6 Language module specific (700-899) </H3> diff --git a/Examples/test-suite/errors/cpp_shared_ptr.i b/Examples/test-suite/errors/cpp_shared_ptr.i new file mode 100644 index 000000000..edbd0cf87 --- /dev/null +++ b/Examples/test-suite/errors/cpp_shared_ptr.i @@ -0,0 +1,29 @@ +%module cpp_shared_ptr + +%include <boost_shared_ptr.i> + +%shared_ptr(B); +%shared_ptr(C); + +%inline %{ + #include <stdio.h> + #include <boost/shared_ptr.hpp> + + struct A { + virtual ~A() {} + }; + + struct B { + virtual ~B() {} + }; + + struct C : B, A { + virtual ~C() {} + }; + + struct D : C { + virtual ~D() {} + }; +%} + + diff --git a/Examples/test-suite/errors/expected.log b/Examples/test-suite/errors/expected.log index 06942064f..e6430293b 100644 --- a/Examples/test-suite/errors/expected.log +++ b/Examples/test-suite/errors/expected.log @@ -10,6 +10,7 @@ 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_class.i:3: Warning 314: 'class' is a python keyword, renaming to '_class' :::::::::::::::::::::::::::::::: c_default_error.i ::::::::::::::::::::::::::::::::::: @@ -280,6 +281,11 @@ cpp_nobase.i:6: Warning 401: Maybe you forgot to instantiate 'Bar< int >' using 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_shared_ptr.i ::::::::::::::::::::::::::::::::::: +cpp_shared_ptr.i:20: Warning 520: Base class 'A' of 'C' is not similarly marked as a smart pointer. +cpp_shared_ptr.i:24: Warning 520: Derived class 'D' of 'C' is not similarly marked as a smart pointer. +cpp_shared_ptr.i:24: Warning 520: Derived class 'D' of 'B' is not similarly marked as a smart pointer. + :::::::::::::::::::::::::::::::: cpp_template_argname.i ::::::::::::::::::::::::::::::::::: :::::::::::::::::::::::::::::::: cpp_template_nargs.i ::::::::::::::::::::::::::::::::::: diff --git a/Examples/test-suite/errors/make.sh b/Examples/test-suite/errors/make.sh index 52d6c8967..875d1ecbe 100755 --- a/Examples/test-suite/errors/make.sh +++ b/Examples/test-suite/errors/make.sh @@ -76,6 +76,7 @@ cpp_nobase cpp_overload cpp_private_defvalue cpp_private_inherit +cpp_shared_ptr cpp_template_argname cpp_template_nargs cpp_template_not @@ -98,14 +99,14 @@ for i in ${CFILES}; do echo " Testing : ${i}.i"; echo "" >> ${LOGFILE}; echo ":::::::::::::::::::::::::::::::: ${i}.i :::::::::::::::::::::::::::::::::::" >> ${LOGFILE}; - ${SWIG} -Wall ${SWIGOPT} ${i}.i >>${LOGFILE} 2>&1 + ${SWIG} -python -Wall ${SWIGOPT} ${i}.i >>${LOGFILE} 2>&1 done for i in ${CPPFILES}; do echo " Testing : ${i}.i"; echo "" >> ${LOGFILE} echo ":::::::::::::::::::::::::::::::: ${i}.i :::::::::::::::::::::::::::::::::::" >> ${LOGFILE}; - ${SWIG} -Wall -c++ ${SWIGOPT} ${i}.i >>${LOGFILE} 2>&1 + ${SWIG} -python -Wall -c++ ${SWIGOPT} ${i}.i >>${LOGFILE} 2>&1 done echo "" diff --git a/Source/Include/swigwarn.h b/Source/Include/swigwarn.h index b13015994..9c5c3be74 100644 --- a/Source/Include/swigwarn.h +++ b/Source/Include/swigwarn.h @@ -193,6 +193,7 @@ #define WARN_LANG_DIRECTOR_ABSTRACT 517 #define WARN_LANG_PORTABILITY_FILENAME 518 #define WARN_LANG_TEMPLATE_METHOD_IGNORE 519 +#define WARN_LANG_SMARTPTR_MISSING 520 /* -- Reserved (600-799) -- */ diff --git a/Source/Modules/typepass.cxx b/Source/Modules/typepass.cxx index 438b66617..8751b1e67 100644 --- a/Source/Modules/typepass.cxx +++ b/Source/Modules/typepass.cxx @@ -254,12 +254,17 @@ class TypePass:private Dispatcher { Delete(smartnamestr); /* setup inheritance relationship between smart pointer templates */ SwigType_inherit(smart, bsmart, 0, convcode); + if (!GetFlag(bclass, "feature:smartptr")) + Swig_warning(WARN_LANG_SMARTPTR_MISSING, Getfile(first), Getline(first), "Base class '%s' of '%s' is not similarly marked as a smart pointer.\n", SwigType_namestr(Getattr(bclass, "name")), SwigType_namestr(Getattr(first, "name"))); Delete(convcode); Delete(bsmart); Delete(smart); } else { Swig_error(Getfile(first), Getline(first), "Invalid type (%s) in 'smartptr' feature for class %s.\n", SwigType_namestr(smartptr), SwigType_namestr(clsname)); } + } else { + if (GetFlag(bclass, "feature:smartptr")) + Swig_warning(WARN_LANG_SMARTPTR_MISSING, Getfile(first), Getline(first), "Derived class '%s' of '%s' is not similarly marked as a smart pointer.\n", SwigType_namestr(Getattr(first, "name")), SwigType_namestr(Getattr(bclass, "name"))); } if (!importmode) { String *btype = Copy(bname); |