On Mon, May 19, 2025 at 10:46:10AM -0500, Eric Blake wrote:
> On Fri, May 16, 2025 at 08:16:24AM -0500, Eric Blake wrote:
> > Since you continue to patch things as fast as I report them (now
> > testing with commit a4cc0f3c):
> 
> Now testing with b686ed, you have a problem with redefining a macro as
> empty if it has been undefined in the meantime:
> 
> $ echo 'changequote([,])define(a)undefine([a])define(a)' | m4p
> Traceback (most recent call last):
>   File "/home/eblake/m4p/.venv/bin/m4p", line 8, in <module>
>     sys.exit(main())
>              ~~~~^^
> ...
>   File "/home/eblake/m4p/m4p/parser.py", line 279, in add_define
>     self.macros[ident][-1] = defn
>     ~~~~~~~~~~~~~~~~~~^^^^
> IndexError: list assignment index out of range

This appears to fix it for me:

diff --git i/m4p/parser.py w/m4p/parser.py
index 4793c8a..83c69df 100644
--- i/m4p/parser.py
+++ w/m4p/parser.py
@@ -272,7 +272,7 @@ class Parser:

     def add_define(self, ident: bytes, defn: bytes | Builtin):
         """Equivalent to m4_define(ident, defn)."""
-        if self.macros.get(ident) is None:
+        if not self.macros.get(ident, []):
             self.macros[ident] = [defn]
         else:
             # GNU ext define: replace top. Others: replace all with 1.

-- 
Eric Blake, Principal Software Engineer
Red Hat, Inc.
Virtualization:  qemu.org | libguestfs.org


Reply via email to