This is the mail archive of the
guile@sourceware.cygnus.com
mailing list for the Guile project.
Re: Another const PATCH plus problems with gh_new_procedure
- To: Dirk Herrmann <dirk at ida dot ing dot tu-bs dot de>
- Subject: Re: Another const PATCH plus problems with gh_new_procedure
- From: "Greg J. Badros" <gjb at cs dot washington dot edu>
- Date: 09 Dec 1999 07:50:58 -0800
- Cc: Guile Mailing List <guile at sourceware dot cygnus dot com>
- References: <Pine.LNX.4.10.9912090956370.9178-100000@marvin.ida.ing.tu-bs.de>
Dirk Herrmann <dirk@ida.ing.tu-bs.de> writes:
> Since I'm using guile in combination with C++, the switch to the latest gcc
> requires to fix some constness problems. Thus I stumbled across the problems
> in my latest patch, and also across the following:
>
> diff -u -p -r1.21 gh.h
> --- gh.h 1999/11/19 18:16:19 1.21
> +++ gh.h 1999/12/09 08:58:04
> @@ -104,7 +104,7 @@ SCM gh_long2scm(long x);
> SCM gh_double2scm(double x);
> SCM gh_char2scm(char c);
> SCM gh_str2scm(char *s, int len);
> -SCM gh_str02scm(char *s);
> +SCM gh_str02scm(const char *s);
> void gh_set_substr(char *src, SCM dst, int start, int len);
> SCM gh_symbol2scm(const char *symbol_str);
> SCM gh_ints2scm(int *d, int n);
>
>
> diff -u -p -r1.23 gh_data.c
> --- gh_data.c 1999/11/19 18:16:19 1.23
> +++ gh_data.c 1999/12/09 08:58:04
> @@ -87,7 +87,7 @@ gh_str2scm (char *s, int len)
> return scm_makfromstr (s, len, 0);
> }
> SCM
> -gh_str02scm (char *s)
> +gh_str02scm (const char *s)
> {
> return scm_makfrom0str (s);
> }
Ok, I've got the above const-fixes in my working copy and will commit
them if no-one's beaten me to it.
> However, there appears another problem that is not easy to fix (at least for
> me), and for which I would like to ask people from the list for help:
>
> SWIG has generated the following code:
> gh_new_procedure("foo", _wrap_gscm_foo, 3, 0, 0);
> where _wrap_gscm_foo has the following prototype:
> SCM _wrap_gscm_foo(SCM s_0,SCM s_1,SCM s_2);
> Then the C++ compiler complains:
> ANSI C++ prohibits conversion from `(long int, long int, long int)' to `(...)'
>
> The reason is, that gh_new_procedure accepts any function as its second
> parameter: SCM (*fn)(), which basically means SCM (*fn)(...). However, for
> ANSI C++ it seems not to be allowed to pass a SCM (*fn)(SCM,SCM,SCM) as a
> parameter when a SCM (*fn)(...) is required.
>
> Wrapping include<gh.h> with extern "C" did not help.
>
> Any ideas for a solution?
In scwm-snarf.h, I force scwm_make_gsubr to cast the function argument
to (SCM (*)(...)) when it expands the registration of the procedure. I
did the same thing for guile's snarf.h and that works for SCM_PROC
macros. You could make SWIG generate the cast in the call to
gh_new_procedure. I don't think C++ has any way to turn off that
argument checking globallly-- I believe each invocation needs the cast
since it is relying on the undefined (but well-supported) "feature" that
the two function pointers look the same in memory.
Greg