本文整理汇总了C++中PG_FREE_IF_COPY函数的典型用法代码示例。如果您正苦于以下问题:C++ PG_FREE_IF_COPY函数的具体用法?C++ PG_FREE_IF_COPY怎么用?C++ PG_FREE_IF_COPY使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了PG_FREE_IF_COPY函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: cube_ur_coord
/* Return a specific normalized UR coordinate */
Datum
cube_ur_coord(PG_FUNCTION_ARGS)
{
NDBOX *c = PG_GETARG_NDBOX(0);
int n = PG_GETARG_INT16(1);
double result;
if (c->dim >= n && n > 0)
result = Max(c->x[n - 1], c->x[c->dim + n - 1]);
else
result = 0;
PG_FREE_IF_COPY(c, 0);
PG_RETURN_FLOAT8(result);
}
示例2: cube_ur_coord
/* Return a specific normalized UR coordinate */
Datum
cube_ur_coord(PG_FUNCTION_ARGS)
{
NDBOX *c = PG_GETARG_NDBOX(0);
int n = PG_GETARG_INT16(1);
double result;
if (DIM(c) >= n && n > 0)
result = Max(LL_COORD(c, n - 1), UR_COORD(c, n - 1));
else
result = 0;
PG_FREE_IF_COPY(c, 0);
PG_RETURN_FLOAT8(result);
}
示例3: text2ltree
Datum
text2ltree(PG_FUNCTION_ARGS)
{
text *in = PG_GETARG_TEXT_PP(0);
char *s;
ltree *out;
s = text_to_cstring(in);
out = (ltree *) DatumGetPointer(DirectFunctionCall1(ltree_in,
PointerGetDatum(s)));
pfree(s);
PG_FREE_IF_COPY(in, 0);
PG_RETURN_POINTER(out);
}
示例4: ltree_addtext
Datum
ltree_addtext(PG_FUNCTION_ARGS)
{
ltree *a = PG_GETARG_LTREE(0);
text *b = PG_GETARG_TEXT_PP(1);
char *s;
ltree *r,
*tmp;
s = text_to_cstring(b);
tmp = (ltree *) DatumGetPointer(DirectFunctionCall1(ltree_in,
PointerGetDatum(s)));
pfree(s);
r = ltree_concat(a, tmp);
pfree(tmp);
PG_FREE_IF_COPY(a, 0);
PG_FREE_IF_COPY(b, 1);
PG_RETURN_POINTER(r);
}
示例5: parse_byname
Datum
parse_byname(PG_FUNCTION_ARGS)
{
FuncCallContext *funcctx;
Datum result;
SET_FUNCOID();
if (SRF_IS_FIRSTCALL())
{
text *name = PG_GETARG_TEXT_P(0);
text *txt = PG_GETARG_TEXT_P(1);
funcctx = SRF_FIRSTCALL_INIT();
prs_setup_firstcall(fcinfo, funcctx, name2id_prs(name), txt);
PG_FREE_IF_COPY(name, 0);
PG_FREE_IF_COPY(txt, 1);
}
funcctx = SRF_PERCALL_SETUP();
if ((result = prs_process_call(funcctx)) != (Datum) 0)
SRF_RETURN_NEXT(funcctx, result);
SRF_RETURN_DONE(funcctx);
}
示例6: cube_size
/* cube_size */
Datum
cube_size(PG_FUNCTION_ARGS)
{
NDBOX *a = PG_GETARG_NDBOX(0);
double result;
int i,
j;
result = 1.0;
for (i = 0, j = a->dim; i < a->dim; i++, j++)
result = result * Abs((a->x[j] - a->x[i]));
PG_FREE_IF_COPY(a, 0);
PG_RETURN_FLOAT8(result);
}
示例7: LWGEOM_to_BOX2DF
Datum LWGEOM_to_BOX2DF(PG_FUNCTION_ARGS)
{
GSERIALIZED *geom = PG_GETARG_GSERIALIZED_P(0);
GBOX gbox;
if ( gserialized_get_gbox_p(geom, &gbox) == LW_FAILURE )
PG_RETURN_NULL();
/* Strip out higher dimensions */
FLAGS_SET_Z(gbox.flags, 0);
FLAGS_SET_M(gbox.flags, 0);
PG_FREE_IF_COPY(geom, 0);
PG_RETURN_POINTER(gbox_copy(&gbox));
}
示例8: show_trgm
Datum
show_trgm(PG_FUNCTION_ARGS)
{
text *in = PG_GETARG_TEXT_P(0);
TRGM *trg;
Datum *d;
ArrayType *a;
trgm *ptr;
int i;
trg = generate_trgm(VARDATA(in), VARSIZE(in) - VARHDRSZ);
d = (Datum *) palloc(sizeof(Datum) * (1 + ARRNELEM(trg)));
for (i = 0, ptr = GETARR(trg); i < ARRNELEM(trg); i++, ptr++)
{
text *item = (text *) palloc(VARHDRSZ + Max(12, pg_database_encoding_max_length() * 3));
if (pg_database_encoding_max_length() > 1 && !ISPRINTABLETRGM(ptr))
{
snprintf(VARDATA(item), 12, "0x%06x", trgm2int(ptr));
SET_VARSIZE(item, VARHDRSZ + strlen(VARDATA(item)));
}
else
{
SET_VARSIZE(item, VARHDRSZ + 3);
CPTRGM(VARDATA(item), ptr);
}
d[i] = PointerGetDatum(item);
}
a = construct_array(
d,
ARRNELEM(trg),
TEXTOID,
-1,
false,
'i'
);
for (i = 0; i < ARRNELEM(trg); i++)
pfree(DatumGetPointer(d[i]));
pfree(d);
pfree(trg);
PG_FREE_IF_COPY(in, 0);
PG_RETURN_POINTER(a);
}
示例9: cube_is_point
/* Test if a box is also a point */
Datum
cube_is_point(PG_FUNCTION_ARGS)
{
NDBOX *a = PG_GETARG_NDBOX(0);
int i,
j;
for (i = 0, j = a->dim; i < a->dim; i++, j++)
{
if (a->x[i] != a->x[j])
PG_RETURN_BOOL(FALSE);
}
PG_FREE_IF_COPY(a, 0);
PG_RETURN_BOOL(TRUE);
}
示例10: citext_hash
Datum
citext_hash(PG_FUNCTION_ARGS)
{
text *txt = PG_GETARG_TEXT_PP(0);
char *str;
Datum result;
str = str_tolower(VARDATA_ANY(txt), VARSIZE_ANY_EXHDR(txt));
result = hash_any((unsigned char *) str, strlen(str));
pfree(str);
/* Avoid leaking memory for toasted inputs */
PG_FREE_IF_COPY(txt, 0);
PG_RETURN_DATUM(result);
}
示例11: sfcgal_is_solid
Datum sfcgal_is_solid(PG_FUNCTION_ARGS)
{
int result;
GSERIALIZED *input = PG_GETARG_GSERIALIZED_P(0);
LWGEOM *lwgeom = lwgeom_from_gserialized(input);
PG_FREE_IF_COPY(input, 0);
if (! lwgeom)
{
lwerror("sfcgal_is_solid: Unable to deserialize input");
}
result = FLAGS_GET_SOLID( lwgeom->flags );
lwgeom_free(lwgeom);
PG_RETURN_BOOL(result);
}
示例12: jsquery_hash
Datum
jsquery_hash(PG_FUNCTION_ARGS)
{
JsQuery *jq = PG_GETARG_JSQUERY(0);
JsQueryItem v;
pg_crc32 res;
INIT_CRC32(res);
jsqInit(&v, jq);
hashJsQuery(&v, &res);
FIN_CRC32(res);
PG_FREE_IF_COPY(jq, 0);
PG_RETURN_INT32(res);
}
示例13: geography_from_geometry
Datum geography_from_geometry(PG_FUNCTION_ARGS)
{
GSERIALIZED *geom = (GSERIALIZED*)PG_DETOAST_DATUM_COPY(PG_GETARG_DATUM(0));
LWGEOM *lwgeom = NULL;
GSERIALIZED *g_ser = NULL;
geography_valid_type(gserialized_get_type(geom));
lwgeom = lwgeom_from_gserialized(geom);
/* Force default SRID */
if ( (int)lwgeom->srid <= 0 )
{
lwgeom->srid = SRID_DEFAULT;
}
/* Error on any SRID != default */
srid_is_latlong(fcinfo, lwgeom->srid);
/* Force the geometry to have valid geodetic coordinate range. */
lwgeom_nudge_geodetic(lwgeom);
if ( lwgeom_force_geodetic(lwgeom) == LW_TRUE )
{
ereport(NOTICE, (
errmsg_internal("Coordinate values were coerced into range [-180 -90, 180 90] for GEOGRAPHY" ))
);
}
/*
** Serialize our lwgeom and set the geodetic flag so subsequent
** functions do the right thing.
*/
lwgeom_set_geodetic(lwgeom, true);
/* Recalculate the boxes after re-setting the geodetic bit */
lwgeom_drop_bbox(lwgeom);
lwgeom_add_bbox(lwgeom);
g_ser = geography_serialize(lwgeom);
/*
** Replace the unaligned lwgeom with a new aligned one based on GSERIALIZED.
*/
lwgeom_free(lwgeom);
PG_FREE_IF_COPY(geom, 0);
PG_RETURN_POINTER(g_ser);
}
示例14: cube_c_f8_f8
/* Add a dimension to an existing cube */
Datum
cube_c_f8_f8(PG_FUNCTION_ARGS)
{
NDBOX *cube = PG_GETARG_NDBOX(0);
double x1 = PG_GETARG_FLOAT8(1);
double x2 = PG_GETARG_FLOAT8(2);
NDBOX *result;
int size;
int i;
if (DIM(cube) + 1 > CUBE_MAX_DIM)
ereport(ERROR,
(errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
errmsg("can't extend cube"),
errdetail("A cube cannot have more than %d dimensions.",
CUBE_MAX_DIM)));
if (IS_POINT(cube) && (x1 == x2))
{
size = POINT_SIZE((DIM(cube) + 1));
result = (NDBOX *) palloc0(size);
SET_VARSIZE(result, size);
SET_DIM(result, DIM(cube) + 1);
SET_POINT_BIT(result);
for (i = 0; i < DIM(cube); i++)
result->x[i] = cube->x[i];
result->x[DIM(result) - 1] = x1;
}
else
{
size = CUBE_SIZE((DIM(cube) + 1));
result = (NDBOX *) palloc0(size);
SET_VARSIZE(result, size);
SET_DIM(result, DIM(cube) + 1);
for (i = 0; i < DIM(cube); i++)
{
result->x[i] = LL_COORD(cube, i);
result->x[DIM(result) + i] = UR_COORD(cube, i);
}
result->x[DIM(result) - 1] = x1;
result->x[2 * DIM(result) - 1] = x2;
}
PG_FREE_IF_COPY(cube, 0);
PG_RETURN_NDBOX(result);
}
示例15: cube_subset
Datum
cube_subset(PG_FUNCTION_ARGS)
{
NDBOX *c,
*result;
ArrayType *idx;
int size,
dim,
i;
int *dx;
c = PG_GETARG_NDBOX(0);
idx = (ArrayType *) PG_GETARG_VARLENA_P(1);
if (ARR_HASNULL(idx))
{
ereport(ERROR,
(errcode(ERRCODE_ARRAY_ELEMENT_ERROR),
errmsg("Cannot work with NULL arrays")));
}
dx = (int4 *) ARR_DATA_PTR(idx);
dim = ARRNELEMS(idx);
size = offsetof(NDBOX, x[0]) + sizeof(double) * 2 * dim;
result = (NDBOX *) palloc(size);
memset(result, 0, size);
result->size = size;
result->dim = dim;
for (i = 0; i < dim; i++)
{
if ((dx[i] <= 0) || (dx[i] > c->dim))
{
pfree(result);
ereport(ERROR,
(errcode(ERRCODE_ARRAY_ELEMENT_ERROR),
errmsg("Index out of bounds")));
}
result->x[i] = c->x[dx[i] - 1];
result->x[i + dim] = c->x[dx[i] + c->dim - 1];
}
PG_FREE_IF_COPY(c,0);
PG_RETURN_NDBOX(result);
}