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.
Afficher les réponses par date
For completeness, here are the two conversion "opcode-"macros which I've forgotten to show in my previous mail:
#define ___BEGIN_CFUN_SV_to_string_SCMOBJ(svp, obj) \ if ((___err = gperl__SV_to_string_SCMOBJ(svp, &obj)) == ___FIX(___NO_ERR)) { #define ___END_CFUN_SV_to_string_SCMOBJ(svp, obj) }