Skip to content

Commit

Permalink
try R_ToplevelExec()
Browse files Browse the repository at this point in the history
  • Loading branch information
shikokuchuo committed Nov 27, 2024
1 parent 50aebba commit de43f60
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions inst/include/later.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,11 +96,18 @@ inline void later(void (*func)(void*), void* data, double secs) {
later(func, data, secs, GLOBAL_LOOP);
}

typedef void (*elfdnfun)(void (*)(int *, void *), void *, int, struct pollfd *, double, int);

static elfdnfun eval_res = NULL;

void eval_safe(void *data) {
eval_res = (elfdnfun) R_GetCCallable("later", "execLaterFdNative");
}

inline void later_fd(void (*func)(int *, void *), void *data, int num_fds, struct pollfd *fds, double secs, int loop_id) {
// See above note for later()

// The function type for the real execLaterFdNative
typedef void (*elfdnfun)(void (*)(int *, void *), void *, int, struct pollfd *, double, int);
static elfdnfun elfdn = NULL;
if (!elfdn) {
// Initialize if necessary
Expand All @@ -112,7 +119,10 @@ inline void later_fd(void (*func)(int *, void *), void *data, int num_fds, struc
"If you're using <later.h>, please switch to <later_api.h>.\n"
);
}
elfdn = (elfdnfun) R_GetCCallable("later", "execLaterFdNative");
if (R_ToplevelExec(eval_safe, (void *) NULL)) {
elfdn = eval_res;
}

}

// We didn't want to execute anything, just initialize
Expand Down

0 comments on commit de43f60

Please sign in to comment.