[PECL-CVS] [pecl-networking-gearman] fix-fork-premature-job-completion: address reviews

[email protected] (Rasmus Lerdorf) Sat, 4 Apr 2026 14:41:42 +0000
Newsgroups php.pecl.cvs
Message-ID <[email protected]>
Author: Rasmus Lerdorf (rlerdorf)
Date: 2026-04-04T10:41:38-04:00

Commit: https://github.com/php/pecl-networking-gearman/commit/07c4519c7614ced3efaec1d1be816d5d57f84c15
Raw diff: https://github.com/php/pecl-networking-gearman/commit/07c4519c7614ced3efaec1d1be816d5d57f84c15.diff

address reviews

Changed paths:
  M  php_gearman_client.c
  M  php_gearman_client.h
  M  php_gearman_worker.c
  M  php_gearman_worker.h


Diff:

diff --git a/php_gearman_client.c b/php_gearman_client.c
index 9158212..5a30ed1 100644
--- a/php_gearman_client.c
+++ b/php_gearman_client.c
@@ -30,7 +30,7 @@ static void gearman_client_ctor(INTERNAL_FUNCTION_PARAMETERS) {
         }
 
         client->flags |= GEARMAN_CLIENT_OBJ_CREATED;
-        client->created_pid = getpid();
+        client->created_pid = (zend_long)getpid();
         gearman_client_add_options(&(client->client), GEARMAN_CLIENT_FREE_TASKS);
         gearman_client_set_workload_malloc_fn(&(client->client), _php_malloc, NULL);
         gearman_client_set_workload_free_fn(&(client->client), _php_free, NULL);
@@ -83,7 +83,7 @@ PHP_METHOD(GearmanClient, __destruct)
         }
 
         if (intern->flags & GEARMAN_CLIENT_OBJ_CREATED) {
-                if (getpid() == intern->created_pid) {
+                if ((zend_long)getpid() == intern->created_pid) {
                         context = gearman_client_context(&(intern->client));
                         if (context) {
                                 efree(context);
diff --git a/php_gearman_client.h b/php_gearman_client.h
index 416498a..c621041 100644
--- a/php_gearman_client.h
+++ b/php_gearman_client.h
@@ -16,9 +16,6 @@
 #include "php_ini.h"
 #include "ext/standard/info.h"
 
-#ifdef HAVE_UNISTD_H
-# include <unistd.h>
-#endif
 
 #include "zend_exceptions.h"
 #include "zend_interfaces.h"
@@ -55,7 +52,7 @@ typedef struct {
 
 	zend_ulong created_tasks;
 	zval task_list;
-	pid_t created_pid;
+	zend_long created_pid;
 
 	zend_object std;
 } gearman_client_obj;
diff --git a/php_gearman_worker.c b/php_gearman_worker.c
index 8b64792..cd10e7e 100644
--- a/php_gearman_worker.c
+++ b/php_gearman_worker.c
@@ -31,7 +31,7 @@ static void gearman_worker_ctor(INTERNAL_FUNCTION_PARAMETERS) {
 	}
 
 	worker->flags |= GEARMAN_WORKER_OBJ_CREATED;
-	worker->created_pid = getpid();
+	worker->created_pid = (zend_long)getpid();
 	gearman_worker_set_workload_malloc_fn(&(worker->worker), _php_malloc, NULL);
 	gearman_worker_set_workload_free_fn(&(worker->worker), _php_free, NULL);
 }
@@ -66,7 +66,7 @@ void gearman_worker_free_obj(zend_object *object) {
                  * sending protocol messages over the parent's connection,
                  * which would cause gearmand to prematurely mark the
                  * parent's in-progress job as complete. See #40. */
-                if (getpid() == intern->created_pid) {
+                if ((zend_long)getpid() == intern->created_pid) {
                         gearman_worker_free(&(intern->worker));
                 }
                 intern->flags &= ~GEARMAN_WORKER_OBJ_CREATED;
@@ -87,7 +87,7 @@ PHP_METHOD(GearmanWorker, __destruct) {
 	}
 
 	if (intern->flags & GEARMAN_WORKER_OBJ_CREATED) {
-		if (getpid() == intern->created_pid) {
+		if ((zend_long)getpid() == intern->created_pid) {
 			gearman_worker_free(&(intern->worker));
 		}
 		intern->flags &= ~GEARMAN_WORKER_OBJ_CREATED;
diff --git a/php_gearman_worker.h b/php_gearman_worker.h
index 6e05d08..f619001 100644
--- a/php_gearman_worker.h
+++ b/php_gearman_worker.h
@@ -16,9 +16,6 @@
 #include "php_ini.h"
 #include "ext/standard/info.h"
 
-#ifdef HAVE_UNISTD_H
-# include <unistd.h>
-#endif
 
 #include "zend_exceptions.h"
 #include "zend_interfaces.h"
@@ -52,7 +49,7 @@ typedef struct {
         gearman_worker_obj_flags_t flags;
         gearman_worker_st worker;
         zval cb_list;
-        pid_t created_pid;
+        zend_long created_pid;
 
         zend_object std;
 } gearman_worker_obj;