/* Code adapted from CarbonEL. * Thanks to Simon Urbanek for the suggestion on r-devel mailing list. */ static void nvimcom_uih(void *data) { char buf[16]; if(read(ifd, buf, 1) < 1) REprintf("nvimcom error: read < 1\n"); R_ToplevelExec(nvimcom_exec, NULL); fired = 0; }
SEXP Rserve_eval(SEXP what, SEXP rho, SEXP retLast, SEXP retExp, SEXP ctxObj) { int need_last = asInteger(retLast), exp_value = asInteger(retExp); rs_eval_t e = { what, rho, 0, 0, 0, 0 }; SEXP saved_context = RS_current_context; int saved_context_is_protected = RS_current_context_is_protected; if (ctxObj != R_NilValue) { RS_current_context = ctxObj; /* this is transient so no protection */ RS_current_context_is_protected = 0; } e.ctx_obj = RS_current_context; if (!R_ToplevelExec(Rserve_eval_, &e)) { RS_current_context = saved_context; RS_current_context_is_protected = saved_context_is_protected; SEXP res = PROTECT(mkNamed(VECSXP, (const char*[]) { "error", "traceback", "expression", "context", "" }));
Error executeSafely(boost::function<void()> function) { // disable custom error handlers while we execute code DisableErrorHandlerScope disableErrorHandler; Rboolean success = R_ToplevelExec(topLevelExec, (void*)&function); if (!success) { return rCodeExecutionError(getErrorMessage(), ERROR_LOCATION); } else { return Success(); } }
void RKStructureGetter::getStructureSafe (SEXP value, const QString &name, bool misplaced, RData *storage) { RK_TRACE (RBACKEND); GetStructureWorkerArgs args; args.toplevel = value; args.name = name; args.misplaced = misplaced; args.storage = storage; args.getter = this; Rboolean ok = R_ToplevelExec ((void (*)(void*)) getStructureWrapper, &args); if (ok != TRUE) { storage->discardData(); Rf_warning ("failure to get object %s", name.toLatin1().data ()); getStructureWorker (R_NilValue, name, misplaced, storage); } }
core::Error executeSafely(boost::function<SEXP()> function, SEXP* pSEXP) { // disable custom error handlers while we execute code DisableErrorHandlerScope disableErrorHandler; SEXPTopLevelExecContext context ; context.function = function ; context.pReturnSEXP = pSEXP ; Rboolean success = R_ToplevelExec(SEXPTopLevelExec, (void*)&context); if (!success) { return rCodeExecutionError(getErrorMessage(), ERROR_LOCATION); } else { return Success(); } }
void RKStructureGetter::getStructureSafe (SEXP value, const QString &name, int add_type_flags, RData *storage, int nesting_depth) { RK_TRACE (RBACKEND); GetStructureWorkerArgs args; args.toplevel = value; args.name = name; args.add_type_flags = add_type_flags; args.storage = storage; args.getter = this; args.nesting_depth = nesting_depth; Rboolean ok = R_ToplevelExec ((void (*)(void*)) getStructureWrapper, &args); if (ok != TRUE) { storage->discardData(); Rf_warning ("failure to get object %s", name.toLatin1().data ()); getStructureWorker (R_NilValue, name, add_type_flags, storage, nesting_depth); } }
USER_OBJECT_ tryEval(USER_OBJECT_ e, int *ErrorOccurred) { Rboolean ok; ProtectedEvalData data; data.expression = e; data.val = NULL; ok = R_ToplevelExec(protectedEval, &data); if(ErrorOccurred) { *ErrorOccurred = (ok == FALSE); } if(ok == FALSE) data.val = NULL; else UNPROTECT(1); return(data.val); }
/** * Call this method to check for user interrupts. * This is based on the results of a discussion on the * R-devel mailing list, suggested by Simon Urbanek. * @attention This method must not be called by any other * thread than the master thread. If called from within * an OpenMP parallel for loop, make sure to check * for omp_get_thread_num()==0 before calling this method! * @return True, if a user interrupt has been detected. */ inline bool check_interrupt() { return (R_ToplevelExec(check_interrupt_impl, NULL) == FALSE); }
static void _R_tcldo(void) { (void) R_ToplevelExec(TclSpinLoop, NULL); }
int pending_interrupt() { return !(R_ToplevelExec(check_interrupt_fn, NULL)); }