mighty-gerbils / gerbil

Gerbil Scheme
https://cons.io
GNU Lesser General Public License v2.1
1.16k stars 112 forks source link

linking libssl causes issue with stdout #1230

Closed fare closed 6 months ago

fare commented 6 months ago

Had issues compiling an executable, wherein linking in libssl causes stdout to disappear(!). To reproduce, create a ssl.ss file with the following contents:

(import :std/net/ssl/libssl)
(export #t) (def (main) (displayln "ZZZZZZZZZZZZZZZZ"))

And compile with: gxc -o ssl -exe ssl.ss && ./ssl, and it won't display anything. Removing the import and it does print. Redirect ./ssl > a and it works again(!)

vyzo commented 6 months ago

Further examination: its a terminal issue, redirecting stdout makes the problem disappear.

fare commented 6 months ago

1233 should fix it, though (1) I have no idea what the mechanism for this error behavior is, and (2) the same issue works directly with Gambit:

cat > o.scm <<'END'
(c-declare #<<END-C
#include <stdio.h>
#include <openssl/ssl.h>
END-C
)

(c-initialize #<<END-C
int r;
printf("hello, "); fflush(stdout);
r = OPENSSL_init_ssl(0, NULL);
if (r) {
  printf("success "); fflush(stdout);
} else {
  printf("failure "); fflush(stdout);
}
printf("world\n"); fflush(stdout);
END-C
)

(display "ZZZZZZZZZZZZZZZZ") (newline) (force-output)
END
gsc -o o -exe -ld-options -lssl o.scm && ( echo aaa ; ./o ; echo bbb ; ./o > x ; cat x)
aaa
hello, success world
bbb
hello, success world
ZZZZZZZZZZZZZZZZ