本文整理汇总了C++中repalloc函数的典型用法代码示例。如果您正苦于以下问题:C++ repalloc函数的具体用法?C++ repalloc怎么用?C++ repalloc使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了repalloc函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: ResourceOwnerEnlargePreparedStmts
/*
* Make sure there is room for at least one more entry in a ResourceOwner's
* prepared statements reference array.
*
* This is separate from actually inserting an entry because if we run out
* of memory, it's critical to do so *before* acquiring the resource.
*/
void
ResourceOwnerEnlargePreparedStmts(ResourceOwner owner)
{
int newmax;
if (owner->nstmts < owner->maxstmts)
return; /* nothing to do */
if (owner->stmts == NULL)
{
newmax = 16;
owner->stmts = (char *)
MemoryContextAlloc(TopMemoryContext, newmax * CNAME_MAXLEN);
owner->maxstmts = newmax;
}
else
{
newmax = owner->maxstmts * 2;
owner->stmts = (char *)
repalloc(owner->stmts, newmax * CNAME_MAXLEN);
owner->maxstmts = newmax;
}
}
开发者ID:techdragon,项目名称:Postgres-XL,代码行数:30,代码来源:resowner.c
示例2: ResourceOwnerEnlargeTupleDescs
/*
* Make sure there is room for at least one more entry in a ResourceOwner's
* tupdesc reference array.
*
* This is separate from actually inserting an entry because if we run out
* of memory, it's critical to do so *before* acquiring the resource.
*/
void
ResourceOwnerEnlargeTupleDescs(ResourceOwner owner)
{
int newmax;
if (owner->ntupdescs < owner->maxtupdescs)
return; /* nothing to do */
if (owner->tupdescs == NULL)
{
newmax = 16;
owner->tupdescs = (TupleDesc *)
MemoryContextAlloc(TopMemoryContext, newmax * sizeof(TupleDesc));
owner->maxtupdescs = newmax;
}
else
{
newmax = owner->maxtupdescs * 2;
owner->tupdescs = (TupleDesc *)
repalloc(owner->tupdescs, newmax * sizeof(TupleDesc));
owner->maxtupdescs = newmax;
}
}
开发者ID:leckie711,项目名称:incubator-hawq,代码行数:30,代码来源:resowner.c
示例3: ResourceOwnerEnlargeCatCacheListRefs
/*
* Make sure there is room for at least one more entry in a ResourceOwner's
* catcache-list reference array.
*
* This is separate from actually inserting an entry because if we run out
* of memory, it's critical to do so *before* acquiring the resource.
*/
void
ResourceOwnerEnlargeCatCacheListRefs(ResourceOwner owner)
{
int newmax;
if (owner->ncatlistrefs < owner->maxcatlistrefs)
return; /* nothing to do */
if (owner->catlistrefs == NULL)
{
newmax = 16;
owner->catlistrefs = (CatCList **)
MemoryContextAlloc(TopMemoryContext, newmax * sizeof(CatCList *));
owner->maxcatlistrefs = newmax;
}
else
{
newmax = owner->maxcatlistrefs * 2;
owner->catlistrefs = (CatCList **)
repalloc(owner->catlistrefs, newmax * sizeof(CatCList *));
owner->maxcatlistrefs = newmax;
}
}
开发者ID:leckie711,项目名称:incubator-hawq,代码行数:30,代码来源:resowner.c
示例4: ResourceOwnerEnlargeRelationRefs
/*
* Make sure there is room for at least one more entry in a ResourceOwner's
* relcache reference array.
*
* This is separate from actually inserting an entry because if we run out
* of memory, it's critical to do so *before* acquiring the resource.
*/
void
ResourceOwnerEnlargeRelationRefs(ResourceOwner owner)
{
int newmax;
if (owner->nrelrefs < owner->maxrelrefs)
return; /* nothing to do */
if (owner->relrefs == NULL)
{
newmax = 16;
owner->relrefs = (Relation *)
MemoryContextAlloc(TopMemoryContext, newmax * sizeof(Relation));
owner->maxrelrefs = newmax;
}
else
{
newmax = owner->maxrelrefs * 2;
owner->relrefs = (Relation *)
repalloc(owner->relrefs, newmax * sizeof(Relation));
owner->maxrelrefs = newmax;
}
}
开发者ID:leckie711,项目名称:incubator-hawq,代码行数:30,代码来源:resowner.c
示例5: ResourceOwnerEnlargeFiles
/*
* Make sure there is room for at least one more entry in a ResourceOwner's
* files reference array.
*
* This is separate from actually inserting an entry because if we run out
* of memory, it's critical to do so *before* acquiring the resource.
*/
void
ResourceOwnerEnlargeFiles(ResourceOwner owner)
{
int newmax;
if (owner->nfiles < owner->maxfiles)
return; /* nothing to do */
if (owner->files == NULL)
{
newmax = 16;
owner->files = (File *)
MemoryContextAlloc(TopMemoryContext, newmax * sizeof(File));
owner->maxfiles = newmax;
}
else
{
newmax = owner->maxfiles * 2;
owner->files = (File *)
repalloc(owner->files, newmax * sizeof(File));
owner->maxfiles = newmax;
}
}
开发者ID:KMU-embedded,项目名称:mosbench-ext,代码行数:30,代码来源:resowner.c
示例6: ResourceOwnerEnlargePlanCacheRefs
/*
* Make sure there is room for at least one more entry in a ResourceOwner's
* plancache reference array.
*
* This is separate from actually inserting an entry because if we run out
* of memory, it's critical to do so *before* acquiring the resource.
*/
void
ResourceOwnerEnlargePlanCacheRefs(ResourceOwner owner)
{
int newmax;
if (owner->nplanrefs < owner->maxplanrefs)
return; /* nothing to do */
if (owner->planrefs == NULL)
{
newmax = 16;
owner->planrefs = (CachedPlan **)
MemoryContextAlloc(TopMemoryContext, newmax * sizeof(CachedPlan *));
owner->maxplanrefs = newmax;
}
else
{
newmax = owner->maxplanrefs * 2;
owner->planrefs = (CachedPlan **)
repalloc(owner->planrefs, newmax * sizeof(CachedPlan *));
owner->maxplanrefs = newmax;
}
}
开发者ID:KMU-embedded,项目名称:mosbench-ext,代码行数:30,代码来源:resowner.c
示例7: ResourceOwnerEnlargeSnapshots
/*
* Make sure there is room for at least one more entry in a ResourceOwner's
* snapshot reference array.
*
* This is separate from actually inserting an entry because if we run out
* of memory, it's critical to do so *before* acquiring the resource.
*/
void
ResourceOwnerEnlargeSnapshots(ResourceOwner owner)
{
int newmax;
if (owner->nsnapshots < owner->maxsnapshots)
return; /* nothing to do */
if (owner->snapshots == NULL)
{
newmax = 16;
owner->snapshots = (Snapshot *)
MemoryContextAlloc(TopMemoryContext, newmax * sizeof(Snapshot));
owner->maxsnapshots = newmax;
}
else
{
newmax = owner->maxsnapshots * 2;
owner->snapshots = (Snapshot *)
repalloc(owner->snapshots, newmax * sizeof(Snapshot));
owner->maxsnapshots = newmax;
}
}
开发者ID:techdragon,项目名称:Postgres-XL,代码行数:30,代码来源:resowner.c
示例8: finalizeForecastModel
/*
* finalizeForecastModel
*
* no more input tuples to read
*/
void
finalizeForecastModel(ModelInfo *model)
{
int length = 0;
FunctionCall1(&(model->algInfo->algFinalizeForecastModel),PointerGetDatum(model->model));
length = model->model->trainingTupleCount;
//MEASURE-CHANGE
// length=20;
if (model->upperBound==0) {
if(((int)(length*0.1))<1)
model->lowerBound = 1;
else
model->lowerBound = (((int)(length*0.1)));
//XXX: CHANGE FOR MESURING
if(!model->errorArray){
if(((int)(length*0.1))<2)
model->errorArray = palloc0(2*sizeof(double));
else
model->errorArray = palloc0(((int)(length*0.1))*sizeof(double));
}
else
if(model->upperBound < ((int)(length*0.1))){
model->errorArray = repalloc(model->errorArray, ((int)(length*0.1))*sizeof(double));
model->errorArray[((int)(length*0.1))-1] = 0.0;
}
if(((int)(length*0.1))<2)
model->upperBound = 2;
else
model->upperBound = ((int)(length*0.1));
}
}
开发者ID:Khalefa,项目名称:Miracle,代码行数:42,代码来源:algorithm.c
示例9: istore_pairs_insert
/*
* insert key value to IStorePairs
*/
void
istore_pairs_insert(IStorePairs *pairs, int32 key, int32 val)
{
if (pairs->size == pairs->used)
{
if (pairs->used == PAIRS_MAX(IStorePair))
elog(ERROR, "istore can't have more than %lu keys", PAIRS_MAX(IStorePair));
pairs->size *= 2;
// overflow check pairs->size should have been grown but not exceed PAIRS_MAX(IStorePair)
if (pairs->size < pairs->used || pairs->size > PAIRS_MAX(IStorePair))
pairs->size = PAIRS_MAX(IStorePair);
pairs->pairs = repalloc(pairs->pairs, pairs->size * sizeof(IStorePair));
}
pairs->pairs[pairs->used].key = key;
pairs->pairs[pairs->used].val = val;
pairs->buflen += digits32(key) + digits32(val) + BUFLEN_OFFSET;
if (pairs->buflen < 0)
elog(ERROR, "istore buffer overflow");
pairs->used++;
}
开发者ID:adjust,项目名称:istore,代码行数:27,代码来源:pairs.c
示例10: ginInsertData
/*
* Stores heap item pointer. For robust, it checks that
* item pointer are ordered
*/
static void
ginInsertData(BuildAccumulator *accum, EntryAccumulator *entry, ItemPointer heapptr)
{
if (entry->number >= entry->length)
{
accum->allocatedMemory += sizeof(ItemPointerData) * entry->length;
entry->length *= 2;
entry->list = (ItemPointerData *) repalloc(entry->list,
sizeof(ItemPointerData) * entry->length);
}
if (entry->shouldSort == FALSE)
{
int res = compareItemPointers(entry->list + entry->number - 1, heapptr);
Assert(res != 0);
if (res > 0)
entry->shouldSort = TRUE;
}
entry->list[entry->number] = *heapptr;
entry->number++;
}
开发者ID:qiuyesuifeng,项目名称:gpdb,代码行数:28,代码来源:ginbulk.c
示例11: add_gin_entry
/* Add new entry to GinEntries */
static int
add_gin_entry(GinEntries *entries, Datum entry)
{
int id = entries->count;
if (entries->count >= entries->allocated)
{
if (entries->allocated)
{
entries->allocated *= 2;
entries->buf = repalloc(entries->buf,
sizeof(Datum) * entries->allocated);
}
else
{
entries->allocated = 8;
entries->buf = palloc(sizeof(Datum) * entries->allocated);
}
}
entries->buf[entries->count++] = entry;
return id;
}
开发者ID:davidfetter,项目名称:postgresql_projects,代码行数:25,代码来源:jsonb_gin.c
示例12: MakeSharedInvalidMessagesArray
/*
* Collect invalidation messages into SharedInvalidMessagesArray array.
*/
static void
MakeSharedInvalidMessagesArray(const SharedInvalidationMessage *msgs, int n)
{
/*
* Initialise array first time through in each commit
*/
if (SharedInvalidMessagesArray == NULL)
{
maxSharedInvalidMessagesArray = FIRSTCHUNKSIZE;
numSharedInvalidMessagesArray = 0;
/*
* Although this is being palloc'd we don't actually free it directly.
* We're so close to EOXact that we now we're going to lose it anyhow.
*/
SharedInvalidMessagesArray = palloc(maxSharedInvalidMessagesArray
* sizeof(SharedInvalidationMessage));
}
if ((numSharedInvalidMessagesArray + n) > maxSharedInvalidMessagesArray)
{
while ((numSharedInvalidMessagesArray + n) > maxSharedInvalidMessagesArray)
maxSharedInvalidMessagesArray *= 2;
SharedInvalidMessagesArray = repalloc(SharedInvalidMessagesArray,
maxSharedInvalidMessagesArray
* sizeof(SharedInvalidationMessage));
}
/*
* Append the next chunk onto the array
*/
memcpy(SharedInvalidMessagesArray + numSharedInvalidMessagesArray,
msgs, n * sizeof(SharedInvalidationMessage));
numSharedInvalidMessagesArray += n;
}
开发者ID:AXLEproject,项目名称:postgres,代码行数:39,代码来源:inval.c
示例13: ResourceOwnerEnlargeDSMs
/*
* Make sure there is room for at least one more entry in a ResourceOwner's
* dynamic shmem segment reference array.
*
* This is separate from actually inserting an entry because if we run out
* of memory, it's critical to do so *before* acquiring the resource.
*/
void
ResourceOwnerEnlargeDSMs(ResourceOwner owner)
{
int newmax;
if (owner->ndsms < owner->maxdsms)
return; /* nothing to do */
if (owner->dsms == NULL)
{
newmax = 16;
owner->dsms = (dsm_segment **)
MemoryContextAlloc(TopMemoryContext,
newmax * sizeof(dsm_segment *));
owner->maxdsms = newmax;
}
else
{
newmax = owner->maxdsms * 2;
owner->dsms = (dsm_segment **)
repalloc(owner->dsms, newmax * sizeof(dsm_segment *));
owner->maxdsms = newmax;
}
}
开发者ID:42penguins,项目名称:postgres,代码行数:31,代码来源:resowner.c
示例14: ResourceOwnerEnlargeBuffers
/*
* Make sure there is room for at least one more entry in a ResourceOwner's
* buffer array.
*
* This is separate from actually inserting an entry because if we run out
* of memory, it's critical to do so *before* acquiring the resource.
*
* We allow the case owner == NULL because the bufmgr is sometimes invoked
* outside any transaction (for example, during WAL recovery).
*/
void
ResourceOwnerEnlargeBuffers(ResourceOwner owner)
{
int newmax;
if (owner == NULL ||
owner->nbuffers < owner->maxbuffers)
return; /* nothing to do */
if (owner->buffers == NULL)
{
newmax = 16;
owner->buffers = (Buffer *)
MemoryContextAlloc(TopMemoryContext, newmax * sizeof(Buffer));
owner->maxbuffers = newmax;
}
else
{
newmax = owner->maxbuffers * 2;
owner->buffers = (Buffer *)
repalloc(owner->buffers, newmax * sizeof(Buffer));
owner->maxbuffers = newmax;
}
}
开发者ID:lhcezar,项目名称:postgres,代码行数:34,代码来源:resowner.c
示例15: pgss_shmem_startup
//.........这里部分代码省略.........
memset(&info, 0, sizeof(info));
info.keysize = sizeof(pgssHashKey);
info.entrysize = offsetof(pgssEntry, query) +query_size;
info.hash = pgss_hash_fn;
info.match = pgss_match_fn;
pgss_hash = ShmemInitHash("pg_stat_statements hash",
pgss_max, pgss_max,
&info,
HASH_ELEM | HASH_FUNCTION | HASH_COMPARE);
LWLockRelease(AddinShmemInitLock);
/*
* If we're in the postmaster (or a standalone backend...), set up a shmem
* exit hook to dump the statistics to disk.
*/
if (!IsUnderPostmaster)
on_shmem_exit(pgss_shmem_shutdown, (Datum) 0);
/*
* Attempt to load old statistics from the dump file, if this is the first
* time through and we weren't told not to.
*/
if (found || !pgss_save)
return;
/*
* Note: we don't bother with locks here, because there should be no other
* processes running when this code is reached.
*/
file = AllocateFile(PGSS_DUMP_FILE, PG_BINARY_R);
if (file == NULL)
{
if (errno == ENOENT)
return; /* ignore not-found error */
goto error;
}
buffer_size = query_size;
buffer = (char *) palloc(buffer_size);
if (fread(&header, sizeof(uint32), 1, file) != 1 ||
header != PGSS_FILE_HEADER ||
fread(&num, sizeof(int32), 1, file) != 1)
goto error;
for (i = 0; i < num; i++)
{
pgssEntry temp;
pgssEntry *entry;
if (fread(&temp, offsetof(pgssEntry, mutex), 1, file) != 1)
goto error;
/* Encoding is the only field we can easily sanity-check */
if (!PG_VALID_BE_ENCODING(temp.key.encoding))
goto error;
/* Previous incarnation might have had a larger query_size */
if (temp.key.query_len >= buffer_size)
{
buffer = (char *) repalloc(buffer, temp.key.query_len + 1);
buffer_size = temp.key.query_len + 1;
}
if (fread(buffer, 1, temp.key.query_len, file) != temp.key.query_len)
goto error;
buffer[temp.key.query_len] = '\0';
/* Clip to available length if needed */
if (temp.key.query_len >= query_size)
temp.key.query_len = pg_encoding_mbcliplen(temp.key.encoding,
buffer,
temp.key.query_len,
query_size - 1);
temp.key.query_ptr = buffer;
/* make the hashtable entry (discards old entries if too many) */
entry = entry_alloc(&temp.key);
/* copy in the actual stats */
entry->counters = temp.counters;
}
pfree(buffer);
FreeFile(file);
return;
error:
ereport(LOG,
(errcode_for_file_access(),
errmsg("could not read pg_stat_statement file \"%s\": %m",
PGSS_DUMP_FILE)));
if (buffer)
pfree(buffer);
if (file)
FreeFile(file);
/* If possible, throw away the bogus file; ignore any error */
unlink(PGSS_DUMP_FILE);
}
开发者ID:HBPSP8Repo,项目名称:NoDB,代码行数:101,代码来源:pg_stat_statements.c
示例16: GinFormTuple
/*
* Form a tuple for entry tree.
*
* If the tuple would be too big to be stored, function throws a suitable
* error if errorTooBig is TRUE, or returns NULL if errorTooBig is FALSE.
*
* See src/backend/access/gin/README for a description of the index tuple
* format that is being built here. We build on the assumption that we
* are making a leaf-level key entry containing a posting list of nipd items.
* If the caller is actually trying to make a posting-tree entry, non-leaf
* entry, or pending-list entry, it should pass dataSize = 0 and then overwrite
* the t_tid fields as necessary. In any case, 'data' can be NULL to skip
* filling in the posting list; the caller is responsible for filling it
* afterwards if data = NULL and nipd > 0.
*/
IndexTuple
GinFormTuple(GinState *ginstate,
OffsetNumber attnum, Datum key, GinNullCategory category,
Pointer data, Size dataSize, int nipd,
bool errorTooBig)
{
Datum datums[2];
bool isnull[2];
IndexTuple itup;
uint32 newsize;
/* Build the basic tuple: optional column number, plus key datum */
if (ginstate->oneCol)
{
datums[0] = key;
isnull[0] = (category != GIN_CAT_NORM_KEY);
}
else
{
datums[0] = UInt16GetDatum(attnum);
isnull[0] = false;
datums[1] = key;
isnull[1] = (category != GIN_CAT_NORM_KEY);
}
itup = index_form_tuple(ginstate->tupdesc[attnum - 1], datums, isnull);
/*
* Determine and store offset to the posting list, making sure there is
* room for the category byte if needed.
*
* Note: because index_form_tuple MAXALIGNs the tuple size, there may well
* be some wasted pad space. Is it worth recomputing the data length to
* prevent that? That would also allow us to Assert that the real data
* doesn't overlap the GinNullCategory byte, which this code currently
* takes on faith.
*/
newsize = IndexTupleSize(itup);
if (IndexTupleHasNulls(itup))
{
uint32 minsize;
Assert(category != GIN_CAT_NORM_KEY);
minsize = GinCategoryOffset(itup, ginstate) + sizeof(GinNullCategory);
newsize = Max(newsize, minsize);
}
newsize = SHORTALIGN(newsize);
GinSetPostingOffset(itup, newsize);
GinSetNPosting(itup, nipd);
/*
* Add space needed for posting list, if any. Then check that the tuple
* won't be too big to store.
*/
newsize += dataSize;
newsize = MAXALIGN(newsize);
if (newsize > GinMaxItemSize)
{
if (errorTooBig)
ereport(ERROR,
(errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
errmsg("index row size %zu exceeds maximum %zu for index \"%s\"",
(Size) newsize, (Size) GinMaxItemSize,
RelationGetRelationName(ginstate->index))));
pfree(itup);
return NULL;
}
/*
* Resize tuple if needed
*/
if (newsize != IndexTupleSize(itup))
{
itup = repalloc(itup, newsize);
/*
* PostgreSQL 9.3 and earlier did not clear this new space, so we
* might find uninitialized padding when reading tuples from disk.
*/
memset((char *) itup + IndexTupleSize(itup),
//.........这里部分代码省略.........
开发者ID:HyukjinKwon,项目名称:pipelinedb,代码行数:101,代码来源:ginentrypage.c
示例17: compute_sql_asm_tsp
static int compute_sql_asm_tsp(char* sql, int sourceVertexId,
bool reverseCost,
tspPathElementType **path, int *pathCount) {
int SPIcode;
void *SPIplan;
Portal SPIportal;
bool moredata = TRUE;
int ntuples;
tspEdgeType *edges = NULL;
int totalTuples = 0;
DBG("Sql %s source %d reverse %s",sql,sourceVertexId,reverseCost==true?"true":"false");
tspEdgeType edgeColumns = {.id= -1, .source= -1, .target= -1, .cost= -1 };
char *errMesg;
int ret = -1;
errMesg=palloc(sizeof(char) * 300);
DBG("start compute_sql_asm_tsp %i",*pathCount);
SPIcode = SPI_connect();
if (SPIcode != SPI_OK_CONNECT) {
elog(ERROR, "compute_sql_asm_tsp: couldn't open a connection to SPI");
return -1;
}
SPIplan = SPI_prepare(sql, 0, NULL);
if (SPIplan == NULL) {
elog(ERROR, "compute_sql_asm_tsp: couldn't create query plan via SPI");
return -1;
}
if ((SPIportal = SPI_cursor_open(NULL, SPIplan, NULL, NULL, true)) == NULL) {
elog(ERROR, "compute_sql_asm_tsp: SPI_cursor_open('%s') returns NULL", sql);
return -1;
}
while (moredata == TRUE) {
SPI_cursor_fetch(SPIportal, TRUE, TUPLIMIT);
if (edgeColumns.id == -1) {
if (!fetchEdgeTspColumns(SPI_tuptable, &edgeColumns,reverseCost))
return finish(SPIcode, ret);
}
ntuples = SPI_processed;
totalTuples += ntuples;
if (!edges){
edges = palloc(totalTuples * sizeof(tspEdgeType));
} else {
edges = repalloc(edges, totalTuples * sizeof(tspEdgeType));
}
if (edges == NULL) {
elog(ERROR, "Out of memory");
return finish(SPIcode, ret);
}
if (ntuples > 0) {
int t;
SPITupleTable *tuptable = SPI_tuptable;
TupleDesc tupdesc = SPI_tuptable->tupdesc;
for (t = 0; t < ntuples; t++) {
HeapTuple tuple = tuptable->vals[t];
fetchEdgeTsp(&tuple, &tupdesc, &edgeColumns, &edges[totalTuples - ntuples + t],reverseCost);
}
SPI_freetuptable(tuptable);
} else {
moredata = FALSE;
}
}
DBG("Total %i tuples", totalTuples);
DBG("Calling tsp functions total tuples <%i> initial path count <%i>", totalTuples,*pathCount);
ret=processATSPData(edges,totalTuples,sourceVertexId,reverseCost, path, pathCount,errMesg);
DBG("SIZE %i elements to process",*pathCount);
if (!ret ) {
elog(ERROR, "Error computing path: %s", errMesg);
}
return finish(SPIcode, ret);
}
PG_FUNCTION_INFO_V1(sql_asm_tsp);
Datum sql_asm_tsp(PG_FUNCTION_ARGS) {
FuncCallContext *funcctx;
int callCntr;
int maxCalls;
TupleDesc tupleDesc;
tspPathElementType *path;
/* stuff done only on the first call of the function */
if (SRF_IS_FIRSTCALL()) {
MemoryContext oldcontext;
int pathCount = 0;
int ret;
//.........这里部分代码省略.........
开发者ID:mrdapotts,项目名称:pgrouting,代码行数:101,代码来源:tspInterface.c
示例18: setup_regexp_matches
/*
* setup_regexp_matches --- do the initial matching for regexp_matches()
* or regexp_split()
*
* To avoid having to re-find the compiled pattern on each call, we do
* all the matching in one swoop. The returned regexp_matches_ctx contains
* the locations of all the substrings matching the pattern.
*
* The three bool parameters have only two patterns (one for each caller)
* but it seems clearer to distinguish the functionality this way than to
* key it all off one "is_split" flag.
*/
static regexp_matches_ctx *
setup_regexp_matches(text *orig_str, text *pattern, text *flags,
Oid collation,
bool force_glob, bool use_subpatterns,
bool ignore_degenerate)
{
regexp_matches_ctx *matchctx = palloc0(sizeof(regexp_matches_ctx));
int orig_len;
pg_wchar *wide_str;
int wide_len;
pg_re_flags re_flags;
regex_t *cpattern;
regmatch_t *pmatch;
int pmatch_len;
int array_len;
int array_idx;
int prev_match_end;
int start_search;
/* save original string --- we'll extract result substrings from it */
matchctx->orig_str = orig_str;
/* convert string to pg_wchar form for matching */
orig_len = VARSIZE_ANY_EXHDR(orig_str);
wide_str = (pg_wchar *) palloc(sizeof(pg_wchar) * (orig_len + 1));
wide_len = pg_mb2wchar_with_len(VARDATA_ANY(orig_str), wide_str, orig_len);
/* determine options */
parse_re_flags(&re_flags, flags);
if (force_glob)
{
/* user mustn't specify 'g' for regexp_split */
if (re_flags.glob)
ereport(ERROR,
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
errmsg("regexp_split does not support the global option")));
/* but we find all the matches anyway */
re_flags.glob = true;
}
/* set up the compiled pattern */
cpattern = RE_compile_and_cache(pattern, re_flags.cflags, collation);
/* do we want to remember subpatterns? */
if (use_subpatterns && cpattern->re_nsub > 0)
{
matchctx->npatterns = cpattern->re_nsub;
pmatch_len = cpattern->re_nsub + 1;
}
else
{
use_subpatterns = false;
matchctx->npatterns = 1;
pmatch_len = 1;
}
/* temporary output space for RE package */
pmatch = palloc(sizeof(regmatch_t) * pmatch_len);
/* the real output space (grown dynamically if needed) */
array_len = re_flags.glob ? 256 : 32;
matchctx->match_locs = (int *) palloc(sizeof(int) * array_len);
array_idx = 0;
/* search for the pattern, perhaps repeatedly */
prev_match_end = 0;
start_search = 0;
while (RE_wchar_execute(cpattern, wide_str, wide_len, start_search,
pmatch_len, pmatch))
{
/*
* If requested, ignore degenerate matches, which are zero-length
* matches occurring at the start or end of a string or just after a
* previous match.
*/
if (!ignore_degenerate ||
(pmatch[0].rm_so < wide_len &&
pmatch[0].rm_eo > prev_match_end))
{
/* enlarge output space if needed */
while (array_idx + matchctx->npatterns * 2 > array_len)
{
array_len *= 2;
matchctx->match_locs = (int *) repalloc(matchctx->match_locs,
sizeof(int) * array_len);
}
/* save this match's locations */
//.........这里部分代码省略.........
开发者ID:BioBD,项目名称:Hypothetical_Indexes,代码行数:101,代码来源:regexp.c
示例19: parse_hstore
static void
parse_hstore(HSParser *state)
{
int st = WKEY;
bool escaped = false;
state->plen = 16;
state->pairs = (Pairs *) palloc(sizeof(Pairs) * state->plen);
state->pcur = 0;
state->ptr = state->begin;
state->word = NULL;
while (1)
{
if (st == WKEY)
{
if (!get_val(state, false, &escaped))
return;
if (state->pcur >= state->plen)
{
state->plen *= 2;
state->pairs = (Pairs *) repalloc(state->pairs, sizeof(Pairs) * state->plen);
}
state->pairs[state->pcur].key = state->word;
state->pairs[state->pcur].keylen = hstoreCheckKeyLen(state->cur - state->word);
state->pairs[state->pcur].val = NULL;
state->word = NULL;
st = WEQ;
}
else if (st == WEQ)
{
if (*(state->ptr) == '=')
{
st = WGT;
}
else if (*(state->ptr) == '\0')
{
elog(ERROR, "Unexpected end of string");
}
else if (!isspace((unsigned char) *(state->ptr)))
{
elog(ERROR, "Syntax error near '%c' at position %d", *(state->ptr), (int4) (state->ptr - state->begin));
}
}
else if (st == WGT)
{
if (*(state->ptr) == '>')
{
st = WVAL;
}
else if (*(state->ptr) == '\0')
{
elog(ERROR, "Unexpected end of string");
}
else
{
elog(ERROR, "Syntax error near '%c' at position %d", *(state->ptr), (int4) (state->ptr - state->begin));
}
}
else if (st == WVAL)
{
if (!get_val(state, true, &escaped))
elog(ERROR, "Unexpected end of string");
state->pairs[state->pcur].val = state->word;
state->pairs[state->pcur].vallen = hstoreCheckValLen(state->cur - state->word);
state->pairs[state->pcur].isnull = false;
state->pairs[state->pcur].needfree = true;
if (state->cur - state->word == 4 && !escaped)
{
state->word[4] = '\0';
if (0 == pg_strcasecmp(state->word, "null"))
state->pairs[state->pcur].isnull = true;
}
state->word = NULL;
state->pcur++;
st = WDEL;
}
else if (st == WDEL)
{
if (*(state->ptr) == ',')
{
st = WKEY;
}
else if (*(state->ptr) == '\0')
{
return;
}
else if (!isspace((unsigned char) *(state->ptr)))
{
elog(ERROR, "Syntax error near '%c' at position %d", *(state->ptr), (int4) (state->ptr - state->begin));
}
}
else
elog(ERROR, "Unknown state %d at line %d in file '%s'", st, __LINE__, __FILE__);
state->ptr++;
}
}
开发者ID:d,项目名称:gpdb,代码行数:98,代码来源:hstore_io.c
示例20: add_regex_array
/*
* Add an regular expression pattern
*/
int add_regex_array(RegArray *ar, char *pattern)
{
int regex_flags;
regex_t *regex;
char *pat;
int len;
if (ar == NULL)
{
ereport(WARNING,
(errmsg("failed to add regex pattern, regex array is NULL")));
return -1;
}
if (pattern == NULL)
{
ereport(WARNING,
(errmsg("failed to add regex pattern, regex pattern is NULL")));
return -1;
}
len = strlen(pattern);
/* Force case insensitive pattern matching */
regex_flags = REG_NOSUB;
regex_flags |= REG_ICASE;
/* Add extended regex search */
regex_flags |= REG_EXTENDED;
pat = palloc(sizeof(char)*(len+3));
if (strncmp(pattern, "^", 1) != 0)
{
strncpy(pat, "^", 2);
strncat(pat, pattern, len + 1);
}
else
{
strncpy(pat, pattern, len + 1);
}
if (len == 0 || (len > 0 && pattern[len - 1] != '$'))
{
strncat(pat, "$", 2);
}
/* Compile our regex */
regex = palloc(sizeof(regex_t));
if (regcomp(regex, pat, regex_flags) != 0)
{
ereport(WARNING,
(errmsg("failed to add regex pattern, invalid regex pattern: \"%s\" (%s)", pattern, pat)));
pfree(regex);
pfree(pat);
return -1;
}
pfree(pat);
if (ar->pos == ar->size)
{
ar->size += AR_ALLOC_UNIT;
ar->regex = repalloc(ar->regex, sizeof(regex_t *) * ar->size);
}
ar->regex[ar->pos] = regex;
ar->pos++;
return 0;
}
开发者ID:onderaycicek,项目名称:pgpool2,代码行数:72,代码来源:regex_array.c
注:本文中的repalloc函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论