Skip to content

Commit

Permalink
Merge pull request #145 from shikokuchuo/master
Browse files Browse the repository at this point in the history
Fix non-API calls for closures
  • Loading branch information
spgarbet authored Jul 5, 2024
2 parents 8d6f7c3 + 903a78a commit afde119
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 7 deletions.
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ Package: yaml
Type: Package
Title: Methods to Convert R Data to YAML and Back
Date: 2023-11-28
Version: 2.3.8
Version: 2.3.9
Suggests: RUnit
Author: Shawn P Garbett [aut], Jeremy Stephens [aut, cre], Kirill Simonov [aut], Yihui Xie [ctb],
Zhuoer Dong [ctb], Hadley Wickham [ctb], Jeffrey Horner [ctb], reikoch [ctb],
Will Beasley [ctb], Brendan O'Connor [ctb], Gregory R. Warnes [ctb],
Michael Quinn [ctb], Zhian N. Kamvar [ctb]
Michael Quinn [ctb], Zhian N. Kamvar [ctb], Charlie Gao [ctb]
Maintainer: Shawn Garbett <shawn.garbett@vumc.org>
License: BSD_3_clause + file LICENSE
Description: Implements the 'libyaml' 'YAML' 1.1 parser and emitter
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.3.8
2.3.9
21 changes: 17 additions & 4 deletions src/r_emit.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,22 @@ typedef struct {
size_t capa;
} s_emitter_output;

#if R_VERSION < R_Version(4, 5, 0)

# define R_ClosureFormals(x) FORMALS(x)
# define R_ClosureBody(x) BODY(x)
# define R_ClosureEnv(x) CLOENV(x)

static inline SEXP R_mkClosure(SEXP formals, SEXP body, SEXP env) {
SEXP fun = Rf_allocSExp(CLOSXP);
SET_FORMALS(fun, formals);
SET_BODY(fun, body);
SET_CLOENV(fun, env);
return fun;
}

#endif

static SEXP Ryaml_deparse_function(SEXP s_obj)
{
SEXP s_new_obj = NULL, s_call = NULL, s_result = NULL, s_chr = NULL;
Expand All @@ -20,10 +36,7 @@ static SEXP Ryaml_deparse_function(SEXP s_obj)
/* Copy function without any attributes */
if (TYPEOF(s_obj) == CLOSXP) {
PROTECT(s_obj);
PROTECT(s_new_obj = allocSExp(CLOSXP));
SET_FORMALS(s_new_obj, FORMALS(s_obj));
SET_BODY(s_new_obj, BODY(s_obj));
SET_CLOENV(s_new_obj, CLOENV(s_obj));
PROTECT(s_new_obj = R_mkClosure(R_ClosureFormals(s_obj), R_ClosureBody(s_obj), R_ClosureEnv(s_obj)));
SET_OBJECT(s_new_obj, OBJECT(s_obj));
UNPROTECT(2);
s_obj = s_new_obj;
Expand Down
1 change: 1 addition & 0 deletions src/r_ext.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include <limits.h>
#include "R.h"
#include "Rdefines.h"
#include "Rversion.h"
#include "R_ext/Rdynload.h"
#include "R_ext/Parse.h"
#include "R_ext/Print.h"
Expand Down

0 comments on commit afde119

Please sign in to comment.