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
This commit is contained in:
parent
ef3644f052
commit
3d7799fe0d
8 changed files with 107 additions and 16 deletions
|
|
@ -5,6 +5,15 @@ See the RELEASENOTES file for a summary of changes in each release.
|
||||||
Version 2.0.2 (in progress)
|
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
|
2010-01-14: wsfulton
|
||||||
Added some missing multi-argument typemaps: (char *STRING, size_t LENGTH) and
|
Added some missing multi-argument typemaps: (char *STRING, size_t LENGTH) and
|
||||||
(char *STRING, int LENGTH). Documentation for this updated. Java patch from
|
(char *STRING, int LENGTH). Documentation for this updated. Java patch from
|
||||||
|
|
|
||||||
|
|
@ -1802,20 +1802,6 @@ struct DerivedIntValue : IntValue {
|
||||||
</pre>
|
</pre>
|
||||||
</div>
|
</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:
|
|
||||||
</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
|
|
||||||
</pre>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<p>
|
<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++:
|
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>
|
</p>
|
||||||
|
|
@ -1828,6 +1814,59 @@ int val4 = example.extractValueSmart(div);
|
||||||
</pre>
|
</pre>
|
||||||
</div>
|
</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.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>
|
||||||
|
Adding the missing <tt>%shared_ptr</tt> macros will fix this:
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<div class="code">
|
||||||
|
<pre>
|
||||||
|
%include "boost_shared_ptr.i"
|
||||||
|
%shared_ptr(GrandParent);
|
||||||
|
%shared_ptr(Parent);
|
||||||
|
%shared_ptr(Child);
|
||||||
|
|
||||||
|
... as before ...
|
||||||
|
</pre>
|
||||||
|
</div>
|
||||||
|
|
||||||
<H2><a name="Library_nn16"></a>8.5 Utility Libraries</H2>
|
<H2><a name="Library_nn16"></a>8.5 Utility Libraries</H2>
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -513,6 +513,7 @@ example.i(4) : Syntax error in input.
|
||||||
<li>517.
|
<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>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>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>
|
</ul>
|
||||||
|
|
||||||
<H3><a name="Warnings_nn15"></a>14.9.6 Language module specific (700-899) </H3>
|
<H3><a name="Warnings_nn15"></a>14.9.6 Language module specific (700-899) </H3>
|
||||||
|
|
|
||||||
29
Examples/test-suite/errors/cpp_shared_ptr.i
Normal file
29
Examples/test-suite/errors/cpp_shared_ptr.i
Normal file
|
|
@ -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() {}
|
||||||
|
};
|
||||||
|
%}
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -10,6 +10,7 @@ c_bad_native.i:3: Error: %native declaration 'foo' is not a function.
|
||||||
|
|
||||||
:::::::::::::::::::::::::::::::: c_class.i :::::::::::::::::::::::::::::::::::
|
:::::::::::::::::::::::::::::::: c_class.i :::::::::::::::::::::::::::::::::::
|
||||||
c_class.i:3: Warning 301: class keyword used, but not in C++ mode.
|
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 :::::::::::::::::::::::::::::::::::
|
:::::::::::::::::::::::::::::::: 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:6: Warning 309: private inheritance from base 'Foo' (ignored).
|
||||||
cpp_private_inherit.i:9: Warning 309: protected 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_argname.i :::::::::::::::::::::::::::::::::::
|
||||||
|
|
||||||
:::::::::::::::::::::::::::::::: cpp_template_nargs.i :::::::::::::::::::::::::::::::::::
|
:::::::::::::::::::::::::::::::: cpp_template_nargs.i :::::::::::::::::::::::::::::::::::
|
||||||
|
|
|
||||||
|
|
@ -76,6 +76,7 @@ cpp_nobase
|
||||||
cpp_overload
|
cpp_overload
|
||||||
cpp_private_defvalue
|
cpp_private_defvalue
|
||||||
cpp_private_inherit
|
cpp_private_inherit
|
||||||
|
cpp_shared_ptr
|
||||||
cpp_template_argname
|
cpp_template_argname
|
||||||
cpp_template_nargs
|
cpp_template_nargs
|
||||||
cpp_template_not
|
cpp_template_not
|
||||||
|
|
@ -98,14 +99,14 @@ for i in ${CFILES}; do
|
||||||
echo " Testing : ${i}.i";
|
echo " Testing : ${i}.i";
|
||||||
echo "" >> ${LOGFILE};
|
echo "" >> ${LOGFILE};
|
||||||
echo ":::::::::::::::::::::::::::::::: ${i}.i :::::::::::::::::::::::::::::::::::" >> ${LOGFILE};
|
echo ":::::::::::::::::::::::::::::::: ${i}.i :::::::::::::::::::::::::::::::::::" >> ${LOGFILE};
|
||||||
${SWIG} -Wall ${SWIGOPT} ${i}.i >>${LOGFILE} 2>&1
|
${SWIG} -python -Wall ${SWIGOPT} ${i}.i >>${LOGFILE} 2>&1
|
||||||
done
|
done
|
||||||
|
|
||||||
for i in ${CPPFILES}; do
|
for i in ${CPPFILES}; do
|
||||||
echo " Testing : ${i}.i";
|
echo " Testing : ${i}.i";
|
||||||
echo "" >> ${LOGFILE}
|
echo "" >> ${LOGFILE}
|
||||||
echo ":::::::::::::::::::::::::::::::: ${i}.i :::::::::::::::::::::::::::::::::::" >> ${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
|
done
|
||||||
|
|
||||||
echo ""
|
echo ""
|
||||||
|
|
|
||||||
|
|
@ -193,6 +193,7 @@
|
||||||
#define WARN_LANG_DIRECTOR_ABSTRACT 517
|
#define WARN_LANG_DIRECTOR_ABSTRACT 517
|
||||||
#define WARN_LANG_PORTABILITY_FILENAME 518
|
#define WARN_LANG_PORTABILITY_FILENAME 518
|
||||||
#define WARN_LANG_TEMPLATE_METHOD_IGNORE 519
|
#define WARN_LANG_TEMPLATE_METHOD_IGNORE 519
|
||||||
|
#define WARN_LANG_SMARTPTR_MISSING 520
|
||||||
|
|
||||||
/* -- Reserved (600-799) -- */
|
/* -- Reserved (600-799) -- */
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -254,12 +254,17 @@ class TypePass:private Dispatcher {
|
||||||
Delete(smartnamestr);
|
Delete(smartnamestr);
|
||||||
/* setup inheritance relationship between smart pointer templates */
|
/* setup inheritance relationship between smart pointer templates */
|
||||||
SwigType_inherit(smart, bsmart, 0, convcode);
|
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(convcode);
|
||||||
Delete(bsmart);
|
Delete(bsmart);
|
||||||
Delete(smart);
|
Delete(smart);
|
||||||
} else {
|
} else {
|
||||||
Swig_error(Getfile(first), Getline(first), "Invalid type (%s) in 'smartptr' feature for class %s.\n", SwigType_namestr(smartptr), SwigType_namestr(clsname));
|
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) {
|
if (!importmode) {
|
||||||
String *btype = Copy(bname);
|
String *btype = Copy(bname);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue