Fixed bug in typemaps which caused derived_byvalue and rname test cases to fail.

git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@9648 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
Mark Gossage 2007-02-22 09:21:23 +00:00
commit e38a14b2df
3 changed files with 72 additions and 13 deletions

View file

@ -1,6 +1,10 @@
Version 1.3.32 (in progress)
============================
02/22/2007: mgossage
[Lua] Fixed bug in typemaps which caused derived_byvalue and rname test cases to fail.
Updated derived_byvalue.i to explain how to find and fix the problem
01/25/2007: wsfulton
Fix #1538522 and #1338527, forward templated class declarations without a
name for the templated class parameters, such as:

View file

@ -31,11 +31,61 @@ struct Bar {
if the derived class is deleted, it works again
if the previos Foo::method
if the previous Foo::method is deleted, it works again
*/
struct DerFoo : Foo {
};
/*
The problem is caused by accidentally remembering a object value type
instead of an object pointer type.
During the course of SWIGing a file, several calls to SwigType_remember()
or SwigType_remember_clientdata() will be made.
When the SwigType_emit_type_table() function is called it emits all the
type conversion functions.
If a object type exists in the SwigType table, you get this error.
You can view the SwigType table, with a #define DEBUG at the top of
Source/Swig/typesys.c
When run you get an output like this:
---r_mangled---
Hash {
'_p_Bar' : Hash {
'p.Bar' : _p_Bar,
}
,
'_p_DerFoo' : Hash {
'p.DerFoo' : _p_DerFoo,
}
,
'_p_Foo' : Hash {
'r.Foo' : _p_Foo,
'p.Foo' : _p_Foo,
}
,
'_Foo' : Hash {
'Foo' : _Foo,
}
,
}
....
The last field ('_Foo') is an object type and caused the error.
It can be fixed either by checking all the calls to SwigType_remember()
and by checking the typemaps.
The typemap code also calls SwigType_remember(), if your typemaps
defined an object type, it will be added into the SwigType table.
its normally a
SWIG_ConvertPtr(....$descriptor...)
when it should have been a $&descriptor or $*descriptor
Commenting out all your object typemaps (and typecheck fns) may help
isolate it.
*/
#
%}

View file

@ -110,17 +110,13 @@
}
%}
/*%typemap(in,checkfn="SWIG_isptrtype") SWIGTYPE*,SWIGTYPE[]
%{$1=($1_ltype)SWIG_MustGetPtr(L,$input,$descriptor,0,$argnum,"$symname");%}
%typemap(in,checkfn="lua_isuserdata") SWIGTYPE&
%{$1=($1_ltype)SWIG_MustGetPtr(L,$input,$descriptor,0,$argnum,"$symname");%}
*/
// out is simple
%typemap(out) SWIGTYPE*,SWIGTYPE&
%{SWIG_NewPointerObj(L,$1,$descriptor,$owner); SWIG_arg++; %}
// dynamic casts
// this uses the SWIG_TypeDynamicCast() which relies on RTTI to find out what the pointer really is
// the we return it as the correct type
%typemap(out) SWIGTYPE *DYNAMIC,
SWIGTYPE &DYNAMIC
{
@ -130,12 +126,12 @@
// passing objects by value
// SWIG expects the object pointer (the $&ltype argp)
// SWIG_ConvertPtr wants an object pointer (the $&ltype argp)
// then dereferences it to get the object
%typemap(in,checkfn="lua_isuserdata") SWIGTYPE ($&ltype argp)
%{
if (!SWIG_IsOK(SWIG_ConvertPtr(L,$input,(void**)&argp,$&descriptor,0))){
SWIG_fail_ptr("$symname",$argnum,$descriptor);
SWIG_fail_ptr("$symname",$argnum,$&descriptor);
}
$1 = *argp;
%}
@ -143,7 +139,7 @@
// Primitive types--return by value
// must make a new object, copy the data & return the new object
// Note: the brackets are {...} and not %{..%}, because we want them to be included in the wrapper
// this is because out tpyemaps do not support local variables, like in typemaps do
// this is because typemap(out) does not support local variables, like in typemap(in) does
// and we need the $&1_ltype resultptr; to be declared
#ifdef __cplusplus
%typemap(out) SWIGTYPE
@ -251,7 +247,7 @@ parmeters match which function
}
}
%typecheck(SWIG_TYPECHECK_POINTER) SWIGTYPE, SWIGTYPE & {
%typecheck(SWIG_TYPECHECK_POINTER) SWIGTYPE & {
void *ptr;
if (lua_isuserdata(L,$input)==0 || SWIG_ConvertPtr(L,$input, (void **) &ptr, $1_descriptor, 0)) {
$1 = 0;
@ -260,6 +256,15 @@ parmeters match which function
}
}
%typecheck(SWIG_TYPECHECK_POINTER) SWIGTYPE {
void *ptr;
if (lua_isuserdata(L,$input)==0 || SWIG_ConvertPtr(L,$input, (void **) &ptr, $&1_descriptor, 0)) {
$1 = 0;
} else {
$1 = 1;
}
}
%typecheck(SWIG_TYPECHECK_VOIDPTR) void * {
void *ptr;
if (SWIG_isptrtype(L,$input)==0 || SWIG_ConvertPtr(L,$input, (void **) &ptr, 0, 0)) {
@ -314,7 +319,7 @@ SWIG_NUMBER_BY_CONST_REF(long long);
SWIG_NUMBER_BY_CONST_REF(signed long long);
SWIG_NUMBER_BY_CONST_REF(unsigned long long);
%apply const unsigned long & { const size_t & };
%apply const unsigned long & { const size_t & }; // size_t is the same as unsigned long
// Also needed for object ptrs by const ref