PyList_New coredumps if called from inline function

Alexander Moibenko <[email protected]> Thu, 6 Nov 2025 17:41:06 +0300
Newsgroups gmane.comp.programming.swig
Message-ID <CALqOg-J7r-gf3CNoC-c779p7DavyGLu4gWe0jjztWgJ-mq1RsQ@mail.gmail.com>
--===============0856962293532929930==
Content-Type: multipart/alternative; boundary="000000000000bb24700642ee0e3e"

--000000000000bb24700642ee0e3e
Content-Type: text/plain; charset="UTF-8"

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;
  }
    %}
======================================
Testing:
python
Python 3.12.7 (main, Oct 20 2025, 13:39:44) [GCC 11.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import test_PyList_New
>>> test_PyList_New.test_PyList_New(20)
test_PyList_New requested buffer length 20
Segmentation fault (core dumped)

This worked with earlier swig versions, at least 2.XX
Please help.
Thanks a lot in advance.
Alexander

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

<div dir=3D"ltr"><div>Hello,</div><div>call of=C2=A0PyList_New causes cored=
ump=C2=A0if called from inline function.</div><div>Environment:</div><div>O=
S: Ubuntu, or Alma Linux=C2=A09 (give same result)</div><div>swig:</div><di=
v>SWIG Version 4.0.2<br>Compiled with g++ [x86_64-pc-linux-gnu]<br>Configur=
ed options: +pcre</div><div><br></div><div>python:=C2=A0Python 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(&quot;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>=C2=A0 }<br>=C2=A0 =
=C2=A0 %}<br>=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=3D</div><div>Testing:</=
div><div>python<br>Python 3.12.7 (main, Oct 20 2025, 13:39:44) [GCC 11.4.0]=
 on linux<br>Type &quot;help&quot;, &quot;copyright&quot;, &quot;credits&qu=
ot; or &quot;license&quot; for more information.<br>&gt;&gt;&gt; import tes=
t_PyList_New<br>&gt;&gt;&gt; test_PyList_New.test_PyList_New(20)<br>test_Py=
List_New requested buffer length 20<br>Segmentation fault (core dumped)<br>=
<br></div><div>This worked with earlier swig versions, at least 2.XX=C2=A0<=
/div><div>Please help.</div><div>Thanks a lot in advance.</div><div>Alexand=
er</div><div><br></div></div>

--000000000000bb24700642ee0e3e--


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


--===============0856962293532929930==
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

--===============0856962293532929930==--