Example #1
0
File: scheme.c Project: abw/hemp
void
hemp_scheme_free(
    HempScheme scheme
) {
    if (scheme->name)
        hemp_mem_free(scheme->name);

    hemp_mem_free(scheme);
}
Example #2
0
File: viewer.c Project: abw/hemp
void
hemp_viewer_free(
    HempViewer viewer
) {
    if (viewer->view)
        hemp_mem_free(viewer->view);
    
    hemp_mem_free(viewer->name);
    hemp_mem_free(viewer);
}
Example #3
0
void
hemp_module_free(
    HempModule     module
) {
    if (module->handle)
        hemp_module_unload(module);

    if (module->error)
        hemp_mem_free(module->error);

    hemp_mem_free(module->name);
    hemp_mem_free(module);
}
Example #4
0
File: factory.c Project: abw/hemp
void
hemp_factory_free(
    HempFactory factory
) {
    /* run any custom instance cleaner */
    if (factory->cleaner)
        hemp_hash_each(factory->instances, factory->cleaner);

    /* put our own house in order */
    hemp_hash_free(factory->instances);
    hemp_hash_each(factory->constructors, &hemp_factory_free_constructor);
    hemp_hash_free(factory->constructors);
    hemp_mem_free(factory->name);
    hemp_mem_free(factory);
}
Example #5
0
File: text.c Project: abw/hemp
HEMP_INLINE void
hemp_text_free(
    HempText text
) {
    hemp_text_release(text);
    hemp_mem_free(text);
}
Example #6
0
File: list.c Project: abw/hemp
void
hemp_list_free(
    HempList list
) {
    hemp_list_release(list);
    hemp_mem_free(list);
}
Example #7
0
File: test.c Project: abw/hemp
void 
hemp_test_plan_cleanup(
    HempTestPlan plan
) {
    hemp_mem_free(plan);

    if (plan == hemp_global_test_plan)
        hemp_global_test_plan = NULL;
}
Example #8
0
File: file.c Project: abw/hemp
void
hemp_scheme_file_cleaner(
    HempSource source 
) {
    if (source->text) {
        hemp_debug_call("cleaning file source: %s\n%s\n", source->name, source->text);
        hemp_mem_free(source->text);
    }
}
Example #9
0
File: test.c Project: abw/hemp
HempUint
hemp_test_expect_script(
    HempString  language,
    HempString  dialect,
    HempString  testdir,
    HempString  name,
    HempContext context
) {
//    hemp_mem_trace_reset();
    HempString dir    = hemp_filesystem_join_path(testdir, "scripts");
    HempString file   = hemp_filesystem_join_path(dir, name);
    HempString text   = hemp_filesystem_read_file(file);
    HempUint   result = hemp_test_expect_text(language, dialect, text, name, context);
    hemp_mem_free(text);
    hemp_mem_free(file);
    hemp_mem_free(dir);

    return result;
}
Example #10
0
File: text.c Project: abw/hemp
HEMP_INLINE void
hemp_text_release(
    HempText text
) {
    if (text->string) {
//      hemp_debug_mem("releasing text string at %p -> %p: %s\n", text, text->string, text->string);
        hemp_mem_free(text->string);
        text->string = NULL;
    }
}
Example #11
0
File: list.c Project: abw/hemp
HempBool
hemp_list_each_free(
    HempList     list,
    HempPos      pos,
    HempValue    item
) {
//  hemp_debug_mem("freeing list item %d at %p\n", pos, hemp_val_ptr(item));
    /* this assume that each element is a pointer */
    hemp_mem_free( hemp_val_ptr(item) );
    return HEMP_TRUE;
}
Example #12
0
File: slab.c Project: abw/hemp
void
hemp_slab_free(
    HempSlab slab
) {
    HempSlab next_slab;
    while (slab) {
//      hemp_debug_mem("freeing slab at %p\n", slab);
        next_slab = slab->next;
        hemp_mem_free(slab);
        slab = next_slab;
    }
}
Example #13
0
File: test.c Project: abw/hemp
HempUint
hemp_test_expect_file(
    HempString  language,
    HempString  dialect,
    HempString  file,
    HempContext context
) {
    HempString text   = hemp_filesystem_read_file(file);
    HempUint   result = hemp_test_expect_text(language, dialect, text, file, context);
    hemp_mem_free(text);
    return result;
}
Example #14
0
File: list.c Project: abw/hemp
void
hemp_list_release(
    HempList list
) {
    hemp_debug_call("hemp_list_release(%p)\n", list);
    if (list->items) {
        if (list->cleaner) {
            hemp_list_each(list, list->cleaner);
        }
        hemp_mem_free(list->items);
        list->items = NULL;
    }
}
Example #15
0
HEMP_INLINE HempBool
hemp_module_failed(
    HempModule     module,
    HempString     error,
    ...
) {
    if (module->error)
        hemp_mem_free(module->error);

    va_list args;
    va_start(args, error);
    module->error = hemp_string_vprintf(error, args);
    va_end(args);

//  hemp_debug("ERROR: %s\n", module->error);

    return HEMP_FALSE;
}
Example #16
0
File: document.c Project: abw/hemp
void
hemp_document_free(
    HempDocument document
) {
    /* First call any custom cleanup code for the dialect */
    if (document->dialect->cleanup)
        document->dialect->cleanup(document);

    /* Zap the scanner stack if we have one */ 
    if (document->scantags)
        hemp_stack_free(document->scantags);

    /* Free the source, the tagset and then the document object itself. */
    /* The fragments cleaner will take care of cleaning any other tokens */
    hemp_fragments_free(document->fragments);
    hemp_scope_free(document->scope);
    hemp_source_free(document->source);
//    hemp_tagset_free(document->tagset);

    hemp_mem_free(document);
}
Example #17
0
File: viewer.c Project: abw/hemp
void
hemp_viewer_resize(
    HempViewer viewer,
    HempU16    min_size
) {
    hemp_debug_call("hemp_viewer_resize(%s, %d)\n", viewer->name, min_size);
    HempU16    old_size = viewer->size;
    HempU16    new_size = old_size;
    HempMemory buffer;
    HempU16    size;

    if (! new_size)
        new_size = HEMP_VIEW_SIZE;

    while (min_size >= new_size) {
        new_size = new_size << 1;
    }

    size   = new_size * sizeof(hemp_view_f);
    buffer = hemp_mem_alloc(size);

    if (! buffer)
        hemp_mem_fail("viewer view buffer");

    memset(buffer, 0, size);
    hemp_debug_mem("allocated and cleared %d bytes for %d views\n", size, new_size);
        
    if (old_size) {
        size = old_size * sizeof(hemp_view_f);
        hemp_mem_copy(viewer->view, buffer, size);
        hemp_debug_mem("copied %d bytes from previous %d views\n", size, old_size);
        hemp_mem_free(viewer->view);
    }
    
    viewer->view = buffer;
    viewer->size = new_size;
}
Example #18
0
void
hemp_fragment_free(
    HempFragment fragment
) {
    hemp_mem_free(fragment);
}
Example #19
0
HempModule
hemp_use_module(
    Hemp       hemp,
    HempString     type,
    HempString     name
) {
    hemp_debug_call("hemp_use_module(%s => %s)\n", type, name);

    HempValue  path = hemp_config_get(hemp, HEMP_CONFIG_MODPATH);
    HempString string;

    if (hemp_is_defined(path)) {
        string = hemp_to_string(path, hemp->context);
//      hemp_debug_msg("already got %s: %s\n", HEMP_CONFIG_MODPATH, string);
    }
    else {
        HempValue  dir  = hemp_config_get(hemp, HEMP_CONFIG_DIR);
        HempValue  mod  = hemp_config_get(hemp, HEMP_CONFIG_MODDIR);
        HempString dstr = hemp_to_string(dir, hemp->context);
        HempString mstr = hemp_to_string(mod, hemp->context);

        string = hemp_uri_path_join(dstr, mstr, 1);
//      hemp_debug_msg("constructed %s: %s\n", HEMP_CONFIG_MODPATH, string);

        /* ugly work-around so we can get the context to manage memory */
        HempText text = hemp_context_tmp_text_size(hemp->context, strlen(string) + 1);
        hemp_text_append_string(text, string);
        hemp_mem_free(string);
        string = text->string;
//        hemp_config_set(hemp, HEMP_CONFIG_MODPATH, hemp_text_val(text));
    }

    // TODO: need a way to save dotted path (hemp.module_path) back into config

    /* quick hack to get something working */
    HempString modpath = getenv("HEMP_MODULE_PATH");

    if (! modpath || ! *modpath) {
        modpath = string;
//        hemp_debug_msg("No HEMP_MODULE_PATH environment variable set\n");
//        return HEMP_FALSE;
    }

    /* TODO: sort this mess out */
    HempString tpath = hemp_uri_path_join(modpath, type, 1);
    HempString mpath = hemp_uri_path_join(tpath, name, 1);
    HempText   mtext = hemp_text_from_string(mpath);
    hemp_text_append_string(mtext, HEMP_MODULE_EXT);
    hemp_mem_free(mpath);
    hemp_mem_free(tpath);
//  hemp_debug_msg("constructed module path: %s\n", mtext->string);

    HempModule module = hemp_global_module(hemp->global, mtext->string);

    if (module->binder) {
        module->binder(module, hemp);
    }
    else if (module->error) {
        hemp_fatal(module->error);
    }
    else {
        /* should never happen - famous last word */
        hemp_fatal("No binder function for %s module", name);
    }

    hemp_text_free(mtext);
    return module;
}