Esempio n. 1
0
/*
 *   Delete the table 
 */
CVmMetaTable::~CVmMetaTable()
{
    /* clear the table */
    clear();
    
    /* free the table, if we ever allocated one */
    if (table_ != 0)
        t3free(table_);

    /* free the reverse map */
    t3free(reverse_map_);
}
Esempio n. 2
0
/*
 *   destroy the code stream 
 */
CTcCodeStream::~CTcCodeStream()
{
    size_t i;

    /* release all active labels */
    release_labels();

    /* delete the line records pages */
    for (i = 0 ; i < line_pages_alloc_ ; ++i)
        t3free(line_pages_[i]);

    /* delete the master list of pages */
    t3free(line_pages_);
}
Esempio n. 3
0
/*
 *   delete 
 */
CTcDataStream::~CTcDataStream()
{
    size_t i;

    /* delete the page slots if we allocated any */
    for (i = 0 ; i < page_cnt_ ; ++i)
        t3free(pages_[i]);

    /* delete the page slot array if we allocated it */
    if (pages_ != 0)
        t3free(pages_);

    /* delete our label/fixup allocator */
    delete allocator_;
}
Esempio n. 4
0
/*
 *   delete the pool's resources - this is called from our destructor, and
 *   can also be called explicitly to reset the pool 
 */
void CVmPoolInMem::terminate_nv()
{
    /* free any pages we allocated from the backing store */
    free_backing_pages();

    /* free all of the dynamic object handles */
    while (dyn_head_ != 0)
    {
        CVmPoolDynObj *nxt;

        /* note the next object */
        nxt = dyn_head_->get_next();

        /* delete this object */
        t3free(dyn_head_);

        /* move on to the next one */
        dyn_head_ = nxt;
    }

    /* we no longer have anything in the list */
    dyn_head_ = dyn_tail_ = 0;

    /* we no longer have any dynamic pages */
    first_dyn_page_ = 0;
}
Esempio n. 5
0
/*
 *   Log a message with sprintf-style formatting 
 */
void vm_log_fmt(VMG_ const char *fmt, ...)
{
    /* format the message */
    va_list args;
    va_start(args, fmt);
    char *str = t3vsprintf_alloc(fmt, args);
    va_end(args);

    /* log the message */
    vm_log(vmg_ str, strlen(str));

    /* done with the string */
    t3free(str);
}
Esempio n. 6
0
/*
 *   Check a storage server status code returned by
 *   vmnet_get_storagesrv_reply().  On failure, throw an error; on success,
 *   simply return.  In either case, we'll free the status code buffer. 
 */
void vmnet_check_storagesrv_stat(VMG_ char *stat)
{
    /* if it's not "OK", throw an error */
    if (memcmp(stat, "OK ", 3) != 0)
    {
        /* 
         *   Error.  Push the error code/message text string as the argument
         *   to the runtime error constructor, then discard our copy of the
         *   buffer.  
         */
        G_interpreter->push_string(vmg_ stat);
        t3free(stat);

        /* throw a StorageServerError */
        G_interpreter->throw_new_rtesub(
            vmg_ G_predef->storage_server_error, 1,
            VMERR_STORAGE_SERVER_ERR);
    }
    else
    {
        /* success - discard the message text */
        t3free(stat);
    }
}
Esempio n. 7
0
/*
 *   free pages that we allocated from the backing store 
 */
void CVmPoolInMem::free_backing_pages()
{
    size_t i;
    pool_ofs_t ofs;
    CVmPool_pg *info;

    /* 
     *   delete any dynamically-allocated pages (these are not managed by
     *   the backing store) 
     */
    for (i = first_dyn_page_, info = &pages_[i] ; i < page_slots_ ;
         ++i, ++info)
    {
        /* if this slot was allocated, delete it */
        if (info->mem != 0)
        {
            /* free the memory */
            t3free((char *)info->mem);

            /* note that we've freed it */
            info->mem = 0;
        }
    }

    /* if there's no backing store, there's nothing to do */
    if (backing_store_ == 0)
        return;

    /* 
     *   Run through the page array and delete each allocated page.  Since
     *   we allocate pages through the backing store, delete pages through
     *   the backing store.  
     */
    for (i = 0, info = pages_, ofs = 0 ; i < first_dyn_page_ ;
         ++i, ++info, ofs += page_size_)
    {
        /* if this slot was allocated, delete it */
        if (info->mem != 0)
        {
            /* delete the page */
            backing_store_->vmpbs_free_page(info->mem, ofs, page_size_);

            /* forget it */
            info->mem = 0;
        }
    }
}
Esempio n. 8
0
/*
 *   Fix up the global symbol table to set the correct metaclasses for all
 *   object symbols.  This has to wait until we've finished reading the whole
 *   image file, because we have need to finish reading all of the actual
 *   objects (specifically the OBJS records) before we can be sure we'll have
 *   access to all of the metaclass information.  
 */
