PARROT_EXPORT void Parrot_set_executable_name(PARROT_INTERP, Parrot_String name) { PMC * const name_pmc = pmc_new(interp, enum_class_String); VTABLE_set_string_native(interp, name_pmc, name); VTABLE_set_pmc_keyed_int(interp, interp->iglobals, IGLOBALS_EXECUTABLE, name_pmc); }
/* =item C<PMC * Parrot_ex_build_exception(PARROT_INTERP, INTVAL severity, long error, STRING *msg)> Constructs a new exception object from the passed in arguments. =cut */ PARROT_EXPORT PARROT_CANNOT_RETURN_NULL PMC * Parrot_ex_build_exception(PARROT_INTERP, INTVAL severity, long error, ARGIN_NULLOK(STRING *msg)) { ASSERT_ARGS(Parrot_ex_build_exception) const int exception_type_id = Parrot_hll_get_ctx_HLL_type(interp, enum_class_Exception); PMC * const exception = Parrot_pmc_new(interp, exception_type_id); VTABLE_set_integer_keyed_str(interp, exception, CONST_STRING(interp, "severity"), severity); VTABLE_set_integer_keyed_str(interp, exception, CONST_STRING(interp, "type"), error); if (msg) VTABLE_set_string_native(interp, exception, msg); return exception; }
PARROT_EXPORT PARROT_CANNOT_RETURN_NULL PARROT_WARN_UNUSED_RESULT PMC* Parrot_make_cb(PARROT_INTERP, ARGMOD(PMC* sub), ARGIN(PMC* user_data), ARGIN(STRING *cb_signature)) { ASSERT_ARGS(Parrot_make_cb) PMC *cb, *cb_sig; int type = 0; STRING *sc; /* * we stuff all the information into the user_data PMC and pass that * on to the external sub */ PMC * const interp_pmc = VTABLE_get_pmc_keyed_int(interp, interp->iglobals, (INTVAL) IGLOBALS_INTERPRETER); if (default_interp == NULL) default_interp = interp; /* be sure __LINE__ is consistent */ sc = CONST_STRING(interp, "_interpreter"); Parrot_pmc_setprop(interp, user_data, sc, interp_pmc); sc = CONST_STRING(interp, "_sub"); Parrot_pmc_setprop(interp, user_data, sc, sub); /* only ASCII signatures are supported */ if (STRING_length(cb_signature) == 3) { /* Callback return type ignored */ if (STRING_ord(interp, cb_signature, 1) == 'U') { type = 'D'; } else { if (STRING_ord(interp, cb_signature, 2) == 'U') { type = 'C'; } } } if (type != 'C' && type != 'D') Parrot_ex_throw_from_c_args(interp, NULL, 1, "unhandled signature '%Ss' in make_cb", cb_signature); cb_sig = Parrot_pmc_new(interp, enum_class_String); VTABLE_set_string_native(interp, cb_sig, cb_signature); sc = CONST_STRING(interp, "_signature"); Parrot_pmc_setprop(interp, user_data, sc, cb_sig); /* * We are going to be passing the user_data PMC to external code, but * it may go out of scope until the callback is called -- we don't know * for certain as we don't know when the callback will be called. * Therefore, to prevent the PMC from being destroyed by a GC sweep, * we need to anchor it. * */ Parrot_pmc_gc_register(interp, user_data); /* * Finally, the external lib awaits a function pointer. * Create a PMC that points to Parrot_callback_C (or _D); * it can be passed on with signature 'p'. */ cb = Parrot_pmc_new(interp, enum_class_UnManagedStruct); /* * Currently, we handle only 2 types: * _C ... user_data is 2nd parameter * _D ... user_data is 1st parameter */ if (type == 'C') VTABLE_set_pointer(interp, cb, F2DPTR(Parrot_callback_C)); else VTABLE_set_pointer(interp, cb, F2DPTR(Parrot_callback_D)); Parrot_pmc_gc_register(interp, cb); return cb; }