Skip to content

hs_init is not idempotent

hs_init tries to be idempotent by ignoring all calls but the first one. However, subsequent calls to hs_init do not set argc and argv correctly.

Here's a test case:

#include "HsFFI.h"
#include "stdio.h"

void try_init() {
  char *argv[] = { "./test", "+RTS", "-s", "-RTS", "arg", 0 };
  char **argv_ptr = argv;
  int argc = sizeof(argv)/sizeof(argv[0]) - 1;
  hs_init(&argc, &argv_ptr);
  printf("%d\n", argc);
}

int main() {
  try_init();
  try_init();
}

Result:

2
5
Trac metadata
Trac field Value
Version 8.0.2
Type Bug
TypeOfFailure OtherFailure
Priority normal
Resolution Unresolved
Component Compiler
Test case
Differential revisions
BlockedBy
Related
Blocking
CC
Operating system
Architecture
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information