Skip to content

Convert resource to object in Sysvshm extension #5499

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

Closed
wants to merge 10 commits into from
Closed
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
5 changes: 5 additions & 0 deletions UPGRADING
Original file line number Diff line number Diff line change
Expand Up @@ -448,6 +448,11 @@ PHP 8.0 UPGRADE NOTES
Return value checks using is_resource() should be replaced with checks
for `false`.

- Sysvshm:
. shm_attach() will now return an SysvSharedMemory object rather than a resource.
Return value checks using is_resource() should be replaced with checks
for `false`.

- tidy:
. The $use_include_path parameter, which was not used internally, has been
removed from tidy_repair_string().
Expand Down
14 changes: 7 additions & 7 deletions ext/sysvsem/tests/sysv.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@ if (! sem_acquire($sem_id)) {
}
echo "Success acquire semaphore.\n";

$shm_id = shm_attach($SHMKEY, $MEMSIZE);
$shm_id = shm_attach($SHMKEY, $MEMSIZE);
if ($shm_id === FALSE) {
echo "Fail to attach shared memory.\n";
sem_remove($sem_id);
exit;
}
echo "Success to attach shared memory : $shm_id.\n";
echo "Success to attach shared memory.\n";

// Write variable 1
if (!shm_put_var($shm_id, 1, "Variable 1")) {
Expand All @@ -48,7 +48,7 @@ echo "Write var1 to shared memory.\n";

// Write variable 2
if (!shm_put_var($shm_id, 2, "Variable 2")) {
echo "Fail to put var 2 on shared memory $shm_id.\n";
echo "Fail to put var 2 on shared memory.\n";
sem_remove($sem_id);
shm_remove ($shm_id);
exit;
Expand All @@ -58,15 +58,15 @@ echo "Write var2 to shared memory.\n";
// Read variable 1
$var1 = shm_get_var ($shm_id, 1);
if ($var1 === FALSE) {
echo "Fail to retrieve Var 1 from Shared memory $shm_id, return value=$var1.\n";
echo "Fail to retrieve Var 1 from Shared memory, return value=$var1.\n";
} else {
echo "Read var1=$var1.\n";
}

// Read variable 1
$var2 = shm_get_var ($shm_id, 2);
if ($var1 === FALSE) {
echo "Fail to retrieve Var 2 from Shared memory $shm_id, return value=$var2.\n";
echo "Fail to retrieve Var 2 from Shared memory, return value=$var2.\n";
} else {
echo "Read var2=$var2.\n";
}
Expand All @@ -81,7 +81,7 @@ if (!sem_release($sem_id)) {
if (shm_remove ($shm_id)) {
echo "Shared memory successfully removed from SysV.\n";
} else {
echo "Fail to remove $shm_id shared memory from SysV.\n";
echo "Fail to remove shared memory from SysV.\n";
}

// Remove semaphore
Expand All @@ -101,7 +101,7 @@ echo "End.\n";
Start.
Got semaphore.
Success acquire semaphore.
Success to attach shared memory : %s.
Success to attach shared memory.
Write var1 to shared memory.
Write var2 to shared memory.
Read var1=Variable 1.
Expand Down
4 changes: 1 addition & 3 deletions ext/sysvshm/php_sysvshm.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,7 @@ extern zend_module_entry sysvshm_module_entry;
# include <sys/shm.h>
#endif

#define PHP_SHM_RSRC_NAME "sysvshm"

typedef struct {
int le_shm;
zend_long init_mem;
} sysvshm_module;

Expand All @@ -64,6 +61,7 @@ typedef struct {
key_t key; /* key set by user */
zend_long id; /* returned by shmget */
sysvshm_chunk_head *ptr; /* memory address of shared memory */
zend_object std;
} sysvshm_shm;

PHP_MINIT_FUNCTION(sysvshm);
Expand Down
Loading