diff options
| author | Dag-Erling Smørgrav <des@FreeBSD.org> | 2026-05-22 13:36:27 +0000 |
|---|---|---|
| committer | Dag-Erling Smørgrav <des@FreeBSD.org> | 2026-05-22 13:36:27 +0000 |
| commit | 3dcfa5af412125cd1bad1d383ff7c18c5effbd77 (patch) | |
| tree | abc0f699ca62367a3ac39ce6899ec9f64e26769f /contrib/python | |
| parent | 4891157c57ccd537cf8fc88feb002be10e94c288 (diff) | |
Diffstat (limited to 'contrib/python')
| -rw-r--r-- | contrib/python/ldns.i | 4 | ||||
| -rw-r--r-- | contrib/python/ldns_rdf.i | 67 |
2 files changed, 68 insertions, 3 deletions
diff --git a/contrib/python/ldns.i b/contrib/python/ldns.i index 881ba5e858a7..b4a740820e12 100644 --- a/contrib/python/ldns.i +++ b/contrib/python/ldns.i @@ -99,12 +99,14 @@ %typemap(in, noblock=1) (ssize_t) { int $1_res = 0; - $1_res = SWIG_AsVal_long($input, &$1); + long val; + $1_res = SWIG_AsVal_long($input, &val); if (!SWIG_IsOK($1_res)) { SWIG_exception_fail(SWIG_ArgError($1_res), "in method '" "$symname" "', argument " "$argnum" " of type '" "$type""'"); } + $1 = val; } diff --git a/contrib/python/ldns_rdf.i b/contrib/python/ldns_rdf.i index 5d7448fdc45c..39f9af1895cb 100644 --- a/contrib/python/ldns_rdf.i +++ b/contrib/python/ldns_rdf.i @@ -50,13 +50,18 @@ 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. */ %typemap(arginit, noblock=1) const ldns_rdf * { +#if SWIG_VERSION >= 0x040200 + PyObject *$1_bytes = NULL; +#else char *$1_str = NULL; +#endif } /* @@ -66,11 +71,17 @@ %typemap(in, noblock=1) const ldns_rdf * (void* argp, $1_ltype tmp = 0, int res) { if (Python_str_Check($input)) { + const char *argstr; +#if SWIG_VERSION >= 0x040200 + argstr = SWIG_PyUnicode_AsUTF8AndSize($input, NULL, &$1_bytes); +#else $1_str = SWIG_Python_str_AsChar($input); - if ($1_str == NULL) { + argstr = $1_str; +#endif + if (argstr == NULL) { %argument_fail(SWIG_TypeError, "char *", $symname, $argnum); } - tmp = ldns_dname_new_frm_str($1_str); + tmp = ldns_dname_new_frm_str(argstr); if (tmp == NULL) { %argument_fail(SWIG_TypeError, "char *", $symname, $argnum); } @@ -90,11 +101,63 @@ */ %typemap(freearg, noblock=1) const ldns_rdf * { +#if SWIG_VERSION >= 0x040200 + if ($1_bytes != NULL) { + /* Is not NULL only when a conversion form string occurred. */ + Py_XDECREF($1_bytes); + } +#else if ($1_str != NULL) { /* Is not NULL only when a conversion form string occurred. */ SWIG_Python_str_DelForPy3($1_str); /* Is a empty macro for Python < 3. */ } +#endif +} + +#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. */ |
