Skip to content

PHPC-1956: Remove disabled __wakeup function in non-serializable classes #1513

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jan 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 11 additions & 24 deletions php_phongo.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,27 +56,28 @@ zend_object_handlers* phongo_get_std_object_handlers(void)
/* }}} */

/* {{{ Memory allocation wrappers */
static void* php_phongo_malloc(size_t num_bytes) /* {{{ */
Copy link
Member

Choose a reason for hiding this comment

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

I thought I had removed all of these, but I guess I haven't. Thanks for cleaning this up!

Copy link
Member Author

Choose a reason for hiding this comment

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

Is "these" referring to the foldmarkers (i.e. {{{ and }}})? There are a bunch more, so I can go through and clean those up separately if we like. None of us are using vim to work on this project, so I don't have to worry about @bjori yelling at me.

static void* php_phongo_malloc(size_t num_bytes)
{
return pemalloc(num_bytes, 1);
} /* }}} */
}

static void* php_phongo_calloc(size_t num_members, size_t num_bytes) /* {{{ */
static void* php_phongo_calloc(size_t num_members, size_t num_bytes)
{
return pecalloc(num_members, num_bytes, 1);
} /* }}} */
}

static void* php_phongo_realloc(void* mem, size_t num_bytes) /* {{{ */
static void* php_phongo_realloc(void* mem, size_t num_bytes)
{
return perealloc(mem, num_bytes, 1);
} /* }}} */
}

static void php_phongo_free(void* mem) /* {{{ */
static void php_phongo_free(void* mem)
{
if (mem) {
pefree(mem, 1);
}
} /* }}} */
}
/* }}} */

PHP_RINIT_FUNCTION(mongodb) /* {{{ */
{
Expand Down Expand Up @@ -153,12 +154,12 @@ static zend_class_entry* php_phongo_fetch_internal_class(const char* class_name,
return NULL;
}

static HashTable* php_phongo_std_get_gc(phongo_compat_object_handler_type* object, zval** table, int* n) /* {{{ */
static HashTable* php_phongo_std_get_gc(phongo_compat_object_handler_type* object, zval** table, int* n)
{
*table = NULL;
*n = 0;
return zend_std_get_properties(object);
} /* }}} */
}

PHP_MINIT_FUNCTION(mongodb) /* {{{ */
{
Expand Down Expand Up @@ -515,20 +516,6 @@ PHP_MINFO_FUNCTION(mongodb) /* {{{ */
phongo_display_ini_entries(ZEND_MODULE_INFO_FUNC_ARGS_PASSTHRU);
} /* }}} */

/* {{{ Shared function entries for disabling constructors and unserialize() */
PHP_FUNCTION(MongoDB_disabled___construct) /* {{{ */
{
phongo_throw_exception(PHONGO_ERROR_RUNTIME, "Accessing private constructor");
} /* }}} */

PHP_FUNCTION(MongoDB_disabled___wakeup) /* {{{ */
{
PHONGO_PARSE_PARAMETERS_NONE();

phongo_throw_exception(PHONGO_ERROR_RUNTIME, "%s", "MongoDB\\Driver objects cannot be serialized");
} /* }}} */
/* }}} */

/* {{{ Module dependencies and module entry */
static const zend_module_dep mongodb_deps[] = {
/* clang-format off */
Expand Down
11 changes: 0 additions & 11 deletions php_phongo.h
Original file line number Diff line number Diff line change
Expand Up @@ -117,15 +117,4 @@ zend_object_handlers* phongo_get_std_object_handlers(void);
phongo_throw_exception(PHONGO_ERROR_RUNTIME, "Accessing private constructor"); \
}

#define PHONGO_DISABLED_WAKEUP(classname) \
static PHP_METHOD(classname, __wakeup) \
{ \
PHONGO_PARSE_PARAMETERS_NONE(); \
phongo_throw_exception(PHONGO_ERROR_RUNTIME, "MongoDB\\Driver objects cannot be serialized"); \
}

/* Shared function entries for disabling constructors and unserialize() */
PHP_FUNCTION(MongoDB_disabled___construct);
Copy link
Member

Choose a reason for hiding this comment

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

Noted that I added the macros in 6887226 but forgot to remove the shared functions below. Thanks for cleaning up my mess!

PHP_FUNCTION(MongoDB_disabled___wakeup);

#endif /* PHONGO_H */
1 change: 0 additions & 1 deletion src/BSON/Iterator.c
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,6 @@ static HashTable* php_phongo_iterator_get_properties_hash(phongo_compat_object_h
}

PHONGO_DISABLED_CONSTRUCTOR(MongoDB_BSON_Iterator)
PHONGO_DISABLED_WAKEUP(MongoDB_BSON_Iterator)

static PHP_METHOD(MongoDB_BSON_Iterator, current)
{
Expand Down
2 changes: 0 additions & 2 deletions src/BSON/Iterator.stub.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,4 @@ final public function next(): void {}
final public function rewind(): void {}

final public function valid(): bool {}

final public function __wakeup(): void {}
}
6 changes: 1 addition & 5 deletions src/BSON/Iterator_arginfo.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 0 additions & 2 deletions src/MongoDB/BulkWrite.c
Original file line number Diff line number Diff line change
Expand Up @@ -542,8 +542,6 @@ static PHP_METHOD(MongoDB_Driver_BulkWrite, count)
RETURN_LONG(intern->num_ops);
}

