Skip to content

Commit

Permalink
Merge pull request #1625 from rstudio/c-api-compliance
Browse files Browse the repository at this point in the history
Moving into R's C API compliance
  • Loading branch information
t-kalinowski authored Jun 19, 2024
2 parents a7da5ce + e94c08e commit 98f96c2
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 20 deletions.
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# reticulate (development version)

- Internal updates for compliance with R's upcoming formalized C API. (#1625)

- Added support for converting NumPy StringDType arrays to R character arrays. (#1623)

- Internal updates for NumPy 2.0 (#1621)
Expand Down
24 changes: 4 additions & 20 deletions src/python.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -502,20 +502,11 @@ SEXP current_env(void) {
// are looking for to begin with. We use instead this workaround:
// Call `sys.frame()` from a closure to push a new frame on the
// stack, and use negative indexing to get the previous frame.
ParseStatus status;
SEXP code = PROTECT(Rf_mkString("sys.frame(-1)"));
SEXP parsed = PROTECT(R_ParseVector(code, -1, &status, R_NilValue));
SEXP body = VECTOR_ELT(parsed, 0);

SEXP fn = PROTECT(Rf_allocSExp(CLOSXP));
SET_FORMALS(fn, R_NilValue);
SET_BODY(fn, body);
SET_CLOENV(fn, R_BaseEnv);

SEXP fn = PROTECT(R_ParseEvalString("function() sys.frame(-1)", R_BaseEnv));
SEXP call = Rf_lang1(fn);
R_PreserveObject(call);

UNPROTECT(3);
UNPROTECT(1);
return call;
}();

Expand Down Expand Up @@ -808,20 +799,13 @@ bool traceback_enabled() {

SEXP get_current_call(void) {
static SEXP call = []() {
ParseStatus status;
SEXP code = PROTECT(Rf_mkString("sys.call(-1)"));
SEXP parsed = PROTECT(R_ParseVector(code, -1, &status, R_NilValue));
SEXP body = VECTOR_ELT(parsed, 0);

SEXP fn = PROTECT(Rf_allocSExp(CLOSXP));
SET_FORMALS(fn, R_NilValue);
SET_BODY(fn, body);
SET_CLOENV(fn, R_BaseEnv);
SEXP fn = PROTECT(R_ParseEvalString("function() sys.call(-1)", R_BaseEnv));

SEXP call = Rf_lang1(fn);
R_PreserveObject(call);

UNPROTECT(3);
UNPROTECT(1);
return call;
}();

Expand Down

0 comments on commit 98f96c2

Please sign in to comment.