From: Chong Yidong <cyd@stupidchicken.com>
Cc: emacs-devel@gnu.org, bojohan+mail@dd.chalmers.se
Subject: Re: [BUG] Regexp compiler, problem with character classes
Date: Fri, 15 Sep 2006 11:13:39 -0400 [thread overview]
Message-ID: <87odth17to.fsf@stupidchicken.com> (raw)
In-Reply-To: <E1GOEhF-00072t-Ic@fencepost.gnu.org> (Richard Stallman's message of "Fri\, 15 Sep 2006 10\:29\:37 -0400")
Richard Stallman <rms@gnu.org> writes:
> + void
> + clear_regexp_cache ()
> + {
> + int i;
> +
> + BLOCK_INPUT;
> + for (i = 0; i < REGEXP_CACHE_SIZE; ++i)
> + searchbufs[i].regexp = Qnil;
> + UNBLOCK_INPUT;
> + }
>
> 1. That leaks the memory in the compiled regexps.
Are you sure? AFAICT, re_compile_pattern automagically manages the
memory allocated in each re_pattern_buffer struct, based on the value
of bufp->allocated and bufp->buffer. If we reset searchbuf->regexp to
Qnil, that means that cache element can be used to store a compiled
regexp, and the memory used by any compiled regexp (i.e., the
re_pattern_buffer) previously existing in that cache element is
reused.
This seems to be the existing practice in search.c: the cache elements
are initialized in syms_of_search as
for (i = 0; i < REGEXP_CACHE_SIZE; ++i)
{
searchbufs[i].buf.allocated = 100;
searchbufs[i].buf.buffer = (unsigned char *) xmalloc (100);
...
searchbufs[i].regexp = Qnil;
...
}
When compile_pattern is called with an uncached regexp, it tries to
cache it in an empty cache element (i.e., one with a nil `regexp'
entry). If no cache elements are empty, it uses the oldest cache
element by resetting its `regexp' entry and passing it along to
re_compile_pattern.
> 2. I don't see a reason for BLOCK_INPUT.
> I don't think anything in a signal handler can compile a regexp.
That's probably true.
next prev parent reply other threads:[~2006-09-15 15:13 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2006-06-03 1:14 [BUG] Regexp compiler, problem with character classes Johan Bockgård
2006-09-07 21:15 ` Richard Stallman
2006-09-13 9:50 ` Johan Bockgård
2006-09-13 19:25 ` Richard Stallman
2006-09-07 21:15 ` Richard Stallman
2006-09-14 23:20 ` Chong Yidong
2006-09-15 14:29 ` Richard Stallman
2006-09-15 15:13 ` Chong Yidong [this message]
2006-09-18 8:43 ` Johan Bockgård
2006-09-18 12:53 ` Chong Yidong
2006-09-18 13:03 ` Stefan Monnier
2006-09-18 13:12 ` Johan Bockgård
2006-09-15 3:14 ` Richard Stallman
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
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87odth17to.fsf@stupidchicken.com \
--to=cyd@stupidchicken.com \
--cc=bojohan+mail@dd.chalmers.se \
--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 external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.