Skip to content

Commit

Permalink
WIP - fixup whitespace
Browse files Browse the repository at this point in the history
  • Loading branch information
lfittl committed Jan 1, 2024
1 parent 648dc23 commit 4117d10
Show file tree
Hide file tree
Showing 18 changed files with 166 additions and 45 deletions.
9 changes: 0 additions & 9 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -147,15 +147,6 @@ extract_source: $(PGDIR)
mkdir ./src/postgres
mkdir ./src/postgres/include
LIBCLANG=/Library/Developer/CommandLineTools/usr/lib/libclang.dylib ruby ./scripts/extract_source.rb $(PGDIR)/ ./src/postgres/
cp $(PGDIR)/src/include/storage/dsm_impl.h ./src/postgres/include/storage
cp $(PGDIR)/src/include/port/atomics/arch-x86.h ./src/postgres/include/port/atomics
cp $(PGDIR)/src/include/port/atomics/arch-arm.h ./src/postgres/include/port/atomics
cp $(PGDIR)/src/include/port/atomics/arch-ppc.h ./src/postgres/include/port/atomics
cp $(PGDIR)/src/include/port/atomics/generic-msvc.h ./src/postgres/include/port/atomics
cp $(PGDIR)/src/include/port/win32.h ./src/postgres/include/port
cp $(PGDIR)/src/include/port/win32_port.h ./src/postgres/include/port
cp -a $(PGDIR)/src/include/port/win32 ./src/postgres/include/port
cp -a $(PGDIR)/src/include/port/win32_msvc ./src/postgres/include/port
# 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
Expand Down
11 changes: 9 additions & 2 deletions scripts/extract_source.rb
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,14 @@ def write_out

#return

@include_files_to_output.each do |include_file|
additional_includes = Dir.glob(@basepath + 'src/include/storage/dsm_impl.h') +
Dir.glob(@basepath + 'src/include/port/atomics/**/*.h') +
Dir.glob(@basepath + 'src/include/port/win32/**/*.h') +
Dir.glob(@basepath + 'src/include/port/win32_msvc/**/*.h') +
Dir.glob(@basepath + 'src/include/port/win32.h') +
Dir.glob(@basepath + 'src/include/port/win32_port.h')

