Beispiel #1
0
NetStream *net_stream_create (NetStreamOnAdd on_add,
                              NetStreamOnClose on_close, 
                              NetStreamOnRead on_read,
                              void *tag)
{
        NetStream *stream;

        if (!(stream = memory_create (sizeof (NetStream)))) {
                error_code (FunctionCall, 1);
                return NULL;
        }
        if (!(stream->poll = net_poll_create (&poll_on_monitor,
                                              &poll_on_close,
                                              &poll_on_read,
                                              &poll_on_write))) {
                memory_destroy (stream);
                error_code (FunctionCall, 2);
                return NULL;
        }
        if (!(stream->worker = net_stream_worker_create (stream->poll))) {
                net_poll_destroy (stream->poll);
                memory_destroy (stream);
                error_code (FunctionCall, 3);
                return NULL;
        }
        stream->on_add = on_add;
        stream->on_close = on_close;
        stream->on_read = on_read;
        stream->poll->tag = stream;
        stream->tag = tag;
        return stream;
}
DisplayPlugin *display_plugin_create (const char *path)
{
        DisplayPlugin *display_plugin;

        if (!path) {
                error (InvalidArgument);
                return NULL;
        }
        if (!(display_plugin = memory_create (sizeof (DisplayPlugin)))) {
                error_code (FunctionCall, 1);
                return NULL;
        }
        if (!(display_plugin->plugin = plugin_create (path))) {
                memory_destroy (display_plugin);
                error_code (FunctionCall, 2);
                return NULL;
        }
        if (!(plugin_set_function (display_plugin->plugin, 
                                   (void **)&display_plugin->display_canvas, 
                                   "display_canvas"))) {
                plugin_destroy (display_plugin->plugin);
                memory_destroy (display_plugin);
                error_code (FunctionCall, 3);
                return NULL;
        }
        if (!display_plugin->plugin->load ()) {
                plugin_destroy (display_plugin->plugin);
                memory_destroy (display_plugin);
                error_code (FunctionCall, 4);
                return NULL;
        }
        return display_plugin;
}
Beispiel #3
0
void tree_iterator_destroy (TreeIterator *iterator)
{
	if (!iterator) {
		error (InvalidArgument);
		return;
	}
	memory_destroy (iterator->path);
	memory_destroy (iterator);
}
Beispiel #4
0
void tree_destroy (Tree *tree)
{
	if (!tree) {
		error (InvalidArgument);
        	return;
	}
	if (tree->root != tree->nil) {
		node_destroy (tree, tree->root);
	}
	memory_destroy (tree->nil);
    	memory_destroy (tree);
}
Beispiel #5
0
void canvas_destroy (Canvas *canvas)
{
        if (!canvas) {
                error (InvalidArgument);
                return;
        }
        thread_lock_destroy (&canvas->lock);
        if (canvas->image.map) {
                memory_destroy (canvas->image.map);
        }
        memory_destroy (canvas);
}
Beispiel #6
0
void list_destroy (List *list)
{
	ListItem *item;

	if (!list) {
		error (InvalidArgument);
		return;
	}
	for (item = list->first; item; item = list->first) {
		list->first = item->next;
		memory_destroy (item);
	}
	memory_destroy (list);
}
Beispiel #7
0
static char *
test_memory_read_memory_size_bit_0(void)
{
    printf("test_memory_read_memory_size_bit_0\n");
    mu_assert("Memory init failed", memory_init(16384));
    word location;
    location.WORD = 0xFFDA;
    mu_assert("Memory read at FFDA did not return 1", memory_read(location) == 1);
    memory_destroy();
    mu_assert("Memory init failed", memory_init(16385));
    mu_assert("Memory read at FFDA did not return 0", memory_read(location) == 0);
    memory_destroy();
    return 0;
}
Beispiel #8
0
void net_websocket_frame_destroy (NetWebsocketFrame *frame)
{
        if (frame->buffer) {
                memory_destroy (frame->buffer);
                frame->buffer = NULL;
        }
}
void compile_project_destroy (CompileProject *project)
{
	ListNode *node;

	if (!project) {
		return;
	}
	if (project->directory) {
		directory_close (project->directory);
	}
	if (project->topological) {
		topological_destroy (project->topological);
	}
	if (project->directory_to_compile) {
		tree_destroy (project->directory_to_compile);
	}
	if (project->sorted) {
		list_destroy (project->sorted);
	}
	for (node = list_first (project->nodes); node; node = list_next (node)) {
		compile_destroy (node->data);
	}
	if (project->nodes) {
		list_destroy (project->nodes);
	}
	memory_destroy (project);
}
Beispiel #10
0
static char *
test_memory_init_negative_bytes_returns_false(void)
{
    printf("test_memory_init_negative_bytes_returns_false\n");
    mu_assert("Memory init succeeded", !memory_init(-10));
    memory_destroy();
    return 0;
}
Beispiel #11
0
static char *
test_memory_init_map_mode_set_to_zero(void)
{
    printf("test_memory_init_map_mode_set_to_zero\n");
    mu_assert("Memory init failed", memory_init(4096));
    mu_assert("memory_map_mode not zero", memory_map_mode == 0);
    memory_destroy();
    return 0;
}
Beispiel #12
0
static char *
test_memory_init_4096_correct_bits_set(void) 
{
    printf("test_memory_init_4096_correct_bits_set\n");
    mu_assert("memory_size_bit_0 incorrect", memory_size_bit_0 == 0);
    mu_assert("memory_size_bit_1 incorrect", memory_size_bit_0 == 0);
    memory_destroy();
    return 0;
}
Beispiel #13
0
static char *
test_memory_init_memory_not_null(void) 
{
    printf("test_memory_init_memory_not_null\n");
    mu_assert("Could not allocate memory", memory_init(4096));
    mu_assert("Memory returned was NULL", memory != NULL);
    memory_destroy();
    return 0;    
}
void pattern_tokens_destroy (List *tokens)
{
	PatternToken *token;
	PatternTokenSet *set;
	ListNode *node;

	for (node = list_first (tokens); node; node = list_next (node)) {
		token = node->data;
		if (token->type == PatternTokenTypeSet) {
			set = (PatternTokenSet *)token;
			if (set->values != NULL) {
				memory_destroy (set->values);
			}
		}
		memory_destroy (node->data);
	}
	list_destroy (tokens);
}
Beispiel #15
0
void net_stream_destroy (NetStream *stream)
{
        if (!stream) {
                error (InvalidArgument);
                return;
        }
        net_stream_worker_destroy (stream->worker);
        net_poll_destroy (stream->poll);
        memory_destroy (stream);
}
Beispiel #16
0
bool test_file_path_size_1 (Test *test)
{
	char *path;

	TITLE ();
	file_path_size (0);
	CATCH (!(path = directory_current_path ()));
	memory_destroy (path);
	PASS ();
}
Beispiel #17
0
void list_remove (List *list, ListNode *node)
{
        if (!list ||
	    !node) {
		error (InvalidArgument);
		return;
	}
        list_item_remove (list, (ListItem *)node);
        memory_destroy (node);
}
void display_plugin_destroy (DisplayPlugin *display_plugin)
{
        if (!display_plugin) {
                error (InvalidArgument);
                return;
        }
        display_plugin->plugin->unload ();
        plugin_destroy (display_plugin->plugin);
        memory_destroy (display_plugin);
}
Beispiel #19
0
static void node_destroy (Tree *tree, TreeNode *node)
{
	if (node->link[0] != tree->nil) {
		node_destroy (tree, node->link[0]);
	}
	if (node->link[1] != tree->nil) {
		node_destroy (tree, node->link[1]);
	}
	memory_destroy (node);
}
Beispiel #20
0
static char *
test_memory_less_than_4096(void)
{
    printf("test_memory_less_than_4096\n");
    mu_assert("Memory init failed", memory_init(512));
    mu_assert("memory_size_bit_0 not 0", memory_size_bit_0 == 0);
    mu_assert("memory_size_bit_1 not 0", memory_size_bit_0 == 0);
    memory_destroy();
    return 0;
}
Beispiel #21
0
static char *
test_memory_more_than_16k(void)
{
    printf("test_memory_more_than_16k\n");
    mu_assert("Memory init failed", memory_init(16385));
    mu_assert("memory_size_bit_0 not 0", memory_size_bit_0 == 0);
    mu_assert("memory_size_bit_1 not 1", memory_size_bit_1 == 1);
    memory_destroy();
    return 0;
}
Beispiel #22
0
void
emulator_destroy(emulator_t* emu)
{
  fb_destroy(&emu->fb);
  pr_destroy(&emu->pr);
  mbox_destroy(&emu->mbox);
  gpio_destroy(&emu->gpio);
  cpu_destroy(&emu->cpu);
  vfp_destroy(&emu->vfp);
  memory_destroy(&emu->memory);
}
Beispiel #23
0
static char *
test_memory_write_writes_to_byte_zero(void)
{
    word location;
    location.WORD = 0;
    printf("test_memory_write_writes_to_byte_zero\n");
    mu_assert("Memory init failed", memory_init(4096));
    memory_write(location, 1);
    mu_assert("Incorrect byte written", memory[0] == 1);
    memory_destroy();
    return 0;
}
Beispiel #24
0
static char *
test_memory_read_correct_byte(void)
{
    word location;
    location.WORD = 0x100;
    printf("test_memory_read_correct_byte\n");
    mu_assert("Memory init failed", memory_init(4096));
    memory[location.WORD] = 0x12;
    mu_assert("Read failed(expected 0x12)", memory[location.WORD] == 0x12);
    memory_destroy();
    return 0;
}
Beispiel #25
0
Canvas *canvas_create (Size size)
{
        Canvas *canvas;

        if (size.width == 0) {
                error_code (InvalidArgument, 1);
                return NULL;
        }
        if (size.height == 0) {
                error_code (InvalidArgument, 2);
                return NULL;
        }
        if (!size_t_mul (size.width, size.height, NULL)) {
                error_code (Overflow, 1);
                return NULL;
        }
        if (!size_t_mul (size.width * size.height, sizeof (Color), NULL)) {
                error_code (Overflow, 2);
                return NULL;
        }
        if (!(canvas = memory_create (sizeof (Canvas)))) {
                error_code (FunctionCall, 1);
                return NULL;
        }
        if (!thread_lock_create (&canvas->lock)) {
                memory_destroy (canvas);
                error_code (FunctionCall, 2);
                return NULL;
        }
        if (!(canvas->image.map = memory_create (size.width * size.height * sizeof (Color)))) {
                thread_lock_destroy (&canvas->lock);
                memory_destroy (canvas);
                error_code (FunctionCall, 3);
                return NULL;
        }
        canvas->image.width = size.width;
        canvas->image.height = size.height;
        canvas->changed = false;
        return canvas;
}
Beispiel #26
0
static char *
test_memory_write_writes_correct_byte(void)
{
    word location;
    byte value = 0x12;
    location.WORD = 0x100;
    printf("test_memory_write_writes_correct_byte\n");
    mu_assert("Memory init failed", memory_init(4096));
    memory_write(location, value);
    mu_assert("Write failed(expected 0x12)", memory[location.WORD] == 0x12);
    memory_destroy();
    return 0;
}
Beispiel #27
0
static char *
test_memory_read16_read_correct_word(void)
{
    word location, value;
    location.WORD = 0x100;
    printf("test_memory_read16_read_correct_word\n");
    mu_assert("Memory init failed", memory_init(4096));
    memory[location.WORD] = 0x12;
    memory[location.WORD + 1] = 0x34;
    value = memory_read16(location);
    mu_assert("Read failed(expected 0x1234)", value.WORD == 0x1234);
    memory_destroy();
    return 0;
}
void file_reader_destroy (FileReader *reader)
{
	if (!reader) {
                error (InvalidArgument);
		return;
	}
	if (reader->map) {
		munmap (reader->map, (size_t)reader->size);
	}
	if (reader->file_descriptor != -1) {
		close (reader->file_descriptor);
	}
	memory_destroy (reader);
}
Beispiel #29
0
static char *
test_memory_write16_writes_correct_word(void)
{
    word location, value;
    location.WORD = 0x100;
    printf("test_memory_write16_writes_correct_word\n");
    mu_assert("Memory init failed", memory_init(4096));
    value.BYTE.high = 0xE8;
    value.BYTE.low = 0x12;
    memory_write16(location, value);
    mu_assert("Write failed(expected 0xE8)", memory[0x100] == 0xE8);
    mu_assert("Write failed(expected 0x12)", memory[0x101] == 0x12);
    memory_destroy();
    return 0;
}
Beispiel #30
0
void net_poll_events_destroy (NetPollEvents *events)
{
        if (!events) {
                error (InvalidArgument);
                return;
        }
        queue_destroy (&events->queue);
        if (events->internal_event != -1) {
                close (events->internal_event);
        }
        if (events->file != -1) {
                close (events->file);
        }
        memory_destroy (events);
}