Wednesday, October 1, 2025
HomeGolangAre GODEBUG and different env vars ignored when loading a Go DLL...

Are GODEBUG and different env vars ignored when loading a Go DLL from overseas code? – Technical Dialogue


Whats up,

We have a posh integration testing setup the place we use Python to check information interchange between varied runtimes corresponding to Go, Java, and so forth. For that function, we compile a shared library with C-compatible entrypoints utilizing go construct -buildmode=c-shared. The shared library is then loaded and invoked at runtime utilizing Python’s cffi library.

I’m presently making an attempt to customise Go habits on this integration testing setup by setting atmosphere variables corresponding to GOMEMLIMIT and GODEBUG earlier than loading the Go-generated DLL. Nonetheless, I get the impression that these atmosphere variables are ignored (for instance, utilizing gctrace=1,clobberfree=1 I don’t really get any debug output).

Is my assumption above proper? In that case, is there another approach to affect Go runtime habits?

For reference, the associated Python snippet:

Edit: I’ve began in search of clues within the Go supply code and I feel I get it. Like most different languages, Python’s os.environ calls the libc getenv and setenv capabilities to entry the userspace atmosphere. Nonetheless, Go works otherwise: it parses the atmosphere variables as they had been set when the method was initialized (right here, the Python course of). Due to this fact, if I set atmosphere variables from contained in the Python course of loading the Go DLL, the brand new values are usually not seen by Go. I’ve to set the atmosphere variables kind the mum or dad course of.

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments