[plt-scheme] Question about _gcpointer and _cvector

From: Will M. Farr (wmfarr at gmail.com)
Date: Wed Nov 11 15:57:22 EST 2009

Hello all,

I have a question that (I think) the manual doesn't answer regarding the interaction between _gcpointer and _cvector in the foreign interface.  Suppose I have a C routine that uses the scheme_malloc_... functions to create an array of structs allocated under the control of the garbage collector.  Then I do the following in the FFI:

(define make-some-stuff 
  (get-ffi-obj 'make_some_stuff my-library
    (_fun (n-stuff : _ufixnum) -> (stuff-array _gcpointer) -> 
          (make-cvector* stuff-array _stuff-pointer n-stuff))))

Does the cvector object always know that the pointer it holds should be a _gcpointer? Suppose I change the _gcpointer above to _pointer (which would be a mistake, but understandable)---does the cvector notice?  What about if the memory is allocated using regular malloc, and I use _gcpointer above---is the new cvector vulnerable to the same memory bug that led to the creation of _gcpointer?  In short, does a cvector know about the _[gc]pointer status of the memory block it holds?

For the moment, these questions are academic (in that I have an interface like the above, and nothing seems to go wrong under many repetitions of allocation, use, and discard with interspersed (collect-garbage) calls), but since the bugs that required the introduction of _gcpointer were intermittent, I'm nervous.  


Posted on the users mailing list.