Hi Jon,

2014-03-17 21:57 GMT+01:00 Jon Harper <jon.harpe...@gmail.com>:
> Hi list,
> I am working with libyaml, a C library to parse yaml docs. Some libyaml
> functions give string results by malloc'ing memory and giving back pointers
> to those strings in a struct. They then require the caller to call a libyaml
> "destroy" function on the struct that frees the strings.
>
> I would like to make a deep copy of the manually managed struct to a garbage
> collected struct so that I can keep some data after I called the libyaml
> destroy function and not worry about freeing it. Does anyone know how to do
> this simply ?

Let me preface this by saying that I'm far from an expert neither on
libyaml or factor... But this is what I think I've figured out about
how alien memory management works.

What I think you are doing wrong is worrying to much about freeing the
memory you are allocating. The ?scalar-value word is only an
intermediate step in the doc parsing process. Since the yaml> words
body already is wrapped in a with-destructors block, and it is the
main entry point for your parser, you don't need to call
with-destructors anywhere else.

Just remember to pair every allocation (or resource acquisition) with a
&destructor word (which you already are doing) and factor should work
it out fine.


--
mvh/best regards Björn Lindqvist

------------------------------------------------------------------------------
Learn Graph Databases - Download FREE O'Reilly Book
"Graph Databases" is the definitive new guide to graph databases and their
applications. Written by three acclaimed leaders in the field,
this first edition is now available. Download your free book today!
http://p.sf.net/sfu/13534_NeoTech
_______________________________________________
Factor-talk mailing list
Factor-talk@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/factor-talk

Reply via email to