Keep the old non-resolved type str and add the fully
resolved one if is needed. Add examples showing the problem with SWIG_TypeQuery and template+typedef and the old type str, and how it works now. git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk/SWIG@5704 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
parent
d3caa4eefc
commit
2a573e9a08
4 changed files with 58 additions and 15 deletions
|
|
@ -31,3 +31,15 @@ except:
|
|||
print g, "is not an instance"
|
||||
raise RuntimeError
|
||||
|
||||
|
||||
# the old large format
|
||||
if not SWIG_TypeQuery("vfncs::ArithUnaryFunction<vfncs::arith_traits<float,float>::argument_type,vfncs::arith_traits<float,float >::result_type > *"):
|
||||
raise RuntimeError
|
||||
|
||||
# the reduced format
|
||||
if not SWIG_TypeQuery("vfncs::ArithUnaryFunction<double,double> *"):
|
||||
raise RuntimeError
|
||||
|
||||
# this is a bad name
|
||||
if SWIG_TypeQuery("vfncs::ArithUnaryFunction<double,doublex> *"):
|
||||
raise RuntimeError
|
||||
|
|
|
|||
|
|
@ -171,3 +171,4 @@ namespace vfncs {
|
|||
|
||||
}
|
||||
|
||||
swig_type_info *SWIG_TypeQuery(const char* name);
|
||||
|
|
|
|||
|
|
@ -175,25 +175,41 @@ SWIG_TypeName(const swig_type_info *ty) {
|
|||
strncmp, but skipping ' '.
|
||||
*/
|
||||
static int
|
||||
SWIG_TypeNameComp(const char *name1, const char *name2) {
|
||||
register size_t s1 = strlen(name1);
|
||||
register size_t s2 = strlen(name2);
|
||||
register size_t i1 = 0;
|
||||
register size_t i2 = 0;
|
||||
for( ; (i1 < s1) && (i2 < s2); ++i1, ++i2) {
|
||||
while ((name1[i1] == ' ') && (i1 < s1)) ++i1;
|
||||
while ((name2[i2] == ' ') && (i2 < s2)) ++i2;
|
||||
if (name1[i1] != name2[i2]) return name1[i1] - name2[i2];
|
||||
SWIG_TypeNameComp(const char *f1, const char *l1,
|
||||
const char *f2, const char *l2) {
|
||||
for (;(f1 != l1) && (f2 != l2); ++f1, ++f2) {
|
||||
while ((*f1 == ' ') && (f1 != l1)) ++f1;
|
||||
while ((*f2 == ' ') && (f2 != l2)) ++f2;
|
||||
if (*f1 != *f2) return *f1 - *f2;
|
||||
}
|
||||
return (s1 - i1) - (s2 - i2);
|
||||
return (l1 - f1) - (l2 - f2);
|
||||
}
|
||||
|
||||
/*
|
||||
Check type equivalence in a name list like <name1>|<name2>|...
|
||||
*/
|
||||
static int
|
||||
SWIG_TypeEquiv(const char *nb, const char *tb) {
|
||||
int equiv = 0;
|
||||
const char* te = tb + strlen(tb);
|
||||
const char* ne = nb;
|
||||
while (!equiv && *ne) {
|
||||
for (nb = ne; *ne; ++ne) {
|
||||
if (*ne == '|') break;
|
||||
}
|
||||
equiv = SWIG_TypeNameComp(nb, ne, tb, te) == 0;
|
||||
if (*ne) ++ne;
|
||||
}
|
||||
return equiv;
|
||||
}
|
||||
|
||||
|
||||
/* Search for a swig_type_info structure */
|
||||
SWIGRUNTIME(swig_type_info *)
|
||||
SWIG_TypeQuery(const char *name) {
|
||||
swig_type_info *ty = swig_type_list;
|
||||
while (ty) {
|
||||
if (ty->str && (SWIG_TypeNameComp(name,ty->str) == 0)) return ty;
|
||||
if (ty->str && (SWIG_TypeEquiv(ty->str,name))) return ty;
|
||||
if (ty->name && (strcmp(name,ty->name) == 0)) return ty;
|
||||
ty = ty->prev;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1674,7 +1674,11 @@ SwigType_emit_type_table(File *f_forward, File *f_table) {
|
|||
while (ki.key) {
|
||||
List *el;
|
||||
Iterator ei;
|
||||
SwigType *ft;
|
||||
SwigType *lt;
|
||||
SwigType *rt;
|
||||
String *nt;
|
||||
String *ln;
|
||||
String *rn;
|
||||
const String *cd;
|
||||
|
||||
Printf(f_forward,"#define SWIGTYPE%s swig_types[%d] \n", ki.key, i);
|
||||
|
|
@ -1682,8 +1686,17 @@ SwigType_emit_type_table(File *f_forward, File *f_table) {
|
|||
|
||||
cd = SwigType_clientdata_collect(ki.key,0);
|
||||
if (!cd) cd = "0";
|
||||
ft = SwigType_typedef_resolve_all(Getattr(r_ltype,ki.key));
|
||||
Printv(types,"{\"", ki.key, "\", 0, \"",SwigType_str(ft,0),"\", ", cd, ", 0, 0, 0},", NIL);
|
||||
lt = Getattr(r_ltype,ki.key);
|
||||
rt = SwigType_typedef_resolve_all(lt);
|
||||
/* we save the original type and the fully resolved version */
|
||||
ln = SwigType_str(lt,0);
|
||||
rn = SwigType_str(rt,0);
|
||||
if (Strcmp(ln,rn) == 0) {
|
||||
nt = NewStringf("%s", ln);
|
||||
} else {
|
||||
nt = NewStringf("%s|%s", rn, ln);
|
||||
}
|
||||
Printv(types,"{\"", ki.key, "\", 0, \"",nt,"\", ", cd, ", 0, 0, 0},", NIL);
|
||||
el = SwigType_equivalent_mangle(ki.key,0,0);
|
||||
for (ei = First(el); ei.item; ei = Next(ei)) {
|
||||
String *ckey;
|
||||
|
|
@ -1698,7 +1711,8 @@ SwigType_emit_type_table(File *f_forward, File *f_table) {
|
|||
Delete(ckey);
|
||||
}
|
||||
Delete(el);
|
||||
Delete(ft);
|
||||
Delete(nt);
|
||||
Delete(rt);
|
||||
Printf(types,"{0, 0, 0, 0, 0, 0, 0}};\n");
|
||||
Printv(table, "_swigt_", ki.key, ", \n", NIL);
|
||||
ki = Next(ki);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue