From: "Mattias Engdegård" <mattiase@acm.org>
To: Yuan Fu <casouri@gmail.com>
Cc: Eli Zaretskii <eliz@gnu.org>, emacs-devel <emacs-devel@gnu.org>
Subject: Re: Matching regex case-sensitively in C strings?
Date: Tue, 8 Nov 2022 11:18:10 +0100 [thread overview]
Message-ID: <580E87E6-DCFD-42AE-807A-339BBB3878C2@acm.org> (raw)
In-Reply-To: <A7401408-917E-402A-9BD3-5D7228C11726@gmail.com>
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.
>
next prev parent reply other threads:[~2022-11-08 10:18 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-11-07 5:41 Matching regex case-sensitively in C strings? Yuan Fu
2022-11-07 11:52 ` Eli Zaretskii
2022-11-07 20:35 ` Yuan Fu
2022-11-08 10:18 ` Mattias Engdegård [this message]
2022-11-08 12:29 ` Eli Zaretskii
2022-11-08 19:31 ` Yuan Fu
2022-11-08 19:37 ` Eli Zaretskii
2022-11-08 20:59 ` Yuan Fu
2022-11-09 10:53 ` Mattias Engdegård
2022-11-09 10:33 ` Mattias Engdegård
2022-11-09 13:06 ` Eli Zaretskii
2022-11-10 9:52 ` Mattias Engdegård
2022-11-10 11:18 ` Eli Zaretskii
2022-11-10 11:35 ` Robert Pluim
2022-11-10 14:20 ` Mattias Engdegård
2022-11-10 22:25 ` Yuan Fu
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=580E87E6-DCFD-42AE-807A-339BBB3878C2@acm.org \
--to=mattiase@acm.org \
--cc=casouri@gmail.com \
--cc=eliz@gnu.org \
--cc=emacs-devel@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).