]> git.ipfire.org Git - thirdparty/ldns.git/commitdiff
const ldns_rdf * typemap fixes to support swig-4.2.0 231/head
authorWilliam S Fulton <wsf@fultondesigns.co.uk>
Sat, 6 Jan 2024 15:02:39 +0000 (15:02 +0000)
committerGitHub <noreply@github.com>
Sat, 6 Jan 2024 15:02:39 +0000 (15:02 +0000)
SWIG_Python_str_AsChar needs to be replaced by SWIG_PyUnicode_AsUTF8AndSize
See https://github.com/swig/swig/commit/f89dd59d4b82ece899087682fdb86e94d2611513

contrib/python/ldns_rdf.i

index 5d7448fdc45cfa1ae3f0adb6e3d985603a590c65..4924b979cfa0bef0b63895c5188f12eae15f162f 100644 (file)
@@ -50,6 +50,7 @@
       SWIGTYPE_p_ldns_struct_rdf, SWIG_POINTER_OWN | 0));
 }
 
+#if SWIG_VERSION < 0x040200
 /*
  * Automatic conversion of const (ldns_rdf *) parameter from string.
  * Argument default value.
   }
 }
 
+#else
+/*
+ * Automatic conversion of const (ldns_rdf *) parameter from string.
+ * Argument default value.
+ */
+%typemap(arginit, noblock=1) const ldns_rdf *
+{
+  PyObject *$1_bytes = NULL;
+}
+
+/*
+ * Automatic conversion of const (ldns_rdf *) parameter from string.
+ * Preparation of arguments.
+ */
+%typemap(in, noblock=1) const ldns_rdf * (void* argp, $1_ltype tmp = 0, int res)
+{
+  if (Python_str_Check($input)) {
+    const char *$1_str = SWIG_PyUnicode_AsUTF8AndSize($input, NULL, &$1_bytes);
+    if ($1_str == NULL) {
+      %argument_fail(SWIG_TypeError, "char *", $symname, $argnum);
+    }
+    tmp = ldns_dname_new_frm_str($1_str);
+    if (tmp == NULL) {
+      %argument_fail(SWIG_TypeError, "char *", $symname, $argnum);
+    }
+    $1 = ($1_ltype) tmp;
+  } else {
+    res = SWIG_ConvertPtr($input, &argp, SWIGTYPE_p_ldns_struct_rdf, 0 | 0);
+    if (!SWIG_IsOK(res)) {
+      %argument_fail(res, "ldns_rdf const *", $symname, $argnum);
+    }
+    $1 = ($1_ltype) argp;
+  }
+}
+
+/*
+ * Automatic conversion of const (ldns_rdf *) parameter from string.
+ * Freeing of allocated memory (it's a no op unless compiling for some older versions of the Python stable ABI).
+ */
+%typemap(freearg, noblock=1) const ldns_rdf *
+{
+  Py_XDECREF($1_bytes);
+}
+#endif
+
 %nodefaultctor ldns_struct_rdf; /* No default constructor. */
 %nodefaultdtor ldns_struct_rdf; /* No default destructor. */