bug-guile
[Top][All Lists]
Advanced

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

Re: ‘scm_from_locale_string’ and locale character encoding


From: Bruce Korb
Subject: Re: ‘scm_from_locale_string’ and locale character encoding
Date: Mon, 18 Jul 2011 09:18:13 -0700
User-agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.18) Gecko/20110616 SUSE/3.1.11 Thunderbird/3.1.11

On 07/17/11 13:47, Ludovic Courtès wrote:
FWIW, I do understand the inconvenience and frustration reported here.

But as Andy suggests, I think it should come as no surprise that
‘scm_from_locale_string’ returns a string from a locale-encoded one.
Guile 1.8 already documented things this way [0].

The issue is less about scm_from_locale_string than:

* This appears to me to be habitual.  If it were not, my glue layer
  would not be so large.

* This is a behavioral change in a bug fix release.  The kind of
  change one might more readily anticipate in a 2.0.x to 2.1 transition.

* There was no warning mechanism put in place.  Release docs don't
  count because code I ship now will be built against Guile releases
  that have not been released yet.  I've not seen 2.0.2 even yet.

WRT the misuse of this particular function, what happened from
my perspective is that I was happily using the SCM_CHARS stuff with:
  export GUILE_WARN_DEPRECATED=detailed
in my testing environment and not getting any testing errors.
Then my clients report that they cannot build it any more.
(Why didn't the deprecation warning fire?  How about adding
GUILE_ERROR_DEPRECATED??  Then my testing should fail immediately!
In any event, I scan the test logs for "warn" and saw nothing.)
Somebody somewhere said, "use scm_from_locale_string".  I looked
it up and saw no better alternative, used it and it worked as I
needed it to.  Now it doesn't.

My biggest desire is to not have to read release documents and
figure out if somewhere in there is something that affects
my usage of the guile library interface.  I want to be thumped
with GUILE_WARN_DEPRECATED and have an obvious replacement.
Thank you.


/**
 *  Get the NUL terminated string from an SCM.
 *  As of Guile 1.7.x, access to the NUL terminated string referenced by
 *  an SCM is no longer guaranteed.  Therefore, we must extract the string
 *  into one of our "scribble" buffers.
 *
 * @param  s     the string to convert
 * @param  type  a string describing the string
 * @return a NUL terminated string, or it aborts.
 */
LOCAL char *
ag_scm2zchars(SCM s, const char * type)
{
#if GUILE_VERSION < 107000  /* pre-Guile 1.7.x */

    if (! AG_SCM_STRING_P(s))
        AG_ABEND(aprf(zNotStr, type));

    if (SCM_SUBSTRP(s))
        s = scm_makfromstr(SCM_CHARS(s), SCM_LENGTH(s), 0);
    return SCM_CHARS(s);

#else
    static char const bad_val[] =
        "scm_string_length returned wrong value: %d != %d\n";
    size_t len;
    char * buf;

    if (! AG_SCM_STRING_P(s))
        AG_ABEND(aprf("%s is not a string", type));

    len = scm_c_string_length(s);
    if (len == 0) {
        static char z = NUL;
        return &z;
    }

    buf = ag_scribble(len+1);

    {
        size_t buflen = scm_to_locale_stringbuf(s, buf, len);
        if (buflen != len)
            AG_ABEND(aprf(bad_val, buflen, len));
    }

    buf[len] = NUL;
    return buf;
#endif
}



reply via email to

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