]> granicus.if.org Git - python/commitdiff
added "magic" number to the _sre module, to avoid weird errors caused
authorFredrik Lundh <fredrik@pythonware.com>
Mon, 15 Jan 2001 12:46:09 +0000 (12:46 +0000)
committerFredrik Lundh <fredrik@pythonware.com>
Mon, 15 Jan 2001 12:46:09 +0000 (12:46 +0000)
by compiler/engine mismatches

Lib/sre_compile.py
Lib/sre_constants.py
Modules/_sre.c
Modules/sre_constants.h

index adab767230bcaca4dee3285b739eee6c98c83b7f..c2996fc3a25b340f3dc77f1a1645d1186de28ecc 100644 (file)
@@ -12,6 +12,8 @@ import _sre
 
 from sre_constants import *
 
+assert _sre.MAGIC == MAGIC, "SRE module mismatch"
+
 MAXCODE = 65535
 
 def _compile(code, pattern, flags):
index a5e4bb8c1e30c6b31e90182ab152a02bed5eaeab..b429a33cbf0aa99ae0ef909458e7bf4200b0ad97 100644 (file)
@@ -9,8 +9,15 @@
 # See the sre.py file for information on usage and redistribution.
 #
 
+# update when constants are added or removed
+
+MAGIC = 20010115
+
+# max code word in this release
+
 MAXREPEAT = 65535
 
+# SRE standard exception (access as sre.error)
 # should this really be here?
 
 class error(Exception):
@@ -211,6 +218,8 @@ if __name__ == "__main__":
 
 """)
 
+    f.write("#define SRE_MAGIC %d\n" % MAGIC)
+
     dump(f, OPCODES, "SRE_OP")
     dump(f, ATCODES, "SRE")
     dump(f, CHCODES, "SRE")
index b040d8739336ac3bd9c5056e67e02dff20aecf57..efb704bdf573b817da0cf0e77b037dc85c612116 100644 (file)
@@ -2355,11 +2355,19 @@ __declspec(dllexport)
 #endif
 init_sre(void)
 {
+    PyObject* m;
+    PyObject* d;
+
     /* Patch object types */
     Pattern_Type.ob_type = Match_Type.ob_type =
         Scanner_Type.ob_type = &PyType_Type;
 
-    Py_InitModule("_" MODULE, _functions);
+    m = Py_InitModule("_" MODULE, _functions);
+    d = PyModule_GetDict(m);
+
+    PyDict_SetItemString(
+        d, "MAGIC", (PyObject*) PyInt_FromLong(SRE_MAGIC)
+        );
 }
 
 #endif /* !defined(SRE_RECURSIVE) */
index 6cad0899c63f7c00b214137bf6c8e2de5ec3ecb0..c6850ad69bec2ae28c5c5e71092546d80fb29038 100644 (file)
@@ -11,6 +11,7 @@
  * See the _sre.c file for information on usage and redistribution.
  */
 
+#define SRE_MAGIC 20010115
 #define SRE_OP_FAILURE 0
 #define SRE_OP_SUCCESS 1
 #define SRE_OP_ANY 2