void CVmImageLoader::fix_gsym_meta(VMG0_)
{
    tc_metaclass_t *xlat;
    size_t i, cnt;
    fix_obj_meta_cb_ctx ctx;

    /* if there's no global symbol table, there's nothing to do */
    if (G_prs->get_global_symtab() == 0)
        return;

    /*
     *   Tell the debugger code generator about the actual loaded metaclass
     *   dependency table.  This is necessary so that the code generator can
     *   generate the correct metaclass index references for this object
     *   file.  First, start the table.
     */
    G_cg->start_image_file_meta_table();

    /* now add each entry from the table */
    for (cnt = G_meta_table->get_count(), i = 0 ; i < cnt ; ++i)
    {
        /* get this item's name */
        const char *nm = G_meta_table->get_entry(i)->image_meta_name_;

        /* find the version suffix, if any */
        const char *p;
        for (p = nm ; *p != '\0' && *p != '/' ; ++p) ;

        /* tell the code generator about the entry */
        G_cg->load_image_file_meta_table(nm, p - nm, i);
    }

    /* done with the table */
    G_cg->end_image_file_meta_table();

    /* build a translation from metaclass index to compiler TC_META_xxx ID */
    xlat = CVmMetaTable::build_runtime_to_compiler_id_table(vmg0_);

    /* now run through the symbol table and fix up each object symbol */
    ctx.vmg = VMGLOB_ADDR;
    ctx.xlat = xlat;
    G_prs->get_global_symtab()->enum_entries(&fix_obj_meta_cb, &ctx);

    /* free our temporary translation table */
    t3free(xlat);
}
Esempio n. 9
0
/*
 *   delete - deletes all of our symbol list entries
 */
CVmRuntimeSymbols::~CVmRuntimeSymbols()
{
    vm_runtime_sym *sym;
    vm_runtime_sym *nxt;

    /* delete each symbol */
    for (sym = head_ ; sym != 0 ; sym = nxt)
    {
        /*
         *   remember the next one, since we're deleting our link pointer
         *   along with the structure
         */
        nxt = sym->nxt;

        /* delete it */
        t3free(sym);
    }
}
Esempio n. 10
0
/*
 *   Log a string with a given length
 */
void vm_log(VMG_ const char *str, size_t len)
{
    /* open the system log file */
    osfildef *fp = osfoprwt(G_syslogfile, OSFTTEXT);
    if (fp != 0)
    {
        /* wrap it in a data source */
        CVmFileSource ds(fp);

        /* get a printable timestamp */
        os_time_t timer = os_time(0);
        struct tm *tblk = os_localtime(&timer);
        char *tmsg = asctime(tblk);

        /* remove the trailing '\n' from the asctime message */
        size_t tmsgl = strlen(tmsg);
        if (tmsgl > 0 && tmsg[tmsgl-1] == '\n')
            tmsg[--tmsgl] = '\0';

        /* build the full message: [<timestamp>] <message> <newline> */
        char *msg = t3sprintf_alloc("[%s] %.*s\n", tmsg, (int)len, str);
        size_t msglen = strlen(msg);

        /* seek to the end of the file */
        ds.seek(0, OSFSK_END);

        /* if we can convert to a local character set, do so */
        if (G_cmap_to_log != 0)
        {
            /* write the message in the local character set */
            G_cmap_to_file->write_file(&ds, msg, msglen);
        }
        else
        {
            /* write the message with no character set conversion */
            (void)osfwb(fp, (unsigned char*)msg, msglen);
        }

        /* done with the formatted text string */
        t3free(msg);
    }
}
Esempio n. 11
0
 void vmpbs_free_page(const char *mem, pool_ofs_t, size_t)
 {
     t3free((char *)mem);
 }
Esempio n. 12
0
 ~NetString()
 {
     if (buf != 0)
         t3free(buf);
 }
Esempio n. 13
0
/*
 *   Show a popup menu 
 */
