Esempio n. 1
0
/* create or initialize empty slist structure */
slist *
sinit() {
	slist *sl;

	sl=(slist *)sf_calloc(1, sizeof(slist));
	if(!sl)
		return NULL;

	sl->listlen = 4;

	sl->list = (char **)sf_malloc(sizeof(char *) * sl->listlen);
	if(!sl->list) {
		free(sl);
		return NULL;
	}

	sl->lens = (size_t *)sf_malloc(sizeof(size_t) * sl->listlen);
	if(!sl->lens) {
		free(sl->list);
		free(sl);
		return NULL;
	}

	*(sl->list) = NULL;
	*(sl->lens) = 0;

	return sl;
};
Esempio n. 2
0
sf_vartable_t* sf_var_create(char *name, char *value, ngx_pool_t *pool)
{
#if 0
    sf_vartable_t *v = sf_calloc (sizeof(sf_vartable_t));
    v->name = sf_strdup(name);
    v->value = value?sf_strdup(value):strdup("");
#endif    
    sf_vartable_t *v = ngx_pcalloc(pool, sizeof(sf_vartable_t));
    v->name = ngx_pstrdup(pool, name);
    v->value = value?ngx_pstrdup(pool, value):"";
    return v;
}
Esempio n. 3
0
int main(int argc, char *argv[]) {
    // Initialize the custom allocator
    sf_mem_init(MAX_HEAP_SIZE);

    // Tell the user about the fields
    info("Initialized heap with %dmb of heap space.\n", MAX_HEAP_SIZE >> 20);
    //press_to_cont(); 

    // Print out title for first test
    printf("=== Test1: Allocation test ===\n");
    // Test #1: Allocate an integer
    int *value1 = sf_malloc(sizeof(int));
    null_check(value1, sizeof(int));
    payload_check(value1);
    // Print out the allocator block
    sf_varprint(value1);
    //press_to_cont();

    // Now assign a value
    printf("=== Test2: Assignment test ===\n");
    info("Attempting to assign value1 = %d\n", VALUE1_VALUE);
    // Assign the value
    *value1 = VALUE1_VALUE;
    // Now check its value
    check_prim_contents(value1, VALUE1_VALUE, "%d", "value1");
    //press_to_cont();

    printf("=== Test3: Allocate a second variable ===\n");
    info("Attempting to assign value2 = %ld\n", VALUE2_VALUE);
    long *value2 = sf_malloc(sizeof(long));
    null_check(value2, sizeof(long));
    payload_check(value2);
    sf_varprint(value2);
    // Assign a value
    *value2 = VALUE2_VALUE;
    // Check value
    check_prim_contents(value2, VALUE2_VALUE, "%ld", "value2");
    //press_to_cont();

    printf("=== Test4: does value1 still equal %d ===\n", VALUE1_VALUE);
    check_prim_contents(value1, VALUE1_VALUE, "%d", "value1");
    //press_to_cont();

    // Snapshot the freelist
    printf("=== Test5: Perform a snapshot ===\n");
    sf_snapshot(true);
    //press_to_cont();

    // Free a variable
    printf("=== Test6: Free a block and snapshot ===\n");
    info("Freeing value1...\n");
    sf_free(value1);
    sf_snapshot(true);
    //press_to_cont();

    // Allocate more memory
    printf("=== Test7: 8192 byte allocation ===\n");
    void *memory = sf_calloc(4096,1);
    sf_varprint(memory);
    perror("Testing calloc");
    sf_snapshot(true);
    memory = sf_malloc(8192);
    sf_varprint(memory);
    perror("Testing free");
    sf_free(memory);
    //press_to_cont();

    return EXIT_SUCCESS;
}