diff mbox series

[1/2] libselinux: fix swig bindings for 4.3.0

Message ID 20241016184825.200567-1-lautrbach@redhat.com (mailing list archive)
State New
Headers show
Series [1/2] libselinux: fix swig bindings for 4.3.0 | expand

Commit Message

Petr Lautrbach Oct. 16, 2024, 6:48 p.m. UTC
https://github.com/swig/swig/blob/master/CHANGES.current

"[Python] #2907 Fix returning null from functions with output
parameters.  Ensures OUTPUT and INOUT typemaps are handled
consistently wrt return type.

New declaration of SWIG_Python_AppendOutput is now:

  SWIG_Python_AppendOutput(PyObject* result, PyObject* obj, int is_void);

The 3rd parameter is new and the new $isvoid special variable
should be passed to it, indicating whether or not the wrapped
function returns void.

Also consider replacing with:

  SWIG_AppendOutput(PyObject* result, PyObject* obj);

which calls SWIG_Python_AppendOutput with same parameters but adding $isvoid
for final parameter."

Fixes: https://github.com/SELinuxProject/selinux/issues/447

    selinuxswig_python_wrap.c: In function ‘_wrap_security_compute_user’:
    selinuxswig_python_wrap.c:11499:17: error: too few arguments to function ‘SWIG_Python_AppendOutput’
    11499 |     resultobj = SWIG_Python_AppendOutput(resultobj, plist);
          |                 ^~~~~~~~~~~~~~~~~~~~~~~~
    selinuxswig_python_wrap.c:1248:1: note: declared here
     1248 | SWIG_Python_AppendOutput(PyObject* result, PyObject* obj, int is_void) {
          | ^~~~~~~~~~~~~~~~~~~~~~~~
    selinuxswig_python_wrap.c: In function ‘_wrap_security_compute_user_raw’:
    selinuxswig_python_wrap.c:11570:17: error: too few arguments to function ‘SWIG_Python_AppendOutput’
    11570 |     resultobj = SWIG_Python_AppendOutput(resultobj, plist);
          |                 ^~~~~~~~~~~~~~~~~~~~~~~~
    selinuxswig_python_wrap.c:1248:1: note: declared here
     1248 | SWIG_Python_AppendOutput(PyObject* result, PyObject* obj, int is_void) {
          | ^~~~~~~~~~~~~~~~~~~~~~~~
    selinuxswig_python_wrap.c: In function ‘_wrap_security_get_boolean_names’:
    selinuxswig_python_wrap.c:12470:17: error: too few arguments to function ‘SWIG_Python_AppendOutput’
    12470 |     resultobj = SWIG_Python_AppendOutput(resultobj, list);
          |                 ^~~~~~~~~~~~~~~~~~~~~~~~
    selinuxswig_python_wrap.c:1248:1: note: declared here
     1248 | SWIG_Python_AppendOutput(PyObject* result, PyObject* obj, int is_void) {
          | ^~~~~~~~~~~~~~~~~~~~~~~~
    error: command '/usr/bin/gcc' failed with exit code 1

Suggested-by: Jitka Plesnikova <jplesnik@redhat.com>
Signed-off-by: Petr Lautrbach <lautrbach@redhat.com>
---
 libselinux/src/selinuxswig_python.i | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Comments

James Carter Oct. 17, 2024, 6:34 p.m. UTC | #1
On Wed, Oct 16, 2024 at 2:48 PM Petr Lautrbach <lautrbach@redhat.com> wrote:
>
> https://github.com/swig/swig/blob/master/CHANGES.current
>
> "[Python] #2907 Fix returning null from functions with output
> parameters.  Ensures OUTPUT and INOUT typemaps are handled
> consistently wrt return type.
>
> New declaration of SWIG_Python_AppendOutput is now:
>
>   SWIG_Python_AppendOutput(PyObject* result, PyObject* obj, int is_void);
>
> The 3rd parameter is new and the new $isvoid special variable
> should be passed to it, indicating whether or not the wrapped
> function returns void.
>
> Also consider replacing with:
>
>   SWIG_AppendOutput(PyObject* result, PyObject* obj);
>
> which calls SWIG_Python_AppendOutput with same parameters but adding $isvoid
> for final parameter."
>
> Fixes: https://github.com/SELinuxProject/selinux/issues/447
>
>     selinuxswig_python_wrap.c: In function ‘_wrap_security_compute_user’:
>     selinuxswig_python_wrap.c:11499:17: error: too few arguments to function ‘SWIG_Python_AppendOutput’
>     11499 |     resultobj = SWIG_Python_AppendOutput(resultobj, plist);
>           |                 ^~~~~~~~~~~~~~~~~~~~~~~~
>     selinuxswig_python_wrap.c:1248:1: note: declared here
>      1248 | SWIG_Python_AppendOutput(PyObject* result, PyObject* obj, int is_void) {
>           | ^~~~~~~~~~~~~~~~~~~~~~~~
>     selinuxswig_python_wrap.c: In function ‘_wrap_security_compute_user_raw’:
>     selinuxswig_python_wrap.c:11570:17: error: too few arguments to function ‘SWIG_Python_AppendOutput’
>     11570 |     resultobj = SWIG_Python_AppendOutput(resultobj, plist);
>           |                 ^~~~~~~~~~~~~~~~~~~~~~~~
>     selinuxswig_python_wrap.c:1248:1: note: declared here
>      1248 | SWIG_Python_AppendOutput(PyObject* result, PyObject* obj, int is_void) {
>           | ^~~~~~~~~~~~~~~~~~~~~~~~
>     selinuxswig_python_wrap.c: In function ‘_wrap_security_get_boolean_names’:
>     selinuxswig_python_wrap.c:12470:17: error: too few arguments to function ‘SWIG_Python_AppendOutput’
>     12470 |     resultobj = SWIG_Python_AppendOutput(resultobj, list);
>           |                 ^~~~~~~~~~~~~~~~~~~~~~~~
>     selinuxswig_python_wrap.c:1248:1: note: declared here
>      1248 | SWIG_Python_AppendOutput(PyObject* result, PyObject* obj, int is_void) {
>           | ^~~~~~~~~~~~~~~~~~~~~~~~
>     error: command '/usr/bin/gcc' failed with exit code 1
>
> Suggested-by: Jitka Plesnikova <jplesnik@redhat.com>
> Signed-off-by: Petr Lautrbach <lautrbach@redhat.com>

For these two patches:
Acked-by: James Carter <jwcart2@gmail.com>


> ---
>  libselinux/src/selinuxswig_python.i | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/libselinux/src/selinuxswig_python.i b/libselinux/src/selinuxswig_python.i
> index 17e03b9e36a5..03ed296d5b85 100644
> --- a/libselinux/src/selinuxswig_python.i
> +++ b/libselinux/src/selinuxswig_python.i
> @@ -71,7 +71,7 @@ def install(src, dest):
>         for (i = 0; i < *$2; i++) {
>                 PyList_SetItem(list, i, PyString_FromString((*$1)[i]));
>         }
> -       $result = SWIG_Python_AppendOutput($result, list);
> +       $result = SWIG_AppendOutput($result, list);
>  }
>
>  /* return a sid along with the result */
> @@ -108,7 +108,7 @@ def install(src, dest):
>                 plist = PyList_New(0);
>         }
>
> -       $result = SWIG_Python_AppendOutput($result, plist);
> +       $result = SWIG_AppendOutput($result, plist);
>  }
>
>  /* Makes functions in get_context_list.h return a Python list of contexts */
> --
> 2.47.0
>
>
diff mbox series

Patch

diff --git a/libselinux/src/selinuxswig_python.i b/libselinux/src/selinuxswig_python.i
index 17e03b9e36a5..03ed296d5b85 100644
--- a/libselinux/src/selinuxswig_python.i
+++ b/libselinux/src/selinuxswig_python.i
@@ -71,7 +71,7 @@  def install(src, dest):
 	for (i = 0; i < *$2; i++) {
 		PyList_SetItem(list, i, PyString_FromString((*$1)[i]));
 	}
-	$result = SWIG_Python_AppendOutput($result, list);
+	$result = SWIG_AppendOutput($result, list);
 }
 
 /* return a sid along with the result */
@@ -108,7 +108,7 @@  def install(src, dest):
 		plist = PyList_New(0);
 	}
 
-	$result = SWIG_Python_AppendOutput($result, plist);
+	$result = SWIG_AppendOutput($result, plist);
 }
 
 /* Makes functions in get_context_list.h return a Python list of contexts */