Commit 8409b604 authored by Heikki Linnakangas's avatar Heikki Linnakangas

Revert the behavior of inet/cidr functions to not unpack the arguments.

I forgot to change the functions to use the PG_GETARG_INET_PP() macro,
when I changed DatumGetInetP() to unpack the datum, like Datum*P macros
usually do. Also, I screwed up the definition of the PG_GETARG_INET_PP()
macro, and didn't notice because it wasn't used.

This fixes the memory leak when sorting inet values, as reported
by Jochen Erwied and debugged by Andres Freund. Backpatch to 8.3, like
the previous patch that broke it.
parent 0f443351
...@@ -172,7 +172,7 @@ network_out(inet *src, bool is_cidr) ...@@ -172,7 +172,7 @@ network_out(inet *src, bool is_cidr)
Datum Datum
inet_out(PG_FUNCTION_ARGS) inet_out(PG_FUNCTION_ARGS)
{ {
inet *src = PG_GETARG_INET_P(0); inet *src = PG_GETARG_INET_PP(0);
PG_RETURN_CSTRING(network_out(src, false)); PG_RETURN_CSTRING(network_out(src, false));
} }
...@@ -180,7 +180,7 @@ inet_out(PG_FUNCTION_ARGS) ...@@ -180,7 +180,7 @@ inet_out(PG_FUNCTION_ARGS)
Datum Datum
cidr_out(PG_FUNCTION_ARGS) cidr_out(PG_FUNCTION_ARGS)
{ {
inet *src = PG_GETARG_INET_P(0); inet *src = PG_GETARG_INET_PP(0);
PG_RETURN_CSTRING(network_out(src, true)); PG_RETURN_CSTRING(network_out(src, true));
} }
...@@ -299,7 +299,7 @@ network_send(inet *addr, bool is_cidr) ...@@ -299,7 +299,7 @@ network_send(inet *addr, bool is_cidr)
Datum Datum
inet_send(PG_FUNCTION_ARGS) inet_send(PG_FUNCTION_ARGS)
{ {
inet *addr = PG_GETARG_INET_P(0); inet *addr = PG_GETARG_INET_PP(0);
PG_RETURN_BYTEA_P(network_send(addr, false)); PG_RETURN_BYTEA_P(network_send(addr, false));
} }
...@@ -307,7 +307,7 @@ inet_send(PG_FUNCTION_ARGS) ...@@ -307,7 +307,7 @@ inet_send(PG_FUNCTION_ARGS)
Datum Datum
cidr_send(PG_FUNCTION_ARGS) cidr_send(PG_FUNCTION_ARGS)
{ {
inet *addr = PG_GETARG_INET_P(0); inet *addr = PG_GETARG_INET_PP(0);
PG_RETURN_BYTEA_P(network_send(addr, true)); PG_RETURN_BYTEA_P(network_send(addr, true));
} }
...@@ -316,7 +316,7 @@ cidr_send(PG_FUNCTION_ARGS) ...@@ -316,7 +316,7 @@ cidr_send(PG_FUNCTION_ARGS)
Datum Datum
inet_to_cidr(PG_FUNCTION_ARGS) inet_to_cidr(PG_FUNCTION_ARGS)
{ {
inet *src = PG_GETARG_INET_P(0); inet *src = PG_GETARG_INET_PP(0);
inet *dst; inet *dst;
int bits; int bits;
int byte; int byte;
...@@ -357,7 +357,7 @@ inet_to_cidr(PG_FUNCTION_ARGS) ...@@ -357,7 +357,7 @@ inet_to_cidr(PG_FUNCTION_ARGS)
Datum Datum
inet_set_masklen(PG_FUNCTION_ARGS) inet_set_masklen(PG_FUNCTION_ARGS)
{ {
inet *src = PG_GETARG_INET_P(0); inet *src = PG_GETARG_INET_PP(0);
int bits = PG_GETARG_INT32(1); int bits = PG_GETARG_INT32(1);
inet *dst; inet *dst;
...@@ -381,7 +381,7 @@ inet_set_masklen(PG_FUNCTION_ARGS) ...@@ -381,7 +381,7 @@ inet_set_masklen(PG_FUNCTION_ARGS)
Datum Datum
cidr_set_masklen(PG_FUNCTION_ARGS) cidr_set_masklen(PG_FUNCTION_ARGS)
{ {
inet *src = PG_GETARG_INET_P(0); inet *src = PG_GETARG_INET_PP(0);
int bits = PG_GETARG_INT32(1); int bits = PG_GETARG_INT32(1);
inet *dst; inet *dst;
int byte; int byte;
...@@ -457,8 +457,8 @@ network_cmp_internal(inet *a1, inet *a2) ...@@ -457,8 +457,8 @@ network_cmp_internal(inet *a1, inet *a2)
Datum Datum
network_cmp(PG_FUNCTION_ARGS) network_cmp(PG_FUNCTION_ARGS)
{ {
inet *a1 = PG_GETARG_INET_P(0); inet *a1 = PG_GETARG_INET_PP(0);
inet *a2 = PG_GETARG_INET_P(1); inet *a2 = PG_GETARG_INET_PP(1);
PG_RETURN_INT32(network_cmp_internal(a1, a2)); PG_RETURN_INT32(network_cmp_internal(a1, a2));
} }
...@@ -469,8 +469,8 @@ network_cmp(PG_FUNCTION_ARGS) ...@@ -469,8 +469,8 @@ network_cmp(PG_FUNCTION_ARGS)
Datum Datum
network_lt(PG_FUNCTION_ARGS) network_lt(PG_FUNCTION_ARGS)
{ {
inet *a1 = PG_GETARG_INET_P(0); inet *a1 = PG_GETARG_INET_PP(0);
inet *a2 = PG_GETARG_INET_P(1); inet *a2 = PG_GETARG_INET_PP(1);
PG_RETURN_BOOL(network_cmp_internal(a1, a2) < 0); PG_RETURN_BOOL(network_cmp_internal(a1, a2) < 0);
} }
...@@ -478,8 +478,8 @@ network_lt(PG_FUNCTION_ARGS) ...@@ -478,8 +478,8 @@ network_lt(PG_FUNCTION_ARGS)
Datum Datum
network_le(PG_FUNCTION_ARGS) network_le(PG_FUNCTION_ARGS)
{ {
inet *a1 = PG_GETARG_INET_P(0); inet *a1 = PG_GETARG_INET_PP(0);
inet *a2 = PG_GETARG_INET_P(1); inet *a2 = PG_GETARG_INET_PP(1);
PG_RETURN_BOOL(network_cmp_internal(a1, a2) <= 0); PG_RETURN_BOOL(network_cmp_internal(a1, a2) <= 0);
} }
...@@ -487,8 +487,8 @@ network_le(PG_FUNCTION_ARGS) ...@@ -487,8 +487,8 @@ network_le(PG_FUNCTION_ARGS)
Datum Datum
network_eq(PG_FUNCTION_ARGS) network_eq(PG_FUNCTION_ARGS)
{ {
inet *a1 = PG_GETARG_INET_P(0); inet *a1 = PG_GETARG_INET_PP(0);
inet *a2 = PG_GETARG_INET_P(1); inet *a2 = PG_GETARG_INET_PP(1);
PG_RETURN_BOOL(network_cmp_internal(a1, a2) == 0); PG_RETURN_BOOL(network_cmp_internal(a1, a2) == 0);
} }
...@@ -496,8 +496,8 @@ network_eq(PG_FUNCTION_ARGS) ...@@ -496,8 +496,8 @@ network_eq(PG_FUNCTION_ARGS)
Datum Datum
network_ge(PG_FUNCTION_ARGS) network_ge(PG_FUNCTION_ARGS)
{ {
inet *a1 = PG_GETARG_INET_P(0); inet *a1 = PG_GETARG_INET_PP(0);
inet *a2 = PG_GETARG_INET_P(1); inet *a2 = PG_GETARG_INET_PP(1);
PG_RETURN_BOOL(network_cmp_internal(a1, a2) >= 0); PG_RETURN_BOOL(network_cmp_internal(a1, a2) >= 0);
} }
...@@ -505,8 +505,8 @@ network_ge(PG_FUNCTION_ARGS) ...@@ -505,8 +505,8 @@ network_ge(PG_FUNCTION_ARGS)
Datum Datum
network_gt(PG_FUNCTION_ARGS) network_gt(PG_FUNCTION_ARGS)
{ {
inet *a1 = PG_GETARG_INET_P(0); inet *a1 = PG_GETARG_INET_PP(0);
inet *a2 = PG_GETARG_INET_P(1); inet *a2 = PG_GETARG_INET_PP(1);
PG_RETURN_BOOL(network_cmp_internal(a1, a2) > 0); PG_RETURN_BOOL(network_cmp_internal(a1, a2) > 0);
} }
...@@ -514,8 +514,8 @@ network_gt(PG_FUNCTION_ARGS) ...@@ -514,8 +514,8 @@ network_gt(PG_FUNCTION_ARGS)
Datum Datum
network_ne(PG_FUNCTION_ARGS) network_ne(PG_FUNCTION_ARGS)
{ {
inet *a1 = PG_GETARG_INET_P(0); inet *a1 = PG_GETARG_INET_PP(0);
inet *a2 = PG_GETARG_INET_P(1); inet *a2 = PG_GETARG_INET_PP(1);
PG_RETURN_BOOL(network_cmp_internal(a1, a2) != 0); PG_RETURN_BOOL(network_cmp_internal(a1, a2) != 0);
} }
...@@ -526,7 +526,7 @@ network_ne(PG_FUNCTION_ARGS) ...@@ -526,7 +526,7 @@ network_ne(PG_FUNCTION_ARGS)
Datum Datum
hashinet(PG_FUNCTION_ARGS) hashinet(PG_FUNCTION_ARGS)
{ {
inet *addr = PG_GETARG_INET_P(0); inet *addr = PG_GETARG_INET_PP(0);
int addrsize = ip_addrsize(addr); int addrsize = ip_addrsize(addr);
/* XXX this assumes there are no pad bytes in the data structure */ /* XXX this assumes there are no pad bytes in the data structure */
...@@ -539,8 +539,8 @@ hashinet(PG_FUNCTION_ARGS) ...@@ -539,8 +539,8 @@ hashinet(PG_FUNCTION_ARGS)
Datum Datum
network_sub(PG_FUNCTION_ARGS) network_sub(PG_FUNCTION_ARGS)
{ {
inet *a1 = PG_GETARG_INET_P(0); inet *a1 = PG_GETARG_INET_PP(0);
inet *a2 = PG_GETARG_INET_P(1); inet *a2 = PG_GETARG_INET_PP(1);
if (ip_family(a1) == ip_family(a2)) if (ip_family(a1) == ip_family(a2))
{ {
...@@ -554,8 +554,8 @@ network_sub(PG_FUNCTION_ARGS) ...@@ -554,8 +554,8 @@ network_sub(PG_FUNCTION_ARGS)
Datum Datum
network_subeq(PG_FUNCTION_ARGS) network_subeq(PG_FUNCTION_ARGS)
{ {
inet *a1 = PG_GETARG_INET_P(0); inet *a1 = PG_GETARG_INET_PP(0);
inet *a2 = PG_GETARG_INET_P(1); inet *a2 = PG_GETARG_INET_PP(1);
if (ip_family(a1) == ip_family(a2)) if (ip_family(a1) == ip_family(a2))
{ {
...@@ -569,8 +569,8 @@ network_subeq(PG_FUNCTION_ARGS) ...@@ -569,8 +569,8 @@ network_subeq(PG_FUNCTION_ARGS)
Datum Datum
network_sup(PG_FUNCTION_ARGS) network_sup(PG_FUNCTION_ARGS)
{ {
inet *a1 = PG_GETARG_INET_P(0); inet *a1 = PG_GETARG_INET_PP(0);
inet *a2 = PG_GETARG_INET_P(1); inet *a2 = PG_GETARG_INET_PP(1);
if (ip_family(a1) == ip_family(a2)) if (ip_family(a1) == ip_family(a2))
{ {
...@@ -584,8 +584,8 @@ network_sup(PG_FUNCTION_ARGS) ...@@ -584,8 +584,8 @@ network_sup(PG_FUNCTION_ARGS)
Datum Datum
network_supeq(PG_FUNCTION_ARGS) network_supeq(PG_FUNCTION_ARGS)
{ {
inet *a1 = PG_GETARG_INET_P(0); inet *a1 = PG_GETARG_INET_PP(0);
inet *a2 = PG_GETARG_INET_P(1); inet *a2 = PG_GETARG_INET_PP(1);
if (ip_family(a1) == ip_family(a2)) if (ip_family(a1) == ip_family(a2))
{ {
...@@ -602,7 +602,7 @@ network_supeq(PG_FUNCTION_ARGS) ...@@ -602,7 +602,7 @@ network_supeq(PG_FUNCTION_ARGS)
Datum Datum
network_host(PG_FUNCTION_ARGS) network_host(PG_FUNCTION_ARGS)
{ {
inet *ip = PG_GETARG_INET_P(0); inet *ip = PG_GETARG_INET_PP(0);
char *ptr; char *ptr;
char tmp[sizeof("xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:255.255.255.255/128")]; char tmp[sizeof("xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:255.255.255.255/128")];
...@@ -628,7 +628,7 @@ network_host(PG_FUNCTION_ARGS) ...@@ -628,7 +628,7 @@ network_host(PG_FUNCTION_ARGS)
Datum Datum
network_show(PG_FUNCTION_ARGS) network_show(PG_FUNCTION_ARGS)
{ {
inet *ip = PG_GETARG_INET_P(0); inet *ip = PG_GETARG_INET_PP(0);
int len; int len;
char tmp[sizeof("xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:255.255.255.255/128")]; char tmp[sizeof("xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:255.255.255.255/128")];
...@@ -651,7 +651,7 @@ network_show(PG_FUNCTION_ARGS) ...@@ -651,7 +651,7 @@ network_show(PG_FUNCTION_ARGS)
Datum Datum
inet_abbrev(PG_FUNCTION_ARGS) inet_abbrev(PG_FUNCTION_ARGS)
{ {
inet *ip = PG_GETARG_INET_P(0); inet *ip = PG_GETARG_INET_PP(0);
char *dst; char *dst;
char tmp[sizeof("xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:255.255.255.255/128")]; char tmp[sizeof("xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:255.255.255.255/128")];
...@@ -669,7 +669,7 @@ inet_abbrev(PG_FUNCTION_ARGS) ...@@ -669,7 +669,7 @@ inet_abbrev(PG_FUNCTION_ARGS)
Datum Datum
cidr_abbrev(PG_FUNCTION_ARGS) cidr_abbrev(PG_FUNCTION_ARGS)
{ {
inet *ip = PG_GETARG_INET_P(0); inet *ip = PG_GETARG_INET_PP(0);
char *dst; char *dst;
char tmp[sizeof("xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:255.255.255.255/128")]; char tmp[sizeof("xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:255.255.255.255/128")];
...@@ -687,7 +687,7 @@ cidr_abbrev(PG_FUNCTION_ARGS) ...@@ -687,7 +687,7 @@ cidr_abbrev(PG_FUNCTION_ARGS)
Datum Datum
network_masklen(PG_FUNCTION_ARGS) network_masklen(PG_FUNCTION_ARGS)
{ {
inet *ip = PG_GETARG_INET_P(0); inet *ip = PG_GETARG_INET_PP(0);
PG_RETURN_INT32(ip_bits(ip)); PG_RETURN_INT32(ip_bits(ip));
} }
...@@ -695,7 +695,7 @@ network_masklen(PG_FUNCTION_ARGS) ...@@ -695,7 +695,7 @@ network_masklen(PG_FUNCTION_ARGS)
Datum Datum
network_family(PG_FUNCTION_ARGS) network_family(PG_FUNCTION_ARGS)
{ {
inet *ip = PG_GETARG_INET_P(0); inet *ip = PG_GETARG_INET_PP(0);
switch (ip_family(ip)) switch (ip_family(ip))
{ {
...@@ -714,7 +714,7 @@ network_family(PG_FUNCTION_ARGS) ...@@ -714,7 +714,7 @@ network_family(PG_FUNCTION_ARGS)
Datum Datum
network_broadcast(PG_FUNCTION_ARGS) network_broadcast(PG_FUNCTION_ARGS)
{ {
inet *ip = PG_GETARG_INET_P(0); inet *ip = PG_GETARG_INET_PP(0);
inet *dst; inet *dst;
int byte; int byte;
int bits; int bits;
...@@ -763,7 +763,7 @@ network_broadcast(PG_FUNCTION_ARGS) ...@@ -763,7 +763,7 @@ network_broadcast(PG_FUNCTION_ARGS)
Datum Datum
network_network(PG_FUNCTION_ARGS) network_network(PG_FUNCTION_ARGS)
{ {
inet *ip = PG_GETARG_INET_P(0); inet *ip = PG_GETARG_INET_PP(0);
inet *dst; inet *dst;
int byte; int byte;
int bits; int bits;
...@@ -807,7 +807,7 @@ network_network(PG_FUNCTION_ARGS) ...@@ -807,7 +807,7 @@ network_network(PG_FUNCTION_ARGS)
Datum Datum
network_netmask(PG_FUNCTION_ARGS) network_netmask(PG_FUNCTION_ARGS)
{ {
inet *ip = PG_GETARG_INET_P(0); inet *ip = PG_GETARG_INET_PP(0);
inet *dst; inet *dst;
int byte; int byte;
int bits; int bits;
...@@ -849,7 +849,7 @@ network_netmask(PG_FUNCTION_ARGS) ...@@ -849,7 +849,7 @@ network_netmask(PG_FUNCTION_ARGS)
Datum Datum
network_hostmask(PG_FUNCTION_ARGS) network_hostmask(PG_FUNCTION_ARGS)
{ {
inet *ip = PG_GETARG_INET_P(0); inet *ip = PG_GETARG_INET_PP(0);
inet *dst; inet *dst;
int byte; int byte;
int bits; int bits;
...@@ -1218,7 +1218,7 @@ inet_server_port(PG_FUNCTION_ARGS) ...@@ -1218,7 +1218,7 @@ inet_server_port(PG_FUNCTION_ARGS)
Datum Datum
inetnot(PG_FUNCTION_ARGS) inetnot(PG_FUNCTION_ARGS)
{ {
inet *ip = PG_GETARG_INET_P(0); inet *ip = PG_GETARG_INET_PP(0);
inet *dst; inet *dst;
dst = (inet *) palloc0(sizeof(inet)); dst = (inet *) palloc0(sizeof(inet));
...@@ -1243,8 +1243,8 @@ inetnot(PG_FUNCTION_ARGS) ...@@ -1243,8 +1243,8 @@ inetnot(PG_FUNCTION_ARGS)
Datum Datum
inetand(PG_FUNCTION_ARGS) inetand(PG_FUNCTION_ARGS)
{ {
inet *ip = PG_GETARG_INET_P(0); inet *ip = PG_GETARG_INET_PP(0);
inet *ip2 = PG_GETARG_INET_P(1); inet *ip2 = PG_GETARG_INET_PP(1);
inet *dst; inet *dst;
dst = (inet *) palloc0(sizeof(inet)); dst = (inet *) palloc0(sizeof(inet));
...@@ -1275,8 +1275,8 @@ inetand(PG_FUNCTION_ARGS) ...@@ -1275,8 +1275,8 @@ inetand(PG_FUNCTION_ARGS)
Datum Datum
inetor(PG_FUNCTION_ARGS) inetor(PG_FUNCTION_ARGS)
{ {
inet *ip = PG_GETARG_INET_P(0); inet *ip = PG_GETARG_INET_PP(0);
inet *ip2 = PG_GETARG_INET_P(1); inet *ip2 = PG_GETARG_INET_PP(1);
inet *dst; inet *dst;
dst = (inet *) palloc0(sizeof(inet)); dst = (inet *) palloc0(sizeof(inet));
...@@ -1359,7 +1359,7 @@ internal_inetpl(inet *ip, int64 addend) ...@@ -1359,7 +1359,7 @@ internal_inetpl(inet *ip, int64 addend)
Datum Datum
inetpl(PG_FUNCTION_ARGS) inetpl(PG_FUNCTION_ARGS)
{ {
inet *ip = PG_GETARG_INET_P(0); inet *ip = PG_GETARG_INET_PP(0);
int64 addend = PG_GETARG_INT64(1); int64 addend = PG_GETARG_INT64(1);
PG_RETURN_INET_P(internal_inetpl(ip, addend)); PG_RETURN_INET_P(internal_inetpl(ip, addend));
...@@ -1369,7 +1369,7 @@ inetpl(PG_FUNCTION_ARGS) ...@@ -1369,7 +1369,7 @@ inetpl(PG_FUNCTION_ARGS)
Datum Datum
inetmi_int8(PG_FUNCTION_ARGS) inetmi_int8(PG_FUNCTION_ARGS)
{ {
inet *ip = PG_GETARG_INET_P(0); inet *ip = PG_GETARG_INET_PP(0);
int64 addend = PG_GETARG_INT64(1); int64 addend = PG_GETARG_INT64(1);
PG_RETURN_INET_P(internal_inetpl(ip, -addend)); PG_RETURN_INET_P(internal_inetpl(ip, -addend));
...@@ -1379,8 +1379,8 @@ inetmi_int8(PG_FUNCTION_ARGS) ...@@ -1379,8 +1379,8 @@ inetmi_int8(PG_FUNCTION_ARGS)
Datum Datum
inetmi(PG_FUNCTION_ARGS) inetmi(PG_FUNCTION_ARGS)
{ {
inet *ip = PG_GETARG_INET_P(0); inet *ip = PG_GETARG_INET_PP(0);
inet *ip2 = PG_GETARG_INET_P(1); inet *ip2 = PG_GETARG_INET_PP(1);
int64 res = 0; int64 res = 0;
if (ip_family(ip) != ip_family(ip2)) if (ip_family(ip) != ip_family(ip2))
......
...@@ -74,7 +74,7 @@ typedef struct macaddr ...@@ -74,7 +74,7 @@ typedef struct macaddr
#define DatumGetInetPP(X) ((inet *) PG_DETOAST_DATUM_PACKED(X)) #define DatumGetInetPP(X) ((inet *) PG_DETOAST_DATUM_PACKED(X))
#define InetPGetDatum(X) PointerGetDatum(X) #define InetPGetDatum(X) PointerGetDatum(X)
#define PG_GETARG_INET_P(n) DatumGetInetP(PG_GETARG_DATUM(n)) #define PG_GETARG_INET_P(n) DatumGetInetP(PG_GETARG_DATUM(n))
#define PG_GETARG_INET_PP(n) DatumGetInetP(PG_GETARG_DATUM_PACKED(n)) #define PG_GETARG_INET_PP(n) DatumGetInetPP(PG_GETARG_DATUM(n))
#define PG_RETURN_INET_P(x) return InetPGetDatum(x) #define PG_RETURN_INET_P(x) return InetPGetDatum(x)
/* macaddr is a fixed-length pass-by-reference datatype */ /* macaddr is a fixed-length pass-by-reference datatype */
#define DatumGetMacaddrP(X) ((macaddr *) DatumGetPointer(X)) #define DatumGetMacaddrP(X) ((macaddr *) DatumGetPointer(X))
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment