unofficial mirror of bug-guile@gnu.org 
 help / color / mirror / Atom feed
* bug#31343: scm_c_primitive_load behavior/documentation bug
@ 2018-05-02 17:35 Tom Balzer
  2018-05-28 12:55 ` Mark H Weaver
  0 siblings, 1 reply; 2+ messages in thread
From: Tom Balzer @ 2018-05-02 17:35 UTC (permalink / raw)
  To: 31343


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





^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2018-05-28 12:55 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-05-02 17:35 bug#31343: scm_c_primitive_load behavior/documentation bug Tom Balzer
2018-05-28 12:55 ` Mark H Weaver

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).