the foreign c-string type: what animal is that?
"Hoehle, Joerg-Cyril" <[email protected]> Wed, 3 Apr 2002 15:58:00 +0200
| Newsgroups | gmane.lisp.uffi.general |
|---|---|
| Message-ID | <[email protected]> |
Hi, c-string is a dangerous area. Witness this comment in a project where I participated, using CMUCL: ;; when I reported the :in-out c-string GC bug (1996), CMU thought it was ;; dangerous anyway and disabled :in-out c-string combination. ;; We work around the problem by not using DEF-ALIEN-ROUTINE and call ;; the function directly. ... (alien-funcall (extern-alien #) #) I'm looking for advice on this topic. I really have a problem with foreign/alien c-string types. (malloc 'c-string "abc") does in fact two allocations: 1. one for the pointer, since char* IS a pointer 2. one for the buffer contents This problem does not arise when allocating buffers directly: (malloc '(c-array character 13) "abcde...") like (malloc 'int -123456789) This is a fundamental difference! Any ideas greatly appreciated. I had the following idea. A malloc with initialization doesn't allocate a c-string (pointer object) and a buffer. Instead, it creates a foreign-variable of type (:array character <N>) where <N> is computed dynamically as (1+ (length init)). But I don't like exceptions to otherwise regular schemes. And it cannot handle malloc without initarg. Commens are highly appreciated, Jorg Hohle.