Skip to content

Commit

Permalink
Run clang-format on code
Browse files Browse the repository at this point in the history
  • Loading branch information
cevian committed Feb 5, 2019
1 parent b891a28 commit 34edba1
Show file tree
Hide file tree
Showing 187 changed files with 6,382 additions and 5,752 deletions.
133 changes: 67 additions & 66 deletions src/agg_bookend.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,24 +33,23 @@ TS_FUNCTION_INFO_V1(ts_bookend_deserializefunc);
/* A PolyDatum represents a polymorphic datum */
typedef struct PolyDatum
{
Oid type_oid;
bool is_null;
Datum datum;
Oid type_oid;
bool is_null;
Datum datum;
} PolyDatum;


/* PolyDatumIOState is internal state used by polydatum_serialize and polydatum_deserialize */
typedef struct PolyDatumIOState
{
Oid type_oid;
FmgrInfo proc;
Oid typeioparam;
Oid type_oid;
FmgrInfo proc;
Oid typeioparam;
} PolyDatumIOState;

static PolyDatum
polydatum_from_arg(int argno, FunctionCallInfo fcinfo)
{
PolyDatum value;
PolyDatum value;

value.type_oid = get_fn_expr_argtype(fcinfo->flinfo, argno);
value.is_null = PG_ARGISNULL(argno);
Expand All @@ -65,7 +64,7 @@ polydatum_from_arg(int argno, FunctionCallInfo fcinfo)
static void
polydatum_serialize(PolyDatum *pd, StringInfo buf, PolyDatumIOState *state, FunctionCallInfo fcinfo)
{
bytea *outputbytes;
bytea *outputbytes;

pq_sendint(buf, pd->type_oid, sizeof(Oid));

Expand All @@ -78,14 +77,11 @@ polydatum_serialize(PolyDatum *pd, StringInfo buf, PolyDatumIOState *state, Func

if (state->type_oid != pd->type_oid)
{
Oid func;
bool is_varlena;

getTypeBinaryOutputInfo(pd->type_oid,
&func,
&is_varlena);
fmgr_info_cxt(func, &state->proc,
fcinfo->flinfo->fn_mcxt);
Oid func;
bool is_varlena;

getTypeBinaryOutputInfo(pd->type_oid, &func, &is_varlena);
fmgr_info_cxt(func, &state->proc, fcinfo->flinfo->fn_mcxt);
state->type_oid = pd->type_oid;
}
outputbytes = SendFunctionCall(&state->proc, pd->datum);
Expand All @@ -99,12 +95,13 @@ polydatum_serialize(PolyDatum *pd, StringInfo buf, PolyDatumIOState *state, Func
*
*/
static PolyDatum *
polydatum_deserialize(PolyDatum *result, StringInfo buf, PolyDatumIOState *state, FunctionCallInfo fcinfo)
polydatum_deserialize(PolyDatum *result, StringInfo buf, PolyDatumIOState *state,
FunctionCallInfo fcinfo)
{
int itemlen;
int itemlen;
StringInfoData item_buf;
StringInfo bufptr;
char csave;
StringInfo bufptr;
char csave;

if (NULL == result)
{
Expand Down Expand Up @@ -154,20 +151,14 @@ polydatum_deserialize(PolyDatum *result, StringInfo buf, PolyDatumIOState *state
/* Now call the column's receiveproc */
if (state->type_oid != result->type_oid)
{
Oid func;
Oid func;

getTypeBinaryInputInfo(result->type_oid,
&func,
&state->typeioparam);
fmgr_info_cxt(func, &state->proc,
fcinfo->flinfo->fn_mcxt);
getTypeBinaryInputInfo(result->type_oid, &func, &state->typeioparam);
fmgr_info_cxt(func, &state->proc, fcinfo->flinfo->fn_mcxt);
state->type_oid = result->type_oid;
}

result->datum = ReceiveFunctionCall(&state->proc,
bufptr,
state->typeioparam,
-1);
result->datum = ReceiveFunctionCall(&state->proc, bufptr, state->typeioparam, -1);

if (bufptr)
{
Expand All @@ -185,22 +176,22 @@ polydatum_deserialize(PolyDatum *result, StringInfo buf, PolyDatumIOState *state
/* Internal state for bookend aggregates */
typedef struct InternalCmpAggStore
{
PolyDatum value;
PolyDatum cmp; /* the comparison element. e.g. time */
PolyDatum value;
PolyDatum cmp; /* the comparison element. e.g. time */
} InternalCmpAggStore;

/* State used to cache data for serialize/deserialize operations */
typedef struct InternalCmpAggStoreIOState
{
PolyDatumIOState value;
PolyDatumIOState cmp; /* the comparison element. e.g. time */
PolyDatumIOState cmp; /* the comparison element. e.g. time */
} InternalCmpAggStoreIOState;

typedef struct TypeInfoCache
{
Oid type_oid;
int16 typelen;
bool typebyval;
Oid type_oid;
int16 typelen;
bool typebyval;
} TypeInfoCache;

inline static void
Expand Down Expand Up @@ -232,9 +223,9 @@ typeinfocache_polydatumcopy(TypeInfoCache *tic, PolyDatum input, PolyDatum *outp

typedef struct CmpFuncCache
{
Oid cmp_type;
char op;
FmgrInfo proc;
Oid cmp_type;
char op;
FmgrInfo proc;
} CmpFuncCache;

inline static void
Expand All @@ -244,15 +235,15 @@ cmpfunccache_init(CmpFuncCache *cache)
}

inline static bool
cmpfunccache_cmp(CmpFuncCache *cache, FunctionCallInfo fcinfo, char *opname, PolyDatum left, PolyDatum right)
cmpfunccache_cmp(CmpFuncCache *cache, FunctionCallInfo fcinfo, char *opname, PolyDatum left,
PolyDatum right)
{
Assert(left.type_oid == right.type_oid);
Assert(opname[1] == '\0');

if (cache->cmp_type != left.type_oid || cache->op != opname[0])
{
Oid cmp_op,
cmp_regproc;
Oid cmp_op, cmp_regproc;

if (!OidIsValid(left.type_oid))
elog(ERROR, "could not determine the type of the comparison_element");
Expand All @@ -261,11 +252,14 @@ cmpfunccache_cmp(CmpFuncCache *cache, FunctionCallInfo fcinfo, char *opname, Pol
elog(ERROR, "could not find a %s operator for type %d", opname, left.type_oid);
cmp_regproc = get_opcode(cmp_op);
if (!OidIsValid(cmp_regproc))
elog(ERROR, "could not find the procedure for the %s operator for type %d", opname, left.type_oid);
fmgr_info_cxt(cmp_regproc, &cache->proc,
fcinfo->flinfo->fn_mcxt);
elog(ERROR,
"could not find the procedure for the %s operator for type %d",
opname,
left.type_oid);
fmgr_info_cxt(cmp_regproc, &cache->proc, fcinfo->flinfo->fn_mcxt);
}
return DatumGetBool(FunctionCall2Coll(&cache->proc, fcinfo->fncollation, left.datum, right.datum));
return DatumGetBool(
FunctionCall2Coll(&cache->proc, fcinfo->fncollation, left.datum, right.datum));
}

typedef struct TransCache
Expand All @@ -282,8 +276,7 @@ transcache_get(FunctionCallInfo fcinfo)

if (my_extra == NULL)
{
fcinfo->flinfo->fn_extra =
MemoryContextAlloc(fcinfo->flinfo->fn_mcxt, sizeof(TransCache));
fcinfo->flinfo->fn_extra = MemoryContextAlloc(fcinfo->flinfo->fn_mcxt, sizeof(TransCache));
my_extra = (TransCache *) fcinfo->flinfo->fn_extra;
typeinfocache_init(&my_extra->value_type_cache);
typeinfocache_init(&my_extra->cmp_type_cache);
Expand All @@ -296,7 +289,8 @@ transcache_get(FunctionCallInfo fcinfo)
* bookend_sfunc - internal function called by ts_last_sfunc and ts_first_sfunc;
*/
static inline Datum
bookend_sfunc(MemoryContext aggcontext, InternalCmpAggStore *state, PolyDatum value, PolyDatum cmp, char *opname, FunctionCallInfo fcinfo)
bookend_sfunc(MemoryContext aggcontext, InternalCmpAggStore *state, PolyDatum value, PolyDatum cmp,
char *opname, FunctionCallInfo fcinfo)
{
MemoryContext old_context;
TransCache *cache = transcache_get(fcinfo);
Expand All @@ -312,7 +306,8 @@ bookend_sfunc(MemoryContext aggcontext, InternalCmpAggStore *state, PolyDatum va
else
{
/* only do comparison if cmp is not NULL */
if (!cmp.is_null && cmpfunccache_cmp(&cache->cmp_func_cache, fcinfo, opname, cmp, state->cmp))
if (!cmp.is_null &&
cmpfunccache_cmp(&cache->cmp_func_cache, fcinfo, opname, cmp, state->cmp))
{
typeinfocache_polydatumcopy(&cache->value_type_cache, value, &state->value);
typeinfocache_polydatumcopy(&cache->cmp_type_cache, cmp, &state->cmp);
Expand All @@ -327,7 +322,8 @@ bookend_sfunc(MemoryContext aggcontext, InternalCmpAggStore *state, PolyDatum va
* fmgr args are: (internal internal_state, internal2 internal_state)
*/
static inline Datum
bookend_combinefunc(MemoryContext aggcontext, InternalCmpAggStore *state1, InternalCmpAggStore *state2, char *opname, FunctionCallInfo fcinfo)
bookend_combinefunc(MemoryContext aggcontext, InternalCmpAggStore *state1,
InternalCmpAggStore *state2, char *opname, FunctionCallInfo fcinfo)
{
MemoryContext old_context;
TransCache *cache;
Expand All @@ -345,7 +341,8 @@ bookend_combinefunc(MemoryContext aggcontext, InternalCmpAggStore *state1, Inter
{
old_context = MemoryContextSwitchTo(aggcontext);

state1 = (InternalCmpAggStore *) MemoryContextAlloc(aggcontext, sizeof(InternalCmpAggStore));
state1 =
(InternalCmpAggStore *) MemoryContextAlloc(aggcontext, sizeof(InternalCmpAggStore));
typeinfocache_polydatumcopy(&cache->value_type_cache, state2->value, &state1->value);
typeinfocache_polydatumcopy(&cache->cmp_type_cache, state2->cmp, &state1->cmp);

Expand Down Expand Up @@ -379,9 +376,10 @@ bookend_combinefunc(MemoryContext aggcontext, InternalCmpAggStore *state1, Inter
Datum
ts_first_sfunc(PG_FUNCTION_ARGS)
{
InternalCmpAggStore *store = PG_ARGISNULL(0) ? NULL : (InternalCmpAggStore *) PG_GETARG_POINTER(0);
PolyDatum value = polydatum_from_arg(1, fcinfo);
PolyDatum cmp = polydatum_from_arg(2, fcinfo);
InternalCmpAggStore *store =
PG_ARGISNULL(0) ? NULL : (InternalCmpAggStore *) PG_GETARG_POINTER(0);
PolyDatum value = polydatum_from_arg(1, fcinfo);
PolyDatum cmp = polydatum_from_arg(2, fcinfo);
MemoryContext aggcontext;

if (!AggCheckCallContext(fcinfo, &aggcontext))
Expand All @@ -397,9 +395,10 @@ ts_first_sfunc(PG_FUNCTION_ARGS)
Datum
ts_last_sfunc(PG_FUNCTION_ARGS)
{
InternalCmpAggStore *store = PG_ARGISNULL(0) ? NULL : (InternalCmpAggStore *) PG_GETARG_POINTER(0);
PolyDatum value = polydatum_from_arg(1, fcinfo);
PolyDatum cmp = polydatum_from_arg(2, fcinfo);
InternalCmpAggStore *store =
PG_ARGISNULL(0) ? NULL : (InternalCmpAggStore *) PG_GETARG_POINTER(0);
PolyDatum value = polydatum_from_arg(1, fcinfo);
PolyDatum cmp = polydatum_from_arg(2, fcinfo);
MemoryContext aggcontext;

if (!AggCheckCallContext(fcinfo, &aggcontext))
Expand All @@ -416,8 +415,10 @@ Datum
ts_first_combinefunc(PG_FUNCTION_ARGS)
{
MemoryContext aggcontext;
InternalCmpAggStore *state1 = PG_ARGISNULL(0) ? NULL : (InternalCmpAggStore *) PG_GETARG_POINTER(0);
InternalCmpAggStore *state2 = PG_ARGISNULL(1) ? NULL : (InternalCmpAggStore *) PG_GETARG_POINTER(1);
InternalCmpAggStore *state1 =
PG_ARGISNULL(0) ? NULL : (InternalCmpAggStore *) PG_GETARG_POINTER(0);
InternalCmpAggStore *state2 =
PG_ARGISNULL(1) ? NULL : (InternalCmpAggStore *) PG_GETARG_POINTER(1);

if (!AggCheckCallContext(fcinfo, &aggcontext))
{
Expand All @@ -432,8 +433,10 @@ Datum
ts_last_combinefunc(PG_FUNCTION_ARGS)
{
MemoryContext aggcontext;
InternalCmpAggStore *state1 = PG_ARGISNULL(0) ? NULL : (InternalCmpAggStore *) PG_GETARG_POINTER(0);
InternalCmpAggStore *state2 = PG_ARGISNULL(1) ? NULL : (InternalCmpAggStore *) PG_GETARG_POINTER(1);
InternalCmpAggStore *state1 =
PG_ARGISNULL(0) ? NULL : (InternalCmpAggStore *) PG_GETARG_POINTER(0);
InternalCmpAggStore *state2 =
PG_ARGISNULL(1) ? NULL : (InternalCmpAggStore *) PG_GETARG_POINTER(1);

if (!AggCheckCallContext(fcinfo, &aggcontext))
{
Expand All @@ -443,7 +446,6 @@ ts_last_combinefunc(PG_FUNCTION_ARGS)
return bookend_combinefunc(aggcontext, state1, state2, ">", fcinfo);
}


/* ts_bookend_serializefunc(internal) => bytea */
Datum
ts_bookend_serializefunc(PG_FUNCTION_ARGS)
Expand Down Expand Up @@ -472,7 +474,7 @@ ts_bookend_serializefunc(PG_FUNCTION_ARGS)
Datum
ts_bookend_deserializefunc(PG_FUNCTION_ARGS)
{
bytea *sstate;
bytea *sstate;
StringInfoData buf;
InternalCmpAggStore *result;
InternalCmpAggStoreIOState *my_extra;
Expand Down Expand Up @@ -503,7 +505,6 @@ ts_bookend_deserializefunc(PG_FUNCTION_ARGS)
PG_RETURN_POINTER(result);
}


/* ts_bookend_finalfunc(internal, anyelement, "any") => anyelement */
Datum
ts_bookend_finalfunc(PG_FUNCTION_ARGS)
Expand Down
42 changes: 18 additions & 24 deletions src/base64_compat.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,15 @@
* BASE64
*/

static const char _base64[] =
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
static const char _base64[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";

static const int8 b64lookup[128] = {
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 62, -1, -1, -1, 63,
52, 53, 54, 55, 56, 57, 58, 59, 60, 61, -1, -1, -1, -1, -1, -1,
-1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, -1, -1, -1, -1, -1,
-1, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40,
41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 62,
-1, -1, -1, 63, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, -1, -1, -1, -1, -1, -1, -1, 0,
1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22,
23, 24, 25, -1, -1, -1, -1, -1, -1, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38,
39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, -1, -1, -1, -1, -1,
};

/*
Expand All @@ -48,11 +45,10 @@ static const int8 b64lookup[128] = {
TSDLLEXPORT int
pg_b64_encode(const char *src, int len, char *dst)
{
char *p;
const char *s,
*end = src + len;
int pos = 2;
uint32 buf = 0;
char *p;
const char *s, *end = src + len;
int pos = 2;
uint32 buf = 0;

s = src;
p = dst;
Expand Down Expand Up @@ -95,14 +91,12 @@ pg_b64_encode(const char *src, int len, char *dst)
TSDLLEXPORT int
pg_b64_decode(const char *src, int len, char *dst)
{
const char *srcend = src + len,
*s = src;
char *p = dst;
char c;
int b = 0;
uint32 buf = 0;
int pos = 0,
end = 0;
const char *srcend = src + len, *s = src;
char *p = dst;
char c;
int b = 0;
uint32 buf = 0;
int pos = 0, end = 0;

while (s < srcend)
{
Expand Down Expand Up @@ -198,4 +192,4 @@ pg_b64_dec_len(int srclen)
{
return (srclen * 3) >> 2;
}
#endif /* PG96 */
#endif /* PG96 */
2 changes: 1 addition & 1 deletion src/base64_compat.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,4 @@ extern TSDLLEXPORT int pg_b64_dec_len(int srclen);

#endif

#endif /* BASE64_COMPAT_H */
#endif /* BASE64_COMPAT_H */
Loading

0 comments on commit 34edba1

Please sign in to comment.