view src/list/listContext.c @ 123:4ff6f093b695

Fix segmentation fault
author Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
date Tue, 13 Sep 2016 11:54:25 +0900
parents 2ff693c5563c
children
line wrap: on
line source

#include <stdlib.h>

#include "listContext.h"

extern __code code1_stub(struct Context*);
extern __code code2_stub(struct Context*);
extern __code code3_stub(struct Context*);
extern __code code4_stub(struct Context*);
extern __code code5_stub(struct Context*);
extern __code code6_stub(struct Context*);
extern __code code7_stub(struct Context*);
extern __code meta(struct Context*);
extern __code allocate(struct Context*);
extern __code append_stub(struct Context*);
extern __code traverse_stub(struct Context*);
extern __code delete_stub(struct Context*);
extern __code exit_code(struct Context*);

__code initListContext(struct Context* context) {
    context->dataSize   = sizeof(union Data)*ALLOCATE_SIZE;
    context->code       = malloc(sizeof(__code*)*ALLOCATE_SIZE);
    context->data       = malloc(sizeof(union Data*)*ALLOCATE_SIZE);
    context->heap_start = malloc(context->dataSize);

    context->codeNum         = Exit;
    context->code[Allocator] = allocate;
    context->code[Code1]     = code1_stub;
    context->code[Code2]     = code2_stub;
    context->code[Code3]     = code3_stub;
    context->code[Code4]     = code4_stub;
    context->code[Code5]     = code5_stub;
    context->code[Code6]     = code6_stub;
    context->code[Code7]     = code7_stub;
    context->code[Append]    = append_stub;
    context->code[Traverse]  = traverse_stub;
    context->code[Delete]    = delete_stub;
    context->code[Exit]      = exit_code;

    context->heap = context->heap_start;

    context->data[Allocate] = context->heap;
    context->heap          += sizeof(struct Allocate);

    context->data[List]     = context->heap;
    context->heap          += sizeof(struct List);

    context->dataNum = List;
}