您当前的位置:首页 > IT编程 > C++
| C语言 | Java | VB | VC | python | Android | TensorFlow | C++ | oracle | 学术与代码 | cnn卷积神经网络 | gnn | 图像修复 | Keras | 数据集 | Neo4j | 自然语言处理 | 深度学习 | 医学CAD | 医学影像 | 超参数 | pointnet | pytorch | 异常检测 | Transformers | 情感分类 | 知识图谱 |

自学教程:C++ xcalloc函数代码示例

51自学网 2021-06-03 10:15:45
  C++
这篇教程C++ xcalloc函数代码示例写得很实用,希望能帮到您。

本文整理汇总了C++中xcalloc函数的典型用法代码示例。如果您正苦于以下问题:C++ xcalloc函数的具体用法?C++ xcalloc怎么用?C++ xcalloc使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。

在下文中一共展示了xcalloc函数的27个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。

示例1: split_argv

/* * Splits 's' into an argument vector. Handles quoted string and basic * escape characters (//, /", /'). Caller must free the argument vector * and its members. */static intsplit_argv(const char *s, int *argcp, char ***argvp){	int r = SSH_ERR_INTERNAL_ERROR;	int argc = 0, quote, i, j;	char *arg, **argv = xcalloc(1, sizeof(*argv));	*argvp = NULL;	*argcp = 0;	for (i = 0; s[i] != '/0'; i++) {		/* Skip leading whitespace */		if (s[i] == ' ' || s[i] == '/t')			continue;		/* Start of a token */		quote = 0;		if (s[i] == '//' &&		    (s[i + 1] == '/'' || s[i + 1] == '/"' || s[i + 1] == '//'))			i++;		else if (s[i] == '/'' || s[i] == '"')			quote = s[i++];		argv = xreallocarray(argv, (argc + 2), sizeof(*argv));		arg = argv[argc++] = xcalloc(1, strlen(s + i) + 1);		argv[argc] = NULL;		/* Copy the token in, removing escapes */		for (j = 0; s[i] != '/0'; i++) {			if (s[i] == '//') {				if (s[i + 1] == '/'' ||				    s[i + 1] == '/"' ||				    s[i + 1] == '//') {					i++; /* Skip '/' */					arg[j++] = s[i];				} else {					/* Unrecognised escape */					arg[j++] = s[i];				}			} else if (quote == 0 && (s[i] == ' ' || s[i] == '/t'))				break; /* done */			else if (quote != 0 && s[i] == quote)				break; /* done */			else				arg[j++] = s[i];		}		if (s[i] == '/0') {			if (quote != 0) {				/* Ran out of string looking for close quote */				r = SSH_ERR_INVALID_FORMAT;				goto out;			}			break;		}	}	/* Success */	*argcp = argc;	*argvp = argv;	argc = 0;	argv = NULL;	r = 0; out:	if (argc != 0 && argv != NULL) {		for (i = 0; i < argc; i++)			free(argv[i]);		free(argv);	}	return r;}
开发者ID:eworm-de,项目名称:openssh-portable,代码行数:74,


示例2: load_subtree

static void load_subtree(struct notes_tree *t, struct leaf_node *subtree,		struct int_node *node, unsigned int n){	unsigned char object_sha1[20];	unsigned int prefix_len;	void *buf;	struct tree_desc desc;	struct name_entry entry;	int len, path_len;	unsigned char type;	struct leaf_node *l;	buf = fill_tree_descriptor(&desc, subtree->val_sha1);	if (!buf)		die("Could not read %s for notes-index",		     sha1_to_hex(subtree->val_sha1));	prefix_len = subtree->key_sha1[19];	assert(prefix_len * 2 >= n);	memcpy(object_sha1, subtree->key_sha1, prefix_len);	while (tree_entry(&desc, &entry)) {		path_len = strlen(entry.path);		len = get_sha1_hex_segment(entry.path, path_len,				object_sha1 + prefix_len, 20 - prefix_len);		if (len < 0)			goto handle_non_note; /* entry.path is not a SHA1 */		len += prefix_len;		/*		 * If object SHA1 is complete (len == 20), assume note object		 * If object SHA1 is incomplete (len < 20), and current		 * component consists of 2 hex chars, assume note subtree		 */		if (len <= 20) {			type = PTR_TYPE_NOTE;			l = (struct leaf_node *)				xcalloc(sizeof(struct leaf_node), 1);			hashcpy(l->key_sha1, object_sha1);			hashcpy(l->val_sha1, entry.sha1);			if (len < 20) {				if (!S_ISDIR(entry.mode) || path_len != 2)					goto handle_non_note; /* not subtree */				l->key_sha1[19] = (unsigned char) len;				type = PTR_TYPE_SUBTREE;			}			if (note_tree_insert(t, node, n, l, type,					     combine_notes_concatenate))				die("Failed to load %s %s into notes tree "				    "from %s",				    type == PTR_TYPE_NOTE ? "note" : "subtree",				    sha1_to_hex(l->key_sha1), t->ref);		}		continue;handle_non_note:		/*		 * Determine full path for this non-note entry:		 * The filename is already found in entry.path, but the		 * directory part of the path must be deduced from the subtree		 * containing this entry. We assume here that the overall notes		 * tree follows a strict byte-based progressive fanout		 * structure (i.e. using 2/38, 2/2/36, etc. fanouts, and not		 * e.g. 4/36 fanout). This means that if a non-note is found at		 * path "dead/beef", the following code will register it as		 * being found on "de/ad/beef".		 * On the other hand, if you use such non-obvious non-note		 * paths in the middle of a notes tree, you deserve what's		 * coming to you ;). Note that for non-notes that are not		 * SHA1-like at the top level, there will be no problems.		 *		 * To conclude, it is strongly advised to make sure non-notes		 * have at least one non-hex character in the top-level path		 * component.		 */		{			char non_note_path[PATH_MAX];			char *p = non_note_path;			const char *q = sha1_to_hex(subtree->key_sha1);			int i;			for (i = 0; i < prefix_len; i++) {				*p++ = *q++;				*p++ = *q++;				*p++ = '/';			}			strcpy(p, entry.path);			add_non_note(t, non_note_path, entry.mode, entry.sha1);		}	}	free(buf);}
开发者ID:julesbowden,项目名称:git,代码行数:90,


示例3: threaded_lazy_init_name_hash

static void threaded_lazy_init_name_hash(	struct index_state *istate){	int nr_each;	int k_start;	int t;	struct lazy_entry *lazy_entries;	struct lazy_dir_thread_data *td_dir;	struct lazy_name_thread_data *td_name;	k_start = 0;	nr_each = DIV_ROUND_UP(istate->cache_nr, lazy_nr_dir_threads);	lazy_entries = xcalloc(istate->cache_nr, sizeof(struct lazy_entry));	td_dir = xcalloc(lazy_nr_dir_threads, sizeof(struct lazy_dir_thread_data));	td_name = xcalloc(1, sizeof(struct lazy_name_thread_data));	init_dir_mutex();	/*	 * Phase 1:	 * Build "istate->dir_hash" using n "dir" threads (and a read-only index).	 */	for (t = 0; t < lazy_nr_dir_threads; t++) {		struct lazy_dir_thread_data *td_dir_t = td_dir + t;		td_dir_t->istate = istate;		td_dir_t->lazy_entries = lazy_entries;		td_dir_t->k_start = k_start;		k_start += nr_each;		if (k_start > istate->cache_nr)			k_start = istate->cache_nr;		td_dir_t->k_end = k_start;		if (pthread_create(&td_dir_t->pthread, NULL, lazy_dir_thread_proc, td_dir_t))			die("unable to create lazy_dir_thread");	}	for (t = 0; t < lazy_nr_dir_threads; t++) {		struct lazy_dir_thread_data *td_dir_t = td_dir + t;		if (pthread_join(td_dir_t->pthread, NULL))			die("unable to join lazy_dir_thread");	}	/*	 * Phase 2:	 * Iterate over all index entries and add them to the "istate->name_hash"	 * using a single "name" background thread.	 * (Testing showed it wasn't worth running more than 1 thread for this.)	 *	 * Meanwhile, finish updating the parent directory ref-counts for each	 * index entry using the current thread.  (This step is very fast and	 * doesn't need threading.)	 */	td_name->istate = istate;	td_name->lazy_entries = lazy_entries;	if (pthread_create(&td_name->pthread, NULL, lazy_name_thread_proc, td_name))		die("unable to create lazy_name_thread");	lazy_update_dir_ref_counts(istate, lazy_entries);	if (pthread_join(td_name->pthread, NULL))		die("unable to join lazy_name_thread");	cleanup_dir_mutex();	free(td_name);	free(td_dir);	free(lazy_entries);}
开发者ID:basilgor,项目名称:git,代码行数:67,


示例4: kex_choose_conf

static voidkex_choose_conf(Kex *kex){	Newkeys *newkeys;	char **my, **peer;	char **cprop, **sprop;	int nenc, nmac, ncomp;	u_int mode, ctos, need;	int first_kex_follows, type;#ifdef	NONE_CIPHER_ENABLED	int auth_flag;#endif	my   = kex_buf2prop(&kex->my, NULL);	peer = kex_buf2prop(&kex->peer, &first_kex_follows);	if (kex->server) {		cprop=peer;		sprop=my;	} else {		cprop=my;		sprop=peer;	}	/* Check whether server offers roaming */	if (!kex->server) {		char *roaming;		roaming = match_list(KEX_RESUME, peer[PROPOSAL_KEX_ALGS], NULL);		if (roaming) {			kex->roaming = 1;			xfree(roaming);		}	}	/* Algorithm Negotiation */#ifdef	NONE_CIPHER_ENABLED	auth_flag = packet_get_authentication_state();	debug ("AUTH STATE is %d", auth_flag);#endif	for (mode = 0; mode < MODE_MAX; mode++) {		newkeys = xcalloc(1, sizeof(*newkeys));		kex->newkeys[mode] = newkeys;		ctos = (!kex->server && mode == MODE_OUT) ||		    (kex->server && mode == MODE_IN);		nenc  = ctos ? PROPOSAL_ENC_ALGS_CTOS  : PROPOSAL_ENC_ALGS_STOC;		nmac  = ctos ? PROPOSAL_MAC_ALGS_CTOS  : PROPOSAL_MAC_ALGS_STOC;		ncomp = ctos ? PROPOSAL_COMP_ALGS_CTOS : PROPOSAL_COMP_ALGS_STOC;		choose_enc (&newkeys->enc,  cprop[nenc],  sprop[nenc]);		choose_mac (&newkeys->mac,  cprop[nmac],  sprop[nmac]);		choose_comp(&newkeys->comp, cprop[ncomp], sprop[ncomp]);#ifdef	NONE_CIPHER_ENABLED		debug("REQUESTED ENC.NAME is '%s'", newkeys->enc.name);		if (strcmp(newkeys->enc.name, "none") == 0) {			debug("Requesting NONE. Authflag is %d", auth_flag);						if (auth_flag == 1)				debug("None requested post authentication.");			else				fatal("Pre-authentication none cipher requests "				    "are not allowed.");		} #endif		debug("kex: %s %s %s %s",		    ctos ? "client->server" : "server->client",		    newkeys->enc.name,		    newkeys->mac.name,		    newkeys->comp.name);	}	choose_kex(kex, cprop[PROPOSAL_KEX_ALGS], sprop[PROPOSAL_KEX_ALGS]);	choose_hostkeyalg(kex, cprop[PROPOSAL_SERVER_HOST_KEY_ALGS],	    sprop[PROPOSAL_SERVER_HOST_KEY_ALGS]);	need = 0;	for (mode = 0; mode < MODE_MAX; mode++) {		newkeys = kex->newkeys[mode];		if (need < newkeys->enc.key_len)			need = newkeys->enc.key_len;		if (need < newkeys->enc.block_size)			need = newkeys->enc.block_size;		if (need < newkeys->mac.key_len)			need = newkeys->mac.key_len;	}	/* XXX need runden? */	kex->we_need = need;	/* ignore the next message if the proposals do not match */	if (first_kex_follows && !proposals_match(my, peer) &&	    !(datafellows & SSH_BUG_FIRSTKEX)) {		type = packet_read();		debug2("skipping next packet (type %u)", type);	}	kex_prop_free(my);	kex_prop_free(peer);}
开发者ID:edgar-pek,项目名称:PerspicuOS,代码行数:93,


示例5: test_xcalloc_fail

static voidtest_xcalloc_fail() {  expect_string( mock_die, output, "Out of memory, xcalloc failed" );  expect_assert_failure( xcalloc( 1, 1 ) );}
开发者ID:RnD-Labs,项目名称:trema,代码行数:5,


示例6: lpx_warm_up

int lpx_warm_up(LPX *lp){     int m, n, j, k, ret, type, stat, p_stat, d_stat;      double lb, ub, prim, dual, tol_bnd, tol_dj, dir;      double *row_prim, *row_dual, *col_prim, *col_dual, sum;      m = lpx_get_num_rows(lp);      n = lpx_get_num_cols(lp);      /* reinvert the basis matrix, if necessary */      if (lpx_is_b_avail(lp))         ret = LPX_E_OK;      else      {  if (m == 0 || n == 0)         {  ret = LPX_E_EMPTY;            goto done;         }#if 0         ret = lpx_invert(lp);         switch (ret)         {  case 0:               ret = LPX_E_OK;               break;            case 1:            case 2:               ret = LPX_E_SING;               goto done;            case 3:               ret = LPX_E_BADB;               goto done;            default:               xassert(ret != ret);         }#else         switch (glp_factorize(lp))         {  case 0:               ret = LPX_E_OK;               break;            case GLP_EBADB:               ret = LPX_E_BADB;               goto done;            case GLP_ESING:            case GLP_ECOND:               ret = LPX_E_SING;               goto done;            default:               xassert(lp != lp);         }#endif      }      /* allocate working arrays */      row_prim = xcalloc(1+m, sizeof(double));      row_dual = xcalloc(1+m, sizeof(double));      col_prim = xcalloc(1+n, sizeof(double));      col_dual = xcalloc(1+n, sizeof(double));      /* compute primal basic solution components */      lpx_eval_b_prim(lp, row_prim, col_prim);      /* determine primal status of basic solution */      tol_bnd = 3.0 * lpx_get_real_parm(lp, LPX_K_TOLBND);      p_stat = LPX_P_FEAS;      for (k = 1; k <= m+n; k++)      {  if (k <= m)         {  type = lpx_get_row_type(lp, k);            lb = lpx_get_row_lb(lp, k);            ub = lpx_get_row_ub(lp, k);            prim = row_prim[k];         }         else         {  type = lpx_get_col_type(lp, k-m);            lb = lpx_get_col_lb(lp, k-m);            ub = lpx_get_col_ub(lp, k-m);            prim = col_prim[k-m];         }         if (type == LPX_LO || type == LPX_DB || type == LPX_FX)         {  /* variable x[k] has lower bound */            if (prim < lb - tol_bnd * (1.0 + fabs(lb)))            {  p_stat = LPX_P_INFEAS;               break;            }         }         if (type == LPX_UP || type == LPX_DB || type == LPX_FX)         {  /* variable x[k] has upper bound */            if (prim > ub + tol_bnd * (1.0 + fabs(ub)))            {  p_stat = LPX_P_INFEAS;               break;            }         }      }      /* compute dual basic solution components */      lpx_eval_b_dual(lp, row_dual, col_dual);      /* determine dual status of basic solution */      tol_dj = 3.0 * lpx_get_real_parm(lp, LPX_K_TOLDJ);      dir = (lpx_get_obj_dir(lp) == LPX_MIN ? +1.0 : -1.0);      d_stat = LPX_D_FEAS;      for (k = 1; k <= m+n; k++)      {  if (k <= m)         {  stat = lpx_get_row_stat(lp, k);            dual = row_dual[k];         }         else         {  stat = lpx_get_col_stat(lp, k-m);            dual = col_dual[k-m];         }//.........这里部分代码省略.........
开发者ID:davidwhogg,项目名称:SpectralArchetypes,代码行数:101,


示例7: lpx_transform_row

int lpx_transform_row(LPX *lp, int len, int ind[], double val[]){     int i, j, k, m, n, t, lll, *iii;      double alfa, *a, *aB, *rho, *vvv;      if (!lpx_is_b_avail(lp))         xfault("lpx_transform_row: LP basis is not available/n");      m = lpx_get_num_rows(lp);      n = lpx_get_num_cols(lp);      /* unpack the row to be transformed to the array a */      a = xcalloc(1+n, sizeof(double));      for (j = 1; j <= n; j++) a[j] = 0.0;      if (!(0 <= len && len <= n))         xfault("lpx_transform_row: len = %d; invalid row length/n",            len);      for (t = 1; t <= len; t++)      {  j = ind[t];         if (!(1 <= j && j <= n))            xfault("lpx_transform_row: ind[%d] = %d; column index out o"               "f range/n", t, j);         if (val[t] == 0.0)            xfault("lpx_transform_row: val[%d] = 0; zero coefficient no"               "t allowed/n", t);         if (a[j] != 0.0)            xfault("lpx_transform_row: ind[%d] = %d; duplicate column i"               "ndices not allowed/n", t, j);         a[j] = val[t];      }      /* construct the vector aB */      aB = xcalloc(1+m, sizeof(double));      for (i = 1; i <= m; i++)      {  k = lpx_get_b_info(lp, i);         /* xB[i] is k-th original variable */         xassert(1 <= k && k <= m+n);         aB[i] = (k <= m ? 0.0 : a[k-m]);      }      /* solve the system B'*rho = aB to compute the vector rho */      rho = aB, lpx_btran(lp, rho);      /* compute coefficients at non-basic auxiliary variables */      len = 0;      for (i = 1; i <= m; i++)      {  if (lpx_get_row_stat(lp, i) != LPX_BS)         {  alfa = - rho[i];            if (alfa != 0.0)            {  len++;               ind[len] = i;               val[len] = alfa;            }         }      }      /* compute coefficients at non-basic structural variables */      iii = xcalloc(1+m, sizeof(int));      vvv = xcalloc(1+m, sizeof(double));      for (j = 1; j <= n; j++)      {  if (lpx_get_col_stat(lp, j) != LPX_BS)         {  alfa = a[j];            lll = lpx_get_mat_col(lp, j, iii, vvv);            for (t = 1; t <= lll; t++) alfa += vvv[t] * rho[iii[t]];            if (alfa != 0.0)            {  len++;               ind[len] = m+j;               val[len] = alfa;            }         }      }      xassert(len <= n);      xfree(iii);      xfree(vvv);      xfree(aB);      xfree(a);      return len;}
开发者ID:davidwhogg,项目名称:SpectralArchetypes,代码行数:70,


示例8: dolist

/*ARGSUSED*/voiddolist(Char **v, struct command *c){    Char **globbed;    int     i, k;    struct stat st;    USE(c);    if (*++v == NULL) {	struct Strbuf word = Strbuf_INIT;	Strbuf_terminate(&word);	cleanup_push(&word, Strbuf_cleanup);	(void) t_search(&word, LIST, TW_ZERO, 0, STRNULL, 0);	cleanup_until(&word);	return;    }    v = glob_all_or_error(v);    globbed = v;    cleanup_push(globbed, blk_cleanup);    for (k = 0; v[k] != NULL && v[k][0] != '-'; k++)	continue;    if (v[k]) {	/*	 * We cannot process a flag therefore we let ls do it right.	 */	Char *lspath;	struct command *t;	struct wordent cmd, *nextword, *lastword;	Char   *cp;	struct varent *vp;	if (setintr) {	    pintr_disabled++;	    cleanup_push(&pintr_disabled, disabled_cleanup);	}	if (seterr) {	    xfree(seterr);	    seterr = NULL;	}	lspath = STRls;	STRmCF[1] = 'C';	STRmCF[3] = '/0';	/* Look at listflags, to add -A to the flags, to get a path	   of ls if necessary */	if ((vp = adrof(STRlistflags)) != NULL && vp->vec != NULL &&	    vp->vec[0] != STRNULL) {	    if (vp->vec[1] != NULL && vp->vec[1][0] != '/0')		lspath = vp->vec[1];	    for (cp = vp->vec[0]; *cp; cp++)		switch (*cp) {		case 'x':		    STRmCF[1] = 'x';		    break;		case 'a':		    STRmCF[3] = 'a';		    break;		case 'A':		    STRmCF[3] = 'A';		    break;		default:		    break;		}	}	cmd.word = STRNULL;	lastword = &cmd;	nextword = xcalloc(1, sizeof cmd);	nextword->word = Strsave(lspath);	lastword->next = nextword;	nextword->prev = lastword;	lastword = nextword;	nextword = xcalloc(1, sizeof cmd);	nextword->word = Strsave(STRmCF);	lastword->next = nextword;	nextword->prev = lastword;#if defined(KANJI) && defined(SHORT_STRINGS) && defined(DSPMBYTE)	if (dspmbyte_ls) {	    lastword = nextword;	    nextword = xcalloc(1, sizeof cmd);	    nextword->word = Strsave(STRmmliteral);	    lastword->next = nextword;	    nextword->prev = lastword;	}#endif#ifdef COLOR_LS_F	if (color_context_ls) {	    lastword = nextword;	    nextword = xcalloc(1, sizeof cmd);	    nextword->word = Strsave(STRmmcolormauto);	    lastword->next = nextword;	    nextword->prev = lastword;	}#endif /* COLOR_LS_F */	lastword = nextword;	for (cp = *v; cp; cp = *++v) {	    nextword = xcalloc(1, sizeof cmd);	    nextword->word = quote(Strsave(cp));//.........这里部分代码省略.........
开发者ID:VojtechVitek,项目名称:tcsh,代码行数:101,


示例9: aliasrun

/* * Karl Kleinpaste, 21oct1983. * Set up a one-word alias command, for use for special things. * This code is based on the mainline of process(). */voidaliasrun(int cnt, Char *s1, Char *s2){    struct wordent w, *new1, *new2;	/* for holding alias name */    struct command *t = NULL;    jmp_buf_t osetexit;    int status;    size_t omark;    getexit(osetexit);    if (seterr) {	xfree(seterr);	seterr = NULL;	/* don't repeatedly print err msg. */    }    w.word = STRNULL;    new1 = xcalloc(1, sizeof w);    new1->word = Strsave(s1);    if (cnt == 1) {	/* build a lex list with one word. */	w.next = w.prev = new1;	new1->next = new1->prev = &w;    }    else {	/* build a lex list with two words. */	new2 = xcalloc(1, sizeof w);	new2->word = Strsave(s2);	w.next = new2->prev = new1;	new1->next = w.prev = new2;	new1->prev = new2->next = &w;    }    cleanup_push(&w, lex_cleanup);    /* Save the old status */    status = getn(varval(STRstatus));    /* expand aliases like process() does. */    alias(&w);    /* build a syntax tree for the command. */    t = syntax(w.next, &w, 0);    cleanup_push(t, syntax_cleanup);    if (seterr)	stderror(ERR_OLD);    psavejob();    cleanup_push(&cnt, psavejob_cleanup); /* cnt is used only as a marker */    /* catch any errors here */    omark = cleanup_push_mark();    if (setexit() == 0)	/* execute the parse tree. */	/*	 * From: Michael Schroeder <[email
C++ xcb_change_property函数代码示例
C++ xc_interface_open函数代码示例
万事OK自学网:51自学网_软件自学网_CAD自学网自学excel、自学PS、自学CAD、自学C语言、自学css3实例,是一个通过网络自主学习工作技能的自学平台,网友喜欢的软件自学网站。