From: Daniel J. <dan...@gm...> - 2016-06-19 12:46:40
|
I'm currently working on the regexp module (I'm still here in case anyone wondered). I've a few questions / suggestions: I think it would be good to have regexp-exec fail when there are more matches than the number of possible return values and it was specified to return the matches as multiple values. Currently, regexp-exec then just returns the results as a list: // ... switch (rettype) { case ret_values: if (re_count < fixnum_to_V(Symbol_value(S(multiple_values_limit)))) { STACK_to_mv(re_count); break; } /* else FALLTHROUGH */ case ret_list: VALUES1(listof(re_count)); break; // ... This could lead to surprises, when e.g. calling: (multiple-value-list (match some-pattern some-string)) When match returns multiple values, one get's a list with the matches. But when - because of a different pattern - there are more matches then suddenly this returns a list with the list of matches, which could confuse code using the result. It's probably not that critical as one needs to have a pattern with 127 sub-expressions or more, though. Next, currently regex-compile returns a foreign-pointer, and regex-exec expects a foreign pointer. Thus I could supply regexp-exec with a foreign pointer acquire from some other function, resulting in undefined behavior (because regexp-exec blindly assumes it to be a regex_t * ). AFAIK the policy for CLISP is to not just crash on such errors. As solution, I'd wrap the foreign pointer in a (defstruct pattern pointer). Are there any objections against this? |