emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Matching regex case-sensitively in C strings?


From: Yuan Fu
Subject: Re: Matching regex case-sensitively in C strings?
Date: Tue, 8 Nov 2022 11:31:35 -0800


> On Nov 8, 2022, at 2:18 AM, Mattias Engdegård <mattiase@acm.org> wrote:
> 
> 7 nov. 2022 kl. 21.35 skrev Yuan Fu <casouri@gmail.com>:
> 
>> fast_c_string_match_ignore_case (Lisp_Object regexp,
>>                               const char *string, ptrdiff_t len)
>> {
>> regexp = string_make_unibyte (regexp);
> 
> This is expensive and not obviously correct when it makes a difference. Ie, 
> no longer "fast", and may hide bugs.
> Something should be done about that.
> 
>> // Why do we need to unwind stack?
>> specpdl_ref count = SPECPDL_INDEX ();
> 
> Because freeze_pattern pushes an unwind-protect on the specpdl.
> 
>> struct regexp_cache *cache_entry
>>   = compile_pattern (regexp, 0, Vascii_canon_table, 0, 0);
> 
> `Vascii_canon_table` is what makes it case-insensitive; you want to use Qnil 
> (but you probably already know that now).
> Since this is the only thing that differs from your intended use, I suggest 
> you generalise this subroutine with a boolean parameter.
> 
>> // What does freezing a pattern do?
>> freeze_pattern (cache_entry);
> 
> It locks the compiled pattern record to make the regexp engine reentrant (but 
> here it also seems to be used for GC purposes; not sure about that).
> 
>> // What is re_match_object for? I see that it can be t, nil or a string.
>> re_match_object = Qt;
> 
> Described in regex-emacs.h:
> 
>> /* The string or buffer being matched.
>>   It is used for looking up syntax properties.
>> 
>>   If the value is a Lisp string object, match text in that string; if
>>   it's nil, match text in the current buffer; if it's t, match text
>>   in a C string.
>> 
>>   This value is effectively another parameter to re_search_2 and
>>   re_match_2.  No calls into Lisp or thread switches are allowed
>>   before setting re_match_object and calling into the regex search
>>   and match functions.  These functions capture the current value of
>>   re_match_object into gl_state on entry.
>> 

Thanks! How about:

Yuan

Attachment: c_string_match.diff
Description: Binary data



reply via email to

[Prev in Thread] Current Thread [Next in Thread]