Skip to content

Port hashtypes to Windows #17

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

Open
wants to merge 2 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: 5 additions & 0 deletions src/crc32.c
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
#include "postgres.h"
#include "fmgr.h"

#include <stdint.h>

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)
Expand Down
32 changes: 16 additions & 16 deletions src/md5.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);


/*
Expand Down
28 changes: 14 additions & 14 deletions src/sha.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);


/*
Expand Down
41 changes: 41 additions & 0 deletions windows.mak
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@

## 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

## This implicit rule takes 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

## 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