PHONGO_DISABLED_WAKEUP(MongoDB_Driver_BulkWrite)

/* MongoDB\Driver\BulkWrite object handlers */
static zend_object_handlers php_phongo_handler_bulkwrite;

Expand Down
2 changes: 0 additions & 2 deletions src/MongoDB/BulkWrite.stub.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,4 @@ public function update(array|object $filter, array|object $newObj, ?array $updat
*/
public function update($filter, $newObj, ?array $updateOptions = null): void {}
#endif

final public function __wakeup(): void {}
}
7 changes: 1 addition & 6 deletions src/MongoDB/BulkWrite_arginfo.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 0 additions & 2 deletions src/MongoDB/ClientEncryption.c
Original file line number Diff line number Diff line change
Expand Up @@ -473,8 +473,6 @@ static PHP_METHOD(MongoDB_Driver_ClientEncryption, rewrapManyDataKey)
mongoc_client_encryption_rewrap_many_datakey_result_destroy(result);
}

PHONGO_DISABLED_WAKEUP(MongoDB_Driver_ClientEncryption)

/* MongoDB\Driver\ClientEncryption object handlers */
static zend_object_handlers php_phongo_handler_clientencryption;

Expand Down
2 changes: 0 additions & 2 deletions src/MongoDB/ClientEncryption.stub.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,4 @@ final public function rewrapManyDataKey(array|object $filter, ?array $options =
/** @param array|object $filter */
final public function rewrapManyDataKey($filter, ?array $options = null): object {}
#endif

final public function __wakeup(): void {}
}
7 changes: 1 addition & 6 deletions src/MongoDB/ClientEncryption_arginfo.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 0 additions & 2 deletions src/MongoDB/Command.c
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,6 @@ static PHP_METHOD(MongoDB_Driver_Command, __construct)
php_phongo_command_init(intern, document, options);
}

PHONGO_DISABLED_WAKEUP(MongoDB_Driver_Command)

/* MongoDB\Driver\Command object handlers */
static zend_object_handlers php_phongo_handler_command;

Expand Down
2 changes: 0 additions & 2 deletions src/MongoDB/Command.stub.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,4 @@ final public function __construct(array|object $document, ?array $commandOptions
/** @param array|object $document */
final public function __construct($document, ?array $commandOptions = null) {}
#endif

final public function __wakeup(): void {}
}
7 changes: 1 addition & 6 deletions src/MongoDB/Command_arginfo.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion src/MongoDB/Cursor.c
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,6 @@ static PHP_METHOD(MongoDB_Driver_Cursor, rewind)
}

PHONGO_DISABLED_CONSTRUCTOR(MongoDB_Driver_Cursor)
PHONGO_DISABLED_WAKEUP(MongoDB_Driver_Cursor)

/* MongoDB\Driver\Cursor object handlers */
static zend_object_handlers php_phongo_handler_cursor;
Expand Down
2 changes: 0 additions & 2 deletions src/MongoDB/Cursor.stub.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,4 @@ final public function setTypeMap(array $typemap): void {}
final public function toArray(): array {}

public function valid(): bool {}

final public function __wakeup(): void {}
}
6 changes: 1 addition & 5 deletions src/MongoDB/Cursor_arginfo.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 0 additions & 2 deletions src/MongoDB/Manager.c
Original file line number Diff line number Diff line change
Expand Up @@ -242,8 +242,6 @@ static bool php_phongo_manager_select_server(bool for_writes, bool inherit_read_
return false;
}

PHONGO_DISABLED_WAKEUP(MongoDB_Driver_Manager)

/* Constructs a new Manager */
static PHP_METHOD(MongoDB_Driver_Manager, __construct)
{
Expand Down
2 changes: 0 additions & 2 deletions src/MongoDB/Manager.stub.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,4 @@ final public function removeSubscriber(Monitoring\Subscriber $subscriber): void
final public function selectServer(?ReadPreference $readPreference = null): Server {}

final public function startSession(?array $options = null): Session {}

final public function __wakeup(): void {}
}
7 changes: 1 addition & 6 deletions src/MongoDB/Manager_arginfo.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion src/MongoDB/Monitoring/CommandFailedEvent.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
zend_class_entry* php_phongo_commandfailedevent_ce;

PHONGO_DISABLED_CONSTRUCTOR(MongoDB_Driver_Monitoring_CommandFailedEvent)
PHONGO_DISABLED_WAKEUP(MongoDB_Driver_Monitoring_CommandFailedEvent)

/* Returns the command name for this event */
static PHP_METHOD(MongoDB_Driver_Monitoring_CommandFailedEvent, getCommandName)
Expand Down
2 changes: 0 additions & 2 deletions src/MongoDB/Monitoring/CommandFailedEvent.stub.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,4 @@ final public function getServer(): \MongoDB\Driver\Server {}
final public function getServiceId(): ?\MongoDB\BSON\ObjectId {}

final public function getServerConnectionId(): ?int {}

final public function __wakeup(): void {}
}
Loading