[Top][All Lists]

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

[Chicken-users] c-string return question

From: Jörg F . Wittenberger
Subject: [Chicken-users] c-string return question
Date: 13 Oct 2011 18:02:45 +0200


ages ago I wrote these simple lines:

(define integer->utf8string
  c-string ((unsigned-integer ch))
  "static C_uchar off[6]={0xFC,0xF8,0xF0,0xE0,0xC0,0x00};
 int size=5; C_uchar buf[7];
 if (ch < 0x80) {
 } else {
   buf[size--]=(ch&0x3F)|0x80; ch=ch>>6;
   while (ch) { buf[size--]=(ch&0x3F)|0x80; ch=ch>>6; }
   /* Write the size information into the first byte */

this happend to work at least on i336 amd64 and ARM for years
every day.

Recently this code begin to return garbage under gcc 4.4.5
on amd64 and ARM, though more reliable on ARM.

However: no clear test case available:

When I write the above definition plus some test code
(define xx (integer->utf8string 160))
(display (char->integer (string-ref xx 0)))
into it's own file, I have so far been unable to make it return

It does return garbage I compile this code
as the only one foreign function together with the ssax parser
in it's own module (and link it into a larger program).

Maybe it's helpful to know how I escaped:
1.) static C_uchar buf[7];
   does the trick.

2.) AND so does adding a for-loop right before the return, which
   prints a hex output of "buf" to stderr!  (Instead of the static
   declaration.  So it's rather obvious a gcc issue.)

As far as I understand the C code into which Chicken expands this
function, I'd say: that one is correct.

Plus: so far I have gcc 4.5.2 on my dev machine.  There I never
have been able to reproduce this case.

MAybe it's helpful to know what can go wrong.

BEst Regards


reply via email to

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