I recently was informed that building the Perl binding for the Dazuko
library results in size mismatch warnings (pointers vs integers) on
64bit systems.  Here is a quick patch to cleanup how C pointers are
passed to Perl scripts and back.

An even better method would be to make use of "blessed pointers",
which would add automatic type verification on behalf of perlxs(1).
But since I consider the current implementation inappropriate anyway
(it "leaks" the library's internals into the Perl application), that
quick hack should do for now and a much improved version should
materialize RSN.  I have plans to cleanly encapsulate internals and to
adjust the API so that applications cannot "forget" to return access
events.  This should bring the Perl binding up to where the Python,
Ruby and Lua bindings currently are.


Please notice that some systems may insist in that all object files
which are used to build the IO.so shared library shall be built with
the -fPIC option.  So it may be necessary to run the follwing steps:

  $ tar xzf dazuko-<version>.tar.gz
  $ cd dazuko-<version>
  $ ./configure [ options ]
  $ vi library/Makefile
  maybe add "CFLAGS += -fPIC"
  $ make -C library
  $ cd example_perl
  $ perl Makefile.PL
  $ make
  # make test
  # make install
  # perl Example.pl `pwd`


virtually yours                                     Gerhard Sittig
pgp fingerprint AF29 3CD2 A531 F5A8 5F42  CB9A 1B7F 59F8 BA7A 9EE5
-- 
    If you don't understand or are scared by any of the above,
            ask your parents or an adult to help you.
patch against the Perl language binding for Dazuko to fix
an "integer vs pointer size mismatch" on 64bit systems

--- example_perl/IO.xs  21 Sep 2006 08:10:43 -0000      1.2
+++ example_perl/IO.xs  1 Aug 2007 08:54:25 -0000
@@ -112,7 +112,7 @@ PPCODE:
                /* otherwise return($acc, $deny, $event, ...) */
                undef = &PL_sv_undef;   /* shortcut */
                EXTEND(SP, 13);
-               PUSHs(sv_2mortal(newSViv((IV)acc)));
+               PUSHs(sv_2mortal(newSViv(PTR2IV(acc))));
                PUSHs(sv_2mortal(newSViv(acc->deny)));
                PUSHs(acc->set_event ? sv_2mortal(newSViv(acc->event)) : undef);
                PUSHs(acc->set_flags ? sv_2mortal(newSViv(acc->flags)) : undef);
@@ -130,12 +130,12 @@ PPCODE:
 
 int
 dazukoReturnAccess(ref, deny = 0)
-       int ref
+       IV ref
        int deny
 PREINIT:
        struct dazuko_access *acc;
 CODE:
-       acc = (struct dazuko_access *)ref;
+       acc = INT2PTR(struct dazuko_access *, ref);
        acc->deny = deny;
        RETVAL = dazukoReturnAccess(&acc);
 OUTPUT:
@@ -205,70 +205,70 @@ PPCODE:
        /* return $id if we succeeded to register */
        if (rc == 0) {
                EXTEND(SP, 1);
-               PUSHs(sv_2mortal(newSViv((IV)idp)));
+               PUSHs(sv_2mortal(newSViv(PTR2IV(idp))));
        }
 
 int
 dazukoUnregister_TS(id)
-       int id
+       IV id
 PREINIT:
        dazuko_id_t *idp;
 CODE:
-       idp = (dazuko_id_t *)id;
+       idp = INT2PTR(dazuko_id_t *, id);
        RETVAL = dazukoUnregister_TS(&idp);
 OUTPUT:
        RETVAL
 
 int
 dazukoSetAccessMask_TS(id, mask)
-       int id
+       IV id
        int mask
 PREINIT:
        dazuko_id_t *idp;
 CODE:
-       idp = (dazuko_id_t *)id;
+       idp = INT2PTR(dazuko_id_t *, id);
        RETVAL = dazukoSetAccessMask_TS(idp, mask);
 OUTPUT:
        RETVAL
 
 int
 dazukoAddIncludePath_TS(id, path)
-       int id
+       IV id
        char *path
 PREINIT:
        dazuko_id_t *idp;
 CODE:
-       idp = (dazuko_id_t *)id;
+       idp = INT2PTR(dazuko_id_t *, id);
        RETVAL = dazukoAddIncludePath_TS(idp, path);
 OUTPUT:
        RETVAL
 
 int
 dazukoAddExcludePath_TS(id, path)
-       int id
+       IV id
        char *path
 PREINIT:
        dazuko_id_t *idp;
 CODE:
-       idp = (dazuko_id_t *)id;
+       idp = INT2PTR(dazuko_id_t *, id);
        RETVAL = dazukoAddExcludePath_TS(idp, path);
 OUTPUT:
        RETVAL
 
 int
 dazukoRemoveAllPaths_TS(id)
-       int id
+       IV id
 PREINIT:
        dazuko_id_t *idp;
 CODE:
-       idp = (dazuko_id_t *)id;
+       idp = INT2PTR(dazuko_id_t *, id);
        RETVAL = dazukoRemoveAllPaths_TS(idp);
 OUTPUT:
        RETVAL
 
 void
 dazukoGetAccess_TS(id)
-       int id
+       IV id
 PREINIT:
        /*
         * this one needs some more attention -- it is not merely
@@ -281,7 +281,7 @@ PREINIT:
        int rc;
        SV *undef;
 PPCODE:
-       idp = (dazuko_id_t *)id;
+       idp = INT2PTR(dazuko_id_t *, id);
        /* place an "undef" as (default) RETVAL */
        ST(0) = sv_newmortal();
        /* invoke the C routine */
@@ -300,7 +300,7 @@ PPCODE:
                /* otherwise return($acc, $deny, $event, ...) */
                undef = &PL_sv_undef;   /* shortcut */
                EXTEND(SP, 13);
-               PUSHs(sv_2mortal(newSViv((IV)acc)));
+               PUSHs(sv_2mortal(newSViv(PTR2IV(acc))));
                PUSHs(sv_2mortal(newSViv(acc->deny)));
                PUSHs(acc->set_event ? sv_2mortal(newSViv(acc->event)) : undef);
                PUSHs(acc->set_flags ? sv_2mortal(newSViv(acc->flags)) : undef);
@@ -318,15 +318,15 @@ PPCODE:
 
 int
 dazukoReturnAccess_TS(id, ref, deny = 0)
-       int id
-       int ref
+       IV id
+       IV ref
        int deny
 PREINIT:
        dazuko_id_t *idp;
        struct dazuko_access *acc;
 CODE:
-       idp = (dazuko_id_t *)id;
-       acc = (struct dazuko_access *)ref;
+       idp = INT2PTR(dazuko_id_t *, id);
+       acc = INT2PTR(struct dazuko_access *, ref);
        acc->deny = deny;
        RETVAL = dazukoReturnAccess_TS(idp, &acc);
 OUTPUT:

_______________________________________________
Dazuko-devel mailing list
[email protected]
http://lists.nongnu.org/mailman/listinfo/dazuko-devel

Reply via email to