void CVmBifTIOExt::show_popup_menu(VMG_ uint argc)
{
    int x, y, default_pos;
    char *txt;
    os_event_info_t evt;
    int ret;
    int elecnt;
    vm_obj_id_t lst_obj;
    CVmObjList *lst;
    vm_val_t val;
    
    /* check arguments */
    check_argc(vmg_ argc, 3);

    /* get the x,y coordinates */
    if (G_stk->get(0)->typ == VM_NIL)
    {
        /* nil x,y - use default position */
        default_pos = TRUE;
        x = y = 0;

        /* discard the nil x,y values */
        G_stk->discard(2);
    }
    else
    {
        /* pop the x,y positions */
        x = pop_int_val(vmg0_);
        y = pop_int_val(vmg0_);
    }

    /* get the HTML text for the contents of the window */
    txt = pop_str_val_ui(vmg_ 0, 0);

    /* flush the console display output */
    G_console->flush_all(vmg_ VM_NL_NONE);

    /* show the window */
    ret = os_show_popup_menu(default_pos, x, y, txt, strlen(txt), &evt);

    /* free the HTML text buffer we allocated */
    t3free(txt);

    /* see what we have */
    switch (ret)
    {
    case OSPOP_FAIL:
    case OSPOP_CANCEL:
    case OSPOP_EOF:
    default:
        elecnt = 1;
        break;

    case OSPOP_HREF:
        elecnt = 2;
        break;
    }

    /* allocate the return list */
    lst_obj = CVmObjList::create(vmg_ FALSE, elecnt);
    lst = (CVmObjList *)vm_objp(vmg_ lst_obj);
    lst->cons_clear();

    /* protect the list from garbage collection */
    val.set_obj(lst_obj);
    G_stk->push(&val);

    /* set the first element to the main return code */
    val.set_int(ret);
    lst->cons_set_element(0, &val);

    /* set additional elements according to the return code */
    switch (ret)
    {
    case OSPOP_HREF:
        /* add the HREF element */
        val.set_obj(str_from_ui_str(vmg_ evt.href));
        lst->cons_set_element(1, &val);
        break;

    default:
        /* there aren't any other elements for other return codes */
        break;
    }

    /* return the list */
    retval_obj(vmg_ lst_obj);

    /* discard the GC protection */
    G_stk->discard();
}
Esempio n. 14
0
/*
 *   Free a string previously allocated with lib_copy_str() 
 */
void lib_free_str(char *buf)
{
    if (buf != 0)
        t3free(buf);
}
Esempio n. 15
0
/* 
 *   delete 
 */
CTcSrcMemory::~CTcSrcMemory()
{
    /* free our buffer */
    t3free(buf_alo_);
}
Esempio n. 16
0
/*
 *   load a configuration file 
 */
void TadsNetConfig::read(osfildef *fp, CVmMainClientIfc *clientifc)
{
    /* read the file line by line */
    for (int linenum = 1 ; ; ++linenum)
    {
        /* read the next line */
        char buf[512];
        if (osfgets(buf, sizeof(buf), fp) == 0)
            break;

        /* skip leading whitespace */
        char *p;
        for (p = buf ; isspace(*p) ; ++p) ;

        /* skip blank lines and comments */
        if (*p == '\0' || *p == '#')
            continue;

        /* the variable name is the first token on the line */
        char *name = p;

        /* find the end of the name: the next space or '=' */
        for ( ; *p != '\0' && !isspace(*p) && *p != '=' ; ++p) ;
        char *name_end = p;

        /* skip spaces */
        for ( ; isspace(*p) ; ++p) ;

        /* make sure we stopped at a '=' */
        if (*p != '=')
        {
            char *msg = t3sprintf_alloc(
                "Missing '=' in web config file at line %d", linenum);
            clientifc->display_error(0, 0, msg, FALSE);
            t3free(msg);
            continue;
        }

        /* null-terminate the name */
        *name_end = '\0';

        /* skip spaces after the '=' */
        for (++p ; isspace(*p) ; ++p) ;

        /* the value starts here */
        char *val = p;

        /* 
         *   the value is the rest of the line, minus trailing spaces and
         *   newlines 
         */
        for (p += strlen(p) ;
             p > val && (isspace(*(p-1))
                         || *(p-1) == '\n' || *(p-1) == '\r') ;
             --p) ;

        /* null-terminate the value */
        *p = '\0';

        /* add the variable */
        TadsNetConfigVar *var = set(name, val);

        /* check that this is a variable name we recognize */
        static const char *known_vars[] = {
            "serverid",
            "storage.domain",
            "storage.rootpath",
            "storage.apikey",
            "watchdog"
        };

        int found = FALSE;
        for (size_t i = 0 ; i < countof(known_vars) ; ++i)
        {

            if (var->matchname(known_vars[i]))
            {
                found = TRUE;
                break;
            }
        }

        /* warn if we didn't find it among the known variables */
        if (!found)
        {
            char *msg = t3sprintf_alloc(
                "Warning: unknown variable name '%s' in web config file "
                "at line %d\n", name, linenum);
            clientifc->display_error(0, 0, msg, FALSE);
            t3free(msg);
        }
    }
}
Esempio n. 17
0
/*
 *   delete the stack 
 */
CVmStack::~CVmStack()
{
    /* delete the stack element array */
    t3free(arr_);
}