Subject: [clisp-list] about a regexp module (was: FFI: variable size values)

From: "Hoehle, Joerg-Cyril" <[email-masked]>
Date: Wed Aug 6 03:40:06 2003

Hi,

>> BTW, the current CLISP regexp module arbitrarily limits the return to
>> 10 group positions ("num-matches"), because it does not consider the
>> re_nsub slot out off the regex_t structure.
>> 
>> This is a case where I'd recommend a little C wrapper code to make
>> interfacing easier. I very much prefer this over duplicating the
>> regex_t structure in Lisp via (FFI:C-STRUCT <many slots>). I don't
>> want to have to maintain this by hand, whereas the C wrapper would
>> always stay in sync with the C regex.h header by mere recompilation.
>
>interesting.
>so this wrapper will allocate the array of regmatch_t structs of the
>necessary size and return a pointer to it.
>who and when will release it?
Who and when to release stuff is to be defined.
It could be the :malloc-free protocol.
It could be the caller who allocates and frees.

But that's not what I had in mind. Just a really tiny wrapper.
LISPFUNN(regex_nsub,1)
{ var object obj = popSTACK();
  check_foreign_pointer(obj);
  var void* re = TheFpointer(obj);
  VALUES1(ULtoI(((regex_t*)re)->re_nsub));
} -- as part of an external module
or
size_t re_nsubs(struct regex_t *preg) { return re->re_nsub;
} -- requiring FFI to interface
and do the rest in Lisp.

Your approach is quite feasible as well. Indeed, I've always been in favour of thicker interfaces, which better match Lisp.

In this case, the wrapper could be around regexec, allocate regmatch_t[re->re_nsub] and return a Lisp array directly.
If I were to interface to regexp with the module interface rather than with the FFI (or an FFI module), that's what I'd do.

Once you know how to pushSTACK() etc. the CLISP stack machine, writing such interfaces is trivial to do -- Dan could comment on this. It may take more time than writing Lisp FFI code, but it works on all machines (FFI/ffcall has not been ported to all machines that CLISP runs on) and exhibits better performance than any FFI conversion and manipulation overhead.

Regards,
	Jorg.

---

From: Dan Stanger <[email-masked]>
Date: Wed Aug 6 05:12:02 2003

I wonder if SWIG could be modified to generate these wrappers.  It can handle Scheme now,
so maybe it wouldn't take much work.

"Hoehle, Joerg-Cyril" wrote:

> -------------------------------------------------------
> This SF.Net email sponsored by: Free pre-built ASP.NET sites including
> Data Reports, E-commerce, Portals, and Forums are available now.
> Download today and enter to win an XBOX or Visual Studio .NET.
> http://aspnet.click-url.com/go/psa00100003ave/direct;at.aspnet_072303_01/01
> _______________________________________________
> clisp-list mailing list
> [email-masked]
> https://lists.sourceforge.net/lists/listinfo/clisp-list

---

From: Sam Steingold <[email-masked]>
Date: Wed Aug 6 08:07:15 2003

OK, I removed this arbitrary num-matches limit.
I wonder if we _should_ discard the FFI in regexp altogether for
performance reasons...

there are just 4 functions in the API (and all of them now have C
wrappers!!), so this is not a big deal (as opposed to, say, hundreds of
functions in linux.lisp), and this is a big performance issue (as those
who use regexp are likely to call the regexec function a lot of times)

-- 
Sam Steingold (http://www.podval.org/~sds) running w2k
<http://www.camera.org> <http://www.iris.org.il> <http://www.memri.org/>
<http://www.mideasttruth.com/> <http://www.palestine-central.com/links.html>
When we write programs that "learn", it turns out we do and they don't.