void mpiReduce_pickerV3(float *resDataAbsMaxPaddedGlobal, size_t *resDataMaxIndPaddedGlobal, size_t resSize, eXCorrMerge bAbs) { resSizeMPI = resSize; MPI_Datatype mpiType; MPI_Type_contiguous((int) 2, MPI_FLOAT, &mpiType); MPI_Type_commit(&mpiType); float *resDataGlobalNode = NULL; float *resDataGlobalNodeReduce = NULL; array_new(resDataGlobalNode, 2*resSize); array_new(resDataGlobalNodeReduce, 2*resSize); memcpy(resDataGlobalNode, resDataAbsMaxPaddedGlobal, resSize*sizeof(float)); mpiOp_array_typecast(resDataMaxIndPaddedGlobal, resDataGlobalNode+resSize, resSize); MPI_Op mpiOp; switch (bAbs) { case XCORR_MERGE_NEGATIVE: MPI_Op_create((MPI_User_function *) mpiOp_xcorrMergeResultGlobalV3Abs, 1, // commutative &mpiOp); break; case XCORR_MERGE_POSITIVE: MPI_Op_create((MPI_User_function *) mpiOp_xcorrMergeResultGlobalV3, 1, // commutative &mpiOp); break; default: ERROR("mpiReduce_pickerV3", "unsupported merging mode"); } MPI_Reduce(resDataGlobalNode, resDataGlobalNodeReduce, (int) resSize, // resSize elements of size 2*sizeof(float) mpiType, mpiOp, 0, MPI_COMM_WORLD); MPI_Op_free(&mpiOp); memcpy(resDataAbsMaxPaddedGlobal, resDataGlobalNodeReduce, resSize*sizeof(float)); mpiOp_array_typecast(resDataGlobalNodeReduce+resSize, resDataMaxIndPaddedGlobal, resSize); array_delete(resDataGlobalNode); array_delete(resDataGlobalNodeReduce); MPI_Type_free(&mpiType); }
void ShaderNode_clear_links(ShaderNode _sn) { ShaderObject exec_so = {NULL}; /** if ( to_ptr(_sn->result_link) != NULL ) { ShaderObject_delete(_sn->result_link); _sn->result_link = exec_so; } **/ for (euint32 i = 0; i < array_n(_sn->input_links); i++) { ShaderObject so = array_safe_get(_sn->input_links, i); if ( to_ptr(so) != NULL ) ShaderObject_delete(so); } array_delete(_sn->input_links); _sn->input_links = array_new(ShaderObject, 5, exec_so); for (euint32 i = 0; i < array_n(_sn->output_links); i++) { ShaderObject so = array_safe_get(_sn->output_links, i); if ( to_ptr(so) != NULL ) ShaderObject_delete(so); } array_delete(_sn->output_links); _sn->output_links = array_new(ShaderObject, 5, exec_so); }
void mesh_delete(mesh_t *mesh) { // Delete the vertex & index buffer object glDeleteBuffers(1, &mesh->vbo); glDeleteBuffers(1, &mesh->ibo); // Delete the vertex attribute array array_delete(mesh->vattributes); // Delete the index array array_delete(mesh->indices); // Delete all the material groups size_t size = array_size(mesh->mtl_grps); for(uint64_t i = 0; i < size; i++) { material_group_t *grp = (material_group_t*)array_at(mesh->mtl_grps, i); // Delete the texture if it exists glDeleteTextures(1, &grp->mtl.tex.texID); } // Delete the material group array array_delete(mesh->mtl_grps); // Finally delete the vertex array object glDeleteVertexArrays(1, &mesh->vao); }
static bool final_keyword_check(struct dsync_mail_change *change, const char *name, char *type_r) { const char *const *changes; unsigned int i, count; *type_r = KEYWORD_CHANGE_FINAL; changes = array_get(&change->keyword_changes, &count); for (i = 0; i < count; i++) { if (strcmp(changes[i]+1, name) != 0) continue; switch (changes[i][0]) { case KEYWORD_CHANGE_ADD: /* replace with ADD_AND_FINAL */ array_delete(&change->keyword_changes, i, 1); *type_r = KEYWORD_CHANGE_ADD_AND_FINAL; return FALSE; case KEYWORD_CHANGE_REMOVE: /* a final keyword is marked as removed. this shouldn't normally happen. */ array_delete(&change->keyword_changes, i, 1); return FALSE; case KEYWORD_CHANGE_ADD_AND_FINAL: case KEYWORD_CHANGE_FINAL: /* no change */ return TRUE; } } return FALSE; }
int SOMAascii (SOMAsetup *ssetup, const char *expr, int nparams, Parameter *params, const char *file, SOMAreturn* sr) { Array2D array; int i; char *buf; long len; struct csv_parser csvp; clock_t begin, end; MuExpr me; array_init(&array); //Parse CSV file if (csv_init (&csvp, CSV_APPEND_NULL)!=0) return ERR; if ((buf=read_file_into_buffer (file, &len))==NULL) return ERR_FILE; csv_parse (&csvp, buf, len, csvcallback1, csvcallback2, (void*) &array); csv_fini (&csvp, csvcallback1, csvcallback2, (void*) &array); csv_free (&csvp); //array_print (&array); //debug muexpr_init (&me, expr); for (i=0; i<nparams; i++) if (defpar (&me, params+i, i)!=OK) { return ERR_PARAMS; array_delete (&array); muexpr_free (&me); } findvars (&me, VAR_NAME_PREFIX); //CVS file and expression don't match if (me.nvars!=array.ncolumns-1) { array_delete (&array); muexpr_free (&me); return ERR_COLUMNS; } muexpr_eval (&me); if (mupError (me.hparser)) { array_delete (&array); muexpr_free (&me); return ERR_EXPR; } //Initialize output struct SOMAreturn_init (sr, ssetup->Migrations, nparams); begin=clock(); //SOMA call SOMA (ssetup, nparams, params, sr, &array, &me); end=clock(); sr->time=(double) (end-begin)/CLOCKS_PER_SEC; array_delete (&array); muexpr_free (&me); return OK; }
static unsigned int view_sync_expunges2seqs(struct mail_index_view_sync_ctx *ctx) { struct mail_index_view *view = ctx->view; struct seq_range *src, *src_end, *dest; unsigned int count, expunge_count = 0; uint32_t prev_seq = 0; /* convert UIDs to sequences */ src = dest = array_get_modifiable(&ctx->expunges, &count); src_end = src + count; for (; src != src_end; src++) { if (!mail_index_lookup_seq_range(view, src->seq1, src->seq2, &dest->seq1, &dest->seq2)) count--; else { i_assert(dest->seq1 > prev_seq); prev_seq = dest->seq2; expunge_count += dest->seq2 - dest->seq1 + 1; dest++; } } array_delete(&ctx->expunges, count, array_count(&ctx->expunges) - count); return expunge_count; }
int SOMAexternal (SOMAsetup *ssetup, FitnessFunction ffunc, int nparams, Parameter *params, const char *file, SOMAreturn* sr) { Array2D array; char *buf; long len; struct csv_parser csvp; clock_t begin, end; array_init (&array); array_append_column(&array); //blank column for external fitness function array.currentcolumn++; //Parse CSV file if (csv_init (&csvp, CSV_APPEND_NULL)!=0) return ERR; if ((buf=read_file_into_buffer (file, &len))==NULL) return ERR_FILE; csv_parse (&csvp, buf, len, csvcallback1, csvcallback2e, (void*) &array); csv_fini (&csvp, csvcallback1, csvcallback2e, (void*) &array); csv_free (&csvp); //array_print (&array); //debug //soma_array=&array; //Initialize output struct SOMAreturn_init (sr, ssetup->Migrations, nparams); begin=clock(); //SOMA call SOMA2 (ssetup, nparams, params, sr, &array, ffunc); end=clock(); sr->time=(double) (end-begin)/CLOCKS_PER_SEC; array_delete (&array); return OK; }
void dispatch_delete(dispatch_t * self) { if (unlikely(self == NULL)) throw_unexpected(DISPATCH_NULL); close(self->fd), self->fd = -1; array_delete(&self->events); }
void acl_rights_sort(struct acl_object *aclobj) { struct acl_rights *rights; unsigned int i, dest, count; if (!array_is_created(&aclobj->rights)) return; array_sort(&aclobj->rights, acl_rights_cmp); /* merge identical identifiers */ rights = array_get_modifiable(&aclobj->rights, &count); for (dest = 0, i = 1; i < count; i++) { if (acl_rights_cmp(&rights[i], &rights[dest]) == 0) { /* add i's rights to dest and delete i */ acl_right_names_merge(aclobj->rights_pool, &rights[dest].rights, rights[i].rights, FALSE); acl_right_names_merge(aclobj->rights_pool, &rights[dest].neg_rights, rights[i].neg_rights, FALSE); } else { if (++dest != i) rights[dest] = rights[i]; } } if (++dest != count) array_delete(&aclobj->rights, dest, count - dest); }
void mailbox_search_result_free(struct mail_search_result **_result) { struct mail_search_result *result = *_result; struct mail_search_result *const *results; unsigned int i, count; *_result = NULL; results = array_get(&result->box->search_results, &count); for (i = 0; i < count; i++) { if (results[i] == result) { array_delete(&result->box->search_results, i, 1); break; } } i_assert(i != count); if (result->search_args != NULL) mail_search_args_unref(&result->search_args); array_free(&result->uids); array_free(&result->never_uids); if (array_is_created(&result->removed_uids)) { array_free(&result->removed_uids); array_free(&result->added_uids); } i_free(result); }
static int json_parse_denest(struct json_parser *parser) { const enum json_state *nested_states; unsigned count; parser->data++; json_parser_update_input_pos(parser); nested_states = array_get(&parser->nesting, &count); i_assert(count > 0); if (count == 1) { /* closing root */ parser->state = JSON_STATE_DONE; if ((parser->flags & JSON_PARSER_NO_ROOT_OBJECT) == 0) return 0; /* we want to return the ending "]" or "}" to caller */ return 1; } /* closing a nested object */ parser->state = nested_states[count-2] == JSON_STATE_OBJECT_OPEN ? JSON_STATE_OBJECT_NEXT : JSON_STATE_ARRAY_NEXT; array_delete(&parser->nesting, count-1, 1); if (parser->nested_skip_count > 0) { parser->nested_skip_count--; return 0; } return 1; }
END_TEST START_TEST(array_delete_test) { job_array *pa; pa = new job_array(); pa->job_ids = (char **)calloc(10, sizeof(char *)); pa->ai_qs.array_size = 10; //Set up the save path path_arrays = (char *)"./"; strcpy(pa->ai_qs.fileprefix,"tempFile"); strcpy(pa->ai_qs.parent_id, "1.roshar"); char path[256]; snprintf(path, sizeof(path), "%s%s%s", path_arrays, pa->ai_qs.fileprefix, ARRAY_FILE_SUFFIX); FILE *fp = fopen(path,"w"); fprintf(fp,"I'm a very temporary file.\n"); fclose(fp); array_depend *pdep = (array_depend *)calloc(1,sizeof(array_depend)); pa->ai_qs.deps.push_back(pdep); pdep->dp_jobs.push_back(new (array_depend_job)); pdep->dp_jobs.push_back(new (array_depend_job)); pdep->dp_jobs.push_back(new (array_depend_job)); pdep->dp_jobs.push_back(new (array_depend_job)); pdep->dp_jobs.push_back(new (array_depend_job)); allarrays.insert(pa, pa->ai_qs.parent_id); array_delete("1.roshar"); }
static void rm_watch(int wd, bool update_parent) { watch_node* node = table_get(watches, wd); if (node == NULL) { return; } userlog(LOG_DEBUG, "unwatching %s: %d (%p)", node->path, node->wd, node); if (inotify_rm_watch(inotify_fd, node->wd) < 0) { userlog(LOG_DEBUG, "inotify_rm_watch(%d:%s): %s", node->wd, node->path, strerror(errno)); } for (int i=0; i<array_size(node->kids); i++) { watch_node* kid = array_get(node->kids, i); if (kid != NULL) { rm_watch(kid->wd, false); } } if (update_parent && node->parent != NULL) { for (int i=0; i<array_size(node->parent->kids); i++) { if (array_get(node->parent->kids, i) == node) { array_put(node->parent->kids, i, NULL); break; } } } array_delete(node->kids); free(node); table_put(watches, wd, NULL); }
static int json_parse_denest(struct json_parser *parser) { const enum json_state *nested_states; unsigned count; parser->data++; json_parser_update_input_pos(parser); nested_states = array_get(&parser->nesting, &count); if (count == 0) { /* closing root */ parser->state = JSON_STATE_DONE; return 0; } /* closing a nested object */ if (count == 1) { /* we're back to root */ parser->state = JSON_STATE_OBJECT_NEXT; } else { /* back to previous nested object */ parser->state = nested_states[count-2] == JSON_STATE_OBJECT_OPEN ? JSON_STATE_OBJECT_NEXT : JSON_STATE_ARRAY_NEXT; } array_delete(&parser->nesting, count-1, 1); if (parser->nested_skip_count > 0) { parser->nested_skip_count--; return 0; } return 1; }
void imapc_msgmap_expunge(struct imapc_msgmap *msgmap, uint32_t rseq) { i_assert(rseq > 0); i_assert(rseq <= imapc_msgmap_count(msgmap)); array_delete(&msgmap->uids, rseq-1, 1); }
void mdbox_file_unrefed(struct dbox_file *file) { struct mdbox_file *mfile = (struct mdbox_file *)file; struct mdbox_file *oldest_file; unsigned int i, count; /* don't cache metadata seeks while file isn't being referenced */ file->metadata_read_offset = (uoff_t)-1; mfile->close_time = ioloop_time; if (mfile->file_id != 0) { count = array_count(&mfile->storage->open_files); if (!file->deleted && count <= MDBOX_MAX_OPEN_UNUSED_FILES) { /* we can leave this file open for now */ mdbox_file_close_later(mfile); return; } /* close the oldest file with refcount=0 */ oldest_file = mdbox_find_oldest_unused_file(mfile->storage, &i); i_assert(oldest_file != NULL); array_delete(&mfile->storage->open_files, i, 1); if (oldest_file != mfile) { dbox_file_free(&oldest_file->file); mdbox_file_close_later(mfile); return; } /* have to close ourself */ } dbox_file_free(file); }
struct array_s* array_new(int num, int element_size) { int buffer_size = num * element_size; struct array_s* ret = (struct array_s*)malloc(sizeof(struct array_s)); if(NULL != ret) { memset(ret, 0, sizeof(*ret)); ret->buffer = (char*)malloc(buffer_size); if(NULL != ret->buffer) { memset(ret->buffer, 0, buffer_size); ret->element_size = element_size; ret->element_num = num; ret->buffer_size = buffer_size; } else { array_delete(ret); ret = NULL; } } return ret; }
void watch_delete(watch_t * self) { if (unlikely(self == NULL)) throw_unexpected(WATCH_NULL); close(self->fd), self->fd = -1; array_delete(&self->callbacks); }
void auth_fields_remove(struct auth_fields *fields, const char *key) { unsigned int idx; if (auth_fields_find_idx(fields, key, &idx)) { auth_fields_snapshot_preserve(fields); array_delete(&fields->fields, idx, 1); } }
void process_thread_delete(process_thread_t * process_thread) { if(process_thread) { if(process_thread->maps_path) { free(process_thread->maps_path); } if(process_thread->mem_path) { free(process_thread->mem_path); } if(process_thread->memory_zones) { memory_zones_delete(process_thread->memory_zones); } if(process_thread->memory_chunk) { array_delete(process_thread->memory_chunk); } if(process_thread->file && fclose(process_thread->file) == EOF) { perror("process_thread_delete"); } free(process_thread); } }
void array_delete_vs_data(array* a) { if (a != NULL) { for (int i=0; i<a->size; i++) { if (a->data[i] != NULL) { free(a->data[i]); } } array_delete(a); } }
///==============================ShaderNode========================================/// void ShaderNode_Dest(shader_node* _sn) { if (_sn->node_name) EString_delete(_sn->node_name); if (_sn->function) EString_delete(_sn->function); /** ShaderObject_delete(_sn->result); if ( to_ptr(_sn->result_link) != NULL ) ShaderObject_delete(_sn->result_link); **/ for (euint32 i = 0; i < array_n(_sn->input_param_table); i++) { ShaderObject so = array_safe_get(_sn->input_param_table, i); if ( to_ptr(so) != NULL ) ShaderObject_delete(so); } array_delete(_sn->input_param_table); for (euint32 i = 0; i < array_n(_sn->output_param_table); i++) { ShaderObject so = array_safe_get(_sn->output_param_table, i); if ( to_ptr(so) != NULL ) ShaderObject_delete(so); } array_delete(_sn->output_param_table); for (euint32 i = 0; i < array_n(_sn->input_links); i++) { ShaderObject so = array_safe_get(_sn->input_links, i); if ( to_ptr(so) != NULL ) ShaderObject_delete(so); } array_delete(_sn->input_links); for (euint32 i = 0; i < array_n(_sn->output_links); i++) { ShaderObject so = array_safe_get(_sn->output_links, i); if ( to_ptr(so) != NULL ) ShaderObject_delete(so); } array_delete(_sn->output_links); }
int main(int argc, char** argv) { if (argc > 1) { if (strcmp(argv[1], "--help") == 0) { printf(USAGE_MSG); return 0; } else if (strcmp(argv[1], "--version") == 0) { printf(VERSION_MSG); return 0; } else if (strcmp(argv[1], "--selftest") == 0) { self_test = true; } else { printf("unrecognized option: %s\n", argv[1]); printf(HELP_MSG); return 1; } } init_log(); if (!self_test) { userlog(LOG_INFO, "started (v." VERSION ")"); } else { userlog(LOG_INFO, "started (self-test mode) (v." VERSION ")"); } setvbuf(stdin, NULL, _IONBF, 0); setvbuf(stdout, NULL, _IONBF, 0); roots = array_create(20); if (init_inotify() && roots != NULL) { set_inotify_callback(&inotify_callback); if (!self_test) { main_loop(); } else { run_self_test(); } unregister_roots(); } else { printf("GIVEUP\n"); } close_inotify(); array_delete(roots); userlog(LOG_INFO, "finished"); closelog(); return 0; }
void sql_driver_unregister(const struct sql_db *driver) { const struct sql_db *const *drivers; unsigned int i, count; drivers = array_get(&sql_drivers, &count); for (i = 0; i < count; i++) { if (drivers[i] == driver) { array_delete(&sql_drivers, i, 1); break; } } }
static bool client_search_update_cancel(struct client *client, const char *tag) { struct imap_search_update *update; unsigned int idx; update = client_search_update_lookup(client, tag, &idx); if (update == NULL) return FALSE; imap_search_update_free(update); array_delete(&client->search_updates, idx, 1); return TRUE; }
void ts_exit() { u64 i; for (i = 0; i < ts_type_size_s; ++i) { if (i < ts_builtin_types) { st_delete(&ts_type_table[i].id); } // struct and same length? if (ts_type_table[i].of == TY_STRUCT) { free(ts_type_table[i].structure.fields); array_delete(&ts_type_table[i].structure.members); array_delete(&ts_type_table[i].structure.alias); } else if (ts_type_table[i].of == TY_FUNCTION) { free(ts_type_table[i].func.params); } else if (ts_type_table[i].of == TY_TEMPLATE) { array_delete(&ts_type_table[i].tpl.usedby); } } free(ts_type_table); ts_type_table = 0; }
void http_client_remove_request_error(struct http_client *client, struct http_client_request *req) { struct http_client_request *const *reqs; unsigned int i, count; reqs = array_get(&client->delayed_failing_requests, &count); for (i = 0; i < count; i++) { if (reqs[i] == req) { array_delete(&client->delayed_failing_requests, i, 1); return; } } }
void mail_index_unregister_sync_lost_handler(struct mail_index *index, mail_index_sync_lost_handler_t *cb) { mail_index_sync_lost_handler_t *const *handlers; unsigned int i, count; handlers = array_get(&index->sync_lost_handlers, &count); for (i = 0; i < count; i++) { if (handlers[i] == cb) { array_delete(&index->sync_lost_handlers, i, 1); break; } } }
void amino_acid_delete(AminoAcid *aa) { int i; for(i = 0; i < array_size(aa->atoms); i++) { Atom *a = (Atom *)array_get(aa->atoms, i); atom_delete(a); } array_delete(aa->atoms); aa->N = NULL; aa->CA = NULL; aa->C = NULL; free(aa); }
void flang_exit(ast_t* root) { ast_delete(root); pool_destroy(); ts_exit(); array_delete(identifiers); free(identifiers); identifiers = 0; st_memfree(); st_replace_allocators(malloc, realloc, free); hash_replace_allocators(malloc, realloc, free); array_replace_allocators(malloc, realloc, free); }