Re: [Chicken-users] c-string return question

2011-10-14 Thread Felix
My point is, that this code is valid wrt. the manual and apparently valid given my understanding of what the C code tries to do: make it possible to return on stack strings. Can you point out the relevant manual section? For me it ends up like this: --- #define return(x)

Re: [Chicken-users] c-string return question

2011-10-14 Thread Jörg F . Wittenberger
Sorry JohnFelix, I must have been overworked. Some sleep already made me aware that the memory in question is indeed clobbered. The c-pointer section in the FFI manual is just not clear about that. (And somehow I must have convinced myself that C_mpointer would already copy out the memory,

[Chicken-users] c-string return question

2011-10-13 Thread Jörg F . Wittenberger
Hi, ages ago I wrote these simple lines: (define integer-utf8string (foreign-lambda* c-string ((unsigned-integer ch)) static C_uchar off[6]={0xFC,0xF8,0xF0,0xE0,0xC0,0x00}; int size=5; C_uchar buf[7]; buf[6]='\\0'; if (ch 0x80) { buf[5]=ch; } else { buf[size--]=(ch0x3F)|0x80;

Re: [Chicken-users] c-string return question

2011-10-13 Thread John Cowan
Jörg F. Wittenberger scripsit: (define integer-utf8string (foreign-lambda* c-string ((unsigned-integer ch)) static C_uchar off[6]={0xFC,0xF8,0xF0,0xE0,0xC0,0x00}; int size=5; C_uchar buf[7]; buf[6]='\\0'; if (ch 0x80) { buf[5]=ch; } else { buf[size--]=(ch0x3F)|0x80;

Re: [Chicken-users] c-string return question

2011-10-13 Thread Jörg F . Wittenberger
On Oct 13 2011, John Cowan wrote: Jörg F. Wittenberger scripsit: (define integer-utf8string (foreign-lambda* c-string ((unsigned-integer ch)) static C_uchar off[6]={0xFC,0xF8,0xF0,0xE0,0xC0,0x00}; int size=5; C_uchar buf[7]; buf[6]='\\0'; if (ch 0x80) { buf[5]=ch; } else {

Re: [Chicken-users] c-string return question

2011-10-13 Thread Jim Ursetto
On Oct 13, 2011, at 11:02 AM, Jörg F. Wittenberger wrote: ages ago I wrote these simple lines: Out of curiosity, would this suit your purposes instead: (##sys#char-utf8-string (integer-char x)) ___ Chicken-users mailing list Chicken-users@nongnu.org

Re: [Chicken-users] c-string return question

2011-10-13 Thread Jörg F . Wittenberger
On Oct 13 2011, Jörg F. Wittenberger wrote: Recently this code begin to return garbage under gcc 4.4.5 on amd64 and ARM, though more reliable on ARM. I forgot some marginal thing you might want to know just in case: With gcc 4.4.5 (as in current debian stable) you really, really don't want to

Re: [Chicken-users] c-string return question

2011-10-13 Thread Alan Post
On Thu, Oct 13, 2011 at 07:24:12PM +0200, Jörg F. Wittenberger wrote: IMHO the moral of the story: Never trust you C compiler too much. I've had to get more familiar with gcc's -f flag, as the years have gone by. '-fno-strict-aliasing' is one that I've personally needed (and chicken requires

Re: [Chicken-users] c-string return question

2011-10-13 Thread Jörg F . Wittenberger
On Oct 13 2011, Jim Ursetto wrote: On Oct 13, 2011, at 11:02 AM, Jörg F. Wittenberger wrote: ages ago I wrote these simple lines: Out of curiosity, would this suit your purposes instead: (##sys#char-utf8-string (integer-char x)) Looks good. I did not notice that this made it into the

Re: [Chicken-users] c-string return question

2011-10-13 Thread John Cowan
Jörg F. Wittenberger scripsit: (Watch out for C_cblock and C_cblockend #defines in chicken.h , which depend on the C compiler in use.) Normally, they are ({ and }) respectively, the GNU C extension for statement expressions (see http://gcc.gnu.org/onlinedocs/gcc/Statement-Exprs.html ). In C++

Re: [Chicken-users] c-string return question

2011-10-13 Thread Alan Post
On Thu, Oct 13, 2011 at 02:07:04PM -0400, John Cowan wrote: Jörg F. Wittenberger scripsit: So I'll stick with the test case and remove the static keyword from the buffer definition once I have an updated gcc in my production environment. Program testing can be used to show the presence

Re: [Chicken-users] c-string return question

2011-10-13 Thread John Cowan
Alan Post scripsit: It does make the routine non-reentrant. Does that matter here? I don't see how. This routine is called from Chicken, and the string gets copied into a Chicken string right away. I suppose you might want to shut off interrupts. -- John Cowanhttp://ccil.org/~cowan

Re: [Chicken-users] c-string return question

2011-10-13 Thread Alan Post
On Thu, Oct 13, 2011 at 02:46:30PM -0400, John Cowan wrote: Alan Post scripsit: It does make the routine non-reentrant. Does that matter here? I don't see how. This routine is called from Chicken, and the string gets copied into a Chicken string right away. I suppose you might want

Re: [Chicken-users] c-string return question

2011-10-13 Thread Jörg F . Wittenberger
John, it's not my intention to argue about the merits of the way the foreign-lambda* I posted has been written. (If I had to do so, I would argue that using a dynamic buf would be better style. Less sensible to being [re]used in a multi threaded or reentrant environment.) My point is, that

Re: [Chicken-users] c-string return question

2011-10-13 Thread Jörg F . Wittenberger
On Oct 13 2011, John Cowan wrote: Jörg F. Wittenberger scripsit: So I'll stick with the test case and remove the static keyword from the buffer definition once I have an updated gcc in my production environment. Program testing can be used to show the presence of bugs, but never to show

Re: [Chicken-users] c-string return question

2011-10-13 Thread Jörg F . Wittenberger
On Oct 13 2011, John Cowan wrote: Alan Post scripsit: It does make the routine non-reentrant. Does that matter here? I don't see how. This routine is called from Chicken, and the string gets copied into a Chicken string right away. I suppose you might want to shut off interrupts.

Re: [Chicken-users] c-string return question

2011-10-13 Thread Jörg F . Wittenberger
On Oct 13 2011, Alan Post wrote: On Thu, Oct 13, 2011 at 02:46:30PM -0400, John Cowan wrote: Alan Post scripsit: It does make the routine non-reentrant. Does that matter here? I don't see how. This routine is called from Chicken, and the string gets copied into a Chicken string right