[gambit-list] refcounts and threads

Christian christian at pflanze.mine.nu
Fri Aug 19 13:54:00 EDT 2005


Hello

I've noticed that my perl interface leaked memory until I added a
___still_obj_refcount_dec call after allocation of a scheme
object. This is in code which converts a perl datastructure to a
scheme one; the resulting object is not used by C or perl code, only
by scheme. So since a newly allocated still object starts with a
refcount of 1, I have to decrement it again. I now do this immediately
after allocation, e.g.:

___SCMOBJ /* for ___err */
gperl__SV_to_string_SCMOBJ (SV *sv,
			    ___SCMOBJ* obj)
{
...
	result = ___alloc_scmobj (___sSTRING, n<<___LCS, ___STILL);
	___still_obj_refcount_dec(result);
        // now copy over perl string, then:
        *obj = result;
        return ___FIX(___NO_ERR);
}

I use the above from scheme like:

(c-define-type SV* (pointer "SV" SV* "gperl_release_sv"))
(c-define-type SV*->string "SV*" "SV_to_string_SCMOBJ" "NOTIMPLEMENTED" #f)
(define sv->string
  (c-lambda (SV*)
	    SV*->string
	    "___result=___arg1;"))

My question: is the above thread safe? Do I have to add (declare (not
interrupts-enabled)), like:

(define (sv->string sv)
  (declare (not interrupts-enabled))
  ((c-lambda (SV*)
	     SV*->string
	     "___result=___arg1;") sv))

Thanks
Christian.




More information about the Gambit-list mailing list