]> git.ipfire.org Git - thirdparty/unbound.git/commitdiff
- Fix #1489 from jplesnik: Replace removed Python 2 C API master
authorW.C.A. Wijngaards <wouter@nlnetlabs.nl>
Fri, 7 Aug 2026 06:57:32 +0000 (08:57 +0200)
committerW.C.A. Wijngaards <wouter@nlnetlabs.nl>
Fri, 7 Aug 2026 06:57:32 +0000 (08:57 +0200)
  macros for SWIG 4.5.0 compatibility.

doc/Changelog
pythonmod/interface.i
pythonmod/pythonmod.c

index bf37b87156017c4c190cbc69c64b248daacb145d..25a43cfd68273af26994e35edd1419404c06a772 100644 (file)
@@ -1,3 +1,7 @@
+7 August 2026: Wouter
+       - Fix #1489 from jplesnik: Replace removed Python 2 C API
+         macros for SWIG 4.5.0 compatibility.
+
 6 August 2026: Alex Khanin
        - Fix #1488: bounds check in packed_rr_to_string, it checked
          the assembled rr length against the output string length
index 735f2ed50ea0f95d5a3e0862797843e760f38c81..7e2a188aa2cc3c4b1e1a9344a6c0a2c73d0eed01 100644 (file)
@@ -79,7 +79,7 @@
                 i+(int)((unsigned int)name[i]) < len) {
                 memmove(buf, name + i + 1, (unsigned int)name[i]);
                 buf[(unsigned int)name[i]] = 0;
-                PyList_SetItem(list, cnt, PyString_FromString(buf));
+                PyList_SetItem(list, cnt, PyUnicode_FromString(buf));
         }
         i += ((unsigned int)name[i]) + 1;
         cnt++;
@@ -96,7 +96,7 @@
 
      list = PyList_New(len);
      for (i=0; i < len; i++) {
-            PyList_SET_ITEM(list, i, PyString_FromString(array[i]));
+            PyList_SET_ITEM(list, i, PyUnicode_FromString(array[i]));
      }
      return list;
    }
@@ -207,7 +207,7 @@ struct query_info {
        char buf[LDNS_MAX_DOMAINLEN];
        buf[0] = '\0';
        dname_str((uint8_t*)PyBytes_AsString(dname), buf);
-       return PyString_FromString(buf);
+       return PyUnicode_FromString(buf);
    }
 %}
 
@@ -345,7 +345,7 @@ struct packed_rrset_data {
    PyObject* _get_data_rr_len(struct packed_rrset_data* d, int idx) {
      if ((d != NULL) && (idx >= 0) &&
              ((size_t)idx < (d->count+d->rrsig_count)))
-        return PyInt_FromLong(d->rr_len[idx]);
+        return PyLong_FromLong(d->rr_len[idx]);
      return Py_None;
    }
    void _set_data_rr_ttl(struct packed_rrset_data* d, int idx, uint32_t ttl)
@@ -357,7 +357,7 @@ struct packed_rrset_data {
    PyObject* _get_data_rr_ttl(struct packed_rrset_data* d, int idx) {
      if ((d != NULL) && (idx >= 0) &&
              ((size_t)idx < (d->count+d->rrsig_count)))
-        return PyInt_FromLong(d->rr_ttl[idx]);
+        return PyLong_FromLong(d->rr_ttl[idx]);
      return Py_None;
    }
    PyObject* _get_data_rr_data(struct packed_rrset_data* d, int idx) {
@@ -555,12 +555,12 @@ struct sockaddr_storage {};
 
         if (ss->ss_family == AF_INET) {
             const struct sockaddr_in *sa4 = (struct sockaddr_in *)ss;
-            return PyInt_FromLong(ntohs(sa4->sin_port));
+            return PyLong_FromLong(ntohs(sa4->sin_port));
         }
 
         if (ss->ss_family == AF_INET6) {
             const struct sockaddr_in6 *sa6 = (struct sockaddr_in6 *)ss;
-            return PyInt_FromLong(ntohs(sa6->sin6_port));
+            return PyLong_FromLong(ntohs(sa6->sin6_port));
         }
 
         return Py_None;
@@ -574,7 +574,7 @@ struct sockaddr_storage {};
         }
 
         sa6 = (struct sockaddr_in6 *)ss;
-        return PyInt_FromLong(ntohl(sa6->sin6_flowinfo));
+        return PyLong_FromLong(ntohl(sa6->sin6_flowinfo));
     }
 
     PyObject *_sockaddr_storage_scope_id(const struct sockaddr_storage *ss) {
@@ -585,7 +585,7 @@ struct sockaddr_storage {};
         }
 
         sa6 = (struct sockaddr_in6 *)ss;
-        return PyInt_FromLong(ntohl(sa6->sin6_scope_id));
+        return PyLong_FromLong(ntohl(sa6->sin6_scope_id));
     }
 %}
 
