On Fri, Oct 27, 2017 at 11:19:48AM +0200, Thierry Fournier wrote:
> It is really sad because the Lua ensure that the final '\0' is set :-( Maybe
> it will be clever to add a function like regex_prepare_string which copy a
> const string or not according with the compilation options and the final '\0'
> found or not ?

It's tricky because you don't know if you're allowed to even *read* this
trailing zero. Imagine if you have a 16-byte string allocated at 0x123BFF0,
the zero will be located at 0x123C000 which belongs to another page and may
or may not be allocated, risking a segfault once in a while.

> Or two parameters for the regex function: "char *subject" and
> "const char * subject0". These parameters are exclusive, or a flag confirming
> or not the final '\0'.

Yes that would probably be better. In fact since this read-write subject
is a pain to deal with from all call places, it would be better that the
called function duplicates it by itself when needed (ie the match function
would use a const char* and duplicate the subject for libc). Also people
using libc's regex don't care much about performance and wil not notice
the memcpy.

> Note that, I try to save a memcpy(), which use a little bit of CPU, just 
> before
> executing a regex which heavily use the CPU, maybe it is useless.

Yep. I think the easiest to do *for now* is to perform the memcpy(trash) in
your patch as it's well isolated and the Lua code doesn't use the trash, and
then in the future we'll try to improve the regex code to use only const and
perform the copies itself when appropriate. A bit like we do with the samples
marked const.

Cheers,
Willy

Reply via email to