[R-pkg-devel] safely allocate SEXP and handle failure

Jan Gorecki j@goreck| @end|ng |rom w|t@edu@p|
Thu Sep 21 09:46:26 CEST 2023


Dear pkg developers

I would like to safely allocate R object from C. By safely I mean
that, I can test if allocation succeeded or failed, and then raise
exception myself.
R_alloc and allocVector both raises exception straightaway, so I am
not able to handle failed allocation myself.
In plain C it is something like that:

int *x = malloc(nx*sizeof(int));
if (!x) {
  my_fun_to_set_exception_signal();
  free(x);
  return;
}

How can I do it for creating SEXP object?

Best Regards,
Jan Gorecki



More information about the R-package-devel mailing list