fix for the typemap match option

git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk/SWIG@8108 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
Marcelo Matus 2005-12-28 07:52:55 +00:00
commit 88e6edcac3
7 changed files with 71 additions and 16 deletions

View file

@ -299,7 +299,11 @@ Version 1.3.28 (unreleased).
entire test-suite compiles fine with and without the
castmode.
Note2: the castmode disables the -fatdispatch option.
Note2: the cast mode can't be comnined with the fast
dispatch mode, ie, the -fastdispatch option has no effect
when the cast mode is selected. The penalties, however,
are minimum since the cast dispatch code is already based
in the same fast dispatch mechanism.
See the file overload_dispatch_cast_runme.py file for
new cases and examples.

View file

@ -189,7 +189,7 @@ typedef struct {
int implicitconv;
} PySwigClientData;
SWIGRUNTIME int
SWIGRUNTIMEINLINE int
SWIG_Python_CheckImplicit(swig_type_info *ty)
{
PySwigClientData *data = (PySwigClientData *)ty->clientdata;

View file

@ -37,7 +37,7 @@
$1 = ($1_ltype) buf;
$2 = ($2_ltype) size - 1;
}
%typemap(freearg,noblock=1) (TYPEMAP, SIZE) {
%typemap(freearg,noblock=1,match="in") (TYPEMAP, SIZE) {
if (alloc$argnum == SWIG_NEWOBJ) %delete_array(buf$argnum);
}
%enddef
@ -61,6 +61,7 @@
%typemap(in,noblock=1,numinputs=0) TYPEMAP (Char temp[MAX+1]) {
$1 = ($1_ltype) temp;
}
%typemap(freearg,match="in") TYPEMAP "";
%typemap(argout,noblock=1,fragment= #SWIG_FromCharPtr ) TYPEMAP {
$1[MAX] = 0;
%append_output(SWIG_FromCharPtr($1));
@ -86,6 +87,7 @@
%typemap(in,noblock=1,numinputs=0) TYPEMAP(Char temp[SIZE]) {
$1 = ($1_ltype) temp;
}
%typemap(freearg,match="in") TYPEMAP "";
%typemap(argout,noblock=1,fragment= #SWIG_FromCharPtrAndSize) TYPEMAP {
%append_output(SWIG_FromCharPtrAndSize($1,SIZE));
}
@ -121,6 +123,7 @@
temp[n - 1] = 0;
$1 = ($1_ltype) temp;
}
%typemap(freearg,match="in") TYPEMAP "";
%typemap(argout,noblock=1,fragment=#SWIG_FromCharPtr) TYPEMAP {
$1[MAX] = 0;
%append_output(SWIG_FromCharPtr($1));
@ -158,6 +161,7 @@
if (alloc == SWIG_NEWOBJ) %delete_array(t);
$1[n-1] = 0;
}
%typemap(freearg,match="in") TYPEMAP "";
%typemap(argout,noblock=1,fragment=#SWIG_FromCharPtr) TYPEMAP {
%append_output(SWIG_FromCharPtr($1));
%delete_array($1);
@ -185,7 +189,7 @@
$2 = %numeric_cast(size, $2_ltype);
$1 = %static_cast(buff,$1_ltype);
}
%typemap(freearg,noblock=1) (TYPEMAP,SIZE) {
%typemap(freearg,noblock=1,match="in") (TYPEMAP,SIZE) {
if (buff$argnum) %delete_array(buff$argnum);
}
%typemap(argout,noblock=1,fragment=#SWIG_FromCharPtr) (TYPEMAP,SIZE) {
@ -216,7 +220,7 @@
size = %numeric_cast(n,$*2_ltype);
$2 = &size;
}
%typemap(freearg,noblock=1)(TYPEMAP,SIZE) {
%typemap(freearg,noblock=1,match="in")(TYPEMAP,SIZE) {
if (buff$argnum) %delete_array(buff$argnum);
}
%typemap(argout,noblock=1,fragment=#SWIG_FromCharPtrAndSize) (TYPEMAP,SIZE) {
@ -242,6 +246,7 @@
%typemap(in,noblock=1,numinputs=0) TYPEMAP($*1_ltype temp = 0) {
$1 = &temp;
}
%typemap(freearg,match="in") TYPEMAP "";
%typemap(argout,noblock=1,fragment=#SWIG_FromCharPtr) TYPEMAP {
if (*$1) {
%append_output(SWIG_FromCharPtr(*$1));
@ -269,6 +274,7 @@
%typemap(in,noblock=1,numinputs=0) (TYPEMAP, SIZE) ($*1_ltype temp = 0, $*2_ltype tempn) {
$1 = &temp; $2 = &tempn;
}
%typemap(freearg,match="in") (TYPEMAP,SIZE) "";
%typemap(argout,noblock=1,fragment=#SWIG_FromCharPtrAndSize)(TYPEMAP,SIZE) {
if (*$1) {
%append_output(SWIG_FromCharPtrAndSize(*$1,*$2));

View file

@ -422,7 +422,7 @@
$1 = %static_cast(buf, $1_ltype);
$2 = %numeric_cast(size, $2_ltype);
}
%typemap(freearg, noblock=1,match="in") (Char *STRING, size_t SIZE) {
%typemap(freearg,noblock=1,match="in") (Char *STRING, size_t SIZE) {
if (alloc$argnum == SWIG_NEWOBJ) %delete_array(buf$argnum);
}
/* old 'int' form */

View file

@ -9,6 +9,7 @@
}
$1 = %reinterpret_cast(argp, $ltype);
}
%typemap(freearg) SWIGTYPE * "";
%typemap(in, noblock=1) SWIGTYPE [] (void *argp = 0) {
if (!SWIG_IsOK(SWIG_ConvertPtr($input, &argp,$descriptor, $disown | %convertptr_flags))) {
@ -16,6 +17,7 @@
}
$1 = %reinterpret_cast(argp, $ltype);
}
%typemap(freearg) SWIGTYPE [] "";
%typemap(in, noblock=1) SWIGTYPE* const& (void *argp = 0, $*ltype temp) {
@ -25,6 +27,7 @@
temp = %reinterpret_cast(argp, $*ltype);
$1 = &temp;
}
%typemap(freearg) SWIGTYPE* const& "";
/* Reference */
@ -35,8 +38,10 @@
if (!argp) { %argument_nullref("$type", $argnum); }
$1 = %reinterpret_cast(argp, $ltype);
}
%typemap(freearg) SWIGTYPE & "";
#if defined(__cplusplus) && defined(%implicitconv_flag)
%typemap(in, noblock=1,implicitconv=1) const SWIGTYPE & (void *argp = 0, int res) {
%typemap(in,implicitconv=1) const SWIGTYPE & (void *argp = 0, int res) {
res = SWIG_ConvertPtr($input, &argp, $descriptor, %convertptr_flags | %implicitconv_flag);
if (!SWIG_IsOK(res)) {
%argument_fail(SWIG_TypeError, "$type", $argnum);
@ -44,7 +49,7 @@
if (!argp) { %argument_nullref("$type", $argnum); }
$1 = %reinterpret_cast(argp, $ltype);
}
%typemap(freearg,noblock=1,match="in") const SWIGTYPE &
%typemap(freearg,noblock=1,match="in",implicitconv=1) const SWIGTYPE &
{
if (SWIG_IsNewObj(res$argnum)) %delete($1);
}
@ -87,6 +92,7 @@
$1 = *(%reinterpret_cast(argp, $&ltype));
}
}
%typemap(freearg) SWIGTYPE "";
#endif
/* -----------------------------------------------------------------------------

View file

@ -1404,7 +1404,7 @@ public:
const char *get_implicitconv_flag(Node *klass)
{
int conv = 0;
if (klass && Getattr(klass,"feature:implicitconv")) {
if (klass && GetFlag(klass,"feature:implicitconv")) {
conv = 1;
}
return conv ? "SWIG_POINTER_IMPLICIT_CONV" : "0";
@ -1537,9 +1537,12 @@ public:
if (constructor && num_arguments == 1 && num_required == 1) {
if (Cmp(storage,"explicit") == 0) {
String *desc = NewStringf("SWIGTYPE%s", SwigType_manglestr(Getattr(n,"type")));
Printf(f->code, "if (SWIG_CheckImplicit(%s)) SWIG_fail;\n", desc);
Delete(desc);
Node *parent = Swig_methodclass(n);
if (GetFlag(parent,"feature:implicitconv")) {
String *desc = NewStringf("SWIGTYPE%s", SwigType_manglestr(Getattr(n,"type")));
Printf(f->code, "if (SWIG_CheckImplicit(%s)) SWIG_fail;\n", desc);
Delete(desc);
}
}
}
@ -1703,9 +1706,19 @@ public:
/* Insert cleanup code */
for (p = l; p;) {
if (!checkAttribute(p,"tmap:in:numinputs","0") &&
!Getattr(p,"tmap:in:parse") && (tm = Getattr(p,"tmap:freearg"))) {
if (Len(tm) != 0) {
if (!checkAttribute(p,"tmap:in:numinputs","0") && !Getattr(p,"tmap:in:parse")) {
tm = Getattr(p,"tmap:freearg");
if (Getattr(p,"tmap:freearg:implicitconv")) {
const char *convflag = "0";
if (!Getattr(p,"self")) {
SwigType *ptype = Getattr(p,"type");
convflag = get_implicitconv_flag(classLookup(ptype));
}
tm = (strcmp(convflag,"0") != 0) ? Getattr(p,"tmap:freearg") : 0;
} else {
tm = Getattr(p,"tmap:freearg");
}
if (tm && (Len(tm) != 0)) {
Replaceall(tm,"$source",Getattr(p,"lname"));
Printv(cleanup,tm,"\n",NIL);
}

View file

@ -1421,6 +1421,9 @@ Swig_typemap_attach_kwargs(Hash *tm, const String_or_char *op, Parm *p) {
Delete(value);
kw = nextSibling(kw);
}
Clear(temp);
Printf(temp,"%s:match_type",op);
Setattr(p,tmop_name(temp),Getattr(tm,k_type));
Delete(temp);
}
@ -1507,8 +1510,31 @@ Swig_typemap_attach_parms(const String_or_char *op, ParmList *parms, Wrapper *f)
if (kwmatch) {
String *tmname = NewStringf("tmap:%s",kwmatch);
Hash *tmin = Getattr(p,tmname);
if (!tmin || !Equal(Getattr(tmin,k_type),Getattr(tm,k_type))) {
if (tmin) {
SwigType *typetm = Getattr(tm,k_type);
SwigType *typein = Getattr(tmin,k_type);
if (!typein) {
String *temp = NewStringf("tmap:%s:match_type",kwmatch);
typein = Getattr(p,temp);
Delete(temp);
}
if (!typetm) {
Printf(stderr,"notm %s\n",tm);
}
if (!typein) {
Printf(stderr,"noin %s\n",tmin);
}
if (!Equal(typein,typetm)) {
Printf(stderr,"type in %s tm %s\n", typein, typetm);
p = nextSibling(p);
Delete(tmname);
continue;
}
} else {
p = nextSibling(p);
Delete(tmname);
continue;
}
Delete(tmname);