Skip to content

Commit

Permalink
Enabled -Wall and fixed various small issues. Added test for progress…
Browse files Browse the repository at this point in the history
… monitor via callback, which is broken in 7.
  • Loading branch information
Danack committed Feb 24, 2015
1 parent 6b578ca commit 1a66083
Show file tree
Hide file tree
Showing 7 changed files with 80 additions and 25 deletions.
2 changes: 1 addition & 1 deletion configure-cflags.sh
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ echo "strictImageMagick is ${strictImageMagick}"
echo "strictPHP is ${strictPHP}"

if [[ $strictPHP = '1' ]] && [[ $strictImageMagick = '1' ]]; then
CFLAGS="-Wno-deprecated-declarations -Wdeclaration-after-statement -Werror";
CFLAGS="-Wno-deprecated-declarations -Wdeclaration-after-statement -Werror -Wall";
else
CFLAGS="-Wno-deprecated-declarations";
fi
Expand Down
6 changes: 4 additions & 2 deletions imagick_class.c
Original file line number Diff line number Diff line change
Expand Up @@ -3416,7 +3416,6 @@ PHP_METHOD(imagick, readimages)
zval *value;
zval *files;
php_imagick_object *intern;
HashPosition pos;
php_imagick_rw_result_t rc;

/* Parse parameters given to function */
Expand Down Expand Up @@ -11237,8 +11236,11 @@ PHP_METHOD(imagick, setprogressmonitor)
callback->previous_callback = IMAGICK_G(progress_callback);

//Add a ref and store the user's callback
//Z_ADDREF_P(user_callback);
#ifdef ZEND_ENGINE_3
Z_TRY_ADDREF_P(user_callback);
#else
Z_ADDREF_P(user_callback);
#endif
callback->user_callback = user_callback;

