denosaurs / deno_python

🐍 Python interpreter bindings for Deno and Bun.
https://deno.land/x/python
MIT License
684 stars 20 forks source link

TypeError: 'builtin_function_or_method' object does not support vectorcall #55

Closed sigmaSd closed 11 months ago

sigmaSd commented 1 year ago

This is the reproduction I have, you need to keep moving the slider fast until it throws the above error or sefaults

import {
  Adw,
  Gtk,
  Gtk_,
  kw,
  NamedArgument,
  python,
} from "https://raw.githubusercontent.com/sigmaSd/deno-gtk-py/13f3da6c4890d62e09312747c905fa85263f5ca8/mod.ts";

class MainWindow extends Gtk.ApplicationWindow {
  #slider: Gtk_.Scale;
  constructor(kwArg: NamedArgument) {
    super(kwArg);
    this.set_default_size(600, 250);
    this.#slider = Gtk.Scale();
    this.#slider.set_range(0, 10);
    this.#slider.connect("value-changed", this.slider_changed);

    this.set_child(this.#slider);
  }

  slider_changed = python.callback(
    (_kwargs, slider: Gtk_.Scale): undefined => {
      slider.get_value(); // this line trigger the error/segfault
    },
  );
}

class App extends Adw.Application {
  #win: MainWindow | undefined;
  constructor(kwArg: NamedArgument) {
    super(kwArg);
    this.connect("activate", this.onActivate);
  }
  onActivate = python.callback((_kwarg, app: Gtk_.Application): undefined => {
    this.#win = new MainWindow(new NamedArgument("application", app));
    this.#win.present();
  });
}

const app = new App(kw`application_id=${"com.example.com"}`);
app.run(Deno.args);
sigmaSd commented 1 year ago

coredump:

           PID: 40828 (deno)
           UID: 1000 (mrcool)
           GID: 1000 (mrcool)
        Signal: 11 (SEGV)
     Timestamp: Sat 2023-11-11 21:43:17 CET (1min 3s ago)
  Command Line: /home/mrcool/.deno/bin/deno run --unstable-ffi -A examples/smoke/main.ts
    Executable: /home/mrcool/.deno/bin/deno
 Control Group: /user.slice/user-1000.slice/user@1000.service/app.slice/flatpak-session-helper.service
          Unit: user@1000.service
     User Unit: flatpak-session-helper.service
         Slice: user-1000.slice
     Owner UID: 1000 (mrcool)
       Boot ID: 5e84d00665ca4b95921ad32c5aaa5016
    Machine ID: e37a32c7cb794197a17b26360ae4cb77
      Hostname: fedora
       Storage: /var/lib/systemd/coredump/core.deno.1000.5e84d00665ca4b95921ad32c5aaa5016.40828.1699735397000000.zst (present)
  Size on Disk: 10.9M
       Message: Process 40828 (deno) of user 1000 dumped core.

