Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
lfittl committed Jan 1, 2024
1 parent f2c9b0b commit 648dc23
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 6 deletions.
11 changes: 9 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,12 @@ $(PGDIR):
# Only define strlcpy when needed
sed -i "" '$(shell echo 's/\#include "c.h"/#include "c.h"\n#if HAVE_DECL_STRLCPY == 0/')' $(PGDIR)/src/port/strlcpy.c
echo "#endif // HAVE_DECL_STRLCPY == 0" >> $(PGDIR)/src/port/strlcpy.c
# Define symbols needed by elog.c that are commonly defined by win32/signal.c
echo "#ifdef WIN32" >> $(PGDIR)/src/backend/utils/error/elog.c
echo "volatile int pg_signal_queue;" >> $(PGDIR)/src/backend/utils/error/elog.c
echo "int pg_signal_mask;" >> $(PGDIR)/src/backend/utils/error/elog.c
echo "void pgwin32_dispatch_queued_signals(void) {}" >> $(PGDIR)/src/backend/utils/error/elog.c
echo "#endif" >> $(PGDIR)/src/backend/utils/error/elog.c

extract_source: $(PGDIR)
-@ $(RM) -rf ./src/postgres/
Expand All @@ -153,8 +159,9 @@ extract_source: $(PGDIR)
# Override OS-specific pg_config_os.h to only load Win32 logic (the primary port logic that matters for libpg_query), if needed
echo "#if defined(_WIN32) || defined(_WIN64)" > ./src/postgres/include/pg_config_os.h
echo "#include \"port/win32.h\"" >> ./src/postgres/include/pg_config_os.h
# Load windows.h early so ERROR is defined so win_32.port.h can undef it (loaded via postgres.h/c.h)
echo "#include <windows.h>" >> ./src/postgres/include/pg_config_os.h
# Don't mark anything as visible based on how Postgres defines it
echo "#undef PGDLLIMPORT" >> ./src/postgres/include/pg_config_os.h
echo "#undef PGDLLEXPORT" >> ./src/postgres/include/pg_config_os.h
echo "#endif" >> ./src/postgres/include/pg_config_os.h
# Adjust version string to ignore differences in build environments
sed -i "" '$(shell echo 's/\#define PG_VERSION_STR .*/#define PG_VERSION_STR "PostgreSQL $(PG_VERSION) \(libpg_query\)"/')' ./src/postgres/include/pg_config.h
Expand Down
8 changes: 7 additions & 1 deletion scripts/extract_source.rb
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,7 @@ def analyze_file(file)
'-I', `xcrun --sdk macosx --show-sdk-path`.strip + '/usr/include',
'-DDLSUFFIX=".bundle"',
'-g',
'-ferror-limit=0',
'-DUSE_ASSERT_CHECKING',
# EXEC_BACKEND is used on Windows, and can always be safely set during code analysis
'-DEXEC_BACKEND',
Expand All @@ -234,6 +235,8 @@ def analyze_file(file)
# To override built-ins, we must avoid pulling in any system headers, so pretend we already defined c.h
if file == @basepath + 'src/port/strlcpy.c'
flags << '-DC_H'
flags << '-DHAVE_DECL_STRLCPY=0'
flags << '-Dsize_t=unsigned'
end

translation_unit = index.parse_translation_unit(file, flags)
Expand Down Expand Up @@ -623,7 +626,10 @@ def write_out
runner.deep_resolve('pg_rightmost_one_pos')
runner.deep_resolve('pg_number_of_ones')
runner.deep_resolve('GetMessageEncoding')
runner.deep_resolve('__builtin___strlcpy_chk') # aka "strlcpy" on Windows
runner.deep_resolve('strlcpy')
runner.deep_resolve('pg_signal_queue')
runner.deep_resolve('pg_signal_mask')
runner.deep_resolve('pgwin32_dispatch_queued_signals')

runner.write_out

Expand Down
3 changes: 2 additions & 1 deletion src/postgres/include/pg_config_os.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#if defined(_WIN32) || defined(_WIN64)
#include "port/win32.h"
#include <windows.h>
#undef PGDLLIMPORT
#undef PGDLLEXPORT
#endif
11 changes: 11 additions & 0 deletions src/postgres/src_backend_utils_error_elog.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
* - emit_log_hook
* - send_message_to_server_log
* - send_message_to_frontend
* - pgwin32_dispatch_queued_signals
* - set_stack_entry_location
* - matches_backtrace_functions
* - backtrace_symbol_list
Expand All @@ -44,6 +45,9 @@
* - errcontext_msg
* - CopyErrorData
* - FlushErrorState
* - pg_signal_queue
* - pg_signal_mask
* - pgwin32_dispatch_queued_signals
*--------------------------------------------------------------------
*/

Expand Down Expand Up @@ -1930,3 +1934,10 @@ write_stderr(const char *fmt,...)
* hard-to-explain kluge.
*/

#ifdef WIN32
__thread volatile int pg_signal_queue;

__thread int pg_signal_mask;

void pgwin32_dispatch_queued_signals(void) {}
#endif
1 change: 0 additions & 1 deletion src/postgres/src_port_strerror.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
/*--------------------------------------------------------------------
* Symbols referenced in this file:
* - pg_strerror_r
* - win32_socket_strerror
* - gnuish_strerror_r
* - get_errno_symbol
*--------------------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion src/postgres/src_port_strlcpy.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*--------------------------------------------------------------------
* Symbols referenced in this file:
* - __builtin___strlcpy_chk
* - strlcpy
*--------------------------------------------------------------------
*/

Expand Down

0 comments on commit 648dc23

Please sign in to comment.