This is the mail archive of the guile@sourceware.cygnus.com mailing list for the Guile project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: SWIG (Was Re: Another const PATCH plus problems with gh_new_procedure)


On 9 Dec 1999, Lars Arvestad wrote:

> I think it is really cool that you have worked on a SWIG
> interface. The SWIG author (David Beazley?) will probably be happy
> about your patches. I remember that an early version of SWIG did in
> fact have Guile support. I believe he withdraw the support because of
> the volatile status of Guile rather than for political reasons or lack 
> of interest. 
> 
> Have you used GOOPS in this interface? I have not thought this
> through, but it seems as GOOPS could make a very pretty mapping from
> C/C++ structs/classes to Scheme objects. 

Ahem... This was no big deal, just a few patches to the (already mostly
working) guile support of SWIG1.1p5, which still is the latest stable
release.

It's not a lot of changes anyway, and the first 6 lines are even from 
Dave Beazley himself.

So what did I actually change:

Modules/guile.cxx:
* make the '$argnum' and '$arg' directives work (from Dave Beazley)
* use gh_new_procedure[0-5]_0 whenever possible, only for argument counts
  larger than 5 fall back to gh_new_procedure and cast the function 
  parameter to (SCM (*)(...)).
* for registering access functions for global variables use
  gh_new_procedure0_1.
SWIG/parser.y:
* allow string constants in %name directives, in order to allow other than
  C/C++ identifiers to name functions on the scheme level.

Anyway, since it's not that much, find the patches enclosed below.

Dirk Herrmann




--- ../SWIG1.1p5/Modules/guile.cxx      Tue Jul  8 07:15:10 1997
+++ Modules/guile.cxx   Thu Dec  9 17:04:01 1999
@@ -323,7 +323,12 @@
 
     if ((tm = typemap_lookup("in","guile",p->t,p->name,source,target))) {
       // Yep.  Use it instead of the default
-      fprintf(f_wrappers,"%s\n", tm);
+      String tmap = tm;
+      char argnum[8];
+      sprintf(argnum,"%d\0",i);
+      tmap.replace("$argnum",argnum);
+      tmap.replace("$arg",source);
+      fprintf(f_wrappers,"%s\n", tmap.get());
     } else {
       if (!p->t->is_pointer) {
         switch(p->t->type) {
@@ -488,8 +493,13 @@
   fprintf(f_wrappers,"}\n");
 
   // Now register the function
-  fprintf(f_init,"\t gh_new_procedure(\"%s\", _wrap_gscm_%s, %d, 0, 0);\n", 
-          iname, wname, pcount);
+  if (pcount <= 5) {
+      fprintf(f_init,"\t gh_new_procedure%d_0(\"%s\", _wrap_gscm_%s);\n", 
+             pcount, iname, wname);
+  } else {
+      fprintf(f_init,"\t gh_new_procedure(\"%s\", (SCM (*)(...))_wrap_gscm_%s, %d, 0, 0);\n", 
+             iname, wname, pcount);
+  };
 
   // Make a documentation entry for this
 
@@ -695,7 +705,7 @@
     
     // Now add symbol to the Guile interpreter
     
-    fprintf(f_init,"\t gh_new_procedure(\"%s\", %s, 0, 1, 0);\n",iname, var_name);
+    fprintf(f_init,"\t gh_new_procedure0_1(\"%s\", %s);\n",iname, var_name);
     
   } else {
     fprintf(stderr,"%s : Line %d. ** Warning. Unable to link with type %s (ignored).\n",



--- ../SWIG1.1p5/SWIG/parser.y  Sun Nov 23 16:27:49 1997
+++ SWIG/parser.y       Thu Dec  9 16:41:55 1999
@@ -564,7 +564,7 @@
 %type <pl>       parms ptail;
 %type <p>        parm parm_type;
 %type <tmparm>   typemap_parm tm_list tm_tail;
-%type <id>       pname cpptype base_specifier access_specifier typemap_name tm_method idstring;
+%type <id>       pname cpptype base_specifier access_specifier typemap_name tm_method idstring targetName;
 %type <type>     type opt_signed opt_unsigned strict_type;
 %type <decl>     declaration nested_decl;
 %type <ivalue>   stars cpp_const_expr;
@@ -847,7 +847,7 @@
               }
 
 /* New %name directive */
-               | NAME LPAREN ID RPAREN {
+               | NAME LPAREN targetName RPAREN {
                 if (allow) {
                      strcpy(yy_rename,$3);
                      Rename_true = 1;
@@ -3193,7 +3193,7 @@
 
 /* This is the new style rename */
 
-             | NAME LPAREN ID RPAREN {
+             | NAME LPAREN targetName RPAREN {
               if (allow) {
                 strcpy(yy_rename,$3);
                 Rename_true = 1;
@@ -3353,6 +3353,10 @@
                     
              }
               | SEMI { }
+              ;
+
+targetName    : ID { $$ = $1; }
+              | STRING { $$ = $1; }
               ;
 
 nested_decl   : declaration { $$ = $1;}


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]