bug-guile
[Top][All Lists]
Advanced

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

Weird scm_to_latin1_string() behavior.


From: David Hansen
Subject: Weird scm_to_latin1_string() behavior.
Date: Sat, 10 Sep 2011 03:33:27 +0200
User-agent: Gnus/5.110018 (No Gnus v0.18) Emacs/24.0.50 (gnu/linux)

Hello,

the attached code produces

$ ./a.out
foo,bar
bar

while I would expect

$ ./a.out
foo
bar

Similar behavior can be produced with `substring', but `substring/copy'
will work as expected.  So I suspect this is some issue with strings
sharing memory and a missing '0' when scm_to_latin1_string calls
scm_strdup.

David

#include <libguile.h>

/*
  This outputs:

  address@hidden ~/tmp $ ./a.out
  foo,bar
  bar

*/

static void
inner_main (void *data, int argc, char **argv)
{
  char *cstr;

  SCM string = scm_from_latin1_string ("foo,bar");
  SCM tokens = scm_string_split (string, SCM_MAKE_CHAR (','));
  SCM tok;

  for (tok = tokens; !scm_is_null (tok); tok = scm_cdr (tok))
    {
      cstr = scm_to_latin1_string (scm_car (tok));
      printf ("%s\n", cstr);
      free (cstr);
    }
}

int
main (int argc, char **argv)
{
  scm_boot_guile (argc, argv, inner_main, NULL);
}

/* Local Variables: */
/* compile-command: "gcc `pkg-config --cflags --libs guile-2.0` main.c" */
/* End: */

reply via email to

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