Beispiel #1
0
/* assemble a string on the stack into a proc */
void op_asm(vm_internal_type *vm) {
    object_type *obj = 0;
    object_type *closure =0;
    env_type *env = 0;

    uint8_t *code_ref = 0;
    size_t written = 0;

    gc_register_root(vm->gc, (void **)&obj);
    gc_register_root(vm->gc, (void **)&closure);
    gc_register_root(vm->gc, (void **)&code_ref);
    gc_register_root(vm->gc, (void **)&env);

    obj = vm_pop(vm);

    if(!obj || obj->type != STRING) {
        throw(vm, "Attempt to assemble non-string", 1, obj);

    } else {
        /* assemble the string */
        written = asm_string(vm->gc, obj->value.string.bytes, &code_ref);

        /* clone the current environment in a
           closure */
        clone_env(vm, (env_type **)&env, vm->env, false);

        /* point to the entry point of our
           assembled code_ref */
        env->code_ref = code_ref;
        env->ip = 0;
        env->length = written;

        closure = vm_alloc(vm, CLOSURE);
        /* save the new closure onto our stack */
        closure->value.closure = env;

        vm_push(vm, closure);
    }

    gc_unregister_root(vm->gc, (void **)&env);
    gc_unregister_root(vm->gc, (void **)&code_ref);
    gc_unregister_root(vm->gc, (void **)&closure);
    gc_unregister_root(vm->gc, (void **)&obj);

}
dumb_ptr<invocation> spell_clone_effect(dumb_ptr<invocation> base)
{
    dumb_ptr<invocation> retval;
    retval.new_();

    // block_list in general is not copyable
    // since this is the only call site, it is expanded here
    //*retval = *base;

    retval->next_invocation = NULL;
    retval->flags = INVOCATION_FLAG::ZERO;
    dumb_ptr<env_t> env = retval->env = clone_env(base->env);
    retval->spell = base->spell;
    retval->caster = base->caster;
    retval->subject = 0;
    // retval->timer = 0;
    retval->stack_size = 0;
    // retval->stack = undef;
    retval->script_pos = 0;
    // huh?
    retval->current_effect = base->trigger_effect;
    retval->trigger_effect = base->trigger_effect;
    retval->end_effect = NULL;
    // retval->status_change_refs = NULL;

    retval->bl_id = 0;
    retval->bl_prev = NULL;
    retval->bl_next = NULL;
    retval->bl_m = base->bl_m;
    retval->bl_x = base->bl_x;
    retval->bl_y = base->bl_y;
    retval->bl_type = base->bl_type;

    retval->bl_id = map_addobject(retval);
    set_env_invocation(VAR_INVOCATION, retval);

    return retval;
}
Beispiel #3
0
static int __ibv_exp_use_priv_env(struct ibv_context *context)
{
	struct verbs_context_exp *vctx;
	int err;
	struct verbs_environment *venv;

	vctx = verbs_get_exp_ctx_op(context, lib_exp_use_priv_env);
	if (!vctx) {
		errno = ENOSYS;
		fprintf(stderr, "could not retrieve context\n");
		return -1;
	}
	pthread_mutex_lock(&venv_mutex);
	if (!vctx->venv) {
		venv = calloc(1, sizeof(*venv));
		if (!venv) {
			errno = ENOMEM;
			err = -1;
			goto out;
		}
		venv->head = NULL;
		if (pthread_mutex_init(&venv->mtx, NULL)) {
			err = -1;
			goto out;
		}
		clone_env(venv);
		vctx->venv = venv;
	}
	pthread_mutex_unlock(&venv_mutex);
	return 0;

out:
	free(venv);
	pthread_mutex_unlock(&venv_mutex);
	return err;
}