                Module libGL.so.1 from rpm libglvnd-1.7.0-1.fc39.x86_64
                Module libpciaccess.so.0 from rpm libpciaccess-0.16-9.fc39.x86_64
                Module libtinfo.so.6 from rpm ncurses-6.4-7.20230520.fc39.x86_64
                Module libedit.so.0 from rpm libedit-3.1-48.20230828cvs.fc39.x86_64
                Module libdrm_intel.so.1 from rpm libdrm-2.4.117-1.fc39.x86_64
                Module libdrm_nouveau.so.2 from rpm libdrm-2.4.117-1.fc39.x86_64
                Module libdrm_amdgpu.so.1 from rpm libdrm-2.4.117-1.fc39.x86_64
                Module libdrm_radeon.so.1 from rpm libdrm-2.4.117-1.fc39.x86_64
                Module libsensors.so.4 from rpm lm_sensors-3.6.0-14.fc39.x86_64
                Module crocus_dri.so from rpm mesa-23.2.1-2.fc39.x86_64
                Module libxshmfence.so.1 from rpm libxshmfence-1.3-13.fc39.x86_64
                Module libxcb-sync.so.1 from rpm libxcb-1.13.1-12.fc39.x86_64
                Module libxcb-present.so.0 from rpm libxcb-1.13.1-12.fc39.x86_64
                Module libxcb-dri3.so.0 from rpm libxcb-1.13.1-12.fc39.x86_64
                Module libxcb-xfixes.so.0 from rpm libxcb-1.13.1-12.fc39.x86_64
                Module libxcb-dri2.so.0 from rpm libxcb-1.13.1-12.fc39.x86_64
                Module libglapi.so.0 from rpm mesa-23.2.1-2.fc39.x86_64
                Module libEGL_mesa.so.0 from rpm mesa-23.2.1-2.fc39.x86_64
                Module librsvg-2.so.2 from rpm librsvg2-2.57.0-1.fc39.x86_64
                Module libpixbufloader-svg.so from rpm librsvg2-2.57.0-1.fc39.x86_64
                Module libssl.so.3 from rpm openssl-3.1.1-4.fc39.x86_64
                Module libnghttp2.so.14 from rpm nghttp2-1.55.1-4.fc39.x86_64
                Module libstemmer.so.0 from rpm snowball-2.2.0-7.fc39.x86_64
                Module libyaml-0.so.2 from rpm libyaml-0.2.5-12.fc39.x86_64
                Module libxmlb.so.2 from rpm libxmlb-0.3.14-1.fc39.x86_64
                Module libcurl.so.4 from rpm curl-8.2.1-3.fc39.x86_64
                Module libappstream.so.4 from rpm appstream-0.16.1-4.fc39.x86_64
                Module libadwaita-1.so.0 from rpm libadwaita-1.4.0-1.fc39.x86_64
                Module libgvfscommon.so from rpm gvfs-1.52.1-1.fc39.x86_64
                Module libgvfsdbus.so from rpm gvfs-1.52.1-1.fc39.x86_64
                Module libdconfsettings.so from rpm dconf-0.40.0-9.fc39.x86_64
                Module libgstaudio-1.0.so.0 from rpm gstreamer1-plugins-base-1.22.5-1.fc39.x86_64
                Module libxcb-randr.so.0 from rpm libxcb-1.13.1-12.fc39.x86_64
                Module libexpat.so.1 from rpm expat-2.5.0-3.fc39.x86_64
                Module libwayland-server.so.0 from rpm wayland-1.22.0-2.fc39.x86_64
                Module libGLdispatch.so.0 from rpm libglvnd-1.7.0-1.fc39.x86_64
                Module libelf.so.1 from rpm elfutils-0.190-1.fc39.x86_64
                Module libgstpbutils-1.0.so.0 from rpm gstreamer1-plugins-base-1.22.5-1.fc39.x86_64
                Module libgsttag-1.0.so.0 from rpm gstreamer1-plugins-base-1.22.5-1.fc39.x86_64
                Module libgbm.so.1 from rpm mesa-23.2.1-2.fc39.x86_64
                Module libdrm.so.2 from rpm libdrm-2.4.117-1.fc39.x86_64
                Module libgudev-1.0.so.0 from rpm libgudev-238-2.fc39.x86_64
                Module libX11-xcb.so.1 from rpm libX11-1.8.7-1.fc39.x86_64
                Module libwayland-cursor.so.0 from rpm wayland-1.22.0-2.fc39.x86_64
                Module libGLX.so.0 from rpm libglvnd-1.7.0-1.fc39.x86_64
                Module libEGL.so.1 from rpm libglvnd-1.7.0-1.fc39.x86_64
                Module libgstallocators-1.0.so.0 from rpm gstreamer1-plugins-base-1.22.5-1.fc39.x86_64
                Module libdw.so.1 from rpm elfutils-0.190-1.fc39.x86_64
                Module libunwind.so.8 from rpm libunwind-1.7.0-0.2.rc2.fc39.x86_64
                Module liborc-0.4.so.0 from rpm orc-0.4.33-3.fc39.x86_64
                Module libgstbase-1.0.so.0 from rpm gstreamer1-1.22.6-1.fc39.x86_64
                Module libgstplay-1.0.so.0 from rpm gstreamer1-plugins-bad-free-1.22.5-2.fc39.x86_64
                Module libgstgl-1.0.so.0 from rpm gstreamer1-plugins-base-1.22.5-1.fc39.x86_64
                Module libgstreamer-1.0.so.0 from rpm gstreamer1-1.22.6-1.fc39.x86_64
                Module libgstvideo-1.0.so.0 from rpm gstreamer1-plugins-base-1.22.5-1.fc39.x86_64
                Module libgstplayer-1.0.so.0 from rpm gstreamer1-plugins-bad-free-1.22.5-2.fc39.x86_64
                Module libmedia-gstreamer.so from rpm gtk4-4.12.3-1.fc39.x86_64
                Module libibus-1.0.so.5 from rpm ibus-1.5.29~rc1-3.fc39.x86_64
                Module libim-ibus.so from rpm ibus-1.5.29~rc1-3.fc39.x86_64
                Module libprintbackend-file.so from rpm gtk4-4.12.3-1.fc39.x86_64
                Module liblz4.so.1 from rpm lz4-1.9.4-4.fc39.x86_64
                Module libsystemd.so.0 from rpm systemd-254.5-2.fc39.x86_64
                Module libcap.so.2 from rpm libcap-2.48-7.fc39.x86_64
                Module libgmp.so.10 from rpm gmp-6.2.1-5.fc39.x86_64
                Module libhogweed.so.6 from rpm nettle-3.9.1-2.fc39.x86_64
                Module libnettle.so.8 from rpm nettle-3.9.1-2.fc39.x86_64
                Module libtasn1.so.6 from rpm libtasn1-4.19.0-3.fc39.x86_64
                Module libunistring.so.5 from rpm libunistring-1.1-5.fc39.x86_64
                Module libidn2.so.0 from rpm libidn2-2.3.4-3.fc39.x86_64
                Module libp11-kit.so.0 from rpm p11-kit-0.25.2-1.fc39.x86_64
                Module libdbus-1.so.3 from rpm dbus-1.14.10-1.fc39.x86_64
                Module libcrypto.so.3 from rpm openssl-3.1.1-4.fc39.x86_64
                Module libkeyutils.so.1 from rpm keyutils-1.6.1-7.fc39.x86_64
                Module libkrb5support.so.0 from rpm krb5-1.21.2-2.fc39.x86_64
                Module libcom_err.so.2 from rpm e2fsprogs-1.47.0-2.fc39.x86_64
                Module libk5crypto.so.3 from rpm krb5-1.21.2-2.fc39.x86_64
                Module libkrb5.so.3 from rpm krb5-1.21.2-2.fc39.x86_64
                Module libudev.so.1 from rpm systemd-254.5-2.fc39.x86_64
                Module liblcms2.so.2 from rpm lcms2-2.15-2.fc39.x86_64
                Module libgnutls.so.30 from rpm gnutls-3.8.1-1.fc39.x86_64
                Module libavahi-client.so.3 from rpm avahi-0.8-24.fc39.x86_64
                Module libavahi-common.so.3 from rpm avahi-0.8-24.fc39.x86_64
                Module libgssapi_krb5.so.2 from rpm krb5-1.21.2-2.fc39.x86_64
                Module libcolord.so.2 from rpm colord-1.4.6-6.fc39.x86_64
                Module libcups.so.2 from rpm cups-2.4.7-1.fc39.x86_64
                Module libprintbackend-cups.so from rpm gtk4-4.12.3-1.fc39.x86_64
                Module libsharpyuv.so.0 from rpm libwebp-1.3.2-2.fc39.x86_64
                Module libjbig.so.2.1 from rpm jbigkit-2.1-26.fc39.x86_64
                Module libLerc.so.4 from rpm liblerc-4.0.0-4.fc39.x86_64
                Module libzstd.so.1 from rpm zstd-1.5.5-4.fc39.x86_64
                Module libwebp.so.7 from rpm libwebp-1.3.2-2.fc39.x86_64
                Module libjson-glib-1.0.so.0 from rpm json-glib-1.8.0-1.fc39.x86_64
                Module libcairo-script-interpreter.so.2 from rpm cairo-1.18.0-1.fc39.x86_64
                Module libXinerama.so.1 from rpm libXinerama-1.1.5-3.fc39.x86_64
                Module libXrandr.so.2 from rpm libXrandr-1.5.4-1.fc39.x86_64
                Module libXfixes.so.3 from rpm libXfixes-6.0.0-6.fc39.x86_64
                Module libXdamage.so.1 from rpm libXdamage-1.1.5-10.fc39.x86_64
                Module libXcursor.so.1 from rpm libXcursor-1.2.1-4.fc39.x86_64
                Module libwayland-egl.so.1 from rpm wayland-1.22.0-2.fc39.x86_64
                Module libwayland-client.so.0 from rpm wayland-1.22.0-2.fc39.x86_64
                Module libxkbcommon.so.0 from rpm libxkbcommon-1.6.0-1.fc39.x86_64
                Module libtiff.so.5 from rpm libtiff-4.4.0-8.fc39.x86_64
                Module libtracker-sparql-3.0.so.0 from rpm tracker-3.6.0-1.fc39.x86_64
                Module libpangoft2-1.0.so.0 from rpm pango-1.51.0-1.fc39.x86_64
                Module libXi.so.6 from rpm libXi-1.8.1-2.fc39.x86_64
                Module libgraphene-1.0.so.0 from rpm graphene-1.10.6-6.fc39.x86_64
                Module libepoxy.so.0 from rpm libepoxy-1.5.10-4.fc39.x86_64
                Module libpangocairo-1.0.so.0 from rpm pango-1.51.0-1.fc39.x86_64
                Module libgtk-4.so.1 from rpm gtk4-4.12.3-1.fc39.x86_64
                Module libjpeg.so.62 from rpm libjpeg-turbo-2.1.4-3.fc39.x86_64
                Module libgdk_pixbuf-2.0.so.0 from rpm gdk-pixbuf2-2.42.10-5.fc39.x86_64
                Module libdatrie.so.1 from rpm libdatrie-0.2.13-7.fc39.x86_64
                Module libthai.so.0 from rpm libthai-0.1.29-6.fc39.x86_64
                Module libfribidi.so.0 from rpm fribidi-1.0.13-2.fc39.x86_64
                Module libpango-1.0.so.0 from rpm pango-1.51.0-1.fc39.x86_64
                Module array.cpython-312-x86_64-linux-gnu.so from rpm python3.12-3.12.0-1.fc39.x86_64
                Module select.cpython-312-x86_64-linux-gnu.so from rpm python3.12-3.12.0-1.fc39.x86_64
                Module math.cpython-312-x86_64-linux-gnu.so from rpm python3.12-3.12.0-1.fc39.x86_64
                Module _socket.cpython-312-x86_64-linux-gnu.so from rpm python3.12-3.12.0-1.fc39.x86_64
                Module _cairo.cpython-312-x86_64-linux-gnu.so from rpm pycairo-1.25.1-1.fc39.x86_64
                Module libbrotlicommon.so.1 from rpm brotli-1.1.0-1.fc39.x86_64
                Module libgraphite2.so.3 from rpm graphite2-1.3.14-12.fc39.x86_64
                Module liblzma.so.5 from rpm xz-5.4.4-1.fc39.x86_64
                Module libXau.so.6 from rpm libXau-1.0.11-3.fc39.x86_64
                Module libbrotlidec.so.1 from rpm brotli-1.1.0-1.fc39.x86_64
                Module libharfbuzz.so.0 from rpm harfbuzz-8.2.1-2.fc39.x86_64
                Module libbz2.so.1 from rpm bzip2-1.0.8-16.fc39.x86_64
                Module libxml2.so.2 from rpm libxml2-2.10.4-3.fc39.x86_64
                Module libpixman-1.so.0 from rpm pixman-0.42.2-2.fc39.x86_64
                Module libxcb-shm.so.0 from rpm libxcb-1.13.1-12.fc39.x86_64
                Module libxcb-render.so.0 from rpm libxcb-1.13.1-12.fc39.x86_64
                Module libxcb.so.1 from rpm libxcb-1.13.1-12.fc39.x86_64
                Module libXrender.so.1 from rpm libXrender-0.9.11-3.fc39.x86_64
                Module libXext.so.6 from rpm libXext-1.3.5-3.fc39.x86_64
                Module libX11.so.6 from rpm libX11-1.8.7-1.fc39.x86_64
                Module libfreetype.so.6 from rpm freetype-2.13.1-2.fc39.x86_64
                Module libfontconfig.so.1 from rpm fontconfig-2.14.2-5.fc39.x86_64
                Module libpng16.so.16 from rpm libpng-1.6.37-15.fc39.x86_64
                Module libcairo-gobject.so.2 from rpm cairo-1.18.0-1.fc39.x86_64
                Module libcairo.so.2 from rpm cairo-1.18.0-1.fc39.x86_64
                Module _gi_cairo.cpython-312-x86_64-linux-gnu.so from rpm pygobject3-3.46.0-1.fc39.x86_64
                Module libblkid.so.1 from rpm util-linux-2.39.2-1.fc39.x86_64
                Module libselinux.so.1 from rpm libselinux-3.5-5.fc39.x86_64
                Module libmount.so.1 from rpm util-linux-2.39.2-1.fc39.x86_64
                Module libz.so.1 from rpm zlib-1.2.13-4.fc39.x86_64
                Module libgio-2.0.so.0 from rpm glib2-2.78.1-1.fc39.x86_64
                Module libgmodule-2.0.so.0 from rpm glib2-2.78.1-1.fc39.x86_64
                Module libpcre2-8.so.0 from rpm pcre2-10.42-1.fc39.2.x86_64
                Module libffi.so.8 from rpm libffi-3.4.4-4.fc39.x86_64
                Module libgobject-2.0.so.0 from rpm glib2-2.78.1-1.fc39.x86_64
                Module libgirepository-1.0.so.1 from rpm gobject-introspection-1.78.1-1.fc39.x86_64
                Module libglib-2.0.so.0 from rpm glib2-2.78.1-1.fc39.x86_64
                Module _gi.cpython-312-x86_64-linux-gnu.so from rpm pygobject3-3.46.0-1.fc39.x86_64
                Module libpython3.12.so from rpm python3.12-3.12.0-1.fc39.x86_64
                Stack trace of thread 40828:
                #0  0x00007f2345410954 cfunction_call (libpython3.12.so + 0x210954)
                #1  0x00007f234541f6b9 _PyObject_Call (libpython3.12.so + 0x21f6b9)
                #2  0x00007f234590cfae pygi_signal_closure_marshal.lto_priv.0 (_gi.cpython-312-x86_64-linux-gnu.so + 0x33fae)
                #3  0x00007f2344d6b52a g_closure_invoke (libgobject-2.0.so.0 + 0x1452a)
                #4  0x00007f2344d99fec signal_emit_unlocked_R.isra.0 (libgobject-2.0.so.0 + 0x42fec)
                #5  0x00007f2344d8ad59 signal_emit_valist_unlocked (libgobject-2.0.so.0 + 0x33d59)
                #6  0x00007f2344d8af91 g_signal_emit_valist (libgobject-2.0.so.0 + 0x33f91)
                #7  0x00007f2344d8b053 g_signal_emit (libgobject-2.0.so.0 + 0x34053)
                #8  0x00007f233f5cb4c3 gtk_range_adjustment_value_changed (libgtk-4.so.1 + 0x1cb4c3)
                #9  0x00007f2344d6b52a g_closure_invoke (libgobject-2.0.so.0 + 0x1452a)
                #10 0x00007f2344d99fec signal_emit_unlocked_R.isra.0 (libgobject-2.0.so.0 + 0x42fec)
                #11 0x00007f2344d8ad59 signal_emit_valist_unlocked (libgobject-2.0.so.0 + 0x33d59)
                #12 0x00007f2344d8af91 g_signal_emit_valist (libgobject-2.0.so.0 + 0x33f91)
                #13 0x00007f2344d8b053 g_signal_emit (libgobject-2.0.so.0 + 0x34053)
                #14 0x00007f233f4c11a7 adjustment_set_value (libgtk-4.so.1 + 0xc11a7)
                #15 0x00007f233f5cb144 gtk_range_real_change_value (libgtk-4.so.1 + 0x1cb144)
                #16 0x00007f233f4b3daa _gtk_marshal_BOOLEAN__ENUM_DOUBLEv (libgtk-4.so.1 + 0xb3daa)
                #17 0x00007f2344d8ae85 signal_emit_valist_unlocked (libgobject-2.0.so.0 + 0x33e85)
                #18 0x00007f2344d8af91 g_signal_emit_valist (libgobject-2.0.so.0 + 0x33f91)
                #19 0x00007f2344d8b053 g_signal_emit (libgobject-2.0.so.0 + 0x34053)
                #20 0x00007f233f5cbe9a update_slider_position (libgtk-4.so.1 + 0x1cbe9a)
                #21 0x00007f233f5cc219 gtk_range_drag_gesture_update (libgtk-4.so.1 + 0x1cc219)
                #22 0x00007f233f4b431b _gtk_marshal_VOID__DOUBLE_DOUBLEv (libgtk-4.so.1 + 0xb431b)
                #23 0x00007f2344d8ae85 signal_emit_valist_unlocked (libgobject-2.0.so.0 + 0x33e85)
                #24 0x00007f2344d8af91 g_signal_emit_valist (libgobject-2.0.so.0 + 0x33f91)
                #25 0x00007f2344d8b053 g_signal_emit (libgobject-2.0.so.0 + 0x34053)
                #26 0x00007f2344d6f62a g_cclosure_marshal_VOID__BOXEDv (libgobject-2.0.so.0 + 0x1862a)
                #27 0x00007f2344d8ae85 signal_emit_valist_unlocked (libgobject-2.0.so.0 + 0x33e85)
                #28 0x00007f2344d8af91 g_signal_emit_valist (libgobject-2.0.so.0 + 0x33f91)
                #29 0x00007f2344d8b053 g_signal_emit (libgobject-2.0.so.0 + 0x34053)
                #30 0x00007f233f555ca8 gtk_gesture_handle_event.lto_priv.0 (libgtk-4.so.1 + 0x155ca8)
                #31 0x00007f233f559119 gtk_gesture_single_handle_event (libgtk-4.so.1 + 0x159119)
                #32 0x00007f233f66f8df gtk_widget_run_controllers (libgtk-4.so.1 + 0x26f8df)
                #33 0x00007f233f66fc4d gtk_widget_event (libgtk-4.so.1 + 0x26fc4d)
                #34 0x00007f233f8b561a gtk_propagate_event_internal.isra.0 (libgtk-4.so.1 + 0x4b561a)
                #35 0x00007f233f59737f gtk_main_do_event.part.0 (libgtk-4.so.1 + 0x19737f)
                #36 0x00007f233f685904 surface_event (libgtk-4.so.1 + 0x285904)
                #37 0x00007f233f7dd81c _gdk_marshal_BOOLEAN__POINTERv (libgtk-4.so.1 + 0x3dd81c)
                #38 0x00007f233f852348 gdk_surface_event_marshallerv (libgtk-4.so.1 + 0x452348)
                #39 0x00007f2344d8ae85 signal_emit_valist_unlocked (libgobject-2.0.so.0 + 0x33e85)
                #40 0x00007f2344d8af91 g_signal_emit_valist (libgobject-2.0.so.0 + 0x33f91)
                #41 0x00007f2344d8b053 g_signal_emit (libgobject-2.0.so.0 + 0x34053)
                #42 0x00007f233f8ac647 gdk_surface_handle_event.isra.0 (libgtk-4.so.1 + 0x4ac647)
                #43 0x00007f233f852fa5 gdk_surface_flush_events (libgtk-4.so.1 + 0x452fa5)
                #44 0x00007f2344d8ae85 signal_emit_valist_unlocked (libgobject-2.0.so.0 + 0x33e85)
                #45 0x00007f2344d8af91 g_signal_emit_valist (libgobject-2.0.so.0 + 0x33f91)
                #46 0x00007f2344d8b053 g_signal_emit (libgobject-2.0.so.0 + 0x34053)
                #47 0x00007f233f8378d5 gdk_frame_clock_flush_idle (libgtk-4.so.1 + 0x4378d5)
                #48 0x00007f2344e13799 g_timeout_dispatch (libglib-2.0.so.0 + 0x5c799)
                #49 0x00007f2344e12e5c g_main_context_dispatch_unlocked.lto_priv.0 (libglib-2.0.so.0 + 0x5be5c)
                #50 0x00007f2344e6ddd8 g_main_context_iterate_unlocked.isra.0 (libglib-2.0.so.0 + 0xb6dd8)
                #51 0x00007f2344e10ad3 g_main_context_iteration (libglib-2.0.so.0 + 0x59ad3)
                #52 0x00007f2344bcfc5d g_application_run (libgio-2.0.so.0 + 0xe9c5d)
                #53 0x00007f2345897056 ffi_call_unix64 (libffi.so.8 + 0x9056)
                #54 0x00007f23458935ef ffi_call_int.lto_priv.0 (libffi.so.8 + 0x55ef)
                #55 0x00007f23458963fe ffi_call (libffi.so.8 + 0x83fe)
                #56 0x00007f2345909bdb pygi_invoke_c_callable (_gi.cpython-312-x86_64-linux-gnu.so + 0x30bdb)
                #57 0x00007f234590812a _wrap_g_callable_info_invoke (_gi.cpython-312-x86_64-linux-gnu.so + 0x2f12a)
                #58 0x00007f234541f6b9 _PyObject_Call (libpython3.12.so + 0x21f6b9)
                #59 0x00007f2345310043 _PyEval_EvalFrameDefault.cold (libpython3.12.so + 0x110043)
                #60 0x00007f23454325bd method_vectorcall (libpython3.12.so + 0x2325bd)
                #61 0x0000557510432052 n/a (/home/mrcool/.deno/bin/deno + 0x26df052)
                #62 0x00007ffc9ee61a30 n/a (n/a + 0x0)
                ELF object binary architecture: AMD x86-64
sigmaSd commented 11 months ago

Here is an easier reproduction

import {
  Adw,
  Gtk,
  Gtk_,
  kw,
  NamedArgument,
  python,
} from "https://raw.githubusercontent.com/sigmaSd/deno-gtk-py/0.1.4/mod.ts";

class MainWindow extends Gtk.ApplicationWindow {
  #blobs: [number, number][] = [];
  #dw: Gtk_.DrawingArea;
  constructor(kwArg: NamedArgument) {
    super(kwArg);
    this.set_default_size(600, 250);
    this.#dw = Gtk.DrawingArea();

    this.#dw.set_draw_func(this.draw);
    const evk = Gtk.GestureClick.new();
    evk.connect("pressed", this.dw_click);
    this.#dw.add_controller(evk);

    this.set_child(this.#dw);
  }

  draw = python.callback(
    (_kwargs, _area, c): undefined => {
      c.set_source_rgb(1, 0, 1);
      for (const [x, y] of this.#blobs) {
        c.arc(x, y, 10, 0, 2 * 3.1415926);
        c.fill();
      }
    },
  );
  dw_click = python.callback(
    (_kwargs, _gesture: Gtk_.GestureClick, _data, x, y) => {
      this.#blobs.push([x, y]);
      this.#dw.queue_draw(); // Force a redraw
    },
  );
}

class App extends Adw.Application {
  #win: MainWindow | undefined;
  constructor(kwArg: NamedArgument) {
    super(kwArg);
    this.connect("activate", this.onActivate);
  }
  onActivate = python.callback((_kwarg, app: Gtk_.Application): undefined => {
    this.#win = new MainWindow(new NamedArgument("application", app));
    this.#win.present();
  });
}

const app = new App(kw`application_id=${"com.example.com"}`);
app.run(Deno.args);

click on the board multipe times fast enough and it will segfault

seems like this vector_call thing is an optimization that is not correctly handled ?

sigmaSd commented 11 months ago

To catch the segfault , you need to run gdb like this G_DEBUG=fatal-criticals gdb --args deno run -A --unstable code.ts

backtrace

#0  0x00007ffff7e92b20 in main_arena () at /lib64/libc.so.6
#1  0x00007ffff5a10956 in cfunction_call () at /lib64/libpython3.12.so
#2  0x00007ffff5a1f6b9 in _PyObject_Call () at /lib64/libpython3.12.so
#3  0x00007ffff5eac802 in _pygi_closure_handle () at /usr/lib64/python3.12/site-packages/gi/_gi.cpython-312-x86_64-linux-gnu.so
#4  0x00007ffff5e5fa81 in ffi_closure_unix64_inner () at /lib64/libffi.so.8
#5  0x00007ffff5e60278 in ffi_closure_unix64 () at /lib64/libffi.so.8
#6  0x00007fffd2310f60 in gtk_drawing_area_snapshot () at /lib64/libgtk-4.so.1
#7  0x00007fffd248467c in gtk_widget_create_render_node () at /lib64/libgtk-4.so.1
#8  0x00007fffd2484bf8 in gtk_widget_do_snapshot () at /lib64/libgtk-4.so.1
#9  0x00007fffd24855d2 in gtk_widget_snapshot_child () at /lib64/libgtk-4.so.1
#10 0x00007fffd246a9ee in gtk_widget_real_snapshot () at /lib64/libgtk-4.so.1
#11 0x00007fffd248467c in gtk_widget_create_render_node () at /lib64/libgtk-4.so.1
#12 0x00007fffd2484bf8 in gtk_widget_do_snapshot () at /lib64/libgtk-4.so.1
#13 0x00007fffd24855d2 in gtk_widget_snapshot_child () at /lib64/libgtk-4.so.1
#14 0x00007fffd246a9ee in gtk_widget_real_snapshot () at /lib64/libgtk-4.so.1
#15 0x00007fffd248467c in gtk_widget_create_render_node () at /lib64/libgtk-4.so.1
#16 0x00007fffd2484bf8 in gtk_widget_do_snapshot () at /lib64/libgtk-4.so.1
#17 0x00007fffd24855d2 in gtk_widget_snapshot_child () at /lib64/libgtk-4.so.1
#18 0x00007fffd246a9ee in gtk_widget_real_snapshot () at /lib64/libgtk-4.so.1
#19 0x00007fffd24849c0 in gtk_widget_create_render_node () at /lib64/libgtk-4.so.1
#20 0x00007fffd2484bf8 in gtk_widget_do_snapshot () at /lib64/libgtk-4.so.1
#21 0x00007fffd248539f in gtk_widget_render () at /lib64/libgtk-4.so.1
#22 0x00007fffd24859c9 in surface_render () at /lib64/libgtk-4.so.1
#23 0x00007fffd25dd967 in _gdk_marshal_BOOLEAN__BOXEDv () at /lib64/libgtk-4.so.1
#24 0x00007ffff5365e85 in signal_emit_valist_unlocked () at /lib64/libgobject-2.0.so.0
#25 0x00007ffff5365f91 in g_signal_emit_valist () at /lib64/libgobject-2.0.so.0
#26 0x00007ffff5366053 in g_signal_emit () at /lib64/libgobject-2.0.so.0
#27 0x00007fffd264b0b9 in gdk_surface_paint_on_clock () at /lib64/libgtk-4.so.1
#28 0x00007ffff5365e85 in signal_emit_valist_unlocked () at /lib64/libgobject-2.0.so.0
#29 0x00007ffff5365f91 in g_signal_emit_valist () at /lib64/libgobject-2.0.so.0
#30 0x00007ffff5366053 in g_signal_emit () at /lib64/libgobject-2.0.so.0
#31 0x00007fffd263798c in gdk_frame_clock_paint_idle () at /lib64/libgtk-4.so.1
#32 0x00007fffd2637b5e in gdk_frame_clock_flush_idle () at /lib64/libgtk-4.so.1
#33 0x00007ffff5413799 in g_timeout_dispatch () at /lib64/libglib-2.0.so.0
--Type <RET> for more, q to quit, c to continue without paging--quit
#34 0x00007ffff5412e5c in g_main_context_dispatch_unlocked.lto_priv () at /lib64/libglib-2.0.so.0
#35 0x00007ffff546ddd8 in g_main_context_iterate_unlocked.isra () at /lib64/libglib-2.0.so.0
#36 0x00007ffff5410ad3 in g_main_context_iteration () at /lib64/libglib-2.0.so.0
#37 0x00007ffff51aac5d in g_application_run () at /lib64/libgio-2.0.so.0
#38 0x00007ffff5e60056 in ffi_call_unix64 () at /lib64/libffi.so.8
#39 0x00007ffff5e5c5ef in ffi_call_int.lto_priv () at /lib64/libffi.so.8
#40 0x00007ffff5e5f3fe in ffi_call () at /lib64/libffi.so.8
#41 0x00007ffff5eadbdb in pygi_invoke_c_callable () at /usr/lib64/python3.12/site-packages/gi/_gi.cpython-312-x86_64-linux-gnu.so
#42 0x00007ffff5eac12a in _wrap_g_callable_info_invoke () at /usr/lib64/python3.12/site-packages/gi/_gi.cpython-312-x86_64-linux-gnu.so
#43 0x00007ffff5a1f6b9 in _PyObject_Call () at /lib64/libpython3.12.so
#44 0x00007ffff5910043 in _PyEval_EvalFrameDefault.cold () at /lib64/libpython3.12.so
#45 0x00007ffff5a325bd in method_vectorcall () at /lib64/libpython3.12.so
#46 0x0000555557c3b052 in ffi_call_unix64 ()
#47 0x000055555a23ae8c in ffi_call_int.llvm ()
#48 0x000055555a23abf1 in ffi_call ()
#49 0x000055555a201d09 in <extern "C" fn(A0) .> R as v8::support::CFnFrom<F>>::mapping::c_fn::h4d87b05f7d17b230 ()
#50 0x0000555558d2c95d in Builtins_CallApiCallbackGeneric ()
sigmaSd commented 11 months ago

I found the weirdest fix , logging with Deno.stdout.write, somehow fixes the problem

diff --git a/src/python.ts b/src/python.ts
index 66cf3bd..3bed6d8 100644
--- a/src/python.ts
+++ b/src/python.ts
@@ -470,6 +470,7 @@ export class PyObject {
             BigInt(Deno.UnsafePointer.value(Deno.UnsafePointer.of(nameBuf)!)),
             LE,
           );
+          Deno.stdout.write(struct);
           const fn = py.PyCFunction_NewEx(
             struct,
             PyObject.from(null).handle,

Also I noticed if I use console.log in that python.ts file I make the segfault more likely to happen.

sigmaSd commented 11 months ago

AapoAlas in deno discord helped me debugging this, it seems the root issue, is that when using PyCFunction_NewEx we're assuming struct will live long enough , but v8 does not know it should so it can be destroyed at any point.

The fix is to extend its lifetime, the only obvious place to stick it in is PyObject, I can open a pr with this idea for review