/* {{{ proto void R::init([array argv]) */ static PHP_METHOD(R, init) { zval *argv = NULL; int argc = 3; HashPosition pos; char **argv_arr; zval **element; int i; char *r_home; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|a", &argv) == FAILURE) { return; } r_home = getenv("R_HOME"); if (!r_home || r_home[0] == '\0') { setenv("R_HOME", PHP_R_DIR, 0); } R_SetErrorHook(php_r_error_handler); R_SetWarningHook(php_r_warning_handler); if (argv) { argc += zend_hash_num_elements(Z_ARRVAL_P(argv)); } argv_arr = safe_emalloc(argc, sizeof(char *), 0); argv_arr[0] = "REmbeddedPHP"; argv_arr[1] = "--gui=none"; argv_arr[2] = "--silent"; if (argv) { i = 3; for (zend_hash_internal_pointer_reset_ex(Z_ARRVAL_P(argv), &pos); zend_hash_get_current_data_ex(Z_ARRVAL_P(argv), (void **) &element, &pos) == SUCCESS; zend_hash_move_forward_ex(Z_ARRVAL_P(argv), &pos) ) { convert_to_string_ex(element); argv_arr[i] = Z_STRVAL_PP(element); /* no copy here, libR does strdup() itself */ i++; } } Rf_initEmbeddedR(argc, argv_arr); efree(argv_arr); }
CAMLprim value ocamlr_init_error_hook (value ml_unit) { R_SetErrorHook(&ocamlr_error_hook); return Val_unit; }
static void ocamlr_error_hook(SEXP call, char * message) { ocamlr_error_call = call; ocamlr_error_message = message; R_SetErrorHook(&ocamlr_error_hook); }