From: Tom Balzer <niebieskitrociny@gmail.com>
To: 31343@debbugs.gnu.org
Subject: bug#31343: scm_c_primitive_load behavior/documentation bug
Date: Wed, 02 May 2018 12:35:54 -0500 [thread overview]
Message-ID: <877eom2c63.fsf@gmail.com> (raw)
Hello -
In ./guile/libguile/load.c, the function scm_c_primitive_load converts a
c string to a SCM string via scm_from_locale_string. I was reading the
manual and in section 6.6.5.14, it says:
> C Function: SCM scm_from_locale_string (const char *str)
> C Function: SCM scm_from_locale_stringn (const char *str, size_t
>
> [...]
>
> Note that these functions should _not_ be used to convert C string
> constants, because there is no guarantee that the current locale
> will match that of the execution character set, used for string and
> character constants. Most modern C compilers use UTF-8 by default,
> so to convert C string constants we recommend
> ‘scm_from_utf8_string’.
This implies to me that you should not use scm_c_primitive_load with any
constant, like this:
#include <libguile.h>
#include <stdlib.h>
#define FILE "/home/niebie/sc/sdl/states.scm"
void *some_func(void *arg){
SCM scm_c_primitive_load(FILE);
return NULL;
}
int main(int argc, char **argv){
void *res = scm_with_guile(some_func, NULL);
return EXIT_SUCCESS;
}
I saw this only by reading the source for this function, as from the
documentation it isn't obvious. I am sending this to bug-guile because I
think that either this is a documentation bug or an implementation
bug. In either case I am happy to send a patch that fixes whichever is
at fault.
A counter example is scm_c_public_variable in modules.c, which uses
scm_from_utf8_symbol on the inputs, which precludes the use of dynamic c
strings for the input. Again, not something documented. I would think
both of these functions would do things the same way.
Thanks,
Tom
next reply other threads:[~2018-05-02 17:35 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-05-02 17:35 Tom Balzer [this message]
2018-05-28 12:55 ` bug#31343: scm_c_primitive_load behavior/documentation bug Mark H Weaver
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/guile/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=877eom2c63.fsf@gmail.com \
--to=niebieskitrociny@gmail.com \
--cc=31343@debbugs.gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).