From 57becbb57d3f9f7f457e54a08e2b508012b91994 Mon Sep 17 00:00:00 2001 From: Johann 'Myrkraverk' Oskarsson Date: Tue, 20 Aug 2019 23:30:38 +0800 Subject: [PATCH 1/2] Windows port. --- src/crc32.c | 5 +++++ src/md5.c | 32 ++++++++++++++++---------------- src/sha.c | 28 ++++++++++++++-------------- windows.mak | 35 +++++++++++++++++++++++++++++++++++ 4 files changed, 70 insertions(+), 30 deletions(-) create mode 100644 windows.mak diff --git a/src/crc32.c b/src/crc32.c index da8cc19..356fc68 100644 --- a/src/crc32.c +++ b/src/crc32.c @@ -1,11 +1,16 @@ #include "postgres.h" #include "fmgr.h" +#include + typedef uint32 crc32; #define PG_GETARG_CRC32(N) PG_GETARG_UINT32(N) #define PG_RETURN_CRC32(X) PG_RETURN_UINT32(X) +PGDLLEXPORT Datum crc32_in(PG_FUNCTION_ARGS); +PGDLLEXPORT Datum crc32_out(PG_FUNCTION_ARGS); + PG_FUNCTION_INFO_V1(crc32_in); Datum crc32_in(PG_FUNCTION_ARGS) diff --git a/src/md5.c b/src/md5.c index e106cf1..39f3da4 100644 --- a/src/md5.c +++ b/src/md5.c @@ -25,22 +25,22 @@ typedef struct Md5 { #define PG_GETARG_MD5(n) DatumGetMd5(PG_GETARG_DATUM(n)) #define PG_RETURN_MD5(x) return Md5GetDatum(x) -Datum md5_in(PG_FUNCTION_ARGS); -Datum md5_out(PG_FUNCTION_ARGS); -Datum md5_recv(PG_FUNCTION_ARGS); -Datum md5_send(PG_FUNCTION_ARGS); -Datum md5_to_text(PG_FUNCTION_ARGS); -Datum text_to_md5(PG_FUNCTION_ARGS); -Datum bytea_to_md5(PG_FUNCTION_ARGS); -Datum md5_to_bytea(PG_FUNCTION_ARGS); -Datum md5_cmp(PG_FUNCTION_ARGS); -Datum md5_eq(PG_FUNCTION_ARGS); -Datum md5_ne(PG_FUNCTION_ARGS); -Datum md5_ge(PG_FUNCTION_ARGS); -Datum md5_gt(PG_FUNCTION_ARGS); -Datum md5_le(PG_FUNCTION_ARGS); -Datum md5_lt(PG_FUNCTION_ARGS); -Datum md5_hash(PG_FUNCTION_ARGS); +PGDLLEXPORT Datum md5_in(PG_FUNCTION_ARGS); +PGDLLEXPORT Datum md5_out(PG_FUNCTION_ARGS); +PGDLLEXPORT Datum md5_recv(PG_FUNCTION_ARGS); +PGDLLEXPORT Datum md5_send(PG_FUNCTION_ARGS); +PGDLLEXPORT Datum md5_to_text(PG_FUNCTION_ARGS); +PGDLLEXPORT Datum text_to_md5(PG_FUNCTION_ARGS); +PGDLLEXPORT Datum bytea_to_md5(PG_FUNCTION_ARGS); +PGDLLEXPORT Datum md5_to_bytea(PG_FUNCTION_ARGS); +PGDLLEXPORT Datum md5_cmp(PG_FUNCTION_ARGS); +PGDLLEXPORT Datum md5_eq(PG_FUNCTION_ARGS); +PGDLLEXPORT Datum md5_ne(PG_FUNCTION_ARGS); +PGDLLEXPORT Datum md5_ge(PG_FUNCTION_ARGS); +PGDLLEXPORT Datum md5_gt(PG_FUNCTION_ARGS); +PGDLLEXPORT Datum md5_le(PG_FUNCTION_ARGS); +PGDLLEXPORT Datum md5_lt(PG_FUNCTION_ARGS); +PGDLLEXPORT Datum md5_hash(PG_FUNCTION_ARGS); /* diff --git a/src/sha.c b/src/sha.c index c69e7b1..d082246 100644 --- a/src/sha.c +++ b/src/sha.c @@ -57,20 +57,20 @@ typedef struct Sha { #define hash_function funcname(sha_hash, SHA_NAME) -Datum input_function(PG_FUNCTION_ARGS); -Datum output_function(PG_FUNCTION_ARGS); -Datum sha_to_text_fn(PG_FUNCTION_ARGS); -Datum text_to_sha_fn(PG_FUNCTION_ARGS); -Datum bytea_to_sha_fn(PG_FUNCTION_ARGS); -Datum sha_to_bytea_fn(PG_FUNCTION_ARGS); -Datum cmp_function(PG_FUNCTION_ARGS); -Datum equal_function(PG_FUNCTION_ARGS); -Datum notequal_function(PG_FUNCTION_ARGS); -Datum ge_function(PG_FUNCTION_ARGS); -Datum gt_function(PG_FUNCTION_ARGS); -Datum le_function(PG_FUNCTION_ARGS); -Datum lt_function(PG_FUNCTION_ARGS); -Datum hash_function(PG_FUNCTION_ARGS); +PGDLLEXPORT Datum input_function(PG_FUNCTION_ARGS); +PGDLLEXPORT Datum output_function(PG_FUNCTION_ARGS); +PGDLLEXPORT Datum sha_to_text_fn(PG_FUNCTION_ARGS); +PGDLLEXPORT Datum text_to_sha_fn(PG_FUNCTION_ARGS); +PGDLLEXPORT Datum bytea_to_sha_fn(PG_FUNCTION_ARGS); +PGDLLEXPORT Datum sha_to_bytea_fn(PG_FUNCTION_ARGS); +PGDLLEXPORT Datum cmp_function(PG_FUNCTION_ARGS); +PGDLLEXPORT Datum equal_function(PG_FUNCTION_ARGS); +PGDLLEXPORT Datum notequal_function(PG_FUNCTION_ARGS); +PGDLLEXPORT Datum ge_function(PG_FUNCTION_ARGS); +PGDLLEXPORT Datum gt_function(PG_FUNCTION_ARGS); +PGDLLEXPORT Datum le_function(PG_FUNCTION_ARGS); +PGDLLEXPORT Datum lt_function(PG_FUNCTION_ARGS); +PGDLLEXPORT Datum hash_function(PG_FUNCTION_ARGS); /* diff --git a/windows.mak b/windows.mak new file mode 100644 index 0000000..cf3363f --- /dev/null +++ b/windows.mak @@ -0,0 +1,35 @@ + +## You will need to change these two settings for your own system. +CC="C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\Llvm\8.0.0\bin\clang.exe" + +POSTGRES="C:\Program Files\PostgreSQL\11" + +## Nothing below this line should require touching. + +CFLAGS=-m64 -Wall -Wextra -O3 \ + -I$(POSTGRES)\include\server\port\win32_msvc \ + -I$(POSTGRES)\include\server\port\win32 \ + -I$(POSTGRES)\include\server \ + -I$(POSTGRES)\include + +LDFLAGS=-L$(POSTGRES)\lib -lpostgres + +# These rules take care of common.obj, crc32.obj and md5.obj +.c.obj: + $(CC) $(CFLAGS) -c $< -o$@ + +src\hashtypes.dll: src\common.obj src\crc32.obj src\md5.obj src\sha1.obj \ + src\sha224.obj src\sha256.obj src\sha384.obj src\sha512.obj + $(CC) $(CFLAGS) -shared $** $(LDFLAGS) -o$@ + +src\sha1.obj: src\sha.c + $(CC) $(CFLAGS) -c src\sha.c -o$@ -DSHA_NAME=1 -DSHA_LENGTH=20 +src\sha224.obj: src\sha.c + $(CC) $(CFLAGS) -c src\sha.c -o$@ -DSHA_NAME=224 -DSHA_LENGTH=28 +src\sha256.obj: src\sha.c + $(CC) $(CFLAGS) -c src\sha.c -o$@ -DSHA_NAME=256 -DSHA_LENGTH=32 +src\sha384.obj: src\sha.c + $(CC) $(CFLAGS) -c src\sha.c -o$@ -DSHA_NAME=384 -DSHA_LENGTH=48 +src\sha512.obj: src\sha.c + $(CC) $(CFLAGS) -c src\sha.c -o$@ -DSHA_NAME=512 -DSHA_LENGTH=64 + From 8ac8773b1573a51d4290cbc2a5aca7ed17ed299a Mon Sep 17 00:00:00 2001 From: Johann 'Myrkraverk' Oskarsson Date: Tue, 20 Aug 2019 23:40:57 +0800 Subject: [PATCH 2/2] Fix Windows makefile. --- windows.mak | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/windows.mak b/windows.mak index cf3363f..3a47315 100644 --- a/windows.mak +++ b/windows.mak @@ -14,7 +14,7 @@ CFLAGS=-m64 -Wall -Wextra -O3 \ LDFLAGS=-L$(POSTGRES)\lib -lpostgres -# These rules take care of common.obj, crc32.obj and md5.obj +## This implicit rule takes care of common.obj, crc32.obj and md5.obj .c.obj: $(CC) $(CFLAGS) -c $< -o$@ @@ -33,3 +33,9 @@ src\sha384.obj: src\sha.c src\sha512.obj: src\sha.c $(CC) $(CFLAGS) -c src\sha.c -o$@ -DSHA_NAME=512 -DSHA_LENGTH=64 +## We only install version 0.1.5 since the earlier releases haven't +## been ported to Windows. +install: src\hashtypes.dll + copy src\hashtypes.dll $(POSTGRES)\lib + copy hashtypes.control $(POSTGRES)\share\extension + copy sql\hashtypes--0.1.5.sql $(POSTGRES)\share\extension