logo       

Re: Typedefs of template instantiations not recognized properly?: msg#00140

programming.swig

Subject: Re: Typedefs of template instantiations not recognized properly?

Zachary Pincus wrote:

I get the following error:
Type error. Got _p_std__vectorTA__OpaqueType_t, expected _p_A__OpaqueVectorType

That is, the wrapper code doesn't realize that std::vector<OpaqueType> and A::OpaqueVectorType are the same thing!

I can't really figure out if the problem is due to the template mechanism, the typedef mechanism, or throwing namespaces into the mix. (It doesn't matter whether the %template line is above or below the namespace definition.)

Any thoughts? Is this a known issue? Am I just doing something wrong?
Basically, is there anything I can do, short or find/replace on the interface files to get rid of the need for the typedefs?

I had a very similar problem with partial specialization, and created the attached patch. (Hopefully it will apply cleanly; it's actually in the middle of a series of patches I have applied to my swig 1.3.21.) When looking for a matching template, it tries matching both the unqualified name you provided and the namespace-qualified name. Note that I don't really understand what I'm doing here, but it works for me.


Index: Source/CParse/templ.c
===================================================================
RCS file: /usr/local/cvs/Imports/SWIG-1.3.21/Source/CParse/templ.c,v
retrieving revision 1.1
diff -u -u -r1.1 templ.c
--- Source/CParse/templ.c 19 May 2004 19:11:27 -0000 1.1
+++ Source/CParse/templ.c 24 May 2004 17:17:03 -0000
@@ -387,7 +387,7 @@
Node *
Swig_cparse_template_locate(String *name, Parm *tparms) {
Node *n;
- String *tname, *rname = 0;
+ String *tname, *qualname, *rname = 0;
Node *templ;
List *mpartials = 0;
Parm *p;
@@ -415,24 +415,27 @@

/* Search for an exact specialization.
Example: template<> class name<int> { ... } */
- {
- if (template_debug) {
- Printf(stdout," searching: '%s' (exact specialization)\n", tname);
- }
- n = Swig_symbol_clookup_local(tname,0);
- if (n) {
- Node *tn;
- if (Strcmp(nodeType(n),"template") == 0) goto success;
- tn = Getattr(n,"template");
- if (tn) {
- n = tn;
- goto success; /* Previously wrapped by a template return that */
- }
- Swig_error(cparse_file, cparse_line, "'%s' is not defined as a
template. (%s)\n", name, nodeType(n));
- Delete(tname);
- Delete(parms);
- return 0; /* Found a match, but it's not a template of any
kind. */
- }
+ if (template_debug) {
+ Printf(stdout," searching: '%s' (exact specialization)\n", tname);
+ }
+ n = Swig_symbol_clookup_local(tname,0);
+ qualname = Copy(Swig_symbol_getscopename());
+ Append(qualname, "::");
+ Append(qualname, tname);
+ if (!n) n = Swig_symbol_clookup_local(qualname,0);
+ if (n) {
+ Node *tn;
+ if (Strcmp(nodeType(n),"template") == 0) goto success;
+ tn = Getattr(n,"template");
+ if (tn) {
+ n = tn;
+ goto success; /* Previously wrapped by a template return that */
+ }
+ Swig_error(cparse_file, cparse_line, "'%s' is not defined as a template.
(%s)\n", name, nodeType(n));
+ Delete(tname);
+ Delete(parms);
+ Delete(qualname);
+ return 0; /* Found a match, but it's not a template of any kind. */
}

/* Search for generic template */
@@ -499,8 +502,11 @@
}
if (template_debug) {
Printf(stdout," searching: '%s' (partial specialization -
%s)\n", ss, pi.item);
+ Printf(stdout," %s eq %s\n", ss, tname);
+ Printf(stdout," %s eq %s\n", ss, rname);
+ Printf(stdout," %s eq %s\n", ss, qualname);
}
- if ((Strcmp(ss,tname) == 0) || (Strcmp(ss,rname) == 0)) {
+ if ((Strcmp(ss,tname) == 0) || (Strcmp(ss,rname) == 0) ||
(Strcmp(ss,qualname) == 0)) {
Append(mpartials,pi.item);
}
Delete(ss);
@@ -535,6 +541,7 @@
success:
Delete(tname);
Delete(rname);
+ Delete(qualname);
Delete(mpartials);
if ((template_debug) && (n)) {
Printf(stdout,"Node: %x\n", n);
<Prev in Thread] Current Thread [Next in Thread>
Google Custom Search

News | FAQ | advertise