mwunsch / overscan

A live coding environment for live streaming video
https://www.overscan.tv/
GNU Lesser General Public License v3.0
36 stars 2 forks source link

Issue with gobject introspection #4

Open MilheiroSantos opened 3 years ago

MilheiroSantos commented 3 years ago

Hi!

I'm trying to get introspection working in racket and I have an issue.

The following racket code does not work:

#lang racket    

(require ffi/unsafe/introspection)    

(define gtk (introspection 'Gtk "3.0"))    
(define vte (introspection 'Vte "2.91"))    
(define glib (introspection 'GLib))          

((gtk 'init) 0 #f)    

(define window ((gtk 'Window) 'new 'toplevel))    
(define terminal ((vte 'Terminal) 'new))    

(connect window 'destroy (lambda (a b) ((gtk 'main_quit))))    

(gobject-send terminal     
  'spawn_sync    
  'default            
  "/home/pedro"            
  #("/bin/bash")    
  #f    
  'default    
  #f    
  #f    
  #f    
)

(gobject-send window 'add terminal)    
(gobject-send window 'show_all)        
((gtk 'main))    

The equivalent python code works:

import gi    
gi.require_version('Gtk', '3.0')    
gi.require_version('Vte', '2.91')    
from gi.repository import Gtk, Vte, GLib    

window = Gtk.Window()    
terminal = Vte.Terminal()    

window.connect("destroy", Gtk.main_quit)    

terminal.spawn_sync(    
    Vte.PtyFlags.DEFAULT,    
    "/home/pedro",    
    ["/bin/bash"],    
    None,    
    GLib.SpawnFlags.DEFAULT,    
    None,    
    None,    
)    

window.add(terminal)    
window.show_all()       
Gtk.main()              

Do you know what could be the issue? I'm still getting the hang of racket, but I'll be available to help in debugging/fixing the issue.

kengruven commented 1 year ago

Since "does not work" is not terribly descriptive, I tried this. Interestingly, it sometimes works, and sometimes fails. When it fails, it prints text like:

0
#f
47

(racket:10538): VTE-WARNING **: 22:07:51.851: (../src/vtepty.cc:670):bool _vte_pty_spawn_sync(VtePty*, const char*, const char* const*, const char* const*, GSpawnFlags, GSpawnChildSetupFunc, gpointer, GDestroyNotify, GPid*, int, GCancellable*, GError**): runtime check failed: ((spawn_flags & forbidden_spawn_flags()) == 0)
invalid memory reference.  Some debugging context lost
  context...:
   /home/ken/.local/share/racket/8.7/pkgs/overscan/ffi/unsafe/introspection.rkt:1006:2
   body of "/tmp/g.rkt"

When it succeeds (i.e., opens a window titled "racket" with a blinking cursor), it prints text like:

0
#f
48

(racket:10542): VTE-CRITICAL **: 22:07:53.905: gboolean vte_terminal_spawn_sync(VteTerminal*, VtePtyFlags, const char*, char**, char**, GSpawnFlags, GSpawnChildSetupFunc, gpointer, GPid*, GCancellable*, GError**): assertion '(spawn_flags & (VTE_SPAWN_NO_SYSTEMD_SCOPE | VTE_SPAWN_REQUIRE_SYSTEMD_SCOPE)) == 0' failed
#f
1148526873

Something is odd: both the errors logged by libvte are about spawn_flags, but it looks (to my newbie eye) like this test program is passing DEFAULT, i.e., 0.