@@ -11,6 +11,22 @@ typedef struct {
1111size_t capa ;
1212}s_emitter_output ;
1313
14+ #if R_VERSION < R_Version (4 ,5 ,0 )
15+
16+ # define R_ClosureFormals (x ) FORMALS(x)
17+ # define R_ClosureBody (x ) BODY(x)
18+ # define R_ClosureEnv (x ) CLOENV(x)
19+
20+ static inline SEXP R_mkClosure (SEXP formals ,SEXP body ,SEXP env ) {
21+ SEXP fun = Rf_allocSExp (CLOSXP );
22+ SET_FORMALS (fun ,formals );
23+ SET_BODY (fun ,body );
24+ SET_CLOENV (fun ,env );
25+ return fun ;
26+ }
27+
28+ #endif
29+
1430static SEXP Ryaml_deparse_function (SEXP s_obj )
1531{
1632SEXP s_new_obj = NULL ,s_call = NULL ,s_result = NULL ,s_chr = NULL ;
@@ -20,10 +36,7 @@ static SEXP Ryaml_deparse_function(SEXP s_obj)
2036/* Copy function without any attributes */
2137if (TYPEOF (s_obj )== CLOSXP ) {
2238PROTECT (s_obj );
23- PROTECT (s_new_obj = allocSExp (CLOSXP ));
24- SET_FORMALS (s_new_obj ,FORMALS (s_obj ));
25- SET_BODY (s_new_obj ,BODY (s_obj ));
26- SET_CLOENV (s_new_obj ,CLOENV (s_obj ));
39+ PROTECT (s_new_obj = R_mkClosure (R_ClosureFormals (s_obj ),R_ClosureBody (s_obj ),R_ClosureEnv (s_obj )));
2740SET_OBJECT (s_new_obj ,OBJECT (s_obj ));
2841UNPROTECT (2 );
2942s_obj = s_new_obj ;