Subject: [clisp-list] regexp-exec filters too much

From: "Hoehle, Joerg-Cyril" <[email-masked]>
Date: Mon Apr 15 00:58:05 2002

Hi,

Sam wrote:
> > I don't know if variable size arrays will ever be 
> > implemented for the FFI.
> I thought you were working on that!

I'm dreaming of
(def-c-call-out regexec
    (:arguments (preg (c-ptr regex_t))
                (string c-string)
                (nmatch size_t :in)
                (pmatch (c-ptr (c-array regmatch_t ,is_len(nmatch))) :out :alloca)
                (eflags int))
  (:return-type int))
but this is not yet within reach.
It's also broken (cf. my FFI-limits text). My current thoughts are along:

(def-c-call-out regexec
    (:arguments (preg (c-ptr regex_t))
                (string c-string)
                (nmatch size_t :in)
                (pmatch (c-ptr (c-array regmatch_t ,is_len(nmatch))) :out :alloca
			:guard (zerop result))
                (eflags int))
  (:return-type int))
I.e. the array is only returned when the function call returns success.

For now, I concentrate on more low-level (i.e. less declarative) variable-size stuff. This should be useful for UFFI as well.

> > b3) "100% better solution": revisit interface so as to not stupidly
> > impose NUM-MATCH=10 but obtain number of actual groups via
> > regexp-compile. Be dynamic!
> thanks.  are you sure you b3 is out of reach?
The above is 100% of course (or 150%)).

Another 100% good enough for regexp I've been thinking about is a cached
mapping from n in [0..] to foreign-function of
type (c-function (c-ptr (c-array regmatch_t ,n)) #)

(defun regexp-exec (compiled-pattern string)
 (let ((nsub (regexp-groups compiled-pattern)))
   (multiple-value-bind (errcode matches)
       (funcall (or (getf array nsub) (setf+extend array i)
                      (fcast #'regexec ;; fcast is in my hacks#1 file
               (ffi::parse-c-type
        ;; cf todays critique of default-foreign-language mail
        `(c-function (..... (c-ptr (c-array regmatch_t ,nsub)) )))
         compiled-pattern
         (1+ nsub))
      (if (zerop errcode) matches))))

That's as efficient as it can get. Presetting of cache array is of course possible at load-time.

Regards,
	Jorg Hohle.

---

From: Sam Steingold <[email-masked]>
Date: Tue Apr 16 07:35:21 2002

> * In message <[email-masked]>
> * On the subject of "[clisp-list] regexp-exec filters too much"
> * Sent on Mon, 15 Apr 2002 09:57:16 +0200
> * Honorable "Hoehle, Joerg-Cyril" <[email-masked]> writes:
>
> Sam wrote:

comma outside of backquote!

> I.e. the array is only returned when the function call returns success.

just allow
 (pmatch (c-ptr-null (c-array regmatch_t is_len(nmatch))) :out :alloca)
and you don't need to guard!
(just return NIL!)

-- 
Sam Steingold (http://www.podval.org/~sds) running RedHat7.2 GNU/Linux
Read, think and remember! <http://www.iris.org.il> <http://www.memri.org/>
<http://www.palestine-central.com/> <http://www.mideasttruth.com/>
Cannot handle the fatal error due to a fatal error in the fatal error handler.