(@include_files_to_output + additional_includes).each do |include_file|
if include_file.start_with?(@basepath + 'src/include')
out_file = @out_path + include_file.gsub(%r{^#{@basepath}src/}, '')
else
Expand All @@ -463,7 +470,7 @@ def write_out

code = File.read(include_file)
all_thread_local_variables.each do |variable|
code.gsub!(/(PGDLLIMPORT|extern)\s+(const|volatile)?\s*(\w+)\s+(\*{0,2})#{variable}(\[\])?;/, "\\1 __thread \\2 \\3 \\4#{variable}\\5;")
code.gsub!(/(extern\s+)(PGDLLIMPORT\s+)?(const\s+)?(volatile\s+)?(\w+)\s+(\*{0,2})#{variable}(\[\])?;/, "\\1\\2__thread \\3\\4\\5 \\6#{variable}\\7;")
end

FileUtils.mkdir_p File.dirname(out_file)
Expand Down
2 changes: 1 addition & 1 deletion src/postgres/include/miscadmin.h
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ extern PGDLLIMPORT bool IsUnderPostmaster;
extern PGDLLIMPORT bool IsBackgroundWorker;
extern PGDLLIMPORT bool IsBinaryUpgrade;

extern PGDLLIMPORT __thread bool ExitOnAnyError;
extern PGDLLIMPORT __thread bool ExitOnAnyError;

extern PGDLLIMPORT char *DataDir;
extern PGDLLIMPORT int data_directory_mode;
Expand Down
2 changes: 1 addition & 1 deletion src/postgres/include/nodes/nodes.h
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ typedef struct Node
* Fortunately, this macro isn't recursive so we just define
* a global variable for this purpose.
*/
extern PGDLLIMPORT __thread Node *newNodeMacroHolder;
extern PGDLLIMPORT __thread Node *newNodeMacroHolder;

#define newNode(size, tag) \
( \
Expand Down
6 changes: 3 additions & 3 deletions src/postgres/include/parser/parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@ typedef enum
} BackslashQuoteType;

/* GUC variables in scan.l (every one of these is a bad idea :-() */
extern PGDLLIMPORT __thread int backslash_quote;
extern PGDLLIMPORT __thread bool escape_string_warning;
extern PGDLLIMPORT __thread bool standard_conforming_strings;
extern PGDLLIMPORT __thread int backslash_quote;
extern PGDLLIMPORT __thread bool escape_string_warning;
extern PGDLLIMPORT __thread bool standard_conforming_strings;


/* Primary entry point for the raw parsing functions */
Expand Down
2 changes: 1 addition & 1 deletion src/postgres/include/pgstat.h
Original file line number Diff line number Diff line change
Expand Up @@ -764,7 +764,7 @@ extern PGDLLIMPORT PgStat_Counter pgStatActiveTime;
extern PGDLLIMPORT PgStat_Counter pgStatTransactionIdleTime;

/* updated by the traffic cop and in errfinish() */
extern PGDLLIMPORT __thread SessionEndType pgStatSessionEndCause;
extern PGDLLIMPORT __thread SessionEndType pgStatSessionEndCause;


/*
Expand Down
4 changes: 2 additions & 2 deletions src/postgres/include/pl_gram.h
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ typedef union YYSTYPE
# define YYSTYPE_IS_TRIVIAL 1
#endif

extern __thread YYSTYPE plpgsql_yylval;
extern __thread YYSTYPE plpgsql_yylval;

#if ! defined YYLTYPE && ! defined YYLTYPE_IS_DECLARED
typedef struct YYLTYPE
Expand All @@ -382,4 +382,4 @@ typedef struct YYLTYPE
# define YYLTYPE_IS_TRIVIAL 1
#endif

extern __thread YYLTYPE plpgsql_yylloc;
extern __thread YYLTYPE plpgsql_yylloc;
22 changes: 11 additions & 11 deletions src/postgres/include/plpgsql.h
Original file line number Diff line number Diff line change
Expand Up @@ -1191,11 +1191,11 @@ typedef enum
IDENTIFIER_LOOKUP_EXPR /* In SQL expression --- special case */
} IdentifierLookup;

extern __thread IdentifierLookup plpgsql_IdentifierLookup;
extern __thread IdentifierLookup plpgsql_IdentifierLookup;

extern __thread int plpgsql_variable_conflict;
extern __thread int plpgsql_variable_conflict;

extern __thread bool plpgsql_print_strict_params;
extern __thread bool plpgsql_print_strict_params;

extern bool plpgsql_check_asserts;

Expand All @@ -1209,18 +1209,18 @@ extern bool plpgsql_check_asserts;
extern int plpgsql_extra_warnings;
extern int plpgsql_extra_errors;

extern __thread bool plpgsql_check_syntax;
extern __thread bool plpgsql_DumpExecTree;
extern __thread bool plpgsql_check_syntax;
extern __thread bool plpgsql_DumpExecTree;

extern __thread PLpgSQL_stmt_block *plpgsql_parse_result;
extern __thread PLpgSQL_stmt_block *plpgsql_parse_result;

extern __thread int plpgsql_nDatums;
extern __thread PLpgSQL_datum **plpgsql_Datums;
extern __thread int plpgsql_nDatums;
extern __thread PLpgSQL_datum **plpgsql_Datums;

extern __thread char *plpgsql_error_funcname;
extern __thread char *plpgsql_error_funcname;

extern __thread PLpgSQL_function *plpgsql_curr_compile;
extern __thread MemoryContext plpgsql_compile_tmp_cxt;
extern __thread PLpgSQL_function *plpgsql_curr_compile;
extern __thread MemoryContext plpgsql_compile_tmp_cxt;

extern PLpgSQL_plugin **plpgsql_plugin_ptr;

Expand Down
17 changes: 17 additions & 0 deletions src/postgres/include/port/atomics/arch-hppa.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/*-------------------------------------------------------------------------
*
* arch-hppa.h
* Atomic operations considerations specific to HPPA
*
* Portions Copyright (c) 1996-2023, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
* NOTES:
*
* src/include/port/atomics/arch-hppa.h
*
*-------------------------------------------------------------------------
*/

/* HPPA doesn't do either read or write reordering */
#define pg_memory_barrier_impl() pg_compiler_barrier_impl()
106 changes: 106 additions & 0 deletions src/postgres/include/port/atomics/generic-sunpro.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
/*-------------------------------------------------------------------------
*
* generic-sunpro.h
* Atomic operations for solaris' CC
*
* Portions Copyright (c) 2013-2023, PostgreSQL Global Development Group
*
* NOTES:
*
* Documentation:
* * manpage for atomic_cas(3C)
* http://www.unix.com/man-page/opensolaris/3c/atomic_cas/
* http://docs.oracle.com/cd/E23824_01/html/821-1465/atomic-cas-3c.html
*
* src/include/port/atomics/generic-sunpro.h
*
* -------------------------------------------------------------------------
*/

#if defined(HAVE_ATOMICS)

#ifdef HAVE_MBARRIER_H
#include <mbarrier.h>

#define pg_compiler_barrier_impl() __compiler_barrier()

#ifndef pg_memory_barrier_impl
/*
* Despite the name this is actually a full barrier. Expanding to mfence/
* membar #StoreStore | #LoadStore | #StoreLoad | #LoadLoad on x86/sparc
* respectively.
*/
# define pg_memory_barrier_impl() __machine_rw_barrier()
#endif
#ifndef pg_read_barrier_impl
# define pg_read_barrier_impl() __machine_r_barrier()
#endif
#ifndef pg_write_barrier_impl
# define pg_write_barrier_impl() __machine_w_barrier()
#endif

#endif /* HAVE_MBARRIER_H */

/* Older versions of the compiler don't have atomic.h... */
#ifdef HAVE_ATOMIC_H

#include <atomic.h>

#define PG_HAVE_ATOMIC_U32_SUPPORT
typedef struct pg_atomic_uint32
{
volatile uint32 value;
} pg_atomic_uint32;

#define PG_HAVE_ATOMIC_U64_SUPPORT
typedef struct pg_atomic_uint64
{
/*
* Syntax to enforce variable alignment should be supported by versions
* supporting atomic.h, but it's hard to find accurate documentation. If
* it proves to be a problem, we'll have to add more version checks for 64
* bit support.
*/
volatile uint64 value pg_attribute_aligned(8);
} pg_atomic_uint64;

#endif /* HAVE_ATOMIC_H */

#endif /* defined(HAVE_ATOMICS) */


#if defined(HAVE_ATOMICS)

#ifdef HAVE_ATOMIC_H

#define PG_HAVE_ATOMIC_COMPARE_EXCHANGE_U32
static inline bool
pg_atomic_compare_exchange_u32_impl(volatile pg_atomic_uint32 *ptr,
uint32 *expected, uint32 newval)
{
bool ret;
uint32 current;

current = atomic_cas_32(&ptr->value, *expected, newval);
ret = current == *expected;
*expected = current;
return ret;
}

#define PG_HAVE_ATOMIC_COMPARE_EXCHANGE_U64
static inline bool
pg_atomic_compare_exchange_u64_impl(volatile pg_atomic_uint64 *ptr,
uint64 *expected, uint64 newval)
{
bool ret;
uint64 current;

current = atomic_cas_64(&ptr->value, *expected, newval);
ret = current == *expected;
*expected = current;
return ret;
}

#endif /* HAVE_ATOMIC_H */

#endif /* defined(HAVE_ATOMICS) */
4 changes: 2 additions & 2 deletions src/postgres/include/port/win32_port.h
Original file line number Diff line number Diff line change
Expand Up @@ -478,8 +478,8 @@ extern char *pgwin32_setlocale(int category, const char *locale);


/* In backend/port/win32/signal.c */
extern PGDLLIMPORT volatile int pg_signal_queue;
extern PGDLLIMPORT int pg_signal_mask;
extern PGDLLIMPORT __thread volatile int pg_signal_queue;
extern PGDLLIMPORT __thread int pg_signal_mask;
extern PGDLLIMPORT HANDLE pgwin32_signal_event;
extern PGDLLIMPORT HANDLE pgwin32_initial_signal_pipe;

Expand Down
2 changes: 1 addition & 1 deletion src/postgres/include/storage/ipc.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ typedef void (*shmem_startup_hook_type) (void);


/* ipc.c */
extern PGDLLIMPORT __thread bool proc_exit_inprogress;
extern PGDLLIMPORT __thread bool proc_exit_inprogress;
extern PGDLLIMPORT bool shmem_exit_inprogress;

extern void proc_exit(int code) pg_attribute_noreturn();
Expand Down
4 changes: 2 additions & 2 deletions src/postgres/include/tcop/tcopprot.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@
/* Required daylight between max_stack_depth and the kernel limit, in bytes */
#define STACK_DEPTH_SLOP (512 * 1024L)

extern PGDLLIMPORT __thread CommandDest whereToSendOutput;
extern PGDLLIMPORT __thread CommandDest whereToSendOutput;
extern PGDLLIMPORT __thread const char *debug_query_string;
extern PGDLLIMPORT __thread int max_stack_depth;
extern PGDLLIMPORT __thread int max_stack_depth;
extern PGDLLIMPORT int PostAuthDelay;
extern PGDLLIMPORT int client_connection_check_interval;

Expand Down
2 changes: 1 addition & 1 deletion src/postgres/include/utils/builtins.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ extern char *regexp_fixed_prefix(text *text_re, bool case_insensitive,
Oid collation, bool *exact);

/* ruleutils.c */
extern PGDLLIMPORT __thread bool quote_all_identifiers;
extern PGDLLIMPORT __thread bool quote_all_identifiers;
extern const char *quote_identifier(const char *ident);
extern char *quote_qualified_identifier(const char *qualifier,
const char *ident);
Expand Down
6 changes: 3 additions & 3 deletions src/postgres/include/utils/elog.h
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ typedef struct ErrorContextCallback
void *arg;
} ErrorContextCallback;

extern PGDLLIMPORT __thread ErrorContextCallback *error_context_stack;
extern PGDLLIMPORT __thread ErrorContextCallback *error_context_stack;


/*----------
Expand Down Expand Up @@ -426,7 +426,7 @@ extern PGDLLIMPORT __thread ErrorContextCallback *error_context_stack;
(pg_re_throw(), pg_unreachable())
#endif

extern PGDLLIMPORT __thread sigjmp_buf *PG_exception_stack;
extern PGDLLIMPORT __thread sigjmp_buf *PG_exception_stack;


/* Stuff that error handlers might want to use */
Expand Down Expand Up @@ -483,7 +483,7 @@ extern char *GetErrorContextStack(void);

/* Hook for intercepting messages before they are sent to the server log */
typedef void (*emit_log_hook_type) (ErrorData *edata);
extern PGDLLIMPORT __thread emit_log_hook_type emit_log_hook;
extern PGDLLIMPORT __thread emit_log_hook_type emit_log_hook;


/* GUC-configurable parameters */
Expand Down
6 changes: 3 additions & 3 deletions src/postgres/include/utils/guc.h
Original file line number Diff line number Diff line change
Expand Up @@ -249,21 +249,21 @@ extern PGDLLIMPORT bool log_executor_stats;
extern PGDLLIMPORT bool log_statement_stats;
extern PGDLLIMPORT bool log_btree_build_stats;

extern PGDLLIMPORT __thread bool check_function_bodies;
extern PGDLLIMPORT __thread bool check_function_bodies;
extern PGDLLIMPORT bool session_auth_is_superuser;

extern PGDLLIMPORT bool log_duration;
extern PGDLLIMPORT int log_parameter_max_length;
extern PGDLLIMPORT int log_parameter_max_length_on_error;
extern PGDLLIMPORT int log_min_error_statement;
extern PGDLLIMPORT __thread int log_min_messages;
extern PGDLLIMPORT __thread int log_min_messages;
extern PGDLLIMPORT int client_min_messages;
extern PGDLLIMPORT int log_min_duration_sample;
extern PGDLLIMPORT int log_min_duration_statement;
extern PGDLLIMPORT int log_temp_files;
extern PGDLLIMPORT double log_statement_sample_rate;
extern PGDLLIMPORT double log_xact_sample_rate;
extern PGDLLIMPORT __thread char *backtrace_functions;
extern PGDLLIMPORT __thread char *backtrace_functions;

extern PGDLLIMPORT int temp_file_limit;

Expand Down
4 changes: 2 additions & 2 deletions src/postgres/include/utils/memutils.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@
* Only TopMemoryContext and ErrorContext are initialized by
* MemoryContextInit() itself.
*/
extern PGDLLIMPORT __thread MemoryContext TopMemoryContext;
extern PGDLLIMPORT __thread MemoryContext ErrorContext;
extern PGDLLIMPORT __thread MemoryContext TopMemoryContext;
extern PGDLLIMPORT __thread MemoryContext ErrorContext;
extern PGDLLIMPORT MemoryContext PostmasterContext;
extern PGDLLIMPORT MemoryContext CacheMemoryContext;
extern PGDLLIMPORT MemoryContext MessageContext;
Expand Down
2 changes: 1 addition & 1 deletion src/postgres/include/utils/palloc.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ typedef struct MemoryContextCallback
* Avoid accessing it directly! Instead, use MemoryContextSwitchTo()
* to change the setting.
*/
extern PGDLLIMPORT __thread MemoryContext CurrentMemoryContext;
extern PGDLLIMPORT __thread MemoryContext CurrentMemoryContext;

/*
* Flags for MemoryContextAllocExtended.
Expand Down

0 comments on commit 4117d10

Please sign in to comment.