void index_storage_mailbox_close(struct mailbox *box) { struct index_mailbox_context *ibox = INDEX_STORAGE_CONTEXT(box); index_mailbox_check_remove_all(box); if (box->input != NULL) i_stream_unref(&box->input); if (box->view_pvt != NULL) mail_index_view_close(&box->view_pvt); if (box->index_pvt != NULL) mail_index_close(box->index_pvt); mail_index_view_close(&box->view); mail_index_close(box->index); box->cache = NULL; ibox->keyword_names = NULL; i_free_and_null(ibox->cache_fields); if (array_is_created(&ibox->recent_flags)) array_free(&ibox->recent_flags); ibox->recent_flags_prev_uid = 0; ibox->recent_flags_count = 0; ibox->sync_last_check = 0; }
static void Release(void) { if (!g_lpDSDevice) return; if ( g_lpPrimaryBuffer!=NULL ) { ULONG status; ChannelFlushAll(0); g_lpPrimaryBuffer->GetStatus(&status); if ( (status&DSBSTATUS_PLAYING)==DSBSTATUS_PLAYING ) g_lpPrimaryBuffer->Stop(); if (g_lpDS3DListener) g_lpDS3DListener->Release(); g_lpPrimaryBuffer->Release(); g_lpPrimaryBuffer = NULL; } if (V3XA.p_driverList) { array_free(V3XA.p_driverList); V3XA.p_driverList = NULL; } }
static void log_append_flag_updates(struct mail_index_export_context *ctx, struct mail_index_transaction *t) { ARRAY(struct mail_transaction_flag_update) log_updates; const struct mail_index_flag_update *updates; struct mail_transaction_flag_update *log_update; unsigned int i, count; updates = array_get(&t->updates, &count); if (count == 0) return; i_array_init(&log_updates, count); for (i = 0; i < count; i++) { log_update = array_append_space(&log_updates); log_update->uid1 = updates[i].uid1; log_update->uid2 = updates[i].uid2; log_update->add_flags = updates[i].add_flags & 0xff; log_update->remove_flags = updates[i].remove_flags & 0xff; if ((updates[i].add_flags & MAIL_INDEX_MAIL_FLAG_UPDATE_MODSEQ) != 0) log_update->modseq_inc_flag = 1; } log_append_buffer(ctx, log_updates.arr.buffer, MAIL_TRANSACTION_FLAG_UPDATE); array_free(&log_updates); }
void cli_mainloop() { signal(SIGPIPE, cli_sigpipe); while (1) { int i; int found = 0; char *line = readline("rss> "); array_t *args = array_init_split_string(line, " "); if (array_count(args) < 1) continue; for(i = 0; i < N(cli_callbacks); i++) { if (!strcmp(cli_callbacks[i].ct_command, array_get(args, 0))) { cli_callbacks[i].ct_function(args); array_free(args, TRUE, FALSE); found = 1; break; } found = 0; } if (!found) xprintf("Nieznane polecenie. Aby zobaczyć pomoc, wpisz 'help'.\n"); free(line); } }
/** * @brief Frees loaded save stuff. */ void load_free (void) { int i; nsave_t *ns; if (load_saves != NULL) { for (i=0; i<array_size(load_saves); i++) { ns = &load_saves[i]; free(ns->path); if (ns->name != NULL) free(ns->name); if (ns->data != NULL) free(ns->data); if (ns->planet != NULL) free(ns->planet); if (ns->shipname != NULL) free(ns->shipname); if (ns->shipmodel != NULL) free(ns->shipmodel); } array_free( load_saves ); } load_saves = NULL; }
/* * Release ows struct */ void ows_free(ows * o) { assert(o); if (o->config_file) buffer_free(o->config_file); if (o->schema_dir) buffer_free(o->schema_dir); if (o->online_resource) buffer_free(o->online_resource); if (o->pg) PQfinish(o->pg); if (o->log_file) buffer_free(o->log_file); if (o->log) fclose(o->log); if (o->pg_dsn) buffer_free(o->pg_dsn); if (o->cgi) array_free(o->cgi); if (o->psql_requests) list_free(o->psql_requests); if (o->layers) ows_layer_list_free(o->layers); if (o->request) ows_request_free(o->request); if (o->max_geobbox) ows_geobbox_free(o->max_geobbox); if (o->metadata) ows_metadata_free(o->metadata); if (o->contact) ows_contact_free(o->contact); if (o->encoding) buffer_free(o->encoding); if (o->db_encoding) buffer_free(o->db_encoding); if (o->wfs_default_version) ows_version_free(o->wfs_default_version); if (o->postgis_version) ows_version_free(o->postgis_version); if (o->schema_wfs_100) xmlSchemaFree(o->schema_wfs_100); if (o->schema_wfs_110) xmlSchemaFree(o->schema_wfs_110); free(o); o = NULL; }
RID render_shader_create(struct render *R, struct shader_init_args *args) { struct shader * s = (struct shader *)array_alloc(&R->shader); if (s == NULL) { return 0; } s->glid = glCreateProgram(); if (!compile_link(R, s, args->vs, args->fs)) { glDeleteProgram(s->glid); array_free(&R->shader, s); return 0; } s->texture_n = args->texture; int i; for (i=0;i<s->texture_n;i++) { s->texture_uniform[i] = glGetUniformLocation(s->glid, args->texture_uniform[i]); } #ifdef VAO_ENABLE glGenVertexArrays(1, &s->glvao); for (i=0;i<MAX_VB_SLOT;i++) { s->vbslot[i] = 0; } s->ib = 0; #endif CHECK_GL_ERROR return array_id(&R->shader, s); }
/* * emoticon_read() * * ³aduje do listy wszystkie makra z pliku ~/.gg/emoticons * format tego pliku w dokumentacji. * * 0/-1 */ int emoticon_read() { const char *filename; char *buf, **emot; FILE *f; if (!(filename = prepare_path("emoticons", 0))) return -1; if (!(f = fopen(filename, "r"))) return -1; while ((buf = read_file(f))) { if (buf[0] == '#') { xfree(buf); continue; } emot = array_make(buf, "\t", 2, 1, 1); if (array_count(emot) == 2) emoticon_add(emot[0], emot[1]); array_free(emot); xfree(buf); } fclose(f); return 0; }
/** * @brief Cleans up a tech group. */ static void tech_freeGroup( tech_group_t *grp ) { if (grp->name != NULL) free(grp->name); if (grp->items != NULL) array_free( grp->items ); }
Array* recplot_los_dtw_noise( const Array *R ){ double noise; double noiseamp = 0.000000001; srand((long)time(NULL)); bool ismat; matrix_CHECK( ismat, R ); if( !ismat ) return NULL; Array *d = array_copy( R, TRUE ); ulong i; for( i=0; i<array_NUMEL(d); i++ ){ /* flip binary matrix and add noise*/ noise = noiseamp*(((double)rand()) / RAND_MAX); array_INDEX1( d, double, i ) = (1.0-array_INDEX1( d, double, i ))+noise; } OptArgList *opt = optarglist( "slope_constraint=int", SLOPE_CONSTRAINT_LAX ); matrix_dtw_cumulate( d, FALSE, opt ); optarglist_free( opt ); Array *P = matrix_dtw_backtrack( d ); array_free( d ); return P; }
void grid_info_free(GridInfo *gi) { if (gi) { array_free(gi->segments); FREE(gi); } }
static void Set_KeyFile(CHANNEL *Chan, const char *KeyFile) { size_t len; assert(Chan != NULL); assert(KeyFile != NULL); len = strlen(KeyFile); if (len < array_bytes(&Chan->keyfile)) { Log(LOG_INFO, "Channel key file of %s removed.", Chan->name); array_free(&Chan->keyfile); } if (len < 1) return; if (!array_copyb(&Chan->keyfile, KeyFile, len+1)) Log(LOG_WARNING, "Could not set new channel key file \"%s\" for %s: %s", KeyFile, Chan->name, strerror(errno)); else Log(LOG_INFO|LOG_snotice, "New local channel key file \"%s\" for %s activated.", KeyFile, Chan->name); } /* Set_KeyFile */
static void stats_top(const char *path, const char *sort_type) { struct top_context ctx; memset(&ctx, 0, sizeof(ctx)); ctx.path = path; ctx.fd = doveadm_connect(path); ctx.prev_pool = pool_alloconly_create("stats top", 1024*16); ctx.cur_pool = pool_alloconly_create("stats top", 1024*16); i_array_init(&ctx.lines, 128); hash_table_create(&ctx.sessions, default_pool, 0, str_hash, strcmp); net_set_nonblock(ctx.fd, FALSE); ctx.input = i_stream_create_fd(ctx.fd, (size_t)-1); if (strstr(sort_type, "cpu") != NULL) ctx.lines_sort = sort_cpu; else ctx.lines_sort = sort_num; ctx.sort_type = sort_type; stats_top_start(&ctx); i_stream_destroy(&ctx.input); hash_table_destroy(&ctx.sessions); array_free(&ctx.lines); pool_unref(&ctx.prev_pool); pool_unref(&ctx.cur_pool); i_close_fd(&ctx.fd); }
void io_loop_handler_deinit(struct ioloop *ioloop) { if (close(ioloop->handler_context->kq) < 0) i_error("close(kqueue) in io_loop_handler_deinit() failed: %m"); array_free(&ioloop->handler_context->events); i_free(ioloop->handler_context); }
void io_loop_handler_deinit(struct ioloop *ioloop) { struct ioloop_handler_context *ctx = ioloop->handler_context; struct io_list **list; unsigned int i, count; list = array_get_modifiable(&ctx->fd_index, &count); for (i = 0; i < count; i++) i_free(list[i]); if (close(ctx->epfd) < 0) i_error("close(epoll) failed: %m"); array_free(&ioloop->handler_context->fd_index); array_free(&ioloop->handler_context->events); i_free(ioloop->handler_context); }
int virtual_transaction_commit(struct mailbox_transaction_context *t, struct mail_transaction_commit_changes *changes_r) { struct virtual_transaction_context *vt = (struct virtual_transaction_context *)t; struct mailbox_transaction_context **bt; unsigned int i, count; int ret = 0; if (t->save_ctx != NULL) { virtual_save_free(t->save_ctx); t->save_ctx = NULL; } bt = array_get_modifiable(&vt->backend_transactions, &count); for (i = 0; i < count; i++) { if (mailbox_transaction_commit(&bt[i]) < 0) ret = -1; } array_free(&vt->backend_transactions); if (index_transaction_commit(t, changes_r) < 0) ret = -1; return ret; }
/* \fn data_valid(data, value) * Valid entry for variable? */ int data_valid(struct data_t *data, struct string_t *value) { /* Valid values for checkbox */ struct array_t *valid_values = NULL; /* Valid data */ struct string_t *valid = string_copy_value(data->valid); /* Return value */ int retval = 0; if (data->type == DATA_TYPE_CHECKBOX) { /* Valid values */ valid_values = string_split_value(valid, "|"); /* Valid? */ if (!string_compare(array_value(valid_values, 0), valid) | !string_compare(array_value(valid_values, 1), valid)) { retval = 1; } /* Free values */ array_free(&valid_values); } else { if (data->flags & DATA_FLAG_DONT_FILL && (!value || !string_compare_value(value, ""))) { retval = 1; } else if ( (data->valid && value && string_match_value(value, data->valid)) || !data->valid) { retval = 1; } } /* Return retval value */ return retval; }
int main(){ Array a = array_create(100); printf("array size=%d\n",array_size(&a)); *array_at(&a,0)=10; printf("%d",*array_at(&a,0)); array_free(&a); }
static void sh_close (struct MuLoader* self, struct MuLibrary* handle) { ShLibrary* library = (ShLibrary*) handle; if (library->tests) { int i; for (i = 0; i < array_size((array*) library->tests); i++) { ShTest* test = library->tests[i]; free((char*) test->function); free((char*) test->suite); free((char*) test->name); free(test); } array_free((array*) library->tests); } free((char*) library->path); free(library->name); free(library); }
GLOBAL void Channel_SetTopic(CHANNEL *Chan, CLIENT *Client, const char *Topic) { size_t len; assert( Chan != NULL ); assert( Topic != NULL ); len = strlen(Topic); if (len < array_bytes(&Chan->topic)) array_free(&Chan->topic); if (len >= COMMAND_LEN || !array_copyb(&Chan->topic, Topic, len+1)) Log(LOG_WARNING, "could not set new Topic \"%s\" on %s: %s", Topic, Chan->name, strerror(errno)); #ifndef STRICT_RFC Chan->topic_time = time(NULL); if (Client != NULL && Client_Type(Client) != CLIENT_SERVER) strlcpy(Chan->topic_who, Client_ID(Client), sizeof Chan->topic_who); else strlcpy(Chan->topic_who, DEFAULT_TOPIC_ID, sizeof Chan->topic_who); #else (void) Client; #endif } /* Channel_SetTopic */
static void index_transaction_free(struct index_transaction_context *t) { mail_cache_view_close(t->cache_view); mail_index_view_close(&t->mailbox_ctx.view); array_free(&t->mailbox_ctx.module_contexts); i_free(t); }
internal inline U32Array collect(Transition x, u32 C) { Segment *inv_head; // X x A u32 *inv_elts; // X x A ClassHead *cls_head; // A u32 *cls_elts; // A State *states; // // This is reversed from the paper -- we push onto the end U32Array suspects = {}; ClassHead CH = cls_head[C]; for (u32 i = CH.first; i < CH.first + CH.size; i++) { Segment inv_x_a = inv_head[x + cls_elts[i] * NUM_TRANSITIONS]; for (u32 j = inv_x_a.first; j < inv_x_a.first + inv_x_a.size; j++) { u32 b = inv_elts[j]; u32 B = states[b].cls_of; if (cls_head[B].counter == 0) { array_push(&suspects, B); array_free(&cls_head[B].move); cls_head[B].move = (U32Array){}; // WTF? } cls_head[B].counter++; array_push(&cls_head[B].move, b); } } return suspects; }
static mp_obj_t py_image_draw_keypoints(mp_obj_t image_obj, mp_obj_t kpts_obj) { image_t *image = NULL; py_kp_obj_t *kpts=NULL; /* get pointer */ image = py_image_cobj(image_obj); kpts = (py_kp_obj_t*)kpts_obj; /* sanity checks */ PY_ASSERT_TRUE_MSG(image->bpp == 1, "This function is only supported on GRAYSCALE images"); PY_ASSERT_TYPE(kpts_obj, &py_kp_type); color_t cl = {.r=0xFF, .g=0xFF, .b=0xFF}; for (int i=0; i<kpts->size; i++) { kp_t *kp = &kpts->kpts[i]; float co = arm_cos_f32(kp->angle); float si = arm_sin_f32(kp->angle); imlib_draw_line(image, kp->x, kp->y, kp->x+(co*10), kp->y+(si*10)); imlib_draw_circle(image, kp->x, kp->y, 4, &cl); } return mp_const_none; } static mp_obj_t py_image_find_blobs(mp_obj_t image_obj) { /* C stuff */ array_t *blobs; struct image *image; mp_obj_t blob_obj[6]; /* MP List */ mp_obj_t objects_list = mp_const_none; /* get image pointer */ image = py_image_cobj(image_obj); /* run color dector */ blobs = imlib_count_blobs(image); /* Create empty Python list */ objects_list = mp_obj_new_list(0, NULL); if (array_length(blobs)) { for (int j=0; j<array_length(blobs); j++) { blob_t *r = array_at(blobs, j); blob_obj[0] = mp_obj_new_int(r->x); blob_obj[1] = mp_obj_new_int(r->y); blob_obj[2] = mp_obj_new_int(r->w); blob_obj[3] = mp_obj_new_int(r->h); blob_obj[4] = mp_obj_new_int(r->c); blob_obj[5] = mp_obj_new_int(r->id); mp_obj_list_append(objects_list, mp_obj_new_tuple(6, blob_obj)); } } array_free(blobs); return objects_list; }
/* Inserts a key and value pair into the table. If memhandlers are set the table takes * ownership of the key and value pointers and is responsible for * deallocating them when they are removed. * table - Pointer to the table. * key - Pointer to the key. * value - Pointer to the value. */ void table_insert(Table *table, KEY key, VALUE value){ ArrayTable *t = (ArrayTable*)table; // make a new table element TableElement *e=malloc(sizeof(TableElement)); e->key = key; e->value = value; // table element to work on TableElement *i; // get loop boundaries for array // array_high and array_low return // arrays array *aHigh = array_high(t->values); array *aLow = array_low(t->values); int high = *((int*)array_inspectValue(aHigh,0)); int low = *((int*)array_inspectValue(aLow,0)); array_free(aHigh); array_free(aLow); // travers through the table/array until either the same key found // or an empty space found // Current, If the table is full, new element is not inserted! for ( int pos = low; pos < high; pos++){ // get TableElement of current array pos i = array_inspectValue(t->values,pos); // if current array pos is empty, put in new element and break if(i == NULL){ array_setValue(t->values,e,pos); t->elementCounter++; break; } // if the key of the current table element is the same as the new // put the new element in place of the old and break if (t->cf(i->key,key)==0){ array_setValue(t->values,e,pos); break; } } }
static Array *merge_and_count (Array *left, Array *right) { NOTNULL(left); NOTNULL(right); Array *merged = NULL; uint64_t split_inversions = 0; size_t index_left = 0; size_t index_right = 0; size_t index_merged = 0; merged = array_new (left->h.length + right->h.length); while ((left->h.length - index_left) || (right->h.length - index_right)) { if ((right->h.length - index_right) < 1) { merged->data [index_merged ++] = left->data [index_left ++]; } else if ((left->h.length - index_left) < 1) { merged->data [index_merged ++] = right->data [index_right ++]; } else if (left->data [index_left] < right->data [index_right]) { merged->data [index_merged ++] = left->data [index_left ++]; } else if (left->data [index_left] > right->data [index_right]) { merged->data [index_merged ++] = right->data [index_right ++]; split_inversions += left->h.length - index_left; } else { merged->data [index_merged ++] = left->data [index_left ++]; merged->data [index_merged ++] = right->data [index_right ++]; } } merged->h.inversions = split_inversions + left->h.inversions + right->h.inversions; array_free (left); array_free (right); return merged; }
int index_mailbox_sync_deinit(struct mailbox_sync_context *_ctx, struct mailbox_sync_status *status_r) { struct index_mailbox_sync_context *ctx = (struct index_mailbox_sync_context *)_ctx; struct mailbox_sync_rec sync_rec; bool delayed_expunges = FALSE; int ret = ctx->failed ? -1 : 0; /* finish handling expunges, so we don't break when updating recent flags */ while (index_mailbox_sync_next_expunge(ctx, &sync_rec) > 0) ; /* convert sequences to uids before syncing view */ index_sync_search_results_uidify(ctx); if (ctx->sync_ctx != NULL) { if (mail_index_view_sync_commit(&ctx->sync_ctx, &delayed_expunges) < 0) { mailbox_set_index_error(_ctx->box); ret = -1; } } index_mailbox_expunge_unseen_recent(ctx); if ((_ctx->box->flags & MAILBOX_FLAG_DROP_RECENT) == 0 && _ctx->box->opened) { /* mailbox syncing didn't necessarily update our recent state */ index_sync_update_recent_count(_ctx->box); } if (status_r != NULL) status_r->sync_delayed_expunges = delayed_expunges; /* update search results after private index is updated */ index_sync_search_results_update(ctx); if (array_is_created(&ctx->flag_updates)) array_free(&ctx->flag_updates); if (array_is_created(&ctx->hidden_updates)) array_free(&ctx->hidden_updates); if (array_is_created(&ctx->all_flag_update_uids)) array_free(&ctx->all_flag_update_uids); i_free(ctx); return ret; }
static void client_destroy(struct client *client) { char **app; i_set_failure_prefix("imap-urlauth[%s](%s): ", my_pid, client->access_user); if (client->url != NULL) { /* deinitialize url */ i_stream_close(client->input); o_stream_close(client->output); (void)client_run_url(client); i_assert(client->url == NULL); } imap_urlauth_worker_client_count--; DLLIST_REMOVE(&imap_urlauth_worker_clients, client); if (client->urlauth_ctx != NULL) imap_urlauth_deinit(&client->urlauth_ctx); if (client->mail_user != NULL) mail_user_unref(&client->mail_user); if (client->io != NULL) io_remove(&client->io); if (client->ctrl_io != NULL) io_remove(&client->ctrl_io); if (client->to_idle != NULL) timeout_remove(&client->to_idle); if (client->input != NULL) i_stream_destroy(&client->input); if (client->output != NULL) o_stream_destroy(&client->output); if (client->ctrl_input != NULL) i_stream_destroy(&client->ctrl_input); if (client->ctrl_output != NULL) o_stream_destroy(&client->ctrl_output); if (client->fd_in >= 0) net_disconnect(client->fd_in); if (client->fd_out >= 0 && client->fd_in != client->fd_out) net_disconnect(client->fd_out); if (client->fd_ctrl >= 0) net_disconnect(client->fd_ctrl); if (client->service_user != NULL) mail_storage_service_user_free(&client->service_user); i_free(client->access_user); array_foreach_modifiable(&client->access_apps, app) i_free(*app); array_free(&client->access_apps); i_free(client); imap_urlauth_worker_refresh_proctitle(); master_service_client_connection_destroyed(master_service); }
void array_free_wipe(array *a) { size_t bytes = a->allocated; if (bytes) memset(a->mem, 0, bytes); array_free(a); }
static void data_array_free(data_unset *d) { data_array *ds = (data_array *)d; buffer_free(ds->key); array_free(ds->value); free(d); }
DLLEXPORT void percentile_disc_deinit(UDF_INIT *initid) { struct Buffer *data = (struct Buffer *) initid->ptr; if (NULL != data) { array_free(&data->values); free(data); data = NULL; } }