void attack(void) { object_t *objp = (object_t *)random(); object_t obj = (object_t)random(); char *name = (char *)random(); void *msg = (void *)random(); size_t size = (size_t)random(); task_t self = task_self(); void *addr = (void *)random(); int attr = random() & 7; thread_t t = (thread_t)random(); thread_t *tp = (thread_t *)random(); object_create(NULL, NULL); object_create(NULL, objp); object_create(name, NULL); object_create(name, objp); object_destroy(0); object_destroy(obj); object_lookup(NULL, objp); object_lookup(name, NULL); object_lookup(name, objp); msg_send(0, msg, size); msg_send(obj, NULL, size); msg_send(obj, msg, 0); msg_send(0, msg, 0); msg_send(0, NULL, size); msg_send(obj, msg, size); msg_receive(0, msg, size); msg_receive(obj, NULL, size); msg_receive(obj, msg, 0); msg_receive(0, msg, 0); msg_receive(0, NULL, size); msg_receive(obj, msg, size); msg_reply(0, msg, size); msg_reply(obj, NULL, size); msg_reply(obj, msg, 0); msg_reply(0, msg, 0); msg_reply(0, NULL, size); msg_reply(obj, msg, size); vm_allocate(self, addr, size, 1); vm_allocate(self, &addr, size, 1); vm_free(self, addr); vm_attribute(self, addr, attr); vm_map(self, addr, size, &addr); thread_create(self, tp); thread_suspend(t); thread_terminate(t); }
static void __for_each(Map *map,void (*func)(Iterator *iter)) { Iterator *cur, *end; dbg_str(OBJ_IMPORTANT,"Map for_each"); cur = map->begin(map); end = map->end(map); for(; !end->equal(end,cur); cur->next(cur)) { func(cur); } object_destroy(cur); object_destroy(end); }
static void destroy(Link self){ BWindow win = self->value.vptr; im_free( win->items); bwindow_free(win); if ( win->onClose) link_free(win->onClose); object_destroy(self); }
void char_remove_inventory(struct character_t *pChar, struct object_t *object) { unsigned i; for(i=0; i<pChar->inventory_count; ++i) { if(pChar->inventory[i] == object) { object_destroy(object); --pChar->inventory_count; if(pChar->inventory_count > 0 && i < pChar->inventory_count) { // swap the last item with the current item and set the last item pointer to null pChar->inventory[i] = pChar->inventory[pChar->inventory_count]; pChar->inventory[pChar->inventory_count] = NULL; } else { pChar->inventory[i] = NULL; } return; } } }
bool write_file(size_t object_size, bool sized) { char filename[64]; benchmark_filename(filename, sizeof(filename), object_size, BENCHMARK_FORMAT_UBJSON, sized ? NULL : "-unopt"); FILE* file = fopen(filename, "wb"); if (!file) { fprintf(stderr, "error opening file for writing!\n"); return false; } // ubjw_open_file() doesn't register any error handler, and // does not check the return value of calls to fwrite() either. // it doesn't seem to have any way of handling i/o errors at all, // such as disk full errors or broken pipes. this seems like // a serious flaw; there's no way to tell if the data was // truncated. ubjw_context_t* dst = ubjw_open_file(file); object_t* object = benchmark_object_create(object_size); bool ok = write_object(dst, object, sized); object_destroy(object); ubjw_close_context(dst); return ok; }
void test_ui_sdl_grath() { Sdl_Graph *sdl_grath; allocator_t *allocator = allocator_get_default_alloc(); char *set_str; cjson_t *root, *e, *s; char buf[2048]; root = cjson_create_object();{ cjson_add_item_to_object(root, "Sdl_Graph", e = cjson_create_object());{ cjson_add_string_to_object(e, "name", "alan"); } } set_str = cjson_print(root); sdl_grath = OBJECT_NEW(allocator, Sdl_Graph,set_str); object_dump(sdl_grath, "Sdl_Graph", buf, 2048); dbg_str(DBG_DETAIL,"Sdl_Graph dump: %s",buf); object_destroy(sdl_grath); free(set_str); }
static void _obj_create (gpointer key, gpointer value, gpointer user_data) { gchar *name = (gchar *)key; DiaObjectType *type = (DiaObjectType *)value; GHashTable *ht = (GHashTable *) user_data; DiaObject *obj; Point startpoint = {0.0,0.0}; Handle *handle1,*handle2; g_assert (g_hash_table_lookup (ht, name) == NULL); /* at least 'Group' has no ops */ if (!type->ops) return; /* the custom objects needs extra_data */ obj = type->ops->create(&startpoint, type->default_user_data, &handle1,&handle2); if (!obj) g_warning ("Failed to create default object for '%s'", name); else if (0 != strcmp (obj->type->name, name)) object_destroy (obj); /* Skip over 'compatibility' names/objects */ else g_hash_table_insert(ht, obj->type->name, obj); }
bool setup_test(size_t object_size) { object_t* object = benchmark_object_create(object_size); binn root; bool ok; if (object->type == type_map) { binn_create_object(&root); ok = write_object(&root, object); } else { binn_create_list(&root); ok = write_list(&root, object); } object_destroy(object); if (!ok) { fprintf(stderr, "binn error writing data!\n"); binn_free(&root); return false; } char filename[64]; benchmark_filename(filename, sizeof(filename), object_size, BENCHMARK_FORMAT_BINN, NULL); FILE* file = fopen(filename, "wb"); fwrite(binn_ptr(&root), binn_size(&root), 1, file); fclose(file); // like libbson, we call binn_free() regardless of whether // we placed it on the stack or the heap; it stores a flag // to say whether it should be freed. this apparently doesn't // cause warnings since GCC chooses not to inline binn_free(). binn_free(&root); return true; }
void object_dec_ref (Object *obj) { assert (obj->ref_count > 0); if (--obj->ref_count == 0) object_destroy (obj); }
static void compound_destroy (Compound * comp) { compound_sanity_check (comp, "Destroying"); object_destroy (&comp->object); g_free (comp->handles); }
static void textobj_destroy(Textobj *textobj) { text_destroy(textobj->text); g_free (textobj->object.enclosing_box); textobj->object.enclosing_box = NULL; object_destroy(&textobj->object); }
/*! * \brief Destruction of the object * \memberof StdPath */ static void stdpath_destroy (StdPath *stdpath) { object_destroy(&stdpath->object); if (stdpath->pattern) g_object_unref (stdpath->pattern); g_free (stdpath->points); /* but not the object itself */ }
/*! * \brief Destruction of the object * \memberof Outline */ static void outline_destroy (Outline *outline) { if (outline->path) cairo_path_destroy (outline->path); g_free (outline->name); object_destroy(&outline->object); /* but not the object itself? */ }
static void destroy(Link self){ Dict dict = self->value.vptr; if (dict){ dictionary_free(dict->dictionary); mutex_free(dict->mutex); free(self->value.vptr); } object_destroy(self); }
/* object real destruction function, calls class destroy functions */ void object_actual_destroy( object_t *object ) { if ( object->destroy_pending == 0 ) { /* object must be finalized first. */ object_destroy( object ); return; } object_run_class_destroy( object, object->class_type->info ); }
/** Release a user semaphore. * @param sem Semaphore to release. */ static void user_semaphore_release(user_semaphore_t *sem) { if(refcount_dec(&sem->count) == 0) { rwlock_write_lock(&semaphore_tree_lock); avl_tree_remove(&semaphore_tree, &sem->tree_link); rwlock_unlock(&semaphore_tree_lock); object_destroy(&sem->obj); id_allocator_free(&semaphore_id_allocator, sem->id); kfree(sem); } }
int main(int argc, char **argv) { const char* name = argv[0]; ++argv; --argc; // argument "-r" will print only the per-iteration time result of the test bool result_only = false; if (argc >= 1 && strcmp(argv[0], "-r") == 0) { result_only = true; ++argv; --argc; } // need sizes if (argc == 0) { fprintf(stderr, "%s: object sizes in the range [1,5] must be " "provided as command-line arguments\n", name); return EXIT_FAILURE; } // generate a throwaway object. we do this so that the generator code // is included in hash readers (it is necessary for hash-object, so we // force all benchmarks to include it so we can subtract the // size correctly) object_destroy(benchmark_object_create(1)); // get executable details struct stat st; stat(name, &st); size_t binary_size = st.st_size; static const char* build = "build/"; if (strlen(name) > strlen(build) && memcmp(name, build, strlen(build)) == 0) name += strlen(build); if (!result_only) printf("%s: executable size: %i bytes\n", name, (int)binary_size); // run different benchmark sizes fragment_memory(); for (; argc > 0; --argc, ++argv) { size_t object_size = atoi(argv[0]); if (object_size < 1 || object_size > 5) { fprintf(stderr, "%s: object size must be in the range [1,5]\n", name); return EXIT_FAILURE; } if (!go(result_only, object_size, (int)st.st_size, name)) return EXIT_FAILURE; } free_fragmented_memory(); return EXIT_SUCCESS; }
int vector_destructor(object_t *self) { if (self->vector.value == NULL) return -1; size_t size = self->vector.length; while (size--) object_destroy(self->vector.value[size]); free(self->vector.value); return 0; }
/* * Send thread */ static void send_thread(void) { struct my_msg msg; object_t o1, o2; int error; char string[] = "A lazy dog laying on the road!!"; printf("Send thread is starting...\n"); /* * Find objects. */ error = object_lookup("test-A", &o1); error = object_lookup("test-B", &o2); /* * Wait a sec. */ timer_sleep(1000, 0); /* * Delete object A. */ printf("Delete object A\n"); object_destroy(o1); /* * Wait a sec. */ timer_sleep(1000, 0); /* * Send message to object B. */ printf("Send message to object B.\n"); strncpy(msg.data, string, sizeof(string)); msg.hdr.code = 42; msg_send(o2, &msg, sizeof(msg)); printf("Send completed.\n"); for (;;) ; }
void polyconn_destroy(PolyConn *poly) { int i; Handle **temp_handles; /* Need to store these temporary since object.handles is freed by object_destroy() */ temp_handles = g_new(Handle *, poly->numpoints); for (i=0;i<poly->numpoints;i++) temp_handles[i] = poly->object.handles[i]; object_destroy(&poly->object); for (i=0;i<poly->numpoints;i++) g_free(temp_handles[i]); g_free(temp_handles); g_free(poly->points); }
/* * Send thread */ static void send_thread(void) { struct msg msg; object_t o1, o2; int error; printf("Send thread is starting...\n"); /* * Find objects. */ error = object_lookup("test-A", &o1); error = object_lookup("test-B", &o2); /* * Wait a sec. */ timer_sleep(1000, 0); /* * Delete object A. */ printf("Delete object A\n"); object_destroy(o1); /* * Wait a sec. */ timer_sleep(1000, 0); /* * Send message to object B. */ printf("Send message to object B.\n"); msg_send(o2, &msg, sizeof(msg)); printf("Send completed.\n"); for (;;) ; }
void test_ui_sdl_window() { Window *window; Graph *g; allocator_t *allocator = allocator_get_default_alloc(); char *set_str; char buf[2048]; set_str = gen_window_setting_str(); window = OBJECT_NEW(allocator, Sdl_Window,set_str); g = window->graph; object_dump(window, "Sdl_Window", buf, 2048); dbg_str(DBG_DETAIL,"Window dump: %s",buf); dbg_str(DBG_DETAIL,"render draw test"); g->render_draw_image(g,0,0,window->background); g->render_present(g); sleep(2); g->render_clear(g); g->render_set_color(g,0xff,0x0,0xff,0xff); g->render_draw_line(g,20,0,50,50); g->render_set_color(g,0xff,0x0,0x0,0xff); g->render_draw_rect(g,20,20,100,100); /* *g->render_fill_rect(g,20,20,100,100); */ g->render_present(g); sleep(5); object_destroy(window); free(set_str); }
void teardown_test(void) { object_destroy(root_object); }
static void thread_destroy(Link self){ free(self->value.vptr); object_destroy(self); }
static void af_destroy(Link self){ if (self->value.vptr) link_free(self->value.vptr); object_destroy(self); }
static void mutex_destroy(Link self){ mutex_free(self->value.vptr); object_destroy(self); }
static void sqlite_destroy(Link self){ Sqlite sql = self->value.vptr; if ( sql->db ) sqlite3_close(sql->db); object_destroy(self); }
static int __render_unload_text(Sdl_Graph *graph, void *text) { dbg_str(DBG_DETAIL,"Sdl_Text unload text"); object_destroy(text); }
static void destroy(Link self){ if (self->value.vptr)stream_close(self->value.vptr); self->value.vptr = NULL; object_destroy(self); }
static int __render_unload_character(Sdl_Graph *graph, void *character) { dbg_str(DBG_DETAIL,"Sdl_Text unload character"); object_destroy(character); }