diff --git a/Makefile b/Makefile index aaf5d42e..e55e2d09 100644 --- a/Makefile +++ b/Makefile @@ -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/ @@ -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 " >> ./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 diff --git a/scripts/extract_source.rb b/scripts/extract_source.rb index 5b807ce8..5508b537 100644 --- a/scripts/extract_source.rb +++ b/scripts/extract_source.rb @@ -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', @@ -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) @@ -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 diff --git a/src/postgres/include/pg_config_os.h b/src/postgres/include/pg_config_os.h index 9348fa62..55baecd0 100644 --- a/src/postgres/include/pg_config_os.h +++ b/src/postgres/include/pg_config_os.h @@ -1,4 +1,5 @@ #if defined(_WIN32) || defined(_WIN64) #include "port/win32.h" -#include +#undef PGDLLIMPORT +#undef PGDLLEXPORT #endif diff --git a/src/postgres/src_backend_utils_error_elog.c b/src/postgres/src_backend_utils_error_elog.c index 48ef40a0..872d2fdf 100644 --- a/src/postgres/src_backend_utils_error_elog.c +++ b/src/postgres/src_backend_utils_error_elog.c @@ -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 @@ -44,6 +45,9 @@ * - errcontext_msg * - CopyErrorData * - FlushErrorState + * - pg_signal_queue + * - pg_signal_mask + * - pgwin32_dispatch_queued_signals *-------------------------------------------------------------------- */ @@ -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 diff --git a/src/postgres/src_port_strerror.c b/src/postgres/src_port_strerror.c index 9c49f758..5ce298f3 100644 --- a/src/postgres/src_port_strerror.c +++ b/src/postgres/src_port_strerror.c @@ -1,7 +1,6 @@ /*-------------------------------------------------------------------- * Symbols referenced in this file: * - pg_strerror_r - * - win32_socket_strerror * - gnuish_strerror_r * - get_errno_symbol *-------------------------------------------------------------------- diff --git a/src/postgres/src_port_strlcpy.c b/src/postgres/src_port_strlcpy.c index 30367e73..e19a9d4d 100644 --- a/src/postgres/src_port_strlcpy.c +++ b/src/postgres/src_port_strlcpy.c @@ -1,6 +1,6 @@ /*-------------------------------------------------------------------- * Symbols referenced in this file: - * - __builtin___strlcpy_chk + * - strlcpy *-------------------------------------------------------------------- */