[gambit-list] How to pass a Scheme string to a const char*?

Vok Vojwo ceving at gmail.com
Mon Nov 21 12:43:18 EST 2011

I have defined wrappers for openlog and syslog. The openlog function
requires an ident string. Whatever I pass to openlog does not survive
until a call to syslog. I have tried to protect the string with
##still-copy (with and without box/unbox) but it does not work. Here
is the example:

(define const-ident #f)

(define openlog
  (let ((openlog (c-lambda
                     (char-string int int)
    (lambda (ident option facility)
      (set! const-ident (box (##still-copy ident)))
      (openlog (unbox const-ident) option facility))))

(define syslog
  (let ((syslog (c-lambda
                    (int nonnull-char-string)
    (lambda (priority . args)
      (syslog priority (apply string-append args)))))

This program:

(define (main . args)
  (openlog "gambit" (+ LOG_NDELAY LOG_PID) LOG_USER)
  (syslog LOG_INFO "hello")

will generate random syslog tags:

Nov 21 17:58:49 sn-e0692 ��*#002[11621]: hello

What is the correct way to protect a string to be able to pass it to a
const char* argument?

More information about the Gambit-list mailing list