PERLUAFS: Modernize lang-specific swig typemaps 17/12517/2
authorAndrew Deason <adeason@sinenomine.net>
Fri, 10 Feb 2017 07:29:28 +0000 (01:29 -0600)
committerBenjamin Kaduk <kaduk@mit.edu>
Sat, 11 Feb 2017 00:08:24 +0000 (19:08 -0500)
Currently, our swig bindings for PERLUAFS define a couple of typemaps
like so:

    %typemap(in, numinputs=1, perl5) (char *READBUF, int LENGTH) {
        [...]
    }

Embedding the target language name in the typemap arguments is a very
old way of specifying what language the typemap is for; they were
removed after swig 1.1. With swig 3.0.x releases (and possibly
others), the specific combination of this deprecated syntax and some
other features we're using causes a segfault. That's clearly a bug in
swig, but we shouldn't be using the deprecated syntax anyway.

Update this to instead use preprocessor symbols to specify
language-specific typemaps (#ifdef SWIGPERL). We only actually define
these for perl right now, so make sure to throw an error if we're not
running for perl.

FIXES 134103

Change-Id: I14264a2dfada53d99413808ed5d60b79b1ee44f3
Reviewed-on: https://gerrit.openafs.org/12517
Tested-by: BuildBot <buildbot@rampaginggeek.com>
Reviewed-by: Michael Meffie <mmeffie@sinenomine.net>
Reviewed-by: Benjamin Kaduk <kaduk@mit.edu>

src/libuafs/ukernel_swig.i

index bf6ce41..94fc6d4 100644 (file)
@@ -16,8 +16,8 @@
  * For each language you want a binding for, there are two typemaps you
  * must define for that language, since SWIG does not handle them natively.
  * These are the 'in' typemap for READBUF and LENGTH, and the 'argout'
- * typemap for READBUF. Search this file for 'perl5' to see existing ones
- * for the Perl 5 bindings.
+ * typemap for READBUF. Search this file for 'SWIGPERL' to see existing ones
+ * for the Perl bindings.
  */
 
 %module "AFS::ukernel"
@@ -78,14 +78,15 @@ extern int uafs_Run(void);
  * (Reading in a binary buffer from e.g. uafs_write is already handled natively
  * by SWIG. Fancy that.)
  */
-%typemap(in, numinputs=1, perl5) (char *READBUF, int LENGTH) {
+#if defined(SWIGPERL)
+%typemap(in, numinputs=1) (char *READBUF, int LENGTH) {
     if (!SvIOK($input)) {
         SWIG_croak("expected an integer");
     }
     $2 = SvIV($input);
     Newx($1, $2, char);
 }
-%typemap(argout, numinputs=1, perl5) char *READBUF {
+%typemap(argout, numinputs=1) char *READBUF {
     /* some logic here copied from typemaps.i and/or SWIG itself, since I'm not
      * a perl dev */
 
@@ -105,6 +106,9 @@ extern int uafs_Run(void);
     Safefree($1);
     argvi++;
 }
+#else
+# error No READBUF typemap defined for the given language
+#endif
 
 extern int uafs_mkdir(char *path, int mode);
 extern int uafs_chdir(char *path);