Re: how to debug broken patsubst in m4p
Nikolaos Chatzikonstantinou <[email protected]> Thu, 15 May 2025 19:53:07 -0400
| Newsgroups | gmane.comp.gnu.m4.general |
|---|---|
| Message-ID | <CAAQmekfi8pRHkNTEX3xB2yVnG3H3YgehtQBJVBan8DbHdKQm7g@mail.gmail.com> |
--000000000000f9d19a0635355e84 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Thu, May 15, 2025, 6:06=E2=80=AFPM Eric Blake <[email protected]> wrote: > On Thu, May 15, 2025 at 07:20:48AM -0500, Eric Blake wrote: > > On Thu, May 15, 2025 at 01:26:16AM -0400, Nikolaos Chatzikonstantinou > wrote: > > > > $ python > > > > Python 3.13.3 (main, Apr 22 2025, 00:00:00) [GCC 15.0.1 20250418 > (Red Hat 15.0.1-0)] on linux > > > > Type "help", "copyright", "credits" or "license" for more > information. > > > > >>> import pygnuregex > > > > >>> pygnuregex.compile(b"a") > > > > Segmentation fault (core dumped) > > > > (.venv) > > > > > > Someone else on a forum helped me debug this. He noticed that the > > > Python pointer was different from the one received by the underlying = C > > > function (by printing the Python pointer and inspecting the C pointer > > > with gdb). In fact it was truncated to 32 bits. We eventually > > > brainstormed that it was because I had neglected to add the argument > > > types for the C functions. I'm not sure why there is a difference in > > > Python 3.10 (where I verified the crash in a VM) versus Python 3.11. > > > > I was testing with Python 3.13, not 3.10, but I can confirm that your > > latest fix finally solves it. > > I can't help but wonder: Do you NEED to call into the C functions, or > would it be possible to write pure python code that translates any m4 > (emacs-style) regex into a similar Python regex? For example, most > characters translate straight over, ^ and $ in anchor positions > translate to \A and \Z (better \z, but that is only available in > Python 3.13 and newer), \( \| \) in m4 (outside of []) translate to ( > | ) in Python while bare ( | ) in m4 translate to \( \| \), and so > forth. A quick google search found > https://www.regexbuddy.com/convert.html as a non-free resource; but > there may be other sites that can summarize how to translate between > flavors without needing foreign function interfacing. > At the time it seemed to be the simplest solution plus it contributes a package to the python ecosystem. I will add your suggestion in the features page for now, but it'll be one more thing to worry about edge cases for, and that's why I didn't elect to do it that way. I'll take a closer look soon. Regards, Nikolaos Chatzikonstantinou > --000000000000f9d19a0635355e84 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable <div dir=3D"auto"><div><br><br><div class=3D"gmail_quote"><div dir=3D"ltr" = class=3D"gmail_attr">On Thu, May 15, 2025, 6:06=E2=80=AFPM Eric Blake <<= a href=3D"mailto:[email protected]" target=3D"_blank" rel=3D"noreferrer">eb= [email protected]</a>> wrote:<br></div><blockquote class=3D"gmail_quote" s= tyle=3D"margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">On T= hu, May 15, 2025 at 07:20:48AM -0500, Eric Blake wrote:<br> > On Thu, May 15, 2025 at 01:26:16AM -0400, Nikolaos Chatzikonstantinou = wrote:<br> > > > $ python<br> > > > Python 3.13.3 (main, Apr 22 2025, 00:00:00) [GCC 15.0.1 2025= 0418 (Red Hat 15.0.1-0)] on linux<br> > > > Type "help", "copyright", "credits&= quot; or "license" for more information.<br> > > > >>> import pygnuregex<br> > > > >>> pygnuregex.compile(b"a")<br> > > > Segmentation fault (core dumped)<br> > > > (.venv)<br> > > <br> > > Someone else on a forum helped me debug this. He noticed that the= <br> > > Python pointer was different from the one received by the underly= ing C<br> > > function (by printing the Python pointer and inspecting the C poi= nter<br> > > with gdb). In fact it was truncated to 32 bits. We eventually<br> > > brainstormed that it was because I had neglected to add the argum= ent<br> > > types for the C functions. I'm not sure why there is a differ= ence in<br> > > Python 3.10 (where I verified the crash in a VM) versus Python 3.= 11.<br> > <br> > I was testing with Python 3.13, not 3.10, but I can confirm that your<= br> > latest fix finally solves it.<br> <br> I can't help but wonder: Do you NEED to call into the C functions, or<b= r> would it be possible to write pure python code that translates any m4<br> (emacs-style) regex into a similar Python regex?=C2=A0 For example, most<br= > characters translate straight over, ^ and $ in anchor positions<br> translate to \A and \Z (better \z, but that is only available in<br> Python 3.13 and newer), \( \| \) in m4 (outside of []) translate to (<br> | ) in Python while bare ( | ) in m4 translate to \( \| \), and so<br> forth.=C2=A0 A quick google search found<br> <a href=3D"https://www.regexbuddy.com/convert.html" rel=3D"noreferrer noref= errer noreferrer" target=3D"_blank">https://www.regexbuddy.com/convert.html= </a> as a non-free resource; but<br> there may be other sites that can summarize how to translate between<br> flavors without needing foreign function interfacing.<br></blockquote></div= ></div><div dir=3D"auto"><br></div><div dir=3D"auto">At the time it seemed = to be the simplest solution plus it contributes a package to the python eco= system. I will add your suggestion in the features page for now, but it'= ;ll be one more thing to worry about edge cases for, and that's why I d= idn't elect to do it that way. I'll take a closer look soon.</div><= div dir=3D"auto"><br></div><div dir=3D"auto">Regards,</div><div dir=3D"auto= ">Nikolaos Chatzikonstantinou=C2=A0</div><div dir=3D"auto"><div class=3D"gm= ail_quote"><blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;bor= der-left:1px #ccc solid;padding-left:1ex"> </blockquote></div></div></div> --000000000000f9d19a0635355e84--