[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: GH replacement proposal (includes a bit of Unicode)

From: Paul Jarc
Subject: Re: GH replacement proposal (includes a bit of Unicode)
Date: Wed, 07 Apr 2004 11:04:47 -0400
User-agent: Gnus/5.110002 (No Gnus v0.2) Emacs/21.3 (gnu/linux)

Marius Vollmer <address@hidden> wrote:
> I have a partial proposal for making type conversions between Scheme
> and C easier.

Looks nice & clean.

>   - macro-free so that we can maintain binary compatibility easier

Well, macros don't cause problems as long as the underlying functions
(if any) also keep the same interface, right?  Has there been much
change of, or pressure to change, those interfaces with the current

> Then there is the error handling: the functions below do not take
> "subr" or "pos" arguments to indicate where the error has happened.  I
> don't think they are really needed and in any case only provides part
> of the backtrace.

I have some code that benefits from having the subr name in the
exception - in the case of 'system-error, it walks the stack to find
and report the call that failed, including arguments.

Nits to follow...

> * Conversion from Scheme to C
>     <type> scm_to_<type> (SCM val, ...);
> ("convert Scheme to <type>".)  When VAL is not representable as a
> <type> or additional constraints are not satisfied, an error is
> signalled.
>   - int scm_to_bool (SCM);
>   - int scm_is_true (SCM);
>     Return 0 when SCM is SCM_BOOL_F, else return 1.

That sounds good for scm_is_true, but maybe scm_to_bool should throw
an exception if given a value other than SCM_BOOL_[TF], for
consistency with other scm_to_* functions.

>  - SCM scm_is_bool (SCM val);
>   - SCM scm_is_integer (SCM val);

Those should return int, right?

>   - scm_t_intmax scm_to_signed_integer (SCM val,
>                                         scm_t_intmax min, scm_t_intmax max);
>   - scm_t_uintmax scm_to_unsigned_integer (SCM val, scm_t_uintmax max);

Wouldn't a min parameter sometimes be useful for unsigned values too?

>   - long scm_to_unicode (SCM ch);
>   - SCM  scm_from_unicode (long code);

long, or unsigned long?  Does Unicode need negative values?

>   - SCM scm_from_locale_string (unsigned char *str, ssize_t len);
>   Return a new Scheme string initialized with STR, a string encoded
>   according to the current locale.  When LEN is -1, STR must be
>   zero-terminated and its length is found that way.  Otherwise LEN
>   gives the length of STR.

Maybe it doesn't matter much, but len could be size_t, and (size_t)-1
could be the only special value, instead of losing a whole bit to

>   The heap should not be locked for long periods of time and no
>   calls to 'normal' libguile functions are allowed while it is
>   locked.

What happens if one is called anyway?  Exception, or undefined

>   - SCM scm_c_list_ref (SCM list, int idx);
>   - SCM scm_c_list_set (SCM list, int idx, SCM val);
>   - int scm_c_list_length (SCM list);

I'd suggest size_t instead of int.  Same for vectors.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]