@@ -661,7 +661,7 @@ struct edns_option {
 %inline %{
     PyObject* _edns_option_opt_code_get(struct edns_option* option) {
         uint16_t opt_code = option->opt_code;
-        return PyInt_FromLong(opt_code);
+        return PyLong_FromLong(opt_code);
     }
 
     PyObject* _edns_option_opt_data_get(struct edns_option* option) {
@@ -1627,7 +1627,7 @@ int edns_opt_list_append(struct edns_option** list, uint16_t code, size_t len,
         }
         result = PyObject_Call(func, py_args, py_kwargs);
         if (result) {
-            res = PyInt_AsLong(result);
+            res = PyLong_AsLong(result);
         }
 out:
         Py_XDECREF(py_edns);
@@ -1711,7 +1711,7 @@ out:
         }
         result = PyObject_Call(func, py_args, py_kwargs);
         if (result) {
-            res = PyInt_AsLong(result);
+            res = PyLong_AsLong(result);
         }
 out:
         Py_XDECREF(py_qinfo);
@@ -1765,7 +1765,7 @@ out:
         }
         result = PyObject_Call(func, py_args, py_kwargs);
         if (result) {
-            res = PyInt_AsLong(result);
+            res = PyLong_AsLong(result);
         }
 out:
         Py_XDECREF(py_qstate);
@@ -1814,7 +1814,7 @@ out:
         }
         result = PyObject_Call(func, py_args, py_kwargs);
         if (result) {
-            res = PyInt_AsLong(result);
+            res = PyLong_AsLong(result);
         }
 out:
         Py_XDECREF(py_qstate);
index 045dd1bbd09ee580d20d210fb387f74f2523145c..1aef55612dc1cd30b3ee04d42df4734f196856f3 100644 (file)
@@ -246,14 +246,14 @@ log_py_err(void)
        }
 
        /* And it should be a string all ready to go - duplicate it. */
-       if (!PyString_Check(obResult) && !PyUnicode_Check(obResult)) {
+       if (!PyBytes_Check(obResult) && !PyUnicode_Check(obResult)) {
                log_err("pythonmod: cannot print exception, "
                        "StringIO.getvalue() result did not String_Check"
                        " or Unicode_Check");
                goto cleanup;
        }
-       if(PyString_Check(obResult)) {
-               result = PyString_AsString(obResult);
+       if(PyBytes_Check(obResult)) {
+               result = PyBytes_AsString(obResult);
        } else {
                ascstr = PyUnicode_AsASCIIString(obResult);
                result = PyBytes_AsString(ascstr);
@@ -450,7 +450,7 @@ int pythonmod_init(struct module_env* env, int id)
 
    pe->data = PyDict_New();
    /* add the script filename to the global "mod_env" for trivial access */
-   fname = PyString_FromString(pe->fname);
+   fname = PyUnicode_FromString(pe->fname);
    if(PyDict_SetItemString(pe->data, "script", fname) < 0) {
        log_err("pythonmod: could not add item to dictionary");
        Py_XDECREF(fname);