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

Providing defaults to array variables compiles but crashes #277

Open
richfitz opened this issue Oct 27, 2022 · 0 comments
Open

Providing defaults to array variables compiles but crashes #277

richfitz opened this issue Oct 27, 2022 · 0 comments

Comments

@richfitz
Copy link
Member

richfitz commented Oct 27, 2022

odin::odin({
  X[] <- user(1)
  dim(X) <- 5
  initial(a) <- 0
  deriv(a) <- sum(X)
}, workdir = "err")

then look in err/src/odin.c

SEXP odin_create(SEXP user) {
  odin_internal *internal = (odin_internal*) R_Calloc(1, odin_internal);
  internal->X = NULL;
  internal->dim_X = 5;
  internal->initial_a = 0;
  internal->X = 1;
  SEXP ptr = PROTECT(R_MakeExternalPtr(internal, R_NilValue, R_NilValue));
  R_RegisterCFinalizer(ptr, odin_finalise);
  UNPROTECT(1);
  return ptr;
}

which creates a really bad pointer for X (and later on a crash). We should either support this properly, or error

Reported by @lwhittles

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

No branches or pull requests

1 participant