diff options
author | Bruce Momjian | 2010-02-26 02:01:40 +0000 |
---|---|---|
committer | Bruce Momjian | 2010-02-26 02:01:40 +0000 |
commit | 65e806cba1f0f154d51caa7478e7192ce58d1056 (patch) | |
tree | 99a656d7b4ec6d038d4c24e07fadf75db4c37e79 /contrib | |
parent | 16040575a04486d8e0823b4e304f4933144baf90 (diff) |
pgindent run for 9.0
Diffstat (limited to 'contrib')
31 files changed, 828 insertions, 806 deletions
diff --git a/contrib/auto_explain/auto_explain.c b/contrib/auto_explain/auto_explain.c index 61406db6342..ffc1a4a1063 100644 --- a/contrib/auto_explain/auto_explain.c +++ b/contrib/auto_explain/auto_explain.c @@ -6,7 +6,7 @@ * Copyright (c) 2008-2010, PostgreSQL Global Development Group * * IDENTIFICATION - * $PostgreSQL: pgsql/contrib/auto_explain/auto_explain.c,v 1.13 2010/02/16 22:19:59 adunstan Exp $ + * $PostgreSQL: pgsql/contrib/auto_explain/auto_explain.c,v 1.14 2010/02/26 02:00:31 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -27,11 +27,11 @@ static int auto_explain_log_format = EXPLAIN_FORMAT_TEXT; static bool auto_explain_log_nested_statements = false; static const struct config_enum_entry format_options[] = { - {"text", EXPLAIN_FORMAT_TEXT, false}, - {"xml", EXPLAIN_FORMAT_XML, false}, - {"json", EXPLAIN_FORMAT_JSON, false}, - {"yaml", EXPLAIN_FORMAT_YAML, false}, - {NULL, 0, false} + {"text", EXPLAIN_FORMAT_TEXT, false}, + {"xml", EXPLAIN_FORMAT_XML, false}, + {"json", EXPLAIN_FORMAT_JSON, false}, + {"yaml", EXPLAIN_FORMAT_YAML, false}, + {NULL, 0, false} }; /* Current nesting depth of ExecutorRun calls */ @@ -231,7 +231,7 @@ explain_ExecutorEnd(QueryDesc *queryDesc) msec = queryDesc->totaltime->total * 1000.0; if (msec >= auto_explain_log_min_duration) { - ExplainState es; + ExplainState es; ExplainInitState(&es); es.analyze = (queryDesc->instrument_options && auto_explain_log_analyze); @@ -257,7 +257,7 @@ explain_ExecutorEnd(QueryDesc *queryDesc) ereport(LOG, (errmsg("duration: %.3f ms plan:\n%s", msec, es.str->data), - errhidestmt(true))); + errhidestmt(true))); pfree(es.str->data); } diff --git a/contrib/btree_gist/btree_cash.c b/contrib/btree_gist/btree_cash.c index 852ba3718bc..a1efde61468 100644 --- a/contrib/btree_gist/btree_cash.c +++ b/contrib/btree_gist/btree_cash.c @@ -1,5 +1,5 @@ /* - * $PostgreSQL: pgsql/contrib/btree_gist/btree_cash.c,v 1.10 2009/12/02 13:13:24 teodor Exp $ + * $PostgreSQL: pgsql/contrib/btree_gist/btree_cash.c,v 1.11 2010/02/26 02:00:31 momjian Exp $ */ #include "btree_gist.h" #include "btree_utils_num.h" @@ -57,8 +57,8 @@ gbt_cashlt(const void *a, const void *b) static int gbt_cashkey_cmp(const void *a, const void *b) { - cashKEY *ia = (cashKEY*)(((Nsrt *) a)->t); - cashKEY *ib = (cashKEY*)(((Nsrt *) b)->t); + cashKEY *ia = (cashKEY *) (((Nsrt *) a)->t); + cashKEY *ib = (cashKEY *) (((Nsrt *) b)->t); if (ia->lower == ib->lower) { diff --git a/contrib/btree_gist/btree_date.c b/contrib/btree_gist/btree_date.c index b6e4e0b292a..d8dce91535d 100644 --- a/contrib/btree_gist/btree_date.c +++ b/contrib/btree_gist/btree_date.c @@ -1,5 +1,5 @@ /* - * $PostgreSQL: pgsql/contrib/btree_gist/btree_date.c,v 1.8 2009/12/02 13:13:24 teodor Exp $ + * $PostgreSQL: pgsql/contrib/btree_gist/btree_date.c,v 1.9 2010/02/26 02:00:31 momjian Exp $ */ #include "btree_gist.h" #include "btree_utils_num.h" @@ -73,9 +73,9 @@ gbt_datelt(const void *a, const void *b) static int gbt_datekey_cmp(const void *a, const void *b) { - dateKEY *ia = (dateKEY*)(((Nsrt *) a)->t); - dateKEY *ib = (dateKEY*)(((Nsrt *) b)->t); - int res; + dateKEY *ia = (dateKEY *) (((Nsrt *) a)->t); + dateKEY *ib = (dateKEY *) (((Nsrt *) b)->t); + int res; res = DatumGetInt32(DirectFunctionCall2(date_cmp, DateADTGetDatum(ia->lower), DateADTGetDatum(ib->lower))); if (res == 0) diff --git a/contrib/btree_gist/btree_float4.c b/contrib/btree_gist/btree_float4.c index 3246f7f43bd..7ece9ea220d 100644 --- a/contrib/btree_gist/btree_float4.c +++ b/contrib/btree_gist/btree_float4.c @@ -1,5 +1,5 @@ /* - * $PostgreSQL: pgsql/contrib/btree_gist/btree_float4.c,v 1.9 2009/12/02 13:13:24 teodor Exp $ + * $PostgreSQL: pgsql/contrib/btree_gist/btree_float4.c,v 1.10 2010/02/26 02:00:31 momjian Exp $ */ #include "btree_gist.h" #include "btree_utils_num.h" @@ -56,8 +56,8 @@ gbt_float4lt(const void *a, const void *b) static int gbt_float4key_cmp(const void *a, const void *b) { - float4KEY *ia = (float4KEY*)(((Nsrt *) a)->t); - float4KEY *ib = (float4KEY*)(((Nsrt *) b)->t); + float4KEY *ia = (float4KEY *) (((Nsrt *) a)->t); + float4KEY *ib = (float4KEY *) (((Nsrt *) b)->t); if (ia->lower == ib->lower) { diff --git a/contrib/btree_gist/btree_float8.c b/contrib/btree_gist/btree_float8.c index 6964d201917..ab4912883db 100644 --- a/contrib/btree_gist/btree_float8.c +++ b/contrib/btree_gist/btree_float8.c @@ -1,5 +1,5 @@ /* - * $PostgreSQL: pgsql/contrib/btree_gist/btree_float8.c,v 1.9 2009/12/02 13:13:24 teodor Exp $ + * $PostgreSQL: pgsql/contrib/btree_gist/btree_float8.c,v 1.10 2010/02/26 02:00:31 momjian Exp $ */ #include "btree_gist.h" #include "btree_utils_num.h" @@ -57,8 +57,8 @@ gbt_float8lt(const void *a, const void *b) static int gbt_float8key_cmp(const void *a, const void *b) { - float8KEY *ia = (float8KEY*)(((Nsrt *) a)->t); - float8KEY *ib = (float8KEY*)(((Nsrt *) b)->t); + float8KEY *ia = (float8KEY *) (((Nsrt *) a)->t); + float8KEY *ib = (float8KEY *) (((Nsrt *) b)->t); if (ia->lower == ib->lower) { diff --git a/contrib/btree_gist/btree_inet.c b/contrib/btree_gist/btree_inet.c index a77864abeb5..a8d18c578ba 100644 --- a/contrib/btree_gist/btree_inet.c +++ b/contrib/btree_gist/btree_inet.c @@ -1,5 +1,5 @@ /* - * $PostgreSQL: pgsql/contrib/btree_gist/btree_inet.c,v 1.11 2009/12/02 13:13:24 teodor Exp $ + * $PostgreSQL: pgsql/contrib/btree_gist/btree_inet.c,v 1.12 2010/02/26 02:00:31 momjian Exp $ */ #include "btree_gist.h" #include "btree_utils_num.h" @@ -60,8 +60,8 @@ gbt_inetlt(const void *a, const void *b) static int gbt_inetkey_cmp(const void *a, const void *b) { - inetKEY *ia = (inetKEY*)(((Nsrt *) a)->t); - inetKEY *ib = (inetKEY*)(((Nsrt *) b)->t); + inetKEY *ia = (inetKEY *) (((Nsrt *) a)->t); + inetKEY *ib = (inetKEY *) (((Nsrt *) b)->t); if (ia->lower == ib->lower) { diff --git a/contrib/btree_gist/btree_int2.c b/contrib/btree_gist/btree_int2.c index 2aeb94b169d..2be4c40aa8d 100644 --- a/contrib/btree_gist/btree_int2.c +++ b/contrib/btree_gist/btree_int2.c @@ -1,5 +1,5 @@ /* - * $PostgreSQL: pgsql/contrib/btree_gist/btree_int2.c,v 1.9 2009/12/02 13:13:24 teodor Exp $ + * $PostgreSQL: pgsql/contrib/btree_gist/btree_int2.c,v 1.10 2010/02/26 02:00:31 momjian Exp $ */ #include "btree_gist.h" #include "btree_utils_num.h" @@ -56,8 +56,8 @@ gbt_int2lt(const void *a, const void *b) static int gbt_int2key_cmp(const void *a, const void *b) { - int16KEY *ia = (int16KEY*)(((Nsrt *) a)->t); - int16KEY *ib = (int16KEY*)(((Nsrt *) b)->t); + int16KEY *ia = (int16KEY *) (((Nsrt *) a)->t); + int16KEY *ib = (int16KEY *) (((Nsrt *) b)->t); if (ia->lower == ib->lower) { diff --git a/contrib/btree_gist/btree_int4.c b/contrib/btree_gist/btree_int4.c index 12a2c476a4d..aa0d4ac33fb 100644 --- a/contrib/btree_gist/btree_int4.c +++ b/contrib/btree_gist/btree_int4.c @@ -1,5 +1,5 @@ /* - * $PostgreSQL: pgsql/contrib/btree_gist/btree_int4.c,v 1.9 2009/12/02 13:13:24 teodor Exp $ + * $PostgreSQL: pgsql/contrib/btree_gist/btree_int4.c,v 1.10 2010/02/26 02:00:31 momjian Exp $ */ #include "btree_gist.h" #include "btree_utils_num.h" @@ -57,8 +57,8 @@ gbt_int4lt(const void *a, const void *b) static int gbt_int4key_cmp(const void *a, const void *b) { - int32KEY *ia = (int32KEY*)(((Nsrt *) a)->t); - int32KEY *ib = (int32KEY*)(((Nsrt *) b)->t); + int32KEY *ia = (int32KEY *) (((Nsrt *) a)->t); + int32KEY *ib = (int32KEY *) (((Nsrt *) b)->t); if (ia->lower == ib->lower) { diff --git a/contrib/btree_gist/btree_int8.c b/contrib/btree_gist/btree_int8.c index 10b119a004d..4cf36a07faa 100644 --- a/contrib/btree_gist/btree_int8.c +++ b/contrib/btree_gist/btree_int8.c @@ -1,5 +1,5 @@ /* - * $PostgreSQL: pgsql/contrib/btree_gist/btree_int8.c,v 1.9 2009/12/02 13:13:24 teodor Exp $ + * $PostgreSQL: pgsql/contrib/btree_gist/btree_int8.c,v 1.10 2010/02/26 02:00:31 momjian Exp $ */ #include "btree_gist.h" #include "btree_utils_num.h" @@ -57,8 +57,8 @@ gbt_int8lt(const void *a, const void *b) static int gbt_int8key_cmp(const void *a, const void *b) { - int64KEY *ia = (int64KEY*)(((Nsrt *) a)->t); - int64KEY *ib = (int64KEY*)(((Nsrt *) b)->t); + int64KEY *ia = (int64KEY *) (((Nsrt *) a)->t); + int64KEY *ib = (int64KEY *) (((Nsrt *) b)->t); if (ia->lower == ib->lower) { diff --git a/contrib/btree_gist/btree_interval.c b/contrib/btree_gist/btree_interval.c index 277835074b6..32b9ddbad74 100644 --- a/contrib/btree_gist/btree_interval.c +++ b/contrib/btree_gist/btree_interval.c @@ -1,5 +1,5 @@ /* - * $PostgreSQL: pgsql/contrib/btree_gist/btree_interval.c,v 1.13 2009/12/02 13:13:24 teodor Exp $ + * $PostgreSQL: pgsql/contrib/btree_gist/btree_interval.c,v 1.14 2010/02/26 02:00:31 momjian Exp $ */ #include "btree_gist.h" #include "btree_utils_num.h" @@ -65,9 +65,9 @@ gbt_intvlt(const void *a, const void *b) static int gbt_intvkey_cmp(const void *a, const void *b) { - intvKEY *ia = (intvKEY*)(((Nsrt *) a)->t); - intvKEY *ib = (intvKEY*)(((Nsrt *) b)->t); - int res; + intvKEY *ia = (intvKEY *) (((Nsrt *) a)->t); + intvKEY *ib = (intvKEY *) (((Nsrt *) b)->t); + int res; res = DatumGetInt32(DirectFunctionCall2(interval_cmp, IntervalPGetDatum(&ia->lower), IntervalPGetDatum(&ib->lower))); if (res == 0) diff --git a/contrib/btree_gist/btree_macaddr.c b/contrib/btree_gist/btree_macaddr.c index 2683e1454cf..60092b4e9e2 100644 --- a/contrib/btree_gist/btree_macaddr.c +++ b/contrib/btree_gist/btree_macaddr.c @@ -1,5 +1,5 @@ /* - * $PostgreSQL: pgsql/contrib/btree_gist/btree_macaddr.c,v 1.9 2009/12/02 13:13:24 teodor Exp $ + * $PostgreSQL: pgsql/contrib/btree_gist/btree_macaddr.c,v 1.10 2010/02/26 02:00:31 momjian Exp $ */ #include "btree_gist.h" #include "btree_utils_num.h" @@ -63,9 +63,9 @@ gbt_macadlt(const void *a, const void *b) static int gbt_macadkey_cmp(const void *a, const void *b) { - macKEY *ia = (macKEY*)(((Nsrt *) a)->t); - macKEY *ib = (macKEY*)(((Nsrt *) b)->t); - int res; + macKEY *ia = (macKEY *) (((Nsrt *) a)->t); + macKEY *ib = (macKEY *) (((Nsrt *) b)->t); + int res; res = DatumGetInt32(DirectFunctionCall2(macaddr_cmp, MacaddrPGetDatum(&ia->lower), MacaddrPGetDatum(&ib->lower))); if (res == 0) diff --git a/contrib/btree_gist/btree_oid.c b/contrib/btree_gist/btree_oid.c index 11327c29be4..96e4be54d4b 100644 --- a/contrib/btree_gist/btree_oid.c +++ b/contrib/btree_gist/btree_oid.c @@ -1,5 +1,5 @@ /* - * $PostgreSQL: pgsql/contrib/btree_gist/btree_oid.c,v 1.9 2009/12/02 13:13:24 teodor Exp $ + * $PostgreSQL: pgsql/contrib/btree_gist/btree_oid.c,v 1.10 2010/02/26 02:00:31 momjian Exp $ */ #include "btree_gist.h" #include "btree_utils_num.h" @@ -57,8 +57,8 @@ gbt_oidlt(const void *a, const void *b) static int gbt_oidkey_cmp(const void *a, const void *b) { - oidKEY *ia = (oidKEY*)(((Nsrt *) a)->t); - oidKEY *ib = (oidKEY*)(((Nsrt *) b)->t); + oidKEY *ia = (oidKEY *) (((Nsrt *) a)->t); + oidKEY *ib = (oidKEY *) (((Nsrt *) b)->t); if (ia->lower == ib->lower) { diff --git a/contrib/btree_gist/btree_time.c b/contrib/btree_gist/btree_time.c index 25c756588be..8566a8efb70 100644 --- a/contrib/btree_gist/btree_time.c +++ b/contrib/btree_gist/btree_time.c @@ -1,5 +1,5 @@ /* - * $PostgreSQL: pgsql/contrib/btree_gist/btree_time.c,v 1.17 2009/12/02 13:13:24 teodor Exp $ + * $PostgreSQL: pgsql/contrib/btree_gist/btree_time.c,v 1.18 2010/02/26 02:00:31 momjian Exp $ */ #include "btree_gist.h" #include "btree_utils_num.h" @@ -101,9 +101,9 @@ gbt_timelt(const void *a, const void *b) static int gbt_timekey_cmp(const void *a, const void *b) { - timeKEY *ia = (timeKEY*)(((Nsrt *) a)->t); - timeKEY *ib = (timeKEY*)(((Nsrt *) b)->t); - int res; + timeKEY *ia = (timeKEY *) (((Nsrt *) a)->t); + timeKEY *ib = (timeKEY *) (((Nsrt *) b)->t); + int res; res = DatumGetInt32(DirectFunctionCall2(time_cmp, TimeADTGetDatumFast(ia->lower), TimeADTGetDatumFast(ib->lower))); if (res == 0) diff --git a/contrib/btree_gist/btree_ts.c b/contrib/btree_gist/btree_ts.c index 9b5dfba8cc8..543f2129b0b 100644 --- a/contrib/btree_gist/btree_ts.c +++ b/contrib/btree_gist/btree_ts.c @@ -1,5 +1,5 @@ /* - * $PostgreSQL: pgsql/contrib/btree_gist/btree_ts.c,v 1.18 2009/12/02 13:13:24 teodor Exp $ + * $PostgreSQL: pgsql/contrib/btree_gist/btree_ts.c,v 1.19 2010/02/26 02:00:32 momjian Exp $ */ #include "btree_gist.h" #include "btree_utils_num.h" @@ -99,9 +99,9 @@ gbt_tslt(const void *a, const void *b) static int gbt_tskey_cmp(const void *a, const void *b) { - tsKEY *ia = (tsKEY*)(((Nsrt *) a)->t); - tsKEY *ib = (tsKEY*)(((Nsrt *) b)->t); - int res; + tsKEY *ia = (tsKEY *) (((Nsrt *) a)->t); + tsKEY *ib = (tsKEY *) (((Nsrt *) b)->t); + int res; res = DatumGetInt32(DirectFunctionCall2(timestamp_cmp, TimestampGetDatumFast(ia->lower), TimestampGetDatumFast(ib->lower))); if (res == 0) diff --git a/contrib/btree_gist/btree_utils_var.c b/contrib/btree_gist/btree_utils_var.c index f5f490bf4e9..916706d8a47 100644 --- a/contrib/btree_gist/btree_utils_var.c +++ b/contrib/btree_gist/btree_utils_var.c @@ -1,5 +1,5 @@ /* - * $PostgreSQL: pgsql/contrib/btree_gist/btree_utils_var.c,v 1.22 2009/12/02 13:13:24 teodor Exp $ + * $PostgreSQL: pgsql/contrib/btree_gist/btree_utils_var.c,v 1.23 2010/02/26 02:00:32 momjian Exp $ */ #include "btree_gist.h" @@ -444,7 +444,7 @@ gbt_vsrt_cmp(const void *a, const void *b, void *arg) GBT_VARKEY_R ar = gbt_var_key_readable(((const Vsrt *) a)->t); GBT_VARKEY_R br = gbt_var_key_readable(((const Vsrt *) b)->t); const gbtree_vinfo *tinfo = (const gbtree_vinfo *) arg; - int res; + int res; res = (*tinfo->f_cmp) (ar.lower, br.lower); if (res == 0) diff --git a/contrib/dblink/dblink.c b/contrib/dblink/dblink.c index f9dfba8da6b..abe64f3daec 100644 --- a/contrib/dblink/dblink.c +++ b/contrib/dblink/dblink.c @@ -8,7 +8,7 @@ * Darko Prenosil <Darko.Prenosil@finteh.hr> * Shridhar Daithankar <shridhar_daithankar@persistent.co.in> * - * $PostgreSQL: pgsql/contrib/dblink/dblink.c,v 1.90 2010/02/24 05:20:49 itagaki Exp $ + * $PostgreSQL: pgsql/contrib/dblink/dblink.c,v 1.91 2010/02/26 02:00:32 momjian Exp $ * Copyright (c) 2001-2010, PostgreSQL Global Development Group * ALL RIGHTS RESERVED; * @@ -101,7 +101,7 @@ static void dblink_security_check(PGconn *conn, remoteConn *rconn); static void dblink_res_error(const char *conname, PGresult *res, const char *dblink_context_msg, bool fail); static char *get_connect_string(const char *servername); static char *escape_param_str(const char *from); -static int get_nondropped_natts(Oid relid); +static int get_nondropped_natts(Oid relid); /* Global */ static remoteConn *pconn = NULL; @@ -506,15 +506,15 @@ PG_FUNCTION_INFO_V1(dblink_fetch); Datum dblink_fetch(PG_FUNCTION_ARGS) { - ReturnSetInfo *rsinfo = (ReturnSetInfo *) fcinfo->resultinfo; - PGresult *res = NULL; - char *conname = NULL; - remoteConn *rconn = NULL; - PGconn *conn = NULL; - StringInfoData buf; - char *curname = NULL; - int howmany = 0; - bool fail = true; /* default to backward compatible */ + ReturnSetInfo *rsinfo = (ReturnSetInfo *) fcinfo->resultinfo; + PGresult *res = NULL; + char *conname = NULL; + remoteConn *rconn = NULL; + PGconn *conn = NULL; + StringInfoData buf; + char *curname = NULL; + int howmany = 0; + bool fail = true; /* default to backward compatible */ DBLINK_INIT; @@ -572,8 +572,8 @@ dblink_fetch(PG_FUNCTION_ARGS) /* * Try to execute the query. Note that since libpq uses malloc, the - * PGresult will be long-lived even though we are still in a - * short-lived memory context. + * PGresult will be long-lived even though we are still in a short-lived + * memory context. */ res = PQexec(conn, buf.data); if (!res || @@ -645,16 +645,16 @@ dblink_get_result(PG_FUNCTION_ARGS) static Datum dblink_record_internal(FunctionCallInfo fcinfo, bool is_async) { - ReturnSetInfo *rsinfo = (ReturnSetInfo *) fcinfo->resultinfo; - char *msg; - PGresult *res = NULL; - PGconn *conn = NULL; - char *connstr = NULL; - char *sql = NULL; - char *conname = NULL; - remoteConn *rconn = NULL; - bool fail = true; /* default to backward compatible */ - bool freeconn = false; + ReturnSetInfo *rsinfo = (ReturnSetInfo *) fcinfo->resultinfo; + char *msg; + PGresult *res = NULL; + PGconn *conn = NULL; + char *connstr = NULL; + char *sql = NULL; + char *conname = NULL; + remoteConn *rconn = NULL; + bool fail = true; /* default to backward compatible */ + bool freeconn = false; /* check to see if caller supports us returning a tuplestore */ if (rsinfo == NULL || !IsA(rsinfo, ReturnSetInfo)) @@ -764,7 +764,7 @@ dblink_record_internal(FunctionCallInfo fcinfo, bool is_async) static void materializeResult(FunctionCallInfo fcinfo, PGresult *res) { - ReturnSetInfo *rsinfo = (ReturnSetInfo *) fcinfo->resultinfo; + ReturnSetInfo *rsinfo = (ReturnSetInfo *) fcinfo->resultinfo; Assert(rsinfo->returnMode == SFRM_Materialize); @@ -780,8 +780,8 @@ materializeResult(FunctionCallInfo fcinfo, PGresult *res) is_sql_cmd = true; /* - * need a tuple descriptor representing one TEXT column to - * return the command status string as our result tuple + * need a tuple descriptor representing one TEXT column to return + * the command status string as our result tuple */ tupdesc = CreateTemplateTupleDesc(1, false); TupleDescInitEntry(tupdesc, (AttrNumber) 1, "status", @@ -831,16 +831,16 @@ materializeResult(FunctionCallInfo fcinfo, PGresult *res) if (ntuples > 0) { - AttInMetadata *attinmeta; - Tuplestorestate *tupstore; - MemoryContext oldcontext; - int row; - char **values; + AttInMetadata *attinmeta; + Tuplestorestate *tupstore; + MemoryContext oldcontext; + int row; + char **values; attinmeta = TupleDescGetAttInMetadata(tupdesc); oldcontext = MemoryContextSwitchTo( - rsinfo->econtext->ecxt_per_query_memory); + rsinfo->econtext->ecxt_per_query_memory); tupstore = tuplestore_begin_heap(true, false, work_mem); rsinfo->setResult = tupstore; rsinfo->setDesc = tupdesc; @@ -1281,13 +1281,13 @@ dblink_build_sql_insert(PG_FUNCTION_ARGS) "attributes too large"))); /* - * ensure we don't ask for more pk attributes than we have - * non-dropped columns + * ensure we don't ask for more pk attributes than we have non-dropped + * columns */ nondropped_natts = get_nondropped_natts(relid); if (pknumatts > nondropped_natts) ereport(ERROR, (errcode(ERRCODE_SYNTAX_ERROR), - errmsg("number of primary key fields exceeds number of specified relation attributes"))); + errmsg("number of primary key fields exceeds number of specified relation attributes"))); /* * Source array is made up of key values that will be used to locate the @@ -1388,13 +1388,13 @@ dblink_build_sql_delete(PG_FUNCTION_ARGS) "attributes too large"))); /* - * ensure we don't ask for more pk attributes than we have - * non-dropped columns + * ensure we don't ask for more pk attributes than we have non-dropped + * columns */ nondropped_natts = get_nondropped_natts(relid); if (pknumatts > nondropped_natts) ereport(ERROR, (errcode(ERRCODE_SYNTAX_ERROR), - errmsg("number of primary key fields exceeds number of specified relation attributes"))); + errmsg("number of primary key fields exceeds number of specified relation attributes"))); /* * Target array is made up of key values that will be used to build the @@ -1487,13 +1487,13 @@ dblink_build_sql_update(PG_FUNCTION_ARGS) "attributes too large"))); /* - * ensure we don't ask for more pk attributes than we have - * non-dropped columns + * ensure we don't ask for more pk attributes than we have non-dropped + * columns */ nondropped_natts = get_nondropped_natts(relid); if (pknumatts > nondropped_natts) ereport(ERROR, (errcode(ERRCODE_SYNTAX_ERROR), - errmsg("number of primary key fields exceeds number of specified relation attributes"))); + errmsg("number of primary key fields exceeds number of specified relation attributes"))); /* * Source array is made up of key values that will be used to locate the @@ -1551,7 +1551,7 @@ dblink_current_query(PG_FUNCTION_ARGS) } /* - * Retrieve async notifications for a connection. + * Retrieve async notifications for a connection. * * Returns an setof record of notifications, or an empty set if none recieved. * Can optionally take a named connection as parameter, but uses the unnamed connection per default. @@ -1563,14 +1563,14 @@ PG_FUNCTION_INFO_V1(dblink_get_notify); Datum dblink_get_notify(PG_FUNCTION_ARGS) { - PGconn *conn = NULL; - remoteConn *rconn = NULL; - PGnotify *notify; - ReturnSetInfo *rsinfo = (ReturnSetInfo *) fcinfo->resultinfo; - TupleDesc tupdesc; - Tuplestorestate *tupstore; - MemoryContext per_query_ctx; - MemoryContext oldcontext; + PGconn *conn = NULL; + remoteConn *rconn = NULL; + PGnotify *notify; + ReturnSetInfo *rsinfo = (ReturnSetInfo *) fcinfo->resultinfo; + TupleDesc tupdesc; + Tuplestorestate *tupstore; + MemoryContext per_query_ctx; + MemoryContext oldcontext; DBLINK_INIT; if (PG_NARGS() == 1) @@ -2484,4 +2484,3 @@ get_nondropped_natts(Oid relid) relation_close(rel, AccessShareLock); return nondropped_natts; } - diff --git a/contrib/dict_xsyn/dict_xsyn.c b/contrib/dict_xsyn/dict_xsyn.c index 8c972484efe..dc16d9583e2 100644 --- a/contrib/dict_xsyn/dict_xsyn.c +++ b/contrib/dict_xsyn/dict_xsyn.c @@ -6,7 +6,7 @@ * Copyright (c) 2007-2010, PostgreSQL Global Development Group * * IDENTIFICATION - * $PostgreSQL: pgsql/contrib/dict_xsyn/dict_xsyn.c,v 1.8 2010/01/02 16:57:32 momjian Exp $ + * $PostgreSQL: pgsql/contrib/dict_xsyn/dict_xsyn.c,v 1.9 2010/02/26 02:00:32 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -147,7 +147,7 @@ dxsyn_init(PG_FUNCTION_ARGS) List *dictoptions = (List *) PG_GETARG_POINTER(0); DictSyn *d; ListCell *l; - char *filename = NULL; + char *filename = NULL; d = (DictSyn *) palloc0(sizeof(DictSyn)); d->len = 0; diff --git a/contrib/hstore/hstore.h b/contrib/hstore/hstore.h index 495ac1afc9b..796dce575e5 100644 --- a/contrib/hstore/hstore.h +++ b/contrib/hstore/hstore.h @@ -1,5 +1,5 @@ /* - * $PostgreSQL: pgsql/contrib/hstore/hstore.h,v 1.9 2009/09/30 19:50:22 tgl Exp $ + * $PostgreSQL: pgsql/contrib/hstore/hstore.h,v 1.10 2010/02/26 02:00:32 momjian Exp $ */ #ifndef __HSTORE_H__ #define __HSTORE_H__ @@ -12,7 +12,7 @@ * HEntry: there is one of these for each key _and_ value in an hstore * * the position offset points to the _end_ so that we can get the length - * by subtraction from the previous entry. the ISFIRST flag lets us tell + * by subtraction from the previous entry. the ISFIRST flag lets us tell * whether there is a previous entry. */ typedef struct @@ -51,7 +51,7 @@ typedef struct /* * it's not possible to get more than 2^28 items into an hstore, * so we reserve the top few bits of the size field. See hstore_compat.c - * for one reason why. Some bits are left for future use here. + * for one reason why. Some bits are left for future use here. */ #define HS_FLAG_NEWVERSION 0x80000000 @@ -88,7 +88,7 @@ typedef struct * evaluation here. */ #define HS_COPYITEM(dent_,dbuf_,dptr_,sptr_,klen_,vlen_,vnull_) \ - do { \ + do { \ memcpy((dptr_), (sptr_), (klen_)+(vlen_)); \ (dptr_) += (klen_)+(vlen_); \ (dent_)++->entry = ((dptr_) - (dbuf_) - (vlen_)) & HENTRY_POSMASK; \ @@ -119,7 +119,7 @@ typedef struct /* finalize a newly-constructed hstore */ #define HS_FINALIZE(hsp_,count_,buf_,ptr_) \ do { \ - int buflen = (ptr_) - (buf_); \ + int buflen = (ptr_) - (buf_); \ if ((count_)) \ ARRPTR(hsp_)[0].entry |= HENTRY_ISFIRST; \ if ((count_) != HS_COUNT((hsp_))) \ @@ -133,7 +133,7 @@ typedef struct /* ensure the varlena size of an existing hstore is correct */ #define HS_FIXSIZE(hsp_,count_) \ do { \ - int bl = (count_) ? HSE_ENDPOS(ARRPTR(hsp_)[2*(count_)-1]) : 0; \ + int bl = (count_) ? HSE_ENDPOS(ARRPTR(hsp_)[2*(count_)-1]) : 0; \ SET_VARSIZE((hsp_), CALCDATASIZE((count_),bl)); \ } while (0) @@ -172,7 +172,7 @@ extern Pairs *hstoreArrayToPairs(ArrayType *a, int *npairs); #define HStoreExistsStrategyNumber 9 #define HStoreExistsAnyStrategyNumber 10 #define HStoreExistsAllStrategyNumber 11 -#define HStoreOldContainsStrategyNumber 13 /* backwards compatibility */ +#define HStoreOldContainsStrategyNumber 13 /* backwards compatibility */ /* * defining HSTORE_POLLUTE_NAMESPACE=0 will prevent use of old function names; diff --git a/contrib/hstore/hstore_compat.c b/contrib/hstore/hstore_compat.c index e2c2b55c100..033d945f9ca 100644 --- a/contrib/hstore/hstore_compat.c +++ b/contrib/hstore/hstore_compat.c @@ -1,5 +1,5 @@ /* - * $PostgreSQL: pgsql/contrib/hstore/hstore_compat.c,v 1.1 2009/09/30 19:50:22 tgl Exp $ + * $PostgreSQL: pgsql/contrib/hstore/hstore_compat.c,v 1.2 2010/02/26 02:00:32 momjian Exp $ * * Notes on old/new hstore format disambiguation. * @@ -106,24 +106,24 @@ typedef struct pos:31; } HOldEntry; -static int hstoreValidNewFormat(HStore *hs); -static int hstoreValidOldFormat(HStore *hs); +static int hstoreValidNewFormat(HStore *hs); +static int hstoreValidOldFormat(HStore *hs); /* * Validity test for a new-format hstore. - * 0 = not valid - * 1 = valid but with "slop" in the length - * 2 = exactly valid + * 0 = not valid + * 1 = valid but with "slop" in the length + * 2 = exactly valid */ static int hstoreValidNewFormat(HStore *hs) { - int count = HS_COUNT(hs); - HEntry *entries = ARRPTR(hs); - int buflen = (count) ? HSE_ENDPOS(entries[2*(count)-1]) : 0; - int vsize = CALCDATASIZE(count,buflen); - int i; + int count = HS_COUNT(hs); + HEntry *entries = ARRPTR(hs); + int buflen = (count) ? HSE_ENDPOS(entries[2 * (count) - 1]) : 0; + int vsize = CALCDATASIZE(count, buflen); + int i; if (hs->size_ & HS_FLAG_NEWVERSION) return 2; @@ -139,10 +139,10 @@ hstoreValidNewFormat(HStore *hs) /* entry position must be nondecreasing */ - for (i = 1; i < 2*count; ++i) + for (i = 1; i < 2 * count; ++i) { if (HSE_ISFIRST(entries[i]) - || (HSE_ENDPOS(entries[i]) < HSE_ENDPOS(entries[i-1]))) + || (HSE_ENDPOS(entries[i]) < HSE_ENDPOS(entries[i - 1]))) return 0; } @@ -150,9 +150,9 @@ hstoreValidNewFormat(HStore *hs) for (i = 1; i < count; ++i) { - if (HS_KEYLEN(entries,i) < HS_KEYLEN(entries,i-1)) + if (HS_KEYLEN(entries, i) < HS_KEYLEN(entries, i - 1)) return 0; - if (HSE_ISNULL(entries[2*i])) + if (HSE_ISNULL(entries[2 * i])) return 0; } @@ -164,18 +164,18 @@ hstoreValidNewFormat(HStore *hs) /* * Validity test for an old-format hstore. - * 0 = not valid - * 1 = valid but with "slop" in the length - * 2 = exactly valid + * 0 = not valid + * 1 = valid but with "slop" in the length + * 2 = exactly valid */ static int hstoreValidOldFormat(HStore *hs) { - int count = hs->size_; - HOldEntry *entries = (HOldEntry *) ARRPTR(hs); - int vsize; - int lastpos = 0; - int i; + int count = hs->size_; + HOldEntry *entries = (HOldEntry *) ARRPTR(hs); + int vsize; + int lastpos = 0; + int i; if (hs->size_ & HS_FLAG_NEWVERSION) return 0; @@ -188,7 +188,7 @@ hstoreValidOldFormat(HStore *hs) if (count > 0xFFFFFFF) return 0; - if (CALCDATASIZE(count,0) > VARSIZE(hs)) + if (CALCDATASIZE(count, 0) > VARSIZE(hs)) return 0; if (entries[0].pos != 0) @@ -198,14 +198,14 @@ hstoreValidOldFormat(HStore *hs) for (i = 1; i < count; ++i) { - if (entries[i].keylen < entries[i-1].keylen) + if (entries[i].keylen < entries[i - 1].keylen) return 0; } /* - * entry position must be strictly increasing, except for the - * first entry (which can be ""=>"" and thus zero-length); and - * all entries must be properly contiguous + * entry position must be strictly increasing, except for the first entry + * (which can be ""=>"" and thus zero-length); and all entries must be + * properly contiguous */ for (i = 0; i < count; ++i) @@ -216,7 +216,7 @@ hstoreValidOldFormat(HStore *hs) + ((entries[i].valisnull) ? 0 : entries[i].vallen)); } - vsize = CALCDATASIZE(count,lastpos); + vsize = CALCDATASIZE(count, lastpos); if (vsize > VARSIZE(hs)) return 0; @@ -255,108 +255,100 @@ hstoreUpgrade(Datum orig) if (valid_new) { /* - * force the "new version" flag and the correct varlena - * length, but only if we have a writable copy already - * (which we almost always will, since short new-format - * values won't come through here) + * force the "new version" flag and the correct varlena length, + * but only if we have a writable copy already (which we almost + * always will, since short new-format values won't come through + * here) */ if (writable) { - HS_SETCOUNT(hs,HS_COUNT(hs)); - HS_FIXSIZE(hs,HS_COUNT(hs)); + HS_SETCOUNT(hs, HS_COUNT(hs)); + HS_FIXSIZE(hs, HS_COUNT(hs)); } return hs; } else { - elog(ERROR,"invalid hstore value found"); + elog(ERROR, "invalid hstore value found"); } } /* - * this is the tricky edge case. It is only possible in some - * quite extreme cases (the hstore must have had a lot - * of wasted padding space at the end). - * But the only way a "new" hstore value could get here is if - * we're upgrading in place from a pre-release version of - * hstore-new (NOT contrib/hstore), so we work off the following - * assumptions: - * 1. If you're moving from old contrib/hstore to hstore-new, - * you're required to fix up any potential conflicts first, - * e.g. by running ALTER TABLE ... USING col::text::hstore; - * on all hstore columns before upgrading. - * 2. If you're moving from old contrib/hstore to new - * contrib/hstore, then "new" values are impossible here - * 3. If you're moving from pre-release hstore-new to hstore-new, - * then "old" values are impossible here - * 4. If you're moving from pre-release hstore-new to new - * contrib/hstore, you're not doing so as an in-place upgrade, - * so there is no issue - * So the upshot of all this is that we can treat all the edge - * cases as "new" if we're being built as hstore-new, and "old" - * if we're being built as contrib/hstore. + * this is the tricky edge case. It is only possible in some quite extreme + * cases (the hstore must have had a lot of wasted padding space at the + * end). But the only way a "new" hstore value could get here is if we're + * upgrading in place from a pre-release version of hstore-new (NOT + * contrib/hstore), so we work off the following assumptions: 1. If you're + * moving from old contrib/hstore to hstore-new, you're required to fix up + * any potential conflicts first, e.g. by running ALTER TABLE ... USING + * col::text::hstore; on all hstore columns before upgrading. 2. If you're + * moving from old contrib/hstore to new contrib/hstore, then "new" values + * are impossible here 3. If you're moving from pre-release hstore-new to + * hstore-new, then "old" values are impossible here 4. If you're moving + * from pre-release hstore-new to new contrib/hstore, you're not doing so + * as an in-place upgrade, so there is no issue So the upshot of all this + * is that we can treat all the edge cases as "new" if we're being built + * as hstore-new, and "old" if we're being built as contrib/hstore. * - * XXX the WARNING can probably be downgraded to DEBUG1 once this - * has been beta-tested. But for now, it would be very useful to - * know if anyone can actually reach this case in a non-contrived - * setting. + * XXX the WARNING can probably be downgraded to DEBUG1 once this has been + * beta-tested. But for now, it would be very useful to know if anyone can + * actually reach this case in a non-contrived setting. */ if (valid_new) { #if HSTORE_IS_HSTORE_NEW - elog(WARNING,"ambiguous hstore value resolved as hstore-new"); + elog(WARNING, "ambiguous hstore value resolved as hstore-new"); /* - * force the "new version" flag and the correct varlena - * length, but only if we have a writable copy already - * (which we almost always will, since short new-format - * values won't come through here) + * force the "new version" flag and the correct varlena length, but + * only if we have a writable copy already (which we almost always + * will, since short new-format values won't come through here) */ if (writable) { - HS_SETCOUNT(hs,HS_COUNT(hs)); - HS_FIXSIZE(hs,HS_COUNT(hs)); + HS_SETCOUNT(hs, HS_COUNT(hs)); + HS_FIXSIZE(hs, HS_COUNT(hs)); } return hs; #else - elog(WARNING,"ambiguous hstore value resolved as hstore-old"); + elog(WARNING, "ambiguous hstore value resolved as hstore-old"); #endif } /* - * must have an old-style value. Overwrite it in place as a new-style - * one, making sure we have a writable copy first. + * must have an old-style value. Overwrite it in place as a new-style one, + * making sure we have a writable copy first. */ if (!writable) hs = (HStore *) PG_DETOAST_DATUM_COPY(orig); { - int count = hs->size_; - HEntry *new_entries = ARRPTR(hs); - HOldEntry *old_entries = (HOldEntry *) ARRPTR(hs); - int i; - + int count = hs->size_; + HEntry *new_entries = ARRPTR(hs); + HOldEntry *old_entries = (HOldEntry *) ARRPTR(hs); + int i; + for (i = 0; i < count; ++i) { - uint32 pos = old_entries[i].pos; - uint32 keylen = old_entries[i].keylen; - uint32 vallen = old_entries[i].vallen; - bool isnull = old_entries[i].valisnull; + uint32 pos = old_entries[i].pos; + uint32 keylen = old_entries[i].keylen; + uint32 vallen = old_entries[i].vallen; + bool isnull = old_entries[i].valisnull; if (isnull) vallen = 0; - new_entries[2*i].entry = (pos + keylen) & HENTRY_POSMASK; - new_entries[2*i+1].entry = (((pos + keylen + vallen) & HENTRY_POSMASK) - | ((isnull) ? HENTRY_ISNULL : 0)); + new_entries[2 * i].entry = (pos + keylen) & HENTRY_POSMASK; + new_entries[2 * i + 1].entry = (((pos + keylen + vallen) & HENTRY_POSMASK) + | ((isnull) ? HENTRY_ISNULL : 0)); } if (count) new_entries[0].entry |= HENTRY_ISFIRST; - HS_SETCOUNT(hs,count); - HS_FIXSIZE(hs,count); + HS_SETCOUNT(hs, count); + HS_FIXSIZE(hs, count); } return hs; @@ -368,9 +360,9 @@ Datum hstore_version_diag(PG_FUNCTION_ARGS); Datum hstore_version_diag(PG_FUNCTION_ARGS) { - HStore *hs = (HStore *) PG_DETOAST_DATUM(PG_GETARG_DATUM(0)); - int valid_new = hstoreValidNewFormat(hs); - int valid_old = hstoreValidOldFormat(hs); + HStore *hs = (HStore *) PG_DETOAST_DATUM(PG_GETARG_DATUM(0)); + int valid_new = hstoreValidNewFormat(hs); + int valid_old = hstoreValidOldFormat(hs); - PG_RETURN_INT32(valid_old*10 + valid_new); + PG_RETURN_INT32(valid_old * 10 + valid_new); } diff --git a/contrib/hstore/hstore_gin.c b/contrib/hstore/hstore_gin.c index 3bd9d718bb3..f5056f53ec6 100644 --- a/contrib/hstore/hstore_gin.c +++ b/contrib/hstore/hstore_gin.c @@ -1,5 +1,5 @@ /* - * $PostgreSQL: pgsql/contrib/hstore/hstore_gin.c,v 1.7 2009/09/30 19:50:22 tgl Exp $ + * $PostgreSQL: pgsql/contrib/hstore/hstore_gin.c,v 1.8 2010/02/26 02:00:32 momjian Exp $ */ #include "postgres.h" @@ -36,10 +36,10 @@ gin_extract_hstore(PG_FUNCTION_ARGS) HStore *hs = PG_GETARG_HS(0); int32 *nentries = (int32 *) PG_GETARG_POINTER(1); Datum *entries = NULL; - HEntry *hsent = ARRPTR(hs); - char *ptr = STRPTR(hs); - int count = HS_COUNT(hs); - int i; + HEntry *hsent = ARRPTR(hs); + char *ptr = STRPTR(hs); + int count = HS_COUNT(hs); + int i; *nentries = 2 * count; if (count) @@ -49,21 +49,21 @@ gin_extract_hstore(PG_FUNCTION_ARGS) { text *item; - item = makeitem(HS_KEY(hsent,ptr,i), HS_KEYLEN(hsent,i)); + item = makeitem(HS_KEY(hsent, ptr, i), HS_KEYLEN(hsent, i)); *VARDATA(item) = KEYFLAG; - entries[2*i] = PointerGetDatum(item); + entries[2 * i] = PointerGetDatum(item); - if (HS_VALISNULL(hsent,i)) + if (HS_VALISNULL(hsent, i)) { item = makeitem(NULL, 0); *VARDATA(item) = NULLFLAG; } else { - item = makeitem(HS_VAL(hsent,ptr,i), HS_VALLEN(hsent,i)); + item = makeitem(HS_VAL(hsent, ptr, i), HS_VALLEN(hsent, i)); *VARDATA(item) = VALFLAG; } - entries[2*i+1] = PointerGetDatum(item); + entries[2 * i + 1] = PointerGetDatum(item); } PG_RETURN_POINTER(entries); @@ -103,14 +103,15 @@ gin_extract_hstore_query(PG_FUNCTION_ARGS) else if (strategy == HStoreExistsAnyStrategyNumber || strategy == HStoreExistsAllStrategyNumber) { - ArrayType *query = PG_GETARG_ARRAYTYPE_P(0); - Datum *key_datums; - bool *key_nulls; - int key_count; - int i,j; + ArrayType *query = PG_GETARG_ARRAYTYPE_P(0); + Datum *key_datums; + bool *key_nulls; + int key_count; + int i, + j; int32 *nentries = (int32 *) PG_GETARG_POINTER(1); Datum *entries = NULL; - text *item; + text *item; deconstruct_array(query, TEXTOID, -1, false, 'i', @@ -145,8 +146,10 @@ gin_consistent_hstore(PG_FUNCTION_ARGS) { bool *check = (bool *) PG_GETARG_POINTER(0); StrategyNumber strategy = PG_GETARG_UINT16(1); + /* HStore *query = PG_GETARG_HS(2); */ int32 nkeys = PG_GETARG_INT32(3); + /* Pointer *extra_data = (Pointer *) PG_GETARG_POINTER(4); */ bool *recheck = (bool *) PG_GETARG_POINTER(5); bool res = true; @@ -178,7 +181,7 @@ gin_consistent_hstore(PG_FUNCTION_ARGS) } else if (strategy == HStoreExistsAllStrategyNumber) { - int i; + int i; for (i = 0; res && i < nkeys; ++i) if (!check[i]) diff --git a/contrib/hstore/hstore_gist.c b/contrib/hstore/hstore_gist.c index b036fa932f2..db58fb62ddf 100644 --- a/contrib/hstore/hstore_gist.c +++ b/contrib/hstore/hstore_gist.c @@ -1,5 +1,5 @@ /* - * $PostgreSQL: pgsql/contrib/hstore/hstore_gist.c,v 1.11 2009/09/30 19:50:22 tgl Exp $ + * $PostgreSQL: pgsql/contrib/hstore/hstore_gist.c,v 1.12 2010/02/26 02:00:32 momjian Exp $ */ #include "postgres.h" @@ -118,20 +118,20 @@ ghstore_compress(PG_FUNCTION_ARGS) HStore *val = DatumGetHStoreP(entry->key); HEntry *hsent = ARRPTR(val); char *ptr = STRPTR(val); - int count = HS_COUNT(val); - int i; + int count = HS_COUNT(val); + int i; SET_VARSIZE(res, CALCGTSIZE(0)); for (i = 0; i < count; ++i) { - int h; + int h; - h = crc32_sz((char *) HS_KEY(hsent,ptr,i), HS_KEYLEN(hsent,i)); + h = crc32_sz((char *) HS_KEY(hsent, ptr, i), HS_KEYLEN(hsent, i)); HASH(GETSIGN(res), h); - if (!HS_VALISNULL(hsent,i)) + if (!HS_VALISNULL(hsent, i)) { - h = crc32_sz((char *) HS_VAL(hsent,ptr,i), HS_VALLEN(hsent,i)); + h = crc32_sz((char *) HS_VAL(hsent, ptr, i), HS_VALLEN(hsent, i)); HASH(GETSIGN(res), h); } } @@ -511,6 +511,7 @@ ghstore_consistent(PG_FUNCTION_ARGS) { GISTTYPE *entry = (GISTTYPE *) DatumGetPointer(((GISTENTRY *) PG_GETARG_POINTER(0))->key); StrategyNumber strategy = (StrategyNumber) PG_GETARG_UINT16(2); + /* Oid subtype = PG_GETARG_OID(3); */ bool *recheck = (bool *) PG_GETARG_POINTER(4); bool res = true; @@ -530,18 +531,18 @@ ghstore_consistent(PG_FUNCTION_ARGS) HStore *query = PG_GETARG_HS(1); HEntry *qe = ARRPTR(query); char *qv = STRPTR(query); - int count = HS_COUNT(query); - int i; + int count = HS_COUNT(query); + int i; for (i = 0; res && i < count; ++i) { - int crc = crc32_sz((char *) HS_KEY(qe,qv,i), HS_KEYLEN(qe,i)); + int crc = crc32_sz((char *) HS_KEY(qe, qv, i), HS_KEYLEN(qe, i)); if (GETBIT(sign, HASHVAL(crc))) { - if (!HS_VALISNULL(qe,i)) + if (!HS_VALISNULL(qe, i)) { - crc = crc32_sz((char *) HS_VAL(qe,qv,i), HS_VALLEN(qe,i)); + crc = crc32_sz((char *) HS_VAL(qe, qv, i), HS_VALLEN(qe, i)); if (!GETBIT(sign, HASHVAL(crc))) res = false; } @@ -559,11 +560,11 @@ ghstore_consistent(PG_FUNCTION_ARGS) } else if (strategy == HStoreExistsAllStrategyNumber) { - ArrayType *query = PG_GETARG_ARRAYTYPE_P(1); - Datum *key_datums; - bool *key_nulls; - int key_count; - int i; + ArrayType *query = PG_GETARG_ARRAYTYPE_P(1); + Datum *key_datums; + bool *key_nulls; + int key_count; + int i; deconstruct_array(query, TEXTOID, -1, false, 'i', @@ -571,7 +572,8 @@ ghstore_consistent(PG_FUNCTION_ARGS) for (i = 0; res && i < key_count; ++i) { - int crc; + int crc; + if (key_nulls[i]) continue; crc = crc32_sz(VARDATA(key_datums[i]), VARSIZE(key_datums[i]) - VARHDRSZ); @@ -581,11 +583,11 @@ ghstore_consistent(PG_FUNCTION_ARGS) } else if (strategy == HStoreExistsAnyStrategyNumber) { - ArrayType *query = PG_GETARG_ARRAYTYPE_P(1); - Datum *key_datums; - bool *key_nulls; - int key_count; - int i; + ArrayType *query = PG_GETARG_ARRAYTYPE_P(1); + Datum *key_datums; + bool *key_nulls; + int key_count; + int i; deconstruct_array(query, TEXTOID, -1, false, 'i', @@ -595,7 +597,8 @@ ghstore_consistent(PG_FUNCTION_ARGS) for (i = 0; !res && i < key_count; ++i) { - int crc; + int crc; + if (key_nulls[i]) continue; crc = crc32_sz(VARDATA(key_datums[i]), VARSIZE(key_datums[i]) - VARHDRSZ); diff --git a/contrib/hstore/hstore_io.c b/contrib/hstore/hstore_io.c index a79cddef0af..fa6da693e94 100644 --- a/contrib/hstore/hstore_io.c +++ b/contrib/hstore/hstore_io.c @@ -1,5 +1,5 @@ /* - * $PostgreSQL: pgsql/contrib/hstore/hstore_io.c,v 1.12 2009/09/30 19:50:22 tgl Exp $ + * $PostgreSQL: pgsql/contrib/hstore/hstore_io.c,v 1.13 2010/02/26 02:00:32 momjian Exp $ */ #include "postgres.h" @@ -18,7 +18,7 @@ PG_MODULE_MAGIC; /* old names for C functions */ -HSTORE_POLLUTE(hstore_from_text,tconvert); +HSTORE_POLLUTE(hstore_from_text, tconvert); typedef struct @@ -370,12 +370,12 @@ hstoreCheckValLen(size_t len) HStore * hstorePairs(Pairs *pairs, int4 pcount, int4 buflen) { - HStore *out; + HStore *out; HEntry *entry; char *ptr; char *buf; - int4 len; - int4 i; + int4 len; + int4 i; len = CALCDATASIZE(pcount, buflen); out = palloc(len); @@ -389,9 +389,9 @@ hstorePairs(Pairs *pairs, int4 pcount, int4 buflen) buf = ptr = STRPTR(out); for (i = 0; i < pcount; i++) - HS_ADDITEM(entry,buf,ptr,pairs[i]); + HS_ADDITEM(entry, buf, ptr, pairs[i]); - HS_FINALIZE(out,pcount,buf,ptr); + HS_FINALIZE(out, pcount, buf, ptr); return out; } @@ -426,9 +426,9 @@ hstore_recv(PG_FUNCTION_ARGS) int4 buflen; HStore *out; Pairs *pairs; - int4 i; - int4 pcount; - StringInfo buf = (StringInfo) PG_GETARG_POINTER(0); + int4 i; + int4 pcount; + StringInfo buf = (StringInfo) PG_GETARG_POINTER(0); pcount = pq_getmsgint(buf, 4); @@ -442,8 +442,8 @@ hstore_recv(PG_FUNCTION_ARGS) for (i = 0; i < pcount; ++i) { - int rawlen = pq_getmsgint(buf, 4); - int len; + int rawlen = pq_getmsgint(buf, 4); + int len; if (rawlen < 0) ereport(ERROR, @@ -482,9 +482,9 @@ Datum hstore_from_text(PG_FUNCTION_ARGS); Datum hstore_from_text(PG_FUNCTION_ARGS) { - text *key; - text *val = NULL; - Pairs p; + text *key; + text *val = NULL; + Pairs p; HStore *out; if (PG_ARGISNULL(0)) @@ -524,13 +524,13 @@ hstore_from_arrays(PG_FUNCTION_ARGS) Pairs *pairs; Datum *key_datums; bool *key_nulls; - int key_count; + int key_count; Datum *value_datums; bool *value_nulls; - int value_count; + int value_count; ArrayType *key_array; ArrayType *value_array; - int i; + int i; if (PG_ARGISNULL(0)) PG_RETURN_NULL(); @@ -540,8 +540,8 @@ hstore_from_arrays(PG_FUNCTION_ARGS) Assert(ARR_ELEMTYPE(key_array) == TEXTOID); /* - * must check >1 rather than != 1 because empty arrays have - * 0 dimensions, not 1 + * must check >1 rather than != 1 because empty arrays have 0 dimensions, + * not 1 */ if (ARR_NDIM(key_array) > 1) @@ -631,15 +631,15 @@ Datum hstore_from_array(PG_FUNCTION_ARGS) { ArrayType *in_array = PG_GETARG_ARRAYTYPE_P(0); - int ndims = ARR_NDIM(in_array); - int count; + int ndims = ARR_NDIM(in_array); + int count; int4 buflen; HStore *out; Pairs *pairs; Datum *in_datums; bool *in_nulls; - int in_count; - int i; + int in_count; + int i; Assert(ARR_ELEMTYPE(in_array) == TEXTOID); @@ -667,7 +667,7 @@ hstore_from_array(PG_FUNCTION_ARGS) ereport(ERROR, (errcode(ERRCODE_ARRAY_SUBSCRIPT_ERROR), errmsg("wrong number of array subscripts"))); - } + } deconstruct_array(in_array, TEXTOID, -1, false, 'i', @@ -679,26 +679,26 @@ hstore_from_array(PG_FUNCTION_ARGS) for (i = 0; i < count; ++i) { - if (in_nulls[i*2]) + if (in_nulls[i * 2]) ereport(ERROR, (errcode(ERRCODE_NULL_VALUE_NOT_ALLOWED), errmsg("null value not allowed for hstore key"))); - if (in_nulls[i*2+1]) + if (in_nulls[i * 2 + 1]) { - pairs[i].key = VARDATA_ANY(in_datums[i*2]); + pairs[i].key = VARDATA_ANY(in_datums[i * 2]); pairs[i].val = NULL; - pairs[i].keylen = hstoreCheckKeyLen(VARSIZE_ANY_EXHDR(in_datums[i*2])); + pairs[i].keylen = hstoreCheckKeyLen(VARSIZE_ANY_EXHDR(in_datums[i * 2])); pairs[i].vallen = 4; pairs[i].isnull = true; pairs[i].needfree = false; } else { - pairs[i].key = VARDATA_ANY(in_datums[i*2]); - pairs[i].val = VARDATA_ANY(in_datums[i*2+1]); - pairs[i].keylen = hstoreCheckKeyLen(VARSIZE_ANY_EXHDR(in_datums[i*2])); - pairs[i].vallen = hstoreCheckValLen(VARSIZE_ANY_EXHDR(in_datums[i*2+1])); + pairs[i].key = VARDATA_ANY(in_datums[i * 2]); + pairs[i].val = VARDATA_ANY(in_datums[i * 2 + 1]); + pairs[i].keylen = hstoreCheckKeyLen(VARSIZE_ANY_EXHDR(in_datums[i * 2])); + pairs[i].vallen = hstoreCheckValLen(VARSIZE_ANY_EXHDR(in_datums[i * 2 + 1])); pairs[i].isnull = false; pairs[i].needfree = false; } @@ -740,25 +740,26 @@ hstore_from_record(PG_FUNCTION_ARGS) HeapTupleHeader rec; int4 buflen; HStore *out; - Pairs *pairs; + Pairs *pairs; Oid tupType; int32 tupTypmod; TupleDesc tupdesc; HeapTupleData tuple; RecordIOData *my_extra; int ncolumns; - int i,j; + int i, + j; Datum *values; bool *nulls; if (PG_ARGISNULL(0)) { - Oid argtype = get_fn_expr_argtype(fcinfo->flinfo,0); + Oid argtype = get_fn_expr_argtype(fcinfo->flinfo, 0); /* - * have no tuple to look at, so the only source of type info - * is the argtype. The lookup_rowtype_tupdesc call below will - * error out if we don't have a known composite type oid here. + * have no tuple to look at, so the only source of type info is the + * argtype. The lookup_rowtype_tupdesc call below will error out if we + * don't have a known composite type oid here. */ tupType = argtype; tupTypmod = -1; @@ -855,7 +856,7 @@ hstore_from_record(PG_FUNCTION_ARGS) */ if (column_info->column_type != column_type) { - bool typIsVarlena; + bool typIsVarlena; getTypeOutputInfo(column_type, &column_info->typiofunc, @@ -889,18 +890,18 @@ Datum hstore_populate_record(PG_FUNCTION_ARGS); Datum hstore_populate_record(PG_FUNCTION_ARGS) { - Oid argtype = get_fn_expr_argtype(fcinfo->flinfo,0); - HStore *hs; - HEntry *entries; - char *ptr; + Oid argtype = get_fn_expr_argtype(fcinfo->flinfo, 0); + HStore *hs; + HEntry *entries; + char *ptr; HeapTupleHeader rec; Oid tupType; int32 tupTypmod; TupleDesc tupdesc; HeapTupleData tuple; - HeapTuple rettuple; + HeapTuple rettuple; RecordIOData *my_extra; - int ncolumns; + int ncolumns; int i; Datum *values; bool *nulls; @@ -918,9 +919,9 @@ hstore_populate_record(PG_FUNCTION_ARGS) rec = NULL; /* - * have no tuple to look at, so the only source of type info - * is the argtype. The lookup_rowtype_tupdesc call below will - * error out if we don't have a known composite type oid here. + * have no tuple to look at, so the only source of type info is the + * argtype. The lookup_rowtype_tupdesc call below will error out if we + * don't have a known composite type oid here. */ tupType = argtype; tupTypmod = -1; @@ -942,9 +943,9 @@ hstore_populate_record(PG_FUNCTION_ARGS) ptr = STRPTR(hs); /* - * if the input hstore is empty, we can only skip the rest if - * we were passed in a non-null record, since otherwise there - * may be issues with domain nulls. + * if the input hstore is empty, we can only skip the rest if we were + * passed in a non-null record, since otherwise there may be issues with + * domain nulls. */ if (HS_COUNT(hs) == 0 && rec) @@ -1012,8 +1013,8 @@ hstore_populate_record(PG_FUNCTION_ARGS) ColumnIOData *column_info = &my_extra->columns[i]; Oid column_type = tupdesc->attrs[i]->atttypid; char *value; - int idx; - int vallen; + int idx; + int vallen; /* Ignore dropped columns in datatype */ if (tupdesc->attrs[i]->attisdropped) @@ -1025,14 +1026,14 @@ hstore_populate_record(PG_FUNCTION_ARGS) idx = hstoreFindKey(hs, 0, NameStr(tupdesc->attrs[i]->attname), strlen(NameStr(tupdesc->attrs[i]->attname))); + /* - * we can't just skip here if the key wasn't found since we - * might have a domain to deal with. If we were passed in a - * non-null record datum, we assume that the existing values - * are valid (if they're not, then it's not our fault), but if - * we were passed in a null, then every field which we don't - * populate needs to be run through the input function just in - * case it's a domain type. + * we can't just skip here if the key wasn't found since we might have + * a domain to deal with. If we were passed in a non-null record + * datum, we assume that the existing values are valid (if they're + * not, then it's not our fault), but if we were passed in a null, + * then every field which we don't populate needs to be run through + * the input function just in case it's a domain type. */ if (idx < 0 && rec) continue; @@ -1050,11 +1051,11 @@ hstore_populate_record(PG_FUNCTION_ARGS) column_info->column_type = column_type; } - if (idx < 0 || HS_VALISNULL(entries,idx)) + if (idx < 0 || HS_VALISNULL(entries, idx)) { /* - * need InputFunctionCall to happen even for nulls, so - * that domain checks are done + * need InputFunctionCall to happen even for nulls, so that domain + * checks are done */ values[i] = InputFunctionCall(&column_info->proc, NULL, column_info->typioparam, @@ -1063,9 +1064,9 @@ hstore_populate_record(PG_FUNCTION_ARGS) } else { - vallen = HS_VALLEN(entries,idx); + vallen = HS_VALLEN(entries, idx); value = palloc(1 + vallen); - memcpy(value, HS_VAL(entries,ptr,idx), vallen); + memcpy(value, HS_VAL(entries, ptr, idx), vallen); value[vallen] = 0; values[i] = InputFunctionCall(&column_info->proc, value, @@ -1105,7 +1106,7 @@ hstore_out(PG_FUNCTION_ARGS) HStore *in = PG_GETARG_HS(0); int buflen, i; - int count = HS_COUNT(in); + int count = HS_COUNT(in); char *out, *ptr; char *base = STRPTR(in); @@ -1121,21 +1122,21 @@ hstore_out(PG_FUNCTION_ARGS) buflen = 0; /* - * this loop overestimates due to pessimistic assumptions about - * escaping, so very large hstore values can't be output. this - * could be fixed, but many other data types probably have the - * same issue. This replaced code that used the original varlena - * size for calculations, which was wrong in some subtle ways. + * this loop overestimates due to pessimistic assumptions about escaping, + * so very large hstore values can't be output. this could be fixed, but + * many other data types probably have the same issue. This replaced code + * that used the original varlena size for calculations, which was wrong + * in some subtle ways. */ for (i = 0; i < count; i++) { /* include "" and => and comma-space */ - buflen += 6 + 2 * HS_KEYLEN(entries,i); + buflen += 6 + 2 * HS_KEYLEN(entries, i); /* include "" only if nonnull */ - buflen += 2 + (HS_VALISNULL(entries,i) + buflen += 2 + (HS_VALISNULL(entries, i) ? 2 - : 2 * HS_VALLEN(entries,i)); + : 2 * HS_VALLEN(entries, i)); } out = ptr = palloc(buflen); @@ -1143,11 +1144,11 @@ hstore_out(PG_FUNCTION_ARGS) for (i = 0; i < count; i++) { *ptr++ = '"'; - ptr = cpw(ptr, HS_KEY(entries,base,i), HS_KEYLEN(entries,i)); + ptr = cpw(ptr, HS_KEY(entries, base, i), HS_KEYLEN(entries, i)); *ptr++ = '"'; *ptr++ = '='; *ptr++ = '>'; - if (HS_VALISNULL(entries,i)) + if (HS_VALISNULL(entries, i)) { *ptr++ = 'N'; *ptr++ = 'U'; @@ -1157,7 +1158,7 @@ hstore_out(PG_FUNCTION_ARGS) else { *ptr++ = '"'; - ptr = cpw(ptr, HS_VAL(entries,base,i), HS_VALLEN(entries,i)); + ptr = cpw(ptr, HS_VAL(entries, base, i), HS_VALLEN(entries, i)); *ptr++ = '"'; } @@ -1179,8 +1180,8 @@ Datum hstore_send(PG_FUNCTION_ARGS) { HStore *in = PG_GETARG_HS(0); - int i; - int count = HS_COUNT(in); + int i; + int count = HS_COUNT(in); char *base = STRPTR(in); HEntry *entries = ARRPTR(in); StringInfoData buf; @@ -1191,18 +1192,20 @@ hstore_send(PG_FUNCTION_ARGS) for (i = 0; i < count; i++) { - int32 keylen = HS_KEYLEN(entries,i); + int32 keylen = HS_KEYLEN(entries, i); + pq_sendint(&buf, keylen, 4); - pq_sendtext(&buf, HS_KEY(entries,base,i), keylen); - if (HS_VALISNULL(entries,i)) + pq_sendtext(&buf, HS_KEY(entries, base, i), keylen); + if (HS_VALISNULL(entries, i)) { pq_sendint(&buf, -1, 4); } else { - int32 vallen = HS_VALLEN(entries,i); + int32 vallen = HS_VALLEN(entries, i); + pq_sendint(&buf, vallen, 4); - pq_sendtext(&buf, HS_VAL(entries,base,i), vallen); + pq_sendtext(&buf, HS_VAL(entries, base, i), vallen); } } diff --git a/contrib/hstore/hstore_op.c b/contrib/hstore/hstore_op.c index cc1a162dacb..ebee60a1dbe 100644 --- a/contrib/hstore/hstore_op.c +++ b/contrib/hstore/hstore_op.c @@ -1,5 +1,5 @@ /* - * $PostgreSQL: pgsql/contrib/hstore/hstore_op.c,v 1.15 2009/09/30 21:26:17 tgl Exp $ + * $PostgreSQL: pgsql/contrib/hstore/hstore_op.c,v 1.16 2010/02/26 02:00:32 momjian Exp $ */ #include "postgres.h" @@ -13,18 +13,18 @@ #include "hstore.h" /* old names for C functions */ -HSTORE_POLLUTE(hstore_fetchval,fetchval); -HSTORE_POLLUTE(hstore_exists,exists); -HSTORE_POLLUTE(hstore_defined,defined); -HSTORE_POLLUTE(hstore_delete,delete); -HSTORE_POLLUTE(hstore_concat,hs_concat); -HSTORE_POLLUTE(hstore_contains,hs_contains); -HSTORE_POLLUTE(hstore_contained,hs_contained); -HSTORE_POLLUTE(hstore_akeys,akeys); -HSTORE_POLLUTE(hstore_avals,avals); -HSTORE_POLLUTE(hstore_skeys,skeys); -HSTORE_POLLUTE(hstore_svals,svals); -HSTORE_POLLUTE(hstore_each,each); +HSTORE_POLLUTE(hstore_fetchval, fetchval); +HSTORE_POLLUTE(hstore_exists, exists); +HSTORE_POLLUTE(hstore_defined, defined); +HSTORE_POLLUTE(hstore_delete, delete); +HSTORE_POLLUTE(hstore_concat, hs_concat); +HSTORE_POLLUTE(hstore_contains, hs_contains); +HSTORE_POLLUTE(hstore_contained, hs_contained); +HSTORE_POLLUTE(hstore_akeys, akeys); +HSTORE_POLLUTE(hstore_avals, avals); +HSTORE_POLLUTE(hstore_skeys, skeys); +HSTORE_POLLUTE(hstore_svals, svals); +HSTORE_POLLUTE(hstore_each, each); /* @@ -34,24 +34,24 @@ HSTORE_POLLUTE(hstore_each,each); * one-off or unordered searches. */ int -hstoreFindKey(HStore * hs, int *lowbound, char *key, int keylen) +hstoreFindKey(HStore *hs, int *lowbound, char *key, int keylen) { HEntry *entries = ARRPTR(hs); - int stopLow = lowbound ? *lowbound : 0; - int stopHigh = HS_COUNT(hs); - int stopMiddle; + int stopLow = lowbound ? *lowbound : 0; + int stopHigh = HS_COUNT(hs); + int stopMiddle; char *base = STRPTR(hs); while (stopLow < stopHigh) { - int difference; + int difference; stopMiddle = stopLow + (stopHigh - stopLow) / 2; - if (HS_KEYLEN(entries,stopMiddle) == keylen) - difference = strncmp(HS_KEY(entries,base,stopMiddle), key, keylen); + if (HS_KEYLEN(entries, stopMiddle) == keylen) + difference = strncmp(HS_KEY(entries, base, stopMiddle), key, keylen); else - difference = (HS_KEYLEN(entries,stopMiddle) > keylen) ? 1 : -1; + difference = (HS_KEYLEN(entries, stopMiddle) > keylen) ? 1 : -1; if (difference == 0) { @@ -73,12 +73,13 @@ hstoreFindKey(HStore * hs, int *lowbound, char *key, int keylen) Pairs * hstoreArrayToPairs(ArrayType *a, int *npairs) { - Datum *key_datums; - bool *key_nulls; - int key_count; - Pairs *key_pairs; - int bufsiz; - int i,j; + Datum *key_datums; + bool *key_nulls; + int key_count; + Pairs *key_pairs; + int bufsiz; + int i, + j; deconstruct_array(a, TEXTOID, -1, false, 'i', @@ -121,14 +122,14 @@ hstore_fetchval(PG_FUNCTION_ARGS) text *key = PG_GETARG_TEXT_PP(1); HEntry *entries = ARRPTR(hs); text *out; - int idx = hstoreFindKey(hs, NULL, + int idx = hstoreFindKey(hs, NULL, VARDATA_ANY(key), VARSIZE_ANY_EXHDR(key)); - if (idx < 0 || HS_VALISNULL(entries,idx)) + if (idx < 0 || HS_VALISNULL(entries, idx)) PG_RETURN_NULL(); - out = cstring_to_text_with_len(HS_VAL(entries,STRPTR(hs),idx), - HS_VALLEN(entries,idx)); + out = cstring_to_text_with_len(HS_VAL(entries, STRPTR(hs), idx), + HS_VALLEN(entries, idx)); PG_RETURN_TEXT_P(out); } @@ -141,7 +142,7 @@ hstore_exists(PG_FUNCTION_ARGS) { HStore *hs = PG_GETARG_HS(0); text *key = PG_GETARG_TEXT_PP(1); - int idx = hstoreFindKey(hs, NULL, + int idx = hstoreFindKey(hs, NULL, VARDATA_ANY(key), VARSIZE_ANY_EXHDR(key)); PG_RETURN_BOOL(idx >= 0); @@ -155,23 +156,23 @@ hstore_exists_any(PG_FUNCTION_ARGS) { HStore *hs = PG_GETARG_HS(0); ArrayType *keys = PG_GETARG_ARRAYTYPE_P(1); - int nkeys; - Pairs *key_pairs = hstoreArrayToPairs(keys, &nkeys); - int i; - int lowbound = 0; - bool res = false; + int nkeys; + Pairs *key_pairs = hstoreArrayToPairs(keys, &nkeys); + int i; + int lowbound = 0; + bool res = false; /* - * we exploit the fact that the pairs list is already sorted into - * strictly increasing order to narrow the hstoreFindKey search; - * each search can start one entry past the previous "found" - * entry, or at the lower bound of the last search. + * we exploit the fact that the pairs list is already sorted into strictly + * increasing order to narrow the hstoreFindKey search; each search can + * start one entry past the previous "found" entry, or at the lower bound + * of the last search. */ for (i = 0; !res && i < nkeys; ++i) { - int idx = hstoreFindKey(hs, &lowbound, - key_pairs[i].key, key_pairs[i].keylen); + int idx = hstoreFindKey(hs, &lowbound, + key_pairs[i].key, key_pairs[i].keylen); if (idx >= 0) res = true; @@ -188,23 +189,23 @@ hstore_exists_all(PG_FUNCTION_ARGS) { HStore *hs = PG_GETARG_HS(0); ArrayType *keys = PG_GETARG_ARRAYTYPE_P(1); - int nkeys; - Pairs *key_pairs = hstoreArrayToPairs(keys, &nkeys); - int i; - int lowbound = 0; - bool res = nkeys ? true : false; + int nkeys; + Pairs *key_pairs = hstoreArrayToPairs(keys, &nkeys); + int i; + int lowbound = 0; + bool res = nkeys ? true : false; /* - * we exploit the fact that the pairs list is already sorted into - * strictly increasing order to narrow the hstoreFindKey search; - * each search can start one entry past the previous "found" - * entry, or at the lower bound of the last search. + * we exploit the fact that the pairs list is already sorted into strictly + * increasing order to narrow the hstoreFindKey search; each search can + * start one entry past the previous "found" entry, or at the lower bound + * of the last search. */ for (i = 0; res && i < nkeys; ++i) { - int idx = hstoreFindKey(hs, &lowbound, - key_pairs[i].key, key_pairs[i].keylen); + int idx = hstoreFindKey(hs, &lowbound, + key_pairs[i].key, key_pairs[i].keylen); if (idx < 0) res = false; @@ -222,9 +223,9 @@ hstore_defined(PG_FUNCTION_ARGS) HStore *hs = PG_GETARG_HS(0); text *key = PG_GETARG_TEXT_PP(1); HEntry *entries = ARRPTR(hs); - int idx = hstoreFindKey(hs, NULL, + int idx = hstoreFindKey(hs, NULL, VARDATA_ANY(key), VARSIZE_ANY_EXHDR(key)); - bool res = (idx >= 0 && !HS_VALISNULL(entries,idx)); + bool res = (idx >= 0 && !HS_VALISNULL(entries, idx)); PG_RETURN_BOOL(res); } @@ -237,20 +238,20 @@ hstore_delete(PG_FUNCTION_ARGS) { HStore *hs = PG_GETARG_HS(0); text *key = PG_GETARG_TEXT_PP(1); - char *keyptr = VARDATA_ANY(key); - int keylen = VARSIZE_ANY_EXHDR(key); + char *keyptr = VARDATA_ANY(key); + int keylen = VARSIZE_ANY_EXHDR(key); HStore *out = palloc(VARSIZE(hs)); char *bufs, - *bufd, + *bufd, *ptrd; HEntry *es, *ed; - int i; - int count = HS_COUNT(hs); - int outcount = 0; + int i; + int count = HS_COUNT(hs); + int outcount = 0; SET_VARSIZE(out, VARSIZE(hs)); - HS_SETCOUNT(out, count); /* temporary! */ + HS_SETCOUNT(out, count); /* temporary! */ bufs = STRPTR(hs); es = ARRPTR(hs); @@ -259,18 +260,19 @@ hstore_delete(PG_FUNCTION_ARGS) for (i = 0; i < count; ++i) { - int len = HS_KEYLEN(es,i); - char *ptrs = HS_KEY(es,bufs,i); + int len = HS_KEYLEN(es, i); + char *ptrs = HS_KEY(es, bufs, i); if (!(len == keylen && strncmp(ptrs, keyptr, keylen) == 0)) { - int vallen = HS_VALLEN(es,i); - HS_COPYITEM(ed, bufd, ptrd, ptrs, len, vallen, HS_VALISNULL(es,i)); + int vallen = HS_VALLEN(es, i); + + HS_COPYITEM(ed, bufd, ptrd, ptrs, len, vallen, HS_VALISNULL(es, i)); ++outcount; } } - HS_FINALIZE(out,outcount,bufd,ptrd); + HS_FINALIZE(out, outcount, bufd, ptrd); PG_RETURN_POINTER(out); } @@ -283,20 +285,21 @@ hstore_delete_array(PG_FUNCTION_ARGS) { HStore *hs = PG_GETARG_HS(0); HStore *out = palloc(VARSIZE(hs)); - int hs_count = HS_COUNT(hs); + int hs_count = HS_COUNT(hs); char *ps, - *bufd, + *bufd, *pd; HEntry *es, *ed; - int i,j; - int outcount = 0; + int i, + j; + int outcount = 0; ArrayType *key_array = PG_GETARG_ARRAYTYPE_P(1); - int nkeys; - Pairs *key_pairs = hstoreArrayToPairs(key_array, &nkeys); + int nkeys; + Pairs *key_pairs = hstoreArrayToPairs(key_array, &nkeys); SET_VARSIZE(out, VARSIZE(hs)); - HS_SETCOUNT(out, hs_count); /* temporary! */ + HS_SETCOUNT(out, hs_count); /* temporary! */ ps = STRPTR(hs); es = ARRPTR(hs); @@ -313,22 +316,22 @@ hstore_delete_array(PG_FUNCTION_ARGS) } /* - * this is in effect a merge between hs and key_pairs, both of - * which are already sorted by (keylen,key); we take keys from - * hs only + * this is in effect a merge between hs and key_pairs, both of which are + * already sorted by (keylen,key); we take keys from hs only */ - for (i = j = 0; i < hs_count; ) + for (i = j = 0; i < hs_count;) { - int difference; - + int difference; + if (j >= nkeys) difference = -1; else { - int skeylen = HS_KEYLEN(es,i); + int skeylen = HS_KEYLEN(es, i); + if (skeylen == key_pairs[j].keylen) - difference = strncmp(HS_KEY(es,ps,i), + difference = strncmp(HS_KEY(es, ps, i), key_pairs[j].key, key_pairs[j].keylen); else @@ -342,14 +345,14 @@ hstore_delete_array(PG_FUNCTION_ARGS) else { HS_COPYITEM(ed, bufd, pd, - HS_KEY(es,ps,i), HS_KEYLEN(es,i), - HS_VALLEN(es,i), HS_VALISNULL(es,i)); + HS_KEY(es, ps, i), HS_KEYLEN(es, i), + HS_VALLEN(es, i), HS_VALISNULL(es, i)); ++outcount; ++i; } } - HS_FINALIZE(out,outcount,bufd,pd); + HS_FINALIZE(out, outcount, bufd, pd); PG_RETURN_POINTER(out); } @@ -363,20 +366,21 @@ hstore_delete_hstore(PG_FUNCTION_ARGS) HStore *hs = PG_GETARG_HS(0); HStore *hs2 = PG_GETARG_HS(1); HStore *out = palloc(VARSIZE(hs)); - int hs_count = HS_COUNT(hs); - int hs2_count = HS_COUNT(hs2); + int hs_count = HS_COUNT(hs); + int hs2_count = HS_COUNT(hs2); char *ps, - *ps2, - *bufd, + *ps2, + *bufd, *pd; HEntry *es, - *es2, + *es2, *ed; - int i,j; - int outcount = 0; + int i, + j; + int outcount = 0; SET_VARSIZE(out, VARSIZE(hs)); - HS_SETCOUNT(out, hs_count); /* temporary! */ + HS_SETCOUNT(out, hs_count); /* temporary! */ ps = STRPTR(hs); es = ARRPTR(hs); @@ -395,25 +399,25 @@ hstore_delete_hstore(PG_FUNCTION_ARGS) } /* - * this is in effect a merge between hs and hs2, both of - * which are already sorted by (keylen,key); we take keys from - * hs only; for equal keys, we take the value from hs unless the - * values are equal + * this is in effect a merge between hs and hs2, both of which are already + * sorted by (keylen,key); we take keys from hs only; for equal keys, we + * take the value from hs unless the values are equal */ - for (i = j = 0; i < hs_count; ) + for (i = j = 0; i < hs_count;) { - int difference; - + int difference; + if (j >= hs2_count) difference = -1; else { - int skeylen = HS_KEYLEN(es,i); - int s2keylen = HS_KEYLEN(es2,j); + int skeylen = HS_KEYLEN(es, i); + int s2keylen = HS_KEYLEN(es2, j); + if (skeylen == s2keylen) - difference = strncmp(HS_KEY(es,ps,i), - HS_KEY(es2,ps2,j), + difference = strncmp(HS_KEY(es, ps, i), + HS_KEY(es2, ps2, j), skeylen); else difference = (skeylen > s2keylen) ? 1 : -1; @@ -423,15 +427,16 @@ hstore_delete_hstore(PG_FUNCTION_ARGS) ++j; else if (difference == 0) { - int svallen = HS_VALLEN(es,i); - int snullval = HS_VALISNULL(es,i); - if (snullval != HS_VALISNULL(es2,j) + int svallen = HS_VALLEN(es, i); + int snullval = HS_VALISNULL(es, i); + + if (snullval != HS_VALISNULL(es2, j) || (!snullval - && (svallen != HS_VALLEN(es2,j) - || strncmp(HS_VAL(es,ps,i), HS_VAL(es2,ps2,j), svallen) != 0))) + && (svallen != HS_VALLEN(es2, j) + || strncmp(HS_VAL(es, ps, i), HS_VAL(es2, ps2, j), svallen) != 0))) { HS_COPYITEM(ed, bufd, pd, - HS_KEY(es,ps,i), HS_KEYLEN(es,i), + HS_KEY(es, ps, i), HS_KEYLEN(es, i), svallen, snullval); ++outcount; } @@ -440,14 +445,14 @@ hstore_delete_hstore(PG_FUNCTION_ARGS) else { HS_COPYITEM(ed, bufd, pd, - HS_KEY(es,ps,i), HS_KEYLEN(es,i), - HS_VALLEN(es,i), HS_VALISNULL(es,i)); + HS_KEY(es, ps, i), HS_KEYLEN(es, i), + HS_VALLEN(es, i), HS_VALISNULL(es, i)); ++outcount; ++i; } } - HS_FINALIZE(out,outcount,bufd,pd); + HS_FINALIZE(out, outcount, bufd, pd); PG_RETURN_POINTER(out); } @@ -463,16 +468,16 @@ hstore_concat(PG_FUNCTION_ARGS) HStore *out = palloc(VARSIZE(s1) + VARSIZE(s2)); char *ps1, *ps2, - *bufd, + *bufd, *pd; HEntry *es1, *es2, *ed; - int s1idx; - int s2idx; - int s1count = HS_COUNT(s1); - int s2count = HS_COUNT(s2); - int outcount = 0; + int s1idx; + int s2idx; + int s1count = HS_COUNT(s1); + int s2count = HS_COUNT(s2); + int outcount = 0; SET_VARSIZE(out, VARSIZE(s1) + VARSIZE(s2) - HSHRDSIZE); HS_SETCOUNT(out, s1count + s2count); @@ -503,25 +508,26 @@ hstore_concat(PG_FUNCTION_ARGS) ed = ARRPTR(out); /* - * this is in effect a merge between s1 and s2, both of which - * are already sorted by (keylen,key); we take s2 for equal keys + * this is in effect a merge between s1 and s2, both of which are already + * sorted by (keylen,key); we take s2 for equal keys */ for (s1idx = s2idx = 0; s1idx < s1count || s2idx < s2count; ++outcount) { - int difference; - + int difference; + if (s1idx >= s1count) difference = 1; else if (s2idx >= s2count) difference = -1; else { - int s1keylen = HS_KEYLEN(es1,s1idx); - int s2keylen = HS_KEYLEN(es2,s2idx); + int s1keylen = HS_KEYLEN(es1, s1idx); + int s2keylen = HS_KEYLEN(es2, s2idx); + if (s1keylen == s2keylen) - difference = strncmp(HS_KEY(es1,ps1,s1idx), - HS_KEY(es2,ps2,s2idx), + difference = strncmp(HS_KEY(es1, ps1, s1idx), + HS_KEY(es2, ps2, s2idx), s1keylen); else difference = (s1keylen > s2keylen) ? 1 : -1; @@ -530,8 +536,8 @@ hstore_concat(PG_FUNCTION_ARGS) if (difference >= 0) { HS_COPYITEM(ed, bufd, pd, - HS_KEY(es2,ps2,s2idx), HS_KEYLEN(es2,s2idx), - HS_VALLEN(es2,s2idx), HS_VALISNULL(es2,s2idx)); + HS_KEY(es2, ps2, s2idx), HS_KEYLEN(es2, s2idx), + HS_VALLEN(es2, s2idx), HS_VALISNULL(es2, s2idx)); ++s2idx; if (difference == 0) ++s1idx; @@ -539,13 +545,13 @@ hstore_concat(PG_FUNCTION_ARGS) else { HS_COPYITEM(ed, bufd, pd, - HS_KEY(es1,ps1,s1idx), HS_KEYLEN(es1,s1idx), - HS_VALLEN(es1,s1idx), HS_VALISNULL(es1,s1idx)); + HS_KEY(es1, ps1, s1idx), HS_KEYLEN(es1, s1idx), + HS_VALLEN(es1, s1idx), HS_VALISNULL(es1, s1idx)); ++s1idx; } } - HS_FINALIZE(out,outcount,bufd,pd); + HS_FINALIZE(out, outcount, bufd, pd); PG_RETURN_POINTER(out); } @@ -558,15 +564,15 @@ hstore_slice_to_array(PG_FUNCTION_ARGS) { HStore *hs = PG_GETARG_HS(0); HEntry *entries = ARRPTR(hs); - char *ptr = STRPTR(hs); + char *ptr = STRPTR(hs); ArrayType *key_array = PG_GETARG_ARRAYTYPE_P(1); ArrayType *aout; - Datum *key_datums; - bool *key_nulls; - Datum *out_datums; - bool *out_nulls; - int key_count; - int i; + Datum *key_datums; + bool *key_nulls; + Datum *out_datums; + bool *out_nulls; + int key_count; + int i; deconstruct_array(key_array, TEXTOID, -1, false, 'i', @@ -583,15 +589,15 @@ hstore_slice_to_array(PG_FUNCTION_ARGS) for (i = 0; i < key_count; ++i) { - text *key = (text*) DatumGetPointer(key_datums[i]); - int idx; + text *key = (text *) DatumGetPointer(key_datums[i]); + int idx; if (key_nulls[i]) idx = -1; else idx = hstoreFindKey(hs, NULL, VARDATA(key), VARSIZE(key) - VARHDRSZ); - if (idx < 0 || HS_VALISNULL(entries,idx)) + if (idx < 0 || HS_VALISNULL(entries, idx)) { out_nulls[i] = true; out_datums[i] = (Datum) 0; @@ -599,8 +605,8 @@ hstore_slice_to_array(PG_FUNCTION_ARGS) else { out_datums[i] = PointerGetDatum( - cstring_to_text_with_len(HS_VAL(entries,ptr,idx), - HS_VALLEN(entries,idx))); + cstring_to_text_with_len(HS_VAL(entries, ptr, idx), + HS_VALLEN(entries, idx))); out_nulls[i] = false; } } @@ -609,7 +615,7 @@ hstore_slice_to_array(PG_FUNCTION_ARGS) ARR_NDIM(key_array), ARR_DIMS(key_array), ARR_LBOUND(key_array), - TEXTOID, -1, false, 'i'); + TEXTOID, -1, false, 'i'); PG_RETURN_POINTER(aout); } @@ -622,16 +628,16 @@ hstore_slice_to_hstore(PG_FUNCTION_ARGS) { HStore *hs = PG_GETARG_HS(0); HEntry *entries = ARRPTR(hs); - char *ptr = STRPTR(hs); + char *ptr = STRPTR(hs); ArrayType *key_array = PG_GETARG_ARRAYTYPE_P(1); - HStore *out; - int nkeys; - Pairs *key_pairs = hstoreArrayToPairs(key_array, &nkeys); - Pairs *out_pairs; - int bufsiz; - int lastidx = 0; - int i; - int out_count = 0; + HStore *out; + int nkeys; + Pairs *key_pairs = hstoreArrayToPairs(key_array, &nkeys); + Pairs *out_pairs; + int bufsiz; + int lastidx = 0; + int i; + int out_count = 0; if (nkeys == 0) { @@ -643,32 +649,32 @@ hstore_slice_to_hstore(PG_FUNCTION_ARGS) bufsiz = 0; /* - * we exploit the fact that the pairs list is already sorted into - * strictly increasing order to narrow the hstoreFindKey search; - * each search can start one entry past the previous "found" - * entry, or at the lower bound of the last search. + * we exploit the fact that the pairs list is already sorted into strictly + * increasing order to narrow the hstoreFindKey search; each search can + * start one entry past the previous "found" entry, or at the lower bound + * of the last search. */ for (i = 0; i < nkeys; ++i) { - int idx = hstoreFindKey(hs, &lastidx, - key_pairs[i].key, key_pairs[i].keylen); + int idx = hstoreFindKey(hs, &lastidx, + key_pairs[i].key, key_pairs[i].keylen); if (idx >= 0) { out_pairs[out_count].key = key_pairs[i].key; bufsiz += (out_pairs[out_count].keylen = key_pairs[i].keylen); - out_pairs[out_count].val = HS_VAL(entries,ptr,idx); - bufsiz += (out_pairs[out_count].vallen = HS_VALLEN(entries,idx)); - out_pairs[out_count].isnull = HS_VALISNULL(entries,idx); + out_pairs[out_count].val = HS_VAL(entries, ptr, idx); + bufsiz += (out_pairs[out_count].vallen = HS_VALLEN(entries, idx)); + out_pairs[out_count].isnull = HS_VALISNULL(entries, idx); out_pairs[out_count].needfree = false; ++out_count; } } /* - * we don't use uniquePairs here because we know that the - * pairs list is already sorted and uniq'ed. + * we don't use uniquePairs here because we know that the pairs list is + * already sorted and uniq'ed. */ out = hstorePairs(out_pairs, out_count, bufsiz); @@ -687,8 +693,8 @@ hstore_akeys(PG_FUNCTION_ARGS) ArrayType *a; HEntry *entries = ARRPTR(hs); char *base = STRPTR(hs); - int count = HS_COUNT(hs); - int i; + int count = HS_COUNT(hs); + int i; if (count == 0) { @@ -700,13 +706,14 @@ hstore_akeys(PG_FUNCTION_ARGS) for (i = 0; i < count; ++i) { - text *item = cstring_to_text_with_len(HS_KEY(entries,base,i), - HS_KEYLEN(entries,i)); + text *item = cstring_to_text_with_len(HS_KEY(entries, base, i), + HS_KEYLEN(entries, i)); + d[i] = PointerGetDatum(item); } a = construct_array(d, count, - TEXTOID, -1, false, 'i'); + TEXTOID, -1, false, 'i'); PG_RETURN_POINTER(a); } @@ -719,13 +726,13 @@ hstore_avals(PG_FUNCTION_ARGS) { HStore *hs = PG_GETARG_HS(0); Datum *d; - bool *nulls; + bool *nulls; ArrayType *a; HEntry *entries = ARRPTR(hs); char *base = STRPTR(hs); - int count = HS_COUNT(hs); - int lb = 1; - int i; + int count = HS_COUNT(hs); + int lb = 1; + int i; if (count == 0) { @@ -738,22 +745,23 @@ hstore_avals(PG_FUNCTION_ARGS) for (i = 0; i < count; ++i) { - if (HS_VALISNULL(entries,i)) + if (HS_VALISNULL(entries, i)) { d[i] = (Datum) 0; nulls[i] = true; } else { - text *item = cstring_to_text_with_len(HS_VAL(entries,base,i), - HS_VALLEN(entries,i)); + text *item = cstring_to_text_with_len(HS_VAL(entries, base, i), + HS_VALLEN(entries, i)); + d[i] = PointerGetDatum(item); nulls[i] = false; } } a = construct_md_array(d, nulls, 1, &count, &lb, - TEXTOID, -1, false, 'i'); + TEXTOID, -1, false, 'i'); PG_RETURN_POINTER(a); } @@ -764,12 +772,12 @@ hstore_to_array_internal(HStore *hs, int ndims) { HEntry *entries = ARRPTR(hs); char *base = STRPTR(hs); - int count = HS_COUNT(hs); - int out_size[2] = { 0, 2 }; - int lb[2] = { 1, 1 }; + int count = HS_COUNT(hs); + int out_size[2] = {0, 2}; + int lb[2] = {1, 1}; Datum *out_datums; bool *out_nulls; - int i; + int i; Assert(ndims < 3); @@ -782,22 +790,24 @@ hstore_to_array_internal(HStore *hs, int ndims) for (i = 0; i < count; ++i) { - text *key = cstring_to_text_with_len(HS_KEY(entries,base,i), - HS_KEYLEN(entries,i)); - out_datums[i*2] = PointerGetDatum(key); - out_nulls[i*2] = false; + text *key = cstring_to_text_with_len(HS_KEY(entries, base, i), + HS_KEYLEN(entries, i)); + + out_datums[i * 2] = PointerGetDatum(key); + out_nulls[i * 2] = false; - if (HS_VALISNULL(entries,i)) + if (HS_VALISNULL(entries, i)) { - out_datums[i*2+1] = (Datum) 0; - out_nulls[i*2+1] = true; + out_datums[i * 2 + 1] = (Datum) 0; + out_nulls[i * 2 + 1] = true; } else { - text *item = cstring_to_text_with_len(HS_VAL(entries,base,i), - HS_VALLEN(entries,i)); - out_datums[i*2+1] = PointerGetDatum(item); - out_nulls[i*2+1] = false; + text *item = cstring_to_text_with_len(HS_VAL(entries, base, i), + HS_VALLEN(entries, i)); + + out_datums[i * 2 + 1] = PointerGetDatum(item); + out_nulls[i * 2 + 1] = false; } } @@ -811,7 +821,7 @@ Datum hstore_to_array(PG_FUNCTION_ARGS); Datum hstore_to_array(PG_FUNCTION_ARGS) { - HStore *hs = PG_GETARG_HS(0); + HStore *hs = PG_GETARG_HS(0); ArrayType *out = hstore_to_array_internal(hs, 1); PG_RETURN_POINTER(out); @@ -822,7 +832,7 @@ Datum hstore_to_matrix(PG_FUNCTION_ARGS); Datum hstore_to_matrix(PG_FUNCTION_ARGS) { - HStore *hs = PG_GETARG_HS(0); + HStore *hs = PG_GETARG_HS(0); ArrayType *out = hstore_to_array_internal(hs, 2); PG_RETURN_POINTER(out); @@ -838,11 +848,11 @@ hstore_to_matrix(PG_FUNCTION_ARGS) */ static void -setup_firstcall(FuncCallContext *funcctx, HStore * hs, +setup_firstcall(FuncCallContext *funcctx, HStore *hs, FunctionCallInfoData *fcinfo) { MemoryContext oldcontext; - HStore *st; + HStore *st; oldcontext = MemoryContextSwitchTo(funcctx->multi_call_memory_ctx); @@ -858,7 +868,7 @@ setup_firstcall(FuncCallContext *funcctx, HStore * hs, /* Build a tuple descriptor for our result type */ if (get_call_result_type(fcinfo, NULL, &tupdesc) != TYPEFUNC_COMPOSITE) elog(ERROR, "return type must be a row type"); - + funcctx->tuple_desc = BlessTupleDesc(tupdesc); } @@ -872,8 +882,8 @@ Datum hstore_skeys(PG_FUNCTION_ARGS) { FuncCallContext *funcctx; - HStore *hs; - int i; + HStore *hs; + int i; if (SRF_IS_FIRSTCALL()) { @@ -888,11 +898,11 @@ hstore_skeys(PG_FUNCTION_ARGS) if (i < HS_COUNT(hs)) { - HEntry *entries = ARRPTR(hs); + HEntry *entries = ARRPTR(hs); text *item; - item = cstring_to_text_with_len(HS_KEY(entries,STRPTR(hs),i), - HS_KEYLEN(entries,i)); + item = cstring_to_text_with_len(HS_KEY(entries, STRPTR(hs), i), + HS_KEYLEN(entries, i)); SRF_RETURN_NEXT(funcctx, PointerGetDatum(item)); } @@ -907,8 +917,8 @@ Datum hstore_svals(PG_FUNCTION_ARGS) { FuncCallContext *funcctx; - HStore *hs; - int i; + HStore *hs; + int i; if (SRF_IS_FIRSTCALL()) { @@ -923,9 +933,9 @@ hstore_svals(PG_FUNCTION_ARGS) if (i < HS_COUNT(hs)) { - HEntry *entries = ARRPTR(hs); + HEntry *entries = ARRPTR(hs); - if (HS_VALISNULL(entries,i)) + if (HS_VALISNULL(entries, i)) { ReturnSetInfo *rsi; @@ -939,8 +949,8 @@ hstore_svals(PG_FUNCTION_ARGS) { text *item; - item = cstring_to_text_with_len(HS_VAL(entries,STRPTR(hs),i), - HS_VALLEN(entries,i)); + item = cstring_to_text_with_len(HS_VAL(entries, STRPTR(hs), i), + HS_VALLEN(entries, i)); SRF_RETURN_NEXT(funcctx, PointerGetDatum(item)); } @@ -962,31 +972,31 @@ hstore_contains(PG_FUNCTION_ARGS) char *tstr = STRPTR(tmpl); HEntry *ve = ARRPTR(val); char *vstr = STRPTR(val); - int tcount = HS_COUNT(tmpl); - int lastidx = 0; - int i; + int tcount = HS_COUNT(tmpl); + int lastidx = 0; + int i; /* - * we exploit the fact that keys in "tmpl" are in strictly - * increasing order to narrow the hstoreFindKey search; each search - * can start one entry past the previous "found" entry, or at the - * lower bound of the search + * we exploit the fact that keys in "tmpl" are in strictly increasing + * order to narrow the hstoreFindKey search; each search can start one + * entry past the previous "found" entry, or at the lower bound of the + * search */ for (i = 0; res && i < tcount; ++i) { - int idx = hstoreFindKey(val, &lastidx, - HS_KEY(te,tstr,i), HS_KEYLEN(te,i)); + int idx = hstoreFindKey(val, &lastidx, + HS_KEY(te, tstr, i), HS_KEYLEN(te, i)); if (idx >= 0) { - bool nullval = HS_VALISNULL(te,i); - int vallen = HS_VALLEN(te,i); + bool nullval = HS_VALISNULL(te, i); + int vallen = HS_VALLEN(te, i); - if (nullval != HS_VALISNULL(ve,idx) + if (nullval != HS_VALISNULL(ve, idx) || (!nullval - && (vallen != HS_VALLEN(ve,idx) - || strncmp(HS_VAL(te,tstr,i), HS_VAL(ve,vstr,idx), vallen)))) + && (vallen != HS_VALLEN(ve, idx) + || strncmp(HS_VAL(te, tstr, i), HS_VAL(ve, vstr, idx), vallen)))) res = false; } else @@ -1015,8 +1025,8 @@ Datum hstore_each(PG_FUNCTION_ARGS) { FuncCallContext *funcctx; - HStore *hs; - int i; + HStore *hs; + int i; if (SRF_IS_FIRSTCALL()) { @@ -1032,26 +1042,26 @@ hstore_each(PG_FUNCTION_ARGS) if (i < HS_COUNT(hs)) { HEntry *entries = ARRPTR(hs); - char *ptr = STRPTR(hs); + char *ptr = STRPTR(hs); Datum res, dvalues[2]; bool nulls[2] = {false, false}; text *item; HeapTuple tuple; - item = cstring_to_text_with_len(HS_KEY(entries,ptr,i), - HS_KEYLEN(entries,i)); + item = cstring_to_text_with_len(HS_KEY(entries, ptr, i), + HS_KEYLEN(entries, i)); dvalues[0] = PointerGetDatum(item); - if (HS_VALISNULL(entries,i)) + if (HS_VALISNULL(entries, i)) { dvalues[1] = (Datum) 0; nulls[1] = true; } else { - item = cstring_to_text_with_len(HS_VAL(entries,ptr,i), - HS_VALLEN(entries,i)); + item = cstring_to_text_with_len(HS_VAL(entries, ptr, i), + HS_VALLEN(entries, i)); dvalues[1] = PointerGetDatum(item); } @@ -1078,15 +1088,15 @@ hstore_cmp(PG_FUNCTION_ARGS) { HStore *hs1 = PG_GETARG_HS(0); HStore *hs2 = PG_GETARG_HS(1); - int hcount1 = HS_COUNT(hs1); - int hcount2 = HS_COUNT(hs2); - int res = 0; + int hcount1 = HS_COUNT(hs1); + int hcount2 = HS_COUNT(hs2); + int res = 0; if (hcount1 == 0 || hcount2 == 0) { /* - * if either operand is empty, and the other is nonempty, the - * nonempty one is larger. If both are empty they are equal. + * if either operand is empty, and the other is nonempty, the nonempty + * one is larger. If both are empty they are equal. */ if (hcount1 > 0) res = 1; @@ -1096,14 +1106,14 @@ hstore_cmp(PG_FUNCTION_ARGS) else { /* here we know both operands are nonempty */ - char *str1 = STRPTR(hs1); - char *str2 = STRPTR(hs2); - HEntry *ent1 = ARRPTR(hs1); - HEntry *ent2 = ARRPTR(hs2); - size_t len1 = HSE_ENDPOS(ent1[2*hcount1 - 1]); - size_t len2 = HSE_ENDPOS(ent2[2*hcount2 - 1]); + char *str1 = STRPTR(hs1); + char *str2 = STRPTR(hs2); + HEntry *ent1 = ARRPTR(hs1); + HEntry *ent2 = ARRPTR(hs2); + size_t len1 = HSE_ENDPOS(ent1[2 * hcount1 - 1]); + size_t len2 = HSE_ENDPOS(ent2[2 * hcount2 - 1]); - res = memcmp(str1, str2, Min(len1,len2)); + res = memcmp(str1, str2, Min(len1, len2)); if (res == 0) { @@ -1117,8 +1127,8 @@ hstore_cmp(PG_FUNCTION_ARGS) res = -1; else { - int count = hcount1 * 2; - int i; + int count = hcount1 * 2; + int i; for (i = 0; i < count; ++i) if (HSE_ENDPOS(ent1[i]) != HSE_ENDPOS(ent2[i]) || @@ -1144,11 +1154,11 @@ hstore_cmp(PG_FUNCTION_ARGS) } /* - * this is a btree support function; this is one of the few - * places where memory needs to be explicitly freed. + * this is a btree support function; this is one of the few places where + * memory needs to be explicitly freed. */ - PG_FREE_IF_COPY(hs1,0); - PG_FREE_IF_COPY(hs2,1); + PG_FREE_IF_COPY(hs1, 0); + PG_FREE_IF_COPY(hs2, 1); PG_RETURN_INT32(res); } @@ -1158,9 +1168,10 @@ Datum hstore_eq(PG_FUNCTION_ARGS); Datum hstore_eq(PG_FUNCTION_ARGS) { - int res = DatumGetInt32(DirectFunctionCall2(hstore_cmp, - PG_GETARG_DATUM(0), - PG_GETARG_DATUM(1))); + int res = DatumGetInt32(DirectFunctionCall2(hstore_cmp, + PG_GETARG_DATUM(0), + PG_GETARG_DATUM(1))); + PG_RETURN_BOOL(res == 0); } @@ -1169,9 +1180,10 @@ Datum hstore_ne(PG_FUNCTION_ARGS); Datum hstore_ne(PG_FUNCTION_ARGS) { - int res = DatumGetInt32(DirectFunctionCall2(hstore_cmp, - PG_GETARG_DATUM(0), - PG_GETARG_DATUM(1))); + int res = DatumGetInt32(DirectFunctionCall2(hstore_cmp, + PG_GETARG_DATUM(0), + PG_GETARG_DATUM(1))); + PG_RETURN_BOOL(res != 0); } @@ -1180,9 +1192,10 @@ Datum hstore_gt(PG_FUNCTION_ARGS); Datum hstore_gt(PG_FUNCTION_ARGS) { - int res = DatumGetInt32(DirectFunctionCall2(hstore_cmp, - PG_GETARG_DATUM(0), - PG_GETARG_DATUM(1))); + int res = DatumGetInt32(DirectFunctionCall2(hstore_cmp, + PG_GETARG_DATUM(0), + PG_GETARG_DATUM(1))); + PG_RETURN_BOOL(res > 0); } @@ -1191,9 +1204,10 @@ Datum hstore_ge(PG_FUNCTION_ARGS); Datum hstore_ge(PG_FUNCTION_ARGS) { - int res = DatumGetInt32(DirectFunctionCall2(hstore_cmp, - PG_GETARG_DATUM(0), - PG_GETARG_DATUM(1))); + int res = DatumGetInt32(DirectFunctionCall2(hstore_cmp, + PG_GETARG_DATUM(0), + PG_GETARG_DATUM(1))); + PG_RETURN_BOOL(res >= 0); } @@ -1202,9 +1216,10 @@ Datum hstore_lt(PG_FUNCTION_ARGS); Datum hstore_lt(PG_FUNCTION_ARGS) { - int res = DatumGetInt32(DirectFunctionCall2(hstore_cmp, - PG_GETARG_DATUM(0), - PG_GETARG_DATUM(1))); + int res = DatumGetInt32(DirectFunctionCall2(hstore_cmp, + PG_GETARG_DATUM(0), + PG_GETARG_DATUM(1))); + PG_RETURN_BOOL(res < 0); } @@ -1213,9 +1228,10 @@ Datum hstore_le(PG_FUNCTION_ARGS); Datum hstore_le(PG_FUNCTION_ARGS) { - int res = DatumGetInt32(DirectFunctionCall2(hstore_cmp, - PG_GETARG_DATUM(0), - PG_GETARG_DATUM(1))); + int res = DatumGetInt32(DirectFunctionCall2(hstore_cmp, + PG_GETARG_DATUM(0), + PG_GETARG_DATUM(1))); + PG_RETURN_BOOL(res <= 0); } @@ -1226,21 +1242,20 @@ Datum hstore_hash(PG_FUNCTION_ARGS) { HStore *hs = PG_GETARG_HS(0); - Datum hval = hash_any((unsigned char *)VARDATA(hs), + Datum hval = hash_any((unsigned char *) VARDATA(hs), VARSIZE(hs) - VARHDRSZ); /* - * this is the only place in the code that cares whether the - * overall varlena size exactly matches the true data size; - * this assertion should be maintained by all the other code, - * but we make it explicit here. + * this is the only place in the code that cares whether the overall + * varlena size exactly matches the true data size; this assertion should + * be maintained by all the other code, but we make it explicit here. */ Assert(VARSIZE(hs) == (HS_COUNT(hs) != 0 ? CALCDATASIZE(HS_COUNT(hs), - HSE_ENDPOS(ARRPTR(hs)[2*HS_COUNT(hs) - 1])) : + HSE_ENDPOS(ARRPTR(hs)[2 * HS_COUNT(hs) - 1])) : HSHRDSIZE)); - PG_FREE_IF_COPY(hs,0); + PG_FREE_IF_COPY(hs, 0); PG_RETURN_DATUM(hval); } diff --git a/contrib/isn/isn.c b/contrib/isn/isn.c index 11cd53a3907..dac760b1114 100644 --- a/contrib/isn/isn.c +++ b/contrib/isn/isn.c @@ -3,11 +3,11 @@ * isn.c * PostgreSQL type definitions for ISNs (ISBN, ISMN, ISSN, EAN13, UPC) * - * Author: German Mendez Bravo (Kronuz) + * Author: German Mendez Bravo (Kronuz) * Portions Copyright (c) 1996-2010, PostgreSQL Global Development Group * * IDENTIFICATION - * $PostgreSQL: pgsql/contrib/isn/isn.c,v 1.13 2010/02/05 04:34:51 momjian Exp $ + * $PostgreSQL: pgsql/contrib/isn/isn.c,v 1.14 2010/02/26 02:00:32 momjian Exp $ * *------------------------------------------------------------------------- */ diff --git a/contrib/isn/isn.h b/contrib/isn/isn.h index 628fdab91b9..fdc72d9b539 100644 --- a/contrib/isn/isn.h +++ b/contrib/isn/isn.h @@ -3,11 +3,11 @@ * isn.h * PostgreSQL type definitions for ISNs (ISBN, ISMN, ISSN, EAN13, UPC) * - * Author: German Mendez Bravo (Kronuz) + * Author: German Mendez Bravo (Kronuz) * Portions Copyright (c) 1996-2010, PostgreSQL Global Development Group * * IDENTIFICATION - * $PostgreSQL: pgsql/contrib/isn/isn.h,v 1.9 2010/02/05 04:34:51 momjian Exp $ + * $PostgreSQL: pgsql/contrib/isn/isn.h,v 1.10 2010/02/26 02:00:32 momjian Exp $ * *------------------------------------------------------------------------- */ diff --git a/contrib/oid2name/oid2name.c b/contrib/oid2name/oid2name.c index 52d6fafeaf4..ff824278aac 100644 --- a/contrib/oid2name/oid2name.c +++ b/contrib/oid2name/oid2name.c @@ -5,7 +5,7 @@ * Originally by * B. Palmer, bpalmer@crimelabs.net 1-17-2001 * - * $PostgreSQL: pgsql/contrib/oid2name/oid2name.c,v 1.37 2010/02/07 20:48:08 tgl Exp $ + * $PostgreSQL: pgsql/contrib/oid2name/oid2name.c,v 1.38 2010/02/26 02:00:32 momjian Exp $ */ #include "postgres_fe.h" @@ -440,7 +440,7 @@ sql_exec_dumpalldbs(PGconn *conn, struct options * opts) /* get the oid and database name from the system pg_database table */ snprintf(todo, sizeof(todo), "SELECT d.oid AS \"Oid\", datname AS \"Database Name\", " - "spcname AS \"Tablespace\" FROM pg_catalog.pg_database d JOIN pg_catalog.pg_tablespace t ON " + "spcname AS \"Tablespace\" FROM pg_catalog.pg_database d JOIN pg_catalog.pg_tablespace t ON " "(dattablespace = t.oid) ORDER BY 2"); sql_exec(conn, todo, opts->quiet); @@ -456,10 +456,10 @@ sql_exec_dumpalltables(PGconn *conn, struct options * opts) char *addfields = ",c.oid AS \"Oid\", nspname AS \"Schema\", spcname as \"Tablespace\" "; snprintf(todo, sizeof(todo), - "SELECT pg_catalog.pg_relation_filenode(c.oid) as \"Filenode\", relname as \"Table Name\" %s " + "SELECT pg_catalog.pg_relation_filenode(c.oid) as \"Filenode\", relname as \"Table Name\" %s " "FROM pg_class c " " LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace " - " LEFT JOIN pg_catalog.pg_database d ON d.datname = pg_catalog.current_database()," + " LEFT JOIN pg_catalog.pg_database d ON d.datname = pg_catalog.current_database()," " pg_catalog.pg_tablespace t " "WHERE relkind IN ('r'%s%s) AND " " %s" @@ -527,7 +527,7 @@ sql_exec_searchtables(PGconn *conn, struct options * opts) /* now build the query */ todo = (char *) myalloc(650 + strlen(qualifiers)); snprintf(todo, 650 + strlen(qualifiers), - "SELECT pg_catalog.pg_relation_filenode(c.oid) as \"Filenode\", relname as \"Table Name\" %s\n" + "SELECT pg_catalog.pg_relation_filenode(c.oid) as \"Filenode\", relname as \"Table Name\" %s\n" "FROM pg_catalog.pg_class c \n" " LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace \n" " LEFT JOIN pg_catalog.pg_database d ON d.datname = pg_catalog.current_database(),\n" diff --git a/contrib/passwordcheck/passwordcheck.c b/contrib/passwordcheck/passwordcheck.c index b18b161227c..adf417769e7 100644 --- a/contrib/passwordcheck/passwordcheck.c +++ b/contrib/passwordcheck/passwordcheck.c @@ -8,7 +8,7 @@ * Author: Laurenz Albe <laurenz.albe@wien.gv.at> * * IDENTIFICATION - * $PostgreSQL: pgsql/contrib/passwordcheck/passwordcheck.c,v 1.2 2010/01/02 16:57:32 momjian Exp $ + * $PostgreSQL: pgsql/contrib/passwordcheck/passwordcheck.c,v 1.3 2010/02/26 02:00:32 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -66,12 +66,12 @@ check_password(const char *username, switch (password_type) { case PASSWORD_TYPE_MD5: + /* - * Unfortunately we cannot perform exhaustive checks on - * encrypted passwords - we are restricted to guessing. - * (Alternatively, we could insist on the password being - * presented non-encrypted, but that has its own security - * disadvantages.) + * Unfortunately we cannot perform exhaustive checks on encrypted + * passwords - we are restricted to guessing. (Alternatively, we + * could insist on the password being presented non-encrypted, but + * that has its own security disadvantages.) * * We only check for username = password. */ @@ -84,6 +84,7 @@ check_password(const char *username, break; case PASSWORD_TYPE_PLAINTEXT: + /* * For unencrypted passwords we can perform better checks */ @@ -106,8 +107,8 @@ check_password(const char *username, for (i = 0; i < pwdlen; i++) { /* - * isalpha() does not work for multibyte encodings - * but let's consider non-ASCII characters non-letters + * isalpha() does not work for multibyte encodings but let's + * consider non-ASCII characters non-letters */ if (isalpha((unsigned char) password[i])) pwd_has_letter = true; @@ -117,7 +118,7 @@ check_password(const char *username, if (!pwd_has_letter || !pwd_has_nonletter) ereport(ERROR, (errcode(ERRCODE_INVALID_PARAMETER_VALUE), - errmsg("password must contain both letters and nonletters"))); + errmsg("password must contain both letters and nonletters"))); #ifdef USE_CRACKLIB /* call cracklib to check password */ diff --git a/contrib/pg_standby/pg_standby.c b/contrib/pg_standby/pg_standby.c index 7df15a978ac..d1a0d60a2c2 100644 --- a/contrib/pg_standby/pg_standby.c +++ b/contrib/pg_standby/pg_standby.c @@ -1,5 +1,5 @@ /* - * $PostgreSQL: pgsql/contrib/pg_standby/pg_standby.c,v 1.27 2009/11/04 12:51:30 heikki Exp $ + * $PostgreSQL: pgsql/contrib/pg_standby/pg_standby.c,v 1.28 2010/02/26 02:00:32 momjian Exp $ * * * pg_standby.c @@ -576,6 +576,7 @@ main(int argc, char **argv) } #ifndef WIN32 + /* * You can send SIGUSR1 to trigger failover. * @@ -614,9 +615,10 @@ main(int argc, char **argv) } break; case 'l': /* Use link */ + /* - * Link feature disabled, possibly permanently. Linking - * causes a problem after recovery ends that is not currently + * Link feature disabled, possibly permanently. Linking causes + * a problem after recovery ends that is not currently * resolved by PostgreSQL. 25 Jun 2009 */ #ifdef NOT_USED diff --git a/contrib/pg_stat_statements/pg_stat_statements.c b/contrib/pg_stat_statements/pg_stat_statements.c index 11dfb6280ad..8fa249e9b8b 100644 --- a/contrib/pg_stat_statements/pg_stat_statements.c +++ b/contrib/pg_stat_statements/pg_stat_statements.c @@ -14,7 +14,7 @@ * Copyright (c) 2008-2010, PostgreSQL Global Development Group * * IDENTIFICATION - * $PostgreSQL: pgsql/contrib/pg_stat_statements/pg_stat_statements.c,v 1.12 2010/01/08 00:38:19 itagaki Exp $ + * $PostgreSQL: pgsql/contrib/pg_stat_statements/pg_stat_statements.c,v 1.13 2010/02/26 02:00:32 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -76,18 +76,18 @@ typedef struct pgssHashKey */ typedef struct Counters { - int64 calls; /* # of times executed */ - double total_time; /* total execution time in seconds */ - int64 rows; /* total # of retrieved or affected rows */ + int64 calls; /* # of times executed */ + double total_time; /* total execution time in seconds */ + int64 rows; /* total # of retrieved or affected rows */ int64 shared_blks_hit; /* # of shared buffer hits */ - int64 shared_blks_read; /* # of shared disk blocks read */ - int64 shared_blks_written;/* # of shared disk blocks written */ - int64 local_blks_hit; /* # of local buffer hits */ + int64 shared_blks_read; /* # of shared disk blocks read */ + int64 shared_blks_written; /* # of shared disk blocks written */ + int64 local_blks_hit; /* # of local buffer hits */ int64 local_blks_read; /* # of local disk blocks read */ - int64 local_blks_written; /* # of local disk blocks written */ - int64 temp_blks_read; /* # of temp blocks read */ - int64 temp_blks_written; /* # of temp blocks written */ - double usage; /* usage factor */ + int64 local_blks_written; /* # of local disk blocks written */ + int64 temp_blks_read; /* # of temp blocks read */ + int64 temp_blks_written; /* # of temp blocks written */ + double usage; /* usage factor */ } Counters; /* @@ -148,7 +148,7 @@ static const struct config_enum_entry track_options[] = static int pgss_max; /* max # statements to track */ static int pgss_track; /* tracking level */ -static bool pgss_track_utility; /* whether to track utility commands */ +static bool pgss_track_utility; /* whether to track utility commands */ static bool pgss_save; /* whether to save stats across shutdown */ @@ -175,12 +175,12 @@ static void pgss_ExecutorRun(QueryDesc *queryDesc, long count); static void pgss_ExecutorEnd(QueryDesc *queryDesc); static void pgss_ProcessUtility(Node *parsetree, - const char *queryString, ParamListInfo params, bool isTopLevel, - DestReceiver *dest, char *completionTag); + const char *queryString, ParamListInfo params, bool isTopLevel, + DestReceiver *dest, char *completionTag); static uint32 pgss_hash_fn(const void *key, Size keysize); static int pgss_match_fn(const void *key1, const void *key2, Size keysize); static void pgss_store(const char *query, double total_time, uint64 rows, - const BufferUsage *bufusage); + const BufferUsage *bufusage); static Size pgss_memsize(void); static pgssEntry *entry_alloc(pgssHashKey *key); static void entry_dealloc(void); @@ -231,7 +231,7 @@ _PG_init(void) NULL); DefineCustomBoolVariable("pg_stat_statements.track_utility", - "Selects whether utility commands are tracked by pg_stat_statements.", + "Selects whether utility commands are tracked by pg_stat_statements.", NULL, &pgss_track_utility, true, @@ -356,8 +356,8 @@ pgss_shmem_startup(void) 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. + * 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; @@ -592,7 +592,7 @@ pgss_ProcessUtility(Node *parsetree, const char *queryString, instr_time start; instr_time duration; uint64 rows = 0; - BufferUsage bufusage; + BufferUsage bufusage; bufusage = pgBufferUsage; INSTR_TIME_SET_CURRENT(start); diff --git a/contrib/pgbench/pgbench.c b/contrib/pgbench/pgbench.c index b38086490a4..b290b7477b1 100644 --- a/contrib/pgbench/pgbench.c +++ b/contrib/pgbench/pgbench.c @@ -4,7 +4,7 @@ * A simple benchmark program for PostgreSQL * Originally written by Tatsuo Ishii and enhanced by many contributors. * - * $PostgreSQL: pgsql/contrib/pgbench/pgbench.c,v 1.96 2010/01/06 01:30:03 itagaki Exp $ + * $PostgreSQL: pgsql/contrib/pgbench/pgbench.c,v 1.97 2010/02/26 02:00:32 momjian Exp $ * Copyright (c) 2000-2010, PostgreSQL Global Development Group * ALL RIGHTS RESERVED; * @@ -28,7 +28,7 @@ */ #ifdef WIN32 -#define FD_SETSIZE 1024 /* set before winsock2.h is included */ +#define FD_SETSIZE 1024 /* set before winsock2.h is included */ #endif /* ! WIN32 */ #include "postgres_fe.h" @@ -66,16 +66,14 @@ #ifdef WIN32 /* Use native win32 threads on Windows */ -typedef struct win32_pthread *pthread_t; -typedef int pthread_attr_t; - -static int pthread_create(pthread_t *thread, pthread_attr_t *attr, void * (*start_routine)(void *), void *arg); -static int pthread_join(pthread_t th, void **thread_return); +typedef struct win32_pthread *pthread_t; +typedef int pthread_attr_t; +static int pthread_create(pthread_t *thread, pthread_attr_t *attr, void *(*start_routine) (void *), void *arg); +static int pthread_join(pthread_t th, void **thread_return); #elif defined(ENABLE_THREAD_SAFETY) /* Use platform-dependent pthread capability */ #include <pthread.h> - #else /* Use emulation with fork. Rename pthread identifiers to avoid conflicts */ @@ -86,12 +84,11 @@ static int pthread_join(pthread_t th, void **thread_return); #define pthread_create pg_pthread_create #define pthread_join pg_pthread_join -typedef struct fork_pthread *pthread_t; -typedef int pthread_attr_t; - -static int pthread_create(pthread_t *thread, pthread_attr_t *attr, void * (*start_routine)(void *), void *arg); -static int pthread_join(pthread_t th, void **thread_return); +typedef struct fork_pthread *pthread_t; +typedef int pthread_attr_t; +static int pthread_create(pthread_t *thread, pthread_attr_t *attr, void *(*start_routine) (void *), void *arg); +static int pthread_join(pthread_t th, void **thread_return); #endif extern char *optarg; @@ -129,7 +126,8 @@ int fillfactor = 100; * end of configurable parameters *********************************************************************/ -#define nbranches 1 /* Makes little sense to change this. Change -s instead */ +#define nbranches 1 /* Makes little sense to change this. Change + * -s instead */ #define ntellers 10 #define naccounts 100000 @@ -156,7 +154,7 @@ typedef struct } Variable; #define MAX_FILES 128 /* max number of SQL script files allowed */ -#define SHELL_COMMAND_SIZE 256 /* maximum size allowed for shell command */ +#define SHELL_COMMAND_SIZE 256 /* maximum size allowed for shell command */ /* * structures used in custom query mode @@ -185,18 +183,18 @@ typedef struct */ typedef struct { - pthread_t thread; /* thread handle */ - CState *state; /* array of CState */ - int nstate; /* length of state[] */ - instr_time start_time; /* thread start time */ + pthread_t thread; /* thread handle */ + CState *state; /* array of CState */ + int nstate; /* length of state[] */ + instr_time start_time; /* thread start time */ } TState; #define INVALID_THREAD ((pthread_t) 0) typedef struct { - instr_time conn_time; - int xacts; + instr_time conn_time; + int xacts; } TResult; /* @@ -224,9 +222,9 @@ typedef struct char *argv[MAX_ARGS]; /* command list */ } Command; -static Command **sql_files[MAX_FILES]; /* SQL script files */ -static int num_files; /* number of script files */ -static int debug = 0; /* debug flag */ +static Command **sql_files[MAX_FILES]; /* SQL script files */ +static int num_files; /* number of script files */ +static int debug = 0; /* debug flag */ /* default scenario */ static char *tpc_b = { @@ -271,7 +269,7 @@ static char *select_only = { /* Function prototypes */ static void setalarm(int seconds); -static void* threadRun(void *arg); +static void *threadRun(void *arg); static void usage(const char *progname) @@ -432,7 +430,7 @@ getVariable(CState *st, char *name) static bool isLegalVariableName(const char *name) { - int i; + int i; for (i = 0; name[i] != '\0'; i++) { @@ -624,29 +622,28 @@ getQueryParams(CState *st, const Command *command, const char **params) static bool runShellCommand(CState *st, char *variable, char **argv, int argc) { - char command[SHELL_COMMAND_SIZE]; - int i, - len = 0; - FILE *fp; - char res[64]; - char *endptr; - int retval; + char command[SHELL_COMMAND_SIZE]; + int i, + len = 0; + FILE *fp; + char res[64]; + char *endptr; + int retval; /* * Join arguments with whilespace separaters. Arguments starting with - * exactly one colon are treated as variables: - * name - append a string "name" - * :var - append a variable named 'var'. - * ::name - append a string ":name" + * exactly one colon are treated as variables: name - append a string + * "name" :var - append a variable named 'var'. ::name - append a string + * ":name" */ for (i = 0; i < argc; i++) { - char *arg; - int arglen; + char *arg; + int arglen; if (argv[i][0] != ':') { - arg = argv[i]; /* a string literal */ + arg = argv[i]; /* a string literal */ } else if (argv[i][1] == ':') { @@ -732,14 +729,14 @@ preparedStatementName(char *buffer, int file, int state) static bool clientDone(CState *st, bool ok) { - (void) ok; /* unused */ + (void) ok; /* unused */ if (st->con != NULL) { PQfinish(st->con); st->con = NULL; } - return false; /* always false */ + return false; /* always false */ } /* return false iff client should be disconnected */ @@ -811,10 +808,10 @@ top: { case PGRES_COMMAND_OK: case PGRES_TUPLES_OK: - break; /* OK */ + break; /* OK */ default: fprintf(stderr, "Client %d aborted in state %d: %s", - st->id, st->state, PQerrorMessage(st->con)); + st->id, st->state, PQerrorMessage(st->con)); PQclear(res); return clientDone(st, false); } @@ -847,7 +844,8 @@ top: if (st->con == NULL) { - instr_time start, end; + instr_time start, + end; INSTR_TIME_SET_CURRENT(start); if ((st->con = doConnect()) == NULL) @@ -1091,7 +1089,7 @@ top: { char *var; int usec; - instr_time now; + instr_time now; if (*argv[1] == ':') { @@ -1124,9 +1122,9 @@ top: } else if (pg_strcasecmp(argv[0], "setshell") == 0) { - bool ret = runShellCommand(st, argv[1], argv + 2, argc - 2); + bool ret = runShellCommand(st, argv[1], argv + 2, argc - 2); - if (timer_exceeded) /* timeout */ + if (timer_exceeded) /* timeout */ return clientDone(st, true); else if (!ret) /* on error */ { @@ -1138,9 +1136,9 @@ top: } else if (pg_strcasecmp(argv[0], "shell") == 0) { - bool ret = runShellCommand(st, NULL, argv + 1, argc - 1); + bool ret = runShellCommand(st, NULL, argv + 1, argc - 1); - if (timer_exceeded) /* timeout */ + if (timer_exceeded) /* timeout */ return clientDone(st, true); else if (!ret) /* on error */ { @@ -1442,7 +1440,7 @@ process_commands(char *buf) */ if (my_commands->argv[1][0] != ':') { - char *c = my_commands->argv[1]; + char *c = my_commands->argv[1]; while (isdigit((unsigned char) *c)) c++; @@ -1667,7 +1665,7 @@ printResults(int ttype, int normal_xacts, int nclients, int nthreads, time_include = INSTR_TIME_GET_DOUBLE(total_time); tps_include = normal_xacts / time_include; tps_exclude = normal_xacts / (time_include - - (INSTR_TIME_GET_DOUBLE(conn_total_time) / nthreads)); + (INSTR_TIME_GET_DOUBLE(conn_total_time) / nthreads)); if (ttype == 0) s = "TPC-B (sort of)"; @@ -1704,8 +1702,8 @@ int main(int argc, char **argv) { int c; - int nclients = 1; /* default number of simulated clients */ - int nthreads = 1; /* default number of threads */ + int nclients = 1; /* default number of simulated clients */ + int nthreads = 1; /* default number of threads */ int is_init_mode = 0; /* initialize mode? */ int is_no_vacuum = 0; /* no vacuum at all before testing? */ int do_vacuum_accounts = 0; /* do vacuum accounts before testing? */ @@ -1826,7 +1824,7 @@ main(int argc, char **argv) } #endif /* HAVE_GETRLIMIT */ break; - case 'j': /* jobs */ + case 'j': /* jobs */ nthreads = atoi(optarg); if (nthreads <= 0) { @@ -2120,7 +2118,8 @@ main(int argc, char **argv) /* the first thread (i = 0) is executed by main thread */ if (i > 0) { - int err = pthread_create(&threads[i].thread, NULL, threadRun, &threads[i]); + int err = pthread_create(&threads[i].thread, NULL, threadRun, &threads[i]); + if (err != 0 || threads[i].thread == INVALID_THREAD) { fprintf(stderr, "cannot create thread: %s\n", strerror(err)); @@ -2138,7 +2137,7 @@ main(int argc, char **argv) INSTR_TIME_SET_ZERO(conn_total_time); for (i = 0; i < nthreads; i++) { - void *ret = NULL; + void *ret = NULL; if (threads[i].thread == INVALID_THREAD) ret = threadRun(&threads[i]); @@ -2147,7 +2146,8 @@ main(int argc, char **argv) if (ret != NULL) { - TResult *r = (TResult *) ret; + TResult *r = (TResult *) ret; + total_xacts += r->xacts; INSTR_TIME_ADD(conn_total_time, r->conn_time); free(ret); @@ -2170,10 +2170,11 @@ threadRun(void *arg) { TState *thread = (TState *) arg; CState *state = thread->state; - TResult *result; - instr_time start, end; + TResult *result; + instr_time start, + end; int nstate = thread->nstate; - int remains = nstate; /* number of remaining clients */ + int remains = nstate; /* number of remaining clients */ int i; result = malloc(sizeof(TResult)); @@ -2202,7 +2203,7 @@ threadRun(void *arg) st->use_file = getrand(0, num_files - 1); if (!doCustom(st, &result->conn_time)) - remains--; /* I've aborted */ + remains--; /* I've aborted */ if (st->ecnt > prev_ecnt && commands[st->state]->type == META_COMMAND) { @@ -2215,10 +2216,10 @@ threadRun(void *arg) while (remains > 0) { - fd_set input_mask; - int maxsock; /* max socket number to be waited */ - int64 now_usec = 0; - int64 min_usec; + fd_set input_mask; + int maxsock; /* max socket number to be waited */ + int64 now_usec = 0; + int64 min_usec; FD_ZERO(&input_mask); @@ -2237,6 +2238,7 @@ threadRun(void *arg) if (min_usec == INT64_MAX) { instr_time now; + INSTR_TIME_SET_CURRENT(now); now_usec = INSTR_TIME_GET_MICROSEC(now); } @@ -2262,18 +2264,20 @@ threadRun(void *arg) goto done; } - FD_SET(sock, &input_mask); + FD_SET (sock, &input_mask); + if (maxsock < sock) maxsock = sock; } if (min_usec > 0 && maxsock != -1) { - int nsocks; /* return from select(2) */ + int nsocks; /* return from select(2) */ if (min_usec != INT64_MAX) { - struct timeval timeout; + struct timeval timeout; + timeout.tv_sec = min_usec / 1000000; timeout.tv_usec = min_usec % 1000000; nsocks = select(maxsock + 1, &input_mask, NULL, NULL, &timeout); @@ -2298,10 +2302,10 @@ threadRun(void *arg) int prev_ecnt = st->ecnt; if (st->con && (FD_ISSET(PQsocket(st->con), &input_mask) - || commands[st->state]->type == META_COMMAND)) + || commands[st->state]->type == META_COMMAND)) { if (!doCustom(st, &result->conn_time)) - remains--; /* I've aborted */ + remains--; /* I've aborted */ } if (st->ecnt > prev_ecnt && commands[st->state]->type == META_COMMAND) @@ -2353,30 +2357,30 @@ setalarm(int seconds) typedef struct fork_pthread { - pid_t pid; - int pipes[2]; -} fork_pthread; + pid_t pid; + int pipes[2]; +} fork_pthread; static int pthread_create(pthread_t *thread, pthread_attr_t *attr, - void * (*start_routine)(void *), + void *(*start_routine) (void *), void *arg) { - fork_pthread *th; - void *ret; - instr_time start_time; + fork_pthread *th; + void *ret; + instr_time start_time; th = (fork_pthread *) malloc(sizeof(fork_pthread)); pipe(th->pipes); th->pid = fork(); - if (th->pid == -1) /* error */ + if (th->pid == -1) /* error */ { free(th); return errno; } - if (th->pid != 0) /* in parent process */ + if (th->pid != 0) /* in parent process */ { close(th->pipes[1]); *thread = th; @@ -2391,11 +2395,11 @@ pthread_create(pthread_t *thread, setalarm(duration); /* - * Set a different random seed in each child process. Otherwise they - * all inherit the parent's state and generate the same "random" - * sequence. (In the threaded case, the different threads will obtain - * subsets of the output of a single random() sequence, which should be - * okay for our purposes.) + * Set a different random seed in each child process. Otherwise they all + * inherit the parent's state and generate the same "random" sequence. + * (In the threaded case, the different threads will obtain subsets of the + * output of a single random() sequence, which should be okay for our + * purposes.) */ INSTR_TIME_SET_CURRENT(start_time); srandom(((unsigned int) INSTR_TIME_GET_MICROSEC(start_time)) + @@ -2411,7 +2415,7 @@ pthread_create(pthread_t *thread, static int pthread_join(pthread_t th, void **thread_return) { - int status; + int status; while (waitpid(th->pid, &status, 0) != th->pid) { @@ -2434,9 +2438,7 @@ pthread_join(pthread_t th, void **thread_return) free(th); return 0; } - #endif - #else /* WIN32 */ static VOID CALLBACK @@ -2468,7 +2470,7 @@ setalarm(int seconds) typedef struct win32_pthread { HANDLE handle; - void *(*routine)(void *); + void *(*routine) (void *); void *arg; void *result; } win32_pthread; @@ -2486,11 +2488,11 @@ win32_pthread_run(void *arg) static int pthread_create(pthread_t *thread, pthread_attr_t *attr, - void * (*start_routine)(void *), + void *(*start_routine) (void *), void *arg) { - int save_errno; - win32_pthread *th; + int save_errno; + win32_pthread *th; th = (win32_pthread *) malloc(sizeof(win32_pthread)); th->routine = start_routine; diff --git a/contrib/unaccent/unaccent.c b/contrib/unaccent/unaccent.c index 99a2ed50dc2..8e012ac1725 100644 --- a/contrib/unaccent/unaccent.c +++ b/contrib/unaccent/unaccent.c @@ -1,12 +1,12 @@ /*------------------------------------------------------------------------- * * unaccent.c - * Text search unaccent dictionary + * Text search unaccent dictionary * * Copyright (c) 2009-2010, PostgreSQL Global Development Group * * IDENTIFICATION - * $PostgreSQL: pgsql/contrib/unaccent/unaccent.c,v 1.4 2010/01/02 16:57:33 momjian Exp $ + * $PostgreSQL: pgsql/contrib/unaccent/unaccent.c,v 1.5 2010/02/26 02:00:32 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -25,26 +25,27 @@ PG_MODULE_MAGIC; /* - * Unaccent dictionary uses uncompressed suffix tree to find a - * character to replace. Each node of tree is an array of + * Unaccent dictionary uses uncompressed suffix tree to find a + * character to replace. Each node of tree is an array of * SuffixChar struct with length = 256 (n-th element of array * corresponds to byte) */ -typedef struct SuffixChar { - struct SuffixChar *nextChar; - char *replaceTo; - int replacelen; +typedef struct SuffixChar +{ + struct SuffixChar *nextChar; + char *replaceTo; + int replacelen; } SuffixChar; /* * placeChar - put str into tree's structure, byte by byte. */ -static SuffixChar* +static SuffixChar * placeChar(SuffixChar *node, unsigned char *str, int lenstr, char *replaceTo, int replacelen) { - SuffixChar *curnode; + SuffixChar *curnode; - if ( !node ) + if (!node) { node = palloc(sizeof(SuffixChar) * 256); memset(node, 0, sizeof(SuffixChar) * 256); @@ -52,20 +53,20 @@ placeChar(SuffixChar *node, unsigned char *str, int lenstr, char *replaceTo, int curnode = node + *str; - if ( lenstr == 1 ) + if (lenstr == 1) { - if ( curnode->replaceTo ) + if (curnode->replaceTo) elog(WARNING, "duplicate TO argument, use first one"); else { curnode->replacelen = replacelen; - curnode->replaceTo = palloc( replacelen ); + curnode->replaceTo = palloc(replacelen); memcpy(curnode->replaceTo, replaceTo, replacelen); } } else { - curnode->nextChar = placeChar( curnode->nextChar, str+1, lenstr-1, replaceTo, replacelen); + curnode->nextChar = placeChar(curnode->nextChar, str + 1, lenstr - 1, replaceTo, replacelen); } return node; @@ -75,13 +76,13 @@ placeChar(SuffixChar *node, unsigned char *str, int lenstr, char *replaceTo, int * initSuffixTree - create suffix tree from file. Function converts * UTF8-encoded file into current encoding. */ -static SuffixChar* -initSuffixTree(char *filename) +static SuffixChar * +initSuffixTree(char *filename) { - SuffixChar * volatile rootSuffixTree = NULL; + SuffixChar *volatile rootSuffixTree = NULL; MemoryContext ccxt = CurrentMemoryContext; - tsearch_readline_state trst; - volatile bool skip; + tsearch_readline_state trst; + volatile bool skip; filename = get_tsearch_config_filename(filename, "rules"); if (!tsearch_readline_begin(&trst, filename)) @@ -90,34 +91,34 @@ initSuffixTree(char *filename) errmsg("could not open unaccent file \"%s\": %m", filename))); - do + do { - char src[4096]; - char trg[4096]; - int srclen; - int trglen; - char *line = NULL; + char src[4096]; + char trg[4096]; + int srclen; + int trglen; + char *line = NULL; skip = true; PG_TRY(); { /* - * pg_do_encoding_conversion() (called by tsearch_readline()) - * will emit exception if it finds untranslatable characters in current locale. - * We just skip such characters. + * pg_do_encoding_conversion() (called by tsearch_readline()) will + * emit exception if it finds untranslatable characters in current + * locale. We just skip such characters. */ while ((line = tsearch_readline(&trst)) != NULL) { - if ( sscanf(line, "%s\t%s\n", src, trg)!=2 ) + if (sscanf(line, "%s\t%s\n", src, trg) != 2) continue; srclen = strlen(src); trglen = strlen(trg); - rootSuffixTree = placeChar(rootSuffixTree, - (unsigned char*)src, srclen, - trg, trglen); + rootSuffixTree = placeChar(rootSuffixTree, + (unsigned char *) src, srclen, + trg, trglen); skip = false; pfree(line); } @@ -141,7 +142,7 @@ initSuffixTree(char *filename) } PG_END_TRY(); } - while(skip); + while (skip); tsearch_readline_end(&trst); @@ -151,13 +152,13 @@ initSuffixTree(char *filename) /* * findReplaceTo - find multibyte character in tree */ -static SuffixChar * -findReplaceTo( SuffixChar *node, unsigned char *src, int srclen ) +static SuffixChar * +findReplaceTo(SuffixChar *node, unsigned char *src, int srclen) { - while( node ) + while (node) { node = node + *src; - if ( srclen == 1 ) + if (srclen == 1) return node; src++; @@ -169,13 +170,13 @@ findReplaceTo( SuffixChar *node, unsigned char *src, int srclen ) } PG_FUNCTION_INFO_V1(unaccent_init); -Datum unaccent_init(PG_FUNCTION_ARGS); +Datum unaccent_init(PG_FUNCTION_ARGS); Datum unaccent_init(PG_FUNCTION_ARGS) { - List *dictoptions = (List *) PG_GETARG_POINTER(0); + List *dictoptions = (List *) PG_GETARG_POINTER(0); SuffixChar *rootSuffixTree = NULL; - bool fileloaded = false; + bool fileloaded = false; ListCell *l; foreach(l, dictoptions) @@ -188,8 +189,8 @@ unaccent_init(PG_FUNCTION_ARGS) ereport(ERROR, (errcode(ERRCODE_INVALID_PARAMETER_VALUE), errmsg("multiple Rules parameters"))); - rootSuffixTree = initSuffixTree(defGetString(defel)); - fileloaded = true; + rootSuffixTree = initSuffixTree(defGetString(defel)); + fileloaded = true; } else { @@ -211,51 +212,52 @@ unaccent_init(PG_FUNCTION_ARGS) } PG_FUNCTION_INFO_V1(unaccent_lexize); -Datum unaccent_lexize(PG_FUNCTION_ARGS); +Datum unaccent_lexize(PG_FUNCTION_ARGS); Datum unaccent_lexize(PG_FUNCTION_ARGS) { - SuffixChar *rootSuffixTree = (SuffixChar*)PG_GETARG_POINTER(0); - char *srcchar = (char *) PG_GETARG_POINTER(1); + SuffixChar *rootSuffixTree = (SuffixChar *) PG_GETARG_POINTER(0); + char *srcchar = (char *) PG_GETARG_POINTER(1); int32 len = PG_GETARG_INT32(2); - char *srcstart, *trgchar = NULL; + char *srcstart, + *trgchar = NULL; int charlen; TSLexeme *res = NULL; SuffixChar *node; srcstart = srcchar; - while( srcchar - srcstart < len ) + while (srcchar - srcstart < len) { charlen = pg_mblen(srcchar); - node = findReplaceTo( rootSuffixTree, (unsigned char *) srcchar, charlen ); - if ( node && node->replaceTo ) + node = findReplaceTo(rootSuffixTree, (unsigned char *) srcchar, charlen); + if (node && node->replaceTo) { - if ( !res ) + if (!res) { /* allocate res only it it's needed */ res = palloc0(sizeof(TSLexeme) * 2); - res->lexeme = trgchar = palloc( len * pg_database_encoding_max_length() + 1 /* \0 */ ); + res->lexeme = trgchar = palloc(len * pg_database_encoding_max_length() + 1 /* \0 */ ); res->flags = TSL_FILTER; - if ( srcchar != srcstart ) + if (srcchar != srcstart) { memcpy(trgchar, srcstart, srcchar - srcstart); trgchar += (srcchar - srcstart); } } - memcpy( trgchar, node->replaceTo, node->replacelen ); - trgchar += node->replacelen; + memcpy(trgchar, node->replaceTo, node->replacelen); + trgchar += node->replacelen; } - else if ( res ) + else if (res) { - memcpy( trgchar, srcchar, charlen ); + memcpy(trgchar, srcchar, charlen); trgchar += charlen; } srcchar += charlen; } - if ( res ) + if (res) *trgchar = '\0'; PG_RETURN_POINTER(res); @@ -265,15 +267,15 @@ unaccent_lexize(PG_FUNCTION_ARGS) * Function-like wrapper for dictionary */ PG_FUNCTION_INFO_V1(unaccent_dict); -Datum unaccent_dict(PG_FUNCTION_ARGS); +Datum unaccent_dict(PG_FUNCTION_ARGS); Datum unaccent_dict(PG_FUNCTION_ARGS) { - text *str; - int strArg; - Oid dictOid; - TSDictionaryCacheEntry *dict; - TSLexeme *res; + text *str; + int strArg; + Oid dictOid; + TSDictionaryCacheEntry *dict; + TSLexeme *res; if (PG_NARGS() == 1) { @@ -290,25 +292,25 @@ unaccent_dict(PG_FUNCTION_ARGS) dict = lookup_ts_dictionary_cache(dictOid); res = (TSLexeme *) DatumGetPointer(FunctionCall4(&(dict->lexize), - PointerGetDatum(dict->dictData), - PointerGetDatum(VARDATA(str)), - Int32GetDatum(VARSIZE(str) - VARHDRSZ), + PointerGetDatum(dict->dictData), + PointerGetDatum(VARDATA(str)), + Int32GetDatum(VARSIZE(str) - VARHDRSZ), PointerGetDatum(NULL))); PG_FREE_IF_COPY(str, strArg); - if ( res == NULL ) + if (res == NULL) { PG_RETURN_TEXT_P(PG_GETARG_TEXT_P_COPY(strArg)); } - else if ( res->lexeme == NULL ) + else if (res->lexeme == NULL) { pfree(res); PG_RETURN_TEXT_P(PG_GETARG_TEXT_P_COPY(strArg)); } else { - text *txt = cstring_to_text(res->lexeme); + text *txt = cstring_to_text(res->lexeme); pfree(res->lexeme); pfree(res); |