From: <wsf...@us...> - 2011-01-17 21:12:41
|
Revision: 12395 http://swig.svn.sourceforge.net/swig/?rev=12395&view=rev Author: wsfulton Date: 2011-01-17 21:12:35 +0000 (Mon, 17 Jan 2011) Log Message: ----------- 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 Modified Paths: -------------- trunk/CHANGES.current trunk/Doc/Manual/Library.html trunk/Doc/Manual/Warnings.html trunk/Examples/test-suite/errors/expected.log trunk/Examples/test-suite/errors/make.sh trunk/Source/Include/swigwarn.h trunk/Source/Modules/typepass.cxx Added Paths: ----------- trunk/Examples/test-suite/errors/cpp_shared_ptr.i Modified: trunk/CHANGES.current =================================================================== --- trunk/CHANGES.current 2011-01-14 21:31:36 UTC (rev 12394) +++ trunk/CHANGES.current 2011-01-17 21:12:35 UTC (rev 12395) @@ -5,6 +5,15 @@ 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 Modified: trunk/Doc/Manual/Library.html =================================================================== --- trunk/Doc/Manual/Library.html 2011-01-14 21:31:36 UTC (rev 12394) +++ trunk/Doc/Manual/Library.html 2011-01-17 21:12:35 UTC (rev 12395) @@ -1803,28 +1803,67 @@ </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> Modified: trunk/Doc/Manual/Warnings.html =================================================================== --- trunk/Doc/Manual/Warnings.html 2011-01-14 21:31:36 UTC (rev 12394) +++ trunk/Doc/Manual/Warnings.html 2011-01-17 21:12:35 UTC (rev 12395) @@ -513,6 +513,7 @@ <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> Added: trunk/Examples/test-suite/errors/cpp_shared_ptr.i =================================================================== --- trunk/Examples/test-suite/errors/cpp_shared_ptr.i (rev 0) +++ trunk/Examples/test-suite/errors/cpp_shared_ptr.i 2011-01-17 21:12:35 UTC (rev 12395) @@ -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() {} + }; +%} + + Modified: trunk/Examples/test-suite/errors/expected.log =================================================================== --- trunk/Examples/test-suite/errors/expected.log 2011-01-14 21:31:36 UTC (rev 12394) +++ trunk/Examples/test-suite/errors/expected.log 2011-01-17 21:12:35 UTC (rev 12395) @@ -10,6 +10,7 @@ :::::::::::::::::::::::::::::::: 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_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 ::::::::::::::::::::::::::::::::::: Modified: trunk/Examples/test-suite/errors/make.sh =================================================================== --- trunk/Examples/test-suite/errors/make.sh 2011-01-14 21:31:36 UTC (rev 12394) +++ trunk/Examples/test-suite/errors/make.sh 2011-01-17 21:12:35 UTC (rev 12395) @@ -76,6 +76,7 @@ cpp_overload cpp_private_defvalue cpp_private_inherit +cpp_shared_ptr cpp_template_argname cpp_template_nargs cpp_template_not @@ -98,14 +99,14 @@ 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 "" Modified: trunk/Source/Include/swigwarn.h =================================================================== --- trunk/Source/Include/swigwarn.h 2011-01-14 21:31:36 UTC (rev 12394) +++ trunk/Source/Include/swigwarn.h 2011-01-17 21:12:35 UTC (rev 12395) @@ -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) -- */ Modified: trunk/Source/Modules/typepass.cxx =================================================================== --- trunk/Source/Modules/typepass.cxx 2011-01-14 21:31:36 UTC (rev 12394) +++ trunk/Source/Modules/typepass.cxx 2011-01-17 21:12:35 UTC (rev 12395) @@ -254,12 +254,17 @@ 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); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |