unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Eli Zaretskii <eliz@gnu.org>
To: npostavs@users.sourceforge.net
Cc: sam.halliday@gmail.com, 24358@debbugs.gnu.org
Subject: bug#24358: 25.1.50; re-search-forward errors with "Variable binding depth exceeds max-specpdl-size"
Date: Wed, 19 Oct 2016 10:02:38 +0300	[thread overview]
Message-ID: <83zim0vn1t.fsf@gnu.org> (raw)
In-Reply-To: <877f95uj66.fsf@users.sourceforge.net> (npostavs@users.sourceforge.net)

> From: npostavs@users.sourceforge.net
> Cc: 24358@debbugs.gnu.org, Sam Halliday <sam.halliday@gmail.com>
> Date: Tue, 18 Oct 2016 23:11:45 -0400
> 
> > Then yes, you will need to somehow pass down the object from which the
> > text comes.  It can be in some global variable, for instance, if
> > changing the function's signature is undesirable.
> 
> I decided that a global variable would be a bad idea since it would
> still effectively be part of the calling convention, and too easy for
> callers to forget.

That's true, but doing this is a standard Emacs coding practice, used
in quite a few other places.

> But just after finishing the patch I noticed this:
> 
>     /* In Emacs, this is the string or buffer in which we
>        are matching.  It is used for looking up syntax properties.  */
>     Lisp_Object re_match_object;

Indeed.

> So now I'm thinking it might be better to reuse that variable instead.
> Although it only seems to get to Qt, Qnil, and string objects; I'm not
> sure what the meaning of Qt and Qnil are.

nil means current buffer, t means a C string.  (This is standard Emacs
convention, used in other places as well, but you can verify it is
used in this case by looking at all the places where these values are
assigned.)  The last case, of a C string, doesn't need to bother about
relocation, of course (but you could ignore that distinction for
simplicity of the code, if you want, it will never do any harm).

I guess you will be rewriting your patch to use re_match_object?  I
expect it to be much simpler and smaller.  re_match_object is already
staticpro'd, btw, so you don't need to worry about GC for the Lisp
object (a string) that gets put in its value.  However, I think we
should assign Qnil to re_match_object as soon as re_match_2 returns,
to avoid having the string protected from GC for too long.

A couple of comments to the patch:

> +#ifdef emacs
> +#define STR_BASE_PTR(obj)                       \
> +    (BUFFERP (obj)? XBUFFER (obj)->text->beg :  \
> +     STRINGP (obj)? SDATA (obj) :               \
> +     NULL)

There's an unnecessary complication here: since, when regex functions
are invoked to search a buffer, that buffer is always the current
buffer, you don't need to pass the buffer object and use XBUFFER,
because the current buffer is always available in the global variable
current_buffer (which is a C struct, not a Lisp object).  So you could
adopt the usual semantics of passing Qnil to mean the current buffer
and a string object to mean that string.  Then the only test in the
macro should be STRINGP.

>  #define ENSURE_FAIL_STACK(space)					\
>  while (REMAINING_AVAIL_SLOTS <= space) {				\
> +  re_char* orig_base = STR_BASE_PTR (string_base);                      \
>    if (!GROW_FAIL_STACK (fail_stack))					\
> -    return -2;								\
> +    return -2;                                                          \
> +  /* GROW_FAIL_STACK may call malloc and relocate the string */         \
> +  /* pointers.  */                                                      \
> +  ptrdiff_t delta = STR_BASE_PTR (string_base) - orig_base;             \
> +  if (string1)                                                          \
> +    {                                                                   \
> +      string1 += delta;                                                 \
> +      end1 += delta;                                                    \
> +      end_match_1 += delta;                                             \
> +    }                                                                   \
> +  if (string2)                                                          \
> +    {                                                                   \
> +      string2 += delta;                                                 \
> +      end2 += delta;                                                    \
> +      end_match_2 += delta;                                             \
> +    }                                                                   \
> +  d += delta;                                                           \
> +  dend += delta;                                                        \
> +  dfail += delta;                                                       \

I think doing this via buffer and string positions instead would yield
slightly more portable code, since Standard C says subtraction of
pointers to different objects yields undefined behavior.

Thanks.





  reply	other threads:[~2016-10-19  7:02 UTC|newest]

Thread overview: 76+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-08-26 20:17 bug#24315: 25.1.50; re-search-forward errors with "Variable binding depth exceeds max-specpdl-size" Peder O. Klingenberg
2016-08-27  3:35 ` npostavs
2016-08-30 13:09   ` Peder O. Klingenberg
2016-09-02  1:58     ` npostavs
2016-09-02 13:45       ` Peder O. Klingenberg
2016-09-03 14:21         ` npostavs
2016-09-06  8:18           ` Peder O. Klingenberg
2016-09-07 23:27             ` npostavs
2016-09-03 15:43   ` bug#24358: " npostavs
2016-10-08  0:29     ` npostavs
2016-10-08  5:55       ` Eli Zaretskii
2016-10-08 13:45         ` npostavs
2016-10-08 14:39           ` Eli Zaretskii
2016-10-08 14:47             ` Eli Zaretskii
2016-10-08 16:57             ` npostavs
2016-10-08 17:23               ` Eli Zaretskii
2016-10-08 18:52                 ` npostavs
2016-10-08 19:47                   ` Eli Zaretskii
2016-10-08 20:55                     ` npostavs
2016-10-09  6:52                       ` Eli Zaretskii
2016-10-13  1:29                     ` npostavs
2016-10-13  6:19                       ` Eli Zaretskii
2016-10-14  2:19                         ` npostavs
2016-10-14  7:02                           ` Eli Zaretskii
2016-10-19  3:11                             ` npostavs
2016-10-19  7:02                               ` Eli Zaretskii [this message]
2016-10-19 12:29                                 ` npostavs
2016-10-19 14:37                                   ` Eli Zaretskii
2016-10-20  4:31                                     ` npostavs
2016-10-20  8:39                                       ` Eli Zaretskii
2016-10-21  1:22                                         ` npostavs
2016-10-21  7:17                                           ` Eli Zaretskii
2016-10-22  2:36                                             ` npostavs
2016-10-22 21:54                                               ` Sam Halliday
2016-10-22 22:46                                                 ` npostavs
2016-10-23  6:41                                                   ` Eli Zaretskii
2016-10-23  8:57                                                     ` Sam Halliday
2016-10-23  9:19                                                       ` Eli Zaretskii
2016-10-23 13:40                                                         ` Sam Halliday
2016-10-23 14:07                                                           ` Eli Zaretskii
2016-10-23 15:42                                                             ` Sam Halliday
2016-10-23 15:48                                                               ` Eli Zaretskii
2016-10-23 15:58                                                                 ` Sam Halliday
2016-10-23 15:58                                                                   ` Sam Halliday
2016-10-23 16:44                                                                     ` Eli Zaretskii
2016-10-23 17:19                                                                   ` Eli Zaretskii
2016-10-23 18:06                                                                     ` Eli Zaretskii
2016-10-23 18:14                                                                       ` Noam Postavsky
2016-10-23 19:18                                                                         ` Eli Zaretskii
2016-10-24 13:29                                                                           ` npostavs
2016-10-24 13:39                                                                             ` Eli Zaretskii
2016-10-24 15:33                                                                               ` Noam Postavsky
2016-10-24 16:13                                                                                 ` Eli Zaretskii
2016-10-25  2:00                                                                                   ` npostavs
2016-10-25 16:03                                                                                     ` Eli Zaretskii
2016-10-26  0:16                                                                                       ` npostavs
2016-10-24 13:43                                                                             ` Eli Zaretskii
2016-10-24 14:03                                                                               ` Eli Zaretskii
2016-10-24 20:13                                                                             ` Sam Halliday
2016-10-24 23:44                                                                               ` npostavs
2016-11-07  3:39                                                                               ` Eli Zaretskii
2016-11-07  3:56                                                                                 ` Noam Postavsky
2016-11-07 15:10                                                                                   ` Eli Zaretskii
2016-10-23 18:16                                                                       ` Sam Halliday
2016-10-23 19:10                                                                         ` Eli Zaretskii
2016-10-23 19:32                                                                           ` Eli Zaretskii
2016-10-23 20:15                                                                             ` Sam Halliday
2016-10-23 20:27                                                                               ` Eli Zaretskii
2016-10-23 20:18                                                                             ` Eli Zaretskii
2016-10-23 23:18                                                                               ` Noam Postavsky
2016-10-24  7:05                                                                                 ` Eli Zaretskii
2016-10-24  8:40                                                                                   ` Eli Zaretskii
2016-10-23 18:11                                                                     ` Sam Halliday
2016-10-18  8:16 ` bug#24358: 25.1.50; Sam Halliday
2016-10-18  8:56   ` Sam Halliday
2016-10-18  9:28   ` Eli Zaretskii

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=83zim0vn1t.fsf@gnu.org \
    --to=eliz@gnu.org \
    --cc=24358@debbugs.gnu.org \
    --cc=npostavs@users.sourceforge.net \
    --cc=sam.halliday@gmail.com \
    /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).