@@ -78,6 +78,16 @@ zend_module_entry shmop_module_entry = {
78
78
ZEND_GET_MODULE (shmop )
79
79
#endif
80
80
81
+ #define PHP_SHMOP_GET_RES \
82
+ shmop = zend_list_find(shmid, &type); \
83
+ if (!shmop) { \
84
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "no shared memory segment with an id of [%lu]", shmid); \
85
+ RETURN_FALSE; \
86
+ } else if (type != shm_type) { \
87
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "not a shmop resource"); \
88
+ RETURN_FALSE; \
89
+ } \
90
+
81
91
/* {{{ rsclean
82
92
*/
83
93
static void rsclean (zend_rsrc_list_entry * rsrc TSRMLS_DC )
@@ -201,13 +211,8 @@ PHP_FUNCTION(shmop_read)
201
211
return ;
202
212
}
203
213
204
- shmop = zend_list_find ( shmid , & type );
214
+ PHP_SHMOP_GET_RES
205
215
206
- if (!shmop ) {
207
- php_error_docref (NULL TSRMLS_CC , E_WARNING , "no shared memory segment with an id of [%lu]" , shmid );
208
- RETURN_FALSE ;
209
- }
210
-
211
216
if (start < 0 || start > shmop -> size ) {
212
217
php_error_docref (NULL TSRMLS_CC , E_WARNING , "start is out of range" );
213
218
RETURN_FALSE ;
@@ -241,12 +246,7 @@ PHP_FUNCTION(shmop_close)
241
246
return ;
242
247
}
243
248
244
- shmop = zend_list_find (shmid , & type );
245
-
246
- if (!shmop ) {
247
- php_error_docref (NULL TSRMLS_CC , E_WARNING , "no shared memory segment with an id of [%lu]" , shmid );
248
- RETURN_FALSE ;
249
- }
249
+ PHP_SHMOP_GET_RES
250
250
251
251
zend_list_delete (shmid );
252
252
}
@@ -264,12 +264,7 @@ PHP_FUNCTION(shmop_size)
264
264
return ;
265
265
}
266
266
267
- shmop = zend_list_find (shmid , & type );
268
-
269
- if (!shmop ) {
270
- php_error_docref (NULL TSRMLS_CC , E_WARNING , "no shared memory segment with an id of [%lu]" , shmid );
271
- RETURN_FALSE ;
272
- }
267
+ PHP_SHMOP_GET_RES
273
268
274
269
RETURN_LONG (shmop -> size );
275
270
}
@@ -290,12 +285,7 @@ PHP_FUNCTION(shmop_write)
290
285
return ;
291
286
}
292
287
293
- shmop = zend_list_find (shmid , & type );
294
-
295
- if (!shmop ) {
296
- php_error_docref (NULL TSRMLS_CC , E_WARNING , "no shared memory segment with an id of [%lu]" , shmid );
297
- RETURN_FALSE ;
298
- }
288
+ PHP_SHMOP_GET_RES
299
289
300
290
if ((shmop -> shmatflg & SHM_RDONLY ) == SHM_RDONLY ) {
301
291
php_error_docref (NULL TSRMLS_CC , E_WARNING , "trying to write to a read only segment" );
@@ -326,12 +316,7 @@ PHP_FUNCTION(shmop_delete)
326
316
return ;
327
317
}
328
318
329
- shmop = zend_list_find (shmid , & type );
330
-
331
- if (!shmop ) {
332
- php_error_docref (NULL TSRMLS_CC , E_WARNING , "no shared memory segment with an id of [%lu]" , shmid );
333
- RETURN_FALSE ;
334
- }
319
+ PHP_SHMOP_GET_RES
335
320
336
321
if (shmctl (shmop -> shmid , IPC_RMID , NULL)) {
337
322
php_error_docref (NULL TSRMLS_CC , E_WARNING , "can 't mark segment for deletion (are you the owner?)");
0 commit comments