本文整理汇总了C++中pcalloc函数的典型用法代码示例。如果您正苦于以下问题:C++ pcalloc函数的具体用法?C++ pcalloc怎么用?C++ pcalloc使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了pcalloc函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: pcalloc
/* The difference between this function, and pr_cmd_alloc(), is that this
* allocates the cmd_rec directly from the given pool, whereas pr_cmd_alloc()
* will allocate a subpool from the given pool, and allocate its cmd_rec
* from the subpool. This means that pr_cmd_alloc()'s cmd_rec's can be
* subsequently destroyed easily; this function's cmd_rec's will be destroyed
* when the given pool is destroyed.
*/
static cmd_rec *make_cmd(pool *cp, int argc, ...) {
va_list args;
cmd_rec *c;
pool *sub_pool;
c = pcalloc(cp, sizeof(cmd_rec));
c->argc = argc;
c->stash_index = -1;
if (argc) {
register unsigned int i;
c->argv = pcalloc(cp, sizeof(void *) * (argc + 1));
va_start(args, argc);
for (i = 0; i < argc; i++) {
c->argv[i] = (void *) va_arg(args, char *);
}
va_end(args);
c->argv[argc] = NULL;
}
/* Make sure we provide pool and tmp_pool for the consumers. */
sub_pool = make_sub_pool(cp);
c->pool = c->tmp_pool = sub_pool;
return c;
}
开发者ID:Distrotech,项目名称:proftpd,代码行数:39,代码来源:auth.c
示例2: pcalloc
pr_buffer_t *pr_netio_buffer_alloc(pr_netio_stream_t *nstrm) {
size_t bufsz;
pr_buffer_t *pbuf = NULL;
if (nstrm == NULL) {
errno = EINVAL;
return NULL;
}
pbuf = pcalloc(nstrm->strm_pool, sizeof(pr_buffer_t));
/* Allocate a buffer. */
bufsz = pr_config_get_server_xfer_bufsz(nstrm->strm_mode);
pbuf->buf = pcalloc(nstrm->strm_pool, bufsz);
pbuf->buflen = bufsz;
/* Position the offset at the start of the buffer, and set the
* remaining bytes value accordingly.
*/
pbuf->current = pbuf->buf;
pbuf->remaining = bufsz;
/* Add this buffer to the given stream. */
nstrm->strm_buf = pbuf;
return pbuf;
}
开发者ID:Nubisa,项目名称:JXPanel,代码行数:27,代码来源:netio.c
示例3: pc_point_make
PCPOINT *
pc_point_make(const PCSCHEMA *s)
{
size_t sz;
PCPOINT *pt;
if ( ! s )
{
pcerror("null schema passed into pc_point_make");
return NULL;
}
/* Width of the data area */
sz = s->size;
if ( ! sz )
{
pcerror("invalid size calculation in pc_point_make");
return NULL;
}
/* Make our own data area */
pt = pcalloc(sizeof(PCPOINT));
pt->data = pcalloc(sz);
/* Set up basic info */
pt->schema = s;
pt->readonly = PC_FALSE;
return pt;
};
开发者ID:Shankarsetty,项目名称:pointcloud,代码行数:29,代码来源:pc_point.c
示例4: pc_point_from_double_array
PCPOINT *
pc_point_from_double_array(const PCSCHEMA *s, double *array, uint32_t nelems)
{
int i;
PCPOINT *pt;
if ( ! s )
{
pcerror("null schema passed into pc_point_from_double_array");
return NULL;
}
if ( s->ndims != nelems )
{
pcerror("number of elements in schema and array differ in pc_point_from_double_array");
return NULL;
}
/* Reference the external data */
pt = pcalloc(sizeof(PCPOINT));
pt->data = pcalloc(s->size);
pt->schema = s;
pt->readonly = PC_FALSE;
for ( i = 0; i < nelems; i++ )
{
if ( PC_FAILURE == pc_point_set_double_by_index(pt, i, array[i]) )
{
pcerror("failed to write value into dimension %d in pc_point_from_double_array", i);
return NULL;
}
}
return pt;
}
开发者ID:Shankarsetty,项目名称:pointcloud,代码行数:35,代码来源:pc_point.c
示例5: pcalloc
char *pr_utf8_encode(pool *p, const char *in, size_t inlen, size_t *outlen) {
#ifdef HAVE_ICONV_H
size_t inbuflen, outbuflen;
char *inbuf, outbuf[PR_TUNABLE_PATH_MAX*2], *res;
if (!p || !in || !outlen) {
errno = EINVAL;
return NULL;
}
if (encode_conv == (iconv_t) -1) {
errno = EPERM;
return NULL;
}
inbuf = pcalloc(p, inlen);
memcpy(inbuf, in, inlen);
inbuflen = inlen;
outbuflen = sizeof(outbuf);
if (utf8_convert(encode_conv, inbuf, &inbuflen, outbuf, &outbuflen) < 0)
return NULL;
*outlen = sizeof(outbuf) - outbuflen;
res = pcalloc(p, *outlen);
memcpy(res, outbuf, *outlen);
return res;
#else
pr_trace_msg("utf8", 1, "missing iconv support, no UTF8 encoding possible");
return pstrdup(p, in);
#endif /* !HAVE_ICONV_H */
}
开发者ID:Nakor78,项目名称:proftpd,代码行数:34,代码来源:utf8.c
示例6: pc_patch_dimensional_compress
PCPATCH_DIMENSIONAL *
pc_patch_dimensional_compress(const PCPATCH_DIMENSIONAL *pdl, PCDIMSTATS *pds)
{
int i;
int ndims = pdl->schema->ndims;
PCPATCH_DIMENSIONAL *pdl_compressed;
assert(pdl);
assert(pdl->schema);
if ( ! pds )
pds = pc_dimstats_make(pdl->schema);
/* Still sampling, update stats */
if ( pds->total_points < PCDIMSTATS_MIN_SAMPLE )
pc_dimstats_update(pds, pdl);
pdl_compressed = pcalloc(sizeof(PCPATCH_DIMENSIONAL));
memcpy(pdl_compressed, pdl, sizeof(PCPATCH_DIMENSIONAL));
pdl_compressed->bytes = pcalloc(ndims*sizeof(PCBYTES));
/* Compress each dimension as dictated by stats */
for ( i = 0; i < ndims; i++ )
{
pdl_compressed->bytes[i] = pc_bytes_encode(pdl->bytes[i], pds->stats[i].recommended_compression);
}
return pdl_compressed;
}
开发者ID:Remi-C,项目名称:pointcloud,代码行数:29,代码来源:pc_patch_dimensional.c
示例7: PR_ERROR_MSG
/*
* _build_data: both cmd_select and cmd_procedure potentially
* return data to mod_sql; this function builds a modret to return
* that data. This is Postgres specific; other backends may choose
* to do things differently.
*/
static modret_t *_build_data(cmd_rec *cmd, db_conn_t *conn) {
PGresult *result = NULL;
sql_data_t *sd = NULL;
char **data = NULL;
int index = 0;
int field = 0;
int row =0;
if (!conn)
return PR_ERROR_MSG(cmd, MOD_SQL_POSTGRES_VERSION, "badly formed request");
result = conn->result;
sd = (sql_data_t *) pcalloc(cmd->tmp_pool, sizeof(sql_data_t));
sd->rnum = (unsigned long) PQntuples(result);
sd->fnum = (unsigned long) PQnfields(result);
data = (char **) pcalloc(cmd->tmp_pool, sizeof(char *) *
((sd->rnum * sd->fnum) + 1));
for (row = 0; row < sd->rnum; row++) {
for (field = 0; field < sd->fnum; field++) {
data[index++] = pstrdup(cmd->tmp_pool, PQgetvalue(result, row, field));
}
}
data[index] = NULL;
sd->data = data;
return mod_create_data( cmd, (void *) sd );
}
开发者ID:Distrotech,项目名称:proftpd,代码行数:37,代码来源:mod_sql_postgres.c
示例8: pool_create
void *new_obj(pool_t *mpool, size_t sz)
{
pool_t *mp = mpool;
obj_t *ob = NULL;
if (mp == NULL) {
mp = pool_create(G_MPOOL_SIZE);
if (mp == NULL) {
return NULL;
}
ob = (obj_t *)pcalloc(mp, sz);
if (ob == NULL) {
pool_destroy(mp);
return NULL;
}
ob->new_mp_flag = 1;
} else {
ob = pcalloc(mp, sz);
if (ob == NULL) {
return NULL;
}
ob->new_mp_flag = 0;
}
ob->mpool = mp;
return ob;
}
开发者ID:joerong666,项目名称:hidb,代码行数:30,代码来源:obj.c
示例9: parse_cgi
int
parse_cgi(epoll_cgi_t *cgi)
{
list_buffer *cgi_data, *send;
buffer *b;
char *p;
int count;
buffer *header, *out, *tmp;
cgi_data = cgi->cgi_data;
if(cgi_data == NULL || cgi_data->b == NULL || cgi_data->b->ptr == NULL || cgi_data->b->size == 0) return 0;
b = cgi_data->b;
send = (list_buffer *) pcalloc(cgi->con->p, sizeof(list_buffer));
header = (buffer *) pcalloc(cgi->con->p, sizeof(buffer));
cgi->con->out->status_code = HTTP_OK;
p = strstr(b->ptr,"\n\n");
if(p != NULL && (p-b->ptr) < b->size) {
buffer_n_to_lower(b, (p-b->ptr)+1);
header->ptr = b->ptr;
header->size = (p-b->ptr) + 2;
tmp = (buffer *) pcalloc(cgi->con->p, sizeof(buffer));
buffer_find_str(header, tmp, "content-type:");
if(tmp->ptr == NULL) {
send_bad_gateway(cgi->con->fd);
return 1;
}
p = tmp->ptr + tmp->size;
while(*p == ' ') p++;
tmp->ptr = p;
p = strchr(p, '\n');
count = p - tmp->ptr ;
if(*(p-1) != '\r' ) count++;
tmp->size = count;
cgi->con->out->content_type = buffer_create_size(cgi->con->p, count);
cgi->con->out->content_type->size = count;
strncpy(cgi->con->out->content_type->ptr, tmp->ptr, count -1);
cgi->con->out->content_type->ptr[count-1] = 0;
out = (buffer *)pcalloc(cgi->con->p, sizeof(buffer));
out->ptr = header->ptr + header->size;
out->size = b->size - header->size;
send->b = out;
send->next = cgi_data->next;
cgi->out = send;
}
}
开发者ID:rentiansheng,项目名称:rhttp,代码行数:59,代码来源:http_request.c
示例10: bytebuffer_new
static bytebuffer_t *
bytebuffer_new(void)
{
bytebuffer_t *bb = pcalloc(sizeof(bytebuffer_t));
bb->sz = 1024;
bb->buf = pcalloc(bb->sz*sizeof(uint8_t));
bb->ptr = bb->buf;
}
开发者ID:gijs,项目名称:pointcloud,代码行数:8,代码来源:pc_util.c
示例11: pc_bitmap_new
PCBITMAP *
pc_bitmap_new(uint32_t npoints)
{
PCBITMAP *map = pcalloc(sizeof(PCBITMAP));
map->map = pcalloc(sizeof(uint8_t)*npoints);
map->npoints = npoints;
map->nset = 0;
return map;
}
开发者ID:ghelobytes,项目名称:pointcloud,代码行数:9,代码来源:pc_filter.c
示例12: pc_pointlist_make
PCPOINTLIST *
pc_pointlist_make(uint32_t npoints)
{
PCPOINTLIST *pl = pcalloc(sizeof(PCPOINTLIST));
pl->points = pcalloc(sizeof(PCPOINT*) * npoints);
pl->maxpoints = npoints;
pl->npoints = 0;
pl->mem = NULL;
return pl;
}
开发者ID:LI3DS,项目名称:pointcloud,代码行数:10,代码来源:pc_pointlist.c
示例13: pc_patch_dimensional_clone
PCPATCH_DIMENSIONAL *
pc_patch_dimensional_clone(const PCPATCH_DIMENSIONAL *patch)
{
PCPATCH_DIMENSIONAL *pdl = pcalloc(sizeof(PCPATCH_DIMENSIONAL));
memcpy(pdl, patch, sizeof(PCPATCH_DIMENSIONAL));
pdl->bytes = pcalloc(patch->schema->ndims * sizeof(PCBYTES));
pdl->npoints = 0;
pdl->stats = NULL;
return pdl;
}
开发者ID:Remi-C,项目名称:pointcloud,代码行数:10,代码来源:pc_patch_dimensional.c
示例14: pc_pointlist_make
PCPOINTLIST *
pc_pointlist_make(uint32_t npoints)
{
PCPOINTLIST *pl = pcalloc(sizeof(PCPOINTLIST));
pl->points = pcalloc(sizeof(PCPOINT*) * npoints);
pl->maxpoints = npoints;
pl->npoints = 0;
pl->readonly = PC_FALSE;
return pl;
}
开发者ID:Remi-C,项目名称:pointcloud,代码行数:10,代码来源:pc_pointlist.c
示例15: pc_schema_new
static PCSCHEMA*
pc_schema_new(uint32_t ndims)
{
PCSCHEMA *pcs = pcalloc(sizeof(PCSCHEMA));
pcs->dims = pcalloc(sizeof(PCDIMENSION*) * ndims);
pcs->namehash = create_string_hashtable();
pcs->ndims = ndims;
pcs->x_position = -1;
pcs->y_position = -1;
return pcs;
}
开发者ID:kjartab,项目名称:pointcloud,代码行数:11,代码来源:pc_schema.c
示例16: strcasecmp
char *pr_encode_str(pool *p, const char *in, size_t inlen, size_t *outlen) {
#ifdef HAVE_ICONV
size_t inbuflen, outbuflen, outbufsz;
char *inbuf, outbuf[PR_TUNABLE_PATH_MAX*2], *res;
if (p == NULL ||
in == NULL ||
outlen == NULL) {
errno = EINVAL;
return NULL;
}
/* If the local charset matches the remote charset, then there's no point
* in converting; the charsets are the same. Indeed, on some libiconv
* implementations, attempting to convert between the same charsets results
* in a tightly spinning CPU (see Bug#3272).
*/
if (local_charset != NULL &&
encoding != NULL &&
strcasecmp(local_charset, encoding) == 0) {
return pstrdup(p, in);
}
if (encode_conv == (iconv_t) -1) {
pr_trace_msg(trace_channel, 1, "invalid encoding conversion handle, "
"unable to encode string");
return pstrdup(p, in);
}
inbuf = pcalloc(p, inlen);
memcpy(inbuf, in, inlen);
inbuflen = inlen;
outbuflen = sizeof(outbuf);
if (str_convert(encode_conv, inbuf, &inbuflen, outbuf, &outbuflen) < 0)
return NULL;
*outlen = sizeof(outbuf) - outbuflen;
/* We allocate one byte more, for a terminating NUL. */
outbufsz = sizeof(outbuf) - outbuflen + 1;
res = pcalloc(p, outbufsz);
memcpy(res, outbuf, *outlen);
return res;
#else
pr_trace_msg(trace_channel, 1,
"missing iconv support, no %s encoding possible", encoding);
return pstrdup(p, in);
#endif /* !HAVE_ICONV */
}
开发者ID:Distrotech,项目名称:proftpd,代码行数:53,代码来源:encode.c
示例17: run_accept
void run_accept(struct server* server) {
static int one = 1;
struct timeval timeout;
timeout.tv_sec = 60;
timeout.tv_usec = 0;
struct pollfd spfd;
spfd.events = POLLIN;
spfd.revents = 0;
spfd.fd = server->fd;
while (1) {
struct mempool* pool = mempool_new();
struct connection* conn = pcalloc(pool, sizeof(struct connection));
conn->pool = pool;
conn->addrlen = sizeof(struct sockaddr_in6);
conn->managed_conn = pcalloc(conn->pool, sizeof(struct netmgr_connection));
conn->managed_conn->pool = conn->pool;
conn->managed_conn->extra = conn;
conn->compression_state = -1;
conn->server = server;
buffer_init(&conn->managed_conn->read_buffer, conn->pool);
buffer_init(&conn->managed_conn->write_buffer, conn->pool);
if (poll(&spfd, 1, -1) < 0) {
printf("Error while polling server: %s\n", strerror(errno));
pfree(pool);
continue;
}
if ((spfd.revents ^ POLLIN) != 0) {
printf("Error after polling server: %i (poll revents)!\n", spfd.revents);
pfree(pool);
break;
}
spfd.revents = 0;
int fd = accept(server->fd, (struct sockaddr*) &conn->addr, &conn->addrlen);
if (fd < 0) {
if (errno == EAGAIN) continue;
printf("Error while accepting client: %s\n", strerror(errno));
pfree(pool);
continue;
}
conn->managed_conn->fd = fd;
if (setsockopt(fd, SOL_SOCKET, SO_RCVTIMEO, (char *) &timeout, sizeof(timeout))) printf("Setting recv timeout failed! %s\n", strerror(errno));
if (setsockopt(fd, SOL_SOCKET, SO_SNDTIMEO, (char *) &timeout, sizeof(timeout))) printf("Setting send timeout failed! %s\n", strerror(errno));
if (setsockopt(fd, IPPROTO_TCP, TCP_NODELAY, (void *) &one, sizeof(one))) printf("Setting TCP_NODELAY failed! %s\n", strerror(errno));
if (fcntl(fd, F_SETFL, fcntl(fd, F_GETFL) | O_NONBLOCK) < 0) {
printf("Setting O_NONBLOCK failed! %s, this error cannot be recovered, closing client.\n", strerror(errno));
close(fd);
continue;
}
queue_push(server->prepared_connections, conn);
}
pthread_cancel (pthread_self());
}
开发者ID:JavaProphet,项目名称:Basin,代码行数:52,代码来源:accept.c
示例18: pc_patch_uncompressed_from_wkb
PCPATCH *
pc_patch_uncompressed_from_wkb(const PCSCHEMA *s, const uint8_t *wkb, size_t wkbsize)
{
/*
byte: endianness (1 = NDR, 0 = XDR)
uint32: pcid (key to POINTCLOUD_SCHEMAS)
uint32: compression (0 = no compression, 1 = dimensional, 2 = lazperf)
uint32: npoints
pcpoint[]: data (interpret relative to pcid)
*/
static size_t hdrsz = 1+4+4+4; /* endian + pcid + compression + npoints */
PCPATCH_UNCOMPRESSED *patch;
uint8_t *data;
uint8_t swap_endian = (wkb[0] != machine_endian());
uint32_t npoints;
if ( wkb_get_compression(wkb) != PC_NONE )
{
pcerror("%s: call with wkb that is not uncompressed", __func__);
return NULL;
}
npoints = wkb_get_npoints(wkb);
if ( (wkbsize - hdrsz) != (s->size * npoints) )
{
pcerror("%s: wkb size and expected data size do not match", __func__);
return NULL;
}
if ( swap_endian )
{
data = uncompressed_bytes_flip_endian(wkb+hdrsz, s, npoints);
}
else
{
data = pcalloc(npoints * s->size);
memcpy(data, wkb+hdrsz, npoints*s->size);
}
patch = pcalloc(sizeof(PCPATCH_UNCOMPRESSED));
patch->type = PC_NONE;
patch->readonly = PC_FALSE;
patch->schema = s;
patch->npoints = npoints;
patch->maxpoints = npoints;
patch->datasize = (wkbsize - hdrsz);
patch->data = data;
patch->stats = NULL;
return (PCPATCH*)patch;
}
开发者ID:mbredif,项目名称:pointcloud,代码行数:51,代码来源:pc_patch_uncompressed.c
示例19: pc_patch_dimensional_deserialize
static PCPATCH *
pc_patch_dimensional_deserialize(const SERIALIZED_PATCH *serpatch, const PCSCHEMA *schema)
{
// typedef struct
// {
// uint32_t size;
// uint32_t pcid;
// uint32_t compression;
// uint32_t npoints;
// double xmin, xmax, ymin, ymax;
// data:
// pcpoint[3] pcstats(min, max, avg)
// pcbytes[ndims];
// }
// SERIALIZED_PATCH;
PCPATCH_DIMENSIONAL *patch;
int i;
const uint8_t *buf;
int ndims = schema->ndims;
int npoints = serpatch->npoints;
size_t stats_size = pc_stats_size(schema); // 3 pcpoints worth of stats
/* Reference the external data */
patch = pcalloc(sizeof(PCPATCH_DIMENSIONAL));
/* Set up basic info */
patch->type = serpatch->compression;
patch->schema = schema;
patch->readonly = true;
patch->npoints = npoints;
patch->bounds = serpatch->bounds;
/* Point into the stats area */
patch->stats = pc_patch_stats_deserialize(schema, serpatch->data);
/* Set up dimensions */
patch->bytes = pcalloc(ndims * sizeof(PCBYTES));
buf = serpatch->data + stats_size;
for ( i = 0; i < ndims; i++ )
{
PCBYTES *pcb = &(patch->bytes[i]);
PCDIMENSION *dim = schema->dims[i];
pc_bytes_deserialize(buf, dim, pcb, true /*readonly*/, false /*flipendian*/);
pcb->npoints = npoints;
buf += pc_bytes_serialized_size(pcb);
}
return (PCPATCH*)patch;
}
开发者ID:Remi-C,项目名称:pointcloud,代码行数:51,代码来源:pc_pgsql.c
示例20: pc_patch_ght_from_wkb
PCPATCH *
pc_patch_ght_from_wkb(const PCSCHEMA *schema, const uint8_t *wkb, size_t wkbsize)
{
#ifndef HAVE_LIBGHT
pcerror("%s: libght support is not enabled", __func__);
return NULL;
#else
/*
byte: endianness (1 = NDR, 0 = XDR)
uint32: pcid (key to POINTCLOUD_SCHEMAS)
uint32: compression (0 = no compression, 1 = dimensional, 2 = GHT)
uint32: npoints
uint32: ghtsize
uint8[]: ghtbuffer
*/
static size_t hdrsz = 1+4+4+4; /* endian + pcid + compression + npoints */
PCPATCH_GHT *patch;
uint8_t swap_endian = (wkb[0] != machine_endian());
uint32_t npoints;
size_t ghtsize;
const uint8_t *buf;
if ( wkb_get_compression(wkb) != PC_GHT )
{
pcerror("%s: call with wkb that is not GHT compressed", __func__);
return NULL;
}
npoints = wkb_get_npoints(wkb);
patch = pcalloc(sizeof(PCPATCH_GHT));
patch->type = PC_GHT;
patch->readonly = PC_FALSE;
patch->schema = schema;
patch->npoints = npoints;
/* Start on the GHT */
buf = wkb+hdrsz;
ghtsize = wkb_get_int32(buf, swap_endian);
buf += 4; /* Move to start of GHT buffer */
/* Copy in the tree buffer */
patch->ght = pcalloc(ghtsize);
patch->ghtsize = ghtsize;
memcpy(patch->ght, buf, ghtsize);
return (PCPATCH*)patch;
#endif
}
开发者ID:cyrilleberger,项目名称:pointcloud,代码行数:49,代码来源:pc_patch_ght.c
注:本文中的pcalloc函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论