Dodge a macro-name conflict with Perl.

Some versions of Perl export a macro named HS_KEY.  This creates a
conflict in contrib/hstore_plperl against hstore's macro of the same
name.  The most future-proof solution seems to be to rename our macro;
I chose HSTORE_KEY.  For consistency, rename HS_VAL and related macros
similarly.

Back-patch to 9.5.  contrib/hstore_plperl doesn't exist before that
so there is no need to worry about the conflict in older releases.

Per reports from Marco Atzeri and Mike Blackwell.
This commit is contained in:
Tom Lane 2015-11-19 14:54:05 -05:00
parent db135e834a
commit 68c1d7d42e
8 changed files with 151 additions and 127 deletions

View file

@ -76,11 +76,11 @@ typedef struct
#define STRPTR(x) ( (char*)(ARRPTR(x) + HS_COUNT((HStore*)(x)) * 2) ) #define STRPTR(x) ( (char*)(ARRPTR(x) + HS_COUNT((HStore*)(x)) * 2) )
/* note multiple/non evaluations */ /* note multiple/non evaluations */
#define HS_KEY(arr_,str_,i_) ((str_) + HSE_OFF((arr_)[2*(i_)])) #define HSTORE_KEY(arr_,str_,i_) ((str_) + HSE_OFF((arr_)[2*(i_)]))
#define HS_VAL(arr_,str_,i_) ((str_) + HSE_OFF((arr_)[2*(i_)+1])) #define HSTORE_VAL(arr_,str_,i_) ((str_) + HSE_OFF((arr_)[2*(i_)+1]))
#define HS_KEYLEN(arr_,i_) (HSE_LEN((arr_)[2*(i_)])) #define HSTORE_KEYLEN(arr_,i_) (HSE_LEN((arr_)[2*(i_)]))
#define HS_VALLEN(arr_,i_) (HSE_LEN((arr_)[2*(i_)+1])) #define HSTORE_VALLEN(arr_,i_) (HSE_LEN((arr_)[2*(i_)+1]))
#define HS_VALISNULL(arr_,i_) (HSE_ISNULL((arr_)[2*(i_)+1])) #define HSTORE_VALISNULL(arr_,i_) (HSE_ISNULL((arr_)[2*(i_)+1]))
/* /*
* currently, these following macros are the _only_ places that rely * currently, these following macros are the _only_ places that rely

View file

@ -149,7 +149,7 @@ hstoreValidNewFormat(HStore *hs)
for (i = 1; i < count; ++i) for (i = 1; i < count; ++i)
{ {
if (HS_KEYLEN(entries, i) < HS_KEYLEN(entries, i - 1)) if (HSTORE_KEYLEN(entries, i) < HSTORE_KEYLEN(entries, i - 1))
return 0; return 0;
if (HSE_ISNULL(entries[2 * i])) if (HSE_ISNULL(entries[2 * i]))
return 0; return 0;

View file

@ -59,14 +59,16 @@ gin_extract_hstore(PG_FUNCTION_ARGS)
{ {
text *item; text *item;
item = makeitem(HS_KEY(hsent, ptr, i), HS_KEYLEN(hsent, i), item = makeitem(HSTORE_KEY(hsent, ptr, i),
HSTORE_KEYLEN(hsent, i),
KEYFLAG); KEYFLAG);
entries[2 * i] = PointerGetDatum(item); entries[2 * i] = PointerGetDatum(item);
if (HS_VALISNULL(hsent, i)) if (HSTORE_VALISNULL(hsent, i))
item = makeitem(NULL, 0, NULLFLAG); item = makeitem(NULL, 0, NULLFLAG);
else else
item = makeitem(HS_VAL(hsent, ptr, i), HS_VALLEN(hsent, i), item = makeitem(HSTORE_VAL(hsent, ptr, i),
HSTORE_VALLEN(hsent, i),
VALFLAG); VALFLAG);
entries[2 * i + 1] = PointerGetDatum(item); entries[2 * i + 1] = PointerGetDatum(item);
} }

View file

@ -129,11 +129,13 @@ ghstore_compress(PG_FUNCTION_ARGS)
{ {
int h; int h;
h = crc32_sz((char *) HS_KEY(hsent, ptr, i), HS_KEYLEN(hsent, i)); h = crc32_sz((char *) HSTORE_KEY(hsent, ptr, i),
HSTORE_KEYLEN(hsent, i));
HASH(GETSIGN(res), h); HASH(GETSIGN(res), h);
if (!HS_VALISNULL(hsent, i)) if (!HSTORE_VALISNULL(hsent, i))
{ {
h = crc32_sz((char *) HS_VAL(hsent, ptr, i), HS_VALLEN(hsent, i)); h = crc32_sz((char *) HSTORE_VAL(hsent, ptr, i),
HSTORE_VALLEN(hsent, i));
HASH(GETSIGN(res), h); HASH(GETSIGN(res), h);
} }
} }
@ -524,13 +526,15 @@ ghstore_consistent(PG_FUNCTION_ARGS)
for (i = 0; res && i < count; ++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 *) HSTORE_KEY(qe, qv, i),
HSTORE_KEYLEN(qe, i));
if (GETBIT(sign, HASHVAL(crc))) if (GETBIT(sign, HASHVAL(crc)))
{ {
if (!HS_VALISNULL(qe, i)) if (!HSTORE_VALISNULL(qe, i))
{ {
crc = crc32_sz((char *) HS_VAL(qe, qv, i), HS_VALLEN(qe, i)); crc = crc32_sz((char *) HSTORE_VAL(qe, qv, i),
HSTORE_VALLEN(qe, i));
if (!GETBIT(sign, HASHVAL(crc))) if (!GETBIT(sign, HASHVAL(crc)))
res = false; res = false;
} }

View file

@ -1068,7 +1068,7 @@ hstore_populate_record(PG_FUNCTION_ARGS)
column_info->column_type = column_type; column_info->column_type = column_type;
} }
if (idx < 0 || HS_VALISNULL(entries, idx)) if (idx < 0 || HSTORE_VALISNULL(entries, idx))
{ {
/* /*
* need InputFunctionCall to happen even for nulls, so that domain * need InputFunctionCall to happen even for nulls, so that domain
@ -1081,9 +1081,9 @@ hstore_populate_record(PG_FUNCTION_ARGS)
} }
else else
{ {
vallen = HS_VALLEN(entries, idx); vallen = HSTORE_VALLEN(entries, idx);
value = palloc(1 + vallen); value = palloc(1 + vallen);
memcpy(value, HS_VAL(entries, ptr, idx), vallen); memcpy(value, HSTORE_VAL(entries, ptr, idx), vallen);
value[vallen] = 0; value[vallen] = 0;
values[i] = InputFunctionCall(&column_info->proc, value, values[i] = InputFunctionCall(&column_info->proc, value,
@ -1144,11 +1144,11 @@ hstore_out(PG_FUNCTION_ARGS)
for (i = 0; i < count; i++) for (i = 0; i < count; i++)
{ {
/* include "" and => and comma-space */ /* include "" and => and comma-space */
buflen += 6 + 2 * HS_KEYLEN(entries, i); buflen += 6 + 2 * HSTORE_KEYLEN(entries, i);
/* include "" only if nonnull */ /* include "" only if nonnull */
buflen += 2 + (HS_VALISNULL(entries, i) buflen += 2 + (HSTORE_VALISNULL(entries, i)
? 2 ? 2
: 2 * HS_VALLEN(entries, i)); : 2 * HSTORE_VALLEN(entries, i));
} }
out = ptr = palloc(buflen); out = ptr = palloc(buflen);
@ -1156,11 +1156,11 @@ hstore_out(PG_FUNCTION_ARGS)
for (i = 0; i < count; i++) for (i = 0; i < count; i++)
{ {
*ptr++ = '"'; *ptr++ = '"';
ptr = cpw(ptr, HS_KEY(entries, base, i), HS_KEYLEN(entries, i)); ptr = cpw(ptr, HSTORE_KEY(entries, base, i), HSTORE_KEYLEN(entries, i));
*ptr++ = '"'; *ptr++ = '"';
*ptr++ = '='; *ptr++ = '=';
*ptr++ = '>'; *ptr++ = '>';
if (HS_VALISNULL(entries, i)) if (HSTORE_VALISNULL(entries, i))
{ {
*ptr++ = 'N'; *ptr++ = 'N';
*ptr++ = 'U'; *ptr++ = 'U';
@ -1170,7 +1170,7 @@ hstore_out(PG_FUNCTION_ARGS)
else else
{ {
*ptr++ = '"'; *ptr++ = '"';
ptr = cpw(ptr, HS_VAL(entries, base, i), HS_VALLEN(entries, i)); ptr = cpw(ptr, HSTORE_VAL(entries, base, i), HSTORE_VALLEN(entries, i));
*ptr++ = '"'; *ptr++ = '"';
} }
@ -1203,20 +1203,20 @@ hstore_send(PG_FUNCTION_ARGS)
for (i = 0; i < count; i++) for (i = 0; i < count; i++)
{ {
int32 keylen = HS_KEYLEN(entries, i); int32 keylen = HSTORE_KEYLEN(entries, i);
pq_sendint(&buf, keylen, 4); pq_sendint(&buf, keylen, 4);
pq_sendtext(&buf, HS_KEY(entries, base, i), keylen); pq_sendtext(&buf, HSTORE_KEY(entries, base, i), keylen);
if (HS_VALISNULL(entries, i)) if (HSTORE_VALISNULL(entries, i))
{ {
pq_sendint(&buf, -1, 4); pq_sendint(&buf, -1, 4);
} }
else else
{ {
int32 vallen = HS_VALLEN(entries, i); int32 vallen = HSTORE_VALLEN(entries, i);
pq_sendint(&buf, vallen, 4); pq_sendint(&buf, vallen, 4);
pq_sendtext(&buf, HS_VAL(entries, base, i), vallen); pq_sendtext(&buf, HSTORE_VAL(entries, base, i), vallen);
} }
} }
@ -1255,20 +1255,24 @@ hstore_to_json_loose(PG_FUNCTION_ARGS)
for (i = 0; i < count; i++) for (i = 0; i < count; i++)
{ {
resetStringInfo(&tmp); resetStringInfo(&tmp);
appendBinaryStringInfo(&tmp, HS_KEY(entries, base, i), HS_KEYLEN(entries, i)); appendBinaryStringInfo(&tmp, HSTORE_KEY(entries, base, i),
HSTORE_KEYLEN(entries, i));
escape_json(&dst, tmp.data); escape_json(&dst, tmp.data);
appendStringInfoString(&dst, ": "); appendStringInfoString(&dst, ": ");
if (HS_VALISNULL(entries, i)) if (HSTORE_VALISNULL(entries, i))
appendStringInfoString(&dst, "null"); appendStringInfoString(&dst, "null");
/* guess that values of 't' or 'f' are booleans */ /* guess that values of 't' or 'f' are booleans */
else if (HS_VALLEN(entries, i) == 1 && *(HS_VAL(entries, base, i)) == 't') else if (HSTORE_VALLEN(entries, i) == 1 &&
*(HSTORE_VAL(entries, base, i)) == 't')
appendStringInfoString(&dst, "true"); appendStringInfoString(&dst, "true");
else if (HS_VALLEN(entries, i) == 1 && *(HS_VAL(entries, base, i)) == 'f') else if (HSTORE_VALLEN(entries, i) == 1 &&
*(HSTORE_VAL(entries, base, i)) == 'f')
appendStringInfoString(&dst, "false"); appendStringInfoString(&dst, "false");
else else
{ {
resetStringInfo(&tmp); resetStringInfo(&tmp);
appendBinaryStringInfo(&tmp, HS_VAL(entries, base, i), HS_VALLEN(entries, i)); appendBinaryStringInfo(&tmp, HSTORE_VAL(entries, base, i),
HSTORE_VALLEN(entries, i));
if (IsValidJsonNumber(tmp.data, tmp.len)) if (IsValidJsonNumber(tmp.data, tmp.len))
appendBinaryStringInfo(&dst, tmp.data, tmp.len); appendBinaryStringInfo(&dst, tmp.data, tmp.len);
else else
@ -1306,15 +1310,17 @@ hstore_to_json(PG_FUNCTION_ARGS)
for (i = 0; i < count; i++) for (i = 0; i < count; i++)
{ {
resetStringInfo(&tmp); resetStringInfo(&tmp);
appendBinaryStringInfo(&tmp, HS_KEY(entries, base, i), HS_KEYLEN(entries, i)); appendBinaryStringInfo(&tmp, HSTORE_KEY(entries, base, i),
HSTORE_KEYLEN(entries, i));
escape_json(&dst, tmp.data); escape_json(&dst, tmp.data);
appendStringInfoString(&dst, ": "); appendStringInfoString(&dst, ": ");
if (HS_VALISNULL(entries, i)) if (HSTORE_VALISNULL(entries, i))
appendStringInfoString(&dst, "null"); appendStringInfoString(&dst, "null");
else else
{ {
resetStringInfo(&tmp); resetStringInfo(&tmp);
appendBinaryStringInfo(&tmp, HS_VAL(entries, base, i), HS_VALLEN(entries, i)); appendBinaryStringInfo(&tmp, HSTORE_VAL(entries, base, i),
HSTORE_VALLEN(entries, i));
escape_json(&dst, tmp.data); escape_json(&dst, tmp.data);
} }
@ -1346,20 +1352,20 @@ hstore_to_jsonb(PG_FUNCTION_ARGS)
val; val;
key.type = jbvString; key.type = jbvString;
key.val.string.len = HS_KEYLEN(entries, i); key.val.string.len = HSTORE_KEYLEN(entries, i);
key.val.string.val = HS_KEY(entries, base, i); key.val.string.val = HSTORE_KEY(entries, base, i);
(void) pushJsonbValue(&state, WJB_KEY, &key); (void) pushJsonbValue(&state, WJB_KEY, &key);
if (HS_VALISNULL(entries, i)) if (HSTORE_VALISNULL(entries, i))
{ {
val.type = jbvNull; val.type = jbvNull;
} }
else else
{ {
val.type = jbvString; val.type = jbvString;
val.val.string.len = HS_VALLEN(entries, i); val.val.string.len = HSTORE_VALLEN(entries, i);
val.val.string.val = HS_VAL(entries, base, i); val.val.string.val = HSTORE_VAL(entries, base, i);
} }
(void) pushJsonbValue(&state, WJB_VALUE, &val); (void) pushJsonbValue(&state, WJB_VALUE, &val);
} }
@ -1393,22 +1399,24 @@ hstore_to_jsonb_loose(PG_FUNCTION_ARGS)
val; val;
key.type = jbvString; key.type = jbvString;
key.val.string.len = HS_KEYLEN(entries, i); key.val.string.len = HSTORE_KEYLEN(entries, i);
key.val.string.val = HS_KEY(entries, base, i); key.val.string.val = HSTORE_KEY(entries, base, i);
(void) pushJsonbValue(&state, WJB_KEY, &key); (void) pushJsonbValue(&state, WJB_KEY, &key);
if (HS_VALISNULL(entries, i)) if (HSTORE_VALISNULL(entries, i))
{ {
val.type = jbvNull; val.type = jbvNull;
} }
/* guess that values of 't' or 'f' are booleans */ /* guess that values of 't' or 'f' are booleans */
else if (HS_VALLEN(entries, i) == 1 && *(HS_VAL(entries, base, i)) == 't') else if (HSTORE_VALLEN(entries, i) == 1 &&
*(HSTORE_VAL(entries, base, i)) == 't')
{ {
val.type = jbvBool; val.type = jbvBool;
val.val.boolean = true; val.val.boolean = true;
} }
else if (HS_VALLEN(entries, i) == 1 && *(HS_VAL(entries, base, i)) == 'f') else if (HSTORE_VALLEN(entries, i) == 1 &&
*(HSTORE_VAL(entries, base, i)) == 'f')
{ {
val.type = jbvBool; val.type = jbvBool;
val.val.boolean = false; val.val.boolean = false;
@ -1418,7 +1426,8 @@ hstore_to_jsonb_loose(PG_FUNCTION_ARGS)
is_number = false; is_number = false;
resetStringInfo(&tmp); resetStringInfo(&tmp);
appendBinaryStringInfo(&tmp, HS_VAL(entries, base, i), HS_VALLEN(entries, i)); appendBinaryStringInfo(&tmp, HSTORE_VAL(entries, base, i),
HSTORE_VALLEN(entries, i));
/* /*
* don't treat something with a leading zero followed by another * don't treat something with a leading zero followed by another
@ -1461,14 +1470,14 @@ hstore_to_jsonb_loose(PG_FUNCTION_ARGS)
{ {
val.type = jbvNumeric; val.type = jbvNumeric;
val.val.numeric = DatumGetNumeric( val.val.numeric = DatumGetNumeric(
DirectFunctionCall3(numeric_in, CStringGetDatum(tmp.data), 0, -1)); DirectFunctionCall3(numeric_in,
CStringGetDatum(tmp.data), 0, -1));
} }
else else
{ {
val.type = jbvString; val.type = jbvString;
val.val.string.len = HS_VALLEN(entries, i); val.val.string.len = HSTORE_VALLEN(entries, i);
val.val.string.val = HS_VAL(entries, base, i); val.val.string.val = HSTORE_VAL(entries, base, i);
} }
} }
(void) pushJsonbValue(&state, WJB_VALUE, &val); (void) pushJsonbValue(&state, WJB_VALUE, &val);

View file

@ -48,10 +48,10 @@ hstoreFindKey(HStore *hs, int *lowbound, char *key, int keylen)
stopMiddle = stopLow + (stopHigh - stopLow) / 2; stopMiddle = stopLow + (stopHigh - stopLow) / 2;
if (HS_KEYLEN(entries, stopMiddle) == keylen) if (HSTORE_KEYLEN(entries, stopMiddle) == keylen)
difference = memcmp(HS_KEY(entries, base, stopMiddle), key, keylen); difference = memcmp(HSTORE_KEY(entries, base, stopMiddle), key, keylen);
else else
difference = (HS_KEYLEN(entries, stopMiddle) > keylen) ? 1 : -1; difference = (HSTORE_KEYLEN(entries, stopMiddle) > keylen) ? 1 : -1;
if (difference == 0) if (difference == 0)
{ {
@ -137,11 +137,11 @@ hstore_fetchval(PG_FUNCTION_ARGS)
int idx = hstoreFindKey(hs, NULL, int idx = hstoreFindKey(hs, NULL,
VARDATA_ANY(key), VARSIZE_ANY_EXHDR(key)); VARDATA_ANY(key), VARSIZE_ANY_EXHDR(key));
if (idx < 0 || HS_VALISNULL(entries, idx)) if (idx < 0 || HSTORE_VALISNULL(entries, idx))
PG_RETURN_NULL(); PG_RETURN_NULL();
out = cstring_to_text_with_len(HS_VAL(entries, STRPTR(hs), idx), out = cstring_to_text_with_len(HSTORE_VAL(entries, STRPTR(hs), idx),
HS_VALLEN(entries, idx)); HSTORE_VALLEN(entries, idx));
PG_RETURN_TEXT_P(out); PG_RETURN_TEXT_P(out);
} }
@ -237,7 +237,7 @@ hstore_defined(PG_FUNCTION_ARGS)
HEntry *entries = ARRPTR(hs); HEntry *entries = ARRPTR(hs);
int idx = hstoreFindKey(hs, NULL, int idx = hstoreFindKey(hs, NULL,
VARDATA_ANY(key), VARSIZE_ANY_EXHDR(key)); VARDATA_ANY(key), VARSIZE_ANY_EXHDR(key));
bool res = (idx >= 0 && !HS_VALISNULL(entries, idx)); bool res = (idx >= 0 && !HSTORE_VALISNULL(entries, idx));
PG_RETURN_BOOL(res); PG_RETURN_BOOL(res);
} }
@ -271,14 +271,15 @@ hstore_delete(PG_FUNCTION_ARGS)
for (i = 0; i < count; ++i) for (i = 0; i < count; ++i)
{ {
int len = HS_KEYLEN(es, i); int len = HSTORE_KEYLEN(es, i);
char *ptrs = HS_KEY(es, bufs, i); char *ptrs = HSTORE_KEY(es, bufs, i);
if (!(len == keylen && memcmp(ptrs, keyptr, keylen) == 0)) if (!(len == keylen && memcmp(ptrs, keyptr, keylen) == 0))
{ {
int vallen = HS_VALLEN(es, i); int vallen = HSTORE_VALLEN(es, i);
HS_COPYITEM(ed, bufd, ptrd, ptrs, len, vallen, HS_VALISNULL(es, i)); HS_COPYITEM(ed, bufd, ptrd, ptrs, len, vallen,
HSTORE_VALISNULL(es, i));
++outcount; ++outcount;
} }
} }
@ -338,10 +339,10 @@ hstore_delete_array(PG_FUNCTION_ARGS)
difference = -1; difference = -1;
else else
{ {
int skeylen = HS_KEYLEN(es, i); int skeylen = HSTORE_KEYLEN(es, i);
if (skeylen == key_pairs[j].keylen) if (skeylen == key_pairs[j].keylen)
difference = memcmp(HS_KEY(es, ps, i), difference = memcmp(HSTORE_KEY(es, ps, i),
key_pairs[j].key, key_pairs[j].key,
key_pairs[j].keylen); key_pairs[j].keylen);
else else
@ -355,8 +356,8 @@ hstore_delete_array(PG_FUNCTION_ARGS)
else else
{ {
HS_COPYITEM(ed, bufd, pd, HS_COPYITEM(ed, bufd, pd,
HS_KEY(es, ps, i), HS_KEYLEN(es, i), HSTORE_KEY(es, ps, i), HSTORE_KEYLEN(es, i),
HS_VALLEN(es, i), HS_VALISNULL(es, i)); HSTORE_VALLEN(es, i), HSTORE_VALISNULL(es, i));
++outcount; ++outcount;
++i; ++i;
} }
@ -421,12 +422,12 @@ hstore_delete_hstore(PG_FUNCTION_ARGS)
difference = -1; difference = -1;
else else
{ {
int skeylen = HS_KEYLEN(es, i); int skeylen = HSTORE_KEYLEN(es, i);
int s2keylen = HS_KEYLEN(es2, j); int s2keylen = HSTORE_KEYLEN(es2, j);
if (skeylen == s2keylen) if (skeylen == s2keylen)
difference = memcmp(HS_KEY(es, ps, i), difference = memcmp(HSTORE_KEY(es, ps, i),
HS_KEY(es2, ps2, j), HSTORE_KEY(es2, ps2, j),
skeylen); skeylen);
else else
difference = (skeylen > s2keylen) ? 1 : -1; difference = (skeylen > s2keylen) ? 1 : -1;
@ -436,16 +437,17 @@ hstore_delete_hstore(PG_FUNCTION_ARGS)
++j; ++j;
else if (difference == 0) else if (difference == 0)
{ {
int svallen = HS_VALLEN(es, i); int svallen = HSTORE_VALLEN(es, i);
int snullval = HS_VALISNULL(es, i); int snullval = HSTORE_VALISNULL(es, i);
if (snullval != HS_VALISNULL(es2, j) if (snullval != HSTORE_VALISNULL(es2, j) ||
|| (!snullval (!snullval && (svallen != HSTORE_VALLEN(es2, j) ||
&& (svallen != HS_VALLEN(es2, j) memcmp(HSTORE_VAL(es, ps, i),
|| memcmp(HS_VAL(es, ps, i), HS_VAL(es2, ps2, j), svallen) != 0))) HSTORE_VAL(es2, ps2, j),
svallen) != 0)))
{ {
HS_COPYITEM(ed, bufd, pd, HS_COPYITEM(ed, bufd, pd,
HS_KEY(es, ps, i), HS_KEYLEN(es, i), HSTORE_KEY(es, ps, i), HSTORE_KEYLEN(es, i),
svallen, snullval); svallen, snullval);
++outcount; ++outcount;
} }
@ -454,8 +456,8 @@ hstore_delete_hstore(PG_FUNCTION_ARGS)
else else
{ {
HS_COPYITEM(ed, bufd, pd, HS_COPYITEM(ed, bufd, pd,
HS_KEY(es, ps, i), HS_KEYLEN(es, i), HSTORE_KEY(es, ps, i), HSTORE_KEYLEN(es, i),
HS_VALLEN(es, i), HS_VALISNULL(es, i)); HSTORE_VALLEN(es, i), HSTORE_VALISNULL(es, i));
++outcount; ++outcount;
++i; ++i;
} }
@ -530,12 +532,12 @@ hstore_concat(PG_FUNCTION_ARGS)
difference = -1; difference = -1;
else else
{ {
int s1keylen = HS_KEYLEN(es1, s1idx); int s1keylen = HSTORE_KEYLEN(es1, s1idx);
int s2keylen = HS_KEYLEN(es2, s2idx); int s2keylen = HSTORE_KEYLEN(es2, s2idx);
if (s1keylen == s2keylen) if (s1keylen == s2keylen)
difference = memcmp(HS_KEY(es1, ps1, s1idx), difference = memcmp(HSTORE_KEY(es1, ps1, s1idx),
HS_KEY(es2, ps2, s2idx), HSTORE_KEY(es2, ps2, s2idx),
s1keylen); s1keylen);
else else
difference = (s1keylen > s2keylen) ? 1 : -1; difference = (s1keylen > s2keylen) ? 1 : -1;
@ -544,8 +546,8 @@ hstore_concat(PG_FUNCTION_ARGS)
if (difference >= 0) if (difference >= 0)
{ {
HS_COPYITEM(ed, bufd, pd, HS_COPYITEM(ed, bufd, pd,
HS_KEY(es2, ps2, s2idx), HS_KEYLEN(es2, s2idx), HSTORE_KEY(es2, ps2, s2idx), HSTORE_KEYLEN(es2, s2idx),
HS_VALLEN(es2, s2idx), HS_VALISNULL(es2, s2idx)); HSTORE_VALLEN(es2, s2idx), HSTORE_VALISNULL(es2, s2idx));
++s2idx; ++s2idx;
if (difference == 0) if (difference == 0)
++s1idx; ++s1idx;
@ -553,8 +555,8 @@ hstore_concat(PG_FUNCTION_ARGS)
else else
{ {
HS_COPYITEM(ed, bufd, pd, HS_COPYITEM(ed, bufd, pd,
HS_KEY(es1, ps1, s1idx), HS_KEYLEN(es1, s1idx), HSTORE_KEY(es1, ps1, s1idx), HSTORE_KEYLEN(es1, s1idx),
HS_VALLEN(es1, s1idx), HS_VALISNULL(es1, s1idx)); HSTORE_VALLEN(es1, s1idx), HSTORE_VALISNULL(es1, s1idx));
++s1idx; ++s1idx;
} }
} }
@ -604,7 +606,7 @@ hstore_slice_to_array(PG_FUNCTION_ARGS)
else else
idx = hstoreFindKey(hs, NULL, VARDATA(key), VARSIZE(key) - VARHDRSZ); idx = hstoreFindKey(hs, NULL, VARDATA(key), VARSIZE(key) - VARHDRSZ);
if (idx < 0 || HS_VALISNULL(entries, idx)) if (idx < 0 || HSTORE_VALISNULL(entries, idx))
{ {
out_nulls[i] = true; out_nulls[i] = true;
out_datums[i] = (Datum) 0; out_datums[i] = (Datum) 0;
@ -612,8 +614,8 @@ hstore_slice_to_array(PG_FUNCTION_ARGS)
else else
{ {
out_datums[i] = PointerGetDatum( out_datums[i] = PointerGetDatum(
cstring_to_text_with_len(HS_VAL(entries, ptr, idx), cstring_to_text_with_len(HSTORE_VAL(entries, ptr, idx),
HS_VALLEN(entries, idx))); HSTORE_VALLEN(entries, idx)));
out_nulls[i] = false; out_nulls[i] = false;
} }
} }
@ -671,9 +673,9 @@ hstore_slice_to_hstore(PG_FUNCTION_ARGS)
{ {
out_pairs[out_count].key = key_pairs[i].key; out_pairs[out_count].key = key_pairs[i].key;
bufsiz += (out_pairs[out_count].keylen = key_pairs[i].keylen); bufsiz += (out_pairs[out_count].keylen = key_pairs[i].keylen);
out_pairs[out_count].val = HS_VAL(entries, ptr, idx); out_pairs[out_count].val = HSTORE_VAL(entries, ptr, idx);
bufsiz += (out_pairs[out_count].vallen = HS_VALLEN(entries, idx)); bufsiz += (out_pairs[out_count].vallen = HSTORE_VALLEN(entries, idx));
out_pairs[out_count].isnull = HS_VALISNULL(entries, idx); out_pairs[out_count].isnull = HSTORE_VALISNULL(entries, idx);
out_pairs[out_count].needfree = false; out_pairs[out_count].needfree = false;
++out_count; ++out_count;
} }
@ -712,10 +714,10 @@ hstore_akeys(PG_FUNCTION_ARGS)
for (i = 0; i < count; ++i) for (i = 0; i < count; ++i)
{ {
text *item = cstring_to_text_with_len(HS_KEY(entries, base, i), text *t = cstring_to_text_with_len(HSTORE_KEY(entries, base, i),
HS_KEYLEN(entries, i)); HSTORE_KEYLEN(entries, i));
d[i] = PointerGetDatum(item); d[i] = PointerGetDatum(t);
} }
a = construct_array(d, count, a = construct_array(d, count,
@ -750,15 +752,15 @@ hstore_avals(PG_FUNCTION_ARGS)
for (i = 0; i < count; ++i) for (i = 0; i < count; ++i)
{ {
if (HS_VALISNULL(entries, i)) if (HSTORE_VALISNULL(entries, i))
{ {
d[i] = (Datum) 0; d[i] = (Datum) 0;
nulls[i] = true; nulls[i] = true;
} }
else else
{ {
text *item = cstring_to_text_with_len(HS_VAL(entries, base, i), text *item = cstring_to_text_with_len(HSTORE_VAL(entries, base, i),
HS_VALLEN(entries, i)); HSTORE_VALLEN(entries, i));
d[i] = PointerGetDatum(item); d[i] = PointerGetDatum(item);
nulls[i] = false; nulls[i] = false;
@ -795,21 +797,21 @@ hstore_to_array_internal(HStore *hs, int ndims)
for (i = 0; i < count; ++i) for (i = 0; i < count; ++i)
{ {
text *key = cstring_to_text_with_len(HS_KEY(entries, base, i), text *key = cstring_to_text_with_len(HSTORE_KEY(entries, base, i),
HS_KEYLEN(entries, i)); HSTORE_KEYLEN(entries, i));
out_datums[i * 2] = PointerGetDatum(key); out_datums[i * 2] = PointerGetDatum(key);
out_nulls[i * 2] = false; out_nulls[i * 2] = false;
if (HS_VALISNULL(entries, i)) if (HSTORE_VALISNULL(entries, i))
{ {
out_datums[i * 2 + 1] = (Datum) 0; out_datums[i * 2 + 1] = (Datum) 0;
out_nulls[i * 2 + 1] = true; out_nulls[i * 2 + 1] = true;
} }
else else
{ {
text *item = cstring_to_text_with_len(HS_VAL(entries, base, i), text *item = cstring_to_text_with_len(HSTORE_VAL(entries, base, i),
HS_VALLEN(entries, i)); HSTORE_VALLEN(entries, i));
out_datums[i * 2 + 1] = PointerGetDatum(item); out_datums[i * 2 + 1] = PointerGetDatum(item);
out_nulls[i * 2 + 1] = false; out_nulls[i * 2 + 1] = false;
@ -903,8 +905,8 @@ hstore_skeys(PG_FUNCTION_ARGS)
HEntry *entries = ARRPTR(hs); HEntry *entries = ARRPTR(hs);
text *item; text *item;
item = cstring_to_text_with_len(HS_KEY(entries, STRPTR(hs), i), item = cstring_to_text_with_len(HSTORE_KEY(entries, STRPTR(hs), i),
HS_KEYLEN(entries, i)); HSTORE_KEYLEN(entries, i));
SRF_RETURN_NEXT(funcctx, PointerGetDatum(item)); SRF_RETURN_NEXT(funcctx, PointerGetDatum(item));
} }
@ -936,7 +938,7 @@ hstore_svals(PG_FUNCTION_ARGS)
{ {
HEntry *entries = ARRPTR(hs); HEntry *entries = ARRPTR(hs);
if (HS_VALISNULL(entries, i)) if (HSTORE_VALISNULL(entries, i))
{ {
ReturnSetInfo *rsi; ReturnSetInfo *rsi;
@ -950,8 +952,8 @@ hstore_svals(PG_FUNCTION_ARGS)
{ {
text *item; text *item;
item = cstring_to_text_with_len(HS_VAL(entries, STRPTR(hs), i), item = cstring_to_text_with_len(HSTORE_VAL(entries, STRPTR(hs), i),
HS_VALLEN(entries, i)); HSTORE_VALLEN(entries, i));
SRF_RETURN_NEXT(funcctx, PointerGetDatum(item)); SRF_RETURN_NEXT(funcctx, PointerGetDatum(item));
} }
@ -986,17 +988,19 @@ hstore_contains(PG_FUNCTION_ARGS)
for (i = 0; res && i < tcount; ++i) for (i = 0; res && i < tcount; ++i)
{ {
int idx = hstoreFindKey(val, &lastidx, int idx = hstoreFindKey(val, &lastidx,
HS_KEY(te, tstr, i), HS_KEYLEN(te, i)); HSTORE_KEY(te, tstr, i),
HSTORE_KEYLEN(te, i));
if (idx >= 0) if (idx >= 0)
{ {
bool nullval = HS_VALISNULL(te, i); bool nullval = HSTORE_VALISNULL(te, i);
int vallen = HS_VALLEN(te, i); int vallen = HSTORE_VALLEN(te, i);
if (nullval != HS_VALISNULL(ve, idx) if (nullval != HSTORE_VALISNULL(ve, idx) ||
|| (!nullval (!nullval && (vallen != HSTORE_VALLEN(ve, idx) ||
&& (vallen != HS_VALLEN(ve, idx) memcmp(HSTORE_VAL(te, tstr, i),
|| memcmp(HS_VAL(te, tstr, i), HS_VAL(ve, vstr, idx), vallen)))) HSTORE_VAL(ve, vstr, idx),
vallen) != 0)))
res = false; res = false;
} }
else else
@ -1047,19 +1051,19 @@ hstore_each(PG_FUNCTION_ARGS)
text *item; text *item;
HeapTuple tuple; HeapTuple tuple;
item = cstring_to_text_with_len(HS_KEY(entries, ptr, i), item = cstring_to_text_with_len(HSTORE_KEY(entries, ptr, i),
HS_KEYLEN(entries, i)); HSTORE_KEYLEN(entries, i));
dvalues[0] = PointerGetDatum(item); dvalues[0] = PointerGetDatum(item);
if (HS_VALISNULL(entries, i)) if (HSTORE_VALISNULL(entries, i))
{ {
dvalues[1] = (Datum) 0; dvalues[1] = (Datum) 0;
nulls[1] = true; nulls[1] = true;
} }
else else
{ {
item = cstring_to_text_with_len(HS_VAL(entries, ptr, i), item = cstring_to_text_with_len(HSTORE_VAL(entries, ptr, i),
HS_VALLEN(entries, i)); HSTORE_VALLEN(entries, i));
dvalues[1] = PointerGetDatum(item); dvalues[1] = PointerGetDatum(item);
} }

View file

@ -27,8 +27,11 @@ hstore_to_plperl(PG_FUNCTION_ARGS)
const char *key; const char *key;
SV *value; SV *value;
key = pnstrdup(HS_KEY(entries, base, i), HS_KEYLEN(entries, i)); key = pnstrdup(HSTORE_KEY(entries, base, i),
value = HS_VALISNULL(entries, i) ? newSV(0) : cstr2sv(pnstrdup(HS_VAL(entries, base, i), HS_VALLEN(entries, i))); HSTORE_KEYLEN(entries, i));
value = HSTORE_VALISNULL(entries, i) ? newSV(0) :
cstr2sv(pnstrdup(HSTORE_VAL(entries, base, i),
HSTORE_VALLEN(entries, i)));
(void) hv_store(hv, key, strlen(key), value, 0); (void) hv_store(hv, key, strlen(key), value, 0);
} }

View file

@ -25,14 +25,16 @@ hstore_to_plpython(PG_FUNCTION_ARGS)
{ {
PyObject *key; PyObject *key;
key = PyString_FromStringAndSize(HS_KEY(entries, base, i), HS_KEYLEN(entries, i)); key = PyString_FromStringAndSize(HSTORE_KEY(entries, base, i),
if (HS_VALISNULL(entries, i)) HSTORE_KEYLEN(entries, i));
if (HSTORE_VALISNULL(entries, i))
PyDict_SetItem(dict, key, Py_None); PyDict_SetItem(dict, key, Py_None);
else else
{ {
PyObject *value; PyObject *value;
value = PyString_FromStringAndSize(HS_VAL(entries, base, i), HS_VALLEN(entries, i)); value = PyString_FromStringAndSize(HSTORE_VAL(entries, base, i),
HSTORE_VALLEN(entries, i));
PyDict_SetItem(dict, key, value); PyDict_SetItem(dict, key, value);
Py_XDECREF(value); Py_XDECREF(value);
} }