[PyQt] Patch to deal with recursive imports

Shaheed Haque srhaque at theiet.org
Thu Jul 13 23:00:45 BST 2017


Hi Phil,

This is a patch against 4.19.3to protect SIP against infinite
recursion in the face of a recursive import.The particular scenario I
had was:

============
srhaque at v-baba: module_generation$ grep -i -B 1 -A 1 import
tmp/kjs/kjsmod.sip tmp/wtf/wtfmod.sip tmp/kjs/bytecode/bytecodemod.sip
tmp/kjs/kjsmod.sip-%If (kjs_bytecode_bytecodemod)
tmp/kjs/kjsmod.sip:%Import(name=kjs/bytecode/bytecodemod.sip)
tmp/kjs/kjsmod.sip-%End
tmp/kjs/kjsmod.sip:%Import(name=QtCore/QtCoremod.sip)
tmp/kjs/kjsmod.sip-%If (wtf_wtfmod)
tmp/kjs/kjsmod.sip:%Import(name=wtf/wtfmod.sip)
tmp/kjs/kjsmod.sip-%End
--
tmp/wtf/wtfmod.sip-%If (kjs_kjsmod)
tmp/wtf/wtfmod.sip:%Import(name=kjs/kjsmod.sip)
tmp/wtf/wtfmod.sip-%End
--
tmp/kjs/bytecode/bytecodemod.sip-%If (kjs_kjsmod)
tmp/kjs/bytecode/bytecodemod.sip:%Import(name=kjs/kjsmod.sip)
tmp/kjs/bytecode/bytecodemod.sip-%End
============

The SIP invocation included "-x wtf_wtfmod": this was intended to work
withthe %If feature tests to guard against direct A <-> B recursion
(IIRC, I added this following an earlier discussion), but that cannot
cope with A -> B-> C -> A.

Please consider applying.

=============
--- sipgen/transform.c.orig     2017-07-13 21:30:10.781596198 +0100
+++ sipgen/transform.c  2017-07-13 22:45:06.820990635 +0100
@@ -614,11 +614,23 @@
     if (mod->imports == NULL || mod->allimports != NULL)
         return;

     /* Make sure all the direct imports are done first. */
     for (mld = mod->imports; mld != NULL; mld = mld->next)
-        setAllImports(mld->module);
+    {
+        moduleListDef *amld;
+
+        for (amld = mld->module->allimports; amld != NULL; amld = amld->next)
+            if (mod == amld->module)
+            {
+                fatalStart();
+                fprintf(stderr, "Module '%s' recursively imports
itself ", mod->name);
+                fatal("via '%s'\n", mld->module->name);
+            }
+            else
+                setAllImports(mld->module);
+    }

     /*
      * Now build the list from our direct imports lists but ignoring
      * duplicates.
      */
===================

Thanks, Shaheed


More information about the PyQt mailing list