Re: gauche-c-wrapper's cwcompile stopped working: function is not found

Jens Thiele <[email protected]> Mon, 29 Apr 2024 21:23:11 +0200
Newsgroups gmane.lisp.scheme.gauche
Message-ID <[email protected]>
Shiro Kawai <[email protected]> writes:

> Ok, I tried to reproduce it.

wow - thanks!

> I started from Debian source (original tarball and patches in
> https://packages.debian.org/buster/gauche-c-wrapper ), needed to fix a
> few places to compile recent Gauche.

Ah, I should have mentioned that I added some patches from Fabian Brosda
for arch linux to my local debian/bookworm packages.

s.a.:
https://aur.archlinux.org/packages/gauche-c-wrapper
https://www.karme.de/debian/pool/main/g/gauche-c-wrapper/

> But once it compiles, it seems to work with your example.

strange

> The error message you got is mysterious, for it is an error when
> dlsym() fails to find the symbol.

i will try to inspect this further

> Here's the changes I made.  The change of Scm_ReadStringLiteral() is
> to avoid conflict with Gauche API with the same name.
>
> =====
> diff --git a/gauche-c-wrapper-0.6.1.orig/src/c-ffi.c b/gauche-c-wrapper-0.6.1.updated/src/c-ffi.c
> index 5f99d6b..8b7834b 100644
> --- a/gauche-c-wrapper-0.6.1.orig/src/c-ffi.c
> +++ b/gauche-c-wrapper-0.6.1.updated/src/c-ffi.c
> @@ -347,7 +347,7 @@ static ffi_type *ffi_type_of(ScmObj ctype)
>      }
>      sa = SCM_SLOT_ACCESSOR(SCM_CDR(p));
>      if (0 <= sa->slotNumber) {
> -        return SCM_FFI_TYPE_DATA(Scm_InstanceSlotRef(ctype, sa->slotNumber));
> +        return SCM_FFI_TYPE_DATA(Scm_InstanceSlotRef(ctype, sa->slotNumber, SCM_UNDEFINED));
>      } else {
>          Scm_Error("wrong slot number: %d", sa->slotNumber);
>      }

this is interesting as I have:
return SCM_FFI_TYPE_DATA(Scm_InstanceSlotRef(ctype, sa->slotNumber, NULL));
from:
https://aur.archlinux.org/cgit/aur.git/tree/16_gauche_0_9_11_compat.patch?h=gauche-c-wrapper

but changing it to SCM_UNDEFINED didn't help

> diff --git a/gauche-c-wrapper-0.6.1.orig/src/c-lex.c b/gauche-c-wrapper-0.6.1.updated/src/c-lex.c
> index 546a469..bab0a08 100644
> --- a/gauche-c-wrapper-0.6.1.orig/src/c-lex.c
> +++ b/gauche-c-wrapper-0.6.1.updated/src/c-lex.c
> @@ -992,7 +992,7 @@ static ScmObj read_character_constant()
>      SCM_RETURN(Scm_MakeInteger(v));
>  }
>  
> -ScmObj Scm_ReadStringLiteral()
> +ScmObj Scm_ReadCStringLiteral()
>  {
>      SCM_RETURN(read_string_literal());
>  }
> diff --git a/gauche-c-wrapper-0.6.1.orig/src/c-lex.h b/gauche-c-wrapper-0.6.1.updated/src/c-lex.h
> index 47b3f15..3ce93fc 100644
> --- a/gauche-c-wrapper-0.6.1.orig/src/c-lex.h
> +++ b/gauche-c-wrapper-0.6.1.updated/src/c-lex.h
> @@ -78,7 +78,7 @@ extern ScmObj Scm_IsForceIdentifierRef();
>  extern ScmObj Scm_IsForceIdentifierSet(ScmObj v);
>  extern ScmObj Scm_ReadIdentifier(ScmObj l);
>  extern ScmObj Scm_ReadOperator(ScmObj c);
> -extern ScmObj Scm_ReadStringLiteral();
> +extern ScmObj Scm_ReadCStringLiteral();
>  extern ScmObj Scm_ReadCharacterConstant();
>  extern ScmObj Scm_ReadOctalOrFlonum(ScmObj l);
>  extern ScmObj Scm_ReadDecimal(ScmObj l);

this is basically identical to 
https://aur.archlinux.org/cgit/aur.git/tree/17_gauche_0_9_13_compat.patch?h=gauche-c-wrapper

> diff --git a/gauche-c-wrapper-0.6.1.orig/src/c-lexlib.stub b/gauche-c-wrapper-0.6.1.updated/src/c-lexlib.stub
> index 4138274..c70d7ed 100644
> --- a/gauche-c-wrapper-0.6.1.orig/src/c-lexlib.stub
> +++ b/gauche-c-wrapper-0.6.1.updated/src/c-lexlib.stub
> @@ -40,7 +40,7 @@
>          "if (nptr == endptr) {"
>          "    SCM_RETURN(SCM_FALSE);"
>          "} else {"
> -        "    SCM_RETURN(Scm_MakeInteger64((ScmInt64) v));"
> +        "    SCM_RETURN(Scm_MakeInteger64((int64_t) v));"
>          "}"))
>  
>  (define-cproc strtod (nptr::<const-cstring>)
> @@ -137,7 +137,7 @@
>    (call "Scm_ReadOperator"))
>  
>  (define-cproc read-string-literal ()
> -  (call "Scm_ReadStringLiteral"))
> +  (call "Scm_ReadCStringLiteral"))
>  
>  (define-cproc read-character-constant ()
>    (call "Scm_ReadCharacterConstant"))
> diff --git a/gauche-c-wrapper-0.6.1.orig/src/c-parser.c b/gauche-c-wrapper-0.6.1.updated/src/c-parser.c
> index 08c39dd..d221d30 100644
> --- a/gauche-c-wrapper-0.6.1.orig/src/c-parser.c
> +++ b/gauche-c-wrapper-0.6.1.updated/src/c-parser.c
> @@ -1691,7 +1691,7 @@ ScmObj Scm_ParseMacroCode(ScmObj in, ScmObj macro_list)
>          /* skip lines starting with "# [0-9]+ <stdin>" and join with following line */
>          while (!SCM_EOFP(next_line_str)
>                 && (SCM_STRING_LENGTH(next_line_str) > 2)
> -               && SCM_REGMATCHP(Scm_RegExec(SCM_REGEXP(skip_regex), SCM_STRING(next_line_str)))) {
> +               && SCM_REGMATCHP(Scm_RegExec(SCM_REGEXP(skip_regex), SCM_STRING(next_line_str), SCM_UNDEFINED,
> SCM_UNDEFINED))) {
>              next_line_str = Scm_ReadLineUnsafe(SCM_PORT(in));
>              if (!SCM_EOFP(next_line_str)) {
>                  line_str = Scm_StringAppend2(SCM_STRING(line_str), SCM_STRING(next_line_str));

this is like
https://aur.archlinux.org/cgit/aur.git/tree/15_fix_scm_reg_exec.patch?h=gauche-c-wrapper

hmm
$ gosh ./test-libhello.scm
works

only
$ gosh -I. ./test-libhello.scm
doesn't

but this is caused by the first version not finding the
libgauche-hello.so and then falling back to normal operation
(without cwcompiled library)

will have to dig further

jens