Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Binary mode for pguint (upgradable) #16

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
*.o
*.so
/results/
/*--*.sql
/*.sql
/uint--*.sql.in
/operators.c
/operators.sql
/operators--*.sql.in
/test/sql/operators.sql
22 changes: 15 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,27 +13,35 @@ pg_config_h := $(shell $(PG_CONFIG) --includedir-server)/pg_config.h
use_float8_byval := $(shell grep -q 'USE_FLOAT8_BYVAL 1' $(pg_config_h) && echo yes)
comma = ,

extension_version = 0

EXTENSION = uint
MODULE_big = uint
OBJS = aggregates.o hash.o hex.o inout.o magic.o misc.o operators.o
DATA_built = uint--$(extension_version).sql
DATA_built = uint--1.sql uint--0--1.sql \
uint--0.sql

REGRESS = init hash hex operators misc drop
REGRESS_OPTS = --inputdir=test

EXTRA_CLEAN += operators.c operators.sql test/sql/operators.sql
EXTRA_CLEAN += operators.c operators--0.sql.in test/sql/operators.sql

PGXS := $(shell $(PG_CONFIG) --pgxs)
include $(PGXS)

uint--$(extension_version).sql: uint.sql hash.sql hex.sql operators.sql
cat $^ | sed 's/@UINT8_PASSEDBYVALUE@/$(if $(use_float8_byval),PASSEDBYVALUE$(comma))/' >$@
uint--1.sql.in: types--1.sql.in hash--0.sql.in hex--0.sql.in operators--0.sql.in
cat $^ >$@

uint--0--1.sql.in: types--0--1.sql.in
cat $^ >$@

uint--0.sql.in: types--0.sql.in hash--0.sql.in hex--0.sql.in operators--0.sql.in
cat $^ >$@

uint--%.sql: uint--%.sql.in
sed 's/@UINT8_PASSEDBYVALUE@/$(if $(use_float8_byval),PASSEDBYVALUE$(comma))/' $< >$@

PYTHON ?= python

operators.c operators.sql test/sql/operators.sql: generate.py
operators.c operators--0.sql.in test/sql/operators.sql: generate.py
$(PYTHON) $< $(pg_version)

python-check: generate.py
Expand Down
2 changes: 1 addition & 1 deletion generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,7 @@ def write_arithmetic_op(f_c, f_sql, f_test_sql, op, leftarg, rightarg):

def main(pgversion):
f_c = open('operators.c', 'w')
f_sql = open('operators.sql', 'w')
f_sql = open('operators--0.sql.in', 'w')
f_test_sql = open('test/sql/operators.sql', 'w')

f_c.write("""\
Expand Down
File renamed without changes.
File renamed without changes.
101 changes: 101 additions & 0 deletions inout.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include <postgres.h>
#include <libpq/pqformat.h>
#include <fmgr.h>
#include <utils/builtins.h>

Expand Down Expand Up @@ -203,3 +204,103 @@ uint8out(PG_FUNCTION_ARGS)
sprintf(result, "%"PRIu64, (uint64_t) arg1);
PG_RETURN_CSTRING(result);
}

PG_FUNCTION_INFO_V1(int1recv);
Datum
int1recv(PG_FUNCTION_ARGS)
{
StringInfo buf = (StringInfo) PG_GETARG_POINTER(0);
PG_RETURN_INT8((int8) pq_getmsgint(buf, sizeof(int8)));
}

PG_FUNCTION_INFO_V1(int1send);
Datum
int1send(PG_FUNCTION_ARGS)
{
int8 arg1 = PG_GETARG_INT8(0);
StringInfoData buf;

pq_begintypsend(&buf);
pq_sendint(&buf, arg1, sizeof(int8));
PG_RETURN_BYTEA_P(pq_endtypsend(&buf));
}

PG_FUNCTION_INFO_V1(uint1recv);
Datum
uint1recv(PG_FUNCTION_ARGS)
{
StringInfo buf = (StringInfo) PG_GETARG_POINTER(0);
PG_RETURN_UINT8((uint8) pq_getmsgint(buf, sizeof(uint8)));
}

PG_FUNCTION_INFO_V1(uint1send);
Datum
uint1send(PG_FUNCTION_ARGS)
{
uint8 arg1 = PG_GETARG_UINT8(0);
StringInfoData buf;

pq_begintypsend(&buf);
pq_sendint(&buf, arg1, sizeof(uint8));
PG_RETURN_BYTEA_P(pq_endtypsend(&buf));
}

PG_FUNCTION_INFO_V1(uint2recv);
Datum
uint2recv(PG_FUNCTION_ARGS)
{
StringInfo buf = (StringInfo) PG_GETARG_POINTER(0);
PG_RETURN_UINT16((uint16) pq_getmsgint(buf, sizeof(uint16)));
}

PG_FUNCTION_INFO_V1(uint2send);
Datum
uint2send(PG_FUNCTION_ARGS)
{
uint16 arg1 = PG_GETARG_UINT16(0);
StringInfoData buf;

pq_begintypsend(&buf);
pq_sendint(&buf, arg1, sizeof(uint16));
PG_RETURN_BYTEA_P(pq_endtypsend(&buf));
}

PG_FUNCTION_INFO_V1(uint4recv);
Datum
uint4recv(PG_FUNCTION_ARGS)
{
StringInfo buf = (StringInfo) PG_GETARG_POINTER(0);
PG_RETURN_UINT32((uint32) pq_getmsgint(buf, sizeof(uint32)));
}

PG_FUNCTION_INFO_V1(uint4send);
Datum
uint4send(PG_FUNCTION_ARGS)
{
uint32 arg1 = PG_GETARG_UINT32(0);
StringInfoData buf;

pq_begintypsend(&buf);
pq_sendint(&buf, arg1, sizeof(uint32));
PG_RETURN_BYTEA_P(pq_endtypsend(&buf));
}

PG_FUNCTION_INFO_V1(uint8recv);
Datum
uint8recv(PG_FUNCTION_ARGS)
{
StringInfo buf = (StringInfo) PG_GETARG_POINTER(0);
PG_RETURN_UINT64((uint64) pq_getmsgint64(buf));
}

PG_FUNCTION_INFO_V1(uint8send);
Datum
uint8send(PG_FUNCTION_ARGS)
{
uint64 arg1 = PG_GETARG_UINT64(0);
StringInfoData buf;

pq_begintypsend(&buf);
pq_sendint64(&buf, arg1);
PG_RETURN_BYTEA_P(pq_endtypsend(&buf));
}
118 changes: 118 additions & 0 deletions types--0--1.sql.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
-- add recv/send functions

CREATE FUNCTION int1recv(internal) RETURNS int1
IMMUTABLE
STRICT
LANGUAGE C
AS '$libdir/uint', 'int1recv';

CREATE FUNCTION int1send(int1) RETURNS bytea
IMMUTABLE
STRICT
LANGUAGE C
AS '$libdir/uint', 'int1send';

-- RECEIVE = int1recv,
-- SEND = int1send,

UPDATE pg_type SET typreceive = 'int1recv', typsend = 'int1send'
WHERE typname = 'int1';

INSERT INTO pg_depend (classid, objid, objsubid, refclassid, refobjid, refobjsubid, deptype)
VALUES
('pg_type'::regclass, 'int1'::regtype, 0, 'pg_proc'::regclass, 'int1recv'::regproc, 0, 'n'),
('pg_type'::regclass, 'int1'::regtype, 0, 'pg_proc'::regclass, 'int1send'::regproc, 0, 'n');


CREATE FUNCTION uint1recv(internal) RETURNS uint1
IMMUTABLE
STRICT
LANGUAGE C
AS '$libdir/uint', 'uint1recv';

CREATE FUNCTION uint1send(uint1) RETURNS bytea
IMMUTABLE
STRICT
LANGUAGE C
AS '$libdir/uint', 'uint1send';

-- RECEIVE = uint1recv,
-- SEND = uint1send,

UPDATE pg_type SET typreceive = 'uint1recv', typsend = 'uint1send'
WHERE typname = 'uint1';

INSERT INTO pg_depend (classid, objid, objsubid, refclassid, refobjid, refobjsubid, deptype)
VALUES
('pg_type'::regclass, 'uint1'::regtype, 0, 'pg_proc'::regclass, 'uint1recv'::regproc, 0, 'n'),
('pg_type'::regclass, 'uint1'::regtype, 0, 'pg_proc'::regclass, 'uint1send'::regproc, 0, 'n');

CREATE FUNCTION uint2recv(internal) RETURNS uint2
IMMUTABLE
STRICT
LANGUAGE C
AS '$libdir/uint', 'uint2recv';

CREATE FUNCTION uint2send(uint2) RETURNS bytea
IMMUTABLE
STRICT
LANGUAGE C
AS '$libdir/uint', 'uint2send';

-- RECEIVE = uint2recv,
-- SEND = uint2send,

UPDATE pg_type SET typreceive = 'uint2recv', typsend = 'uint2send'
WHERE typname = 'uint2';

INSERT INTO pg_depend (classid, objid, objsubid, refclassid, refobjid, refobjsubid, deptype)
VALUES
('pg_type'::regclass, 'uint2'::regtype, 0, 'pg_proc'::regclass, 'uint2recv'::regproc, 0, 'n'),
('pg_type'::regclass, 'uint2'::regtype, 0, 'pg_proc'::regclass, 'uint2send'::regproc, 0, 'n');

CREATE FUNCTION uint4recv(internal) RETURNS uint4
IMMUTABLE
STRICT
LANGUAGE C
AS '$libdir/uint', 'uint4recv';

CREATE FUNCTION uint4send(uint4) RETURNS bytea
IMMUTABLE
STRICT
LANGUAGE C
AS '$libdir/uint', 'uint4send';

-- RECEIVE = uint4recv,
-- SEND = uint4send,

UPDATE pg_type SET typreceive = 'uint4recv', typsend = 'uint4send'
WHERE typname = 'uint4';

INSERT INTO pg_depend (classid, objid, objsubid, refclassid, refobjid, refobjsubid, deptype)
VALUES
('pg_type'::regclass, 'uint4'::regtype, 0, 'pg_proc'::regclass, 'uint4recv'::regproc, 0, 'n'),
('pg_type'::regclass, 'uint4'::regtype, 0, 'pg_proc'::regclass, 'uint4send'::regproc, 0, 'n');

CREATE FUNCTION uint8recv(internal) RETURNS uint8
IMMUTABLE
STRICT
LANGUAGE C
AS '$libdir/uint', 'uint8recv';

CREATE FUNCTION uint8send(uint8) RETURNS bytea
IMMUTABLE
STRICT
LANGUAGE C
AS '$libdir/uint', 'uint8send';

-- RECEIVE = uint8recv,
-- SEND = uint8send,

UPDATE pg_type SET typreceive = 'uint8recv', typsend = 'uint8send'
WHERE typname = 'uint8';

INSERT INTO pg_depend (classid, objid, objsubid, refclassid, refobjid, refobjsubid, deptype)
VALUES
('pg_type'::regclass, 'uint8'::regtype, 0, 'pg_proc'::regclass, 'uint8recv'::regproc, 0, 'n'),
('pg_type'::regclass, 'uint8'::regtype, 0, 'pg_proc'::regclass, 'uint8send'::regproc, 0, 'n');

File renamed without changes.
Loading