! here's the code that redefines pcre_malloc and pcre_free to ! use byte-arrays. this code is tested to work. I was in a ! brute-force trial-and-error frenzy trying all combinations ! of the alien functions to make this work, and couldn't. ! the suggestions I was offered at the irc channel also ! wouldn't work. so I got more rational and started thinking ! about how all the alien functions can work together. ! the result is a bit more repetitive than what I'd like to ! write to make this work, but it works and most importantly ! it makes perfect sense in my head and that of anyone who ! reads the docs for CALLBACK: C-GLOBAL: alien-callback and ! alien-indirect . No example in the docs mention this ! construct and I could not find an existing library that ! does this. maybe this is a first! CALLBACK: void* pcre_malloc_t ( size_t size ) ; C-GLOBAL: pcre_malloc_t pcre_malloc : setup-pcre_malloc ( -- ) void* { size_t } cdecl [ ] alien-callback set-pcre_malloc ; setup-pcre_malloc ! set it up once : pcre-malloc ( size -- ptr ) pcre_malloc void* { size_t } cdecl alien-indirect ; CALLBACK: void pcre_free_t ( void* ptr ) ; C-GLOBAL: pcre_free_t pcre_free : setup-pcre_free ( -- ) void { void* } cdecl [ drop ] alien-callback set-pcre_free ; setup-pcre_free ! set it up once : pcre-free ( ptr -- ) pcre_free void { void* } cdecl alien-indirect ; ! There are two ways to implicitly check that this is works. ! one is that calling (free) on what is returned from ! pcre-malloc crashes Factor in the same way that ! B{ 0 0 0 } (free) crashes it. ! the other way to verify it is by looking at the address ! of the returned alien. The code in the previous ! annotation always returns an alien like this: ! ALIEN: 7fdd8b0c80c0 ! while this code returns an alien like this: ! ALIEN: 110b1b570 ! which to me seem like two very different address spaces, ! and the latter I suspect is Factor's address space, ! although I couldn't get >c-ptr to work in order to verify ! this. ! this should be included in the docs somehow, as it took me ! a while to figure out and no-one in the IRC channel knew ! exactly how to go about it.