scripts/wrap/: fix handling of new enum/fn pdf_zugferd_profile.
authorJulian Smith <[email protected]>
Tue, 4 Jun 2024 15:34:41 +0000 (16:34 +0100)
committerTor Andersson <[email protected]>
Wed, 5 Jun 2024 16:22:41 +0000 (18:22 +0200)
If an enum and fn have same name, we need to not SWIG %ignore the name, so do
this with `pdf_zugferd_profile` like we already do with `pdf_annot_type`. [We
usually %ignore all raw C fn names because we only want SWIG to see the C++
wrapper fns.]

Also fixed generated C# out-param code when handling MuPDF enums.

scripts/wrap/csharp.py
scripts/wrap/rename.py
scripts/wrap/swig.py

index abc11f9c29066a2c103150fdf72c591ec215c35f..22ebc7e746d66b1cdea791ca086eec2015d06eea 100644 (file)
@@ -141,6 +141,13 @@ def make_outparam_helper_csharp(
             elif text == 'int64_t':         text = 'long'
             elif text == 'size_t':          text = 'ulong'
             elif text == 'unsigned int':    text = 'uint'
+            elif text.startswith('enum '):
+                # This is primarily for enum pdf_zugferd_profile; C# does not
+                # like `enum` prefix, and we need to specify namespace name
+                # `mupdf`.
+                text = text[5:]
+                if text.startswith('pdf_') or text.startswith('fz_'):
+                    text = f'{rename.namespace()}.{text}'
             write(f'{text}')
 
     # Generate the returned tuple.
index 984b8d34ea793f3c508170fbed73109b428aea9e..276ac020ab49224359820ffaf93a4f76d45924e2 100644 (file)
@@ -76,13 +76,16 @@ def ll_fn( fnname):
         ret += '_'
     return ret
 
+def namespace():
+    return 'mupdf'
+
 def namespace_ll_fn( fnname):
     '''
     Returns full-qualified name of low-level wrapper function for MuPDF C
     function `fnname()`, adding a `ctx` arg and converting MuPDF exceptions
     into C++ exceptions.
     '''
-    return f'mupdf::{ll_fn(fnname)}'
+    return f'{namespace()}::{ll_fn(fnname)}'
 
 def fn( fnname):
     '''
@@ -96,7 +99,7 @@ def namespace_fn( fnname):
     Returns fully-qualified name of wrapper function for MuPDF C function
     `fnname()`, using wrapper classes for args and return values.
     '''
-    return f'mupdf::{fn(fnname)}'
+    return f'{namespace()}::{fn(fnname)}'
 
 def class_( structname):
     '''
@@ -124,7 +127,7 @@ def namespace_class( structname):
     '''
     Returns fully-qualified name of class that wraps MuPDF struct `structname`.
     '''
-    return f'mupdf::{class_(structname)}'
+    return f'{namespace()}::{class_(structname)}'
 
 def method( structname, fnname):
     '''
index 5caa7265308282c571ef3b7768cc6798c798fcff..49fd7e70caabd2a507289c775746818e38f4c759 100644 (file)
@@ -751,7 +751,11 @@ def build_swig(
     # Ignore all C MuPDF functions; SWIG will still look at the C++ API in
     # namespace mudf.
     for fnname in generated.c_functions:
-        if fnname in ('pdf_annot_type', 'pdf_widget_type'):
+        if fnname in (
+                    'pdf_annot_type',
+                    'pdf_widget_type',
+                    'pdf_zugferd_profile',
+                    ):
             # These are also enums which we don't want to ignore. SWIGing the
             # functions is hopefully harmless.
             pass