Re: PyList_New coredumps if called from inline function

William S Fulton <[email protected]> Mon, 10 Nov 2025 19:00:51 +0000
Newsgroups gmane.comp.programming.swig
Message-ID <CANGqftC1RWr3KTSHVhPa+Of-EYsvCOTPzTvNtYkyr=Uq_i_n8w@mail.gmail.com>
--===============5077661276842967512==
Content-Type: multipart/alternative; boundary="0000000000009e18b90643422882"

--0000000000009e18b90643422882
Content-Type: text/plain; charset="UTF-8"

On Thu, 6 Nov 2025 at 14:41, Alexander Moibenko <[email protected]> wrote:

> Hello,
> call of PyList_New causes coredump if called from inline function.
> Environment:
> OS: Ubuntu, or Alma Linux 9 (give same result)
> swig:
> SWIG Version 4.0.2
> Compiled with g++ [x86_64-pc-linux-gnu]
> Configured options: +pcre
>
> python: Python 3.12.7
>
> Code:
> swig:
> =====================================
> %module test_PyList_New
>
> %inline %{
>   PyObject * test_PyList_New(const int buf_len)
>   {
>     PyObject * out_list;
>
>     printf("test_PyList_New requested buffer length %d\n", buf_len);
>     out_list = PyList_New(buf_len);
>     return NULL;
>

A python error needs to be set if you want to return NULL. Maybe you meant
to return out_list? Also, the latest SWIG version, swig-4.4.0 returns
immediately to the interpreter for the PyObject* typemaps, as it should as
NULL indicates an error.

William

--0000000000009e18b90643422882
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><div dir=3D"ltr"><br></div><br><div class=3D"gmail_quote g=
mail_quote_container"><div dir=3D"ltr" class=3D"gmail_attr">On Thu, 6 Nov 2=
025 at 14:41, Alexander Moibenko &lt;<a href=3D"mailto:[email protected]">=
[email protected]</a>&gt; wrote:<br></div><blockquote class=3D"gmail_quote=
" style=3D"margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);=
padding-left:1ex"><div dir=3D"ltr"><div>Hello,</div><div>call of=C2=A0PyLis=
t_New causes coredump=C2=A0if called from inline function.</div><div>Enviro=
nment:</div><div>OS: Ubuntu, or Alma Linux=C2=A09 (give same result)</div><=
div>swig:</div><div>SWIG Version 4.0.2<br>Compiled with g++ [x86_64-pc-linu=
x-gnu]<br>Configured options: +pcre</div><div><br></div><div>python:=C2=A0P=
ython 3.12.7</div><div><br></div><div>Code:</div><div>swig:</div><div>=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D</div><div>%module test_PyList_New<br><br>=
%inline %{<br>=C2=A0 PyObject * test_PyList_New(const int buf_len)<br>=C2=
=A0 {<br>=C2=A0 =C2=A0 PyObject * out_list;<br><br>=C2=A0 =C2=A0 printf(&qu=
ot;test_PyList_New requested buffer length %d\n&quot;, buf_len);<br>=C2=A0 =
=C2=A0 out_list =3D PyList_New(buf_len);<br>=C2=A0 =C2=A0 return NULL;<br><=
/div></div></blockquote><div><br></div>A python error needs to be set if yo=
u want to return NULL. Maybe you meant to return out_list? Also, the latest=
 SWIG version, swig-4.4.0 returns immediately to the interpreter for the Py=
Object* typemaps, as it should as NULL indicates an error.</div><div class=
=3D"gmail_quote gmail_quote_container"><br></div><div class=3D"gmail_quote =
gmail_quote_container">William=C2=A0</div></div>

--0000000000009e18b90643422882--


--===============5077661276842967512==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline


--===============5077661276842967512==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

_______________________________________________
Swig-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/swig-user

--===============5077661276842967512==--