本文整理汇总了C++中CALLOC函数的典型用法代码示例。如果您正苦于以下问题:C++ CALLOC函数的具体用法?C++ CALLOC怎么用?C++ CALLOC使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了CALLOC函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int
main (int argc, char *argv[])
{
lrs_dic *P1,*P2; /* structure for holding current dictionary and indices */
lrs_dat *Q1,*Q2; /* structure for holding static problem data */
lrs_mp_vector output1; /* holds one line of output; ray,vertex,facet,linearity */
lrs_mp_vector output2; /* holds one line of output; ray,vertex,facet,linearity */
lrs_mp_matrix Lin; /* holds input linearities if any are found */
lrs_dic *P2orig; /* we will save player 2's dictionary in getabasis */
long col; /* output column index for dictionary */
long startcol = 0;
long prune = FALSE; /* if TRUE, getnextbasis will prune tree and backtrack */
long numequilib=0; /* number of nash equilibria found */
long oldnum=0;
/* global variables lrs_ifp and lrs_ofp are file pointers for input and output */
/* they default to stdin and stdout, but may be overidden by command line parms. */
if(argc <= 2 )
{ printf("Usage: index input1 input2 [outputfile] \n");
return 1;
}
/***************************************************
Step 0:
Do some global initialization that should only be done once,
no matter how many lrs_dat records are allocated. db
***************************************************/
if ( !lrs_init ("\n*index:"))
return 1;
printf(AUTHOR);
/*********************************************************************************/
/* Step 1: Allocate lrs_dat, lrs_dic and set up the problem */
/*********************************************************************************/
Q1 = lrs_alloc_dat ("LRS globals"); /* allocate and init structure for static problem data */
if (Q1 == NULL)
return 1;
Q1->nash=TRUE;
if (!lrs_read_dat (Q1, argc, argv)) /* read first part of problem data to get dimensions */
return 1; /* and problem type: H- or V- input representation */
P1 = lrs_alloc_dic (Q1); /* allocate and initialize lrs_dic */
if (P1 == NULL)
return 1;
if (!lrs_read_dic (P1, Q1)) /* read remainder of input to setup P1 and Q1 */
return 1;
output1 = lrs_alloc_mp_vector (Q1->n + Q1->m); /* output holds one line of output from dictionary */
fclose(lrs_ifp);
/* allocate and init structure for player 2's problem data */
printf ("\n*Second input taken from file %s\n", argv[2]);
Q2 = lrs_alloc_dat ("LRS globals");
if (Q2 == NULL)
return 1;
Q2->nash=TRUE;
if (!lrs_read_dat (Q2, 2, argv)) /* read first part of problem data to get dimensions */
return 1; /* and problem type: H- or V- input representation */
if (Q2->nlinearity > 0)
free(Q2->linearity); /* we will start again */
Q2->linearity = CALLOC ((Q2->m + 2), sizeof (long));
P2 = lrs_alloc_dic (Q2); /* allocate and initialize lrs_dic */
if (P2 == NULL)
return 1;
if (!lrs_read_dic (P2, Q2)) /* read remainder of input to setup P2 and Q2 */
return 1;
output2 = lrs_alloc_mp_vector (Q1->n + Q1->m); /* output holds one line of output from dictionary */
P2orig = lrs_getdic(Q2); /* allocate and initialize lrs_dic */
if (P2orig == NULL)
return 1;
copy_dict(Q2,P2orig,P2);
fprintf (lrs_ofp, "\n***** %ld %ld rational", Q1->n, Q2->n);
/*********************************************************************************/
/* Step 2: Find a starting cobasis from default of specified order */
/* P1 is created to hold active dictionary data and may be cached */
/* Lin is created if necessary to hold linearity space */
//.........这里部分代码省略.........
示例2: XvMCCreateSubpicture
PUBLIC
Status XvMCCreateSubpicture(Display *dpy, XvMCContext *context, XvMCSubpicture *subpicture,
unsigned short width, unsigned short height, int xvimage_id)
{
XvMCContextPrivate *context_priv;
XvMCSubpicturePrivate *subpicture_priv;
struct pipe_context *pipe;
struct pipe_resource tex_templ, *tex;
struct pipe_sampler_view sampler_templ;
Status ret;
XVMC_MSG(XVMC_TRACE, "[XvMC] Creating subpicture %p.\n", subpicture);
assert(dpy);
if (!context)
return XvMCBadContext;
context_priv = context->privData;
pipe = context_priv->pipe;
if (!subpicture)
return XvMCBadSubpicture;
if (width > context_priv->subpicture_max_width ||
height > context_priv->subpicture_max_height)
return BadValue;
ret = Validate(dpy, context->port, context->surface_type_id, xvimage_id);
if (ret != Success)
return ret;
subpicture_priv = CALLOC(1, sizeof(XvMCSubpicturePrivate));
if (!subpicture_priv)
return BadAlloc;
memset(&tex_templ, 0, sizeof(tex_templ));
tex_templ.target = PIPE_TEXTURE_2D;
tex_templ.format = XvIDToPipe(xvimage_id);
tex_templ.last_level = 0;
if (pipe->screen->get_video_param(pipe->screen,
PIPE_VIDEO_PROFILE_UNKNOWN,
PIPE_VIDEO_CAP_NPOT_TEXTURES)) {
tex_templ.width0 = width;
tex_templ.height0 = height;
}
else {
tex_templ.width0 = util_next_power_of_two(width);
tex_templ.height0 = util_next_power_of_two(height);
}
tex_templ.depth0 = 1;
tex_templ.array_size = 1;
tex_templ.usage = PIPE_USAGE_DYNAMIC;
tex_templ.bind = PIPE_BIND_SAMPLER_VIEW;
tex_templ.flags = 0;
tex = pipe->screen->resource_create(pipe->screen, &tex_templ);
memset(&sampler_templ, 0, sizeof(sampler_templ));
u_sampler_view_default_template(&sampler_templ, tex, tex->format);
subpicture_priv->sampler = pipe->create_sampler_view(pipe, tex, &sampler_templ);
pipe_resource_reference(&tex, NULL);
if (!subpicture_priv->sampler) {
FREE(subpicture_priv);
return BadAlloc;
}
subpicture_priv->context = context;
subpicture->subpicture_id = XAllocID(dpy);
subpicture->context_id = context->context_id;
subpicture->xvimage_id = xvimage_id;
subpicture->width = width;
subpicture->height = height;
subpicture->num_palette_entries = NumPaletteEntries4XvID(xvimage_id);
subpicture->entry_bytes = PipeToComponentOrder(tex_templ.format, subpicture->component_order);
subpicture->privData = subpicture_priv;
if (subpicture->num_palette_entries > 0) {
tex_templ.target = PIPE_TEXTURE_1D;
tex_templ.format = PIPE_FORMAT_R8G8B8X8_UNORM;
tex_templ.width0 = subpicture->num_palette_entries;
tex_templ.height0 = 1;
tex_templ.usage = PIPE_USAGE_STATIC;
tex = pipe->screen->resource_create(pipe->screen, &tex_templ);
memset(&sampler_templ, 0, sizeof(sampler_templ));
u_sampler_view_default_template(&sampler_templ, tex, tex->format);
sampler_templ.swizzle_a = PIPE_SWIZZLE_ONE;
subpicture_priv->palette = pipe->create_sampler_view(pipe, tex, &sampler_templ);
pipe_resource_reference(&tex, NULL);
if (!subpicture_priv->sampler) {
FREE(subpicture_priv);
return BadAlloc;
}
}
SyncHandle();
//.........这里部分代码省略.........
示例3: hwloc_to_tm
tm_topology_t* hwloc_to_tm(char *filename,double **pcost)
{
hwloc_topology_t topology;
tm_topology_t *res = NULL;
hwloc_obj_t *objs = NULL;
unsigned topodepth,depth;
int nb_nodes,i;
double *cost;
int err;
/* Build the topology */
hwloc_topology_init(&topology);
err = hwloc_topology_set_xml(topology,filename);
if(err == -1){
if(get_verbose_level() >= CRITICAL)
fprintf(stderr,"Error: %s is a bad xml topology file!\n",filename);
exit(-1);
}
hwloc_topology_ignore_all_keep_structure(topology);
hwloc_topology_load(topology);
/* Test if symetric */
if(!symetric(topology)){
if(get_verbose_level() >= CRITICAL)
fprintf(stderr,"%s not symetric!\n",filename);
exit(-1);
}
/* work on depth */
topodepth = hwloc_topology_get_depth(topology);
res = (tm_topology_t*)MALLOC(sizeof(tm_topology_t));
res->nb_levels = topodepth;
res->node_id = (int**)MALLOC(sizeof(int*)*res->nb_levels);
res->nb_nodes = (int*)MALLOC(sizeof(int)*res->nb_levels);
res->arity = (int*)MALLOC(sizeof(int)*res->nb_levels);
if(get_verbose_level() >= INFO)
printf("topodepth = %d\n",topodepth);
/* Build TreeMatch topology */
for( depth = 0 ; depth < topodepth ; depth++ ){
nb_nodes = hwloc_get_nbobjs_by_depth(topology, depth);
res->nb_nodes[depth] = nb_nodes;
res->node_id[depth] = (int*)MALLOC(sizeof(int)*nb_nodes);
objs = (hwloc_obj_t*)MALLOC(sizeof(hwloc_obj_t)*nb_nodes);
objs[0] = hwloc_get_next_obj_by_depth(topology,depth,NULL);
hwloc_get_closest_objs(topology,objs[0],objs+1,nb_nodes-1);
res->arity[depth] = objs[0]->arity;
if(get_verbose_level() >= INFO)
printf("%d(%d):",res->arity[depth],nb_nodes);
/* Build process id tab */
for (i = 0; i < nb_nodes; i++){
res->node_id[depth][i] = objs[i]->os_index;
/* if(depth==topodepth-1) */
}
FREE(objs);
}
cost = (double*)CALLOC(res->nb_levels,sizeof(double));
for(i=0; i<res->nb_levels; i++){
cost[i] = speed(i);
}
*pcost = cost;
/* Destroy topology object. */
hwloc_topology_destroy(topology);
if(get_verbose_level() >= INFO)
printf("\n");
return res;
}
示例4: main
int main(void) {
int fd;
InputStream_T in = NULL;
Bootstrap(); // Need to initialize library
printf("============> Start InputStream Tests\n\n");
printf("=> Test0: create/destroy the file input stream\n");
{
in = InputStream_new(File_open(DATA, "r"));
assert(!InputStream_isClosed(in));
File_close(InputStream_getDescriptor(in));
InputStream_free(&in);
assert(in == NULL);
}
printf("=> Test0: OK\n\n");
printf("=> Test1: get/set timeout\n");
{
assert((fd = File_open(DATA, "r")) >= 0);
in = InputStream_new(fd);
printf("\tCurrent timeout: %ldms\n", InputStream_getTimeout(in));
InputStream_setTimeout(in, TIMEOUT);
assert(InputStream_getTimeout(in) == TIMEOUT);
printf("\tTimeout set to: %dms\n", TIMEOUT);
File_close(fd);
InputStream_free(&in);
}
printf("=> Test1: OK\n\n");
printf("=> Test2: read file by characters\n");
{
int byte;
int byteno = 0;
char content[][1] = {"l", "i", "n", "e", "1", "\n",
"l", "i", "n", "e", "2", "\n",
"l", "i", "n", "e", "3", "\n"};
assert((fd = File_open(DATA, "r")) >= 0);
in = InputStream_new(fd);
while ((byte = InputStream_read(in)) > 0) {
assert(byte == *content[byteno++]);
}
File_close(fd);
InputStream_free(&in);
}
printf("=> Test2: OK\n\n");
printf("=> Test3: read file by lines\n");
{
int lineno = 0;
char line[STRLEN];
char content[][STRLEN] = {"line1\n", "line2\n", "line3\n"};
assert((fd = File_open(DATA, "r")) >= 0);
in = InputStream_new(fd);
while (InputStream_readLine(in, line, sizeof(line))) {
assert(Str_isEqual(content[lineno++], line));
}
File_close(fd);
InputStream_free(&in);
}
printf("=> Test3: OK\n\n");
printf("=> Test4: read file by bytes\n");
{
char array[STRLEN];
char content[] = "line1\nline2\nline3\n";
memset(array, 0, STRLEN);
assert((fd = File_open(DATA, "r")) >= 0);
in = InputStream_new(fd);
while (InputStream_readBytes(in, array, sizeof(array)-1)) {
assert(Str_isEqual(content, array));
}
File_close(fd);
InputStream_free(&in);
}
printf("=> Test4: OK\n\n");
printf("=> Test5: read a large file\n");
{
if ((fd = File_open("/usr/share/dict/words", "r")) >= 0) {
int n = 0;
char array[2][STRLEN + 1];
in = InputStream_new(fd);
for (int i = 0; ((n = InputStream_readBytes(in, array[i], STRLEN)) > 0); i = i ? 0 : 1)
assert(strncmp(array[0], array[1], STRLEN/2) != 0); // ensure that InputStream buffer is filled anew
File_rewind(fd);
// Test read data larger than InputStream's internal buffer
int filesize = (int)File_size("/usr/share/dict/words");
char *bigarray = CALLOC(1, filesize + 1);
n = InputStream_readBytes(in, bigarray, filesize);
assert(n == filesize);
File_close(fd);
InputStream_free(&in);
FREE(bigarray);
} else
ERROR("\t/usr/share/dict/words not available -- skipping test\n");
}
printf("=> Test5: OK\n\n");
//.........这里部分代码省略.........
示例5: bwx_shell
extern int
bwx_shell( struct bwb_line *l )
{
static char *s_buffer;
static int init = FALSE;
static int position;
/* get memory for temporary buffer if necessary */
if ( init == FALSE )
{
init = TRUE;
/* Revised to CALLOC pass-thru call by JBV */
if ( ( s_buffer = CALLOC( MAXSTRINGSIZE + 1, sizeof( char ),"bwx_shell" )) == NULL )
{
bwb_error( err_getmem );
return FALSE;
}
}
/* get the first element and check for a line number */
#if INTENSIVE_DEBUG
sprintf( bwb_ebuf, "in bwx_shell(): line buffer is <%s>.", l->buffer );
bwb_debug( bwb_ebuf );
#endif
position = 0;
adv_element( l->buffer, &position, s_buffer );
if ( is_numconst( s_buffer ) != TRUE ) /* not a line number */
{
#if INTENSIVE_DEBUG
sprintf( bwb_ebuf, "in bwx_shell(): no line number, command <%s>.",
l->buffer );
bwb_debug( bwb_ebuf );
#endif
nl();
endwin(); /* Added by JBV 10/11/97 */
if ( system( l->buffer ) == 0 )
{
refresh(); /* Added by JBV 10/11/97 */
nonl();
ncu_setpos();
return TRUE;
}
else
{
refresh(); /* Added by JBV 10/11/97 */
nonl();
ncu_setpos();
return FALSE;
}
}
else /* advance past line number */
{
adv_ws( l->buffer, &position ); /* advance past whitespace */
#if INTENSIVE_DEBUG
sprintf( bwb_ebuf, "in bwx_shell(): line number, command <%s>.",
l->buffer );
bwb_debug( bwb_ebuf );
#endif
nl();
endwin(); /* Added by JBV 10/11/97 */
if ( system( &( l->buffer[ position ] ) ) == 0 )
{
refresh(); /* Added by JBV 10/11/97 */
nonl();
ncu_setpos();
return TRUE;
}
else
{
refresh(); /* Added by JBV 10/11/97 */
nonl();
ncu_setpos();
return FALSE;
}
}
}
示例6: CALLOC
void *mxCalloc(size_t n, size_t size)
{
//TODO
return CALLOC(n, size);
}
示例7: processReceivedPacketData
// this is the callback function called by the network thread
// to receive packet data placed into a PacketData struct
//
// process the raw data stream and parse into signals,
// push these signals to the signal buffer
// returns true if parsing successful
void processReceivedPacketData(const PacketData * pRaw)
{
GroupInfo g;
GroupInfo* pgOnTrie;
const uint8_t* pBufStart = pRaw->data;
const uint8_t* pBuf = pRaw->data;
bool isControlGroup, firstTimeGroupSeen, success, waitingNextTrial;
int iSignal, nSignals;
// logInfo("processing raw data!");
while(pBuf - pBufStart < pRaw->length) {
if(*pBuf == 0) {
// consider this the null terminator
// odd-length packets are expanded to be even length in Simulink
// so this can occasionally happen
if (pRaw->length - (pBuf-pBufStart) > 1)
logError("Packet parsing stopping due to NULL byte but %ld bytes remaining\n", pRaw->length - (pBuf-pBufStart));
break;
}
// parse the group header and build out the GroupInfo g
pBuf = parseGroupInfoHeader(pBuf, &g);
if(pBuf == NULL) {
logError("Could not parse group header\n");
return;
}
nSignals = g.nSignals;
if(nSignals == 0 || nSignals > MAX_GROUP_SIGNALS) {
logError("Group %s has too many signals (%d)\n", g.name, nSignals);
return;
}
// can do different processing here depending on the version of the packet
// handle control groups differently
if(g.type == GROUP_TYPE_CONTROL)
isControlGroup = true;
else
isControlGroup = false;
// allocate space to parse and hold onto all the signals at once
// we do this in one pass in case parsing fails, since then we'll need to bail
SignalSample* samples = (SignalSample*)CALLOC(sizeof(SignalSample), nSignals);
// parse all the signals into SignalSamples
bool parseError = false;
for(iSignal = 0; iSignal < nSignals; iSignal++) {
pBuf = parseSignalFromBuffer(pBuf, samples + iSignal);
//if (strcmp(g.name, "taskEvent") == 0)
// logError("Seeing event %s\n", samples[0].data);
samples[iSignal].timestamp = g.lastTimestamp;
if(pBuf == NULL) {
parseError = true;
logError("Error parsing signal %d / %d from buffer for group %s\n", iSignal+1, nSignals, g.name);
for(; iSignal >= 0; iSignal--)
freeSignalSampleData(samples + iSignal);
FREE(samples);
return;
}
}
if(parseError) {
for(iSignal = 0; iSignal < nSignals; iSignal++)
freeSignalSampleData(samples + iSignal);
FREE(samples);
return;
}
if(isControlGroup) {
success = processControlSignalSamples(nSignals, (const SignalSample*)samples);
if(!success) {
logError("Issue handling control signals\n");
for(iSignal = 0; iSignal < nSignals; iSignal++)
freeSignalSampleData(samples + iSignal);
FREE(samples);
return;
}
} else {
// non control group
// check whether we'll store this or not
waitingNextTrial = controlGetWaitingForNextTrial();
//.........这里部分代码省略.........
示例8: MALLOC
static sco_data *getScoData(scicos_block * block)
{
sco_data *sco = (sco_data *) * (block->work);
int i, j;
int nclk = block->nipar - 6;
if (sco == NULL)
{
/*
* Data allocation
*/
sco = (sco_data *) MALLOC(sizeof(sco_data));
if (sco == NULL)
{
goto error_handler_sco;
}
sco->internal.numberOfPoints = (int *)CALLOC(nclk, sizeof(int));
if (sco->internal.numberOfPoints == NULL)
{
goto error_handler_numberOfPoints;
}
sco->internal.maxNumberOfPoints = (int *)MALLOC(nclk * sizeof(int));
if (sco->internal.numberOfPoints == NULL)
{
goto error_handler_maxNumberOfPoints;
}
for (i = 0; i < nclk; i++)
{
sco->internal.maxNumberOfPoints[i] = DEFAULT_MAX_NUMBER_OF_POINTS;
}
sco->internal.data = (double **)CALLOC(2 * nclk, sizeof(double *));
if (sco->internal.data == NULL)
{
goto error_handler_data;
}
for (i = 0; i < nclk; i++)
{
/*
* Alloc base pointer
*/
sco->internal.data[2 * i + 0] = (double *)CALLOC(3 * DEFAULT_MAX_NUMBER_OF_POINTS, sizeof(double));
if (sco->internal.data[2 * i + 0] == NULL)
{
goto error_handler_data_i;
}
/*
* Alloc direction pointer
*/
sco->internal.data[2 * i + 1] = (double *)CALLOC(3 * DEFAULT_MAX_NUMBER_OF_POINTS, sizeof(double));
if (sco->internal.data[2 * i + 1] == NULL)
{
FREE(sco->internal.data[2 * i + 0]);
goto error_handler_data_i;
}
}
sco->scope.periodCounter = 0;
sco->scope.cachedFigureUID = 0;
sco->scope.cachedAxeUID = 0;
sco->scope.cachedSegsUIDs = (int*)CALLOC(nclk, sizeof(int));
if (sco->scope.cachedSegsUIDs == NULL)
{
goto error_handler_data_i;
}
*(block->work) = sco;
}
return sco;
/*
* Error management (out of normal flow)
*/
error_handler_data_i:
for (j = 0; j < i; j++)
{
FREE(sco->internal.data[2 * j + 0]);
FREE(sco->internal.data[2 * j + 1]);
}
FREE(sco->internal.data);
error_handler_data:
FREE(sco->internal.maxNumberOfPoints);
error_handler_maxNumberOfPoints:
FREE(sco->internal.numberOfPoints);
error_handler_numberOfPoints:
FREE(sco);
error_handler_sco:
// allocation error
set_block_error(-5);
return NULL;
}
示例9: pp_jimenezmlaa_init_run
/** The init function of the MLAA filter. */
static bool
pp_jimenezmlaa_init_run(struct pp_queue_t *ppq, unsigned int n,
unsigned int val, bool iscolor)
{
struct pipe_box box;
struct pipe_resource res;
char *tmp_text = NULL;
tmp_text = CALLOC(sizeof(blend2fs_1) + sizeof(blend2fs_2) +
IMM_SPACE, sizeof(char));
if (!tmp_text) {
pp_debug("Failed to allocate shader space\n");
return FALSE;
}
ppq->constbuf = pipe_buffer_create(ppq->p->screen,
PIPE_BIND_CONSTANT_BUFFER,
PIPE_USAGE_DEFAULT,
sizeof(constants));
if (ppq->constbuf == NULL) {
pp_debug("Failed to allocate constant buffer\n");
goto fail;
}
pp_debug("mlaa: using %u max search steps\n", val);
util_sprintf(tmp_text, "%s"
"IMM FLT32 { %.8f, 0.0000, 0.0000, 0.0000}\n"
"%s\n", blend2fs_1, (float) val, blend2fs_2);
memset(&res, 0, sizeof(res));
res.target = PIPE_TEXTURE_2D;
res.format = PIPE_FORMAT_R8G8_UNORM;
res.width0 = res.height0 = 165;
res.bind = PIPE_BIND_SAMPLER_VIEW;
res.usage = PIPE_USAGE_DEFAULT;
res.depth0 = res.array_size = res.nr_samples = 1;
if (!ppq->p->screen->is_format_supported(ppq->p->screen, res.format,
res.target, 1, res.bind))
pp_debug("Areamap format not supported\n");
ppq->areamaptex = ppq->p->screen->resource_create(ppq->p->screen, &res);
if (ppq->areamaptex == NULL) {
pp_debug("Failed to allocate area map texture\n");
goto fail;
}
u_box_2d(0, 0, 165, 165, &box);
ppq->p->pipe->texture_subdata(ppq->p->pipe, ppq->areamaptex, 0,
PIPE_TRANSFER_WRITE, &box,
areamap, 165 * 2, sizeof(areamap));
ppq->shaders[n][1] = pp_tgsi_to_state(ppq->p->pipe, offsetvs, true,
"offsetvs");
if (iscolor)
ppq->shaders[n][2] = pp_tgsi_to_state(ppq->p->pipe, color1fs,
false, "color1fs");
else
ppq->shaders[n][2] = pp_tgsi_to_state(ppq->p->pipe, depth1fs,
false, "depth1fs");
ppq->shaders[n][3] = pp_tgsi_to_state(ppq->p->pipe, tmp_text, false,
"blend2fs");
ppq->shaders[n][4] = pp_tgsi_to_state(ppq->p->pipe, neigh3fs, false,
"neigh3fs");
FREE(tmp_text);
return TRUE;
fail:
FREE(tmp_text);
/*
* Call the common free function for destruction of partially initialized
* resources.
*/
pp_jimenezmlaa_free(ppq, n);
return FALSE;
}
示例10: _new_stack
static struct _stack *
_new_stack() {
return (struct _stack *)CALLOC(1, sizeof(struct _stack));
}
示例11: OCTET_STRING_decode_ber
/*
* Decode OCTET STRING type.
*/
asn_dec_rval_t
OCTET_STRING_decode_ber(asn_codec_ctx_t *opt_codec_ctx,
asn_TYPE_descriptor_t *td,
void **sptr, const void *buf_ptr, size_t size, int tag_mode) {
asn_OCTET_STRING_specifics_t *specs = td->specifics
? (asn_OCTET_STRING_specifics_t *)td->specifics
: &asn_DEF_OCTET_STRING_specs;
BIT_STRING_t *st = (BIT_STRING_t *)*sptr;
asn_dec_rval_t rval;
asn_struct_ctx_t *ctx;
ssize_t consumed_myself = 0;
struct _stack *stck; /* Expectations stack structure */
struct _stack_el *sel = 0; /* Stack element */
int tlv_constr;
enum asn_OS_Subvariant type_variant = specs->subvariant;
ASN_DEBUG("Decoding %s as %s (frame %ld)",
td->name,
(type_variant == ASN_OSUBV_STR) ?
"OCTET STRING" : "OS-SpecialCase",
(long)size);
/*
* Create the string if does not exist.
*/
if(st == NULL) {
st = (BIT_STRING_t *)(*sptr = CALLOC(1, specs->struct_size));
if(st == NULL) RETURN(RC_FAIL);
}
/* Restore parsing context */
ctx = (asn_struct_ctx_t *)((char *)st + specs->ctx_offset);
switch(ctx->phase) {
case 0:
/*
* Check tags.
*/
rval = ber_check_tags(opt_codec_ctx, td, ctx,
buf_ptr, size, tag_mode, -1,
&ctx->left, &tlv_constr);
if(rval.code != RC_OK)
return rval;
if(tlv_constr) {
/*
* Complex operation, requires stack of expectations.
*/
ctx->ptr = _new_stack();
if(ctx->ptr) {
stck = (struct _stack *)ctx->ptr;
} else {
RETURN(RC_FAIL);
}
} else {
/*
* Jump into stackless primitive decoding.
*/
_CH_PHASE(ctx, 3);
if(type_variant == ASN_OSUBV_ANY && tag_mode != 1)
APPEND(buf_ptr, rval.consumed);
ADVANCE(rval.consumed);
goto phase3;
}
NEXT_PHASE(ctx);
/* Fall through */
case 1:
phase1:
/*
* Fill the stack with expectations.
*/
stck = (struct _stack *)ctx->ptr;
sel = stck->cur_ptr;
do {
ber_tlv_tag_t tlv_tag;
ber_tlv_len_t tlv_len;
ber_tlv_tag_t expected_tag;
ssize_t tl, ll, tlvl;
/* This one works even if (sel->left == -1) */
size_t Left = ((!sel||(size_t)sel->left >= size)
?size:(size_t)sel->left);
ASN_DEBUG("%p, s->l=%ld, s->wn=%ld, s->g=%ld\n", sel,
(long)(sel?sel->left:0),
(long)(sel?sel->want_nulls:0),
(long)(sel?sel->got:0)
);
if(sel && sel->left <= 0 && sel->want_nulls == 0) {
if(sel->prev) {
struct _stack_el *prev = sel->prev;
if(prev->left != -1) {
if(prev->left < sel->got)
RETURN(RC_FAIL);
prev->left -= sel->got;
}
//.........这里部分代码省略.........
示例12: gammaCreateScreen
gammaScreenPtr gammaCreateScreen( __DRIscreenPrivate *sPriv )
{
gammaScreenPtr gammaScreen;
GLINTDRIPtr gDRIPriv = (GLINTDRIPtr)sPriv->pDevPriv;
int i;
#if 0
/* Check the DRI version */
{
int major, minor, patch;
if ( XF86DRIQueryVersion( sPriv->display, &major, &minor, &patch ) ) {
if ( major != 3 || minor != 1 || patch < 0 ) {
__driUtilMessage( "r128 DRI driver expected DRI version 3.1.x but got version %d.%d.%d", major, minor, patch );
return GL_FALSE;
}
}
}
/* Check that the DDX driver version is compatible */
if ( sPriv->ddxMajor != 4 ||
sPriv->ddxMinor != 0 ||
sPriv->ddxPatch < 0 ) {
__driUtilMessage( "r128 DRI driver expected DDX driver version 4.0.x but got version %d.%d.%d", sPriv->ddxMajor, sPriv->ddxMinor, sPriv->ddxPatch );
return GL_FALSE;
}
/* Check that the DRM driver version is compatible */
if ( sPriv->drmMajor != 2 ||
sPriv->drmMinor != 1 ||
sPriv->drmPatch < 0 ) {
__driUtilMessage( "r128 DRI driver expected DRM driver version 2.1.x but got version %d.%d.%d", sPriv->drmMajor, sPriv->drmMinor, sPriv->drmPatch );
return GL_FALSE;
}
#endif
/* Allocate the private area */
gammaScreen = (gammaScreenPtr) CALLOC( sizeof(*gammaScreen) );
if ( !gammaScreen ) return NULL;
gammaScreen->regionCount = 4; /* Magic number. Can we fix this? */
gammaScreen->regions = Xmalloc(gammaScreen->regionCount *
sizeof(gammaRegion));
gammaScreen->regions[0].handle = gDRIPriv->registers0.handle;
gammaScreen->regions[0].size = gDRIPriv->registers0.size;
gammaScreen->regions[1].handle = gDRIPriv->registers1.handle;
gammaScreen->regions[1].size = gDRIPriv->registers1.size;
gammaScreen->regions[2].handle = gDRIPriv->registers2.handle;
gammaScreen->regions[2].size = gDRIPriv->registers2.size;
gammaScreen->regions[3].handle = gDRIPriv->registers3.handle;
gammaScreen->regions[3].size = gDRIPriv->registers3.size;
/* Next, map all the regions */
for (i = 0; i < gammaScreen->regionCount; i++) {
if (drmMap(sPriv->fd,
gammaScreen->regions[i].handle,
gammaScreen->regions[i].size,
&gammaScreen->regions[i].map)) {
while (--i > 0) {
(void)drmUnmap(gammaScreen->regions[i].map,
gammaScreen->regions[i].size);
}
return GL_FALSE;
}
}
/* Get the list of dma buffers */
gammaScreen->bufs = drmMapBufs(sPriv->fd);
if (!gammaScreen->bufs) {
while (gammaScreen->regionCount > 0) {
(void)drmUnmap(gammaScreen->regions[gammaScreen->regionCount].map,
gammaScreen->regions[gammaScreen->regionCount].size);
gammaScreen->regionCount--;
}
return GL_FALSE;
}
gammaScreen->textureSize = gDRIPriv->textureSize;
gammaScreen->logTextureGranularity = gDRIPriv->logTextureGranularity;
gammaScreen->cpp = gDRIPriv->cpp;
gammaScreen->frontOffset = gDRIPriv->frontOffset;
gammaScreen->frontPitch = gDRIPriv->frontPitch;
gammaScreen->backOffset = gDRIPriv->backOffset;
gammaScreen->backPitch = gDRIPriv->backPitch;
gammaScreen->backX = gDRIPriv->backX;
gammaScreen->backY = gDRIPriv->backY;
gammaScreen->depthOffset = gDRIPriv->depthOffset;
gammaScreen->depthPitch = gDRIPriv->depthPitch;
gammaScreen->driScreen = sPriv;
return gammaScreen;
}
示例13: pixaDisplayTiledAndScaled
/*!
* pixaDisplayTiledAndScaled()
*
* Input: pixa
* outdepth (output depth: 1, 8 or 32 bpp)
* tilewidth (each pix is scaled to this width)
* ncols (number of tiles in each row)
* background (0 for white, 1 for black; this is the color
* of the spacing between the images)
* spacing (between images, and on outside)
* border (width of additional black border on each image;
* use 0 for no border)
* Return: pix of tiled images, or null on error
*
* Notes:
* (1) This can be used to tile a number of renderings of
* an image that are at different scales and depths.
* (2) Each image, after scaling and optionally adding the
* black border, has width 'tilewidth'. Thus, the border does
* not affect the spacing between the image tiles. The
* maximum allowed border width is tilewidth / 5.
*/
PIX *
pixaDisplayTiledAndScaled(PIXA *pixa,
l_int32 outdepth,
l_int32 tilewidth,
l_int32 ncols,
l_int32 background,
l_int32 spacing,
l_int32 border)
{
l_int32 x, y, w, h, wd, hd, d;
l_int32 i, n, nrows, maxht, ninrow, irow, bordval;
l_int32 *rowht;
l_float32 scalefact;
PIX *pix, *pixn, *pixt, *pixb, *pixd;
PIXA *pixan;
PROCNAME("pixaDisplayTiledAndScaled");
if (!pixa)
return (PIX *)ERROR_PTR("pixa not defined", procName, NULL);
if (outdepth != 1 && outdepth != 8 && outdepth != 32)
return (PIX *)ERROR_PTR("outdepth not in {1, 8, 32}", procName, NULL);
if (border < 0 || border > tilewidth / 5)
border = 0;
if ((n = pixaGetCount(pixa)) == 0)
return (PIX *)ERROR_PTR("no components", procName, NULL);
/* Normalize scale and depth for each pix; optionally add border */
pixan = pixaCreate(n);
bordval = (outdepth == 1) ? 1 : 0;
for (i = 0; i < n; i++) {
if ((pix = pixaGetPix(pixa, i, L_CLONE)) == NULL)
continue;
pixGetDimensions(pix, &w, &h, &d);
scalefact = (l_float32)(tilewidth - 2 * border) / (l_float32)w;
if (d == 1 && outdepth > 1 && scalefact < 1.0)
pixt = pixScaleToGray(pix, scalefact);
else
pixt = pixScale(pix, scalefact, scalefact);
if (outdepth == 1)
pixn = pixConvertTo1(pixt, 128);
else if (outdepth == 8)
pixn = pixConvertTo8(pixt, FALSE);
else /* outdepth == 32 */
pixn = pixConvertTo32(pixt);
pixDestroy(&pixt);
if (border)
pixb = pixAddBorder(pixn, border, bordval);
else
pixb = pixClone(pixn);
pixaAddPix(pixan, pixb, L_INSERT);
pixDestroy(&pix);
pixDestroy(&pixn);
}
if ((n = pixaGetCount(pixan)) == 0) { /* should not have changed! */
pixaDestroy(&pixan);
return (PIX *)ERROR_PTR("no components", procName, NULL);
}
/* Determine the size of each row and of pixd */
wd = tilewidth * ncols + spacing * (ncols + 1);
nrows = (n + ncols - 1) / ncols;
if ((rowht = (l_int32 *)CALLOC(nrows, sizeof(l_int32))) == NULL)
return (PIX *)ERROR_PTR("rowht array not made", procName, NULL);
maxht = 0;
ninrow = 0;
irow = 0;
for (i = 0; i < n; i++) {
pix = pixaGetPix(pixan, i, L_CLONE);
ninrow++;
pixGetDimensions(pix, &w, &h, NULL);
maxht = L_MAX(h, maxht);
if (ninrow == ncols) {
//.........这里部分代码省略.........
示例14: SET_decode_ber
/*
* The decoder of the SET type.
*/
asn_dec_rval_t
SET_decode_ber(asn_codec_ctx_t *opt_codec_ctx, asn_TYPE_descriptor_t *td,
void **struct_ptr, const void *ptr, size_t size, int tag_mode) {
/*
* Bring closer parts of structure description.
*/
asn_SET_specifics_t *specs = (asn_SET_specifics_t *)td->specifics;
asn_TYPE_member_t *elements = td->elements;
/*
* Parts of the structure being constructed.
*/
void *st = *struct_ptr; /* Target structure. */
asn_struct_ctx_t *ctx; /* Decoder context */
ber_tlv_tag_t tlv_tag; /* T from TLV */
asn_dec_rval_t rval; /* Return code from subparsers */
ssize_t consumed_myself = 0; /* Consumed bytes from ptr */
int edx; /* SET element's index */
ASN_DEBUG("Decoding %s as SET", td->name);
if(_ASN_STACK_OVERFLOW_CHECK(opt_codec_ctx))
_ASN_DECODE_FAILED;
/*
* Create the target structure if it is not present already.
*/
if(st == 0) {
st = *struct_ptr = CALLOC(1, specs->struct_size);
if(st == 0) {
RETURN(RC_FAIL);
}
}
/*
* Restore parsing context.
*/
ctx = (asn_struct_ctx_t *)((char *)st + specs->ctx_offset);
/*
* Start to parse where left previously
*/
switch(ctx->phase) {
case 0:
/*
* PHASE 0.
* Check that the set of tags associated with given structure
* perfectly fits our expectations.
*/
rval = ber_check_tags(opt_codec_ctx, td, ctx, ptr, size,
tag_mode, 1, &ctx->left, 0);
if(rval.code != RC_OK) {
ASN_DEBUG("%s tagging check failed: %d",
td->name, rval.code);
return rval;
}
if(ctx->left >= 0)
ctx->left += rval.consumed; /* ?Substracted below! */
ADVANCE(rval.consumed);
NEXT_PHASE(ctx);
ASN_DEBUG("Structure advertised %ld bytes, "
"buffer contains %ld", (long)ctx->left, (long)size);
/* Fall through */
case 1:
/*
* PHASE 1.
* From the place where we've left it previously,
* try to decode the next member from the list of
* this structure's elements.
* Note that elements in BER may arrive out of
* order, yet DER mandates that they shall arive in the
* canonical order of their tags. So, there is a room
* for optimization.
*/
for(;; ctx->step = 0) {
asn_TYPE_tag2member_t *t2m;
asn_TYPE_tag2member_t key;
void *memb_ptr; /* Pointer to the member */
void **memb_ptr2; /* Pointer to that pointer */
ssize_t tag_len; /* Length of TLV's T */
if(ctx->step & 1) {
edx = ctx->step >> 1;
goto microphase2;
}
/*
* MICROPHASE 1: Synchronize decoding.
*/
//.........这里部分代码省略.........
示例15: return
/* Internal constructor. */
static Json *Json_new (void) {
return (Json*)CALLOC(Json, 1);
}