[Top][All Lists]

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

Re: [Chicken-users] a couple of questions about foreign functions

From: Valentyn Kamyshenko
Subject: Re: [Chicken-users] a couple of questions about foreign functions
Date: Wed, 21 Jan 2004 23:52:38 -0800

On Jan 21, 2004, at 11:08 PM, Felix Winkelmann wrote:

Am Wed, 21 Jan 2004 20:05:34 -0800 hat Valentyn Kamyshenko <address@hidden> geschrieben:

- in the chicken code, the Scheme strings seem to be never created on
the stack. Are there particular reasons for this? I mean, is
smth. wrong with the following piece of code:

(foreign-lambda* scheme-object () #<<EOF
char buf[13+sizeof(C_header)];
memcpy(((C_SCHEME_BLOCK*)(void*)buf)->data, "Hello, world!", 13);

When this function returns, `buf' will point into a dead stack area,
so the data is likely to be corrupted after the return.

I suspected it!.

What makes the following code correct, then (have found it in runtime.c):

void C_decode_seconds(C_word c, C_word closure, C_word k, C_word secs, C_word mode)
  time_t tsecs;
  struct tm *tmt;
  C_word ab[ 11 ], *a = ab,

  tsecs = (time_t)C_unfix(secs);

  if(mode == C_SCHEME_FALSE) tmt = localtime(&tsecs);
  else tmt = gmtime(&tsecs);

  if(tmt  == NULL)
    C_kontinue(k, C_SCHEME_FALSE);

info = C_vector(&a, 10, C_fix(tmt->tm_sec), C_fix(tmt->tm_min), C_fix(tmt->tm_hour), C_fix(tmt->tm_mday), C_fix(tmt->tm_mon), C_fix(tmt->tm_year),
                  C_fix(tmt->tm_wday), C_fix(tmt->tm_yday),
                  tmt->tm_isdst > 0 ? C_SCHEME_TRUE : C_SCHEME_FALSE,
                 C_fix(timezone) );
  C_kontinue(k, info);

it looks like the vector is created on the stack, and then 'returned' to the continuation...


- can I call error routines from C code (that is, inside
foreign-lambda*, for example)?

If you mean error-routines that eventually invoke Scheme, then
you should use foreign-callback-lambda*. If you handle the
error in C (for example to display a message and exit), then
I see no problem.
I actually meant smth similar to ##sys#signal-hook (the hope was that there is C function that do the same).

Thank you for the answers!



reply via email to

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