本文整理汇总了C++中check_mem函数的典型用法代码示例。如果您正苦于以下问题:C++ check_mem函数的具体用法?C++ check_mem怎么用?C++ check_mem使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了check_mem函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: malloc
Stats *Stats_recreate(double sum,
double sumsq,
unsigned long n,
double min,
double max
)
{
Stats *st = malloc(sizeof(Stats));
check_mem(st);
st->sum = sum;
st->sumsq = sumsq;
st->n = n;
st->min = min;
st->max = max;
return st;
error:
return NULL;
}
示例2: test_check
int test_check(char *file_name)
{
FILE *input = NULL;
char *block = NULL;
block = malloc(100);
check_mem(block);
input = fopen(file_name, "r");
check(input, "Failed to open %s", file_name);
free(block);
fclose(input);
return 0;
error:
if(block) free(block);
if(input) fclose(input);
return -1;
}
示例3: test_sentinel
int test_sentinel(int code)
{
char *temp = malloc(100);
check_mem(temp);
switch(code)
{
case 1:
log_info("it worked");
break;
default:
sentinel("I shouldn't run");
}
free(temp);
return 0;
error:
if(temp) free(temp);
return -1;
}
示例4: Renderer_createTexture
int Renderer_createTexture( const char *pTFile, bool pMipmaps ) {
Texture *t = NULL;
if( renderer && TextureArray_checkSize( &renderer->mTextures ) ) {
t = Texture_new();
check_mem( t );
// texture creation from file
check( Texture_loadFromFile( t, pTFile, pMipmaps ), "Error in texture creation.\n" );
// storage
int index = renderer->mTextures.cpt++;
renderer->mTextures.data[index] = t;
return index;
}
error:
Texture_destroy( t );
return -1;
}
示例5: Filter_add
int Filter_add(StateEvent state, filter_cb cb, bstring load_path, tns_value_t *config)
{
darray_t *filters = Filter_lookup_create(state);
check(filters != NULL, "Invalid filter state: %d given for filter %s",
state, bdata(load_path));
Filter *filter = darray_new(filters);
check_mem(filter);
filter->state = state;
filter->cb = cb;
filter->load_path = bstrcpy(load_path);
filter->config = config;
darray_attach(filters, filter);
darray_push(filters, filter);
return 0;
error:
return -1;
}
示例6: List_unshift
void List_unshift(List *list, void *value)
{
ListNode *node = calloc(1, sizeof(ListNode));
check_mem(node);
node->value = value;
if(list->first == NULL) {
list->first = node;
list->last = node;
} else {
node->next = list->first;
list->first->prev = node;
list->first = node;
}
list->count++;
error:
return;
}
示例7: Renderer_createShader
int Renderer_createShader( const char *pVFile, const char *pFFile ) {
Shader *s = NULL;
if( renderer && ShaderArray_checkSize( &renderer->mShaders ) ) {
s = Shader_new();
check_mem( s );
// shader creation and linking
check( Shader_buildFromFile( s, pVFile, pFFile ), "Error in shader creation.\n" );
// storage
int index = renderer->mShaders.cpt++;
renderer->mShaders.data[index] = s;
return index;
}
error:
Shader_destroy( s );
return -1;
}
示例8: cpu_count
CpuTimes *cpu_times_percent(bool percpu, CpuTimes *prev_times) {
CpuTimes *current = NULL;
CpuTimes *t;
int i, ncpus = percpu ? cpu_count(1) : 1;
CpuTimes *ret;
check(prev_times, "Need a reference point. prev_times can't be NULL");
current = cpu_times(percpu);
check(current, "Couldn't obtain CPU times");
ret = (CpuTimes *)calloc(ncpus, sizeof(CpuTimes));
check_mem(ret);
for (i = 0; i < ncpus; i++) {
t = calculate_cpu_times_percentage(prev_times + i, current + i);
*(ret + i) = *t;
free(t);
}
free(current);
return ret;
error:
free(current);
return NULL;
}
示例9: http_receive_payload
int http_receive_payload(int sockfd, char **payload, int content_length) {
*payload = NULL;
ssize_t recv_size = 0;
*payload = (char *)calloc(sizeof(char), content_length + 1);
check_mem(payload);
recv_size = read_all(sockfd, *payload, content_length);
debug("%s", *payload);
if (recv_size == content_length) {
debug("Read complete Http payload.");
} else if (recv_size == 0) {
log_err("End of TCP stream.");
return ERR_EOF;
} else {
log_err("Error while reading TCP stream.");
// TODO handle
exit(-1);
}
return HTTP_SUCCESS;
}
示例10: qip_ast_freturn_copy
// Copies a node and its children.
//
// node - The node to copy.
// ret - A pointer to where the new copy should be returned to.
//
// Returns 0 if successful, otherwise returns -1.
int qip_ast_freturn_copy(qip_ast_node *node, qip_ast_node **ret)
{
int rc;
check(node != NULL, "Node required");
check(ret != NULL, "Return pointer required");
qip_ast_node *clone = qip_ast_freturn_create(NULL);
check_mem(clone);
rc = qip_ast_node_copy(node->freturn.value, &clone->freturn.value);
check(rc == 0, "Unable to copy return value");
if(clone->freturn.value) clone->freturn.value->parent = clone;
*ret = clone;
return 0;
error:
qip_ast_node_free(clone);
*ret = NULL;
return -1;
}
示例11: test_check
int test_check(char *file_name)
{
FILE *input = NULL;
char *block = NULL;
block = malloc(100);
check_mem(block); // should work
input = fopen(file_name, "r");
check(input, "Failed to open %s", file_name);
free(block);
fclose(input);
return 0;
error:
printf("[goto error] at test_check\n");
if(block) free(block);
if(input) fclose(input);
return -1;
}
示例12: check
static inline DArray *Hashmap_find_bucket(Hashmap *map, void *key, int create, uint32_t *hash_out)
{//caller fn will include 1 or 0 for int create true or false
uint32_t hash = map->hash(key);
int bucket_n = hash % DEFAULT_NUMBER_OF_BUCKETS;//finds bucket, will always find a bucket no matter how big
check(bucket_n >= 0, "Invalid bucket found: %d", bucket_n);
*hash_out = hash; //store it for the return so caller can use it. I forget how caller is supposed to use this
DArray *bucket = DArray_get(map->buckets, bucket_n);
if(!bucket && create) {//creates bucket if none found
//new bucket, set it up
bucket = DArray_create(sizeof(void *), DEFAULT_NUMBER_OF_BUCKETS);
check_mem(bucket);
DArray_set(map->buckets, bucket_n, bucket);
}
return bucket;
error:
return NULL;
}
示例13: create_node
Node_T create_node(Node_T father, SuffixTreeIndex_T start, SuffixTreeIndex_T end,
SuffixTreeIndex_T position)
{
/*Allocate a node.*/
Node_T node = malloc(sizeof(struct Node_T));
check_mem(node);
node->left_son = NULL;
node->right_sibling = NULL;
node->left_sibling = NULL;
node->suffix_link = NULL;
node->father = father;
node->path_position = position;
node->edge_label_start = start;
node->edge_label_end = end;
return node;
error:
if(node) free(node);
return NULL;
}
示例14: qip_ast_block_add_expr
// Appends an expression to the end of the block.
//
// block - The block to append the expression to.
// expr - The expression to append.
//
// Returns 0 if successful, otherwise returns -1.
int qip_ast_block_add_expr(struct qip_ast_node *block, struct qip_ast_node *expr)
{
// Validate.
check(block != NULL, "Block is required");
check(block->type == QIP_AST_TYPE_BLOCK, "Block node is invalid type: %d", block->type);
check(expr != NULL, "Expression is required");
// Append expression to block.
block->block.expr_count++;
block->block.exprs = realloc(block->block.exprs, sizeof(qip_ast_node*) * block->block.expr_count);
check_mem(block->block.exprs);
block->block.exprs[block->block.expr_count-1] = expr;
// Assign parent reference to expression.
expr->parent = block;
return 0;
error:
return -1;
}
示例15: lapack_dsteqr
void lapack_dsteqr(int nn, int ldz, dreal *alph, dreal *beta, dreal *zz)
{
int nwork, info;
char compz = 'I';
dreal *work = NULL;
nwork = (1 >= 2*nn-2) ? 1 : 2*nn-2;
work = (dreal *) calloc(nwork, sizeof(dreal));
check_mem(work, "work");
dsteqr_(&compz, &nn, alph, beta, zz, &ldz, work, &info);
freeup(work);
return;
error:
if(work) freeup(work);
abort();
}