Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OpenBSD: stdout and stderr problem #23

Closed
marianielias opened this issue Dec 4, 2018 · 1 comment · Fixed by #50
Closed

OpenBSD: stdout and stderr problem #23

marianielias opened this issue Dec 4, 2018 · 1 comment · Fixed by #50

Comments

@marianielias
Copy link

Hi guys!
I'm trying to bring Wurlitzer to OpenBSD and the following problem arises:

Currently c_stdout_p and c_stderr_p is defined here:
https://github.com/minrk/wurlitzer/blob/1.0.1/wurlitzer.py#L32

Getting the symbol "stdout" for default and "__stderrp" for Mac OS X.

OpenBSD has neither:
https://github.com/openbsd/src/blob/master/include/stdio.h#L198

I tried to work it out myself but I'm not to savvy in C/Python interfacing.
I understand that __sF is an array with pointers to stdout (__sF[1]) and stderr (__sF[2]).
So we should get the __sF array and then cast __sF[n] to the equivalent of &__sF[n] ?

Again, maybe there is a more direct approach.

Cheers.
Elias.

@minrk
Copy link
Owner

minrk commented Aug 18, 2021

Looking at openbsd, I can't seem to get an easy way to access what we need without a compilation step, since we need two pieces of info:

  1. location of __sF (easy, same as others), and
  2. sizeof(FILE) to locate __sF[1] etc.

If we had easy access to sizeof(FILE), I think we'd be okay, but I can't figure out how to determine without compiling something. And if we are going to compile anyway, it can be pretty simple with cffi:

        _ffi = cffi.FFI()
        _ffi.cdef("const size_t c_stdout_p();")
        _ffi.cdef("const size_t c_stderr_p();")
        _lib = _ffi.verify(
            '\n'.join(
                [
                    "#include <stdio.h>",
                    "const size_t c_stdout_p() { return (size_t) (void*) stdout; }",
                    "const size_t c_stderr_p() { return (size_t) (void*) stderr; }",
                ]
            )
        )
        # if we always require cffi, this step is unnecessary
        c_stdout_p = ctypes.c_void_p(_lib.c_stdout_p())
        c_stderr_p = ctypes.c_void_p(_lib.c_stderr_p()) 

That ought to work just about everywhere, BUT requires a compiler

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants