Skip to content

Comments

Arbitrary improvements#353

Open
danolivo wants to merge 3 commits intomainfrom
arbitrary-improvements
Open

Arbitrary improvements#353
danolivo wants to merge 3 commits intomainfrom
arbitrary-improvements

Conversation

@danolivo
Copy link
Contributor

Removed all the Windows code as we don't intend to support it.

@danolivo danolivo self-assigned this Feb 18, 2026
@danolivo danolivo added the enhancement New feature or request label Feb 18, 2026
@coderabbitai
Copy link

coderabbitai bot commented Feb 18, 2026

📝 Walkthrough

Walkthrough

This pull request removes Windows-specific declarations and code paths, consolidating process and temp-directory handling to POSIX-only implementations, updates PostgreSQL version gating for a build helper, deletes Windows typedefs from pgindent config, and adds a comment to spock conflict documentation. (48 words)

Changes

Cohort / File(s) Summary
Header cleanup
include/spock_sync.h
Removed the Windows-only QuoteWindowsArgv declaration and associated WIN32 guard.
Source changes (process & temp handling)
src/spock_sync.c, src/spock.c
Deleted Windows-specific process handling and helper functions (exec_cmd_win32 and related), removed WIN32 branches; unified to POSIX fork/waitpid flow and TMPDIR-based temp-directory resolution.
Build/version gating
src/spock_sync.c
Added #if PG_VERSION_NUM >= 180000 guard around build_exclude_extension_string.
pgindent typedefs
utils/pgindent/typedefs.list
Removed Windows typedef entries (e.g., BY_HANDLE_FILE_INFORMATION, DWORD, LPVOID, HANDLE, SC_HANDLE, SERVICE_STATUS_HANDLE, win32_deadchild_waitinfo).
Documentation comment
include/spock_conflict.h
Added an extended comment documenting SPOCK_CT_INSERT_EXISTS; no enum value changes.

Poem

🐇 I nibbled through #ifdef vines today,
removed the WIN32 trail along the way.
TMPDIR, fork, and waitpid sing,
simpler paths make my paws spring —
a tidy hop, a cleaner play. 🥕

🚥 Pre-merge checks | ✅ 1 | ❌ 2

❌ Failed checks (1 warning, 1 inconclusive)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Title check ❓ Inconclusive The title 'Arbitrary improvements' is vague and generic, using non-descriptive language that doesn't convey the main purpose of removing all Windows-specific code from the project. Consider a more specific title like 'Remove Windows-specific code and support' or 'Drop Windows platform support' to clearly communicate the primary change.
✅ Passed checks (1 passed)
Check name Status Explanation
Description check ✅ Passed The description clearly states the main objective of the pull request: removing all Windows code since the project won't support it, which aligns with the actual changes across multiple files.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch arbitrary-improvements

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (2)
src/spock_sync.c (2)

106-131: ⚠️ Potential issue | 🟡 Minor

Unhandled fork() failure: pid = -1 falls through to waitpid(-1, …).

With Windows code removed, this is the sole code path. When fork() returns -1:

  • The child block is skipped (correct).
  • waitpid(-1, &stat, 0) is then called, which waits for any child of the process — an unintended side-effect that could reap an unrelated child.
  • If waitpid itself returns -1 (e.g., ECHILD), the check if (-1 != -1) is false and stat is returned uninitialized (undefined behavior).
🐛 Proposed fix
 	if ((pid = fork()) == 0)
 	{
 		if (execv(cmd, cmdargv) < 0)
 		{
 			ereport(ERROR,
 					(errmsg("could not execute \"%s\": %m", cmd)));
 			/* We're already in the child process here, can't return */
 			exit(1);
 		}
 	}
+	else if (pid < 0)
+	{
+		/* fork() failed */
+		return -1;
+	}

 	if (waitpid(pid, &stat, 0) != pid)
 		stat = -1;
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/spock_sync.c` around lines 106 - 131, Handle the case where fork()
returns -1 in exec_cmd: after the fork() call check for pid == -1, log/ereport
the fork failure (including errno via %m) and return an error indicator (e.g.,
set stat = -1 and return it) without calling waitpid; only call waitpid when pid
> 0 and proceed with the existing child handling for pid == 0 in the same
function.

156-174: ⚠️ Potential issue | 🟠 Major

Wrong PostgreSQL version threshold — --exclude-extension was added in PostgreSQL 17.

The pg_dump option --exclude-extension was introduced in PostgreSQL 17, but the code guards it with PG_VERSION_NUM >= 180000 (PostgreSQL 18). This causes build_exclude_extension_string() to be compiled out on PostgreSQL 17, preventing extensions in skip_extension[] from being filtered from dumps.

Both locations need fixing:

  • Line 156: Function definition guard
  • Line 238: Call site guard

Change both from #if PG_VERSION_NUM >= 180000 to #if PG_VERSION_NUM >= 170000.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/spock_sync.c` around lines 156 - 174, The preprocessor guards erroneously
require PostgreSQL 18 for the build_exclude_extension_string feature; update
both occurrences that wrap the function and its call site to use PG_VERSION_NUM
>= 170000 instead of PG_VERSION_NUM >= 180000 so
build_exclude_extension_string() and its use (which relies on
--exclude-extension and the skip_extension[] list) are compiled for PostgreSQL
17+; locate the two guards surrounding build_exclude_extension_string and its
invocation and change the numeric threshold from 180000 to 170000.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Outside diff comments:
In `@src/spock_sync.c`:
- Around line 106-131: Handle the case where fork() returns -1 in exec_cmd:
after the fork() call check for pid == -1, log/ereport the fork failure
(including errno via %m) and return an error indicator (e.g., set stat = -1 and
return it) without calling waitpid; only call waitpid when pid > 0 and proceed
with the existing child handling for pid == 0 in the same function.
- Around line 156-174: The preprocessor guards erroneously require PostgreSQL 18
for the build_exclude_extension_string feature; update both occurrences that
wrap the function and its call site to use PG_VERSION_NUM >= 170000 instead of
PG_VERSION_NUM >= 180000 so build_exclude_extension_string() and its use (which
relies on --exclude-extension and the skip_extension[] list) are compiled for
PostgreSQL 17+; locate the two guards surrounding build_exclude_extension_string
and its invocation and change the numeric threshold from 180000 to 170000.

It is just the fact that --exclude-extension has been introduced in
Postgres 18.
Drop Win32-specific code paths including exec_cmd_win32(), GetTempPath()
temp directory resolution, Windows argument quoting, and related type
definitions. Spock targets POSIX-only environments.
@danolivo danolivo force-pushed the arbitrary-improvements branch from deb228a to 22cd40b Compare February 24, 2026 10:45
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/spock_sync.c (1)

156-174: ⚠️ Potential issue | 🟠 Major

Wrong version threshold: --exclude-extension was added in PostgreSQL 17, not 18.

--exclude-extension was added to pg_dump in PostgreSQL 17 (commit 522ed12f), confirmed by PostgreSQL.org documentation. The current code uses #if PG_VERSION_NUM >= 180000 at lines 156 and 238, which means build_exclude_extension_string() is never called for PostgreSQL 17 installations. This silently omits the --exclude-extension arguments from the pg_dump invocation, causing extensions that should be filtered to be included in the sync dump.

Proposed fix

Change the version threshold from 180000 to 170000 in two locations:

  1. Line 156 (function guard):
-#if PG_VERSION_NUM >= 180000
+#if PG_VERSION_NUM >= 170000
  1. Line 238 (function call):
-#if PG_VERSION_NUM >= 180000
+#if PG_VERSION_NUM >= 170000
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/spock_sync.c` around lines 156 - 174, The preprocessor threshold
incorrectly requires PG_VERSION_NUM >= 180000 so
build_exclude_extension_string() (which builds "--exclude-extension=" args using
skip_extension[] and get_extension_oid()) is not compiled for PostgreSQL 17;
change the two conditional checks that use 180000 to 170000 (the function guard
around build_exclude_extension_string and the corresponding conditional where
the function is invoked) so the function and its invocation are included for PG
17+.
🧹 Nitpick comments (1)
src/spock_sync.c (1)

116-128: Pre-existing: unhandled fork() failure will call waitpid(-1, …) and may reap an unrelated child.

If fork() returns -1, pid is -1 and the code falls through to waitpid(-1, &stat, 0), which waits for any child process rather than returning an error immediately. While this is unlikely to cause data corruption in practice (PostgreSQL backends rarely have unrelated children), the correct handling is an explicit failure guard:

🛡️ Suggested fix (pre-existing, not introduced by this PR)
 	if ((pid = fork()) == 0)
 	{
 		if (execv(cmd, cmdargv) < 0)
 		{
 			ereport(ERROR,
 					(errmsg("could not execute \"%s\": %m", cmd)));
-			/* We're already in the child process here, can't return */
-			exit(1);
+			_exit(1);	/* must not longjmp in child; ereport above may not return */
 		}
 	}
+	else if (pid < 0)
+		ereport(ERROR,
+				(errmsg("could not fork to execute \"%s\": %m", cmd)));
+
 	if (waitpid(pid, &stat, 0) != pid)
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/spock_sync.c` around lines 116 - 128, The code does not handle fork()
failure: if fork() returns -1 the code falls through and calls waitpid(-1,
&stat, 0). Add an explicit error branch for pid == -1 right after the fork()
call (before any waitpid) that logs/raises an error via ereport(ERROR, ...)
including %m or strerror(errno) and sets stat to -1 (or returns/propagates
failure) so waitpid is not called with -1; keep the existing child branch (pid
== 0) where execv is attempted and the parent branch where waitpid(pid, &stat,
0) is used unchanged. Ensure you reference the same symbols (pid, fork(),
waitpid, execv, stat) when locating and implementing the guard.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Outside diff comments:
In `@src/spock_sync.c`:
- Around line 156-174: The preprocessor threshold incorrectly requires
PG_VERSION_NUM >= 180000 so build_exclude_extension_string() (which builds
"--exclude-extension=" args using skip_extension[] and get_extension_oid()) is
not compiled for PostgreSQL 17; change the two conditional checks that use
180000 to 170000 (the function guard around build_exclude_extension_string and
the corresponding conditional where the function is invoked) so the function and
its invocation are included for PG 17+.

---

Nitpick comments:
In `@src/spock_sync.c`:
- Around line 116-128: The code does not handle fork() failure: if fork()
returns -1 the code falls through and calls waitpid(-1, &stat, 0). Add an
explicit error branch for pid == -1 right after the fork() call (before any
waitpid) that logs/raises an error via ereport(ERROR, ...) including %m or
strerror(errno) and sets stat to -1 (or returns/propagates failure) so waitpid
is not called with -1; keep the existing child branch (pid == 0) where execv is
attempted and the parent branch where waitpid(pid, &stat, 0) is used unchanged.
Ensure you reference the same symbols (pid, fork(), waitpid, execv, stat) when
locating and implementing the guard.

ℹ️ Review info

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between deb228a and 22cd40b.

📒 Files selected for processing (5)
  • include/spock_conflict.h
  • include/spock_sync.h
  • src/spock.c
  • src/spock_sync.c
  • utils/pgindent/typedefs.list
💤 Files with no reviewable changes (3)
  • src/spock.c
  • utils/pgindent/typedefs.list
  • include/spock_sync.h

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant