janet-lang / janet

A dynamic language and bytecode vm
https://janet-lang.org
MIT License
3.43k stars 221 forks source link

Using janet_dostring with os/execute evaluates to nil #1307

Closed iacore closed 10 months ago

iacore commented 10 months ago

Reproduction: https://gist.github.com/iacore/6acbb2d98403e468c35dd835518b9be5

Related to https://github.com/janet-lang/janet/issues/926

This may be a spork bug or a janet bug.

sogaiu commented 10 months ago

May be it's not spork as compiling and executing the following:

// build:
//
// gcc -O0 -g main.c -I$HOME/.local/include -L$HOME/.local/lib -ljanet

// run:
//
// export LD_LIBRARY_PATH=$HOME/.local/lib
// ./a.out

#include "janet.h"
#include <stdio.h>

int main() {
  JanetTable *env;

  janet_init();

  env = janet_core_env(NULL);

  int status;

  Janet out;

  status =
    janet_dostring(env,
                   "(os/execute [`ls`] :px)",
                   "source", &out);

  printf("os/execute status: %d\n", status);

  janet_gcroot(out);

  printf("janet_type: %d\n", janet_type(out));

  printf("\n");

  janet_deinit();
}

ends with the output:

os/execute status: 0
janet_type: 1

The expected output is:

os/execute status: 0
janet_type: 0

That is, I expect a number JANET_NUMBER (0) but I'm seeing nil JANET_NIL (1).

Janet 1.31.0-cb25a2ec linux/x64/gcc - '(doc)' for help
repl:1:> (os/execute ["ls"] :px)
...
0
iacore commented 10 months ago

https://github.com/janet-lang/janet/commit/e3f4142d2ae825ff4706ebe4970c389c8f087b77 seems to have fixed this. Can no longer reproduce.