示例#1
0
文件: env.c 项目: berkus/moto
void
moto_delete(MotoEnv *env, MotoVal *val) {
    char *classname;
    void *r;
    char *fname;
    int code;
    void **argv;
    MotoFunction *f;

    classname = val->type->name;

    /* allocate enough room for a destructor function name */
    /* 2 x classname plus two colons, one tilde, the string '(0)' and one '\0' */
    fname = emalloc((2 * strlen(classname)) + 7);
    sprintf(fname, "%s::~%s(0)", classname, classname);

    code = ftab_get(env->ftable, &f, fname, 0, NULL);
    switch (code) {
    case FTAB_NONE:
    case FTAB_MULTIPLE:
        free(val->refval.value);
        break;
    case FTAB_OK:
        /* call destructor */
        argv = emalloc(sizeof(void *));
        argv[0] = val->refval.value;
        (*(f->fptr))(env, 1, argv, &r);
        free(argv);
        break;
    }

    free(fname);

}
示例#2
0
int ftab_add(struct array *OFtable, struct fildes *fd, int *i) {
	unsigned int index;

	for(index = 3; ftab_get(OFtable, index) != NULL; index++);
	if(index >= 100)
		return EMFILE;

	ftab_set(OFtable, fd, index);
	*i = index;

	return 0;
}
示例#3
0
void ftab_copy(struct array *oldtab, struct array **newtab){
	struct fildes *fd;

	if(oldtab == NULL){
		return;
	}

	*newtab = ftab_init();

	for(unsigned int i = 2;
		(fd = ftab_get(oldtab, i)) != NULL;
		i++){
		// v = array_get(oldtab, i);
		ftab_set(*newtab, (void *)fd, i);

		VOP_INCREF(fd->vn);
	}
}