//The callback is now valid, store it in the global
Expand Down
23 changes: 12 additions & 11 deletions imagick_helpers.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,11 @@ MagickBooleanType php_imagick_progress_monitor_callable(const char *text, const
{
int error;
zend_fcall_info fci;
zval retval;
zend_fcall_info_cache fci_cache;

#ifdef ZEND_ENGINE_3
zval zargs[2];
zval retval;
#else
zval **zargs[2];
zval *retval_ptr;
Expand All @@ -81,7 +81,9 @@ MagickBooleanType php_imagick_progress_monitor_callable(const char *text, const
//IMAGICK_G(progress_callback) - this should be quicker
php_imagick_callback *callback = (php_imagick_callback*)userData;

#ifndef ZEND_ENGINE_3
TSRMLS_FETCH_FROM_CTX(callback->thread_ctx);
#endif
fci_cache = empty_fcall_info_cache;

fci.size = sizeof(fci);
Expand Down Expand Up @@ -233,14 +235,15 @@ zend_bool php_imagick_validate_map(const char *map TSRMLS_DC)

double *php_imagick_zval_to_double_array(zval *param_array, long *num_elements TSRMLS_DC)
{
zval **ppzval;
double *double_array;
long i = 0;

#ifdef ZEND_ENGINE_3
zend_ulong num_key;
zend_string *key;
zval *pzvalue;
#else
zval **ppzval;
#endif

*num_elements = zend_hash_num_elements(Z_ARRVAL_P(param_array));
Expand Down Expand Up @@ -284,14 +287,15 @@ double *php_imagick_zval_to_double_array(zval *param_array, long *num_elements T

long *php_imagick_zval_to_long_array(zval *param_array, long *num_elements TSRMLS_DC)
{
zval **ppzval;
long *long_array;
long i = 0;

#ifdef ZEND_ENGINE_3
zend_ulong num_key;
zend_string *key;
zval *pzvalue;
#else
zval **ppzval;
#endif

*num_elements = zend_hash_num_elements(Z_ARRVAL_P(param_array));
Expand All @@ -305,8 +309,6 @@ long *php_imagick_zval_to_long_array(zval *param_array, long *num_elements TSRML
#ifdef ZEND_ENGINE_3

ZEND_HASH_FOREACH_KEY_VAL(Z_ARRVAL_P(param_array), num_key, key, pzvalue) {
zval tmp_zval, *tmp_pzval;
long value = 0;
long_array[i] = zval_get_long(pzvalue);
i++;
} ZEND_HASH_FOREACH_END();
Expand Down Expand Up @@ -339,14 +341,15 @@ long *php_imagick_zval_to_long_array(zval *param_array, long *num_elements TSRML

unsigned char *php_imagick_zval_to_char_array(zval *param_array, long *num_elements TSRMLS_DC)
{
zval **ppzval;
unsigned char *char_array;
long i = 0;

#ifdef ZEND_ENGINE_3
zend_ulong num_key;
zend_string *key;
zval *pzvalue;
#else
zval **ppzval;
#endif

*num_elements = zend_hash_num_elements(Z_ARRVAL_P(param_array));
Expand All @@ -359,9 +362,6 @@ unsigned char *php_imagick_zval_to_char_array(zval *param_array, long *num_eleme

#ifdef ZEND_ENGINE_3
ZEND_HASH_FOREACH_KEY_VAL(Z_ARRVAL_P(param_array), num_key, key, pzvalue) {
zval tmp_zval, *tmp_pzval;
long value = 0;

char_array[i] = zval_get_long(pzvalue);
i++;
} ZEND_HASH_FOREACH_END();
Expand Down Expand Up @@ -493,14 +493,15 @@ PointInfo *php_imagick_zval_to_pointinfo_array(zval *coordinate_array, int *num_
{
PointInfo *coordinates;
long elements, sub_elements, i;
HashTable *coords;
zval **ppzval;
HashTable *sub_array;

#ifdef ZEND_ENGINE_3
zend_ulong num_key;
zend_string *key;
zval *pzvalue;
#else
HashTable *coords;
zval **ppzval;
#endif

i = 0;
Expand Down
7 changes: 5 additions & 2 deletions imagickdraw_class.c
Original file line number Diff line number Diff line change
Expand Up @@ -1187,10 +1187,13 @@ PHP_METHOD(imagickdraw, clone)
PHP_METHOD(imagickdraw, affine)
{
php_imagickdraw_object *internd;
zval *affine_matrix, **ppzval;
zval *affine_matrix;

#ifdef ZEND_ENGINE_3
zval *pzval;
#ifndef ZEND_ENGINE_3
#else
HashTable *affine;
zval **ppzval;
#endif
char *matrix_elements[] = { "sx", "rx", "ry",
"sy", "tx", "ty" };
Expand Down
20 changes: 11 additions & 9 deletions imagickkernel_class.c
Original file line number Diff line number Diff line change
Expand Up @@ -82,24 +82,31 @@ HashTable* php_imagickkernel_get_debug_info(zval *obj, int *is_temp TSRMLS_DC) /
php_imagickkernel_object *internp;
HashTable *debug_info;
KernelInfo *kernel_info;
zval zrv;
#ifdef ZEND_ENGINE_3
zval matrix;
#else
zval *matrix;
#endif

*is_temp = 1; //var_dump will destroy the hashtable

internp = (php_imagickkernel_object *)zend_object_store_get_object(obj TSRMLS_CC);
internp = Z_IMAGICKKERNEL_P(obj);
kernel_info = internp->kernel_info;

ALLOC_HASHTABLE(debug_info);
ZEND_INIT_SYMTABLE_EX(debug_info, 1, 0);

INIT_PZVAL(&zrv);

while (kernel_info != NULL) {
#ifdef ZEND_ENGINE_3
array_init(&matrix);
php_imagickkernelvalues_to_zval(&matrix, kernel_info);
zend_hash_next_index_insert(debug_info, &matrix);
#else
MAKE_STD_ZVAL(matrix);
array_init(matrix);
php_imagickkernelvalues_to_zval(matrix, kernel_info);
zend_hash_next_index_insert(debug_info, &matrix, sizeof(zval *), NULL);
#endif
kernel_info = kernel_info->next;
}

Expand Down Expand Up @@ -189,8 +196,6 @@ static void createKernelZval(zval *pzval, KernelInfo *kernel_info TSRMLS_DC) {
#ifdef ZEND_ENGINE_3
PHP_METHOD(imagickkernel, frommatrix)
{
php_imagickkernel_object *internp;
php_imagickkernel_object *intern_return;
zval *kernel_array;
zval *origin_array;
HashTable *inner_array;
Expand Down Expand Up @@ -228,15 +233,12 @@ PHP_METHOD(imagickkernel, frommatrix)


for (row=0 ; row<num_rows ; row++) {
zval tmp_zval, *tmp_pzval;

pzval_outer = zend_hash_index_find(Z_ARRVAL_P(kernel_array), row);
if (pzval_outer == NULL) {
php_imagick_throw_exception(IMAGICKKERNEL_CLASS, MATRIX_ERROR_UNEVEN TSRMLS_CC);
goto cleanup;
}


column = 0;

if (Z_TYPE_P(pzval_outer) == IS_ARRAY ) {
Expand Down
1 change: 1 addition & 0 deletions php_imagick_defs.h
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,7 @@ static inline php_imagickkernel_object *php_imagickkernel_fetch_object(zend_obje
#define php_imagickdraw_fetch_object(object) ((php_imagickdraw_object *)object)
#define php_imagickpixel_fetch_object(object) ((php_imagickpixel_object *)object)
#define php_imagickpixeliterator_fetch_object(object) ((php_imagickpixeliterator_object *)object)
#define php_imagickkernel_fetch_object(object) ((php_imagickkernel_object *)object)
#endif

// Object access
Expand Down
46 changes: 46 additions & 0 deletions tests/127_Imagick_progressMonitor_basic.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
--TEST--
Test Imagick, progressMonitor
--SKIPIF--
<?php require_once(dirname(__FILE__) . '/skipif.inc'); ?>
--FILE--
<?php

$radius = 5;
$sigma = 1;

$status = 'Not cancelled';
$startTime = time();

$callback = function ($offset, $span) use (&$status, $startTime) {
if (((100 * $offset) / $span) > 20) {
$status = "Processing cancelled";
return false;
}

$nowTime = time();

if ($nowTime - $startTime > 5) {
$status = "Processing cancelled";
return false;
}

return true;
};

$imagick = new \Imagick();
$imagick->newPseudoImage(640, 480, "magick:logo");

$imagick->setProgressMonitor($callback);

try {

$imagick->charcoalImage($radius, $sigma);
$bytes = $imagick->getImageBlob();
echo "Progress monitor failed to interrupt.";
}
catch(\Exception $e) {
echo $status.PHP_EOL;
}
?>
--EXPECTF--
Processing cancelled

0 comments on commit 1a66083

Please sign in to comment.