END_TEST START_TEST(eina_binshare_collision) { Eina_Array *ea; char buffer[50]; int i; srand(time(NULL)); eina_init(); ea = eina_array_new(256); fail_if(!ea); for (i = 0; i < 10000; ++i) { eina_convert_itoa(rand(), buffer); eina_array_push(ea, (void *)eina_binshare_add_length(buffer, strlen(buffer))); if (rand() > RAND_MAX / 2) { const char *r = eina_binshare_add_length(buffer, strlen(buffer)); fail_if(r == NULL); } } for (i = 0; i < 10000; ++i) { const char *r; eina_convert_itoa(60000 - i, buffer); eina_array_push(ea, (void *)eina_binshare_add_length(buffer, strlen(buffer))); r = eina_binshare_add_length(buffer, strlen(buffer)); fail_if(r == NULL); r = eina_binshare_add_length(buffer, strlen(buffer)); fail_if(r == NULL); } for (i = 0; i < 200; ++i) eina_binshare_del(eina_array_data_get(ea, i)); for (i = 0; i < 1000; ++i) eina_binshare_del(eina_array_pop(ea)); eina_shutdown(); eina_array_free(ea); }
void xml_new_user(xmlDocPtr doc, zrpc_user *user) { xmlNodePtr node, node2, p, v, i, s, n, m; char i2[13]; node = xmlDocGetRootElement(doc); //methodCall for (node2 = node; node2; node2 = node2->children->next) if (!strcmp((char*)node2->name, "params")) { p = xmlNewChild(node2, NULL, BAD_CAST "param", NULL); v = xmlNewChild(p, NULL, BAD_CAST "value", NULL); s = xmlNewChild(v, NULL, BAD_CAST "struct", NULL); m = xmlNewChild(s, NULL, BAD_CAST "member", NULL); n = xmlNewChild(m, NULL, BAD_CAST "name", BAD_CAST "uid"); v = xmlNewChild(m, NULL, BAD_CAST "value", NULL); eina_convert_itoa(user->uid, i2); i = xmlNewChild(v, NULL, BAD_CAST "int", BAD_CAST i2); m = xmlNewChild(s, NULL, BAD_CAST "member", NULL); n = xmlNewChild(m, NULL, BAD_CAST "name", BAD_CAST "name"); v = xmlNewChild(m, NULL, BAD_CAST "value", NULL); i = xmlNewChild(v, NULL, BAD_CAST "string", BAD_CAST user->name); m = xmlNewChild(s, NULL, BAD_CAST "member", NULL); n = xmlNewChild(m, NULL, BAD_CAST "name", BAD_CAST "email"); v = xmlNewChild(m, NULL, BAD_CAST "value", NULL); i = xmlNewChild(v, NULL, BAD_CAST "string", BAD_CAST user->email); m = xmlNewChild(s, NULL, BAD_CAST "member", NULL); n = xmlNewChild(m, NULL, BAD_CAST "name", BAD_CAST "active"); v = xmlNewChild(m, NULL, BAD_CAST "value", NULL); eina_convert_itoa(user->active, i2); i = xmlNewChild(v, NULL, BAD_CAST "int", BAD_CAST i2); m = xmlNewChild(s, NULL, BAD_CAST "member", NULL); n = xmlNewChild(m, NULL, BAD_CAST "name", BAD_CAST "type"); v = xmlNewChild(m, NULL, BAD_CAST "value", NULL); eina_convert_itoa(user->type, i2); i = xmlNewChild(v, NULL, BAD_CAST "int", BAD_CAST i2); m = xmlNewChild(s, NULL, BAD_CAST "member", NULL); n = xmlNewChild(m, NULL, BAD_CAST "name", BAD_CAST "language"); v = xmlNewChild(m, NULL, BAD_CAST "value", NULL); i = xmlNewChild(v, NULL, BAD_CAST "string", BAD_CAST user->language); break; } }
static void eina_bench_lookup_evas(int request) { Evas_Hash *hash = NULL; Eina_Array *array = NULL; int *tmp_val; Eina_Array_Iterator it; unsigned int i; unsigned int j; array = eina_array_new(10000); for (i = 0; i < (unsigned int)request; ++i) { char tmp_key[10]; tmp_val = malloc(sizeof (int)); if (!tmp_val) continue; eina_convert_itoa(i, tmp_key); *tmp_val = i; hash = evas_hash_add(hash, tmp_key, tmp_val); eina_array_push(array, tmp_val); } srand(time(NULL)); for (j = 0; j < 200; ++j) for (i = 0; i < (unsigned int)request; ++i) { char tmp_key[10]; eina_convert_itoa(rand() % request, tmp_key); tmp_val = evas_hash_find(hash, tmp_key); } evas_hash_free(hash); EINA_ARRAY_ITER_NEXT(array, i, tmp_val, it) free(tmp_val); eina_array_free(array); }
END_TEST START_TEST(eina_hash_extended) { Eina_Hash *hash = NULL; int i; fail_if(eina_init() != 2); hash = eina_hash_string_djb2_new(NULL); fail_if(hash == NULL); fail_if(eina_hash_direct_add(hash, "42", "42") != EINA_TRUE); for (i = 43; i < 3043; ++i) { char *tmp = malloc(10); fail_if(!tmp); eina_convert_itoa(i, tmp); fail_if(eina_hash_direct_add(hash, tmp, tmp) != EINA_TRUE); } fail_if(eina_hash_find(hash, "42") == NULL); eina_hash_free(hash); fail_if(eina_shutdown() != 1); }
static void eina_bench_lookup_rbtree(int request) { Eina_Rbtree *root = NULL; int i; int j; for (i = 0; i < request; ++i) { Eina_Bench_Rbtree *tmp; tmp = malloc(sizeof (Eina_Bench_Rbtree)); if (!tmp) continue; tmp->value = i; eina_convert_itoa(i, tmp->key); root = eina_rbtree_inline_insert(root, &tmp->node, EINA_RBTREE_CMP_NODE_CB( _eina_bench_rbtree_cmp), NULL); } srand(time(NULL)); for (j = 0; j < 200; ++j) for (i = 0; i < request; ++i) { Eina_Rbtree *tmp; char tmp_key[10]; eina_convert_itoa(rand() % request, tmp_key); tmp = eina_rbtree_inline_lookup(root, tmp_key, 10, EINA_RBTREE_CMP_KEY_CB( _eina_bench_rbtree_key), NULL); /* Suppress warnings as we really don't want to do anything. */ (void) tmp; } eina_rbtree_delete(root, EINA_RBTREE_FREE_CB(_eina_bench_rbtree_free), NULL); }
static void eina_bench_lookup_djb2_inline(int request) { Eina_Hash *hash = NULL; Eina_Bench_DJB2 *elm; unsigned int i; unsigned int j; hash = eina_hash_string_djb2_new(free); for (i = 0; i < (unsigned int)request; ++i) { int length; elm = malloc(sizeof (Eina_Bench_DJB2) + 10); if (!elm) continue; elm->key = (char *)(elm + 1); length = eina_convert_itoa(i, elm->key) + 1; elm->value = i; eina_hash_direct_add_by_hash(hash, elm->key, length, eina_hash_djb2(elm->key, length), elm); } srand(time(NULL)); for (j = 0; j < 200; ++j) for (i = 0; i < (unsigned int)request; ++i) { char tmp_key[10]; int length = eina_convert_itoa(rand() % request, tmp_key) + 1; elm = eina_hash_find_by_hash(hash, tmp_key, length, eina_hash_djb2(tmp_key, length)); } eina_hash_free(hash); }
static void eina_bench_lookup_cityhash(int request) { Eina_Hash *hash = NULL; int *tmp_val; unsigned int i; unsigned int j; hash = eina_hash_new(EINA_KEY_LENGTH(_eina_string_key_length), EINA_KEY_CMP(_eina_string_key_cmp), EINA_KEY_HASH(CityHash64), free, 8); for (i = 0; i < (unsigned int)request; ++i) { char tmp_key[10]; tmp_val = malloc(sizeof (int)); if (!tmp_val) continue; eina_convert_itoa(i, tmp_key); *tmp_val = i; eina_hash_add(hash, tmp_key, tmp_val); } srand(time(NULL)); for (j = 0; j < 200; ++j) for (i = 0; i < (unsigned int)request; ++i) { char tmp_key[10]; eina_convert_itoa(rand() % request, tmp_key); tmp_val = eina_hash_find(hash, tmp_key); } eina_hash_free(hash); }
/** * @brief Convert a double to a string. * * @param d The double to convert. * @param des The destination buffer to store the converted double. * @return #EINA_TRUE on success, #EINA_FALSE otherwise. * * This function converts the double @p d to a string. The string is * stored in the buffer pointed by @p des and must be sufficiently * large to contain the converted double. The returned string is nul * terminated and has the following format: * * @code * [-]0xh.hhhhhp[+-]e * @endcode * * where the h are the hexadecimal cyphers of the mantiss and e the * exponent (a decimal number). * * The returned value is the length of the string, including the nul * character. */ EAPI int eina_convert_dtoa(double d, char *des) { int length = 0; int p; int i; EINA_SAFETY_ON_NULL_RETURN_VAL(des, EINA_FALSE); if (d < 0.0) { *(des++) = '-'; d = -d; length++; } d = frexp(d, &p); if (p) { d *= 2; p -= 1; } *(des++) = '0'; *(des++) = 'x'; *(des++) = look_up_table[(size_t) d]; *(des++) = '.'; length += 4; for (i = 0; i < 16; i++, length++) { d -= floor(d); d *= 16; *(des++) = look_up_table[(size_t) d]; } while (*(des - 1) == '0') { des--; length--; } if (*(des - 1) == '.') { des--; length--; } *(des++) = 'p'; if (p < 0) { *(des++) = '-'; p = -p; } else *(des++) = '+'; length += 2; return length + eina_convert_itoa(p, des); }
static void eina_bench_lookup_ecore(int request) { Ecore_Hash *hash = NULL; Eina_Bench_Ecore *elm; unsigned int i; unsigned int j; hash = ecore_hash_new(ecore_str_hash, ecore_str_compare); ecore_hash_free_key_cb_set(hash, NULL); ecore_hash_free_value_cb_set(hash, free); for (i = 0; i < (unsigned int)request; ++i) { elm = malloc(sizeof (Eina_Bench_Ecore) + 10); if (!elm) continue; elm->key = (char *)(elm + 1); eina_convert_itoa(i, elm->key); elm->value = i; ecore_hash_set(hash, elm->key, elm); } srand(time(NULL)); for (j = 0; j < 200; ++j) for (i = 0; i < (unsigned int)request; ++i) { char tmp_key[10]; eina_convert_itoa(rand() % request, tmp_key); elm = ecore_hash_get(hash, tmp_key); } ecore_hash_destroy(hash); }
static void eina_bench_lookup_djb2(int request) { Eina_Hash *hash = NULL; int *tmp_val; unsigned int i; unsigned int j; hash = eina_hash_string_djb2_new(free); for (i = 0; i < (unsigned int)request; ++i) { char tmp_key[10]; tmp_val = malloc(sizeof (int)); if (!tmp_val) continue; eina_convert_itoa(i, tmp_key); *tmp_val = i; eina_hash_add(hash, tmp_key, tmp_val); } srand(time(NULL)); for (j = 0; j < 200; ++j) for (i = 0; i < (unsigned int)request; ++i) { char tmp_key[10]; eina_convert_itoa(rand() % request, tmp_key); tmp_val = eina_hash_find(hash, tmp_key); } eina_hash_free(hash); }
static void eina_bench_lookup_ghash(int request) { Eina_Bench_Glib *elm; GHashTable *hash; unsigned int i; unsigned int j; hash = g_hash_table_new_full(g_str_hash, g_str_equal, NULL, free); for (i = 0; i < (unsigned int)request; ++i) { elm = malloc(sizeof (Eina_Bench_Glib) + 10); if (!elm) continue; elm->key = (char *)(elm + 1); eina_convert_itoa(i, elm->key); elm->value = i; g_hash_table_insert(hash, elm->key, elm); } srand(time(NULL)); for (j = 0; j < 200; ++j) for (i = 0; i < (unsigned int)request; ++i) { char tmp_key[10]; eina_convert_itoa(rand() % request, tmp_key); elm = g_hash_table_lookup(hash, tmp_key); } g_hash_table_destroy(hash); }
//adds a new int param void xml_new_int(xmlDocPtr doc, int i, int array) { xmlNodePtr node, node2, p, v, s; char i2[13]; eina_convert_itoa(i, i2); node = xmlDocGetRootElement(doc); //methodCall for (node2 = node; node2; node2 = node2->children->next) if (!strcmp((char*)node2->name, (array) ? "data" : "params")) { p = (array) ? node2 : xmlNewChild(node2, NULL, BAD_CAST "param", NULL); v = xmlNewChild(p, NULL, BAD_CAST "value", NULL); s = xmlNewChild(v, NULL, BAD_CAST "int", BAD_CAST i2); break; } }
EAPI int ecore_con_info_get(Ecore_Con_Server *svr, Ecore_Con_Info_Cb done_cb, void *data, struct addrinfo *hints) { CB_Data *cbdata; int fd[2]; if (pipe(fd) < 0) { ecore_con_event_server_error(svr, strerror(errno)); return 0; } _ecore_con_fd_close_on_exec(fd[0]); _ecore_con_fd_close_on_exec(fd[1]); cbdata = calloc(1, sizeof(CB_Data)); if (!cbdata) { close(fd[0]); close(fd[1]); return 0; } cbdata->cb_done = done_cb; cbdata->data = data; cbdata->fd2 = fd[1]; if (!(cbdata->fdh = ecore_main_fd_handler_add(fd[0], ECORE_FD_READ, _ecore_con_info_data_handler, cbdata, NULL, NULL))) { ecore_con_event_server_error(svr, "Memory allocation failure"); free(cbdata); close(fd[0]); close(fd[1]); return 0; } if ((cbdata->pid = fork()) == 0) { Ecore_Con_Info *container; struct addrinfo *result = NULL; char service[NI_MAXSERV] = {0}; char hbuf[NI_MAXHOST] = {0}; char sbuf[NI_MAXSERV] = {0}; unsigned char *tosend = NULL; int tosend_len; int canonname_len = 0; eina_convert_itoa(svr->ecs ? svr->ecs->port : svr->port, service); /* CHILD */ if (!getaddrinfo(svr->ecs ? svr->ecs->ip : svr->name, service, hints, &result) && result) { if (result->ai_canonname) canonname_len = strlen(result->ai_canonname) + 1; tosend_len = sizeof(Ecore_Con_Info) + result->ai_addrlen + canonname_len; tosend = alloca(tosend_len); memset(tosend, 0, tosend_len); container = (Ecore_Con_Info *)tosend; container->size = tosend_len; memcpy(&container->info, result, sizeof(struct addrinfo)); memcpy(tosend + sizeof(Ecore_Con_Info), result->ai_addr, result->ai_addrlen); if (result->ai_canonname) /* FIXME: else... */ memcpy(tosend + sizeof(Ecore_Con_Info) + result->ai_addrlen, result->ai_canonname, canonname_len); if (!getnameinfo(result->ai_addr, result->ai_addrlen, hbuf, sizeof(hbuf), sbuf, sizeof(sbuf), NI_NUMERICHOST | NI_NUMERICSERV)) { memcpy(container->ip, hbuf, sizeof(container->ip)); memcpy(container->service, sbuf, sizeof(container->service)); } if (write(fd[1], tosend, tosend_len) < 0) perror("write"); } if (result) freeaddrinfo(result); if (write(fd[1], "", 1) < 0) perror("write"); close(fd[1]); #if defined(__USE_ISOC99) && !defined(__UCLIBC__) _Exit(0); #else _exit(0); #endif } /* PARENT */ cbdata->handler = ecore_event_handler_add(ECORE_EXE_EVENT_DEL, _ecore_con_info_exit_handler, cbdata); close(fd[1]); if (!cbdata->handler) { ecore_main_fd_handler_del(cbdata->fdh); free(cbdata); close(fd[0]); return 0; } info_slaves = (CB_Data *)eina_inlist_append(EINA_INLIST_GET( info_slaves), EINA_INLIST_GET(cbdata)); svr->infos = eina_list_append(svr->infos, cbdata); return 1; }