scripts/wrap/swig.py: avoid creating invalid global Python PdfObj whose destructor...
authorJulian Smith <[email protected]>
Fri, 27 Sep 2024 23:23:29 +0000 (00:23 +0100)
committerJulian Smith <[email protected]>
Wed, 2 Oct 2024 17:00:29 +0000 (18:00 +0100)
A PdfObj object created from PDF_LIMIT is invalid and will crash pdf_drop_obj()
because values >= PDF_LIMIT are considered to be pointers.

scripts/wrap/swig.py

index 0134eafc0e60ad73fe9cdf57eac3df89a773a327..82cd5ee423c583a7a22e7995a925f8b45bfa03ff 100644 (file)
@@ -1821,7 +1821,10 @@ def build_swig(
                     if enum_name.startswith( 'PDF_ENUM_NAME_'):
                         text += f'{enum_name} = {rename.class_("pdf_obj")}( obj_enum_to_obj( {enum_name}))\n'
 
-            for name in ('NULL', 'TRUE', 'FALSE', 'LIMIT'):
+            # 2024-09-28: important to not include PDF_LIMIT here, because
+            # pdf_drop_obj() treats all pdf_obj*'s as real pointers if they are
+            # >= PDF_LIMIT.
+            for name in ('NULL', 'TRUE', 'FALSE'):
                 text += f'PDF_{name} = {rename.class_("pdf_obj")}( obj_enum_to_obj( PDF_ENUM_{name}))\n'
 
             jlib.fs_update(text, path_out)