Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
lfittl committed Dec 30, 2023
1 parent 77bf65a commit 7ee002e
Show file tree
Hide file tree
Showing 8 changed files with 208 additions and 4 deletions.
8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@ postgres.tar.bz2

*.o
*.a
*.obj
*.so
*.bundle
*.dll
pg_query.exp
pg_query.lib

examples/*
!examples/*.c
Expand All @@ -17,3 +23,5 @@ test/*.dSYM

tmp/*
!tmp/.gitkeep

.vs/*
136 changes: 136 additions & 0 deletions Makefile.win32
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
TARGET = pg_query

PG_VERSION = 16.1
PG_VERSION_MAJOR = 16
PROTOC_VERSION = 25.1

VERSION = 5.0.0
VERSION_MAJOR = 5
VERSION_MINOR = 0
VERSION_PATCH = 0

SO_VERSION = 5.0

SOLIB = $(TARGET).lib
SONAME = $(SOLIB).$(SO_VERSION)
SOLIBVER = $(SONAME).$(VERSION_PATCH)
SOFLAG =

SRC_FILES = src/*.c src/postgres/*.c vendor/protobuf-c/protobuf-c.c vendor/xxhash/xxhash.c protobuf/pg_query.pb-c.c
OBJ_FILES = src/*.o src/postgres/*.o vendor/protobuf-c/protobuf-c.o vendor/xxhash/xxhash.o protobuf/pg_query.pb-c.o

CFLAGS = -I. -I./vendor -I./src/postgres/include -I./src/include -I./src/postgres/include/port/win32 -I./src/postgres/include/port/win32_msvc

TEST_CFLAGS = -I. -I./vendor -I./src/postgres/include -I./src/include -I./src/postgres/include/port/win32 -I./src/postgres/include/port/win32_msvc

CLEANLIBS = $(SOLIB)
CLEANOBJS = $(OBJ_FILES)
CLEANFILES = $(PGDIRBZ2)

INSTALL = install
LN_S = ln -s
RM = rm -f
ECHO = echo

all: examples test build

build: $(SOLIB)

clean:
del *.obj
del pg_query.exp
del pg_query.lib
del pg_query.dll

.PHONY: all clean build build_shared extract_source examples test install

.c.o:
@$(ECHO) compiling $(<)
@$(CC) $(CPPFLAGS) $(CFLAGS) -o $@ -c $<

$(SOLIB): clean $(OBJ_FILES) Makefile
link /dll /DEF:pg_query.def *.obj

EXAMPLES = examples/simple examples/scan examples/normalize examples/simple_error examples/normalize_error examples/simple_plpgsql
examples: $(EXAMPLES)
.\examples\simple
# .\examples\scan BROKEN
.\examples\normalize
.\examples\simple_error
.\examples\normalize_error
# .\examples\simple_plpgsql BROKEN

examples/simple: examples/simple.c $(SOLIB)
$(CC) $(TEST_CFLAGS) -o $@ -g examples/simple.c /link $(SOLIB) $(TEST_LDFLAGS)

examples/scan: examples/scan.c $(SOLIB)
$(CC) $(TEST_CFLAGS) -o $@ -g examples/scan.c /link $(SOLIB) $(TEST_LDFLAGS)

examples/normalize: examples/normalize.c $(SOLIB)
$(CC) $(TEST_CFLAGS) -o $@ -g examples/normalize.c /link $(SOLIB) $(TEST_LDFLAGS)

examples/simple_error: examples/simple_error.c $(SOLIB)
$(CC) $(TEST_CFLAGS) -o $@ -g examples/simple_error.c /link $(SOLIB) $(TEST_LDFLAGS)

examples/normalize_error: examples/normalize_error.c $(SOLIB)
$(CC) $(TEST_CFLAGS) -o $@ -g examples/normalize_error.c /link $(SOLIB) $(TEST_LDFLAGS)

examples/simple_plpgsql: examples/simple_plpgsql.c $(SOLIB)
$(CC) $(TEST_CFLAGS) -o $@ -g examples/simple_plpgsql.c /link $(SOLIB) $(TEST_LDFLAGS)

TESTS = test/deparse test/fingerprint test/fingerprint_opts test/normalize test/parse test/parse_opts test/parse_protobuf test/parse_protobuf_opts test/parse_plpgsql test/scan test/split
test: $(TESTS)
.\test\deparse
.\test\fingerprint
.\test\fingerprint_opts
.\test\normalize
.\test\parse
.\test\parse_opts
.\test\parse_protobuf
.\test\parse_protobuf_opts
# .\test\scan
.\test\split

# Doesn't work because of C2026: string too big, trailing characters truncated
#test/complex: test/complex.c $(SOLIB)
# We have "-Isrc/" because this test uses pg_query_fingerprint_with_opts
# $(CC) $(TEST_CFLAGS) -o $@ -Isrc/ test/complex.c /link $(SOLIB) $(TEST_LDFLAGS)

# Doesn't work since this requires pthreads
#test/concurrency: test/concurrency.c test/parse_tests.c $(SOLIB)
# $(CC) $(TEST_CFLAGS) -o $@ test/concurrency.c /link $(SOLIB) $(TEST_LDFLAGS)

test/deparse: test/deparse.c test/deparse_tests.c $(SOLIB)
$(CC) $(TEST_CFLAGS) -o $@ test/deparse.c /link $(SOLIB) $(TEST_LDFLAGS)

test/fingerprint: test/fingerprint.c test/fingerprint_tests.c $(SOLIB)
# We have "-Isrc/" because this test uses pg_query_fingerprint_with_opts
$(CC) $(TEST_CFLAGS) -o $@ -Isrc/ test/fingerprint.c /link $(SOLIB) $(TEST_LDFLAGS)

test/fingerprint_opts: test/fingerprint_opts.c test/fingerprint_opts_tests.c $(SOLIB)
# We have "-Isrc/" because this test uses pg_query_fingerprint_with_opts
$(CC) $(TEST_CFLAGS) -o $@ -Isrc/ test/fingerprint_opts.c /link $(SOLIB) $(TEST_LDFLAGS)

test/normalize: test/normalize.c test/normalize_tests.c $(SOLIB)
$(CC) $(TEST_CFLAGS) -o $@ test/normalize.c /link $(SOLIB) $(TEST_LDFLAGS)

test/parse: test/parse.c test/parse_tests.c $(SOLIB)
$(CC) $(TEST_CFLAGS) -o $@ test/parse.c /link $(SOLIB) $(TEST_LDFLAGS)

test/parse_opts: test/parse_opts.c test/parse_opts_tests.c $(SOLIB)
$(CC) $(TEST_CFLAGS) -o $@ test/parse_opts.c /link $(SOLIB) $(TEST_LDFLAGS)

test/parse_plpgsql: test/parse_plpgsql.c test/parse_tests.c $(SOLIB)
$(CC) $(TEST_CFLAGS) -o $@ test/parse_plpgsql.c /link $(SOLIB) $(TEST_LDFLAGS)

test/parse_protobuf: test/parse_protobuf.c test/parse_tests.c $(SOLIB)
$(CC) $(TEST_CFLAGS) -o $@ test/parse_protobuf.c /link $(SOLIB) $(TEST_LDFLAGS)

test/parse_protobuf_opts: test/parse_protobuf_opts.c test/parse_opts_tests.c $(SOLIB)
$(CC) $(TEST_CFLAGS) -o $@ test/parse_protobuf_opts.c /link $(SOLIB) $(TEST_LDFLAGS)

test/scan: test/scan.c test/scan_tests.c $(SOLIB)
$(CC) $(TEST_CFLAGS) -o $@ test/scan.c /link $(SOLIB) $(TEST_LDFLAGS)

test/split: test/split.c test/split_tests.c $(SOLIB)
$(CC) $(TEST_CFLAGS) -o $@ test/split.c /link $(SOLIB) $(TEST_LDFLAGS)
29 changes: 29 additions & 0 deletions pg_query.def
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
LIBRARY pg_query
EXPORTS
pg_query_parse
pg_query_free_parse_result
pg_query_exit
pg_query_scan
pg_query_free_scan_result
protobuf_c_enum_descriptor_get_value
pg_query__scan_result__unpack
pg_query__scan_result__free_unpacked
pg_query__keyword_kind__descriptor
pg_query__token__descriptor
pg_query_normalize
pg_query_free_normalize_result
pg_query_parse_plpgsql
pg_query_free_plpgsql_parse_result
pg_query_parse_protobuf
pg_query_split_with_scanner
pg_query_deparse_protobuf
pg_query_free_split_result
pg_query_free_deparse_result
pg_query_free_protobuf_parse_result
pg_query_fingerprint
pg_query_free_fingerprint_result
pg_query_fingerprint_with_opts
pg_query_fingerprint_opts
pg_query_parse_opts
pg_query_parse_protobuf_opts
pg_query_split_with_parser
31 changes: 31 additions & 0 deletions src/postgres/src_backend_nodes_nodes.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*-------------------------------------------------------------------------
*
* nodes.c
* support code for nodes (now that we have removed the home-brew
* inheritance system, our support code for nodes is much simpler)
*
* Portions Copyright (c) 1996-2023, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
*
* IDENTIFICATION
* src/backend/nodes/nodes.c
*
* HISTORY
* Andrew Yu Oct 20, 1994 file creation
*
*-------------------------------------------------------------------------
*/
#include "postgres.h"

#include "nodes/nodes.h"

/*
* Support for newNode() macro
*
* In a GCC build there is no need for the global variable newNodeMacroHolder.
* However, we create it anyway, to support the case of a non-GCC-built
* loadable module being loaded into a GCC-built backend.
*/

Node *newNodeMacroHolder;
1 change: 0 additions & 1 deletion test/deparse.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>
#include <sys/mman.h>
#include <sys/stat.h>
#include <unistd.h>
#include <fcntl.h>
Expand Down
4 changes: 3 additions & 1 deletion test/fingerprint_tests.c

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion test/parse_plpgsql.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#include <fcntl.h>
#include <assert.h>

#ifndef WIN32
#if !defined(_WIN32) && !defined(_WIN64)
#include <libgen.h>
#endif

Expand Down
1 change: 0 additions & 1 deletion test/split.c
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ int main()

buf = strdup("");
for (int i = 0; i < result.n_stmts; i++)
{for (int i = 0; i < result.n_stmts; i++)
{
char *newbuf = malloc(100);
int nbytes = snprintf(newbuf, 100, "%sloc=%d,len=%d;", buf, result.stmts[i]->stmt_location, result.stmts[i]->stmt_len);
Expand Down

0 comments on commit 7ee002e

Please sign in to comment.