int tr_trans_task(int argc, char *argv[]) { FILE *fp; MultiAlign *ma, *tma; if (argc == 1) return tr_trans_usage(); fp = tr_get_fp(argv[1]); tma = ma_read_alignment(fp, 1); ma = ma_trans_align(tma, 1); /* translate to amino acids */ tr_align_output(stdout, ma); ma_free(ma); ma_free(tma); if (fp != stdin) fclose(fp); return 0; }
int tr_filter_task(int argc, char *argv[]) { int c, is_collapse = 0; int is_nucl = 0; int cut_off = 15; FILE *fp; int is_mask = 1; int is_mask_segments = 1; MultiAlign *ma; while ((c = getopt(argc, argv, "F:ngMN")) >= 0) { switch (c) { case 'n': is_nucl = 1; break; case 'g': is_collapse = 1; break; case 'N': is_mask_segments = 0; break; case 'M': is_mask = 0; break; case 'F': cut_off = atoi(optarg); break; } } if (optind == argc) return tr_filter_usage(); fp = tr_get_fp(argv[optind]); ma = ma_read_alignment(fp, is_nucl); if (is_mask) ma_apply_mask(ma); ma_filter(ma, is_collapse, cut_off, is_mask_segments); tr_align_output(stdout, ma); ma_free(ma); if (fp != stdin) fclose(fp); return 0; }
void tr_delete_task(Task *t) { if (t->aln) ma_free(t->aln); if (t->spec_tree) { tr_delete_tree_SDIptr(t->tree); if (t->subtree) tr_delete_tree_SDIptr(t->subtree); tr_delete_tree(t->spec_tree); } if (t->tree) tr_delete_tree_SDIptr(t->tree); if (t->compared) tr_delete_tree(t->compared); if (t->subtree && tr_search(t->tree, t->subtree) == 0) /* not a node in t->tree */ tr_delete_tree(t->subtree); if (t->tree) tr_delete_tree(t->tree); if (t->cut) free(t->cut); if (t->ortho) tr_delete_ortho(t->ortho); if (t->n_con) { int i; for (i = 0; i < t->n_con; ++i) tr_delete_tree(t->constraint[i]); free(t->constraint); } if (t->n_sub) { int i; for (i = 0; i < t->n_sub; ++i) free(t->sub_name[i]); free(t->sub_name); } free(t); }
void lengthfixed_mtmp::free(void *p, size_t sz) { NUT_DEBUGGING_ASSERT_ALIVE; assert(NULL != p && _granularity == std::max(sz, sizeof(void*))); while(true) { if (_free_num >= (int) MAX_FREE_NUM) // NOTE _free_num 只起参考作用 { ma_free(_alloc, p, _granularity); return; } const TagedPtr<void> old_head(_head.cas); *reinterpret_cast<void**>(p) = old_head.ptr; const TagedPtr<void> new_head(p, old_head.tag + 1); if (atomic_cas(&(_head.cas), old_head.cas, new_head.cas)) { // NOTE _free_num 在多线程下并不可靠 if (NULL == old_head.ptr) _free_num = 1; else ++_free_num; return; } } }
void lengthfixed_mtmp::clear() { NUT_DEBUGGING_ASSERT_ALIVE; void *p = _head.ptr; while (NULL != p) { void *next = *reinterpret_cast<void**>(p); ma_free(_alloc, p, _granularity); p = next; } _head.ptr = NULL; _free_num = 0; }
void lengthfixed_stmp::free(void *p, size_t sz) { NUT_DEBUGGING_ASSERT_ALIVE; assert(NULL != p && _granularity == std::max(sz, sizeof(void*))); if (_free_num >= (int) MAX_FREE_NUM) { ma_free(_alloc, p, _granularity); return; } *reinterpret_cast<void**>(p) = _head; _head = p; ++_free_num; }
int tr_mfa2aln_task(int argc, char *argv[]) { MultiAlign *ma; FILE *fp; int c, is_nucl = 0; while ((c = getopt(argc, argv, "n")) >= 0) { switch (c) { case 'n': is_nucl = 1; break; } } if (optind == argc) return tr_mfa2aln_usage(); fp = tr_get_fp(argv[optind]); ma = ma_read_alignment(fp, is_nucl); tr_align_aln_output(stdout, ma); ma_free(ma); if (fp != stdin) fclose(fp); return 0; }
/* Release SSL and free resources Will be automatically executed by mysql_server_end() function SYNOPSIS my_ssl_end() void RETURN VALUES void */ void ma_tls_end() { if (ma_tls_initialized) { pthread_mutex_lock(&LOCK_openssl_config); #if OPENSSL_VERSION_NUMBER < 0x10100000L CRYPTO_set_locking_callback(NULL); CRYPTO_set_id_callback(NULL); { int i; for (i=0; i < CRYPTO_num_locks(); i++) pthread_mutex_destroy(&LOCK_crypto[i]); } ma_free((gptr)LOCK_crypto); LOCK_crypto= NULL; #endif if (SSL_context) { SSL_CTX_free(SSL_context); SSL_context= NULL; } if (mariadb_deinitialize_ssl) { #if OPENSSL_VERSION_NUMBER < 0x10100000L ERR_remove_state(0); #endif EVP_cleanup(); CRYPTO_cleanup_all_ex_data(); ERR_free_strings(); CONF_modules_free(); CONF_modules_unload(1); } ma_tls_initialized= FALSE; pthread_mutex_unlock(&LOCK_openssl_config); pthread_mutex_destroy(&LOCK_openssl_config); } return; }
unsigned int ma_tls_get_finger_print(MARIADB_TLS *ctls, unsigned char *fp, unsigned int len) { EVP_MD *digest= (EVP_MD *)EVP_sha1(); X509 *cert; MYSQL *mysql; unsigned int fp_len; if (!ctls || !ctls->ssl) return 0; mysql= SSL_get_app_data(ctls->ssl); if (!(cert= SSL_get_peer_certificate(ctls->ssl))) { my_set_error(mysql, CR_SSL_CONNECTION_ERROR, SQLSTATE_UNKNOWN, ER(CR_SSL_CONNECTION_ERROR), "Unable to get server certificate"); return 0; } if (len < EVP_MAX_MD_SIZE) { my_set_error(mysql, CR_SSL_CONNECTION_ERROR, SQLSTATE_UNKNOWN, ER(CR_SSL_CONNECTION_ERROR), "Finger print buffer too small"); return 0; } fp_len= len; if (!X509_digest(cert, digest, fp, &fp_len)) { ma_free(fp); my_set_error(mysql, CR_SSL_CONNECTION_ERROR, SQLSTATE_UNKNOWN, ER(CR_SSL_CONNECTION_ERROR), "invalid finger print of server certificate"); return 0; } return (fp_len); }
/* Release SSL and free resources Will be automatically executed by mysql_server_end() function SYNOPSIS my_ssl_end() void RETURN VALUES void */ void ma_tls_end() { if (ma_tls_initialized) { int i; pthread_mutex_lock(&LOCK_openssl_config); CRYPTO_set_locking_callback(NULL); CRYPTO_set_id_callback(NULL); for (i=0; i < CRYPTO_num_locks(); i++) pthread_mutex_destroy(&LOCK_crypto[i]); ma_free((gptr)LOCK_crypto); LOCK_crypto= NULL; if (SSL_context) { SSL_CTX_free(SSL_context); SSL_context= NULL; } if (mariadb_deinitialize_ssl) { ERR_remove_state(0); EVP_cleanup(); CRYPTO_cleanup_all_ex_data(); ERR_free_strings(); CONF_modules_free(); CONF_modules_unload(1); sk_SSL_COMP_free(SSL_COMP_get_compression_methods()); } ma_tls_initialized= FALSE; pthread_mutex_unlock(&LOCK_openssl_config); pthread_mutex_destroy(&LOCK_openssl_config); } return; }
/** * Synchronize memory mapping with the file. * Called from process context. */ static void tempesta_unmap_file(struct file *file, unsigned long addr, unsigned long len, int node) { mm_segment_t oldfs; MArea *ma; loff_t off = 0; ssize_t r; mutex_lock(&map_mtx); ma = ma_lookup(addr, node); if (!ma) { TDB_WARN("Cannot sync memory area for %#lx address at node" " %d\n", addr, node); goto err; } oldfs = get_fs(); set_fs(get_ds()); r = kernel_write(file, (void *)ma->start, len, &off); if (r != len) { TDB_WARN("Cannot sync mapping %lx of size %lu pages\n", ma->start, ma->pages); goto err_fs; } err_fs: set_fs(oldfs); err: fput(file); ma_free(addr, node); mutex_unlock(&map_mtx); }
int tr_distmat_task(int argc, char *argv[]) { extern Matrix *ma_init_matrix(const MultiAlign *ma); extern void ma_init_nucl_data(); int type = -1; int is_nucl = 0; DistParam *dp; MultiAlign *ma; Matrix *mat; FILE *fp; if (argc < 3) return tr_distmat_usage(); if (strcmp(argv[1], "dn") == 0) { type = DIST_DN; is_nucl = 1; } else if (strcmp(argv[1], "ds") == 0) { type = DIST_DS; is_nucl = 1; } else if (strcmp(argv[1], "dm") == 0) { type = DIST_DM; is_nucl = 1; } else if (strcmp(argv[1], "jtt") == 0) type = DIST_JTT; else if (strcmp(argv[1], "kimura") == 0) type = DIST_KIMURA; else if (strcmp(argv[1], "mm") == 0) type = DIST_MM; else if (strcmp(argv[1], "dns") == 0) { type = -1; is_nucl = 1; } else { fprintf(stderr, "ERROR: unrecognized type %s\n", argv[1]); return 1; } fp = tr_get_fp(argv[2]); ma = ma_read_alignment(fp, is_nucl); if (is_nucl) { /* special consideration for nucleotide alignment */ MultiAlign *ma_tmp; ma_init_nucl_data(); ma_tmp = ma; ma = ma_trans_align(ma_tmp, 0); if (ma == 0) { fprintf(stderr, "ERROR: it seems that your input contains errors!\n"); return 1; } ma_free(ma_tmp); } mat = ma_init_matrix(ma); if (type >= 0) { dp = ma_alloc_DistParam(type); ma_cal_dist(mat, ma, 0, dp); tr_matrix_output(stdout, mat); ma_free_DistParam(dp); } else { Matrix *mat_ds; int i, j; float *p_dn, *p_ds; /* calculate dn */ dp = ma_alloc_DistParam(DIST_DN); ma_cal_dist(mat, ma, 0, dp); ma_free_DistParam(dp); /* calculate ds */ mat_ds = ma_init_matrix(ma); dp = ma_alloc_DistParam(DIST_DS); ma_cal_dist(mat_ds, ma, 0, dp); ma_free_DistParam(dp); for (i = 0; i < ma->n; ++i) { p_dn = mat->dist + i * ma->n; p_ds = mat_ds->dist + i * ma->n; for (j = 0; j < i; ++j) printf("%.6f\t%.6f\t%s\t%s\n", p_dn[j], p_ds[j], ma->name[i], ma->name[j]); } tr_delete_matrix(mat_ds); } ma_free(ma); tr_delete_matrix(mat); if (fp != stdin) fclose(fp); return 0; }