From: David Hansen <david.hansen@gmx.net>
To: bug-guile@gnu.org
Subject: Weird scm_to_latin1_string() behavior.
Date: Sat, 10 Sep 2011 03:33:27 +0200 [thread overview]
Message-ID: <877h5hji54.fsf@localhorst.mine.nu> (raw)
[-- Attachment #1: Type: text/plain, Size: 326 bytes --]
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
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: main.c --]
[-- Type: text/x-csrc, Size: 675 bytes --]
#include <libguile.h>
/*
This outputs:
dhansen@localhorst ~/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: */
next reply other threads:[~2011-09-10 1:33 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-09-10 1:33 David Hansen [this message]
2011-09-10 14:03 ` Weird scm_to_latin1_string() behavior Stefan Israelsson Tampe
2011-09-10 18:39 ` Andy Wingo
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=877h5hji54.fsf@localhorst.mine.nu \
--to=david.hansen@gmx.net \
--cc=bug-guile@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).