Ctypes eqivalent in GJS?

Is there a way to call a C function (from glibc) in GJS? Something like ctypes in Python

There is not.

I suppose in principle you could write such a library with GObject-Introspection support. That could then be used by any GI consuming language (PyGObject, GJS, etc), but there currently is no such library I’m aware of.

A glib ctype/ffi certainly could be interesting, but I must admit outside girepository itself I’ve not heard of anything

Of course depending on what your trying to do, a specific wrapper may already exist

Even if I would write such a library, I guess it won’t help if I need to do it from GNOME Shell extension (because I can’t bundle a binary library with the extension, at least if I want to publish it on extensions.gnome.org)

I need to call tcgetpgrp(): https://gitlab.gnome.org/GNOME/vte/-/issues/327

https://wiki.mozilla.org/JSctypes

Although it is against the rules to ship binary executables/libraries in extensions, that is as much about security as the possibility of varying user CPU architectures and stuff.

I’m not sure exactly how you planned on using this, but we don’t prohibit Python scripts in extensions if that’s an option for you.

Unfortunately, the fd that I want to pass to tcgetpgrp() has O_CLOEXEC flag - so it will become invalid in a Python subprocess. And I can’t find a function, accessible from GJS, that can dup a file descriptor and change flags

I guess the only option is rewriting the entire terminal emulator application (it’s bundled in the extension) in Python…