From 6b15f5cf31e73ef143bea4f91c04ea84f0d424de Mon Sep 17 00:00:00 2001 From: Vladimir Kolesnikov Date: Thu, 26 Sep 2013 22:14:53 +0300 Subject: [PATCH 1/6] Use preallocated zvals --- ext/acl/adapter/memory.c | 49 +-- ext/acl/resource.c | 15 +- ext/acl/role.c | 13 +- ext/annotations/base.c | 4 +- ext/annotations/collection.c | 2 +- ext/annotations/parser.c | 4 +- ext/annotations/reader.c | 5 +- ext/annotations/reflection.c | 14 +- ext/assets/collection.c | 38 +- ext/assets/manager.c | 42 +- ext/assets/resource.c | 14 +- ext/assets/resource/css.c | 23 +- ext/assets/resource/js.c | 23 +- ext/cache/backend.c | 4 +- ext/cache/backend/mongo.c | 2 +- ext/cache/multiple.c | 42 +- ext/cli/console.c | 12 +- ext/cli/dispatcher.c | 3 +- ext/config/adapter/ini.c | 7 +- ext/crypt.c | 14 +- ext/db/adapter.c | 235 +++++------ ext/db/adapter/pdo.c | 95 ++--- ext/db/adapter/pdo/mysql.c | 25 +- ext/db/adapter/pdo/oracle.c | 4 +- ext/db/adapter/pdo/postgresql.c | 2 +- ext/db/adapter/pdo/sqlite.c | 6 +- ext/db/dialect/mysql.c | 142 ++----- ext/db/dialect/oracle.c | 167 ++------ ext/db/dialect/postgresql.c | 12 +- ext/db/dialect/sqlite.c | 133 ++---- ext/db/profiler.c | 28 +- ext/db/result/pdo.c | 6 +- ext/debug.c | 34 +- ext/di.c | 23 +- ext/di/factorydefault.c | 3 +- ext/di/factorydefault/cli.c | 3 +- ext/di/service.c | 24 +- ext/di/service/builder.c | 2 +- ext/dispatcher.c | 8 +- ext/escaper.c | 3 +- ext/events/event.c | 21 +- ext/events/manager.c | 67 +-- ext/filter.c | 3 +- ext/flash.c | 2 +- ext/flash/session.c | 28 +- ext/forms/element.c | 135 +++--- ext/forms/element.h | 2 +- ext/forms/element/check.c | 9 +- ext/forms/element/date.c | 2 +- ext/forms/element/email.c | 2 +- ext/forms/element/file.c | 2 +- ext/forms/element/hidden.c | 2 +- ext/forms/element/numeric.c | 2 +- ext/forms/element/password.c | 2 +- ext/forms/element/select.c | 6 +- ext/forms/element/submit.c | 2 +- ext/forms/element/text.c | 2 +- ext/forms/element/textarea.c | 2 +- ext/forms/form.c | 230 ++++------- ext/forms/manager.c | 4 +- ext/http/cookie.c | 9 +- ext/http/request.c | 39 +- ext/http/response.c | 30 +- ext/http/response/cookies.c | 11 +- ext/image/adapter/imagick.c | 4 +- ext/kernel/array.c | 16 +- ext/kernel/fcall.c | 16 +- ext/kernel/fcall.h | 12 +- ext/kernel/framework/router.c | 16 +- ext/kernel/object.c | 14 +- ext/kernel/string.c | 6 +- ext/loader.c | 75 ++-- ext/logger/adapter/file.c | 2 +- ext/logger/adapter/stream.c | 2 +- ext/logger/adapter/syslog.c | 2 +- ext/logger/formatter/line.c | 19 +- ext/logger/item.c | 9 +- ext/mvc/application.c | 21 +- ext/mvc/collection.c | 46 ++- ext/mvc/collection/manager.c | 17 +- ext/mvc/micro.c | 391 ++++-------------- ext/mvc/micro/collection.c | 9 +- ext/mvc/model.c | 70 ++-- ext/mvc/model/behavior.c | 53 +-- ext/mvc/model/behavior/softdelete.c | 7 +- ext/mvc/model/criteria.c | 214 ++++------ ext/mvc/model/manager.c | 40 +- ext/mvc/model/message.c | 15 +- ext/mvc/model/metadata/apc.c | 2 +- ext/mvc/model/metadata/files.c | 14 +- ext/mvc/model/metadata/memory.c | 2 +- ext/mvc/model/metadata/session.c | 2 +- ext/mvc/model/metadata/strategy/annotations.c | 32 +- .../model/metadata/strategy/introspection.c | 43 +- ext/mvc/model/metadata/xcache.c | 2 +- ext/mvc/model/query.c | 24 +- ext/mvc/model/query/builder.c | 53 ++- ext/mvc/model/relation.c | 8 +- ext/mvc/model/resultset.c | 6 +- ext/mvc/model/resultset/complex.c | 2 +- ext/mvc/model/resultset/simple.c | 7 +- ext/mvc/model/transaction.c | 3 +- ext/mvc/model/transaction/manager.c | 12 +- ext/mvc/model/validator.c | 53 +-- ext/mvc/router.c | 25 +- ext/mvc/router/annotations.c | 88 ++-- ext/mvc/router/group.c | 35 +- ext/mvc/router/route.c | 6 +- ext/mvc/url.c | 14 +- ext/mvc/view.c | 63 +-- ext/mvc/view/engine.c | 10 +- ext/mvc/view/engine/php.c | 3 +- ext/mvc/view/engine/volt.c | 12 +- ext/mvc/view/engine/volt/compiler.c | 72 ++-- ext/mvc/view/simple.c | 103 ++--- ext/mvc/view/simple.h | 7 +- ext/phalcon.c | 102 +++++ ext/php_phalcon.h | 7 + ext/queue/beanstalk.c | 8 +- ext/security.c | 2 +- ext/session/adapter.c | 4 +- ext/session/bag.c | 2 +- ext/tag.c | 36 +- ext/tag/select.c | 8 +- ext/text.c | 28 +- ext/translate/adapter.c | 2 +- ext/translate/adapter/nativearray.c | 2 +- ext/validation.c | 30 +- ext/validation/message.c | 13 +- ext/validation/message/group.c | 12 +- ext/validation/validator.c | 10 +- ext/validation/validator/regex.c | 2 +- ext/validation/validator/stringlength.c | 7 +- 133 files changed, 1418 insertions(+), 2535 deletions(-) diff --git a/ext/acl/adapter/memory.c b/ext/acl/adapter/memory.c index 79d905e5031..015973119cb 100644 --- a/ext/acl/adapter/memory.c +++ b/ext/acl/adapter/memory.c @@ -124,21 +124,18 @@ PHALCON_INIT_CLASS(Phalcon_Acl_Adapter_Memory){ */ PHP_METHOD(Phalcon_Acl_Adapter_Memory, __construct){ - zval *ztrue, *resources_names, *access_list; + zval *resources_names, *access_list; PHALCON_MM_GROW(); - PHALCON_INIT_VAR(ztrue); - ZVAL_BOOL(ztrue, 1); - PHALCON_INIT_VAR(resources_names); array_init_size(resources_names, 1); - phalcon_array_update_string(&resources_names, SL("*"), &ztrue, PH_COPY | PH_SEPARATE); + phalcon_array_update_string(&resources_names, SL("*"), &PHALCON_GLOBAL(z_true), PH_COPY); phalcon_update_property_this(this_ptr, SL("_resourcesNames"), resources_names TSRMLS_CC); PHALCON_INIT_VAR(access_list); array_init_size(access_list, 1); - phalcon_array_update_string(&access_list, SL("*!*"), &ztrue, PH_COPY | PH_SEPARATE); + phalcon_array_update_string(&access_list, SL("*!*"), &PHALCON_GLOBAL(z_true), PH_COPY); phalcon_update_property_this(this_ptr, SL("_accessList"), access_list TSRMLS_CC); PHALCON_MM_RESTORE(); @@ -160,7 +157,7 @@ PHP_METHOD(Phalcon_Acl_Adapter_Memory, __construct){ PHP_METHOD(Phalcon_Acl_Adapter_Memory, addRole){ zval *role, *access_inherits = NULL, *role_name = NULL, *object = NULL; - zval *roles_names, *exists, *default_access; + zval *roles_names, *default_access; zval *key; PHALCON_MM_GROW(); @@ -168,7 +165,7 @@ PHP_METHOD(Phalcon_Acl_Adapter_Memory, addRole){ phalcon_fetch_params(1, 1, 1, &role, &access_inherits); if (!access_inherits) { - PHALCON_INIT_VAR(access_inherits); + access_inherits = PHALCON_GLOBAL(z_null); } if (Z_TYPE_P(role) == IS_OBJECT) { @@ -184,19 +181,15 @@ PHP_METHOD(Phalcon_Acl_Adapter_Memory, addRole){ } - PHALCON_OBS_VAR(roles_names); - phalcon_read_property_this(&roles_names, this_ptr, SL("_rolesNames"), PH_NOISY_CC); + roles_names = phalcon_fetch_nproperty_this(this_ptr, SL("_rolesNames"), PH_NOISY_CC); if (phalcon_array_isset(roles_names, role_name)) { RETURN_MM_FALSE; } - PHALCON_INIT_VAR(exists); - ZVAL_BOOL(exists, 1); phalcon_update_property_array_append(this_ptr, SL("_roles"), object TSRMLS_CC); - phalcon_update_property_array(this_ptr, SL("_rolesNames"), role_name, exists TSRMLS_CC); + phalcon_update_property_array(this_ptr, SL("_rolesNames"), role_name, PHALCON_GLOBAL(z_true) TSRMLS_CC); - PHALCON_OBS_VAR(default_access); - phalcon_read_property_this(&default_access, this_ptr, SL("_defaultAccess"), PH_NOISY_CC); + default_access = phalcon_fetch_nproperty_this(this_ptr, SL("_defaultAccess"), PH_NOISY_CC); PHALCON_INIT_VAR(key); PHALCON_CONCAT_VS(key, role_name, "!*!*"); @@ -340,14 +333,14 @@ PHP_METHOD(Phalcon_Acl_Adapter_Memory, isResource){ PHP_METHOD(Phalcon_Acl_Adapter_Memory, addResource){ zval *resource, *access_list = NULL, *resource_name = NULL; - zval *object = NULL, *resources_names, *exists; + zval *object = NULL, *resources_names; PHALCON_MM_GROW(); phalcon_fetch_params(1, 1, 1, &resource, &access_list); if (!access_list) { - PHALCON_INIT_VAR(access_list); + access_list = PHALCON_GLOBAL(z_null); } if (Z_TYPE_P(resource) == IS_OBJECT) { @@ -366,10 +359,8 @@ PHP_METHOD(Phalcon_Acl_Adapter_Memory, addResource){ PHALCON_OBS_VAR(resources_names); phalcon_read_property_this(&resources_names, this_ptr, SL("_resourcesNames"), PH_NOISY_CC); if (!phalcon_array_isset(resources_names, resource_name)) { - PHALCON_INIT_VAR(exists); - ZVAL_BOOL(exists, 1); phalcon_update_property_array_append(this_ptr, SL("_resources"), object TSRMLS_CC); - phalcon_update_property_array(this_ptr, SL("_resourcesNames"), resource_name, exists TSRMLS_CC); + phalcon_update_property_array(this_ptr, SL("_resourcesNames"), resource_name, PHALCON_GLOBAL(z_true) TSRMLS_CC); } phalcon_call_method_p2(return_value, this_ptr, "addresourceaccess", resource_name, access_list); @@ -385,7 +376,7 @@ PHP_METHOD(Phalcon_Acl_Adapter_Memory, addResource){ PHP_METHOD(Phalcon_Acl_Adapter_Memory, addResourceAccess){ zval *resource_name, *access_list, *resources_names; - zval *exception_message, *exists, *internal_access_list; + zval *exception_message, *internal_access_list; zval *access_name = NULL, *access_key = NULL; HashTable *ah0; HashPosition hp0; @@ -404,9 +395,6 @@ PHP_METHOD(Phalcon_Acl_Adapter_Memory, addResourceAccess){ return; } - PHALCON_INIT_VAR(exists); - ZVAL_BOOL(exists, 1); - PHALCON_OBS_VAR(internal_access_list); phalcon_read_property_this(&internal_access_list, this_ptr, SL("_accessList"), PH_NOISY_CC); if (Z_TYPE_P(access_list) == IS_ARRAY) { @@ -420,7 +408,7 @@ PHP_METHOD(Phalcon_Acl_Adapter_Memory, addResourceAccess){ PHALCON_INIT_NVAR(access_key); PHALCON_CONCAT_VSV(access_key, resource_name, "!", access_name); if (!phalcon_array_isset(internal_access_list, access_key)) { - phalcon_update_property_array(this_ptr, SL("_accessList"), access_key, exists TSRMLS_CC); + phalcon_update_property_array(this_ptr, SL("_accessList"), access_key, PHALCON_GLOBAL(z_true) TSRMLS_CC); } zend_hash_move_forward_ex(ah0, &hp0); @@ -432,7 +420,7 @@ PHP_METHOD(Phalcon_Acl_Adapter_Memory, addResourceAccess){ PHALCON_INIT_NVAR(access_key); PHALCON_CONCAT_VSV(access_key, resource_name, "!", access_list); if (!phalcon_array_isset(internal_access_list, access_key)) { - phalcon_update_property_array(this_ptr, SL("_accessList"), access_key, exists TSRMLS_CC); + phalcon_update_property_array(this_ptr, SL("_accessList"), access_key, PHALCON_GLOBAL(z_true) TSRMLS_CC); } } } @@ -854,17 +842,16 @@ PHP_METHOD(Phalcon_Acl_Adapter_Memory, isAllowed){ } } - PHALCON_INIT_VAR(have_access); - ZVAL_BOOL(have_access, allow_access); + ZVAL_BOOL(return_value, allow_access); - phalcon_update_property_this(this_ptr, SL("_accessGranted"), have_access TSRMLS_CC); + phalcon_update_property_this(this_ptr, SL("_accessGranted"), return_value TSRMLS_CC); if (Z_TYPE_P(events_manager) == IS_OBJECT) { PHALCON_INIT_NVAR(event_name); ZVAL_STRING(event_name, "acl:afterCheckAccess", 1); - phalcon_call_method_p3_noret(events_manager, "fire", event_name, this_ptr, have_access); + phalcon_call_method_p3_noret(events_manager, "fire", event_name, this_ptr, return_value); } - RETURN_CCTOR(have_access); + PHALCON_MM_RESTORE(); } /** diff --git a/ext/acl/resource.c b/ext/acl/resource.c index a56b60c5ab6..3efe644809a 100644 --- a/ext/acl/resource.c +++ b/ext/acl/resource.c @@ -69,24 +69,17 @@ PHP_METHOD(Phalcon_Acl_Resource, __construct){ zval *name, *description = NULL; - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 1, 1, &name, &description); - - if (!description) { - PHALCON_INIT_VAR(description); - } + phalcon_fetch_params(0, 1, 1, &name, &description); if (PHALCON_IS_STRING(name, "*")) { - PHALCON_THROW_EXCEPTION_STR(phalcon_acl_exception_ce, "Resource name cannot be \"*\""); + PHALCON_THROW_EXCEPTION_STRW(phalcon_acl_exception_ce, "Resource name cannot be \"*\""); return; } + phalcon_update_property_this(this_ptr, SL("_name"), name TSRMLS_CC); - if (Z_TYPE_P(description) != IS_NULL) { + if (description && Z_TYPE_P(description) != IS_NULL) { phalcon_update_property_this(this_ptr, SL("_description"), description TSRMLS_CC); } - - PHALCON_MM_RESTORE(); } /** diff --git a/ext/acl/role.c b/ext/acl/role.c index eda22494817..3791947827e 100644 --- a/ext/acl/role.c +++ b/ext/acl/role.c @@ -69,24 +69,17 @@ PHP_METHOD(Phalcon_Acl_Role, __construct){ zval *name, *description = NULL; - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 1, 1, &name, &description); - - if (!description) { - PHALCON_INIT_VAR(description); - } + phalcon_fetch_params(0, 1, 1, &name, &description); if (PHALCON_IS_STRING(name, "*")) { PHALCON_THROW_EXCEPTION_STR(phalcon_acl_exception_ce, "Role name cannot be \"*\""); return; } + phalcon_update_property_this(this_ptr, SL("_name"), name TSRMLS_CC); - if (Z_TYPE_P(description) != IS_NULL) { + if (description && Z_TYPE_P(description) != IS_NULL) { phalcon_update_property_this(this_ptr, SL("_description"), description TSRMLS_CC); } - - PHALCON_MM_RESTORE(); } /** diff --git a/ext/annotations/base.c b/ext/annotations/base.c index a9bbbbca815..ff17b0c421b 100644 --- a/ext/annotations/base.c +++ b/ext/annotations/base.c @@ -112,12 +112,12 @@ int phannot_parse_annotations(zval *result, zval *comment, zval *file_path, zval ZVAL_NULL(result); if (Z_TYPE_P(comment) != IS_STRING) { - PHALCON_THROW_EXCEPTION_STR(phalcon_annotations_exception_ce, "Comment must be a string"); + PHALCON_THROW_EXCEPTION_STRW(phalcon_annotations_exception_ce, "Comment must be a string"); return FAILURE; } if(phannot_internal_parse_annotations(&result, comment, file_path, line, &error_msg TSRMLS_CC) == FAILURE){ - PHALCON_THROW_EXCEPTION_STR(phalcon_annotations_exception_ce, Z_STRVAL_P(error_msg)); + PHALCON_THROW_EXCEPTION_STRW(phalcon_annotations_exception_ce, Z_STRVAL_P(error_msg)); return FAILURE; } diff --git a/ext/annotations/collection.c b/ext/annotations/collection.c index 495ba9a31bf..de8c919fdda 100644 --- a/ext/annotations/collection.c +++ b/ext/annotations/collection.c @@ -92,7 +92,7 @@ PHP_METHOD(Phalcon_Annotations_Collection, __construct){ phalcon_fetch_params(1, 0, 1, &reflection_data); if (!reflection_data) { - PHALCON_INIT_VAR(reflection_data); + reflection_data = PHALCON_GLOBAL(z_null); } if (Z_TYPE_P(reflection_data) != IS_NULL) { diff --git a/ext/annotations/parser.c b/ext/annotations/parser.c index 7a7c16ade43..19cffbb5428 100644 --- a/ext/annotations/parser.c +++ b/ext/annotations/parser.c @@ -1300,12 +1300,12 @@ int phannot_parse_annotations(zval *result, zval *comment, zval *file_path, zval ZVAL_NULL(result); if (Z_TYPE_P(comment) != IS_STRING) { - PHALCON_THROW_EXCEPTION_STR(phalcon_annotations_exception_ce, "Comment must be a string"); + PHALCON_THROW_EXCEPTION_STRW(phalcon_annotations_exception_ce, "Comment must be a string"); return FAILURE; } if(phannot_internal_parse_annotations(&result, comment, file_path, line, &error_msg TSRMLS_CC) == FAILURE){ - PHALCON_THROW_EXCEPTION_STR(phalcon_annotations_exception_ce, Z_STRVAL_P(error_msg)); + PHALCON_THROW_EXCEPTION_STRW(phalcon_annotations_exception_ce, Z_STRVAL_P(error_msg)); return FAILURE; } diff --git a/ext/annotations/reader.c b/ext/annotations/reader.c index 7572fbf03b4..967b64daae0 100644 --- a/ext/annotations/reader.c +++ b/ext/annotations/reader.c @@ -273,7 +273,7 @@ PHP_METHOD(Phalcon_Annotations_Reader, parseDocBlock){ } if (!line) { - PHALCON_INIT_VAR(line); + line = PHALCON_GLOBAL(z_null); } if (Z_TYPE_P(file) != IS_STRING) { @@ -281,8 +281,9 @@ PHP_METHOD(Phalcon_Annotations_Reader, parseDocBlock){ ZVAL_STRING(file, "eval code", 1); } if (phannot_parse_annotations(return_value, doc_block, file, line TSRMLS_CC) == FAILURE) { - return; + RETURN_MM(); } + RETURN_MM(); } diff --git a/ext/annotations/reflection.c b/ext/annotations/reflection.c index dc64c8c9be4..28c702479ec 100644 --- a/ext/annotations/reflection.c +++ b/ext/annotations/reflection.c @@ -81,19 +81,11 @@ PHP_METHOD(Phalcon_Annotations_Reflection, __construct){ zval *reflection_data = NULL; - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 0, 1, &reflection_data); + phalcon_fetch_params(0, 0, 1, &reflection_data); - if (!reflection_data) { - PHALCON_INIT_VAR(reflection_data); - } - - if (Z_TYPE_P(reflection_data) == IS_ARRAY) { + if (reflection_data && Z_TYPE_P(reflection_data) == IS_ARRAY) { phalcon_update_property_this(this_ptr, SL("_reflectionData"), reflection_data TSRMLS_CC); } - - PHALCON_MM_RESTORE(); } /** @@ -126,7 +118,7 @@ PHP_METHOD(Phalcon_Annotations_Reflection, getClassAnnotations){ RETURN_CTOR(collection); } - phalcon_update_property_bool(this_ptr, SL("_classAnnotations"), 0 TSRMLS_CC); + phalcon_update_property_this(this_ptr, SL("_classAnnotations"), PHALCON_GLOBAL(z_false) TSRMLS_CC); RETURN_MM_FALSE; } diff --git a/ext/assets/collection.c b/ext/assets/collection.c index 5e0c1d98d9f..8a35963c17a 100644 --- a/ext/assets/collection.c +++ b/ext/assets/collection.c @@ -109,29 +109,27 @@ PHP_METHOD(Phalcon_Assets_Collection, addCss){ phalcon_fetch_params(1, 1, 3, &path, &local, &filter, &attributes); if (!local) { - PHALCON_INIT_VAR(local); + local = PHALCON_GLOBAL(z_null); } if (!filter) { - PHALCON_INIT_VAR(filter); - ZVAL_BOOL(filter, 1); + filter = PHALCON_GLOBAL(z_true); } if (!attributes) { - PHALCON_INIT_VAR(attributes); + attributes = PHALCON_GLOBAL(z_null); } if (Z_TYPE_P(local) == IS_BOOL) { - PHALCON_CPY_WRT(collection_local, local); + collection_local = local; } else { - PHALCON_OBS_NVAR(collection_local); - phalcon_read_property_this(&collection_local, this_ptr, SL("_local"), PH_NOISY_CC); + collection_local = phalcon_fetch_nproperty_this(this_ptr, SL("_local"), PH_NOISY_CC); } + if (Z_TYPE_P(attributes) == IS_ARRAY) { - PHALCON_CPY_WRT(collection_attributes, attributes); + collection_attributes = attributes; } else { - PHALCON_OBS_NVAR(collection_attributes); - phalcon_read_property_this(&collection_attributes, this_ptr, SL("_attributes"), PH_NOISY_CC); + collection_attributes = phalcon_fetch_nproperty_this(this_ptr, SL("_attributes"), PH_NOISY_CC); } PHALCON_INIT_VAR(resource); @@ -162,29 +160,27 @@ PHP_METHOD(Phalcon_Assets_Collection, addJs){ phalcon_fetch_params(1, 1, 3, &path, &local, &filter, &attributes); if (!local) { - PHALCON_INIT_VAR(local); + local = PHALCON_GLOBAL(z_null); } if (!filter) { - PHALCON_INIT_VAR(filter); - ZVAL_BOOL(filter, 1); + filter = PHALCON_GLOBAL(z_true); } if (!attributes) { - PHALCON_INIT_VAR(attributes); + attributes = PHALCON_GLOBAL(z_null); } if (Z_TYPE_P(local) == IS_BOOL) { - PHALCON_CPY_WRT(collection_local, local); + collection_local = local; } else { - PHALCON_OBS_NVAR(collection_local); - phalcon_read_property_this(&collection_local, this_ptr, SL("_local"), PH_NOISY_CC); + collection_local = phalcon_fetch_nproperty_this(this_ptr, SL("_local"), PH_NOISY_CC); } + if (Z_TYPE_P(attributes) == IS_ARRAY) { - PHALCON_CPY_WRT(collection_attributes, attributes); + collection_attributes = attributes; } else { - PHALCON_OBS_NVAR(collection_attributes); - phalcon_read_property_this(&collection_attributes, this_ptr, SL("_attributes"), PH_NOISY_CC); + collection_attributes = phalcon_fetch_nproperty_this(this_ptr, SL("_attributes"), PH_NOISY_CC); } PHALCON_INIT_VAR(resource); @@ -570,7 +566,7 @@ PHP_METHOD(Phalcon_Assets_Collection, getRealTargetPath){ phalcon_fetch_params(1, 0, 1, &base_path); if (!base_path) { - PHALCON_INIT_VAR(base_path); + base_path = PHALCON_GLOBAL(z_null); } PHALCON_OBS_VAR(target_path); diff --git a/ext/assets/manager.c b/ext/assets/manager.c index caf1cbe455d..e10c6524119 100644 --- a/ext/assets/manager.c +++ b/ext/assets/manager.c @@ -70,19 +70,11 @@ PHP_METHOD(Phalcon_Assets_Manager, __construct){ zval *options = NULL; - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 0, 1, &options); - - if (!options) { - PHALCON_INIT_VAR(options); - } + phalcon_fetch_params(0, 0, 1, &options); - if (Z_TYPE_P(options) == IS_ARRAY) { + if (options && Z_TYPE_P(options) == IS_ARRAY) { phalcon_update_property_this(this_ptr, SL("_options"), options TSRMLS_CC); } - - PHALCON_MM_RESTORE(); } /** @@ -156,17 +148,15 @@ PHP_METHOD(Phalcon_Assets_Manager, addCss){ phalcon_fetch_params(1, 1, 3, &path, &local, &filter, &attributes); if (!local) { - PHALCON_INIT_VAR(local); - ZVAL_BOOL(local, 1); + local = PHALCON_GLOBAL(z_true); } if (!filter) { - PHALCON_INIT_VAR(filter); - ZVAL_BOOL(filter, 1); + filter = PHALCON_GLOBAL(z_true); } if (!attributes) { - PHALCON_INIT_VAR(attributes); + attributes = PHALCON_GLOBAL(z_null); } PHALCON_INIT_VAR(type); @@ -203,17 +193,15 @@ PHP_METHOD(Phalcon_Assets_Manager, addJs){ phalcon_fetch_params(1, 1, 3, &path, &local, &filter, &attributes); if (!local) { - PHALCON_INIT_VAR(local); - ZVAL_BOOL(local, 1); + local = PHALCON_GLOBAL(z_true); } if (!filter) { - PHALCON_INIT_VAR(filter); - ZVAL_BOOL(filter, 1); + filter = PHALCON_GLOBAL(z_true); } if (!attributes) { - PHALCON_INIT_VAR(attributes); + attributes = PHALCON_GLOBAL(z_null); } PHALCON_INIT_VAR(type); @@ -666,7 +654,7 @@ PHP_METHOD(Phalcon_Assets_Manager, output){ * resources paths are always filtered */ PHALCON_INIT_NVAR(filter_needed); - ZVAL_BOOL(filter_needed, 1); + ZVAL_TRUE(filter_needed); } /** @@ -987,17 +975,12 @@ PHP_METHOD(Phalcon_Assets_Manager, output){ PHP_METHOD(Phalcon_Assets_Manager, outputCss){ zval *collection_name = NULL, *collection = NULL, *callback, *type = NULL; - zval *output; PHALCON_MM_GROW(); phalcon_fetch_params(1, 0, 1, &collection_name); - if (!collection_name) { - PHALCON_INIT_VAR(collection_name); - } - - if (PHALCON_IS_EMPTY(collection_name)) { + if (!collection_name || PHALCON_IS_EMPTY(collection_name)) { PHALCON_INIT_VAR(collection); phalcon_call_method(collection, this_ptr, "getcss"); } else { @@ -1013,10 +996,9 @@ PHP_METHOD(Phalcon_Assets_Manager, outputCss){ PHALCON_INIT_VAR(type); ZVAL_STRING(type, "css", 1); - PHALCON_INIT_VAR(output); - phalcon_call_method_p3(output, this_ptr, "output", collection, callback, type); + phalcon_call_method_p3(return_value, this_ptr, "output", collection, callback, type); - RETURN_CCTOR(output); + PHALCON_MM_RESTORE(); } /** diff --git a/ext/assets/resource.c b/ext/assets/resource.c index 198d7bcbd6b..c483fad8cca 100644 --- a/ext/assets/resource.c +++ b/ext/assets/resource.c @@ -88,17 +88,15 @@ PHP_METHOD(Phalcon_Assets_Resource, __construct){ phalcon_fetch_params(1, 2, 3, &type, &path, &local, &filter, &attributes); if (!local) { - PHALCON_INIT_VAR(local); - ZVAL_BOOL(local, 1); + local = PHALCON_GLOBAL(z_true); } if (!filter) { - PHALCON_INIT_VAR(filter); - ZVAL_BOOL(filter, 1); + filter = PHALCON_GLOBAL(z_true); } if (!attributes) { - PHALCON_INIT_VAR(attributes); + attributes = PHALCON_GLOBAL(z_null); } phalcon_update_property_this(this_ptr, SL("_type"), type TSRMLS_CC); @@ -345,7 +343,7 @@ PHP_METHOD(Phalcon_Assets_Resource, getContent){ phalcon_fetch_params(1, 0, 1, &base_path); if (!base_path) { - PHALCON_INIT_VAR(base_path); + base_path = PHALCON_GLOBAL(z_null); } PHALCON_OBS_VAR(source_path); @@ -431,7 +429,7 @@ PHP_METHOD(Phalcon_Assets_Resource, getRealSourcePath){ phalcon_fetch_params(1, 0, 1, &base_path); if (!base_path) { - PHALCON_INIT_VAR(base_path); + base_path = PHALCON_GLOBAL(z_null); } PHALCON_OBS_VAR(source_path); @@ -475,7 +473,7 @@ PHP_METHOD(Phalcon_Assets_Resource, getRealTargetPath){ phalcon_fetch_params(1, 0, 1, &base_path); if (!base_path) { - PHALCON_INIT_VAR(base_path); + base_path = PHALCON_GLOBAL(z_null); } PHALCON_OBS_VAR(target_path); diff --git a/ext/assets/resource/css.c b/ext/assets/resource/css.c index 77a48760eef..60ff47400d3 100644 --- a/ext/assets/resource/css.c +++ b/ext/assets/resource/css.c @@ -67,24 +67,17 @@ PHP_METHOD(Phalcon_Assets_Resource_Css, __construct){ phalcon_fetch_params(1, 1, 3, &path, &local, &filter, &attributes); - if (!local) { - PHALCON_INIT_VAR(local); - ZVAL_BOOL(local, 1); - } - - if (!filter) { - PHALCON_INIT_VAR(filter); - ZVAL_BOOL(filter, 1); - } - - if (!attributes) { - PHALCON_INIT_VAR(attributes); - } - PHALCON_INIT_VAR(type); ZVAL_STRING(type, "css", 1); - phalcon_call_parent_p5_noret(this_ptr, phalcon_assets_resource_css_ce, "__construct", type, path, local, filter, attributes); + phalcon_call_parent_p5_noret( + this_ptr, + phalcon_assets_resource_css_ce, "__construct", + type, path, + (local ? local : PHALCON_GLOBAL(z_true)), + (filter ? filter : PHALCON_GLOBAL(z_true)), + (attributes ? attributes : PHALCON_GLOBAL(z_null)) + ); PHALCON_MM_RESTORE(); } diff --git a/ext/assets/resource/js.c b/ext/assets/resource/js.c index fc57e760dcc..44995567e90 100644 --- a/ext/assets/resource/js.c +++ b/ext/assets/resource/js.c @@ -67,24 +67,17 @@ PHP_METHOD(Phalcon_Assets_Resource_Js, __construct){ phalcon_fetch_params(1, 1, 3, &path, &local, &filter, &attributes); - if (!local) { - PHALCON_INIT_VAR(local); - ZVAL_BOOL(local, 1); - } - - if (!filter) { - PHALCON_INIT_VAR(filter); - ZVAL_BOOL(filter, 1); - } - - if (!attributes) { - PHALCON_INIT_VAR(attributes); - } - PHALCON_INIT_VAR(type); ZVAL_STRING(type, "js", 1); - phalcon_call_parent_p5_noret(this_ptr, phalcon_assets_resource_js_ce, "__construct", type, path, local, filter, attributes); + phalcon_call_parent_p5_noret( + this_ptr, + phalcon_assets_resource_js_ce, "__construct", + type, path, + (local ? local : PHALCON_GLOBAL(z_true)), + (filter ? filter : PHALCON_GLOBAL(z_true)), + (attributes ? attributes : PHALCON_GLOBAL(z_null)) + ); PHALCON_MM_RESTORE(); } diff --git a/ext/cache/backend.c b/ext/cache/backend.c index c3656328311..c080bd5172c 100644 --- a/ext/cache/backend.c +++ b/ext/cache/backend.c @@ -111,7 +111,7 @@ PHP_METHOD(Phalcon_Cache_Backend, start){ phalcon_fetch_params(1, 1, 1, &key_name, &lifetime); if (!lifetime) { - PHALCON_INIT_VAR(lifetime); + lifetime = PHALCON_GLOBAL(z_null); } /** @@ -130,7 +130,7 @@ PHP_METHOD(Phalcon_Cache_Backend, start){ } phalcon_update_property_this(this_ptr, SL("_fresh"), fresh TSRMLS_CC); - phalcon_update_property_bool(this_ptr, SL("_started"), 1 TSRMLS_CC); + phalcon_update_property_this(this_ptr, SL("_started"), PHALCON_GLOBAL(z_true) TSRMLS_CC); /** * Update the last lifetime to be used in save() diff --git a/ext/cache/backend/mongo.c b/ext/cache/backend/mongo.c index b71a857919f..6ecb402e883 100644 --- a/ext/cache/backend/mongo.c +++ b/ext/cache/backend/mongo.c @@ -99,7 +99,7 @@ PHP_METHOD(Phalcon_Cache_Backend_Mongo, __construct){ phalcon_fetch_params(1, 1, 1, &frontend, &options); if (!options) { - PHALCON_INIT_VAR(options); + options = PHALCON_GLOBAL(z_null); } if (!phalcon_array_isset_string(options, SS("mongo"))) { diff --git a/ext/cache/multiple.c b/ext/cache/multiple.c index 9da65ccbed3..84b688b2834 100644 --- a/ext/cache/multiple.c +++ b/ext/cache/multiple.c @@ -103,23 +103,19 @@ PHP_METHOD(Phalcon_Cache_Multiple, __construct){ zval *backends = NULL; - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 0, 1, &backends); + phalcon_fetch_params(0, 0, 1, &backends); if (!backends) { - PHALCON_INIT_VAR(backends); + backends = PHALCON_GLOBAL(z_null); } if (Z_TYPE_P(backends) != IS_NULL) { if (Z_TYPE_P(backends) != IS_ARRAY) { - PHALCON_THROW_EXCEPTION_STR(phalcon_cache_exception_ce, "The backends must be an array"); + PHALCON_THROW_EXCEPTION_STRW(phalcon_cache_exception_ce, "The backends must be an array"); return; } phalcon_update_property_this(this_ptr, SL("_backends"), backends TSRMLS_CC); } - - PHALCON_MM_RESTORE(); } /** @@ -163,11 +159,10 @@ PHP_METHOD(Phalcon_Cache_Multiple, get){ phalcon_fetch_params(1, 1, 1, &key_name, &lifetime); if (!lifetime) { - PHALCON_INIT_VAR(lifetime); + lifetime = PHALCON_GLOBAL(z_null); } - PHALCON_OBS_VAR(backends); - phalcon_read_property_this(&backends, this_ptr, SL("_backends"), PH_NOISY_CC); + backends = phalcon_fetch_nproperty_this(this_ptr, SL("_backends"), PH_NOISY_CC); phalcon_is_iterable(backends, &ah0, &hp0, 0, 0); @@ -206,11 +201,10 @@ PHP_METHOD(Phalcon_Cache_Multiple, start){ phalcon_fetch_params(1, 1, 1, &key_name, &lifetime); if (!lifetime) { - PHALCON_INIT_VAR(lifetime); + lifetime = PHALCON_GLOBAL(z_null); } - PHALCON_OBS_VAR(backends); - phalcon_read_property_this(&backends, this_ptr, SL("_backends"), PH_NOISY_CC); + backends = phalcon_fetch_nproperty_this(this_ptr, SL("_backends"), PH_NOISY_CC); phalcon_is_iterable(backends, &ah0, &hp0, 0, 0); @@ -248,24 +242,22 @@ PHP_METHOD(Phalcon_Cache_Multiple, save){ phalcon_fetch_params(1, 0, 4, &key_name, &content, &lifetime, &stop_buffer); if (!key_name) { - PHALCON_INIT_VAR(key_name); + key_name = PHALCON_GLOBAL(z_null); } if (!content) { - PHALCON_INIT_VAR(content); + content = PHALCON_GLOBAL(z_null); } if (!lifetime) { - PHALCON_INIT_VAR(lifetime); + lifetime = PHALCON_GLOBAL(z_null); } if (!stop_buffer) { - PHALCON_INIT_VAR(stop_buffer); - ZVAL_BOOL(stop_buffer, 1); + stop_buffer = PHALCON_GLOBAL(z_true); } - PHALCON_OBS_VAR(backends); - phalcon_read_property_this(&backends, this_ptr, SL("_backends"), PH_NOISY_CC); + backends = phalcon_fetch_nproperty_this(this_ptr, SL("_backends"), PH_NOISY_CC); phalcon_is_iterable(backends, &ah0, &hp0, 0, 0); @@ -299,8 +291,7 @@ PHP_METHOD(Phalcon_Cache_Multiple, delete){ phalcon_fetch_params(1, 1, 0, &key_name); - PHALCON_OBS_VAR(backends); - phalcon_read_property_this(&backends, this_ptr, SL("_backends"), PH_NOISY_CC); + backends = phalcon_fetch_nproperty_this(this_ptr, SL("_backends"), PH_NOISY_CC); phalcon_is_iterable(backends, &ah0, &hp0, 0, 0); @@ -337,15 +328,14 @@ PHP_METHOD(Phalcon_Cache_Multiple, exists){ phalcon_fetch_params(1, 0, 2, &key_name, &lifetime); if (!key_name) { - PHALCON_INIT_VAR(key_name); + key_name = PHALCON_GLOBAL(z_null); } if (!lifetime) { - PHALCON_INIT_VAR(lifetime); + lifetime = PHALCON_GLOBAL(z_null); } - PHALCON_OBS_VAR(backends); - phalcon_read_property_this(&backends, this_ptr, SL("_backends"), PH_NOISY_CC); + backends = phalcon_fetch_nproperty_this(this_ptr, SL("_backends"), PH_NOISY_CC); phalcon_is_iterable(backends, &ah0, &hp0, 0, 0); diff --git a/ext/cli/console.c b/ext/cli/console.c index 2d0456efc50..879d0da1899 100644 --- a/ext/cli/console.c +++ b/ext/cli/console.c @@ -72,19 +72,11 @@ PHP_METHOD(Phalcon_CLI_Console, __construct){ zval *dependency_injector = NULL; - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 0, 1, &dependency_injector); - - if (!dependency_injector) { - PHALCON_INIT_VAR(dependency_injector); - } + phalcon_fetch_params(0, 0, 1, &dependency_injector); - if (Z_TYPE_P(dependency_injector) == IS_OBJECT) { + if (dependency_injector && Z_TYPE_P(dependency_injector) == IS_OBJECT) { phalcon_update_property_this(this_ptr, SL("_dependencyInjector"), dependency_injector TSRMLS_CC); } - - PHALCON_MM_RESTORE(); } /** diff --git a/ext/cli/dispatcher.c b/ext/cli/dispatcher.c index 579f06283b8..e799a931f24 100644 --- a/ext/cli/dispatcher.c +++ b/ext/cli/dispatcher.c @@ -151,8 +151,7 @@ PHP_METHOD(Phalcon_CLI_Dispatcher, _throwDispatchException){ phalcon_fetch_params(1, 1, 1, &message, &exception_code); if (!exception_code) { - PHALCON_INIT_VAR(exception_code); - ZVAL_LONG(exception_code, 0); + exception_code = PHALCON_GLOBAL(z_zero); } PHALCON_INIT_VAR(exception); diff --git a/ext/config/adapter/ini.c b/ext/config/adapter/ini.c index f125df0f8ce..1f99bbaf7c9 100644 --- a/ext/config/adapter/ini.c +++ b/ext/config/adapter/ini.c @@ -135,7 +135,7 @@ PHALCON_INIT_CLASS(Phalcon_Config_Adapter_Ini){ */ PHP_METHOD(Phalcon_Config_Adapter_Ini, __construct){ - zval *file_path, *process_sections, *ini_config; + zval *file_path, *ini_config; zval *exception_message, *config, *directives = NULL; zval *section = NULL, *value = NULL, *key = NULL, *directive_parts = NULL; HashTable *ah0, *ah1; @@ -146,14 +146,11 @@ PHP_METHOD(Phalcon_Config_Adapter_Ini, __construct){ phalcon_fetch_params(1, 1, 0, &file_path); - PHALCON_INIT_VAR(process_sections); - ZVAL_BOOL(process_sections, 1); - /** * Use the standard parse_ini_file */ PHALCON_INIT_VAR(ini_config); - phalcon_call_func_p2(ini_config, "parse_ini_file", file_path, process_sections); + phalcon_call_func_p2(ini_config, "parse_ini_file", file_path, PHALCON_GLOBAL(z_true)); /** * Check if the file had errors diff --git a/ext/crypt.c b/ext/crypt.c index 5e925503d81..e29fcdb71ef 100644 --- a/ext/crypt.c +++ b/ext/crypt.c @@ -594,7 +594,7 @@ PHP_METHOD(Phalcon_Crypt, encryptBase64){ phalcon_fetch_params(1, 1, 1, &text, &key); if (!key) { - PHALCON_INIT_VAR(key); + key = PHALCON_GLOBAL(z_null); } PHALCON_OBS_VAR(encrypted); @@ -619,7 +619,7 @@ PHP_METHOD(Phalcon_Crypt, decryptBase64){ phalcon_fetch_params(1, 1, 1, &text, &key); if (!key) { - PHALCON_INIT_VAR(key); + key = PHALCON_GLOBAL(z_null); } PHALCON_INIT_VAR(decrypt_text); @@ -636,10 +636,7 @@ PHP_METHOD(Phalcon_Crypt, decryptBase64){ PHP_METHOD(Phalcon_Crypt, getAvailableCiphers){ - PHALCON_MM_GROW(); - - phalcon_call_func(return_value, "mcrypt_list_algorithms"); - RETURN_MM(); + phalcon_call_func_params(return_value, return_value_ptr, SL("mcrypt_list_algorithms") TSRMLS_CC, 0); } /** @@ -650,8 +647,5 @@ PHP_METHOD(Phalcon_Crypt, getAvailableCiphers){ PHP_METHOD(Phalcon_Crypt, getAvailableModes){ - PHALCON_MM_GROW(); - - phalcon_call_func(return_value, "mcrypt_list_modes"); - RETURN_MM(); + phalcon_call_func_params(return_value, return_value_ptr, SL("mcrypt_list_modes") TSRMLS_CC, 0); } diff --git a/ext/db/adapter.c b/ext/db/adapter.c index 2523112fbde..39a10e43cfc 100644 --- a/ext/db/adapter.c +++ b/ext/db/adapter.c @@ -80,7 +80,7 @@ PHALCON_INIT_CLASS(Phalcon_Db_Adapter){ */ PHP_METHOD(Phalcon_Db_Adapter, __construct){ - zval *descriptor, *one, *connection_consecutive; + zval *descriptor, *connection_consecutive; zval *next_consecutive, *dialect_type, *dialect_class = NULL; zval *dialect_object; zend_class_entry *ce0; @@ -89,9 +89,6 @@ PHP_METHOD(Phalcon_Db_Adapter, __construct){ phalcon_fetch_params(1, 1, 0, &descriptor); - PHALCON_INIT_VAR(one); - ZVAL_LONG(one, 1); - /** * Every new connection created obtain a consecutive number from the static * property self::$_connectionConsecutive @@ -99,22 +96,18 @@ PHP_METHOD(Phalcon_Db_Adapter, __construct){ connection_consecutive = phalcon_fetch_static_property_ce(phalcon_db_adapter_ce, SL("_connectionConsecutive") TSRMLS_CC); PHALCON_INIT_VAR(next_consecutive); - phalcon_add_function(next_consecutive, connection_consecutive, one TSRMLS_CC); + phalcon_add_function(next_consecutive, connection_consecutive, PHALCON_GLOBAL(z_one) TSRMLS_CC); phalcon_update_static_property_ce(phalcon_db_adapter_ce, SL("_connectionConsecutive"), next_consecutive TSRMLS_CC); phalcon_update_property_this(this_ptr, SL("_connectionId"), connection_consecutive TSRMLS_CC); /** * Dialect class can override the default dialect */ - if (!phalcon_array_isset_string(descriptor, SS("dialectClass"))) { - PHALCON_OBS_VAR(dialect_type); - phalcon_read_property_this(&dialect_type, this_ptr, SL("_dialectType"), PH_NOISY_CC); + if (!phalcon_array_isset_string_fetch(&dialect_class, descriptor, SS("dialectClass"))) { + dialect_type = phalcon_fetch_nproperty_this(this_ptr, SL("_dialectType"), PH_NOISY_CC); PHALCON_INIT_VAR(dialect_class); PHALCON_CONCAT_SV(dialect_class, "phalcon\\db\\dialect\\", dialect_type); - } else { - PHALCON_OBS_NVAR(dialect_class); - phalcon_array_fetch_string(&dialect_class, descriptor, SL("dialectClass"), PH_NOISY); } /** @@ -221,11 +214,11 @@ PHP_METHOD(Phalcon_Db_Adapter, fetchOne){ } if (!bind_params) { - PHALCON_INIT_VAR(bind_params); + bind_params = PHALCON_GLOBAL(z_null); } if (!bind_types) { - PHALCON_INIT_VAR(bind_types); + bind_types = PHALCON_GLOBAL(z_null); } PHALCON_INIT_VAR(result); @@ -270,7 +263,7 @@ PHP_METHOD(Phalcon_Db_Adapter, fetchOne){ PHP_METHOD(Phalcon_Db_Adapter, fetchAll){ zval *sql_query, *fetch_mode = NULL, *bind_params = NULL, *bind_types = NULL; - zval *results, *result, *row = NULL; + zval *result, *row = NULL; zval *r0 = NULL; PHALCON_MM_GROW(); @@ -283,15 +276,14 @@ PHP_METHOD(Phalcon_Db_Adapter, fetchAll){ } if (!bind_params) { - PHALCON_INIT_VAR(bind_params); + bind_params = PHALCON_GLOBAL(z_null); } if (!bind_types) { - PHALCON_INIT_VAR(bind_types); + bind_types = PHALCON_GLOBAL(z_null); } - PHALCON_INIT_VAR(results); - array_init(results); + array_init(return_value); PHALCON_INIT_VAR(result); phalcon_call_method_p3(result, this_ptr, "query", sql_query, bind_params, bind_types); @@ -305,16 +297,15 @@ PHP_METHOD(Phalcon_Db_Adapter, fetchAll){ PHALCON_INIT_NVAR(r0); phalcon_call_method(r0, result, "fetch"); PHALCON_CPY_WRT(row, r0); - if (zend_is_true(row)) { - } else { + if (!zend_is_true(row)) { break; } - phalcon_array_append(&results, row, PH_SEPARATE); + phalcon_array_append(&return_value, row, 0); } } - RETURN_CTOR(results); + PHALCON_MM_RESTORE(); } /** @@ -355,11 +346,11 @@ PHP_METHOD(Phalcon_Db_Adapter, insert){ phalcon_fetch_params(1, 2, 2, &table, &values, &fields, &data_types); if (!fields) { - PHALCON_INIT_VAR(fields); + fields = PHALCON_GLOBAL(z_null); } if (!data_types) { - PHALCON_INIT_VAR(data_types); + data_types = PHALCON_GLOBAL(z_null); } if (unlikely(Z_TYPE_P(values) != IS_ARRAY)) { @@ -518,11 +509,11 @@ PHP_METHOD(Phalcon_Db_Adapter, update){ phalcon_fetch_params(1, 3, 2, &table, &fields, &values, &where_condition, &data_types); if (!where_condition) { - PHALCON_INIT_VAR(where_condition); + where_condition = PHALCON_GLOBAL(z_null); } if (!data_types) { - PHALCON_INIT_VAR(data_types); + data_types = PHALCON_GLOBAL(z_null); } PHALCON_INIT_VAR(placeholders); @@ -690,15 +681,15 @@ PHP_METHOD(Phalcon_Db_Adapter, delete){ phalcon_fetch_params(1, 1, 3, &table, &where_condition, &placeholders, &data_types); if (!where_condition) { - PHALCON_INIT_VAR(where_condition); + where_condition = PHALCON_GLOBAL(z_null); } if (!placeholders) { - PHALCON_INIT_VAR(placeholders); + placeholders = PHALCON_GLOBAL(z_null); } if (!data_types) { - PHALCON_INIT_VAR(data_types); + data_types = PHALCON_GLOBAL(z_null); } if (PHALCON_GLOBAL(db).escape_identifiers) { @@ -707,11 +698,11 @@ PHP_METHOD(Phalcon_Db_Adapter, delete){ } else { PHALCON_CPY_WRT(escaped_table, table); } + + PHALCON_INIT_VAR(sql); if (PHALCON_IS_NOT_EMPTY(where_condition)) { - PHALCON_INIT_VAR(sql); PHALCON_CONCAT_SVSV(sql, "DELETE FROM ", escaped_table, " WHERE ", where_condition); } else { - PHALCON_INIT_NVAR(sql); PHALCON_CONCAT_SV(sql, "DELETE FROM ", escaped_table); } @@ -736,8 +727,7 @@ PHP_METHOD(Phalcon_Db_Adapter, getColumnList){ phalcon_fetch_params(1, 1, 0, &column_list); - PHALCON_OBS_VAR(dialect); - phalcon_read_property_this(&dialect, this_ptr, SL("_dialect"), PH_NOISY_CC); + dialect = phalcon_fetch_nproperty_this(this_ptr, SL("_dialect"), PH_NOISY_CC); phalcon_call_method_p1(return_value, dialect, "getcolumnlist", column_list); RETURN_MM(); } @@ -761,8 +751,7 @@ PHP_METHOD(Phalcon_Db_Adapter, limit){ phalcon_fetch_params(1, 2, 0, &sql_query, &number); - PHALCON_OBS_VAR(dialect); - phalcon_read_property_this(&dialect, this_ptr, SL("_dialect"), PH_NOISY_CC); + dialect = phalcon_fetch_nproperty_this(this_ptr, SL("_dialect"), PH_NOISY_CC); phalcon_call_method_p2(return_value, dialect, "limit", sql_query, number); RETURN_MM(); } @@ -788,11 +777,10 @@ PHP_METHOD(Phalcon_Db_Adapter, tableExists){ phalcon_fetch_params(1, 1, 1, &table_name, &schema_name); if (!schema_name) { - PHALCON_INIT_VAR(schema_name); + schema_name = PHALCON_GLOBAL(z_null); } - PHALCON_OBS_VAR(dialect); - phalcon_read_property_this(&dialect, this_ptr, SL("_dialect"), PH_NOISY_CC); + dialect = phalcon_fetch_nproperty_this(this_ptr, SL("_dialect"), PH_NOISY_CC); PHALCON_INIT_VAR(sql); phalcon_call_method_p2(sql, dialect, "tableexists", table_name, schema_name); @@ -829,11 +817,10 @@ PHP_METHOD(Phalcon_Db_Adapter, viewExists){ phalcon_fetch_params(1, 1, 1, &view_name, &schema_name); if (!schema_name) { - PHALCON_INIT_VAR(schema_name); + schema_name = PHALCON_GLOBAL(z_null); } - PHALCON_OBS_VAR(dialect); - phalcon_read_property_this(&dialect, this_ptr, SL("_dialect"), PH_NOISY_CC); + dialect = phalcon_fetch_nproperty_this(this_ptr, SL("_dialect"), PH_NOISY_CC); PHALCON_INIT_VAR(sql); phalcon_call_method_p2(sql, dialect, "viewexists", view_name, schema_name); @@ -863,8 +850,7 @@ PHP_METHOD(Phalcon_Db_Adapter, forUpdate){ phalcon_fetch_params(1, 1, 0, &sql_query); - PHALCON_OBS_VAR(dialect); - phalcon_read_property_this(&dialect, this_ptr, SL("_dialect"), PH_NOISY_CC); + dialect = phalcon_fetch_nproperty_this(this_ptr, SL("_dialect"), PH_NOISY_CC); phalcon_call_method_p1(return_value, dialect, "forupdate", sql_query); RETURN_MM(); } @@ -883,8 +869,7 @@ PHP_METHOD(Phalcon_Db_Adapter, sharedLock){ phalcon_fetch_params(1, 1, 0, &sql_query); - PHALCON_OBS_VAR(dialect); - phalcon_read_property_this(&dialect, this_ptr, SL("_dialect"), PH_NOISY_CC); + dialect = phalcon_fetch_nproperty_this(this_ptr, SL("_dialect"), PH_NOISY_CC); phalcon_call_method_p1(return_value, dialect, "sharedlock", sql_query); RETURN_MM(); } @@ -913,20 +898,18 @@ PHP_METHOD(Phalcon_Db_Adapter, createTable){ PHALCON_THROW_EXCEPTION_ZVAL(phalcon_db_exception_ce, exception_message); return; } - if (!phalcon_array_isset_string(definition, SS("columns"))) { + + if (!phalcon_array_isset_string_fetch(&columns, definition, SS("columns"))) { PHALCON_THROW_EXCEPTION_STR(phalcon_db_exception_ce, "The table must contain at least one column"); return; } - PHALCON_OBS_VAR(columns); - phalcon_array_fetch_string(&columns, definition, SL("columns"), PH_NOISY); if (!phalcon_fast_count_ev(columns TSRMLS_CC)) { PHALCON_THROW_EXCEPTION_STR(phalcon_db_exception_ce, "The table must contain at least one column"); return; } - PHALCON_OBS_VAR(dialect); - phalcon_read_property_this(&dialect, this_ptr, SL("_dialect"), PH_NOISY_CC); + dialect = phalcon_fetch_nproperty_this(this_ptr, SL("_dialect"), PH_NOISY_CC); PHALCON_INIT_VAR(sql); phalcon_call_method_p3(sql, dialect, "createtable", table_name, schema_name, definition); @@ -952,16 +935,14 @@ PHP_METHOD(Phalcon_Db_Adapter, dropTable){ phalcon_fetch_params(1, 1, 2, &table_name, &schema_name, &if_exists); if (!schema_name) { - PHALCON_INIT_VAR(schema_name); + schema_name = PHALCON_GLOBAL(z_null); } if (!if_exists) { - PHALCON_INIT_VAR(if_exists); - ZVAL_BOOL(if_exists, 1); + if_exists = PHALCON_GLOBAL(z_true); } - PHALCON_OBS_VAR(dialect); - phalcon_read_property_this(&dialect, this_ptr, SL("_dialect"), PH_NOISY_CC); + dialect = phalcon_fetch_nproperty_this(this_ptr, SL("_dialect"), PH_NOISY_CC); PHALCON_INIT_VAR(sql); phalcon_call_method_p3(sql, dialect, "droptable", table_name, schema_name, if_exists); @@ -987,7 +968,7 @@ PHP_METHOD(Phalcon_Db_Adapter, createView){ phalcon_fetch_params(1, 2, 1, &view_name, &definition, &schema_name); if (!schema_name) { - PHALCON_INIT_VAR(schema_name); + schema_name = PHALCON_GLOBAL(z_null); } if (Z_TYPE_P(definition) != IS_ARRAY) { @@ -996,13 +977,13 @@ PHP_METHOD(Phalcon_Db_Adapter, createView){ PHALCON_THROW_EXCEPTION_ZVAL(phalcon_db_exception_ce, exception_message); return; } + if (!phalcon_array_isset_string(definition, SS("sql"))) { PHALCON_THROW_EXCEPTION_STR(phalcon_db_exception_ce, "The table must contain at least one column"); return; } - PHALCON_OBS_VAR(dialect); - phalcon_read_property_this(&dialect, this_ptr, SL("_dialect"), PH_NOISY_CC); + dialect = phalcon_fetch_nproperty_this(this_ptr, SL("_dialect"), PH_NOISY_CC); PHALCON_INIT_VAR(sql); phalcon_call_method_p3(sql, dialect, "createview", view_name, definition, schema_name); @@ -1028,16 +1009,14 @@ PHP_METHOD(Phalcon_Db_Adapter, dropView){ phalcon_fetch_params(1, 1, 2, &view_name, &schema_name, &if_exists); if (!schema_name) { - PHALCON_INIT_VAR(schema_name); + schema_name = PHALCON_GLOBAL(z_null); } if (!if_exists) { - PHALCON_INIT_VAR(if_exists); - ZVAL_BOOL(if_exists, 1); + if_exists = PHALCON_GLOBAL(z_true); } - PHALCON_OBS_VAR(dialect); - phalcon_read_property_this(&dialect, this_ptr, SL("_dialect"), PH_NOISY_CC); + dialect = phalcon_fetch_nproperty_this(this_ptr, SL("_dialect"), PH_NOISY_CC); PHALCON_INIT_VAR(sql); phalcon_call_method_p3(sql, dialect, "dropview", view_name, schema_name, if_exists); @@ -1062,8 +1041,7 @@ PHP_METHOD(Phalcon_Db_Adapter, addColumn){ phalcon_fetch_params(1, 3, 0, &table_name, &schema_name, &column); - PHALCON_OBS_VAR(dialect); - phalcon_read_property_this(&dialect, this_ptr, SL("_dialect"), PH_NOISY_CC); + dialect = phalcon_fetch_nproperty_this(this_ptr, SL("_dialect"), PH_NOISY_CC); PHALCON_INIT_VAR(sql); phalcon_call_method_p3(sql, dialect, "addcolumn", table_name, schema_name, column); @@ -1088,8 +1066,7 @@ PHP_METHOD(Phalcon_Db_Adapter, modifyColumn){ phalcon_fetch_params(1, 3, 0, &table_name, &schema_name, &column); - PHALCON_OBS_VAR(dialect); - phalcon_read_property_this(&dialect, this_ptr, SL("_dialect"), PH_NOISY_CC); + dialect = phalcon_fetch_nproperty_this(this_ptr, SL("_dialect"), PH_NOISY_CC); PHALCON_INIT_VAR(sql); phalcon_call_method_p3(sql, dialect, "modifycolumn", table_name, schema_name, column); @@ -1114,8 +1091,7 @@ PHP_METHOD(Phalcon_Db_Adapter, dropColumn){ phalcon_fetch_params(1, 3, 0, &table_name, &schema_name, &column_name); - PHALCON_OBS_VAR(dialect); - phalcon_read_property_this(&dialect, this_ptr, SL("_dialect"), PH_NOISY_CC); + dialect = phalcon_fetch_nproperty_this(this_ptr, SL("_dialect"), PH_NOISY_CC); PHALCON_INIT_VAR(sql); phalcon_call_method_p3(sql, dialect, "dropcolumn", table_name, schema_name, column_name); @@ -1140,8 +1116,7 @@ PHP_METHOD(Phalcon_Db_Adapter, addIndex){ phalcon_fetch_params(1, 3, 0, &table_name, &schema_name, &index); - PHALCON_OBS_VAR(dialect); - phalcon_read_property_this(&dialect, this_ptr, SL("_dialect"), PH_NOISY_CC); + dialect = phalcon_fetch_nproperty_this(this_ptr, SL("_dialect"), PH_NOISY_CC); PHALCON_INIT_VAR(sql); phalcon_call_method_p3(sql, dialect, "addindex", table_name, schema_name, index); @@ -1166,8 +1141,7 @@ PHP_METHOD(Phalcon_Db_Adapter, dropIndex){ phalcon_fetch_params(1, 3, 0, &table_name, &schema_name, &index_name); - PHALCON_OBS_VAR(dialect); - phalcon_read_property_this(&dialect, this_ptr, SL("_dialect"), PH_NOISY_CC); + dialect = phalcon_fetch_nproperty_this(this_ptr, SL("_dialect"), PH_NOISY_CC); PHALCON_INIT_VAR(sql); phalcon_call_method_p3(sql, dialect, "dropindex", table_name, schema_name, index_name); @@ -1192,8 +1166,7 @@ PHP_METHOD(Phalcon_Db_Adapter, addPrimaryKey){ phalcon_fetch_params(1, 3, 0, &table_name, &schema_name, &index); - PHALCON_OBS_VAR(dialect); - phalcon_read_property_this(&dialect, this_ptr, SL("_dialect"), PH_NOISY_CC); + dialect = phalcon_fetch_nproperty_this(this_ptr, SL("_dialect"), PH_NOISY_CC); PHALCON_INIT_VAR(sql); phalcon_call_method_p3(sql, dialect, "addprimarykey", table_name, schema_name, index); @@ -1216,8 +1189,7 @@ PHP_METHOD(Phalcon_Db_Adapter, dropPrimaryKey){ phalcon_fetch_params(1, 2, 0, &table_name, &schema_name); - PHALCON_OBS_VAR(dialect); - phalcon_read_property_this(&dialect, this_ptr, SL("_dialect"), PH_NOISY_CC); + dialect = phalcon_fetch_nproperty_this(this_ptr, SL("_dialect"), PH_NOISY_CC); PHALCON_INIT_VAR(sql); phalcon_call_method_p2(sql, dialect, "dropprimarykey", table_name, schema_name); @@ -1242,8 +1214,7 @@ PHP_METHOD(Phalcon_Db_Adapter, addForeignKey){ phalcon_fetch_params(1, 3, 0, &table_name, &schema_name, &reference); - PHALCON_OBS_VAR(dialect); - phalcon_read_property_this(&dialect, this_ptr, SL("_dialect"), PH_NOISY_CC); + dialect = phalcon_fetch_nproperty_this(this_ptr, SL("_dialect"), PH_NOISY_CC); PHALCON_INIT_VAR(sql); phalcon_call_method_p3(sql, dialect, "addforeignkey", table_name, schema_name, reference); @@ -1268,8 +1239,7 @@ PHP_METHOD(Phalcon_Db_Adapter, dropForeignKey){ phalcon_fetch_params(1, 3, 0, &table_name, &schema_name, &reference_name); - PHALCON_OBS_VAR(dialect); - phalcon_read_property_this(&dialect, this_ptr, SL("_dialect"), PH_NOISY_CC); + dialect = phalcon_fetch_nproperty_this(this_ptr, SL("_dialect"), PH_NOISY_CC); PHALCON_INIT_VAR(sql); phalcon_call_method_p3(sql, dialect, "dropforeignkey", table_name, schema_name, reference_name); @@ -1291,8 +1261,7 @@ PHP_METHOD(Phalcon_Db_Adapter, getColumnDefinition){ phalcon_fetch_params(1, 1, 0, &column); - PHALCON_OBS_VAR(dialect); - phalcon_read_property_this(&dialect, this_ptr, SL("_dialect"), PH_NOISY_CC); + dialect = phalcon_fetch_nproperty_this(this_ptr, SL("_dialect"), PH_NOISY_CC); phalcon_call_method_p1(return_value, dialect, "getcolumndefinition", column); RETURN_MM(); } @@ -1310,7 +1279,7 @@ PHP_METHOD(Phalcon_Db_Adapter, getColumnDefinition){ PHP_METHOD(Phalcon_Db_Adapter, listTables){ zval *schema_name = NULL, *dialect, *sql, *fetch_num, *tables; - zval *all_tables, *table = NULL, *table_name = NULL; + zval *table = NULL, *table_name = NULL; HashTable *ah0; HashPosition hp0; zval **hd; @@ -1320,11 +1289,10 @@ PHP_METHOD(Phalcon_Db_Adapter, listTables){ phalcon_fetch_params(1, 0, 1, &schema_name); if (!schema_name) { - PHALCON_INIT_VAR(schema_name); + schema_name = PHALCON_GLOBAL(z_null); } - PHALCON_OBS_VAR(dialect); - phalcon_read_property_this(&dialect, this_ptr, SL("_dialect"), PH_NOISY_CC); + dialect = phalcon_fetch_nproperty_this(this_ptr, SL("_dialect"), PH_NOISY_CC); /** * Get the SQL to list the tables @@ -1344,8 +1312,7 @@ PHP_METHOD(Phalcon_Db_Adapter, listTables){ PHALCON_INIT_VAR(tables); phalcon_call_method_p2(tables, this_ptr, "fetchall", sql, fetch_num); - PHALCON_INIT_VAR(all_tables); - array_init(all_tables); + array_init(return_value); phalcon_is_iterable(tables, &ah0, &hp0, 0, 0); @@ -1355,12 +1322,12 @@ PHP_METHOD(Phalcon_Db_Adapter, listTables){ PHALCON_OBS_NVAR(table_name); phalcon_array_fetch_long(&table_name, table, 0, PH_NOISY); - phalcon_array_append(&all_tables, table_name, PH_SEPARATE); + phalcon_array_append(&return_value, table_name, PH_SEPARATE); zend_hash_move_forward_ex(ah0, &hp0); } - RETURN_CTOR(all_tables); + PHALCON_MM_RESTORE(); } /** @@ -1376,7 +1343,7 @@ PHP_METHOD(Phalcon_Db_Adapter, listTables){ PHP_METHOD(Phalcon_Db_Adapter, listViews){ zval *schema_name = NULL, *dialect, *sql, *fetch_num, *tables; - zval *all_tables, *table = NULL, *table_name = NULL; + zval *table = NULL, *table_name = NULL; HashTable *ah0; HashPosition hp0; zval **hd; @@ -1386,11 +1353,10 @@ PHP_METHOD(Phalcon_Db_Adapter, listViews){ phalcon_fetch_params(1, 0, 1, &schema_name); if (!schema_name) { - PHALCON_INIT_VAR(schema_name); + schema_name = PHALCON_GLOBAL(z_null); } - PHALCON_OBS_VAR(dialect); - phalcon_read_property_this(&dialect, this_ptr, SL("_dialect"), PH_NOISY_CC); + dialect = phalcon_fetch_nproperty_this(this_ptr, SL("_dialect"), PH_NOISY_CC); /** * Get the SQL to list the tables @@ -1410,8 +1376,7 @@ PHP_METHOD(Phalcon_Db_Adapter, listViews){ PHALCON_INIT_VAR(tables); phalcon_call_method_p2(tables, this_ptr, "fetchall", sql, fetch_num); - PHALCON_INIT_VAR(all_tables); - array_init(all_tables); + array_init(return_value); phalcon_is_iterable(tables, &ah0, &hp0, 0, 0); @@ -1421,12 +1386,12 @@ PHP_METHOD(Phalcon_Db_Adapter, listViews){ PHALCON_OBS_NVAR(table_name); phalcon_array_fetch_long(&table_name, table, 0, PH_NOISY); - phalcon_array_append(&all_tables, table_name, PH_SEPARATE); + phalcon_array_append(&return_value, table_name, PH_SEPARATE); zend_hash_move_forward_ex(ah0, &hp0); } - RETURN_CTOR(all_tables); + PHALCON_MM_RESTORE(); } /** @@ -1444,7 +1409,7 @@ PHP_METHOD(Phalcon_Db_Adapter, describeIndexes){ zval *table, *schema = NULL, *dialect, *fetch_num, *sql, *describe; zval *indexes, *index = NULL, *key_name = NULL, *empty_arr = NULL, *column_name = NULL; - zval *index_objects, *index_columns = NULL, *name = NULL; + zval *index_columns = NULL, *name = NULL; HashTable *ah0, *ah1; HashPosition hp0, hp1; zval **hd; @@ -1454,11 +1419,10 @@ PHP_METHOD(Phalcon_Db_Adapter, describeIndexes){ phalcon_fetch_params(1, 1, 1, &table, &schema); if (!schema) { - PHALCON_INIT_VAR(schema); + schema = PHALCON_GLOBAL(z_null); } - PHALCON_OBS_VAR(dialect); - phalcon_read_property_this(&dialect, this_ptr, SL("_dialect"), PH_NOISY_CC); + dialect = phalcon_fetch_nproperty_this(this_ptr, SL("_dialect"), PH_NOISY_CC); /** * We're using FETCH_NUM to fetch the columns @@ -1502,8 +1466,7 @@ PHP_METHOD(Phalcon_Db_Adapter, describeIndexes){ zend_hash_move_forward_ex(ah0, &hp0); } - PHALCON_INIT_VAR(index_objects); - array_init(index_objects); + array_init(return_value); phalcon_is_iterable(indexes, &ah1, &hp1, 0, 0); @@ -1519,12 +1482,12 @@ PHP_METHOD(Phalcon_Db_Adapter, describeIndexes){ object_init_ex(index, phalcon_db_index_ce); phalcon_call_method_p2_noret(index, "__construct", name, index_columns); - phalcon_array_update_zval(&index_objects, name, &index, PH_COPY | PH_SEPARATE); + phalcon_array_update_zval(&return_value, name, &index, PH_COPY | PH_SEPARATE); zend_hash_move_forward_ex(ah1, &hp1); } - RETURN_CTOR(index_objects); + PHALCON_MM_RESTORE(); } /** @@ -1544,7 +1507,7 @@ PHP_METHOD(Phalcon_Db_Adapter, describeReferences){ zval *references, *describe, *reference = NULL, *constraint_name = NULL; zval *referenced_schema = NULL, *referenced_table = NULL; zval *reference_array = NULL, *column_name = NULL, *referenced_columns = NULL; - zval *reference_objects, *array_reference = NULL; + zval *array_reference = NULL; zval *name = NULL, *columns = NULL, *definition = NULL; HashTable *ah0, *ah1; HashPosition hp0, hp1; @@ -1555,11 +1518,10 @@ PHP_METHOD(Phalcon_Db_Adapter, describeReferences){ phalcon_fetch_params(1, 1, 1, &table, &schema); if (!schema) { - PHALCON_INIT_VAR(schema); + schema = PHALCON_GLOBAL(z_null); } - PHALCON_OBS_VAR(dialect); - phalcon_read_property_this(&dialect, this_ptr, SL("_dialect"), PH_NOISY_CC); + dialect = phalcon_fetch_nproperty_this(this_ptr, SL("_dialect"), PH_NOISY_CC); /** * We're using FETCH_NUM to fetch the columns @@ -1602,11 +1564,11 @@ PHP_METHOD(Phalcon_Db_Adapter, describeReferences){ PHALCON_INIT_NVAR(reference_array); array_init_size(reference_array, 4); - phalcon_array_update_string(&reference_array, SL("referencedSchema"), &referenced_schema, PH_COPY | PH_SEPARATE); - phalcon_array_update_string(&reference_array, SL("referencedTable"), &referenced_table, PH_COPY | PH_SEPARATE); - phalcon_array_update_string(&reference_array, SL("columns"), &empty_arr, PH_COPY | PH_SEPARATE); - phalcon_array_update_string(&reference_array, SL("referencedColumns"), &empty_arr, PH_COPY | PH_SEPARATE); - phalcon_array_update_zval(&references, constraint_name, &reference_array, PH_COPY | PH_SEPARATE); + phalcon_array_update_string(&reference_array, SL("referencedSchema"), &referenced_schema, PH_COPY); + phalcon_array_update_string(&reference_array, SL("referencedTable"), &referenced_table, PH_COPY); + phalcon_array_update_string(&reference_array, SL("columns"), &empty_arr, PH_COPY); + phalcon_array_update_string(&reference_array, SL("referencedColumns"), &empty_arr, PH_COPY); + phalcon_array_update_zval(&references, constraint_name, &reference_array, PH_COPY); } PHALCON_OBS_NVAR(column_name); @@ -1620,8 +1582,7 @@ PHP_METHOD(Phalcon_Db_Adapter, describeReferences){ zend_hash_move_forward_ex(ah0, &hp0); } - PHALCON_INIT_VAR(reference_objects); - array_init(reference_objects); + array_init(return_value); phalcon_is_iterable(references, &ah1, &hp1, 0, 0); @@ -1644,21 +1605,21 @@ PHP_METHOD(Phalcon_Db_Adapter, describeReferences){ PHALCON_INIT_NVAR(definition); array_init_size(definition, 4); - phalcon_array_update_string(&definition, SL("referencedSchema"), &referenced_schema, PH_COPY | PH_SEPARATE); - phalcon_array_update_string(&definition, SL("referencedTable"), &referenced_table, PH_COPY | PH_SEPARATE); - phalcon_array_update_string(&definition, SL("columns"), &columns, PH_COPY | PH_SEPARATE); - phalcon_array_update_string(&definition, SL("referencedColumns"), &referenced_columns, PH_COPY | PH_SEPARATE); + phalcon_array_update_string(&definition, SL("referencedSchema"), &referenced_schema, PH_COPY); + phalcon_array_update_string(&definition, SL("referencedTable"), &referenced_table, PH_COPY); + phalcon_array_update_string(&definition, SL("columns"), &columns, PH_COPY ); + phalcon_array_update_string(&definition, SL("referencedColumns"), &referenced_columns, PH_COPY); PHALCON_INIT_NVAR(reference); object_init_ex(reference, phalcon_db_reference_ce); phalcon_call_method_p2_noret(reference, "__construct", name, definition); - phalcon_array_update_zval(&reference_objects, name, &reference, PH_COPY | PH_SEPARATE); + phalcon_array_update_zval(&return_value, name, &reference, PH_COPY); zend_hash_move_forward_ex(ah1, &hp1); } - RETURN_CTOR(reference_objects); + PHALCON_MM_RESTORE(); } /** @@ -1682,11 +1643,10 @@ PHP_METHOD(Phalcon_Db_Adapter, tableOptions){ phalcon_fetch_params(1, 1, 1, &table_name, &schema_name); if (!schema_name) { - PHALCON_INIT_VAR(schema_name); + schema_name = PHALCON_GLOBAL(z_null); } - PHALCON_OBS_VAR(dialect); - phalcon_read_property_this(&dialect, this_ptr, SL("_dialect"), PH_NOISY_CC); + dialect = phalcon_fetch_nproperty_this(this_ptr, SL("_dialect"), PH_NOISY_CC); PHALCON_INIT_VAR(sql); phalcon_call_method_p2(sql, dialect, "tableoptions", table_name, schema_name); @@ -1719,8 +1679,7 @@ PHP_METHOD(Phalcon_Db_Adapter, createSavepoint){ phalcon_fetch_params(1, 1, 0, &name); - PHALCON_OBS_VAR(dialect); - phalcon_read_property_this(&dialect, this_ptr, SL("_dialect"), PH_NOISY_CC); + dialect = phalcon_fetch_nproperty_this(this_ptr, SL("_dialect"), PH_NOISY_CC); PHALCON_INIT_VAR(supports_sp); phalcon_call_method(supports_sp, dialect, "supportssavepoints"); @@ -1750,8 +1709,7 @@ PHP_METHOD(Phalcon_Db_Adapter, releaseSavepoint){ phalcon_fetch_params(1, 1, 0, &name); - PHALCON_OBS_VAR(dialect); - phalcon_read_property_this(&dialect, this_ptr, SL("_dialect"), PH_NOISY_CC); + dialect = phalcon_fetch_nproperty_this(this_ptr, SL("_dialect"), PH_NOISY_CC); PHALCON_INIT_VAR(supports_sp); phalcon_call_method(supports_sp, dialect, "supportssavepoints"); @@ -1786,8 +1744,7 @@ PHP_METHOD(Phalcon_Db_Adapter, rollbackSavepoint){ phalcon_fetch_params(1, 1, 0, &name); - PHALCON_OBS_VAR(dialect); - phalcon_read_property_this(&dialect, this_ptr, SL("_dialect"), PH_NOISY_CC); + dialect = phalcon_fetch_nproperty_this(this_ptr, SL("_dialect"), PH_NOISY_CC); PHALCON_INIT_VAR(supports_sp); phalcon_call_method(supports_sp, dialect, "supportssavepoints"); @@ -1817,15 +1774,13 @@ PHP_METHOD(Phalcon_Db_Adapter, setNestedTransactionsWithSavepoints){ phalcon_fetch_params(1, 1, 0, &nested_transactions_with_savepoints); - PHALCON_OBS_VAR(transaction_level); - phalcon_read_property_this(&transaction_level, this_ptr, SL("_transactionLevel"), PH_NOISY_CC); + transaction_level = phalcon_fetch_nproperty_this(this_ptr, SL("_transactionLevel"), PH_NOISY_CC); if (PHALCON_GT_LONG(transaction_level, 0)) { PHALCON_THROW_EXCEPTION_STR(phalcon_db_exception_ce, "Nested transaction with savepoints behavior cannot be changed while a transaction is open"); return; } - PHALCON_OBS_VAR(dialect); - phalcon_read_property_this(&dialect, this_ptr, SL("_dialect"), PH_NOISY_CC); + dialect = phalcon_fetch_nproperty_this(this_ptr, SL("_dialect"), PH_NOISY_CC); PHALCON_INIT_VAR(supports_sp); phalcon_call_method(supports_sp, dialect, "supportssavepoints"); @@ -1859,12 +1814,8 @@ PHP_METHOD(Phalcon_Db_Adapter, getNestedTransactionSavepointName){ zval *transaction_level; - PHALCON_MM_GROW(); - - PHALCON_OBS_VAR(transaction_level); - phalcon_read_property_this(&transaction_level, this_ptr, SL("_transactionLevel"), PH_NOISY_CC); + transaction_level = phalcon_fetch_nproperty_this(this_ptr, SL("_transactionLevel"), PH_NOISY_CC); PHALCON_CONCAT_SV(return_value, "PHALCON_SAVEPOINT_", transaction_level); - RETURN_MM(); } /** diff --git a/ext/db/adapter/pdo.c b/ext/db/adapter/pdo.c index da53f7a8671..204ffff8609 100644 --- a/ext/db/adapter/pdo.c +++ b/ext/db/adapter/pdo.c @@ -264,8 +264,7 @@ PHP_METHOD(Phalcon_Db_Adapter_Pdo, prepare){ phalcon_fetch_params(1, 1, 0, &sql_statement); - PHALCON_OBS_VAR(pdo); - phalcon_read_property_this(&pdo, this_ptr, SL("_pdo"), PH_NOISY_CC); + pdo = phalcon_fetch_nproperty_this(this_ptr, SL("_pdo"), PH_NOISY_CC); phalcon_call_method_p1(return_value, pdo, "prepare", sql_statement); RETURN_MM(); } @@ -401,11 +400,11 @@ PHP_METHOD(Phalcon_Db_Adapter_Pdo, query){ phalcon_fetch_params(1, 1, 2, &sql_statement, &bind_params, &bind_types); if (!bind_params) { - PHALCON_INIT_VAR(bind_params); + bind_params = PHALCON_GLOBAL(z_null); } if (!bind_types) { - PHALCON_INIT_VAR(bind_types); + bind_types = PHALCON_GLOBAL(z_null); } PHALCON_OBS_VAR(events_manager); @@ -429,8 +428,7 @@ PHP_METHOD(Phalcon_Db_Adapter_Pdo, query){ } } - PHALCON_OBS_VAR(pdo); - phalcon_read_property_this(&pdo, this_ptr, SL("_pdo"), PH_NOISY_CC); + pdo = phalcon_fetch_nproperty_this(this_ptr, SL("_pdo"), PH_NOISY_CC); if (Z_TYPE_P(bind_params) == IS_ARRAY) { PHALCON_INIT_VAR(statement); @@ -489,11 +487,11 @@ PHP_METHOD(Phalcon_Db_Adapter_Pdo, execute){ phalcon_fetch_params(1, 1, 2, &sql_statement, &bind_params, &bind_types); if (!bind_params) { - PHALCON_INIT_VAR(bind_params); + bind_params = PHALCON_GLOBAL(z_null); } if (!bind_types) { - PHALCON_INIT_VAR(bind_types); + bind_types = PHALCON_GLOBAL(z_null); } /** @@ -522,8 +520,7 @@ PHP_METHOD(Phalcon_Db_Adapter_Pdo, execute){ PHALCON_INIT_VAR(affected_rows); ZVAL_LONG(affected_rows, 0); - PHALCON_OBS_VAR(pdo); - phalcon_read_property_this(&pdo, this_ptr, SL("_pdo"), PH_NOISY_CC); + pdo = phalcon_fetch_nproperty_this(this_ptr, SL("_pdo"), PH_NOISY_CC); if (Z_TYPE_P(bind_params) == IS_ARRAY) { PHALCON_INIT_VAR(statement); @@ -580,16 +577,13 @@ PHP_METHOD(Phalcon_Db_Adapter_Pdo, close){ zval *pdo; - PHALCON_MM_GROW(); - - PHALCON_OBS_VAR(pdo); - phalcon_read_property_this(&pdo, this_ptr, SL("_pdo"), PH_NOISY_CC); + pdo = phalcon_fetch_nproperty_this(this_ptr, SL("_pdo"), PH_NOISY_CC); if (likely(Z_TYPE_P(pdo) == IS_OBJECT)) { - phalcon_update_property_null(this_ptr, SL("_pdo") TSRMLS_CC); - RETURN_MM_TRUE; + phalcon_update_property_this(this_ptr, SL("_pdo"), PHALCON_GLOBAL(z_null) TSRMLS_CC); + RETURN_TRUE; } - RETURN_MM_TRUE; + RETURN_FALSE; } /** @@ -643,8 +637,7 @@ PHP_METHOD(Phalcon_Db_Adapter_Pdo, escapeString){ phalcon_fetch_params(1, 1, 0, &str); - PHALCON_OBS_VAR(pdo); - phalcon_read_property_this(&pdo, this_ptr, SL("_pdo"), PH_NOISY_CC); + pdo = phalcon_fetch_nproperty_this(this_ptr, SL("_pdo"), PH_NOISY_CC); phalcon_call_method_p1(return_value, pdo, "quote", str); RETURN_MM(); } @@ -774,11 +767,10 @@ PHP_METHOD(Phalcon_Db_Adapter_Pdo, lastInsertId){ phalcon_fetch_params(1, 0, 1, &sequence_name); if (!sequence_name) { - PHALCON_INIT_VAR(sequence_name); + sequence_name = PHALCON_GLOBAL(z_null); } - PHALCON_OBS_VAR(pdo); - phalcon_read_property_this(&pdo, this_ptr, SL("_pdo"), PH_NOISY_CC); + pdo = phalcon_fetch_nproperty_this(this_ptr, SL("_pdo"), PH_NOISY_CC); if (Z_TYPE_P(pdo) != IS_OBJECT) { RETURN_MM_FALSE; } @@ -803,12 +795,10 @@ PHP_METHOD(Phalcon_Db_Adapter_Pdo, begin){ phalcon_fetch_params(1, 0, 1, &nesting); if (!nesting) { - PHALCON_INIT_VAR(nesting); - ZVAL_BOOL(nesting, 1); + nesting = PHALCON_GLOBAL(z_true); } - PHALCON_OBS_VAR(pdo); - phalcon_read_property_this(&pdo, this_ptr, SL("_pdo"), PH_NOISY_CC); + pdo = phalcon_fetch_nproperty_this(this_ptr, SL("_pdo"), PH_NOISY_CC); if (Z_TYPE_P(pdo) != IS_OBJECT) { RETURN_MM_FALSE; } @@ -821,12 +811,10 @@ PHP_METHOD(Phalcon_Db_Adapter_Pdo, begin){ /** * Check the transaction nesting level */ - PHALCON_OBS_VAR(transaction_level); - phalcon_read_property_this(&transaction_level, this_ptr, SL("_transactionLevel"), PH_NOISY_CC); + transaction_level = phalcon_fetch_nproperty_this(this_ptr, SL("_transactionLevel"), PH_NOISY_CC); if (PHALCON_IS_LONG(transaction_level, 1)) { - PHALCON_OBS_VAR(events_manager); - phalcon_read_property_this(&events_manager, this_ptr, SL("_eventsManager"), PH_NOISY_CC); + events_manager = phalcon_fetch_nproperty_this(this_ptr, SL("_eventsManager"), PH_NOISY_CC); /** * Notify the events manager about the started transaction @@ -847,8 +835,7 @@ PHP_METHOD(Phalcon_Db_Adapter_Pdo, begin){ phalcon_call_method(ntw_savepoint, this_ptr, "isnestedtransactionswithsavepoints"); if (zend_is_true(ntw_savepoint)) { - PHALCON_OBS_NVAR(events_manager); - phalcon_read_property_this(&events_manager, this_ptr, SL("_eventsManager"), PH_NOISY_CC); + events_manager = phalcon_fetch_nproperty_this(this_ptr, SL("_eventsManager"), PH_NOISY_CC); PHALCON_INIT_VAR(savepoint_name); phalcon_call_method(savepoint_name, this_ptr, "getnestedtransactionsavepointname"); @@ -888,12 +875,10 @@ PHP_METHOD(Phalcon_Db_Adapter_Pdo, rollback){ phalcon_fetch_params(1, 0, 1, &nesting); if (!nesting) { - PHALCON_INIT_VAR(nesting); - ZVAL_BOOL(nesting, 1); + nesting = PHALCON_GLOBAL(z_true); } - PHALCON_OBS_VAR(pdo); - phalcon_read_property_this(&pdo, this_ptr, SL("_pdo"), PH_NOISY_CC); + pdo = phalcon_fetch_nproperty_this(this_ptr, SL("_pdo"), PH_NOISY_CC); if (Z_TYPE_P(pdo) != IS_OBJECT) { RETURN_MM_FALSE; } @@ -901,17 +886,14 @@ PHP_METHOD(Phalcon_Db_Adapter_Pdo, rollback){ /** * Check the transaction nesting level */ - PHALCON_OBS_VAR(transaction_level); - phalcon_read_property_this(&transaction_level, this_ptr, SL("_transactionLevel"), PH_NOISY_CC); + transaction_level = phalcon_fetch_nproperty_this(this_ptr, SL("_transactionLevel"), PH_NOISY_CC); if (!zend_is_true(transaction_level)) { PHALCON_THROW_EXCEPTION_STR(phalcon_db_exception_ce, "There is no active transaction"); return; } if (PHALCON_IS_LONG(transaction_level, 1)) { - - PHALCON_OBS_VAR(events_manager); - phalcon_read_property_this(&events_manager, this_ptr, SL("_eventsManager"), PH_NOISY_CC); + events_manager = phalcon_fetch_nproperty_this(this_ptr, SL("_eventsManager"), PH_NOISY_CC); /** * Notify the events manager about the rollbacked transaction @@ -936,8 +918,7 @@ PHP_METHOD(Phalcon_Db_Adapter_Pdo, rollback){ phalcon_call_method(ntw_savepoint, this_ptr, "isnestedtransactionswithsavepoints"); if (zend_is_true(ntw_savepoint)) { - PHALCON_OBS_NVAR(events_manager); - phalcon_read_property_this(&events_manager, this_ptr, SL("_eventsManager"), PH_NOISY_CC); + events_manager = phalcon_fetch_nproperty_this(this_ptr, SL("_eventsManager"), PH_NOISY_CC); PHALCON_INIT_VAR(savepoint_name); phalcon_call_method(savepoint_name, this_ptr, "getnestedtransactionsavepointname"); @@ -988,12 +969,10 @@ PHP_METHOD(Phalcon_Db_Adapter_Pdo, commit){ phalcon_fetch_params(1, 0, 1, &nesting); if (!nesting) { - PHALCON_INIT_VAR(nesting); - ZVAL_BOOL(nesting, 1); + nesting = PHALCON_GLOBAL(z_true); } - PHALCON_OBS_VAR(pdo); - phalcon_read_property_this(&pdo, this_ptr, SL("_pdo"), PH_NOISY_CC); + pdo = phalcon_fetch_nproperty_this(this_ptr, SL("_pdo"), PH_NOISY_CC); if (Z_TYPE_P(pdo) != IS_OBJECT) { RETURN_MM_FALSE; } @@ -1001,17 +980,14 @@ PHP_METHOD(Phalcon_Db_Adapter_Pdo, commit){ /** * Check the transaction nesting level */ - PHALCON_OBS_VAR(transaction_level); - phalcon_read_property_this(&transaction_level, this_ptr, SL("_transactionLevel"), PH_NOISY_CC); + transaction_level = phalcon_fetch_nproperty_this(this_ptr, SL("_transactionLevel"), PH_NOISY_CC); if (!zend_is_true(transaction_level)) { PHALCON_THROW_EXCEPTION_STR(phalcon_db_exception_ce, "There is no active transaction"); return; } if (PHALCON_IS_LONG(transaction_level, 1)) { - - PHALCON_OBS_VAR(events_manager); - phalcon_read_property_this(&events_manager, this_ptr, SL("_eventsManager"), PH_NOISY_CC); + events_manager = phalcon_fetch_nproperty_this(this_ptr, SL("_eventsManager"), PH_NOISY_CC); /** * Notify the events manager about the commited transaction @@ -1038,9 +1014,7 @@ PHP_METHOD(Phalcon_Db_Adapter_Pdo, commit){ PHALCON_INIT_VAR(ntw_savepoint); phalcon_call_method(ntw_savepoint, this_ptr, "isnestedtransactionswithsavepoints"); if (zend_is_true(ntw_savepoint)) { - - PHALCON_OBS_NVAR(events_manager); - phalcon_read_property_this(&events_manager, this_ptr, SL("_eventsManager"), PH_NOISY_CC); + events_manager = phalcon_fetch_nproperty_this(this_ptr, SL("_eventsManager"), PH_NOISY_CC); PHALCON_INIT_VAR(savepoint_name); phalcon_call_method(savepoint_name, this_ptr, "getnestedtransactionsavepointname"); @@ -1102,8 +1076,7 @@ PHP_METHOD(Phalcon_Db_Adapter_Pdo, isUnderTransaction){ PHALCON_MM_GROW(); - PHALCON_OBS_VAR(pdo); - phalcon_read_property_this(&pdo, this_ptr, SL("_pdo"), PH_NOISY_CC); + pdo = phalcon_fetch_nproperty_this(this_ptr, SL("_pdo"), PH_NOISY_CC); if (likely(Z_TYPE_P(pdo) == IS_OBJECT)) { phalcon_call_method(return_value, pdo, "intransaction"); RETURN_MM(); @@ -1121,10 +1094,6 @@ PHP_METHOD(Phalcon_Db_Adapter_Pdo, getInternalHandler){ zval *pdo; - PHALCON_MM_GROW(); - - PHALCON_OBS_VAR(pdo); - phalcon_read_property_this(&pdo, this_ptr, SL("_pdo"), PH_NOISY_CC); - RETURN_CCTOR(pdo); + pdo = phalcon_fetch_nproperty_this(this_ptr, SL("_pdo"), PH_NOISY_CC); + RETURN_ZVAL(pdo, 1, 0); } - diff --git a/ext/db/adapter/pdo/mysql.c b/ext/db/adapter/pdo/mysql.c index d46d496de3f..5446ae976a8 100644 --- a/ext/db/adapter/pdo/mysql.c +++ b/ext/db/adapter/pdo/mysql.c @@ -126,7 +126,7 @@ PHP_METHOD(Phalcon_Db_Adapter_Pdo_Mysql, escapeIdentifier){ */ PHP_METHOD(Phalcon_Db_Adapter_Pdo_Mysql, describeColumns){ - zval *table, *schema = NULL, *dialect, *ztrue, *sql, *fetch_num; + zval *table, *schema = NULL, *dialect, *sql, *fetch_num; zval *describe, *old_column = NULL, *size_pattern, *columns; zval *field = NULL, *definition = NULL, *column_type = NULL, *matches = NULL; zval *pos = NULL, *match_one = NULL, *match_two = NULL, *attribute = NULL, *column_name = NULL; @@ -140,15 +140,12 @@ PHP_METHOD(Phalcon_Db_Adapter_Pdo_Mysql, describeColumns){ phalcon_fetch_params(1, 1, 1, &table, &schema); if (!schema) { - PHALCON_INIT_VAR(schema); + schema = PHALCON_GLOBAL(z_null); } PHALCON_OBS_VAR(dialect); phalcon_read_property_this(&dialect, this_ptr, SL("_dialect"), PH_NOISY_CC); - PHALCON_INIT_VAR(ztrue); - ZVAL_BOOL(ztrue, 1); - /** * Get the SQL to describe a table */ @@ -212,7 +209,7 @@ PHP_METHOD(Phalcon_Db_Adapter_Pdo_Mysql, describeColumns){ */ if (phalcon_memnstr_str(column_type, SL("int"))) { phalcon_array_update_string_long(&definition, SL("type"), 0, PH_SEPARATE); - phalcon_array_update_string(&definition, SL("isNumeric"), &ztrue, PH_COPY | PH_SEPARATE); + phalcon_array_update_string(&definition, SL("isNumeric"), &PHALCON_GLOBAL(z_true), PH_COPY | PH_SEPARATE); phalcon_array_update_string_long(&definition, SL("bindType"), 1, PH_SEPARATE); break; } @@ -238,7 +235,7 @@ PHP_METHOD(Phalcon_Db_Adapter_Pdo_Mysql, describeColumns){ */ if (phalcon_memnstr_str(column_type, SL("decimal"))) { phalcon_array_update_string_long(&definition, SL("type"), 3, PH_SEPARATE); - phalcon_array_update_string(&definition, SL("isNumeric"), &ztrue, PH_COPY | PH_SEPARATE); + phalcon_array_update_string(&definition, SL("isNumeric"), &PHALCON_GLOBAL(z_true), PH_COPY | PH_SEPARATE); phalcon_array_update_string_long(&definition, SL("bindType"), 32, PH_SEPARATE); break; } @@ -272,7 +269,7 @@ PHP_METHOD(Phalcon_Db_Adapter_Pdo_Mysql, describeColumns){ */ if (phalcon_memnstr_str(column_type, SL("float"))) { phalcon_array_update_string_long(&definition, SL("type"), 7, PH_SEPARATE); - phalcon_array_update_string(&definition, SL("isNumeric"), &ztrue, PH_COPY | PH_SEPARATE); + phalcon_array_update_string(&definition, SL("isNumeric"), &PHALCON_GLOBAL(z_true), PH_COPY | PH_SEPARATE); phalcon_array_update_string_long(&definition, SL("bindType"), 32, PH_SEPARATE); break; } @@ -282,7 +279,7 @@ PHP_METHOD(Phalcon_Db_Adapter_Pdo_Mysql, describeColumns){ */ if (phalcon_memnstr_str(column_type, SL("double"))) { phalcon_array_update_string_long(&definition, SL("type"), 9, PH_SEPARATE); - phalcon_array_update_string(&definition, SL("isNumeric"), &ztrue, PH_COPY | PH_SEPARATE); + phalcon_array_update_string(&definition, SL("isNumeric"), &PHALCON_GLOBAL(z_true), PH_COPY | PH_SEPARATE); phalcon_array_update_string_long(&definition, SL("bindType"), 32, PH_SEPARATE); break; } @@ -322,14 +319,14 @@ PHP_METHOD(Phalcon_Db_Adapter_Pdo_Mysql, describeColumns){ * Check if the column is unsigned, only MySQL support this */ if (phalcon_memnstr_str(column_type, SL("unsigned"))) { - phalcon_array_update_string(&definition, SL("unsigned"), &ztrue, PH_COPY | PH_SEPARATE); + phalcon_array_update_string(&definition, SL("unsigned"), &PHALCON_GLOBAL(z_true), PH_COPY | PH_SEPARATE); } /** * Positions */ if (!zend_is_true(old_column)) { - phalcon_array_update_string(&definition, SL("first"), &ztrue, PH_COPY | PH_SEPARATE); + phalcon_array_update_string(&definition, SL("first"), &PHALCON_GLOBAL(z_true), PH_COPY | PH_SEPARATE); } else { phalcon_array_update_string(&definition, SL("after"), &old_column, PH_COPY | PH_SEPARATE); } @@ -340,7 +337,7 @@ PHP_METHOD(Phalcon_Db_Adapter_Pdo_Mysql, describeColumns){ PHALCON_OBS_NVAR(attribute); phalcon_array_fetch_long(&attribute, field, 3, PH_NOISY); if (PHALCON_IS_STRING(attribute, "PRI")) { - phalcon_array_update_string(&definition, SL("primary"), &ztrue, PH_COPY | PH_SEPARATE); + phalcon_array_update_string(&definition, SL("primary"), &PHALCON_GLOBAL(z_true), PH_COPY | PH_SEPARATE); } /** @@ -349,7 +346,7 @@ PHP_METHOD(Phalcon_Db_Adapter_Pdo_Mysql, describeColumns){ PHALCON_OBS_NVAR(attribute); phalcon_array_fetch_long(&attribute, field, 2, PH_NOISY); if (PHALCON_IS_STRING(attribute, "NO")) { - phalcon_array_update_string(&definition, SL("notNull"), &ztrue, PH_COPY | PH_SEPARATE); + phalcon_array_update_string(&definition, SL("notNull"), &PHALCON_GLOBAL(z_true), PH_COPY | PH_SEPARATE); } /** @@ -358,7 +355,7 @@ PHP_METHOD(Phalcon_Db_Adapter_Pdo_Mysql, describeColumns){ PHALCON_OBS_NVAR(attribute); phalcon_array_fetch_long(&attribute, field, 5, PH_NOISY); if (PHALCON_IS_STRING(attribute, "auto_increment")) { - phalcon_array_update_string(&definition, SL("autoIncrement"), &ztrue, PH_COPY | PH_SEPARATE); + phalcon_array_update_string(&definition, SL("autoIncrement"), &PHALCON_GLOBAL(z_true), PH_COPY | PH_SEPARATE); } PHALCON_OBS_NVAR(column_name); diff --git a/ext/db/adapter/pdo/oracle.c b/ext/db/adapter/pdo/oracle.c index 85512ca266c..2c5e8054093 100644 --- a/ext/db/adapter/pdo/oracle.c +++ b/ext/db/adapter/pdo/oracle.c @@ -160,7 +160,7 @@ PHP_METHOD(Phalcon_Db_Adapter_Pdo_Oracle, describeColumns){ phalcon_fetch_params(1, 1, 1, &table, &schema); if (!schema) { - PHALCON_INIT_VAR(schema); + schema = PHALCON_GLOBAL(z_null); } PHALCON_INIT_VAR(columns); @@ -338,7 +338,7 @@ PHP_METHOD(Phalcon_Db_Adapter_Pdo_Oracle, lastInsertId){ phalcon_fetch_params(1, 0, 1, &sequence_name); if (!sequence_name) { - PHALCON_INIT_VAR(sequence_name); + sequence_name = PHALCON_GLOBAL(z_null); } PHALCON_INIT_VAR(sql); diff --git a/ext/db/adapter/pdo/postgresql.c b/ext/db/adapter/pdo/postgresql.c index f5b43161419..737ba636f61 100644 --- a/ext/db/adapter/pdo/postgresql.c +++ b/ext/db/adapter/pdo/postgresql.c @@ -147,7 +147,7 @@ PHP_METHOD(Phalcon_Db_Adapter_Pdo_Postgresql, describeColumns){ phalcon_fetch_params(1, 1, 1, &table, &schema); if (!schema) { - PHALCON_INIT_VAR(schema); + schema = PHALCON_GLOBAL(z_null); } PHALCON_INIT_VAR(columns); diff --git a/ext/db/adapter/pdo/sqlite.c b/ext/db/adapter/pdo/sqlite.c index 3c5947affb8..3c5a7706b37 100644 --- a/ext/db/adapter/pdo/sqlite.c +++ b/ext/db/adapter/pdo/sqlite.c @@ -138,7 +138,7 @@ PHP_METHOD(Phalcon_Db_Adapter_Pdo_Sqlite, describeColumns){ phalcon_fetch_params(1, 1, 1, &table, &schema); if (!schema) { - PHALCON_INIT_VAR(schema); + schema = PHALCON_GLOBAL(z_null); } PHALCON_INIT_VAR(columns); @@ -323,7 +323,7 @@ PHP_METHOD(Phalcon_Db_Adapter_Pdo_Sqlite, describeIndexes){ phalcon_fetch_params(1, 1, 1, &table, &schema); if (!schema) { - PHALCON_INIT_VAR(schema); + schema = PHALCON_GLOBAL(z_null); } PHALCON_OBS_VAR(dialect); @@ -428,7 +428,7 @@ PHP_METHOD(Phalcon_Db_Adapter_Pdo_Sqlite, describeReferences){ phalcon_fetch_params(1, 1, 1, &table, &schema); if (!schema) { - PHALCON_INIT_VAR(schema); + schema = PHALCON_GLOBAL(z_null); } PHALCON_OBS_VAR(dialect); diff --git a/ext/db/dialect/mysql.c b/ext/db/dialect/mysql.c index d225529522b..8ecbe08a646 100644 --- a/ext/db/dialect/mysql.c +++ b/ext/db/dialect/mysql.c @@ -667,10 +667,7 @@ PHP_METHOD(Phalcon_Db_Dialect_Mysql, createTable){ PHALCON_OBS_VAR(options); phalcon_array_fetch_string(&options, definition, SL("options"), PH_NOISY); - if (phalcon_array_isset_string(options, SS("temporary"))) { - PHALCON_OBS_NVAR(temporary); - phalcon_array_fetch_string(&temporary, options, SL("temporary"), PH_NOISY); - } + phalcon_array_isset_string_fetch(&temporary, options, SS("temporary")); } /** @@ -845,15 +842,13 @@ PHP_METHOD(Phalcon_Db_Dialect_Mysql, createTable){ PHP_METHOD(Phalcon_Db_Dialect_Mysql, dropTable){ zval *table_name, *schema_name, *if_exists = NULL, *table = NULL; - zval *sql = NULL; PHALCON_MM_GROW(); phalcon_fetch_params(1, 2, 1, &table_name, &schema_name, &if_exists); if (!if_exists) { - PHALCON_INIT_VAR(if_exists); - ZVAL_BOOL(if_exists, 1); + if_exists = PHALCON_GLOBAL(z_true); } if (zend_is_true(schema_name)) { @@ -864,14 +859,12 @@ PHP_METHOD(Phalcon_Db_Dialect_Mysql, dropTable){ PHALCON_CONCAT_SVS(table, "`", table_name, "`"); } if (zend_is_true(if_exists)) { - PHALCON_INIT_VAR(sql); - PHALCON_CONCAT_SV(sql, "DROP TABLE IF EXISTS ", table); + PHALCON_CONCAT_SV(return_value, "DROP TABLE IF EXISTS ", table); } else { - PHALCON_INIT_NVAR(sql); - PHALCON_CONCAT_SV(sql, "DROP TABLE ", table); + PHALCON_CONCAT_SV(return_value, "DROP TABLE ", table); } - RETURN_CTOR(sql); + PHALCON_MM_RESTORE(); } /** @@ -923,32 +916,29 @@ PHP_METHOD(Phalcon_Db_Dialect_Mysql, createView){ PHP_METHOD(Phalcon_Db_Dialect_Mysql, dropView){ zval *view_name, *schema_name, *if_exists = NULL, *view = NULL; - zval *sql = NULL; PHALCON_MM_GROW(); phalcon_fetch_params(1, 2, 1, &view_name, &schema_name, &if_exists); if (!if_exists) { - PHALCON_INIT_VAR(if_exists); - ZVAL_BOOL(if_exists, 1); + if_exists = PHALCON_GLOBAL(z_true); } if (zend_is_true(schema_name)) { PHALCON_INIT_VAR(view); PHALCON_CONCAT_VSV(view, schema_name, ".", view_name); } else { - PHALCON_CPY_WRT(view, view_name); + view = view_name; } + if (zend_is_true(if_exists)) { - PHALCON_INIT_VAR(sql); - PHALCON_CONCAT_SV(sql, "DROP VIEW IF EXISTS ", view); + PHALCON_CONCAT_SV(return_value, "DROP VIEW IF EXISTS ", view); } else { - PHALCON_INIT_NVAR(sql); - PHALCON_CONCAT_SV(sql, "DROP VIEW ", view); + PHALCON_CONCAT_SV(return_value, "DROP VIEW ", view); } - RETURN_CTOR(sql); + PHALCON_MM_RESTORE(); } /** @@ -967,21 +957,14 @@ PHP_METHOD(Phalcon_Db_Dialect_Mysql, tableExists){ zval *table_name, *schema_name = NULL; - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 1, 1, &table_name, &schema_name); - - if (!schema_name) { - PHALCON_INIT_VAR(schema_name); - } + phalcon_fetch_params(0, 1, 1, &table_name, &schema_name); - if (zend_is_true(schema_name)) { + if (schema_name && zend_is_true(schema_name)) { PHALCON_CONCAT_SVSVS(return_value, "SELECT IF(COUNT(*)>0, 1 , 0) FROM `INFORMATION_SCHEMA`.`TABLES` WHERE `TABLE_NAME`= '", table_name, "' AND `TABLE_SCHEMA`='", schema_name, "'"); - RETURN_MM(); } - PHALCON_CONCAT_SVS(return_value, "SELECT IF(COUNT(*)>0, 1 , 0) FROM `INFORMATION_SCHEMA`.`TABLES` WHERE `TABLE_NAME`='", table_name, "'"); - - RETURN_MM(); + else { + PHALCON_CONCAT_SVS(return_value, "SELECT IF(COUNT(*)>0, 1 , 0) FROM `INFORMATION_SCHEMA`.`TABLES` WHERE `TABLE_NAME`='", table_name, "'"); + } } /** @@ -995,21 +978,14 @@ PHP_METHOD(Phalcon_Db_Dialect_Mysql, viewExists){ zval *view_name, *schema_name = NULL; - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 1, 1, &view_name, &schema_name); - - if (!schema_name) { - PHALCON_INIT_VAR(schema_name); - } + phalcon_fetch_params(0, 1, 1, &view_name, &schema_name); - if (zend_is_true(schema_name)) { + if (schema_name && zend_is_true(schema_name)) { PHALCON_CONCAT_SVSVS(return_value, "SELECT IF(COUNT(*)>0, 1 , 0) FROM `INFORMATION_SCHEMA`.`VIEWS` WHERE `TABLE_NAME`= '", view_name, "' AND `TABLE_SCHEMA`='", schema_name, "'"); - RETURN_MM(); } - PHALCON_CONCAT_SVS(return_value, "SELECT IF(COUNT(*)>0, 1 , 0) FROM `INFORMATION_SCHEMA`.`VIEWS` WHERE `TABLE_NAME`='", view_name, "'"); - - RETURN_MM(); + else { + PHALCON_CONCAT_SVS(return_value, "SELECT IF(COUNT(*)>0, 1 , 0) FROM `INFORMATION_SCHEMA`.`VIEWS` WHERE `TABLE_NAME`='", view_name, "'"); + } } /** @@ -1027,21 +1003,14 @@ PHP_METHOD(Phalcon_Db_Dialect_Mysql, describeColumns){ zval *table, *schema = NULL; - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 1, 1, &table, &schema); + phalcon_fetch_params(0, 1, 1, &table, &schema); - if (!schema) { - PHALCON_INIT_VAR(schema); - } - - if (zend_is_true(schema)) { + if (schema && zend_is_true(schema)) { PHALCON_CONCAT_SVSVS(return_value, "DESCRIBE `", schema, "`.`", table, "`"); - RETURN_MM(); } - PHALCON_CONCAT_SVS(return_value, "DESCRIBE `", table, "`"); - - RETURN_MM(); + else { + PHALCON_CONCAT_SVS(return_value, "DESCRIBE `", table, "`"); + } } /** @@ -1058,19 +1027,14 @@ PHP_METHOD(Phalcon_Db_Dialect_Mysql, listTables){ zval *schema_name = NULL; - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 0, 1, &schema_name); - - if (!schema_name) { - PHALCON_INIT_VAR(schema_name); - } + phalcon_fetch_params(0, 0, 1, &schema_name); - if (zend_is_true(schema_name)) { + if (schema_name && zend_is_true(schema_name)) { PHALCON_CONCAT_SVS(return_value, "SHOW TABLES FROM `", schema_name, "`"); - RETURN_MM(); } - RETURN_MM_STRING("SHOW TABLES", 1); + else { + RETURN_STRING("SHOW TABLES", 1); + } } /** @@ -1083,19 +1047,14 @@ PHP_METHOD(Phalcon_Db_Dialect_Mysql, listViews){ zval *schema_name = NULL; - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 0, 1, &schema_name); - - if (!schema_name) { - PHALCON_INIT_VAR(schema_name); - } + phalcon_fetch_params(0, 0, 1, &schema_name); - if (zend_is_true(schema_name)) { + if (schema_name && zend_is_true(schema_name)) { PHALCON_CONCAT_SVS(return_value, "SELECT `TABLE_NAME` AS view_name FROM `INFORMATION_SCHEMA`.`VIEWS` WHERE `TABLE_SCHEMA` = '", schema_name, "' ORDER BY view_name"); - RETURN_MM(); } - RETURN_MM_STRING("SELECT `TABLE_NAME` AS view_name FROM `INFORMATION_SCHEMA`.`VIEWS` ORDER BY view_name", 1); + else { + RETURN_STRING("SELECT `TABLE_NAME` AS view_name FROM `INFORMATION_SCHEMA`.`VIEWS` ORDER BY view_name", 1); + } } /** @@ -1109,21 +1068,14 @@ PHP_METHOD(Phalcon_Db_Dialect_Mysql, describeIndexes){ zval *table, *schema = NULL; - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 1, 1, &table, &schema); - - if (!schema) { - PHALCON_INIT_VAR(schema); - } + phalcon_fetch_params(0, 1, 1, &table, &schema); - if (zend_is_true(schema)) { + if (schema && zend_is_true(schema)) { PHALCON_CONCAT_SVSVS(return_value, "SHOW INDEXES FROM `", schema, "`.`", table, "`"); - RETURN_MM(); } - PHALCON_CONCAT_SVS(return_value, "SHOW INDEXES FROM `", table, "`"); - - RETURN_MM(); + else { + PHALCON_CONCAT_SVS(return_value, "SHOW INDEXES FROM `", table, "`"); + } } /** @@ -1141,13 +1093,9 @@ PHP_METHOD(Phalcon_Db_Dialect_Mysql, describeReferences){ phalcon_fetch_params(1, 1, 1, &table, &schema); - if (!schema) { - PHALCON_INIT_VAR(schema); - } - PHALCON_INIT_VAR(sql); ZVAL_STRING(sql, "SELECT TABLE_NAME,COLUMN_NAME,CONSTRAINT_NAME,REFERENCED_TABLE_SCHEMA,REFERENCED_TABLE_NAME,REFERENCED_COLUMN_NAME FROM INFORMATION_SCHEMA.KEY_COLUMN_USAGE WHERE REFERENCED_TABLE_NAME IS NOT NULL AND ", 1); - if (zend_is_true(schema)) { + if (schema && zend_is_true(schema)) { PHALCON_SCONCAT_SVSVS(sql, "CONSTRAINT_SCHEMA = \"", schema, "\" AND TABLE_NAME = \"", table, "\""); } else { PHALCON_SCONCAT_SVS(sql, "TABLE_NAME = \"", table, "\""); @@ -1171,13 +1119,9 @@ PHP_METHOD(Phalcon_Db_Dialect_Mysql, tableOptions){ phalcon_fetch_params(1, 1, 1, &table, &schema); - if (!schema) { - PHALCON_INIT_VAR(schema); - } - PHALCON_INIT_VAR(sql); ZVAL_STRING(sql, "SELECT TABLES.TABLE_TYPE AS table_type,TABLES.AUTO_INCREMENT AS auto_increment,TABLES.ENGINE AS engine,TABLES.TABLE_COLLATION AS table_collation FROM INFORMATION_SCHEMA.TABLES WHERE ", 1); - if (zend_is_true(schema)) { + if (schema && zend_is_true(schema)) { PHALCON_SCONCAT_SVSVS(sql, "TABLES.TABLE_SCHEMA = \"", schema, "\" AND TABLES.TABLE_NAME = \"", table, "\""); } else { PHALCON_SCONCAT_SVS(sql, "TABLES.TABLE_NAME = \"", table, "\""); diff --git a/ext/db/dialect/oracle.c b/ext/db/dialect/oracle.c index 476b35bf6e1..bd86d8b81ed 100644 --- a/ext/db/dialect/oracle.c +++ b/ext/db/dialect/oracle.c @@ -359,15 +359,13 @@ PHP_METHOD(Phalcon_Db_Dialect_Oracle, createTable){ PHP_METHOD(Phalcon_Db_Dialect_Oracle, dropTable){ zval *table_name, *schema_name, *if_exists = NULL, *table = NULL; - zval *sql = NULL; PHALCON_MM_GROW(); phalcon_fetch_params(1, 2, 1, &table_name, &schema_name, &if_exists); if (!if_exists) { - PHALCON_INIT_VAR(if_exists); - ZVAL_BOOL(if_exists, 1); + if_exists = PHALCON_GLOBAL(z_true); } if (zend_is_true(schema_name)) { @@ -377,14 +375,12 @@ PHP_METHOD(Phalcon_Db_Dialect_Oracle, dropTable){ PHALCON_CPY_WRT(table, table_name); } if (zend_is_true(if_exists)) { - PHALCON_INIT_VAR(sql); - PHALCON_CONCAT_SV(sql, "DROP TABLE IF EXISTS ", table); + PHALCON_CONCAT_SV(return_value, "DROP TABLE IF EXISTS ", table); } else { - PHALCON_INIT_NVAR(sql); - PHALCON_CONCAT_SV(sql, "DROP TABLE ", table); + PHALCON_CONCAT_SV(return_value, "DROP TABLE ", table); } - RETURN_CTOR(sql); + PHALCON_MM_RESTORE(); } /** @@ -398,7 +394,7 @@ PHP_METHOD(Phalcon_Db_Dialect_Oracle, dropTable){ PHP_METHOD(Phalcon_Db_Dialect_Oracle, createView){ zval *view_name, *definition, *schema_name, *view_sql; - zval *view = NULL, *sql; + zval *view = NULL; PHALCON_MM_GROW(); @@ -418,10 +414,9 @@ PHP_METHOD(Phalcon_Db_Dialect_Oracle, createView){ PHALCON_CPY_WRT(view, view_name); } - PHALCON_INIT_VAR(sql); - PHALCON_CONCAT_SVSV(sql, "CREATE VIEW ", view, " AS ", view_sql); + PHALCON_CONCAT_SVSV(return_value, "CREATE VIEW ", view, " AS ", view_sql); - RETURN_CTOR(sql); + PHALCON_MM_RESTORE(); } /** @@ -435,15 +430,13 @@ PHP_METHOD(Phalcon_Db_Dialect_Oracle, createView){ PHP_METHOD(Phalcon_Db_Dialect_Oracle, dropView){ zval *view_name, *schema_name, *if_exists = NULL, *view = NULL; - zval *sql = NULL; PHALCON_MM_GROW(); phalcon_fetch_params(1, 2, 1, &view_name, &schema_name, &if_exists); if (!if_exists) { - PHALCON_INIT_VAR(if_exists); - ZVAL_BOOL(if_exists, 1); + if_exists = PHALCON_GLOBAL(z_true); } if (zend_is_true(schema_name)) { @@ -454,14 +447,12 @@ PHP_METHOD(Phalcon_Db_Dialect_Oracle, dropView){ PHALCON_CONCAT_SVS(view, "`", view_name, "`"); } if (zend_is_true(if_exists)) { - PHALCON_INIT_VAR(sql); - PHALCON_CONCAT_SV(sql, "DROP VIEW IF EXISTS ", view); + PHALCON_CONCAT_SV(return_value, "DROP VIEW IF EXISTS ", view); } else { - PHALCON_INIT_NVAR(sql); - PHALCON_CONCAT_SV(sql, "DROP VIEW ", view); + PHALCON_CONCAT_SV(return_value, "DROP VIEW ", view); } - RETURN_CTOR(sql); + PHALCON_MM_RESTORE(); } /** @@ -478,25 +469,15 @@ PHP_METHOD(Phalcon_Db_Dialect_Oracle, dropView){ */ PHP_METHOD(Phalcon_Db_Dialect_Oracle, tableExists){ - zval *table_name, *schema_name = NULL, *sql = NULL; + zval *table_name, *schema_name = NULL; - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 1, 1, &table_name, &schema_name); - - if (!schema_name) { - PHALCON_INIT_VAR(schema_name); - } + phalcon_fetch_params(0, 1, 1, &table_name, &schema_name); - if (zend_is_true(schema_name)) { - PHALCON_INIT_VAR(sql); - PHALCON_CONCAT_SVSVS(sql, "SELECT CASE WHEN COUNT(*) > 0 THEN 1 ELSE 0 END RET FROM ALL_TABLES WHERE TABLE_NAME='", table_name, "' AND OWNER = '", schema_name, "'"); + if (schema_name && zend_is_true(schema_name)) { + PHALCON_CONCAT_SVSVS(return_value, "SELECT CASE WHEN COUNT(*) > 0 THEN 1 ELSE 0 END RET FROM ALL_TABLES WHERE TABLE_NAME='", table_name, "' AND OWNER = '", schema_name, "'"); } else { - PHALCON_INIT_NVAR(sql); - PHALCON_CONCAT_SVS(sql, "SELECT CASE WHEN COUNT(*) > 0 THEN 1 ELSE 0 END RET FROM ALL_TABLES WHERE TABLE_NAME='", table_name, "'"); + PHALCON_CONCAT_SVS(return_value, "SELECT CASE WHEN COUNT(*) > 0 THEN 1 ELSE 0 END RET FROM ALL_TABLES WHERE TABLE_NAME='", table_name, "'"); } - - RETURN_CTOR(sql); } /** @@ -508,25 +489,15 @@ PHP_METHOD(Phalcon_Db_Dialect_Oracle, tableExists){ */ PHP_METHOD(Phalcon_Db_Dialect_Oracle, viewExists){ - zval *view_name, *schema_name = NULL, *sql = NULL; + zval *view_name, *schema_name = NULL; - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 1, 1, &view_name, &schema_name); - - if (!schema_name) { - PHALCON_INIT_VAR(schema_name); - } + phalcon_fetch_params(0, 1, 1, &view_name, &schema_name); - if (zend_is_true(schema_name)) { - PHALCON_INIT_VAR(sql); - PHALCON_CONCAT_SVSVS(sql, "SELECT CASE WHEN COUNT(*) > 0 THEN 1 ELSE 0 END RET FROM ALL_VIEWS WHERE VIEW_NAME='", view_name, "' AND OWNER='", schema_name, "'"); + if (schema_name && zend_is_true(schema_name)) { + PHALCON_CONCAT_SVSVS(return_value, "SELECT CASE WHEN COUNT(*) > 0 THEN 1 ELSE 0 END RET FROM ALL_VIEWS WHERE VIEW_NAME='", view_name, "' AND OWNER='", schema_name, "'"); } else { - PHALCON_INIT_NVAR(sql); - PHALCON_CONCAT_SVS(sql, "SELECT CASE WHEN COUNT(*) > 0 THEN 1 ELSE 0 END RET FROM ALL_VIEWS WHERE VIEW_NAME='", view_name, "'"); + PHALCON_CONCAT_SVS(return_value, "SELECT CASE WHEN COUNT(*) > 0 THEN 1 ELSE 0 END RET FROM ALL_VIEWS WHERE VIEW_NAME='", view_name, "'"); } - - RETURN_CTOR(sql); } /** @@ -542,25 +513,15 @@ PHP_METHOD(Phalcon_Db_Dialect_Oracle, viewExists){ */ PHP_METHOD(Phalcon_Db_Dialect_Oracle, describeColumns){ - zval *table, *schema = NULL, *sql = NULL; - - PHALCON_MM_GROW(); + zval *table, *schema = NULL; - phalcon_fetch_params(1, 1, 1, &table, &schema); - - if (!schema) { - PHALCON_INIT_VAR(schema); - } + phalcon_fetch_params(0, 1, 1, &table, &schema); - if (zend_is_true(schema)) { - PHALCON_INIT_VAR(sql); - PHALCON_CONCAT_SVSVS(sql, "SELECT TC.COLUMN_NAME, TC.DATA_TYPE, TC.DATA_LENGTH, TC.DATA_PRECISION, TC.DATA_SCALE, TC.NULLABLE, C.CONSTRAINT_TYPE, TC.DATA_DEFAULT, CC.POSITION FROM ALL_TAB_COLUMNS TC LEFT JOIN (ALL_CONS_COLUMNS CC JOIN ALL_CONSTRAINTS C ON (CC.CONSTRAINT_NAME = C.CONSTRAINT_NAME AND CC.TABLE_NAME = C.TABLE_NAME AND CC.OWNER = C.OWNER AND C.CONSTRAINT_TYPE = 'P')) ON TC.TABLE_NAME = CC.TABLE_NAME AND TC.COLUMN_NAME = CC.COLUMN_NAME WHERE TC.TABLE_NAME = '", table, "' AND TC.OWNER = '", schema, "' ORDER BY TC.COLUMN_ID"); + if (schema && zend_is_true(schema)) { + PHALCON_CONCAT_SVSVS(return_value, "SELECT TC.COLUMN_NAME, TC.DATA_TYPE, TC.DATA_LENGTH, TC.DATA_PRECISION, TC.DATA_SCALE, TC.NULLABLE, C.CONSTRAINT_TYPE, TC.DATA_DEFAULT, CC.POSITION FROM ALL_TAB_COLUMNS TC LEFT JOIN (ALL_CONS_COLUMNS CC JOIN ALL_CONSTRAINTS C ON (CC.CONSTRAINT_NAME = C.CONSTRAINT_NAME AND CC.TABLE_NAME = C.TABLE_NAME AND CC.OWNER = C.OWNER AND C.CONSTRAINT_TYPE = 'P')) ON TC.TABLE_NAME = CC.TABLE_NAME AND TC.COLUMN_NAME = CC.COLUMN_NAME WHERE TC.TABLE_NAME = '", table, "' AND TC.OWNER = '", schema, "' ORDER BY TC.COLUMN_ID"); } else { - PHALCON_INIT_NVAR(sql); - PHALCON_CONCAT_SVS(sql, "SELECT TC.COLUMN_NAME, TC.DATA_TYPE, TC.DATA_LENGTH, TC.DATA_PRECISION, TC.DATA_SCALE, TC.NULLABLE, C.CONSTRAINT_TYPE, TC.DATA_DEFAULT, CC.POSITION FROM ALL_TAB_COLUMNS TC LEFT JOIN (ALL_CONS_COLUMNS CC JOIN ALL_CONSTRAINTS C ON (CC.CONSTRAINT_NAME = C.CONSTRAINT_NAME AND CC.TABLE_NAME = C.TABLE_NAME AND CC.OWNER = C.OWNER AND C.CONSTRAINT_TYPE = 'P')) ON TC.TABLE_NAME = CC.TABLE_NAME AND TC.COLUMN_NAME = CC.COLUMN_NAME WHERE TC.TABLE_NAME = '", table, "' ORDER BY TC.COLUMN_ID"); + PHALCON_CONCAT_SVS(return_value, "SELECT TC.COLUMN_NAME, TC.DATA_TYPE, TC.DATA_LENGTH, TC.DATA_PRECISION, TC.DATA_SCALE, TC.NULLABLE, C.CONSTRAINT_TYPE, TC.DATA_DEFAULT, CC.POSITION FROM ALL_TAB_COLUMNS TC LEFT JOIN (ALL_CONS_COLUMNS CC JOIN ALL_CONSTRAINTS C ON (CC.CONSTRAINT_NAME = C.CONSTRAINT_NAME AND CC.TABLE_NAME = C.TABLE_NAME AND CC.OWNER = C.OWNER AND C.CONSTRAINT_TYPE = 'P')) ON TC.TABLE_NAME = CC.TABLE_NAME AND TC.COLUMN_NAME = CC.COLUMN_NAME WHERE TC.TABLE_NAME = '", table, "' ORDER BY TC.COLUMN_ID"); } - - RETURN_CTOR(sql); } /** @@ -575,25 +536,15 @@ PHP_METHOD(Phalcon_Db_Dialect_Oracle, describeColumns){ */ PHP_METHOD(Phalcon_Db_Dialect_Oracle, listTables){ - zval *schema_name = NULL, *sql = NULL; - - PHALCON_MM_GROW(); + zval *schema_name = NULL; - phalcon_fetch_params(1, 0, 1, &schema_name); + phalcon_fetch_params(0, 0, 1, &schema_name); - if (!schema_name) { - PHALCON_INIT_VAR(schema_name); - } - - if (zend_is_true(schema_name)) { - PHALCON_INIT_VAR(sql); - PHALCON_CONCAT_SVS(sql, "SELECT TABLE_NAME, OWNER FROM ALL_TABLES WHERE OWNER='", schema_name, "' ORDER BY OWNER, TABLE_NAME"); + if (schema_name && zend_is_true(schema_name)) { + PHALCON_CONCAT_SVS(return_value, "SELECT TABLE_NAME, OWNER FROM ALL_TABLES WHERE OWNER='", schema_name, "' ORDER BY OWNER, TABLE_NAME"); } else { - PHALCON_INIT_NVAR(sql); - ZVAL_STRING(sql, "SELECT TABLE_NAME, OWNER FROM ALL_TABLES ORDER BY OWNER, TABLE_NAME ", 1); + RETURN_STRING("SELECT TABLE_NAME, OWNER FROM ALL_TABLES ORDER BY OWNER, TABLE_NAME ", 1); } - - RETURN_CTOR(sql); } /** @@ -604,25 +555,15 @@ PHP_METHOD(Phalcon_Db_Dialect_Oracle, listTables){ */ PHP_METHOD(Phalcon_Db_Dialect_Oracle, listViews){ - zval *schema_name = NULL, *sql = NULL; - - PHALCON_MM_GROW(); + zval *schema_name = NULL; - phalcon_fetch_params(1, 0, 1, &schema_name); + phalcon_fetch_params(0, 0, 1, &schema_name); - if (!schema_name) { - PHALCON_INIT_VAR(schema_name); - } - - if (zend_is_true(schema_name)) { - PHALCON_INIT_VAR(sql); - PHALCON_CONCAT_SVS(sql, "SELECT VIEW_NAME FROM ALL_VIEWS WHERE OWNER='", schema_name, "' ORDER BY VIEW_NAME"); + if (schema_name && zend_is_true(schema_name)) { + PHALCON_CONCAT_SVS(return_value, "SELECT VIEW_NAME FROM ALL_VIEWS WHERE OWNER='", schema_name, "' ORDER BY VIEW_NAME"); } else { - PHALCON_INIT_NVAR(sql); - ZVAL_STRING(sql, "SELECT VIEW_NAME FROM ALL_VIEWS VIEW_NAME", 1); + RETURN_STRING("SELECT VIEW_NAME FROM ALL_VIEWS VIEW_NAME", 1); } - - RETURN_CTOR(sql); } /** @@ -634,25 +575,15 @@ PHP_METHOD(Phalcon_Db_Dialect_Oracle, listViews){ */ PHP_METHOD(Phalcon_Db_Dialect_Oracle, describeIndexes){ - zval *table, *schema = NULL, *sql = NULL; - - PHALCON_MM_GROW(); + zval *table, *schema = NULL; - phalcon_fetch_params(1, 1, 1, &table, &schema); - - if (!schema) { - PHALCON_INIT_VAR(schema); - } + phalcon_fetch_params(0, 1, 1, &table, &schema); - if (zend_is_true(schema)) { - PHALCON_INIT_VAR(sql); - PHALCON_CONCAT_SVSVS(sql, "SELECT I.TABLE_NAME, 0 AS C0, I.INDEX_NAME, IC.COLUMN_POSITION, IC.COLUMN_NAME FROM ALL_INDEXES I JOIN ALL_IND_COLUMNS IC ON I.INDEX_NAME = IC.INDEX_NAME WHERE I.TABLE_NAME = '", table, "' AND IC.INDEX_OWNER = '", schema, "'"); + if (schema && zend_is_true(schema)) { + PHALCON_CONCAT_SVSVS(return_value, "SELECT I.TABLE_NAME, 0 AS C0, I.INDEX_NAME, IC.COLUMN_POSITION, IC.COLUMN_NAME FROM ALL_INDEXES I JOIN ALL_IND_COLUMNS IC ON I.INDEX_NAME = IC.INDEX_NAME WHERE I.TABLE_NAME = '", table, "' AND IC.INDEX_OWNER = '", schema, "'"); } else { - PHALCON_INIT_NVAR(sql); - PHALCON_CONCAT_SVS(sql, "SELECT I.TABLE_NAME, 0 AS C0, I.INDEX_NAME, IC.COLUMN_POSITION, IC.COLUMN_NAME FROM ALL_INDEXES I JOIN ALL_IND_COLUMNS IC ON I.INDEX_NAME = IC.INDEX_NAME WHERE I.TABLE_NAME = '", table, "'"); + PHALCON_CONCAT_SVS(return_value, "SELECT I.TABLE_NAME, 0 AS C0, I.INDEX_NAME, IC.COLUMN_POSITION, IC.COLUMN_NAME FROM ALL_INDEXES I JOIN ALL_IND_COLUMNS IC ON I.INDEX_NAME = IC.INDEX_NAME WHERE I.TABLE_NAME = '", table, "'"); } - - RETURN_CTOR(sql); } /** @@ -670,13 +601,9 @@ PHP_METHOD(Phalcon_Db_Dialect_Oracle, describeReferences){ phalcon_fetch_params(1, 1, 1, &table, &schema); - if (!schema) { - PHALCON_INIT_VAR(schema); - } - PHALCON_INIT_VAR(sql); ZVAL_STRING(sql, "SELECT AC.TABLE_NAME, CC.COLUMN_NAME, AC.CONSTRAINT_NAME, AC.R_OWNER, RCC.TABLE_NAME R_TABLE_NAME, RCC.COLUMN_NAME R_COLUMN_NAME FROM ALL_CONSTRAINTS AC JOIN ALL_CONS_COLUMNS CC ON AC.CONSTRAINT_NAME = CC.CONSTRAINT_NAME JOIN ALL_CONS_COLUMNS RCC ON AC.R_OWNER = RCC.OWNER AND AC.R_CONSTRAINT_NAME = RCC.CONSTRAINT_NAME WHERE AC.CONSTRAINT_TYPE='R' ", 1); - if (zend_is_true(schema)) { + if (schema && zend_is_true(schema)) { PHALCON_SCONCAT_SVSVS(sql, "AND AC.OWNER='", schema, "' AND AC.TABLE_NAME = '", table, "'"); } else { PHALCON_SCONCAT_SVS(sql, "AND AC.TABLE_NAME = '", table, "'"); @@ -696,15 +623,9 @@ PHP_METHOD(Phalcon_Db_Dialect_Oracle, tableOptions){ zval *table, *schema = NULL; - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 1, 1, &table, &schema); - - if (!schema) { - PHALCON_INIT_VAR(schema); - } + phalcon_fetch_params(0, 1, 1, &table, &schema); - RETURN_MM_EMPTY_STRING(); + RETURN_EMPTY_STRING(); } /** diff --git a/ext/db/dialect/postgresql.c b/ext/db/dialect/postgresql.c index 03c7116203a..ff85fdcb24e 100644 --- a/ext/db/dialect/postgresql.c +++ b/ext/db/dialect/postgresql.c @@ -357,8 +357,7 @@ PHP_METHOD(Phalcon_Db_Dialect_Postgresql, dropTable){ phalcon_fetch_params(1, 2, 1, &table_name, &schema_name, &if_exists); if (!if_exists) { - PHALCON_INIT_VAR(if_exists); - ZVAL_BOOL(if_exists, 1); + if_exists = PHALCON_GLOBAL(z_true); } if (zend_is_true(schema_name)) { @@ -433,8 +432,7 @@ PHP_METHOD(Phalcon_Db_Dialect_Postgresql, dropView){ phalcon_fetch_params(1, 2, 1, &view_name, &schema_name, &if_exists); if (!if_exists) { - PHALCON_INIT_VAR(if_exists); - ZVAL_BOOL(if_exists, 1); + if_exists = PHALCON_GLOBAL(z_true); } if (zend_is_true(schema_name)) { @@ -502,11 +500,7 @@ PHP_METHOD(Phalcon_Db_Dialect_Postgresql, viewExists){ phalcon_fetch_params(1, 1, 1, &view_name, &schema_name); - if (!schema_name) { - PHALCON_INIT_VAR(schema_name); - } - - if (zend_is_true(schema_name)) { + if (schema_name && zend_is_true(schema_name)) { PHALCON_INIT_VAR(sql); PHALCON_CONCAT_SVSVS(sql, "SELECT CASE WHEN COUNT(*) > 0 THEN 1 ELSE 0 END FROM pg_views WHERE viewname='", view_name, "' AND schemaname='", schema_name, "'"); } else { diff --git a/ext/db/dialect/sqlite.c b/ext/db/dialect/sqlite.c index aa023171a9f..1af59cd9a5b 100644 --- a/ext/db/dialect/sqlite.c +++ b/ext/db/dialect/sqlite.c @@ -409,32 +409,29 @@ PHP_METHOD(Phalcon_Db_Dialect_Sqlite, createTable){ PHP_METHOD(Phalcon_Db_Dialect_Sqlite, dropTable){ zval *table_name, *schema_name, *if_exists = NULL, *table = NULL; - zval *sql = NULL; PHALCON_MM_GROW(); phalcon_fetch_params(1, 2, 1, &table_name, &schema_name, &if_exists); if (!if_exists) { - PHALCON_INIT_VAR(if_exists); - ZVAL_BOOL(if_exists, 1); + if_exists = PHALCON_GLOBAL(z_true); } if (zend_is_true(schema_name)) { PHALCON_INIT_VAR(table); PHALCON_CONCAT_VSV(table, schema_name, "\".\"", table_name); } else { - PHALCON_CPY_WRT(table, table_name); + table = table_name; } - PHALCON_INIT_VAR(sql); if (zend_is_true(if_exists)) { - PHALCON_CONCAT_SVS(sql, "DROP TABLE IF EXISTS \"", table, "\""); + PHALCON_CONCAT_SVS(return_value, "DROP TABLE IF EXISTS \"", table, "\""); } else { - PHALCON_CONCAT_SVS(sql, "DROP TABLE \"", table, "\""); + PHALCON_CONCAT_SVS(return_value, "DROP TABLE \"", table, "\""); } - RETURN_CTOR(sql); + PHALCON_MM_RESTORE(); } /** @@ -485,15 +482,13 @@ PHP_METHOD(Phalcon_Db_Dialect_Sqlite, createView){ PHP_METHOD(Phalcon_Db_Dialect_Sqlite, dropView){ zval *view_name, *schema_name, *if_exists = NULL, *view = NULL; - zval *sql = NULL; PHALCON_MM_GROW(); phalcon_fetch_params(1, 2, 1, &view_name, &schema_name, &if_exists); if (!if_exists) { - PHALCON_INIT_VAR(if_exists); - ZVAL_BOOL(if_exists, 1); + if_exists = PHALCON_GLOBAL(z_true); } if (zend_is_true(schema_name)) { @@ -503,14 +498,12 @@ PHP_METHOD(Phalcon_Db_Dialect_Sqlite, dropView){ PHALCON_CPY_WRT(view, view_name); } if (zend_is_true(if_exists)) { - PHALCON_INIT_VAR(sql); - PHALCON_CONCAT_SVS(sql, "DROP VIEW IF EXISTS \"", view, "\""); + PHALCON_CONCAT_SVS(return_value, "DROP VIEW IF EXISTS \"", view, "\""); } else { - PHALCON_INIT_NVAR(sql); - PHALCON_CONCAT_SVS(sql, "DROP VIEW \"", view, "\""); + PHALCON_CONCAT_SVS(return_value, "DROP VIEW \"", view, "\""); } - RETURN_CTOR(sql); + PHALCON_MM_RESTORE(); } /** @@ -525,19 +518,11 @@ PHP_METHOD(Phalcon_Db_Dialect_Sqlite, dropView){ */ PHP_METHOD(Phalcon_Db_Dialect_Sqlite, tableExists){ - zval *table_name, *schema_name = NULL, *sql; - - PHALCON_MM_GROW(); + zval *table_name, *schema_name = NULL; - phalcon_fetch_params(1, 1, 1, &table_name, &schema_name); + phalcon_fetch_params(0, 1, 1, &table_name, &schema_name); - if (!schema_name) { - PHALCON_INIT_VAR(schema_name); - } - - PHALCON_INIT_VAR(sql); - PHALCON_CONCAT_SVS(sql, "SELECT CASE WHEN COUNT(*) > 0 THEN 1 ELSE 0 END FROM sqlite_master WHERE type='table' AND tbl_name='", table_name, "'"); - RETURN_CTOR(sql); + PHALCON_CONCAT_SVS(return_value, "SELECT CASE WHEN COUNT(*) > 0 THEN 1 ELSE 0 END FROM sqlite_master WHERE type='table' AND tbl_name='", table_name, "'"); } /** @@ -549,19 +534,11 @@ PHP_METHOD(Phalcon_Db_Dialect_Sqlite, tableExists){ */ PHP_METHOD(Phalcon_Db_Dialect_Sqlite, viewExists){ - zval *view_name, *schema_name = NULL, *sql; + zval *view_name, *schema_name = NULL; - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 1, 1, &view_name, &schema_name); - - if (!schema_name) { - PHALCON_INIT_VAR(schema_name); - } + phalcon_fetch_params(0, 1, 1, &view_name, &schema_name); - PHALCON_INIT_VAR(sql); - PHALCON_CONCAT_SVS(sql, "SELECT CASE WHEN COUNT(*) > 0 THEN 1 ELSE 0 END FROM sqlite_master WHERE type='view' AND tbl_name='", view_name, "'"); - RETURN_CTOR(sql); + PHALCON_CONCAT_SVS(return_value, "SELECT CASE WHEN COUNT(*) > 0 THEN 1 ELSE 0 END FROM sqlite_master WHERE type='view' AND tbl_name='", view_name, "'"); } /** @@ -575,19 +552,11 @@ PHP_METHOD(Phalcon_Db_Dialect_Sqlite, viewExists){ */ PHP_METHOD(Phalcon_Db_Dialect_Sqlite, describeColumns){ - zval *table, *schema = NULL, *sql; - - PHALCON_MM_GROW(); + zval *table, *schema = NULL; - phalcon_fetch_params(1, 1, 1, &table, &schema); - - if (!schema) { - PHALCON_INIT_VAR(schema); - } + phalcon_fetch_params(0, 1, 1, &table, &schema); - PHALCON_INIT_VAR(sql); - PHALCON_CONCAT_SVS(sql, "PRAGMA table_info('", table, "')"); - RETURN_CTOR(sql); + PHALCON_CONCAT_SVS(return_value, "PRAGMA table_info('", table, "')"); } /** @@ -600,19 +569,11 @@ PHP_METHOD(Phalcon_Db_Dialect_Sqlite, describeColumns){ */ PHP_METHOD(Phalcon_Db_Dialect_Sqlite, listTables){ - zval *schema_name = NULL, *sql; + zval *schema_name = NULL; - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 0, 1, &schema_name); - - if (!schema_name) { - PHALCON_INIT_VAR(schema_name); - } + phalcon_fetch_params(0, 0, 1, &schema_name); - PHALCON_INIT_VAR(sql); - ZVAL_STRING(sql, "SELECT tbl_name FROM sqlite_master WHERE type = 'table' ORDER BY tbl_name", 1); - RETURN_CTOR(sql); + RETURN_STRING("SELECT tbl_name FROM sqlite_master WHERE type = 'table' ORDER BY tbl_name", 1); } /** @@ -623,19 +584,11 @@ PHP_METHOD(Phalcon_Db_Dialect_Sqlite, listTables){ */ PHP_METHOD(Phalcon_Db_Dialect_Sqlite, listViews){ - zval *schema_name = NULL, *sql; + zval *schema_name = NULL; - PHALCON_MM_GROW(); + phalcon_fetch_params(0, 0, 1, &schema_name); - phalcon_fetch_params(1, 0, 1, &schema_name); - - if (!schema_name) { - PHALCON_INIT_VAR(schema_name); - } - - PHALCON_INIT_VAR(sql); - ZVAL_STRING(sql, "SELECT tbl_name FROM sqlite_master WHERE type = 'view' ORDER BY tbl_name", 1); - RETURN_CTOR(sql); + RETURN_STRING("SELECT tbl_name FROM sqlite_master WHERE type = 'view' ORDER BY tbl_name", 1); } /** @@ -647,19 +600,11 @@ PHP_METHOD(Phalcon_Db_Dialect_Sqlite, listViews){ */ PHP_METHOD(Phalcon_Db_Dialect_Sqlite, describeIndexes){ - zval *table, *schema = NULL, *sql; - - PHALCON_MM_GROW(); + zval *table, *schema = NULL; - phalcon_fetch_params(1, 1, 1, &table, &schema); - - if (!schema) { - PHALCON_INIT_VAR(schema); - } + phalcon_fetch_params(0, 1, 1, &table, &schema); - PHALCON_INIT_VAR(sql); - PHALCON_CONCAT_SVS(sql, "PRAGMA index_list('", table, "')"); - RETURN_CTOR(sql); + PHALCON_CONCAT_SVS(return_value, "PRAGMA index_list('", table, "')"); } /** @@ -670,15 +615,11 @@ PHP_METHOD(Phalcon_Db_Dialect_Sqlite, describeIndexes){ */ PHP_METHOD(Phalcon_Db_Dialect_Sqlite, describeIndex){ - zval *index_name, *sql; - - PHALCON_MM_GROW(); + zval *index_name; - phalcon_fetch_params(1, 1, 0, &index_name); + phalcon_fetch_params(0, 1, 0, &index_name); - PHALCON_INIT_VAR(sql); - PHALCON_CONCAT_SVS(sql, "PRAGMA index_info('", index_name, "')"); - RETURN_CTOR(sql); + PHALCON_CONCAT_SVS(return_value, "PRAGMA index_info('", index_name, "')"); } /** @@ -690,19 +631,11 @@ PHP_METHOD(Phalcon_Db_Dialect_Sqlite, describeIndex){ */ PHP_METHOD(Phalcon_Db_Dialect_Sqlite, describeReferences){ - zval *table, *schema = NULL, *sql; - - PHALCON_MM_GROW(); + zval *table, *schema = NULL; - phalcon_fetch_params(1, 1, 1, &table, &schema); - - if (!schema) { - PHALCON_INIT_VAR(schema); - } + phalcon_fetch_params(0, 1, 1, &table, &schema); - PHALCON_INIT_VAR(sql); - PHALCON_CONCAT_SVS(sql, "PRAGMA foreign_key_list('", table, "')"); - RETURN_CTOR(sql); + PHALCON_CONCAT_SVS(return_value, "PRAGMA foreign_key_list('", table, "')"); } /** diff --git a/ext/db/profiler.c b/ext/db/profiler.c index 41d816a3884..f21e3532268 100644 --- a/ext/db/profiler.c +++ b/ext/db/profiler.c @@ -93,7 +93,7 @@ PHALCON_INIT_CLASS(Phalcon_Db_Profiler){ */ PHP_METHOD(Phalcon_Db_Profiler, startProfile){ - zval *sql_statement, *active_profile, *micro; + zval *sql_statement, *active_profile; zval *time; PHALCON_MM_GROW(); @@ -104,11 +104,8 @@ PHP_METHOD(Phalcon_Db_Profiler, startProfile){ object_init_ex(active_profile, phalcon_db_profiler_item_ce); phalcon_call_method_p1_noret(active_profile, "setsqlstatement", sql_statement); - PHALCON_INIT_VAR(micro); - ZVAL_BOOL(micro, 1); - PHALCON_INIT_VAR(time); - phalcon_call_func_p1(time, "microtime", micro); + phalcon_call_func_p1(time, "microtime", PHALCON_GLOBAL(z_true)); phalcon_call_method_p1_noret(active_profile, "setinitialtime", time); if (phalcon_method_exists_ex(this_ptr, SS("beforestartprofile") TSRMLS_CC) == SUCCESS) { phalcon_call_method_p1_noret(this_ptr, "beforestartprofile", active_profile); @@ -126,16 +123,13 @@ PHP_METHOD(Phalcon_Db_Profiler, startProfile){ */ PHP_METHOD(Phalcon_Db_Profiler, stopProfile){ - zval *micro, *final_time, *active_profile, *initial_time; + zval *final_time, *active_profile, *initial_time; zval *diference, *total_seconds, *new_total_seconds; PHALCON_MM_GROW(); - PHALCON_INIT_VAR(micro); - ZVAL_BOOL(micro, 1); - PHALCON_INIT_VAR(final_time); - phalcon_call_func_p1(final_time, "microtime", micro); + phalcon_call_func_p1(final_time, "microtime", PHALCON_GLOBAL(z_true)); PHALCON_OBS_VAR(active_profile); phalcon_read_property_this(&active_profile, this_ptr, SL("_activeProfile"), PH_NOISY_CC); @@ -170,12 +164,8 @@ PHP_METHOD(Phalcon_Db_Profiler, getNumberTotalStatements){ zval *all_profiles; - PHALCON_MM_GROW(); - - PHALCON_OBS_VAR(all_profiles); - phalcon_read_property_this(&all_profiles, this_ptr, SL("_allProfiles"), PH_NOISY_CC); + all_profiles = phalcon_fetch_nproperty_this(this_ptr, SL("_allProfiles"), PH_NOISY_CC); phalcon_fast_count(return_value, all_profiles TSRMLS_CC); - RETURN_MM(); } /** @@ -209,12 +199,11 @@ PHP_METHOD(Phalcon_Db_Profiler, reset){ zval *empty_arr; - PHALCON_MM_GROW(); - - PHALCON_INIT_VAR(empty_arr); + MAKE_STD_ZVAL(empty_arr); array_init(empty_arr); phalcon_update_property_this(this_ptr, SL("_allProfiles"), empty_arr TSRMLS_CC); - RETURN_THIS(); + zval_ptr_dtor(&empty_arr); + RETURN_THISW(); } /** @@ -227,4 +216,3 @@ PHP_METHOD(Phalcon_Db_Profiler, getLastProfile){ RETURN_MEMBER(this_ptr, "_activeProfile"); } - diff --git a/ext/db/result/pdo.c b/ext/db/result/pdo.c index a4bd0d334d9..694eaea9ac4 100644 --- a/ext/db/result/pdo.c +++ b/ext/db/result/pdo.c @@ -94,15 +94,15 @@ PHP_METHOD(Phalcon_Db_Result_Pdo, __construct){ phalcon_fetch_params(1, 2, 3, &connection, &result, &sql_statement, &bind_params, &bind_types); if (!sql_statement) { - PHALCON_INIT_VAR(sql_statement); + sql_statement = PHALCON_GLOBAL(z_null); } if (!bind_params) { - PHALCON_INIT_VAR(bind_params); + bind_params = PHALCON_GLOBAL(z_null); } if (!bind_types) { - PHALCON_INIT_VAR(bind_types); + bind_types = PHALCON_GLOBAL(z_null); } if (Z_TYPE_P(result) != IS_OBJECT) { diff --git a/ext/debug.c b/ext/debug.c index e58480c1634..177732bbbe6 100644 --- a/ext/debug.c +++ b/ext/debug.c @@ -152,20 +152,11 @@ PHP_METHOD(Phalcon_Debug, listen){ phalcon_fetch_params(1, 0, 2, &exceptions, &low_severity); - if (!exceptions) { - PHALCON_INIT_VAR(exceptions); - ZVAL_BOOL(exceptions, 1); - } - - if (!low_severity) { - PHALCON_INIT_VAR(low_severity); - ZVAL_BOOL(low_severity, 0); - } - - if (zend_is_true(exceptions)) { + if (!exceptions || zend_is_true(exceptions)) { phalcon_call_method_noret(this_ptr, "listenexceptions"); } - if (zend_is_true(low_severity)) { + + if (low_severity && zend_is_true(low_severity)) { phalcon_call_method_noret(this_ptr, "listenlowseverity"); } @@ -227,7 +218,7 @@ PHP_METHOD(Phalcon_Debug, debugVar){ phalcon_fetch_params(1, 1, 1, &var, &key); if (!key) { - PHALCON_INIT_VAR(key); + key = PHALCON_GLOBAL(z_null); } PHALCON_INIT_VAR(ztime); @@ -307,7 +298,7 @@ PHP_METHOD(Phalcon_Debug, _escapeString){ */ PHP_METHOD(Phalcon_Debug, _getArrayDump){ - zval *argument, *n = NULL, *number_arguments, *one, *dump; + zval *argument, *n = NULL, *number_arguments, *dump; zval *v = NULL, *k = NULL, *var_dump = NULL, *escaped_string = NULL, *next = NULL, *array_dump = NULL; zval *class_name = NULL, *joined_dump; HashTable *ah0; @@ -329,9 +320,6 @@ PHP_METHOD(Phalcon_Debug, _getArrayDump){ if (PHALCON_GT_LONG(number_arguments, 0)) { if (PHALCON_LT_LONG(number_arguments, 10)) { - PHALCON_INIT_VAR(one); - ZVAL_LONG(one, 1); - PHALCON_INIT_VAR(dump); array_init(dump); @@ -357,7 +345,7 @@ PHP_METHOD(Phalcon_Debug, _getArrayDump){ } else { if (Z_TYPE_P(v) == IS_ARRAY) { PHALCON_INIT_NVAR(next); - phalcon_add_function(next, n, one TSRMLS_CC); + phalcon_add_function(next, n, PHALCON_GLOBAL(z_one) TSRMLS_CC); PHALCON_INIT_NVAR(array_dump); phalcon_call_method_p2(array_dump, this_ptr, "_getarraydump", v, next); @@ -994,13 +982,10 @@ PHP_METHOD(Phalcon_Debug, onUncaughtException){ zend_print_zval(message, 0); } - PHALCON_INIT_VAR(is_active); - ZVAL_TRUE(is_active); - /** * Globally block the debug component to avoid other exceptions must be shown */ - phalcon_update_static_property_ce(phalcon_debug_ce, SL("_isActive"), is_active TSRMLS_CC); + phalcon_update_static_property_ce(phalcon_debug_ce, SL("_isActive"), PHALCON_GLOBAL(z_true) TSRMLS_CC); PHALCON_INIT_VAR(class_name); phalcon_get_class(class_name, exception, 0 TSRMLS_CC); @@ -1219,13 +1204,10 @@ PHP_METHOD(Phalcon_Debug, onUncaughtException){ */ zend_print_zval(html, 0); - PHALCON_INIT_NVAR(is_active); - ZVAL_BOOL(is_active, 0); - /** * Unlock the exception renderer */ - phalcon_update_static_property_ce(phalcon_debug_ce, SL("_isActive"), is_active TSRMLS_CC); + phalcon_update_static_property_ce(phalcon_debug_ce, SL("_isActive"), PHALCON_GLOBAL(z_false) TSRMLS_CC); RETURN_MM_TRUE; } diff --git a/ext/di.c b/ext/di.c index 726709268a8..291abb502c1 100644 --- a/ext/di.c +++ b/ext/di.c @@ -128,8 +128,7 @@ PHP_METHOD(Phalcon_DI, set){ PHALCON_MM_GROW(); if (!shared) { - PHALCON_INIT_VAR(shared); - ZVAL_FALSE(shared); + shared = PHALCON_GLOBAL(z_false); } object_init_ex(return_value, phalcon_di_service_ce); @@ -149,7 +148,7 @@ PHP_METHOD(Phalcon_DI, set){ */ PHP_METHOD(Phalcon_DI, setShared){ - zval *name, *definition, *shared; + zval *name, *definition; phalcon_fetch_params(0, 2, 0, &name, &definition); @@ -160,11 +159,8 @@ PHP_METHOD(Phalcon_DI, setShared){ PHALCON_MM_GROW(); - PHALCON_INIT_VAR(shared); - ZVAL_TRUE(shared); - object_init_ex(return_value, phalcon_di_service_ce); - phalcon_call_method_p3_noret(return_value, "__construct", name, definition, shared); + phalcon_call_method_p3_noret(return_value, "__construct", name, definition, PHALCON_GLOBAL(z_true)); phalcon_update_property_array(this_ptr, SL("_services"), name, return_value TSRMLS_CC); @@ -216,8 +212,7 @@ PHP_METHOD(Phalcon_DI, attempt){ PHALCON_MM_GROW(); if (!shared) { - PHALCON_INIT_VAR(shared); - ZVAL_FALSE(shared); + shared = PHALCON_GLOBAL(z_false); } object_init_ex(return_value, phalcon_di_service_ce); @@ -343,7 +338,7 @@ PHP_METHOD(Phalcon_DI, get){ PHALCON_MM_GROW(); if (!parameters) { - PHALCON_INIT_VAR(parameters); + parameters = PHALCON_GLOBAL(z_null); } PHALCON_INIT_VAR(instance); @@ -414,14 +409,14 @@ PHP_METHOD(Phalcon_DI, getShared){ */ shared_instances = phalcon_fetch_nproperty_this(this_ptr, SL("_sharedInstances"), PH_NOISY_CC); if (phalcon_array_isset_fetch(&instance, shared_instances, name)) { - phalcon_update_property_bool(this_ptr, SL("_freshInstance"), 0 TSRMLS_CC); + phalcon_update_property_this(this_ptr, SL("_freshInstance"), PHALCON_GLOBAL(z_false) TSRMLS_CC); RETURN_CTORW(instance); } PHALCON_MM_GROW(); if (!parameters) { - PHALCON_INIT_VAR(parameters); + parameters = PHALCON_GLOBAL(z_null); } /** @@ -433,7 +428,7 @@ PHP_METHOD(Phalcon_DI, getShared){ * Save the instance in the first level shared */ phalcon_update_property_array(this_ptr, SL("_sharedInstances"), name, return_value TSRMLS_CC); - phalcon_update_property_bool(this_ptr, SL("_freshInstance"), 1 TSRMLS_CC); + phalcon_update_property_this(this_ptr, SL("_freshInstance"), PHALCON_GLOBAL(z_true) TSRMLS_CC); PHALCON_MM_RESTORE(); } @@ -542,7 +537,7 @@ PHP_METHOD(Phalcon_DI, __call){ phalcon_fetch_params(1, 1, 1, &method, &arguments); if (!arguments) { - PHALCON_INIT_VAR(arguments); + arguments = PHALCON_GLOBAL(z_null); } /** diff --git a/ext/di/factorydefault.c b/ext/di/factorydefault.c index 20979f2b7f1..2cdd473cf08 100644 --- a/ext/di/factorydefault.c +++ b/ext/di/factorydefault.c @@ -75,8 +75,7 @@ PHP_METHOD(Phalcon_DI_FactoryDefault, __construct){ phalcon_call_parent_noret(this_ptr, phalcon_di_factorydefault_ce, "__construct"); - PHALCON_INIT_VAR(shared); - ZVAL_BOOL(shared, 1); + shared = PHALCON_GLOBAL(z_true); PHALCON_INIT_VAR(name); ZVAL_STRING(name, "router", 1); diff --git a/ext/di/factorydefault/cli.c b/ext/di/factorydefault/cli.c index 1917c0e4c5d..64307f3e2a1 100644 --- a/ext/di/factorydefault/cli.c +++ b/ext/di/factorydefault/cli.c @@ -72,8 +72,7 @@ PHP_METHOD(Phalcon_DI_FactoryDefault_CLI, __construct){ phalcon_call_parent_noret(this_ptr, phalcon_di_factorydefault_cli_ce, "__construct"); - PHALCON_INIT_VAR(shared); - ZVAL_BOOL(shared, 1); + shared = PHALCON_GLOBAL(z_true); PHALCON_INIT_VAR(name); ZVAL_STRING(name, "router", 1); diff --git a/ext/di/service.c b/ext/di/service.c index 1014ccad489..1222961ea36 100644 --- a/ext/di/service.c +++ b/ext/di/service.c @@ -81,20 +81,15 @@ PHP_METHOD(Phalcon_DI_Service, __construct){ zval *name, *definition, *shared = NULL; - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 2, 1, &name, &definition, &shared); + phalcon_fetch_params(0, 2, 1, &name, &definition, &shared); if (!shared) { - PHALCON_INIT_VAR(shared); - ZVAL_BOOL(shared, 0); + shared = PHALCON_GLOBAL(z_false); } phalcon_update_property_this(this_ptr, SL("_name"), name TSRMLS_CC); phalcon_update_property_this(this_ptr, SL("_definition"), definition TSRMLS_CC); phalcon_update_property_this(this_ptr, SL("_shared"), shared TSRMLS_CC); - - PHALCON_MM_RESTORE(); } /** @@ -193,11 +188,11 @@ PHP_METHOD(Phalcon_DI_Service, resolve){ phalcon_fetch_params(1, 0, 2, ¶meters, &dependency_injector); if (!parameters) { - PHALCON_INIT_VAR(parameters); + parameters = PHALCON_GLOBAL(z_null); } if (!dependency_injector) { - PHALCON_INIT_VAR(dependency_injector); + dependency_injector = PHALCON_GLOBAL(z_null); } PHALCON_OBS_VAR(shared); @@ -215,13 +210,11 @@ PHP_METHOD(Phalcon_DI_Service, resolve){ } } - PHALCON_INIT_VAR(found); - ZVAL_BOOL(found, 1); + found = PHALCON_GLOBAL(z_true); PHALCON_INIT_VAR(instance); - PHALCON_OBS_VAR(definition); - phalcon_read_property_this(&definition, this_ptr, SL("_definition"), PH_NOISY_CC); + definition = phalcon_fetch_nproperty_this(this_ptr, SL("_definition"), PH_NOISY_CC); if (Z_TYPE_P(definition) == IS_STRING) { /** @@ -238,7 +231,7 @@ PHP_METHOD(Phalcon_DI_Service, resolve){ } } } else { - ZVAL_BOOL(found, 0); + found = PHALCON_GLOBAL(z_false); } } else { /** @@ -264,8 +257,7 @@ PHP_METHOD(Phalcon_DI_Service, resolve){ phalcon_call_method_p3(instance, builder, "build", dependency_injector, definition, parameters); } else { - PHALCON_INIT_NVAR(found); - ZVAL_BOOL(found, 0); + found = PHALCON_GLOBAL(z_false); } } } diff --git a/ext/di/service/builder.c b/ext/di/service/builder.c index 06543f949e1..4908a99b21f 100644 --- a/ext/di/service/builder.c +++ b/ext/di/service/builder.c @@ -254,7 +254,7 @@ PHP_METHOD(Phalcon_DI_Service_Builder, build){ phalcon_fetch_params(1, 2, 1, &dependency_injector, &definition, ¶meters); if (!parameters) { - PHALCON_INIT_VAR(parameters); + parameters = PHALCON_GLOBAL(z_null); } if (Z_TYPE_P(definition) != IS_ARRAY) { diff --git a/ext/dispatcher.c b/ext/dispatcher.c index f8926945c9c..0aaa260d8ad 100644 --- a/ext/dispatcher.c +++ b/ext/dispatcher.c @@ -512,7 +512,7 @@ PHP_METHOD(Phalcon_Dispatcher, dispatch){ /** * Do at least one dispatch */ - phalcon_update_property_bool(this_ptr, SL("_finished"), 0 TSRMLS_CC); + phalcon_update_property_this(this_ptr, SL("_finished"), PHALCON_GLOBAL(z_false) TSRMLS_CC); while (1) { @@ -539,7 +539,7 @@ PHP_METHOD(Phalcon_Dispatcher, dispatch){ break; } - phalcon_update_property_bool(this_ptr, SL("_finished"), 1 TSRMLS_CC); + phalcon_update_property_this(this_ptr, SL("_finished"), PHALCON_GLOBAL(z_true) TSRMLS_CC); /** * If the current namespace is null we used the set in this_ptr::_defaultNamespace @@ -1024,8 +1024,8 @@ PHP_METHOD(Phalcon_Dispatcher, forward){ phalcon_update_property_this(this_ptr, SL("_params"), params TSRMLS_CC); } - phalcon_update_property_bool(this_ptr, SL("_finished"), 0 TSRMLS_CC); - phalcon_update_property_bool(this_ptr, SL("_forwarded"), 1 TSRMLS_CC); + phalcon_update_property_this(this_ptr, SL("_finished"), PHALCON_GLOBAL(z_false) TSRMLS_CC); + phalcon_update_property_this(this_ptr, SL("_forwarded"), PHALCON_GLOBAL(z_true) TSRMLS_CC); } /** diff --git a/ext/escaper.c b/ext/escaper.c index 8abbc67e4e8..f6fdd3c2e06 100644 --- a/ext/escaper.c +++ b/ext/escaper.c @@ -165,8 +165,7 @@ PHP_METHOD(Phalcon_Escaper, detectEncoding){ /** * Strict encoding detection with fallback to non-strict detection. */ - PHALCON_INIT_VAR(strict_check); - ZVAL_BOOL(strict_check, 1); + strict_check = PHALCON_GLOBAL(z_true); PHALCON_INIT_NVAR(charset); ZVAL_STRING(charset, "UTF-32", 1); diff --git a/ext/events/event.c b/ext/events/event.c index baf1a191613..c1a1e72ca1b 100644 --- a/ext/events/event.c +++ b/ext/events/event.c @@ -71,17 +71,14 @@ PHP_METHOD(Phalcon_Events_Event, __construct){ zval *type, *source, *data = NULL, *cancelable = NULL; - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 2, 2, &type, &source, &data, &cancelable); + phalcon_fetch_params(0, 2, 2, &type, &source, &data, &cancelable); if (!data) { - PHALCON_INIT_VAR(data); + data = PHALCON_GLOBAL(z_null); } if (!cancelable) { - PHALCON_INIT_VAR(cancelable); - ZVAL_BOOL(cancelable, 1); + cancelable = PHALCON_GLOBAL(z_true); } phalcon_update_property_this(this_ptr, SL("_type"), type TSRMLS_CC); @@ -93,8 +90,6 @@ PHP_METHOD(Phalcon_Events_Event, __construct){ if (PHALCON_IS_NOT_TRUE(cancelable)) { phalcon_update_property_this(this_ptr, SL("_cancelable"), cancelable TSRMLS_CC); } - - PHALCON_MM_RESTORE(); } /** @@ -193,18 +188,13 @@ PHP_METHOD(Phalcon_Events_Event, stop){ zval *cancelable; - PHALCON_MM_GROW(); - - PHALCON_OBS_VAR(cancelable); - phalcon_read_property_this(&cancelable, this_ptr, SL("_cancelable"), PH_NOISY_CC); + cancelable = phalcon_fetch_nproperty_this(this_ptr, SL("_cancelable"), PH_NOISY_CC); if (zend_is_true(cancelable)) { phalcon_update_property_bool(this_ptr, SL("_stopped"), 1 TSRMLS_CC); } else { - PHALCON_THROW_EXCEPTION_STR(phalcon_events_exception_ce, "Trying to cancel a non-cancelable event"); + PHALCON_THROW_EXCEPTION_STRW(phalcon_events_exception_ce, "Trying to cancel a non-cancelable event"); return; } - - PHALCON_MM_RESTORE(); } /** @@ -215,4 +205,3 @@ PHP_METHOD(Phalcon_Events_Event, isStopped){ RETURN_MEMBER(this_ptr, "_stopped"); } - diff --git a/ext/events/manager.c b/ext/events/manager.c index 6db24f2d4e0..4550d744883 100644 --- a/ext/events/manager.c +++ b/ext/events/manager.c @@ -97,10 +97,10 @@ PHP_METHOD(Phalcon_Events_Manager, attach){ return; } - PHALCON_OBS_VAR(events); - phalcon_read_property_this(&events, this_ptr, SL("_events"), PH_NOISY_CC); - if (Z_TYPE_P(events) != IS_ARRAY) { - PHALCON_INIT_NVAR(events); + events = phalcon_fetch_nproperty_this(this_ptr, SL("_events"), PH_NOISY_CC); + if (Z_TYPE_P(events) != IS_ARRAY) { + SEPARATE_ZVAL_IF_NOT_REF(&events); + zval_dtor(events); array_init(events); } @@ -241,7 +241,7 @@ PHP_METHOD(Phalcon_Events_Manager, dettachAll){ phalcon_fetch_params(1, 0, 1, &type); if (!type) { - PHALCON_INIT_VAR(type); + type = PHALCON_GLOBAL(z_null); } PHALCON_OBS_VAR(events); @@ -611,12 +611,11 @@ PHP_METHOD(Phalcon_Events_Manager, fire){ phalcon_fetch_params(1, 2, 2, &event_type, &source, &data, &cancelable); if (!data) { - PHALCON_INIT_VAR(data); + data = PHALCON_GLOBAL(z_null); } if (!cancelable) { - PHALCON_INIT_VAR(cancelable); - ZVAL_BOOL(cancelable, 1); + cancelable = PHALCON_GLOBAL(z_true); } if (unlikely(Z_TYPE_P(event_type) != IS_STRING)) { @@ -624,8 +623,7 @@ PHP_METHOD(Phalcon_Events_Manager, fire){ return; } - PHALCON_OBS_VAR(events); - phalcon_read_property_this(&events, this_ptr, SL("_events"), PH_NOISY_CC); + events = phalcon_fetch_nproperty_this(this_ptr, SL("_events"), PH_NOISY_CC); if (Z_TYPE_P(events) != IS_ARRAY) { RETURN_MM_NULL(); } @@ -652,10 +650,9 @@ PHP_METHOD(Phalcon_Events_Manager, fire){ PHALCON_INIT_VAR(status); /** - * Responses must be traced? + * Should responses be traced? */ - PHALCON_OBS_VAR(collect); - phalcon_read_property_this(&collect, this_ptr, SL("_collect"), PH_NOISY_CC); + collect = phalcon_fetch_nproperty_this(this_ptr, SL("_collect"), PH_NOISY_CC); if (zend_is_true(collect)) { phalcon_update_property_null(this_ptr, SL("_responses") TSRMLS_CC); } @@ -665,10 +662,7 @@ PHP_METHOD(Phalcon_Events_Manager, fire){ /** * Check if events are grouped by type */ - if (phalcon_array_isset(events, type)) { - - PHALCON_OBS_VAR(fire_events); - phalcon_array_fetch(&fire_events, events, type, PH_NOISY); + if (phalcon_array_isset_fetch(&fire_events, events, type)) { if (Z_TYPE_P(fire_events) == IS_ARRAY || Z_TYPE_P(fire_events) == IS_OBJECT) { /** * Create the event context @@ -686,12 +680,8 @@ PHP_METHOD(Phalcon_Events_Manager, fire){ /** * Check if there are listeners for the event type itself */ - if (phalcon_array_isset(events, event_type)) { - - PHALCON_OBS_NVAR(fire_events); - phalcon_array_fetch(&fire_events, events, event_type, PH_NOISY); + if (phalcon_array_isset_fetch(&fire_events, events, event_type)) { if (Z_TYPE_P(fire_events) == IS_ARRAY || Z_TYPE_P(fire_events) == IS_OBJECT) { - /** * Create the event if it wasn't created before */ @@ -723,19 +713,14 @@ PHP_METHOD(Phalcon_Events_Manager, hasListeners){ zval *type, *events; - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 1, 0, &type); + phalcon_fetch_params(0, 1, 0, &type); - PHALCON_OBS_VAR(events); - phalcon_read_property_this(&events, this_ptr, SL("_events"), PH_NOISY_CC); - if (Z_TYPE_P(events) == IS_ARRAY) { - if (phalcon_array_isset(events, type)) { - RETURN_MM_TRUE; - } + events = phalcon_fetch_nproperty_this(this_ptr, SL("_events"), PH_NOISY_CC); + if (phalcon_array_isset(events, type)) { + RETURN_TRUE; } - RETURN_MM_FALSE; + RETURN_FALSE; } /** @@ -748,20 +733,12 @@ PHP_METHOD(Phalcon_Events_Manager, getListeners){ zval *type, *events, *fire_events; - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 1, 0, &type); + phalcon_fetch_params(0, 1, 0, &type); - PHALCON_OBS_VAR(events); - phalcon_read_property_this(&events, this_ptr, SL("_events"), PH_NOISY_CC); - if (Z_TYPE_P(events) == IS_ARRAY) { - if (phalcon_array_isset(events, type)) { - PHALCON_OBS_VAR(fire_events); - phalcon_array_fetch(&fire_events, events, type, PH_NOISY); - RETURN_CCTOR(fire_events); - } + events = phalcon_fetch_nproperty_this(this_ptr, SL("_events"), PH_NOISY_CC); + if (phalcon_array_isset_fetch(&fire_events, events, type)) { + RETURN_ZVAL(fire_events, 1, 0); } - RETURN_MM_EMPTY_ARRAY(); + array_init(return_value); } - diff --git a/ext/filter.c b/ext/filter.c index 8af9545ad4a..d7a0ff4a0b4 100644 --- a/ext/filter.c +++ b/ext/filter.c @@ -121,8 +121,7 @@ PHP_METHOD(Phalcon_Filter, sanitize){ phalcon_fetch_params(1, 2, 1, &value, &filters, &norecursive); if (!norecursive) { - PHALCON_INIT_VAR(norecursive); - ZVAL_FALSE(norecursive); + norecursive = PHALCON_GLOBAL(z_false); } /** diff --git a/ext/flash.c b/ext/flash.c index 5ff3cae9a17..cebe443d581 100644 --- a/ext/flash.c +++ b/ext/flash.c @@ -308,7 +308,7 @@ PHP_METHOD(Phalcon_Flash, outputMessage){ */ if (!flag_implicit_flush) { PHALCON_INIT_VAR(content); - ZVAL_STRING(content, "", 1); + ZVAL_EMPTY_STRING(content); } /** diff --git a/ext/flash/session.c b/ext/flash/session.c index c4c5238e6a0..82014f10eae 100644 --- a/ext/flash/session.c +++ b/ext/flash/session.c @@ -101,8 +101,7 @@ PHP_METHOD(Phalcon_Flash_Session, _getSessionMessages){ phalcon_fetch_params(1, 1, 0, &remove); - PHALCON_OBS_VAR(dependency_injector); - phalcon_read_property_this(&dependency_injector, this_ptr, SL("_dependencyInjector"), PH_NOISY_CC); + dependency_injector = phalcon_fetch_nproperty_this(this_ptr, SL("_dependencyInjector"), PH_NOISY_CC); if (unlikely(Z_TYPE_P(dependency_injector) != IS_OBJECT)) { PHALCON_THROW_EXCEPTION_STR(phalcon_flash_exception_ce, "A dependency injection container is required to access the 'session' service"); return; @@ -141,8 +140,7 @@ PHP_METHOD(Phalcon_Flash_Session, _setSessionMessages){ phalcon_fetch_params(1, 1, 0, &messages); - PHALCON_OBS_VAR(dependency_injector); - phalcon_read_property_this(&dependency_injector, this_ptr, SL("_dependencyInjector"), PH_NOISY_CC); + dependency_injector = phalcon_fetch_nproperty_this(this_ptr, SL("_dependencyInjector"), PH_NOISY_CC); if (unlikely(Z_TYPE_P(dependency_injector) != IS_OBJECT)) { PHALCON_THROW_EXCEPTION_STR(phalcon_flash_exception_ce, "A dependency injection container is required to access the 'session' service"); return; @@ -170,17 +168,14 @@ PHP_METHOD(Phalcon_Flash_Session, _setSessionMessages){ */ PHP_METHOD(Phalcon_Flash_Session, message){ - zval *type, *message, *remove, *messages = NULL, *empty_array; + zval *type, *message, *messages = NULL, *empty_array; PHALCON_MM_GROW(); phalcon_fetch_params(1, 2, 0, &type, &message); - PHALCON_INIT_VAR(remove); - ZVAL_BOOL(remove, 0); - PHALCON_INIT_VAR(messages); - phalcon_call_method_p1(messages, this_ptr, "_getsessionmessages", remove); + phalcon_call_method_p1(messages, this_ptr, "_getsessionmessages", PHALCON_GLOBAL(z_false)); if (Z_TYPE_P(messages) != IS_ARRAY) { PHALCON_INIT_NVAR(messages); array_init(messages); @@ -189,7 +184,7 @@ PHP_METHOD(Phalcon_Flash_Session, message){ if (!phalcon_array_isset(messages, type)) { PHALCON_INIT_VAR(empty_array); array_init(empty_array); - phalcon_array_update_zval(&messages, type, &empty_array, PH_COPY | PH_SEPARATE); + phalcon_array_update_zval(&messages, type, &empty_array, PH_COPY); } phalcon_array_update_append_multi_2(&messages, type, message, 0); @@ -214,21 +209,18 @@ PHP_METHOD(Phalcon_Flash_Session, getMessages){ phalcon_fetch_params(1, 0, 2, &type, &remove); if (!type) { - PHALCON_INIT_VAR(type); + type = PHALCON_GLOBAL(z_null); } if (!remove) { - PHALCON_INIT_VAR(remove); - ZVAL_BOOL(remove, 1); + remove = PHALCON_GLOBAL(z_true); } PHALCON_INIT_VAR(messages); phalcon_call_method_p1(messages, this_ptr, "_getsessionmessages", remove); if (Z_TYPE_P(messages) == IS_ARRAY) { if (likely(Z_TYPE_P(type) == IS_STRING)) { - if (phalcon_array_isset(messages, type)) { - PHALCON_OBS_VAR(return_messages); - phalcon_array_fetch(&return_messages, messages, type, PH_NOISY); + if (phalcon_array_isset_fetch(&return_messages, messages, type)) { RETURN_CCTOR(return_messages); } @@ -259,8 +251,7 @@ PHP_METHOD(Phalcon_Flash_Session, output){ phalcon_fetch_params(1, 0, 1, &remove); if (!remove) { - PHALCON_INIT_VAR(remove); - ZVAL_BOOL(remove, 1); + remove = PHALCON_GLOBAL(z_true); } PHALCON_INIT_VAR(messages); @@ -283,4 +274,3 @@ PHP_METHOD(Phalcon_Flash_Session, output){ PHALCON_MM_RESTORE(); } - diff --git a/ext/forms/element.c b/ext/forms/element.c index 11b0028218b..73b25995e0b 100644 --- a/ext/forms/element.c +++ b/ext/forms/element.c @@ -79,24 +79,17 @@ PHP_METHOD(Phalcon_Forms_Element, __construct){ zval *name, *attributes = NULL; - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 1, 1, &name, &attributes); - - if (!attributes) { - PHALCON_INIT_VAR(attributes); - } + phalcon_fetch_params(0, 1, 1, &name, &attributes); if (Z_TYPE_P(name) != IS_STRING) { - PHALCON_THROW_EXCEPTION_STR(phalcon_forms_exception_ce, "The element's name must be a string"); + PHALCON_THROW_EXCEPTION_STRW(phalcon_forms_exception_ce, "The element's name must be a string"); return; } + phalcon_update_property_this(this_ptr, SL("_name"), name TSRMLS_CC); - if (Z_TYPE_P(attributes) == IS_ARRAY) { + if (attributes && Z_TYPE_P(attributes) == IS_ARRAY) { phalcon_update_property_this(this_ptr, SL("_attributes"), attributes TSRMLS_CC); } - - PHALCON_MM_RESTORE(); } /** @@ -228,23 +221,21 @@ PHP_METHOD(Phalcon_Forms_Element, addValidators){ phalcon_fetch_params(1, 1, 1, &validators, &merge); if (!merge) { - PHALCON_INIT_VAR(merge); - ZVAL_BOOL(merge, 1); + merge = PHALCON_GLOBAL(z_true); } if (Z_TYPE_P(validators) != IS_ARRAY) { PHALCON_THROW_EXCEPTION_STR(phalcon_forms_exception_ce, "The validators parameter must be an array"); return; } + if (zend_is_true(merge)) { - - PHALCON_OBS_VAR(current_validators); - phalcon_read_property_this(¤t_validators, this_ptr, SL("_validators"), PH_NOISY_CC); + current_validators = phalcon_fetch_nproperty_this(this_ptr, SL("_validators"), PH_NOISY_CC); if (Z_TYPE_P(current_validators) == IS_ARRAY) { PHALCON_INIT_VAR(merged_validators); phalcon_fast_array_merge(merged_validators, ¤t_validators, &validators TSRMLS_CC); } else { - PHALCON_CPY_WRT(merged_validators, validators); + merged_validators = validators; } phalcon_update_property_this(this_ptr, SL("_validators"), merged_validators TSRMLS_CC); @@ -304,16 +295,14 @@ PHP_METHOD(Phalcon_Forms_Element, prepareAttributes){ phalcon_fetch_params(1, 0, 2, &attributes, &use_checked); if (!attributes) { - PHALCON_INIT_VAR(attributes); + attributes = PHALCON_GLOBAL(z_null); } if (!use_checked) { - PHALCON_INIT_VAR(use_checked); - ZVAL_BOOL(use_checked, 0); + use_checked = PHALCON_GLOBAL(z_false); } - PHALCON_OBS_VAR(name); - phalcon_read_property_this(&name, this_ptr, SL("_name"), PH_NOISY_CC); + name = phalcon_fetch_nproperty_this(this_ptr, SL("_name"), PH_NOISY_CC); /** * Create an array of parameters @@ -330,13 +319,12 @@ PHP_METHOD(Phalcon_Forms_Element, prepareAttributes){ /** * Merge passed parameters with default ones */ - PHALCON_OBS_VAR(default_attributes); - phalcon_read_property_this(&default_attributes, this_ptr, SL("_attributes"), PH_NOISY_CC); + default_attributes = phalcon_fetch_nproperty_this(this_ptr, SL("_attributes"), PH_NOISY_CC); if (Z_TYPE_P(default_attributes) == IS_ARRAY) { PHALCON_INIT_VAR(merged_attributes); phalcon_fast_array_merge(merged_attributes, &default_attributes, &widget_attributes TSRMLS_CC); } else { - PHALCON_CPY_WRT(merged_attributes, widget_attributes); + merged_attributes = widget_attributes; } /** @@ -355,10 +343,7 @@ PHP_METHOD(Phalcon_Forms_Element, prepareAttributes){ * Check if the element already has a default value, compare it with the one in the * attributes, if they are the same mark the element as checked */ - if (phalcon_array_isset_string(merged_attributes, SS("value"))) { - - PHALCON_OBS_VAR(current_value); - phalcon_array_fetch_string(¤t_value, merged_attributes, SL("value"), PH_NOISY); + if (phalcon_array_isset_string_fetch(¤t_value, merged_attributes, SS("value"))) { if (PHALCON_IS_EQUAL(current_value, value)) { phalcon_array_update_string_string(&merged_attributes, SL("checked"), SL("checked"), PH_SEPARATE); } @@ -376,7 +361,7 @@ PHP_METHOD(Phalcon_Forms_Element, prepareAttributes){ } } - RETURN_CCTOR(merged_attributes); + RETURN_CTOR(merged_attributes); } /** @@ -408,23 +393,18 @@ PHP_METHOD(Phalcon_Forms_Element, getAttribute){ zval *attribute, *default_value = NULL, *attributes; zval *value; - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 1, 1, &attribute, &default_value); + phalcon_fetch_params(0, 1, 1, &attribute, &default_value); if (!default_value) { - PHALCON_INIT_VAR(default_value); + default_value = PHALCON_GLOBAL(z_null); } - PHALCON_OBS_VAR(attributes); - phalcon_read_property_this(&attributes, this_ptr, SL("_attributes"), PH_NOISY_CC); - if (phalcon_array_isset(attributes, attribute)) { - PHALCON_OBS_VAR(value); - phalcon_array_fetch(&value, attributes, attribute, PH_NOISY); - RETURN_CCTOR(value); + attributes = phalcon_fetch_nproperty_this(this_ptr, SL("_attributes"), PH_NOISY_CC); + if (phalcon_array_isset_fetch(&value, attributes, attribute)) { + RETURN_ZVAL(value, 1, 0); } - RETURN_CCTOR(default_value); + RETURN_ZVAL(default_value, 1, 0); } /** @@ -457,15 +437,13 @@ PHP_METHOD(Phalcon_Forms_Element, getAttributes){ zval *attributes; - PHALCON_MM_GROW(); - - PHALCON_OBS_VAR(attributes); - phalcon_read_property_this(&attributes, this_ptr, SL("_attributes"), PH_NOISY_CC); + attributes = phalcon_fetch_nproperty_this(this_ptr, SL("_attributes"), PH_NOISY_CC); if (Z_TYPE_P(attributes) != IS_ARRAY) { - RETURN_MM_EMPTY_ARRAY(); + array_init(return_value); + return; } - RETURN_CCTOR(attributes); + RETURN_ZVAL(attributes, 1, 0); } /** @@ -501,18 +479,15 @@ PHP_METHOD(Phalcon_Forms_Element, getUserOption){ phalcon_fetch_params(1, 1, 1, &option, &default_value); if (!default_value) { - PHALCON_INIT_VAR(default_value); + default_value = PHALCON_GLOBAL(z_null); } - PHALCON_OBS_VAR(options); - phalcon_read_property_this(&options, this_ptr, SL("_options"), PH_NOISY_CC); - if (phalcon_array_isset(options, option)) { - PHALCON_OBS_VAR(value); - phalcon_array_fetch(&value, options, option, PH_NOISY); - RETURN_CCTOR(value); + options = phalcon_fetch_nproperty_this(this_ptr, SL("_options"), PH_NOISY_CC); + if (phalcon_array_isset_fetch(&value, options, option)) { + RETURN_ZVAL(value, 1, 0); } - RETURN_CCTOR(default_value); + RETURN_ZVAL(default_value, 1, 0); } /** @@ -591,18 +566,13 @@ PHP_METHOD(Phalcon_Forms_Element, label){ phalcon_fetch_params(1, 0, 1, &attributes); - PHALCON_OBS_VAR(label); - phalcon_read_property_this(&label, this_ptr, SL("_label"), PH_NOISY_CC); + label = phalcon_fetch_nproperty_this(this_ptr, SL("_label"), PH_NOISY_CC); /** * Check if there is an 'id' attribute defined */ - if (attributes && phalcon_array_isset_string(attributes, SS("id"))) { - PHALCON_OBS_VAR(name); - phalcon_array_fetch_string(&name, attributes, SL("id"), PH_NOISY); - } else { - PHALCON_OBS_NVAR(name); - phalcon_read_property_this(&name, this_ptr, SL("_name"), PH_NOISY_CC); + if (!attributes || !phalcon_array_isset_string_fetch(&name, attributes, SS("id"))) { + name = phalcon_fetch_nproperty_this(this_ptr, SL("_name"), PH_NOISY_CC); } PHALCON_INIT_VAR(escaped); @@ -636,12 +606,12 @@ PHP_METHOD(Phalcon_Forms_Element, label){ * Use the default label or leave the same name as label */ if (zend_is_true(label)) { - PHALCON_SCONCAT_SVS(html, ">", label, ""); + PHALCON_CONCAT_VSVS(return_value, html, ">", label, ""); } else { - PHALCON_SCONCAT_SVS(html, ">", name, ""); + PHALCON_CONCAT_VSVS(return_value, html, ">", name, ""); } - RETURN_CTOR(html); + PHALCON_MM_RESTORE(); } /** @@ -683,16 +653,14 @@ PHP_METHOD(Phalcon_Forms_Element, getValue){ PHALCON_MM_GROW(); - PHALCON_OBS_VAR(name); - phalcon_read_property_this(&name, this_ptr, SL("_name"), PH_NOISY_CC); + name = phalcon_fetch_nproperty_this(this_ptr, SL("_name"), PH_NOISY_CC); PHALCON_INIT_VAR(value); /** * Get the related form */ - PHALCON_OBS_VAR(form); - phalcon_read_property_this(&form, this_ptr, SL("_form"), PH_NOISY_CC); + form = phalcon_fetch_nproperty_this(this_ptr, SL("_form"), PH_NOISY_CC); if (Z_TYPE_P(form) == IS_OBJECT) { /** @@ -758,20 +726,17 @@ PHP_METHOD(Phalcon_Forms_Element, hasMessages){ zval *messages; - PHALCON_MM_GROW(); - /** * Get the related form */ - PHALCON_OBS_VAR(messages); - phalcon_read_property_this(&messages, this_ptr, SL("_messages"), PH_NOISY_CC); + messages = phalcon_fetch_nproperty_this(this_ptr, SL("_messages"), PH_NOISY_CC); if (Z_TYPE_P(messages) == IS_OBJECT) { if (phalcon_fast_count_ev(messages TSRMLS_CC)) { - RETURN_MM_TRUE; + RETURN_TRUE; } } - RETURN_MM_FALSE; + RETURN_FALSE; } /** @@ -831,29 +796,21 @@ PHP_METHOD(Phalcon_Forms_Element, appendMessage){ */ PHP_METHOD(Phalcon_Forms_Element, clear){ - zval *znull, *name; + zval *name; PHALCON_MM_GROW(); - PHALCON_INIT_VAR(znull); - - PHALCON_OBS_VAR(name); - phalcon_read_property_this(&name, this_ptr, SL("_name"), PH_NOISY_CC); - phalcon_call_static_p2_noret("phalcon\\tag", "setdefault", name, znull); + name = phalcon_fetch_nproperty_this(this_ptr, SL("_name"), PH_NOISY_CC); + phalcon_call_static_p2_noret("phalcon\\tag", "setdefault", name, PHALCON_GLOBAL(z_null)); RETURN_THIS(); } /** - * Magic method __toString renders the widget without atttributes + * Magic method __toString renders the widget without attributes * * @return string */ PHP_METHOD(Phalcon_Forms_Element, __toString){ - - PHALCON_MM_GROW(); - - phalcon_call_method(return_value, this_ptr, "render"); - RETURN_MM(); + phalcon_call_method_params(return_value, return_value_ptr, this_ptr, SL("render"), zend_inline_hash_func(SS("render")) TSRMLS_CC, 0); } - diff --git a/ext/forms/element.h b/ext/forms/element.h index 461d436a179..40a3e5ee96d 100644 --- a/ext/forms/element.h +++ b/ext/forms/element.h @@ -169,7 +169,7 @@ PHALCON_INIT_FUNCS(phalcon_forms_element_method_entry){ PHP_ME(Phalcon_Forms_Element, setMessages, arginfo_phalcon_forms_element_setmessages, ZEND_ACC_PUBLIC) PHP_ME(Phalcon_Forms_Element, appendMessage, arginfo_phalcon_forms_element_appendmessage, ZEND_ACC_PUBLIC) PHP_ME(Phalcon_Forms_Element, clear, NULL, ZEND_ACC_PUBLIC) - PHP_ME(Phalcon_Forms_Element, __toString, NULL, ZEND_ACC_PUBLIC) + PHP_ME(Phalcon_Forms_Element, __toString, NULL, ZEND_ACC_PUBLIC) PHP_FE_END }; diff --git a/ext/forms/element/check.c b/ext/forms/element/check.c index 904c727d29f..0867c5cda18 100644 --- a/ext/forms/element/check.c +++ b/ext/forms/element/check.c @@ -61,21 +61,18 @@ PHALCON_INIT_CLASS(Phalcon_Forms_Element_Check){ */ PHP_METHOD(Phalcon_Forms_Element_Check, render){ - zval *attributes = NULL, *use_checked, *widget_attributes; + zval *attributes = NULL, *widget_attributes; PHALCON_MM_GROW(); phalcon_fetch_params(1, 0, 1, &attributes); if (!attributes) { - PHALCON_INIT_VAR(attributes); + attributes = PHALCON_GLOBAL(z_null); } - PHALCON_INIT_VAR(use_checked); - ZVAL_BOOL(use_checked, 1); - PHALCON_INIT_VAR(widget_attributes); - phalcon_call_method_p2(widget_attributes, this_ptr, "prepareattributes", attributes, use_checked); + phalcon_call_method_p2(widget_attributes, this_ptr, "prepareattributes", attributes, PHALCON_GLOBAL(z_true)); phalcon_call_static_p1(return_value, "phalcon\\tag", "checkfield", widget_attributes); RETURN_MM(); } diff --git a/ext/forms/element/date.c b/ext/forms/element/date.c index 1ba6a874207..2886662418f 100644 --- a/ext/forms/element/date.c +++ b/ext/forms/element/date.c @@ -68,7 +68,7 @@ PHP_METHOD(Phalcon_Forms_Element_Date, render){ phalcon_fetch_params(1, 0, 1, &attributes); if (!attributes) { - PHALCON_INIT_VAR(attributes); + attributes = PHALCON_GLOBAL(z_null); } PHALCON_INIT_VAR(widget_attributes); diff --git a/ext/forms/element/email.c b/ext/forms/element/email.c index 1971b4a7be5..5287499bc3a 100644 --- a/ext/forms/element/email.c +++ b/ext/forms/element/email.c @@ -68,7 +68,7 @@ PHP_METHOD(Phalcon_Forms_Element_Email, render){ phalcon_fetch_params(1, 0, 1, &attributes); if (!attributes) { - PHALCON_INIT_VAR(attributes); + attributes = PHALCON_GLOBAL(z_null); } PHALCON_INIT_VAR(widget_attributes); diff --git a/ext/forms/element/file.c b/ext/forms/element/file.c index d3268e7c7bb..4e80f07d965 100644 --- a/ext/forms/element/file.c +++ b/ext/forms/element/file.c @@ -68,7 +68,7 @@ PHP_METHOD(Phalcon_Forms_Element_File, render){ phalcon_fetch_params(1, 0, 1, &attributes); if (!attributes) { - PHALCON_INIT_VAR(attributes); + attributes = PHALCON_GLOBAL(z_null); } PHALCON_INIT_VAR(widget_attributes); diff --git a/ext/forms/element/hidden.c b/ext/forms/element/hidden.c index 9fa6b1bc5dc..1d4ad860a05 100644 --- a/ext/forms/element/hidden.c +++ b/ext/forms/element/hidden.c @@ -68,7 +68,7 @@ PHP_METHOD(Phalcon_Forms_Element_Hidden, render){ phalcon_fetch_params(1, 0, 1, &attributes); if (!attributes) { - PHALCON_INIT_VAR(attributes); + attributes = PHALCON_GLOBAL(z_null); } PHALCON_INIT_VAR(widget_attributes); diff --git a/ext/forms/element/numeric.c b/ext/forms/element/numeric.c index 27616920126..3f664eb75c2 100644 --- a/ext/forms/element/numeric.c +++ b/ext/forms/element/numeric.c @@ -68,7 +68,7 @@ PHP_METHOD(Phalcon_Forms_Element_Numeric, render){ phalcon_fetch_params(1, 0, 1, &attributes); if (!attributes) { - PHALCON_INIT_VAR(attributes); + attributes = PHALCON_GLOBAL(z_null); } PHALCON_INIT_VAR(widget_attributes); diff --git a/ext/forms/element/password.c b/ext/forms/element/password.c index 90e2b3b2b9c..fedf6de7a62 100644 --- a/ext/forms/element/password.c +++ b/ext/forms/element/password.c @@ -68,7 +68,7 @@ PHP_METHOD(Phalcon_Forms_Element_Password, render){ phalcon_fetch_params(1, 0, 1, &attributes); if (!attributes) { - PHALCON_INIT_VAR(attributes); + attributes = PHALCON_GLOBAL(z_null); } PHALCON_INIT_VAR(widget_attributes); diff --git a/ext/forms/element/select.c b/ext/forms/element/select.c index 6d5c79322c3..df76e8af230 100644 --- a/ext/forms/element/select.c +++ b/ext/forms/element/select.c @@ -72,11 +72,11 @@ PHP_METHOD(Phalcon_Forms_Element_Select, __construct){ phalcon_fetch_params(1, 1, 2, &name, &options, &attributes); if (!options) { - PHALCON_INIT_VAR(options); + options = PHALCON_GLOBAL(z_null); } if (!attributes) { - PHALCON_INIT_VAR(attributes); + attributes = PHALCON_GLOBAL(z_null); } phalcon_update_property_this(this_ptr, SL("_optionsValues"), options TSRMLS_CC); @@ -143,7 +143,7 @@ PHP_METHOD(Phalcon_Forms_Element_Select, render){ phalcon_fetch_params(1, 0, 1, &attributes); if (!attributes) { - PHALCON_INIT_VAR(attributes); + attributes = PHALCON_GLOBAL(z_null); } PHALCON_OBS_VAR(options); diff --git a/ext/forms/element/submit.c b/ext/forms/element/submit.c index f52c3914f0a..93d52abc70f 100644 --- a/ext/forms/element/submit.c +++ b/ext/forms/element/submit.c @@ -68,7 +68,7 @@ PHP_METHOD(Phalcon_Forms_Element_Submit, render){ phalcon_fetch_params(1, 0, 1, &attributes); if (!attributes) { - PHALCON_INIT_VAR(attributes); + attributes = PHALCON_GLOBAL(z_null); } PHALCON_INIT_VAR(widget_attributes); diff --git a/ext/forms/element/text.c b/ext/forms/element/text.c index 0c803dd6de8..004ab7ada81 100644 --- a/ext/forms/element/text.c +++ b/ext/forms/element/text.c @@ -68,7 +68,7 @@ PHP_METHOD(Phalcon_Forms_Element_Text, render){ phalcon_fetch_params(1, 0, 1, &attributes); if (!attributes) { - PHALCON_INIT_VAR(attributes); + attributes = PHALCON_GLOBAL(z_null); } PHALCON_INIT_VAR(widget_attributes); diff --git a/ext/forms/element/textarea.c b/ext/forms/element/textarea.c index 171c400cae5..bd307f6913c 100644 --- a/ext/forms/element/textarea.c +++ b/ext/forms/element/textarea.c @@ -68,7 +68,7 @@ PHP_METHOD(Phalcon_Forms_Element_TextArea, render){ phalcon_fetch_params(1, 0, 1, &attributes); if (!attributes) { - PHALCON_INIT_VAR(attributes); + attributes = PHALCON_GLOBAL(z_null); } PHALCON_INIT_VAR(widget_attributes); diff --git a/ext/forms/form.c b/ext/forms/form.c index ed302474a24..00047caf789 100644 --- a/ext/forms/form.c +++ b/ext/forms/form.c @@ -84,11 +84,11 @@ PHP_METHOD(Phalcon_Forms_Form, __construct){ phalcon_fetch_params(1, 0, 2, &entity, &user_options); if (!entity) { - PHALCON_INIT_VAR(entity); + entity = PHALCON_GLOBAL(z_null); } if (!user_options) { - PHALCON_INIT_VAR(user_options); + user_options = PHALCON_GLOBAL(z_null); } if (Z_TYPE_P(entity) != IS_NULL) { @@ -171,23 +171,19 @@ PHP_METHOD(Phalcon_Forms_Form, getUserOption){ zval *option, *default_value = NULL, *options, *value; - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 1, 1, &option, &default_value); + phalcon_fetch_params(0, 1, 1, &option, &default_value); if (!default_value) { - PHALCON_INIT_VAR(default_value); + default_value = PHALCON_GLOBAL(z_null); } PHALCON_OBS_VAR(options); - phalcon_read_property_this(&options, this_ptr, SL("_options"), PH_NOISY_CC); - if (phalcon_array_isset(options, option)) { - PHALCON_OBS_VAR(value); - phalcon_array_fetch(&value, options, option, PH_NOISY); - RETURN_CCTOR(value); + options = phalcon_fetch_nproperty_this(this_ptr, SL("_options"), PH_NOISY_CC); + if (phalcon_array_isset_fetch(&value, options, option)) { + RETURN_ZVAL(value, 1, 0); } - RETURN_CCTOR(default_value); + RETURN_ZVAL(default_value, 1, 0); } /** @@ -283,7 +279,7 @@ PHP_METHOD(Phalcon_Forms_Form, bind){ phalcon_fetch_params(1, 2, 1, &data, &entity, &whitelist); if (!whitelist) { - PHALCON_INIT_VAR(whitelist); + whitelist = PHALCON_GLOBAL(z_null); } /** @@ -405,17 +401,14 @@ PHP_METHOD(Phalcon_Forms_Form, isValid){ phalcon_fetch_params(1, 0, 2, &data, &entity); if (!data) { - PHALCON_INIT_VAR(data); - } else { - PHALCON_SEPARATE_PARAM(data); + data = PHALCON_GLOBAL(z_null); } if (!entity) { - PHALCON_INIT_VAR(entity); + entity = PHALCON_GLOBAL(z_null); } - PHALCON_OBS_VAR(elements); - phalcon_read_property_this(&elements, this_ptr, SL("_elements"), PH_NOISY_CC); + elements = phalcon_fetch_nproperty_this(this_ptr, SL("_elements"), PH_NOISY_CC); if (Z_TYPE_P(elements) != IS_ARRAY) { RETURN_MM_TRUE; } @@ -431,8 +424,7 @@ PHP_METHOD(Phalcon_Forms_Form, isValid){ * If the data is not an array use the one passed previously */ if (Z_TYPE_P(data) != IS_ARRAY) { - PHALCON_OBS_NVAR(data); - phalcon_read_property_this(&data, this_ptr, SL("_data"), PH_NOISY_CC); + data = phalcon_fetch_nproperty_this(this_ptr, SL("_data"), PH_NOISY_CC); } /** @@ -447,8 +439,7 @@ PHP_METHOD(Phalcon_Forms_Form, isValid){ } } - PHALCON_INIT_VAR(not_failed); - ZVAL_BOOL(not_failed, 1); + not_failed = PHALCON_GLOBAL(z_true); PHALCON_INIT_VAR(messages); array_init(messages); @@ -484,8 +475,8 @@ PHP_METHOD(Phalcon_Forms_Form, isValid){ PHALCON_INIT_NVAR(scope); array_init_size(scope, 2); - phalcon_array_append(&scope, name, PH_SEPARATE); - phalcon_array_append(&scope, validator, PH_SEPARATE); + phalcon_array_append(&scope, name, 0); + phalcon_array_append(&scope, validator, 0); phalcon_array_append(&prepared_validators, scope, PH_SEPARATE); zend_hash_move_forward_ex(ah1, &hp1); @@ -523,8 +514,7 @@ PHP_METHOD(Phalcon_Forms_Form, isValid){ phalcon_call_method(name, element, "getname"); phalcon_array_update_zval(&messages, name, &element_messages, PH_COPY | PH_SEPARATE); - PHALCON_INIT_NVAR(not_failed); - ZVAL_BOOL(not_failed, 0); + not_failed = PHALCON_GLOBAL(z_false); } } } @@ -557,11 +547,11 @@ PHP_METHOD(Phalcon_Forms_Form, isValid){ * Returns the messages generated in the validation * * @param boolean $byItemName - * @return array + * @return Phalcon\Validation\Message\Group */ PHP_METHOD(Phalcon_Forms_Form, getMessages){ - zval *by_item_name = NULL, *messages, *group, *element_messages = NULL; + zval *by_item_name = NULL, *messages, *element_messages = NULL; zval *element = NULL; HashTable *ah0; HashPosition hp0; @@ -572,12 +562,10 @@ PHP_METHOD(Phalcon_Forms_Form, getMessages){ phalcon_fetch_params(1, 0, 1, &by_item_name); if (!by_item_name) { - PHALCON_INIT_VAR(by_item_name); - ZVAL_BOOL(by_item_name, 0); + by_item_name = PHALCON_GLOBAL(z_false); } - PHALCON_OBS_VAR(messages); - phalcon_read_property_this(&messages, this_ptr, SL("_messages"), PH_NOISY_CC); + messages = phalcon_fetch_nproperty_this(this_ptr, SL("_messages"), PH_NOISY_CC); if (zend_is_true(by_item_name)) { if (Z_TYPE_P(messages) != IS_ARRAY) { object_init_ex(return_value, phalcon_validation_message_group_ce); @@ -589,9 +577,8 @@ PHP_METHOD(Phalcon_Forms_Form, getMessages){ RETURN_CCTOR(messages); } - PHALCON_INIT_VAR(group); - object_init_ex(group, phalcon_validation_message_group_ce); - phalcon_call_method_noret(group, "__construct"); + object_init_ex(return_value, phalcon_validation_message_group_ce); + phalcon_call_method_noret(return_value, "__construct"); phalcon_is_iterable(messages, &ah0, &hp0, 0, 0); @@ -600,12 +587,12 @@ PHP_METHOD(Phalcon_Forms_Form, getMessages){ PHALCON_GET_HKEY(element, ah0, hp0); PHALCON_GET_HVALUE(element_messages); - phalcon_call_method_p1_noret(group, "appendmessages", element_messages); + phalcon_call_method_p1_noret(return_value, "appendmessages", element_messages); zend_hash_move_forward_ex(ah0, &hp0); } - RETURN_CTOR(group); + PHALCON_MM_RESTORE(); } /** @@ -615,27 +602,23 @@ PHP_METHOD(Phalcon_Forms_Form, getMessages){ */ PHP_METHOD(Phalcon_Forms_Form, getMessagesFor){ - zval *name, *messages, *element_messages, *group; + zval *name, *messages, *element_messages; PHALCON_MM_GROW(); phalcon_fetch_params(1, 1, 0, &name); - PHALCON_OBS_VAR(messages); - phalcon_read_property_this(&messages, this_ptr, SL("_messages"), PH_NOISY_CC); - if (phalcon_array_isset(messages, name)) { - PHALCON_OBS_VAR(element_messages); - phalcon_array_fetch(&element_messages, messages, name, PH_NOISY); + messages = phalcon_fetch_nproperty_this(this_ptr, SL("_messages"), PH_NOISY_CC); + if (phalcon_array_isset_fetch(&element_messages, messages, name)) { RETURN_CCTOR(element_messages); } - PHALCON_INIT_VAR(group); - object_init_ex(group, phalcon_validation_message_group_ce); - phalcon_call_method_noret(group, "__construct"); + object_init_ex(return_value, phalcon_validation_message_group_ce); + phalcon_call_method_noret(return_value, "__construct"); - phalcon_update_property_array(this_ptr, SL("_messages"), name, group TSRMLS_CC); + phalcon_update_property_array(this_ptr, SL("_messages"), name, return_value TSRMLS_CC); - RETURN_CTOR(group); + PHALCON_MM_RESTORE(); } /** @@ -647,19 +630,14 @@ PHP_METHOD(Phalcon_Forms_Form, hasMessagesFor){ zval *name, *messages, *element_messages; - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 1, 0, &name); + phalcon_fetch_params(0, 1, 0, &name); - PHALCON_OBS_VAR(messages); - phalcon_read_property_this(&messages, this_ptr, SL("_messages"), PH_NOISY_CC); - if (phalcon_array_isset(messages, name)) { - PHALCON_OBS_VAR(element_messages); - phalcon_array_fetch(&element_messages, messages, name, PH_NOISY); - RETURN_CCTOR(element_messages); + messages = phalcon_fetch_nproperty_this(this_ptr, SL("_messages"), PH_NOISY_CC); + if (phalcon_array_isset_fetch(&element_messages, messages, name)) { + RETURN_ZVAL(element_messages, 1, 0); } - RETURN_MM_FALSE; + RETURN_FALSE; } /** @@ -710,14 +688,14 @@ PHP_METHOD(Phalcon_Forms_Form, add){ PHP_METHOD(Phalcon_Forms_Form, render){ zval *name, *attributes = NULL, *elements, *exception_message; - zval *element, *code; + zval *element; PHALCON_MM_GROW(); phalcon_fetch_params(1, 1, 1, &name, &attributes); if (!attributes) { - PHALCON_INIT_VAR(attributes); + attributes = PHALCON_GLOBAL(z_null); } if (Z_TYPE_P(name) != IS_STRING) { @@ -725,22 +703,17 @@ PHP_METHOD(Phalcon_Forms_Form, render){ return; } - PHALCON_OBS_VAR(elements); - phalcon_read_property_this(&elements, this_ptr, SL("_elements"), PH_NOISY_CC); - if (!phalcon_array_isset(elements, name)) { + elements = phalcon_fetch_nproperty_this(this_ptr, SL("_elements"), PH_NOISY_CC); + if (!phalcon_array_isset_fetch(&element, elements, name)) { PHALCON_INIT_VAR(exception_message); PHALCON_CONCAT_SVS(exception_message, "Element with ID=", name, " is not part of the form"); PHALCON_THROW_EXCEPTION_ZVAL(phalcon_forms_exception_ce, exception_message); return; } - PHALCON_OBS_VAR(element); - phalcon_array_fetch(&element, elements, name, PH_NOISY); + phalcon_call_method_p1(return_value, element, "render", attributes); - PHALCON_INIT_VAR(code); - phalcon_call_method_p1(code, element, "render", attributes); - - RETURN_CCTOR(code); + PHALCON_MM_RESTORE(); } /** @@ -753,23 +726,18 @@ PHP_METHOD(Phalcon_Forms_Form, get){ zval *name, *elements, *exception_message, *element; - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 1, 0, &name); + phalcon_fetch_params(0, 1, 0, &name); - PHALCON_OBS_VAR(elements); - phalcon_read_property_this(&elements, this_ptr, SL("_elements"), PH_NOISY_CC); - if (!phalcon_array_isset(elements, name)) { + elements = phalcon_fetch_nproperty_this(this_ptr, SL("_elements"), PH_NOISY_CC); + if (!phalcon_array_isset_fetch(&element, elements, name)) { + PHALCON_MM_GROW(); PHALCON_INIT_VAR(exception_message); PHALCON_CONCAT_SVS(exception_message, "Element with ID=", name, " is not part of the form"); PHALCON_THROW_EXCEPTION_ZVAL(phalcon_forms_exception_ce, exception_message); return; } - PHALCON_OBS_VAR(element); - phalcon_array_fetch(&element, elements, name, PH_NOISY); - - RETURN_CCTOR(element); + RETURN_ZVAL(element, 1, 0); } /** @@ -781,32 +749,26 @@ PHP_METHOD(Phalcon_Forms_Form, get){ PHP_METHOD(Phalcon_Forms_Form, label){ zval *name, *attributes = NULL, *elements, *exception_message, *element; - zval *html; PHALCON_MM_GROW(); phalcon_fetch_params(1, 1, 1, &name, &attributes); if (!attributes) { - PHALCON_INIT_VAR(attributes); + attributes = PHALCON_GLOBAL(z_null); } - PHALCON_OBS_VAR(elements); - phalcon_read_property_this(&elements, this_ptr, SL("_elements"), PH_NOISY_CC); - if (!phalcon_array_isset(elements, name)) { + elements = phalcon_fetch_nproperty_this(this_ptr, SL("_elements"), PH_NOISY_CC); + if (!phalcon_array_isset_fetch(&element, elements, name)) { PHALCON_INIT_VAR(exception_message); PHALCON_CONCAT_SVS(exception_message, "Element with ID=", name, " is not part of the form"); PHALCON_THROW_EXCEPTION_ZVAL(phalcon_forms_exception_ce, exception_message); return; } - PHALCON_OBS_VAR(element); - phalcon_array_fetch(&element, elements, name, PH_NOISY); + phalcon_call_method_p1(return_value, element, "label", attributes); - PHALCON_INIT_VAR(html); - phalcon_call_method_p1(html, element, "label", attributes); - - RETURN_CCTOR(html); + PHALCON_MM_RESTORE(); } /** @@ -824,18 +786,14 @@ PHP_METHOD(Phalcon_Forms_Form, getLabel){ phalcon_fetch_params(1, 1, 0, &name); - PHALCON_OBS_VAR(elements); - phalcon_read_property_this(&elements, this_ptr, SL("_elements"), PH_NOISY_CC); - if (!phalcon_array_isset(elements, name)) { + elements = phalcon_fetch_nproperty_this(this_ptr, SL("_elements"), PH_NOISY_CC); + if (!phalcon_array_isset_fetch(&element, elements, name)) { PHALCON_INIT_VAR(exception_message); PHALCON_CONCAT_SVS(exception_message, "Element with ID=", name, " is not part of the form"); PHALCON_THROW_EXCEPTION_ZVAL(phalcon_forms_exception_ce, exception_message); return; } - PHALCON_OBS_VAR(element); - phalcon_array_fetch(&element, elements, name, PH_NOISY); - PHALCON_INIT_VAR(label); phalcon_call_method(label, element, "getlabel"); @@ -863,10 +821,8 @@ PHP_METHOD(Phalcon_Forms_Form, getValue){ phalcon_fetch_params(1, 1, 0, &name); - PHALCON_OBS_VAR(entity); - phalcon_read_property_this(&entity, this_ptr, SL("_entity"), PH_NOISY_CC); + entity = phalcon_fetch_nproperty_this(this_ptr, SL("_entity"), PH_NOISY_CC); if (Z_TYPE_P(entity) == IS_OBJECT) { - /** * Check if the entity has a getter */ @@ -887,16 +843,13 @@ PHP_METHOD(Phalcon_Forms_Form, getValue){ } } - PHALCON_OBS_VAR(data); - phalcon_read_property_this(&data, this_ptr, SL("_data"), PH_NOISY_CC); + data = phalcon_fetch_nproperty_this(this_ptr, SL("_data"), PH_NOISY_CC); if (Z_TYPE_P(data) == IS_ARRAY) { /** * Check if the data is in the data array */ - if (phalcon_array_isset(data, name)) { - PHALCON_OBS_NVAR(value); - phalcon_array_fetch(&value, data, name, PH_NOISY); + if (phalcon_array_isset_fetch(&value, data, name)) { RETURN_CCTOR(value); } } @@ -914,21 +867,18 @@ PHP_METHOD(Phalcon_Forms_Form, has){ zval *name, *elements; - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 1, 0, &name); + phalcon_fetch_params(0, 1, 0, &name); - PHALCON_OBS_VAR(elements); - phalcon_read_property_this(&elements, this_ptr, SL("_elements"), PH_NOISY_CC); + elements = phalcon_fetch_nproperty_this(this_ptr, SL("_elements"), PH_NOISY_CC); /** * Checks if the element is in the form */ if (phalcon_array_isset(elements, name)) { - RETURN_MM_TRUE; + RETURN_TRUE; } - RETURN_MM_FALSE; + RETURN_FALSE; } /** @@ -941,26 +891,23 @@ PHP_METHOD(Phalcon_Forms_Form, remove){ zval *name, *elements; - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 1, 0, &name); + phalcon_fetch_params(0, 1, 0, &name); - PHALCON_OBS_VAR(elements); - phalcon_read_property_this(&elements, this_ptr, SL("_elements"), PH_NOISY_CC); + elements = phalcon_fetch_nproperty_this(this_ptr, SL("_elements"), PH_NOISY_CC); /** * Checks if the element is in the form */ if (phalcon_array_isset(elements, name)) { phalcon_unset_property_array(this_ptr, SL("_elements"), name TSRMLS_CC); - RETURN_MM_TRUE; + RETURN_TRUE; } /** * Clean the iterator index */ phalcon_update_property_null(this_ptr, SL("_elementsIndexed") TSRMLS_CC); - RETURN_MM_FALSE; + RETURN_FALSE; } /** @@ -981,11 +928,10 @@ PHP_METHOD(Phalcon_Forms_Form, clear){ phalcon_fetch_params(1, 0, 1, &fields); if (!fields) { - PHALCON_INIT_VAR(fields); + fields = PHALCON_GLOBAL(z_null); } - PHALCON_OBS_VAR(elements); - phalcon_read_property_this(&elements, this_ptr, SL("_elements"), PH_NOISY_CC); + elements = phalcon_fetch_nproperty_this(this_ptr, SL("_elements"), PH_NOISY_CC); if (Z_TYPE_P(elements) == IS_ARRAY) { phalcon_is_iterable(elements, &ah0, &hp0, 0, 0); @@ -1021,12 +967,8 @@ PHP_METHOD(Phalcon_Forms_Form, count){ zval *elements; - PHALCON_MM_GROW(); - - PHALCON_OBS_VAR(elements); - phalcon_read_property_this(&elements, this_ptr, SL("_elements"), PH_NOISY_CC); + elements = phalcon_fetch_nproperty_this(this_ptr, SL("_elements"), PH_NOISY_CC); phalcon_fast_count(return_value, elements TSRMLS_CC); - RETURN_MM(); } /** @@ -1040,8 +982,7 @@ PHP_METHOD(Phalcon_Forms_Form, rewind){ phalcon_update_property_long(this_ptr, SL("_position"), 0 TSRMLS_CC); - PHALCON_OBS_VAR(elements); - phalcon_read_property_this(&elements, this_ptr, SL("_elements"), PH_NOISY_CC); + elements = phalcon_fetch_nproperty_this(this_ptr, SL("_elements"), PH_NOISY_CC); PHALCON_INIT_VAR(elements_indexed); phalcon_array_values(elements_indexed, elements); @@ -1059,20 +1000,13 @@ PHP_METHOD(Phalcon_Forms_Form, current){ zval *position, *elements, *element; - PHALCON_MM_GROW(); - - PHALCON_OBS_VAR(position); - phalcon_read_property_this(&position, this_ptr, SL("_position"), PH_NOISY_CC); - - PHALCON_OBS_VAR(elements); - phalcon_read_property_this(&elements, this_ptr, SL("_elementsIndexed"), PH_NOISY_CC); - if (phalcon_array_isset(elements, position)) { - PHALCON_OBS_VAR(element); - phalcon_array_fetch(&element, elements, position, PH_NOISY); - RETURN_CCTOR(element); + position = phalcon_fetch_nproperty_this(this_ptr, SL("_position"), PH_NOISY_CC); + elements = phalcon_fetch_nproperty_this(this_ptr, SL("_elementsIndexed"), PH_NOISY_CC); + if (phalcon_array_isset_fetch(&element, elements, position)) { + RETURN_CCTORW(element); } - RETURN_MM_NULL(); + RETURN_NULL(); } /** @@ -1106,17 +1040,11 @@ PHP_METHOD(Phalcon_Forms_Form, valid){ zval *position, *elements; - PHALCON_MM_GROW(); - - PHALCON_OBS_VAR(position); - phalcon_read_property_this(&position, this_ptr, SL("_position"), PH_NOISY_CC); - - PHALCON_OBS_VAR(elements); - phalcon_read_property_this(&elements, this_ptr, SL("_elementsIndexed"), PH_NOISY_CC); + position = phalcon_fetch_nproperty_this(this_ptr, SL("_position"), PH_NOISY_CC); + elements = phalcon_fetch_nproperty_this(this_ptr, SL("_elementsIndexed"), PH_NOISY_CC); if (phalcon_array_isset(elements, position)) { - RETURN_MM_TRUE; + RETURN_TRUE; } - RETURN_MM_FALSE; + RETURN_FALSE; } - diff --git a/ext/forms/manager.c b/ext/forms/manager.c index 1fcd2d7864c..4a711f18314 100644 --- a/ext/forms/manager.c +++ b/ext/forms/manager.c @@ -74,11 +74,11 @@ PHP_METHOD(Phalcon_Forms_Manager, create){ phalcon_fetch_params(1, 0, 2, &name, &entity); if (!name) { - PHALCON_INIT_VAR(name); + name = PHALCON_GLOBAL(z_null); } if (!entity) { - PHALCON_INIT_VAR(entity); + entity = PHALCON_GLOBAL(z_null); } if (Z_TYPE_P(name) != IS_STRING) { diff --git a/ext/http/cookie.c b/ext/http/cookie.c index a9894661024..c19924769d7 100644 --- a/ext/http/cookie.c +++ b/ext/http/cookie.c @@ -95,12 +95,11 @@ PHP_METHOD(Phalcon_Http_Cookie, __construct){ phalcon_fetch_params(1, 1, 6, &name, &value, &expire, &path, &secure, &domain, &http_only); if (!value) { - PHALCON_INIT_VAR(value); + value = PHALCON_GLOBAL(z_null); } if (!expire) { - PHALCON_INIT_VAR(expire); - ZVAL_LONG(expire, 0); + expire = PHALCON_GLOBAL(z_zero); } if (!path) { @@ -199,11 +198,11 @@ PHP_METHOD(Phalcon_Http_Cookie, getValue){ phalcon_fetch_params(1, 0, 2, &filters, &default_value); if (!filters) { - PHALCON_INIT_VAR(filters); + filters = PHALCON_GLOBAL(z_null); } if (!default_value) { - PHALCON_INIT_VAR(default_value); + default_value = PHALCON_GLOBAL(z_null); } PHALCON_OBS_VAR(restored); diff --git a/ext/http/request.c b/ext/http/request.c index 2d8a22f317d..2865f56b1eb 100644 --- a/ext/http/request.c +++ b/ext/http/request.c @@ -140,25 +140,23 @@ PHP_METHOD(Phalcon_Http_Request, get){ phalcon_fetch_params(1, 0, 5, &name, &filters, &default_value, ¬_allow_empty, &norecursive); if (!name) { - PHALCON_INIT_VAR(name); + name = PHALCON_GLOBAL(z_null); } if (!filters) { - PHALCON_INIT_VAR(filters); + filters = PHALCON_GLOBAL(z_null); } if (!default_value) { - PHALCON_INIT_VAR(default_value); + default_value = PHALCON_GLOBAL(z_null); } if (!not_allow_empty) { - PHALCON_INIT_VAR(not_allow_empty); - ZVAL_FALSE(not_allow_empty); + not_allow_empty = PHALCON_GLOBAL(z_false); } if (!norecursive) { - PHALCON_INIT_VAR(norecursive); - ZVAL_FALSE(norecursive); + norecursive = PHALCON_GLOBAL(z_false); } phalcon_get_global(&_REQUEST, SS("_REQUEST") TSRMLS_CC); @@ -242,25 +240,23 @@ PHP_METHOD(Phalcon_Http_Request, getPost){ phalcon_fetch_params(1, 0, 5, &name, &filters, &default_value, ¬_allow_empty, &norecursive); if (!name) { - PHALCON_INIT_VAR(name); + name = PHALCON_GLOBAL(z_null); } if (!filters) { - PHALCON_INIT_VAR(filters); + filters = PHALCON_GLOBAL(z_null); } if (!default_value) { - PHALCON_INIT_VAR(default_value); + default_value = PHALCON_GLOBAL(z_null); } if (!not_allow_empty) { - PHALCON_INIT_VAR(not_allow_empty); - ZVAL_FALSE(not_allow_empty); + not_allow_empty = PHALCON_GLOBAL(z_false); } if (!norecursive) { - PHALCON_INIT_VAR(norecursive); - ZVAL_FALSE(norecursive); + norecursive = PHALCON_GLOBAL(z_false); } phalcon_get_global(&_POST, SS("_POST") TSRMLS_CC); @@ -347,25 +343,23 @@ PHP_METHOD(Phalcon_Http_Request, getQuery){ phalcon_fetch_params(1, 0, 5, &name, &filters, &default_value, ¬_allow_empty, &norecursive); if (!name) { - PHALCON_INIT_VAR(name); + name = PHALCON_GLOBAL(z_null); } if (!filters) { - PHALCON_INIT_VAR(filters); + filters = PHALCON_GLOBAL(z_null); } if (!default_value) { - PHALCON_INIT_VAR(default_value); + default_value = PHALCON_GLOBAL(z_null); } if (!not_allow_empty) { - PHALCON_INIT_VAR(not_allow_empty); - ZVAL_FALSE(not_allow_empty); + not_allow_empty = PHALCON_GLOBAL(z_false); } if (!norecursive) { - PHALCON_INIT_VAR(norecursive); - ZVAL_FALSE(norecursive); + norecursive = PHALCON_GLOBAL(z_false); } phalcon_get_global(&_GET, SS("_GET") TSRMLS_CC); @@ -900,8 +894,7 @@ PHP_METHOD(Phalcon_Http_Request, getClientAddress){ phalcon_fetch_params(1, 0, 1, &trust_forwarded_header); if (!trust_forwarded_header) { - PHALCON_INIT_VAR(trust_forwarded_header); - ZVAL_FALSE(trust_forwarded_header); + trust_forwarded_header = PHALCON_GLOBAL(z_false); } PHALCON_INIT_VAR(address); diff --git a/ext/http/response.c b/ext/http/response.c index f1e6cbdbde4..8620f5c3807 100644 --- a/ext/http/response.c +++ b/ext/http/response.c @@ -92,22 +92,14 @@ PHP_METHOD(Phalcon_Http_Response, __construct){ phalcon_fetch_params(1, 0, 3, &content, &code, &status); - if (!content) { - PHALCON_INIT_VAR(content); - } - - if (!code) { - PHALCON_INIT_VAR(code); - } - if (!status) { - PHALCON_INIT_VAR(status); + status = PHALCON_GLOBAL(z_null); } - if (Z_TYPE_P(content) != IS_NULL) { + if (content && Z_TYPE_P(content) != IS_NULL) { phalcon_update_property_this(this_ptr, SL("_content"), content TSRMLS_CC); } - if (Z_TYPE_P(code) != IS_NULL) { + if (code && Z_TYPE_P(code) != IS_NULL) { phalcon_call_method_p2_noret(this_ptr, "setstatuscode", code, status); } @@ -452,7 +444,7 @@ PHP_METHOD(Phalcon_Http_Response, setContentType){ phalcon_fetch_params(1, 1, 1, &content_type, &charset); if (!charset) { - PHALCON_INIT_VAR(charset); + charset = PHALCON_GLOBAL(z_null); } PHALCON_INIT_VAR(headers); @@ -542,12 +534,11 @@ PHP_METHOD(Phalcon_Http_Response, redirect){ phalcon_fetch_params(1, 0, 3, &location, &external_redirect, &status_code); if (!location) { - PHALCON_INIT_VAR(location); + location = PHALCON_GLOBAL(z_null); } if (!external_redirect) { - PHALCON_INIT_VAR(external_redirect); - ZVAL_BOOL(external_redirect, 0); + external_redirect = PHALCON_GLOBAL(z_false); } if (!status_code) { @@ -814,12 +805,11 @@ PHP_METHOD(Phalcon_Http_Response, setFileToSend){ phalcon_fetch_params(1, 1, 2, &file_path, &attachment_name, &attachment); if (!attachment_name) { - PHALCON_INIT_VAR(attachment_name); + attachment_name = PHALCON_GLOBAL(z_null); } - if (!attachment) { - PHALCON_INIT_VAR(attachment); - ZVAL_BOOL(attachment, 1); + if (!attachment) { + attachment = PHALCON_GLOBAL(z_true); } if (Z_TYPE_P(attachment_name) != IS_STRING) { @@ -829,7 +819,7 @@ PHP_METHOD(Phalcon_Http_Response, setFileToSend){ PHALCON_CPY_WRT(base_path, attachment_name); } - if (zend_is_true(attachment)) { + if (zend_is_true(attachment)) { PHALCON_INIT_VAR(headers); phalcon_call_method(headers, this_ptr, "getheaders"); diff --git a/ext/http/response/cookies.c b/ext/http/response/cookies.c index 501eb67764d..40d3dbd9741 100644 --- a/ext/http/response/cookies.c +++ b/ext/http/response/cookies.c @@ -142,12 +142,11 @@ PHP_METHOD(Phalcon_Http_Response_Cookies, set){ phalcon_fetch_params(1, 1, 6, &name, &value, &expire, &path, &secure, &domain, &http_only); if (!value) { - PHALCON_INIT_VAR(value); + value = PHALCON_GLOBAL(z_null); } if (!expire) { - PHALCON_INIT_VAR(expire); - ZVAL_LONG(expire, 0); + expire = PHALCON_GLOBAL(z_zero); } if (!path) { @@ -156,15 +155,15 @@ PHP_METHOD(Phalcon_Http_Response_Cookies, set){ } if (!secure) { - PHALCON_INIT_VAR(secure); + secure = PHALCON_GLOBAL(z_null); } if (!domain) { - PHALCON_INIT_VAR(domain); + domain = PHALCON_GLOBAL(z_null); } if (!http_only) { - PHALCON_INIT_VAR(http_only); + http_only = PHALCON_GLOBAL(z_null); } if (Z_TYPE_P(name) != IS_STRING) { diff --git a/ext/image/adapter/imagick.c b/ext/image/adapter/imagick.c index e2503e87cc9..2a83cdb10fd 100644 --- a/ext/image/adapter/imagick.c +++ b/ext/image/adapter/imagick.c @@ -1631,9 +1631,9 @@ PHP_METHOD(Phalcon_Image_Adapter_Imagick, _save) { phalcon_update_property_this(this_ptr, SL("_mime"), mime TSRMLS_CC); - ZVAL_BOOL(return_value, 1); + RETVAL_TRUE; } else { - ZVAL_BOOL(return_value, 0); + RETVAL_FALSE; } PHALCON_MM_RESTORE(); diff --git a/ext/kernel/array.c b/ext/kernel/array.c index 6f2b2edb9eb..fffcd7a00f3 100644 --- a/ext/kernel/array.c +++ b/ext/kernel/array.c @@ -469,7 +469,7 @@ int phalcon_array_update_zval_bool(zval **arr, zval *index, int value, int flags zval *zvalue; - ALLOC_INIT_ZVAL(zvalue); + MAKE_STD_ZVAL(zvalue); ZVAL_BOOL(zvalue, value); return phalcon_array_update_zval(arr, index, &zvalue, flags); @@ -530,7 +530,7 @@ int phalcon_array_update_zval_long(zval **arr, zval *index, long value, int flag zval *zvalue; - ALLOC_INIT_ZVAL(zvalue); + MAKE_STD_ZVAL(zvalue); ZVAL_LONG(zvalue, value); return phalcon_array_update_zval(arr, index, &zvalue, flags); @@ -634,7 +634,7 @@ int phalcon_array_update_string_bool(zval **arr, const char *index, uint index_l zval *zvalue; - ALLOC_INIT_ZVAL(zvalue); + MAKE_STD_ZVAL(zvalue); ZVAL_BOOL(zvalue, value); return phalcon_array_update_string(arr, index, index_length, &zvalue, flags); @@ -666,7 +666,7 @@ int phalcon_array_update_string_long(zval **arr, const char *index, uint index_l zval *zvalue; - ALLOC_INIT_ZVAL(zvalue); + MAKE_STD_ZVAL(zvalue); ZVAL_LONG(zvalue, value); return phalcon_array_update_string(arr, index, index_length, &zvalue, flags); @@ -699,7 +699,7 @@ int phalcon_array_update_string_string(zval **arr, const char *index, uint index zval *zvalue; - ALLOC_INIT_ZVAL(zvalue); + MAKE_STD_ZVAL(zvalue); ZVAL_STRINGL(zvalue, value, value_length, 1); return phalcon_array_update_string(arr, index, index_length, &zvalue, flags); @@ -774,7 +774,7 @@ int phalcon_array_update_long_string(zval **arr, unsigned long index, char *valu zval *zvalue; - ALLOC_INIT_ZVAL(zvalue); + MAKE_STD_ZVAL(zvalue); ZVAL_STRINGL(zvalue, value, value_length, 1); return phalcon_array_update_long(arr, index, &zvalue, flags); @@ -804,7 +804,7 @@ int phalcon_array_update_long_long(zval **arr, unsigned long index, long value, zval *zvalue; - ALLOC_INIT_ZVAL(zvalue); + MAKE_STD_ZVAL(zvalue); ZVAL_LONG(zvalue, value); return phalcon_array_update_long(arr, index, &zvalue, flags); @@ -834,7 +834,7 @@ int phalcon_array_update_long_bool(zval **arr, unsigned long index, int value, i zval *zvalue; - ALLOC_INIT_ZVAL(zvalue); + MAKE_STD_ZVAL(zvalue); ZVAL_BOOL(zvalue, value); return phalcon_array_update_long(arr, index, &zvalue, flags); diff --git a/ext/kernel/fcall.c b/ext/kernel/fcall.c index 03310a0c88b..b04d0e2ef1b 100644 --- a/ext/kernel/fcall.c +++ b/ext/kernel/fcall.c @@ -215,7 +215,7 @@ static int phalcon_call_func_vparams(zval *return_value, zval **return_value_ptr return status; } -int phalcon_call_method_vparams(zval *return_value, zval **return_value_ptr, zval *object, char *method_name, int method_len, ulong method_key TSRMLS_DC, int param_count, va_list ap) { +int phalcon_call_method_vparams(zval *return_value, zval **return_value_ptr, zval *object, const char *method_name, int method_len, ulong method_key TSRMLS_DC, int param_count, va_list ap) { int i, status, free_params = -0, caller_wants_result = 1; zend_class_entry *ce, *active_scope = NULL; @@ -261,7 +261,7 @@ int phalcon_call_method_vparams(zval *return_value, zval **return_value_ptr, zva ce = Z_OBJCE_P(object); active_scope = EG(scope); EG(scope) = ce; - status = phalcon_alt_call_user_method(ce, &object, method_name, method_len, return_value, return_value_ptr, param_count, params_ptr, method_key TSRMLS_CC); + status = phalcon_alt_call_user_method(ce, &object, (char*)method_name, method_len, return_value, return_value_ptr, param_count, params_ptr, method_key TSRMLS_CC); EG(scope) = active_scope; if (unlikely(free_params)) { @@ -285,7 +285,7 @@ int phalcon_call_method_vparams(zval *return_value, zval **return_value_ptr, zva /** * Call single static function on a zval which requires parameters */ -static int phalcon_call_static_zval_str_func_vparams(zval *return_value, zval **return_value_ptr, zval *mixed_name, char *method_name, int method_len TSRMLS_DC, int param_count, va_list ap) { +static int phalcon_call_static_zval_str_func_vparams(zval *return_value, zval **return_value_ptr, zval *mixed_name, const char *method_name, int method_len TSRMLS_DC, int param_count, va_list ap) { zval **params_ptr, **params = NULL, *fn; zval *static_params[10]; @@ -393,7 +393,7 @@ int phalcon_call_func_params(zval *return_value, zval **return_value_ptr, const * @retval @c SUCCESS * @retval @c FAILURE */ -int phalcon_call_method_params(zval *return_value, zval **return_value_ptr, zval *object, char *method_name, int method_len, ulong method_key TSRMLS_DC, int param_count, ...) { +int phalcon_call_method_params(zval *return_value, zval **return_value_ptr, zval *object, const char *method_name, int method_len, ulong method_key TSRMLS_DC, int param_count, ...) { int status; va_list ap; @@ -427,7 +427,7 @@ int phalcon_call_method_zval_params(zval *return_value, zval **return_value_ptr, /** * Call single static function that requires an arbitrary number of parameters */ -int phalcon_call_static_func_params(zval *return_value, zval **return_value_ptr, char *class_name, int class_length, char *method_name, int method_length TSRMLS_DC, int param_count, ...) { +int phalcon_call_static_func_params(zval *return_value, zval **return_value_ptr, const char *class_name, int class_length, const char *method_name, int method_length TSRMLS_DC, int param_count, ...) { zval cls; va_list ap; @@ -448,7 +448,7 @@ int phalcon_call_static_func_params(zval *return_value, zval **return_value_ptr, /** * Call parent static function that requires an arbitrary number of parameters */ -int phalcon_call_parent_func_params(zval *return_value, zval **return_value_ptr, zval *object, zend_class_entry *active_class_ce, char *method_name, int method_len TSRMLS_DC, int param_count, ...) { +int phalcon_call_parent_func_params(zval *return_value, zval **return_value_ptr, zval *object, zend_class_entry *active_class_ce, const char *method_name, int method_len TSRMLS_DC, int param_count, ...) { zval cls; int status; @@ -477,7 +477,7 @@ int phalcon_call_parent_func_params(zval *return_value, zval **return_value_ptr, /** * Call self-class static function which requires parameters */ -int phalcon_call_self_func_params(zval *return_value, zval **return_value_ptr, zval *object, char *method_name, int method_len TSRMLS_DC, int param_count, ...) { +int phalcon_call_self_func_params(zval *return_value, zval **return_value_ptr, zval *object, const char *method_name, int method_len TSRMLS_DC, int param_count, ...) { int status; zend_class_entry *active_scope; @@ -523,7 +523,7 @@ int phalcon_call_static_zval_func_params(zval *return_value, zval **return_value return FAILURE; } -int phalcon_call_static_zval_str_func_params(zval *return_value, zval **return_value_ptr, zval *mixed_name, char *method_name, int method_len TSRMLS_DC, int param_count, ...) { +int phalcon_call_static_zval_str_func_params(zval *return_value, zval **return_value_ptr, zval *mixed_name, const char *method_name, int method_len TSRMLS_DC, int param_count, ...) { int status; va_list ap; diff --git a/ext/kernel/fcall.h b/ext/kernel/fcall.h index dab10667d34..fce132a245e 100644 --- a/ext/kernel/fcall.h +++ b/ext/kernel/fcall.h @@ -472,15 +472,15 @@ #define phalcon_call_zval_str_static_p1(return_value, class_zval, method, p1) PHALCON_CALL_ZSTATIC_STR(return_value, NULL, class_zval, method, 1, p1) int phalcon_call_func_params(zval *return_value, zval **return_value_ptr, const char *func_name, int func_length TSRMLS_DC, int param_count, ...); -int phalcon_call_method_params(zval *return_value, zval **return_value_ptr, zval *object, char *method_name, int method_len, ulong method_key TSRMLS_DC, int param_count, ...); +int phalcon_call_method_params(zval *return_value, zval **return_value_ptr, zval *object, const char *method_name, int method_len, ulong method_key TSRMLS_DC, int param_count, ...); int phalcon_call_method_zval_params(zval *return_value, zval **return_value_ptr, zval *object, zval *method TSRMLS_DC, int param_count, ...); -int phalcon_call_parent_func_params(zval *return_value, zval **return_value_ptr, zval *object, zend_class_entry *active_class_ce, char *method_name, int method_len TSRMLS_DC, int param_count, ...); -int phalcon_call_self_func_params(zval *return_value, zval **return_value_ptr, zval *object, char *method_name, int method_len TSRMLS_DC, int param_count, ...); -int phalcon_call_static_func_params(zval *return_value, zval **return_value_ptr, char *class_name, int class_length, char *method_name, int method_length TSRMLS_DC, int param_count, ...); +int phalcon_call_parent_func_params(zval *return_value, zval **return_value_ptr, zval *object, zend_class_entry *active_class_ce, const char *method_name, int method_len TSRMLS_DC, int param_count, ...); +int phalcon_call_self_func_params(zval *return_value, zval **return_value_ptr, zval *object, const char *method_name, int method_len TSRMLS_DC, int param_count, ...); +int phalcon_call_static_func_params(zval *return_value, zval **return_value_ptr, const char *class_name, int class_length, const char *method_name, int method_length TSRMLS_DC, int param_count, ...); int phalcon_call_static_zval_func_params(zval *return_value, zval **return_value_ptr, zval *mixed_name, zval *method TSRMLS_DC, int param_count, ...); -int phalcon_call_static_zval_str_func_params(zval *return_value, zval **return_value_ptr, zval *mixed_name, char *method_name, int method_len TSRMLS_DC, int param_count, ...); +int phalcon_call_static_zval_str_func_params(zval *return_value, zval **return_value_ptr, zval *mixed_name, const char *method_name, int method_len TSRMLS_DC, int param_count, ...); -int phalcon_call_method_vparams(zval *return_value, zval **return_value_ptr, zval *object, char *method_name, int method_len, ulong method_key TSRMLS_DC, int param_count, va_list ap); +int phalcon_call_method_vparams(zval *return_value, zval **return_value_ptr, zval *object, const char *method_name, int method_len, ulong method_key TSRMLS_DC, int param_count, va_list ap); /** Fast call_user_func_array/call_user_func */ int phalcon_call_user_func_array(zval *return_value, zval *handler, zval *params TSRMLS_DC); diff --git a/ext/kernel/framework/router.c b/ext/kernel/framework/router.c index 07784a1ab7b..63d70694158 100644 --- a/ext/kernel/framework/router.c +++ b/ext/kernel/framework/router.c @@ -121,7 +121,7 @@ void phalcon_replace_paths(zval *return_value, zval *pattern, zval *paths, zval } if (Z_STRLEN_P(pattern) <= 0) { - ZVAL_BOOL(return_value, 0); + ZVAL_FALSE(return_value); return; } @@ -275,18 +275,8 @@ void phalcon_extract_named_params(zval *return_value, zval *str, zval *matches){ char *item, *variable = NULL, *regexp = NULL; smart_str route_str = {0}; - if (Z_TYPE_P(str) != IS_STRING) { - ZVAL_BOOL(return_value, 0); - return; - } - - if (Z_STRLEN_P(str) <= 0) { - ZVAL_BOOL(return_value, 0); - return; - } - - if (Z_TYPE_P(matches) != IS_ARRAY) { - ZVAL_BOOL(return_value, 0); + if (Z_TYPE_P(str) != IS_STRING || Z_STRLEN_P(str) <= 0 || Z_TYPE_P(matches) != IS_ARRAY) { + ZVAL_FALSE(return_value); return; } diff --git a/ext/kernel/object.c b/ext/kernel/object.c index bf4d1c9f06c..45a3d312b6b 100644 --- a/ext/kernel/object.c +++ b/ext/kernel/object.c @@ -758,12 +758,7 @@ int phalcon_update_property_string(zval *object, char *property_name, unsigned i */ int phalcon_update_property_bool(zval *object, char *property_name, unsigned int property_length, int value TSRMLS_DC) { - zval *v; - - ALLOC_ZVAL(v); - Z_UNSET_ISREF_P(v); - Z_SET_REFCOUNT_P(v, 0); - ZVAL_BOOL(v, value ? 1 : 0); + zval *v = value ? PHALCON_GLOBAL(z_true) : PHALCON_GLOBAL(z_false); return phalcon_update_property_zval(object, property_name, property_length, v TSRMLS_CC); } @@ -773,12 +768,7 @@ int phalcon_update_property_bool(zval *object, char *property_name, unsigned int */ int phalcon_update_property_null(zval *object, char *property_name, unsigned int property_length TSRMLS_DC) { - zval *v; - - ALLOC_ZVAL(v); - Z_UNSET_ISREF_P(v); - Z_SET_REFCOUNT_P(v, 0); - ZVAL_NULL(v); + zval *v = PHALCON_GLOBAL(z_null); return phalcon_update_property_zval(object, property_name, property_length, v TSRMLS_CC); } diff --git a/ext/kernel/string.c b/ext/kernel/string.c index 5c1842d23c5..30c7f13dbc8 100644 --- a/ext/kernel/string.c +++ b/ext/kernel/string.c @@ -408,7 +408,7 @@ void phalcon_fast_strpos(zval *return_value, const zval *haystack, const zval *n if (found) { ZVAL_LONG(return_value, found-Z_STRVAL_P(haystack)); } else { - ZVAL_BOOL(return_value, 0); + ZVAL_FALSE(return_value); } } @@ -431,7 +431,7 @@ void phalcon_fast_strpos_str(zval *return_value, const zval *haystack, char *nee if (found) { ZVAL_LONG(return_value, found-Z_STRVAL_P(haystack)); } else { - ZVAL_BOOL(return_value, 0); + ZVAL_FALSE(return_value); } } @@ -464,7 +464,7 @@ void phalcon_fast_stripos_str(zval *return_value, zval *haystack, char *needle, if (found) { ZVAL_LONG(return_value, found-Z_STRVAL_P(haystack)); } else { - ZVAL_BOOL(return_value, 0); + ZVAL_FALSE(return_value); } } diff --git a/ext/loader.c b/ext/loader.c index 202fdb83a86..9080bad91bb 100644 --- a/ext/loader.c +++ b/ext/loader.c @@ -181,24 +181,18 @@ PHP_METHOD(Phalcon_Loader, registerNamespaces){ phalcon_fetch_params(1, 1, 1, &namespaces, &merge); - if (!merge) { - PHALCON_INIT_VAR(merge); - ZVAL_BOOL(merge, 0); - } - if (Z_TYPE_P(namespaces) != IS_ARRAY) { PHALCON_THROW_EXCEPTION_STR(phalcon_loader_exception_ce, "Parameter namespaces must be an array"); return; } - if (zend_is_true(merge)) { + if (merge && zend_is_true(merge)) { - PHALCON_OBS_VAR(current_namespaces); - phalcon_read_property_this(¤t_namespaces, this_ptr, SL("_namespaces"), PH_NOISY_CC); + current_namespaces = phalcon_fetch_nproperty_this(this_ptr, SL("_namespaces"), PH_NOISY_CC); if (Z_TYPE_P(current_namespaces) == IS_ARRAY) { PHALCON_INIT_VAR(merged_namespaces); phalcon_fast_array_merge(merged_namespaces, ¤t_namespaces, &namespaces TSRMLS_CC); } else { - PHALCON_CPY_WRT(merged_namespaces, namespaces); + merged_namespaces = namespaces; } phalcon_update_property_this(this_ptr, SL("_namespaces"), merged_namespaces TSRMLS_CC); @@ -235,24 +229,18 @@ PHP_METHOD(Phalcon_Loader, registerPrefixes){ phalcon_fetch_params(1, 1, 1, &prefixes, &merge); - if (!merge) { - PHALCON_INIT_VAR(merge); - ZVAL_BOOL(merge, 0); - } - if (Z_TYPE_P(prefixes) != IS_ARRAY) { PHALCON_THROW_EXCEPTION_STR(phalcon_loader_exception_ce, "Parameter prefixes must be an array"); return; } - if (zend_is_true(merge)) { - - PHALCON_OBS_VAR(current_prefixes); - phalcon_read_property_this(¤t_prefixes, this_ptr, SL("_prefixes"), PH_NOISY_CC); + + if (merge && zend_is_true(merge)) { + current_prefixes = phalcon_fetch_nproperty_this(this_ptr, SL("_prefixes"), PH_NOISY_CC); if (Z_TYPE_P(current_prefixes) == IS_ARRAY) { PHALCON_INIT_VAR(merged_prefixes); phalcon_fast_array_merge(merged_prefixes, ¤t_prefixes, &prefixes TSRMLS_CC); } else { - PHALCON_CPY_WRT(merged_prefixes, prefixes); + merged_prefixes = prefixes; } phalcon_update_property_this(this_ptr, SL("_prefixes"), merged_prefixes TSRMLS_CC); @@ -290,24 +278,18 @@ PHP_METHOD(Phalcon_Loader, registerDirs){ phalcon_fetch_params(1, 1, 1, &directories, &merge); - if (!merge) { - PHALCON_INIT_VAR(merge); - ZVAL_BOOL(merge, 0); - } - if (Z_TYPE_P(directories) != IS_ARRAY) { PHALCON_THROW_EXCEPTION_STR(phalcon_loader_exception_ce, "Parameter directories must be an array"); return; } - if (zend_is_true(merge)) { - - PHALCON_OBS_VAR(current_directories); - phalcon_read_property_this(¤t_directories, this_ptr, SL("_directories"), PH_NOISY_CC); + + if (merge && zend_is_true(merge)) { + current_directories = phalcon_fetch_nproperty_this(this_ptr, SL("_directories"), PH_NOISY_CC); if (Z_TYPE_P(current_directories) == IS_ARRAY) { PHALCON_INIT_VAR(merged_directories); phalcon_fast_array_merge(merged_directories, ¤t_directories, &directories TSRMLS_CC); } else { - PHALCON_CPY_WRT(merged_directories, directories); + merged_directories = directories; } phalcon_update_property_this(this_ptr, SL("_directories"), merged_directories TSRMLS_CC); @@ -344,24 +326,18 @@ PHP_METHOD(Phalcon_Loader, registerClasses){ phalcon_fetch_params(1, 1, 1, &classes, &merge); - if (!merge) { - PHALCON_INIT_VAR(merge); - ZVAL_BOOL(merge, 0); - } - if (Z_TYPE_P(classes) != IS_ARRAY) { PHALCON_THROW_EXCEPTION_STR(phalcon_loader_exception_ce, "Parameter classes must be an array"); return; } - if (zend_is_true(merge)) { - - PHALCON_OBS_VAR(current_classes); - phalcon_read_property_this(¤t_classes, this_ptr, SL("_classes"), PH_NOISY_CC); + + if (merge && zend_is_true(merge)) { + current_classes = phalcon_fetch_nproperty_this(this_ptr, SL("_classes"), PH_NOISY_CC); if (Z_TYPE_P(current_classes) == IS_ARRAY) { PHALCON_INIT_VAR(merged_classes); phalcon_fast_array_merge(merged_classes, ¤t_classes, &classes TSRMLS_CC); } else { - PHALCON_CPY_WRT(merged_classes, classes); + merged_classes = classes; } phalcon_update_property_this(this_ptr, SL("_classes"), merged_classes TSRMLS_CC); @@ -394,15 +370,14 @@ PHP_METHOD(Phalcon_Loader, register){ PHALCON_MM_GROW(); - PHALCON_OBS_VAR(registered); - phalcon_read_property_this(®istered, this_ptr, SL("_registered"), PH_NOISY_CC); + registered = phalcon_fetch_nproperty_this(this_ptr, SL("_registered"), PH_NOISY_CC); if (PHALCON_IS_FALSE(registered)) { PHALCON_INIT_VAR(autoloader); array_init_size(autoloader, 2); - phalcon_array_append(&autoloader, this_ptr, PH_SEPARATE); + phalcon_array_append(&autoloader, this_ptr, 0); add_next_index_stringl(autoloader, SL("autoLoad"), 1); phalcon_call_func_p1_noret("spl_autoload_register", autoloader); - phalcon_update_property_bool(this_ptr, SL("_registered"), 1 TSRMLS_CC); + phalcon_update_property_this(this_ptr, SL("_registered"), PHALCON_GLOBAL(z_true) TSRMLS_CC); } RETURN_THIS(); @@ -419,15 +394,14 @@ PHP_METHOD(Phalcon_Loader, unregister){ PHALCON_MM_GROW(); - PHALCON_OBS_VAR(registered); - phalcon_read_property_this(®istered, this_ptr, SL("_registered"), PH_NOISY_CC); + registered = phalcon_fetch_nproperty_this(this_ptr, SL("_registered"), PH_NOISY_CC); if (PHALCON_IS_TRUE(registered)) { PHALCON_INIT_VAR(autoloader); array_init_size(autoloader, 2); - phalcon_array_append(&autoloader, this_ptr, PH_SEPARATE); + phalcon_array_append(&autoloader, this_ptr, 0); add_next_index_stringl(autoloader, SL("autoLoad"), 1); phalcon_call_func_p1_noret("spl_autoload_unregister", autoloader); - phalcon_update_property_bool(this_ptr, SL("_registered"), 0 TSRMLS_CC); + phalcon_update_property_this(this_ptr, SL("_registered"), PHALCON_GLOBAL(z_false) TSRMLS_CC); } RETURN_THIS(); @@ -443,7 +417,7 @@ PHP_METHOD(Phalcon_Loader, autoLoad){ zval *class_name, *events_manager, *event_name = NULL; zval *classes, *file_path = NULL, *extensions, *ds, *namespace_separator; - zval *empty_str, *zero, *namespaces, *directory = NULL; + zval *empty_str, *namespaces, *directory = NULL; zval *ns_prefix = NULL, *file_name = NULL, *fixed_directory = NULL; zval *extension = NULL, *pseudo_separator, *prefixes; zval *prefix = NULL, *ds_class_name, *ns_class_name; @@ -499,10 +473,7 @@ PHP_METHOD(Phalcon_Loader, autoLoad){ ZVAL_STRING(namespace_separator, "\\", 1); PHALCON_INIT_VAR(empty_str); - ZVAL_STRING(empty_str, "", 1); - - PHALCON_INIT_VAR(zero); - ZVAL_LONG(zero, 0); + ZVAL_EMPTY_STRING(empty_str); /** * Checking in namespaces diff --git a/ext/logger/adapter/file.c b/ext/logger/adapter/file.c index 3a01a5df30c..72ebc4ef057 100644 --- a/ext/logger/adapter/file.c +++ b/ext/logger/adapter/file.c @@ -85,7 +85,7 @@ PHP_METHOD(Phalcon_Logger_Adapter_File, __construct){ phalcon_fetch_params(1, 1, 1, &name, &options); if (!options) { - PHALCON_INIT_VAR(options); + options = PHALCON_GLOBAL(z_null); } if (phalcon_array_isset_string(options, SS("mode"))) { diff --git a/ext/logger/adapter/stream.c b/ext/logger/adapter/stream.c index 900cfeabf15..99d48cd611e 100644 --- a/ext/logger/adapter/stream.c +++ b/ext/logger/adapter/stream.c @@ -82,7 +82,7 @@ PHP_METHOD(Phalcon_Logger_Adapter_Stream, __construct){ phalcon_fetch_params(1, 1, 1, &name, &options); if (!options) { - PHALCON_INIT_VAR(options); + options = PHALCON_GLOBAL(z_null); } if (phalcon_array_isset_string(options, SS("mode"))) { diff --git a/ext/logger/adapter/syslog.c b/ext/logger/adapter/syslog.c index f25d46f4c47..5c98898d39b 100644 --- a/ext/logger/adapter/syslog.c +++ b/ext/logger/adapter/syslog.c @@ -83,7 +83,7 @@ PHP_METHOD(Phalcon_Logger_Adapter_Syslog, __construct){ phalcon_fetch_params(1, 1, 1, &name, &options); if (!options) { - PHALCON_INIT_VAR(options); + options = PHALCON_GLOBAL(z_null); } /** diff --git a/ext/logger/formatter/line.c b/ext/logger/formatter/line.c index c30464d56a0..6a939ef27bb 100644 --- a/ext/logger/formatter/line.c +++ b/ext/logger/formatter/line.c @@ -71,26 +71,15 @@ PHP_METHOD(Phalcon_Logger_Formatter_Line, __construct){ zval *format = NULL, *date_format = NULL; - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 0, 2, &format, &date_format); - - if (!format) { - PHALCON_INIT_VAR(format); - } + phalcon_fetch_params(0, 0, 2, &format, &date_format); - if (!date_format) { - PHALCON_INIT_VAR(date_format); - } - - if (Z_TYPE_P(format) != IS_NULL) { + if (format && Z_TYPE_P(format) != IS_NULL) { phalcon_update_property_this(this_ptr, SL("_format"), format TSRMLS_CC); } - if (Z_TYPE_P(date_format) != IS_NULL) { + + if (date_format && Z_TYPE_P(date_format) != IS_NULL) { phalcon_update_property_this(this_ptr, SL("_dateFormat"), date_format TSRMLS_CC); } - - PHALCON_MM_RESTORE(); } /** diff --git a/ext/logger/item.c b/ext/logger/item.c index 0c570099c22..43fc36ce71a 100644 --- a/ext/logger/item.c +++ b/ext/logger/item.c @@ -67,20 +67,15 @@ PHP_METHOD(Phalcon_Logger_Item, __construct){ zval *message, *type, *time = NULL; - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 2, 1, &message, &type, &time); + phalcon_fetch_params(0, 2, 1, &message, &type, &time); if (!time) { - PHALCON_INIT_VAR(time); - ZVAL_LONG(time, 0); + time = PHALCON_GLOBAL(z_zero); } phalcon_update_property_this(this_ptr, SL("_message"), message TSRMLS_CC); phalcon_update_property_this(this_ptr, SL("_type"), type TSRMLS_CC); phalcon_update_property_this(this_ptr, SL("_time"), time TSRMLS_CC); - - PHALCON_MM_RESTORE(); } /** diff --git a/ext/mvc/application.c b/ext/mvc/application.c index 3c1f67118c5..48f85ae3702 100644 --- a/ext/mvc/application.c +++ b/ext/mvc/application.c @@ -111,19 +111,15 @@ PHP_METHOD(Phalcon_Mvc_Application, __construct){ zval *dependency_injector = NULL; - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 0, 1, &dependency_injector); + phalcon_fetch_params(0, 0, 1, &dependency_injector); if (!dependency_injector) { - PHALCON_INIT_VAR(dependency_injector); + dependency_injector = PHALCON_GLOBAL(z_null); } if (Z_TYPE_P(dependency_injector) == IS_OBJECT) { phalcon_update_property_this(this_ptr, SL("_dependencyInjector"), dependency_injector TSRMLS_CC); } - - PHALCON_MM_RESTORE(); } /** @@ -172,8 +168,7 @@ PHP_METHOD(Phalcon_Mvc_Application, registerModules){ phalcon_fetch_params(1, 1, 1, &modules, &merge); if (!merge) { - PHALCON_INIT_VAR(merge); - ZVAL_BOOL(merge, 0); + merge = PHALCON_GLOBAL(z_false); } if (Z_TYPE_P(modules) != IS_ARRAY) { @@ -259,7 +254,7 @@ PHP_METHOD(Phalcon_Mvc_Application, handle){ phalcon_fetch_params(1, 0, 1, &uri); if (!uri) { - PHALCON_INIT_VAR(uri); + uri = PHALCON_GLOBAL(z_null); } PHALCON_OBS_VAR(dependency_injector); @@ -510,7 +505,6 @@ PHP_METHOD(Phalcon_Mvc_Application, handle){ phalcon_call_method(controller, dispatcher, "dispatch"); PHALCON_INIT_VAR(returned_response); - ZVAL_BOOL(returned_response, 0); /** * Get the latest value returned by an action @@ -523,6 +517,9 @@ PHP_METHOD(Phalcon_Mvc_Application, handle){ */ phalcon_instance_of(returned_response, possible_response, phalcon_http_responseinterface_ce TSRMLS_CC); } + else { + ZVAL_FALSE(returned_response); + } /** * Calling afterHandleRequest @@ -543,7 +540,6 @@ PHP_METHOD(Phalcon_Mvc_Application, handle){ if (Z_TYPE_P(controller) == IS_OBJECT) { PHALCON_INIT_VAR(render_status); - ZVAL_BOOL(render_status, 1); /** * This allows to make a custom view render @@ -554,6 +550,9 @@ PHP_METHOD(Phalcon_Mvc_Application, handle){ phalcon_call_method_p3(render_status, events_manager, "fire", event_name, this_ptr, view); } + else { + ZVAL_TRUE(render_status); + } /** * Check if the view process has been treated by the developer diff --git a/ext/mvc/collection.c b/ext/mvc/collection.c index 917c0b18928..47a62f3253f 100644 --- a/ext/mvc/collection.c +++ b/ext/mvc/collection.c @@ -289,26 +289,30 @@ PHP_METHOD(Phalcon_Mvc_Collection, getModelsManager){ */ PHP_METHOD(Phalcon_Mvc_Collection, getReservedAttributes){ - zval *reserved, *dummy; + zval *reserved; reserved = phalcon_fetch_static_property_ce(phalcon_mvc_collection_ce, SL("_reserved") TSRMLS_CC); if (Z_TYPE_P(reserved) == IS_NULL) { - MAKE_STD_ZVAL(dummy); - ZVAL_TRUE(dummy); - Z_SET_REFCOUNT_P(dummy, 5); - - array_init_size(reserved, 5); - add_assoc_zval_ex(reserved, SS("_connection"), dummy); - add_assoc_zval_ex(reserved, SS("_dependencyInjector"), dummy); - add_assoc_zval_ex(reserved, SS("_source"), dummy); - add_assoc_zval_ex(reserved, SS("_operationMade"), dummy); - add_assoc_zval_ex(reserved, SS("_errorMessages"), dummy); + zval *dummy = PHALCON_GLOBAL(z_true); + + array_init_size(return_value, 5); + Z_ADDREF_P(dummy); + add_assoc_zval_ex(return_value, SS("_connection"), dummy); + Z_ADDREF_P(dummy); + add_assoc_zval_ex(return_value, SS("_dependencyInjector"), dummy); + Z_ADDREF_P(dummy); + add_assoc_zval_ex(return_value, SS("_source"), dummy); + Z_ADDREF_P(dummy); + add_assoc_zval_ex(return_value, SS("_operationMade"), dummy); + Z_ADDREF_P(dummy); + add_assoc_zval_ex(return_value, SS("_errorMessages"), dummy); /* reserved is a reference, no need to update the property phalcon_update_static_property_ce(phalcon_mvc_collection_ce, SL("_reserved"), reserved TSRMLS_CC); */ + return; } - RETURN_CCTORW(reserved); + RETURN_ZVAL(reserved, 1, 0); } /** @@ -1529,7 +1533,7 @@ PHP_METHOD(Phalcon_Mvc_Collection, findFirst){ phalcon_fetch_params(1, 0, 1, ¶meters); if (!parameters) { - PHALCON_INIT_VAR(parameters); + parameters = PHALCON_GLOBAL(z_null); } if (Z_TYPE_P(parameters) != IS_NULL) { @@ -1551,9 +1555,8 @@ PHP_METHOD(Phalcon_Mvc_Collection, findFirst){ PHALCON_INIT_VAR(connection); phalcon_call_method(connection, collection, "getconnection"); - - PHALCON_INIT_VAR(unique); - ZVAL_BOOL(unique, 1); + + unique = PHALCON_GLOBAL(z_true); phalcon_call_self_p4(return_value, this_ptr, "_getresultset", parameters, collection, connection, unique); RETURN_MM(); } @@ -1607,7 +1610,7 @@ PHP_METHOD(Phalcon_Mvc_Collection, find){ phalcon_fetch_params(1, 0, 1, ¶meters); if (!parameters) { - PHALCON_INIT_VAR(parameters); + parameters = PHALCON_GLOBAL(z_null); } if (Z_TYPE_P(parameters) != IS_NULL) { @@ -1630,8 +1633,7 @@ PHP_METHOD(Phalcon_Mvc_Collection, find){ PHALCON_INIT_VAR(connection); phalcon_call_method(connection, collection, "getconnection"); - PHALCON_INIT_VAR(unique); - ZVAL_BOOL(unique, 0); + unique = PHALCON_GLOBAL(z_false); phalcon_call_self_p4(return_value, this_ptr, "_getresultset", parameters, collection, connection, unique); RETURN_MM(); } @@ -1656,7 +1658,7 @@ PHP_METHOD(Phalcon_Mvc_Collection, count){ phalcon_fetch_params(1, 0, 1, ¶meters); if (!parameters) { - PHALCON_INIT_VAR(parameters); + parameters = PHALCON_GLOBAL(z_null); } if (Z_TYPE_P(parameters) != IS_NULL) { @@ -1752,11 +1754,11 @@ PHP_METHOD(Phalcon_Mvc_Collection, summatory){ phalcon_fetch_params(1, 1, 2, &field, &conditions, &finalize); if (!conditions) { - PHALCON_INIT_VAR(conditions); + conditions = PHALCON_GLOBAL(z_null); } if (!finalize) { - PHALCON_INIT_VAR(finalize); + finalize = PHALCON_GLOBAL(z_null); } if (Z_TYPE_P(field) != IS_STRING) { diff --git a/ext/mvc/collection/manager.c b/ext/mvc/collection/manager.c index 6e907c86e6f..67c3c463779 100644 --- a/ext/mvc/collection/manager.c +++ b/ext/mvc/collection/manager.c @@ -248,23 +248,16 @@ PHP_METHOD(Phalcon_Mvc_Collection_Manager, initialize){ PHP_METHOD(Phalcon_Mvc_Collection_Manager, isInitialized){ zval *model_name, *initialized, *lowercased; - zval *is_intitialized = NULL; - zval *r0 = NULL; - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 1, 0, &model_name); + phalcon_fetch_params(0, 1, 0, &model_name); - PHALCON_OBS_VAR(initialized); - phalcon_read_property_this(&initialized, this_ptr, SL("_initialized"), PH_NOISY_CC); + initialized = phalcon_fetch_nproperty_this(this_ptr, SL("_initialized"), PH_NOISY_CC); - PHALCON_INIT_VAR(lowercased); + ALLOC_INIT_ZVAL(lowercased); phalcon_fast_strtolower(lowercased, model_name); - PHALCON_INIT_VAR(r0); - ZVAL_BOOL(r0, phalcon_array_isset(initialized, lowercased)); - PHALCON_CPY_WRT(is_intitialized, r0); - RETURN_NCTOR(is_intitialized); + RETVAL_BOOL(phalcon_array_isset(initialized, lowercased)); + zval_ptr_dtor(&lowercased); } /** diff --git a/ext/mvc/micro.c b/ext/mvc/micro.c index 0ead5b5adcd..b51f0bba5f3 100644 --- a/ext/mvc/micro.c +++ b/ext/mvc/micro.c @@ -98,11 +98,8 @@ PHP_METHOD(Phalcon_Mvc_Micro, __construct){ phalcon_fetch_params(1, 0, 1, &dependency_injector); - if (!dependency_injector) { - PHALCON_INIT_VAR(dependency_injector); - } - - if (Z_TYPE_P(dependency_injector) == IS_OBJECT) { + if (dependency_injector && Z_TYPE_P(dependency_injector) == IS_OBJECT) { + PHALCON_VERIFY_INTERFACE(dependency_injector, phalcon_diinterface_ce); phalcon_call_method_p1_noret(this_ptr, "setdi", dependency_injector); } @@ -144,86 +141,60 @@ PHP_METHOD(Phalcon_Mvc_Micro, setDI){ PHALCON_MM_RESTORE(); } -/** - * Maps a route to a handler without any HTTP method constraint - * - * @param string $routePattern - * @param callable $handler - * @return Phalcon\Mvc\Router\RouteInterface - */ -PHP_METHOD(Phalcon_Mvc_Micro, map){ - - zval *route_pattern, *handler, *router, *route; - zval *route_id; +static void phalcon_mvc_micro_generic_add(INTERNAL_FUNCTION_PARAMETERS, const char *method) +{ + zval *route_pattern, *handler, *router, *route_id; + phalcon_fetch_params(0, 2, 0, &route_pattern, &handler); PHALCON_MM_GROW(); - phalcon_fetch_params(1, 2, 0, &route_pattern, &handler); - - /** + /** * We create a router even if there is no one in the DI */ PHALCON_INIT_VAR(router); phalcon_call_method(router, this_ptr, "getrouter"); - - /** + + /** * Routes are added to the router */ - PHALCON_INIT_VAR(route); - phalcon_call_method_p1(route, router, "add", route_pattern); - - /** + phalcon_call_method_p1(return_value, router, method, route_pattern); + + /** * Using the id produced by the router we store the handler */ PHALCON_INIT_VAR(route_id); - phalcon_call_method(route_id, route, "getrouteid"); + phalcon_call_method(route_id, return_value, "getrouteid"); phalcon_update_property_array(this_ptr, SL("_handlers"), route_id, handler TSRMLS_CC); - - /** + + /** * The route is returned, the developer can add more things on it */ - RETURN_CCTOR(route); + PHALCON_MM_RESTORE(); + } /** - * Maps a route to a handler that only matches if the HTTP method is GET + * Maps a route to a handler without any HTTP method constraint * * @param string $routePattern * @param callable $handler * @return Phalcon\Mvc\Router\RouteInterface */ -PHP_METHOD(Phalcon_Mvc_Micro, get){ +PHP_METHOD(Phalcon_Mvc_Micro, map){ - zval *route_pattern, *handler, *router, *route; - zval *route_id; + phalcon_mvc_micro_generic_add(INTERNAL_FUNCTION_PARAM_PASSTHRU, "add"); +} - PHALCON_MM_GROW(); +/** + * Maps a route to a handler that only matches if the HTTP method is GET + * + * @param string $routePattern + * @param callable $handler + * @return Phalcon\Mvc\Router\RouteInterface + */ +PHP_METHOD(Phalcon_Mvc_Micro, get){ - phalcon_fetch_params(1, 2, 0, &route_pattern, &handler); - - /** - * We create a router even if there is no one in the DI - */ - PHALCON_INIT_VAR(router); - phalcon_call_method(router, this_ptr, "getrouter"); - - /** - * Routes are added to the router restricting to GET - */ - PHALCON_INIT_VAR(route); - phalcon_call_method_p1(route, router, "addget", route_pattern); - - /** - * Using the id produced by the router we store the handler - */ - PHALCON_INIT_VAR(route_id); - phalcon_call_method(route_id, route, "getrouteid"); - phalcon_update_property_array(this_ptr, SL("_handlers"), route_id, handler TSRMLS_CC); - - /** - * The route is returned, the developer can add more things on it - */ - RETURN_CCTOR(route); + phalcon_mvc_micro_generic_add(INTERNAL_FUNCTION_PARAM_PASSTHRU, "addget"); } /** @@ -235,36 +206,7 @@ PHP_METHOD(Phalcon_Mvc_Micro, get){ */ PHP_METHOD(Phalcon_Mvc_Micro, post){ - zval *route_pattern, *handler, *router, *route; - zval *route_id; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 2, 0, &route_pattern, &handler); - - /** - * We create a router even if there is no one in the DI - */ - PHALCON_INIT_VAR(router); - phalcon_call_method(router, this_ptr, "getrouter"); - - /** - * Routes are added to the router restricting to POST - */ - PHALCON_INIT_VAR(route); - phalcon_call_method_p1(route, router, "addpost", route_pattern); - - /** - * Using the id produced by the router we store the handler - */ - PHALCON_INIT_VAR(route_id); - phalcon_call_method(route_id, route, "getrouteid"); - phalcon_update_property_array(this_ptr, SL("_handlers"), route_id, handler TSRMLS_CC); - - /** - * The route is returned, the developer can add more things on it - */ - RETURN_CCTOR(route); + phalcon_mvc_micro_generic_add(INTERNAL_FUNCTION_PARAM_PASSTHRU, "addpost"); } /** @@ -276,36 +218,7 @@ PHP_METHOD(Phalcon_Mvc_Micro, post){ */ PHP_METHOD(Phalcon_Mvc_Micro, put){ - zval *route_pattern, *handler, *router, *route; - zval *route_id; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 2, 0, &route_pattern, &handler); - - /** - * We create a router even if there is no one in the DI - */ - PHALCON_INIT_VAR(router); - phalcon_call_method(router, this_ptr, "getrouter"); - - /** - * Routes are added to the router restricting to PUT - */ - PHALCON_INIT_VAR(route); - phalcon_call_method_p1(route, router, "addput", route_pattern); - - /** - * Using the id produced by the router we store the handler - */ - PHALCON_INIT_VAR(route_id); - phalcon_call_method(route_id, route, "getrouteid"); - phalcon_update_property_array(this_ptr, SL("_handlers"), route_id, handler TSRMLS_CC); - - /** - * The route is returned, the developer can add more things on it - */ - RETURN_CCTOR(route); + phalcon_mvc_micro_generic_add(INTERNAL_FUNCTION_PARAM_PASSTHRU, "addput"); } /** @@ -317,36 +230,7 @@ PHP_METHOD(Phalcon_Mvc_Micro, put){ */ PHP_METHOD(Phalcon_Mvc_Micro, patch){ - zval *route_pattern, *handler, *router, *route; - zval *route_id; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 2, 0, &route_pattern, &handler); - - /** - * We create a router even if there is no one in the DI - */ - PHALCON_INIT_VAR(router); - phalcon_call_method(router, this_ptr, "getrouter"); - - /** - * Routes are added to the router restricting to PATCH - */ - PHALCON_INIT_VAR(route); - phalcon_call_method_p1(route, router, "addpatch", route_pattern); - - /** - * Using the id produced by the router we store the handler - */ - PHALCON_INIT_VAR(route_id); - phalcon_call_method(route_id, route, "getrouteid"); - phalcon_update_property_array(this_ptr, SL("_handlers"), route_id, handler TSRMLS_CC); - - /** - * The route is returned, the developer can add more things on it - */ - RETURN_CCTOR(route); + phalcon_mvc_micro_generic_add(INTERNAL_FUNCTION_PARAM_PASSTHRU, "addpatch"); } /** @@ -358,36 +242,7 @@ PHP_METHOD(Phalcon_Mvc_Micro, patch){ */ PHP_METHOD(Phalcon_Mvc_Micro, head){ - zval *route_pattern, *handler, *router, *route; - zval *route_id; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 2, 0, &route_pattern, &handler); - - /** - * We create a router even if there is no one in the DI - */ - PHALCON_INIT_VAR(router); - phalcon_call_method(router, this_ptr, "getrouter"); - - /** - * Routes are added to the router restricting to HEAD - */ - PHALCON_INIT_VAR(route); - phalcon_call_method_p1(route, router, "addhead", route_pattern); - - /** - * Using the id produced by the router we store the handler - */ - PHALCON_INIT_VAR(route_id); - phalcon_call_method(route_id, route, "getrouteid"); - phalcon_update_property_array(this_ptr, SL("_handlers"), route_id, handler TSRMLS_CC); - - /** - * The route is returned, the developer can add more things on it - */ - RETURN_CCTOR(route); + phalcon_mvc_micro_generic_add(INTERNAL_FUNCTION_PARAM_PASSTHRU, "addhead"); } /** @@ -399,36 +254,7 @@ PHP_METHOD(Phalcon_Mvc_Micro, head){ */ PHP_METHOD(Phalcon_Mvc_Micro, delete){ - zval *route_pattern, *handler, *router, *route; - zval *route_id; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 2, 0, &route_pattern, &handler); - - /** - * We create a router even if there is no one in the DI - */ - PHALCON_INIT_VAR(router); - phalcon_call_method(router, this_ptr, "getrouter"); - - /** - * Routes are added to the router restricting to DELETE - */ - PHALCON_INIT_VAR(route); - phalcon_call_method_p1(route, router, "adddelete", route_pattern); - - /** - * Using the id produced by the router we store the handler - */ - PHALCON_INIT_VAR(route_id); - phalcon_call_method(route_id, route, "getrouteid"); - phalcon_update_property_array(this_ptr, SL("_handlers"), route_id, handler TSRMLS_CC); - - /** - * The route is returned, the developer can add more things on it - */ - RETURN_CCTOR(route); + phalcon_mvc_micro_generic_add(INTERNAL_FUNCTION_PARAM_PASSTHRU, "adddelete"); } /** @@ -440,36 +266,7 @@ PHP_METHOD(Phalcon_Mvc_Micro, delete){ */ PHP_METHOD(Phalcon_Mvc_Micro, options){ - zval *route_pattern, *handler, *router, *route; - zval *route_id; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 2, 0, &route_pattern, &handler); - - /** - * We create a router even if there is no one in the DI - */ - PHALCON_INIT_VAR(router); - phalcon_call_method(router, this_ptr, "getrouter"); - - /** - * Routes are added to the router restricting to OPTIONS - */ - PHALCON_INIT_VAR(route); - phalcon_call_method_p1(route, router, "addoptions", route_pattern); - - /** - * Using the id produced by the router we store the handler - */ - PHALCON_INIT_VAR(route_id); - phalcon_call_method(route_id, route, "getrouteid"); - phalcon_update_property_array(this_ptr, SL("_handlers"), route_id, handler TSRMLS_CC); - - /** - * The route is returned, the developer can add more things on it - */ - RETURN_CCTOR(route); + phalcon_mvc_micro_generic_add(INTERNAL_FUNCTION_PARAM_PASSTHRU, "addoptions"); } /** @@ -614,40 +411,37 @@ PHP_METHOD(Phalcon_Mvc_Micro, notFound){ */ PHP_METHOD(Phalcon_Mvc_Micro, getRouter){ - zval *router = NULL, *service_name, *remove; + zval *router, *service_name; - PHALCON_MM_GROW(); - - PHALCON_OBS_VAR(router); - phalcon_read_property_this(&router, this_ptr, SL("_router"), PH_NOISY_CC); + router = phalcon_fetch_nproperty_this(this_ptr, SL("_router"), PH_NOISY_CC); if (Z_TYPE_P(router) != IS_OBJECT) { + PHALCON_MM_GROW(); + PHALCON_INIT_VAR(service_name); ZVAL_STRING(service_name, "router", 1); - PHALCON_INIT_NVAR(router); - phalcon_call_method_p1(router, this_ptr, "getsharedservice", service_name); - PHALCON_VERIFY_INTERFACE(router, phalcon_mvc_routerinterface_ce); + phalcon_call_method_p1(return_value, this_ptr, "getsharedservice", service_name); + PHALCON_VERIFY_INTERFACE(return_value, phalcon_mvc_routerinterface_ce); /** * Clear the set routes if any */ - phalcon_call_method_noret(router, "clear"); - - PHALCON_INIT_VAR(remove); - ZVAL_BOOL(remove, 1); + phalcon_call_method_noret(return_value, "clear"); /** * Automatically remove extra slashes */ - phalcon_call_method_p1_noret(router, "removeextraslashes", remove); + phalcon_call_method_p1_noret(return_value, "removeextraslashes", PHALCON_GLOBAL(z_true)); /** * Update the internal router */ - phalcon_update_property_this(this_ptr, SL("_router"), router TSRMLS_CC); + phalcon_update_property_this(this_ptr, SL("_router"), return_value TSRMLS_CC); + PHALCON_MM_RESTORE(); + return; } - - RETURN_CCTOR(router); + + RETURN_ZVAL(router, 1, 0); } /** @@ -667,14 +461,12 @@ PHP_METHOD(Phalcon_Mvc_Micro, setService){ phalcon_fetch_params(1, 2, 1, &service_name, &definition, &shared); if (!shared) { - PHALCON_INIT_VAR(shared); - ZVAL_BOOL(shared, 0); + shared = PHALCON_GLOBAL(z_false); } - PHALCON_OBS_VAR(dependency_injector); - phalcon_read_property_this(&dependency_injector, this_ptr, SL("_dependencyInjector"), PH_NOISY_CC); + dependency_injector = phalcon_fetch_nproperty_this(this_ptr, SL("_dependencyInjector"), PH_NOISY_CC); if (Z_TYPE_P(dependency_injector) != IS_OBJECT) { - PHALCON_INIT_NVAR(dependency_injector); + PHALCON_INIT_VAR(dependency_injector); object_init_ex(dependency_injector, phalcon_di_factorydefault_ce); phalcon_call_method_noret(dependency_injector, "__construct"); @@ -699,10 +491,9 @@ PHP_METHOD(Phalcon_Mvc_Micro, hasService){ phalcon_fetch_params(1, 1, 0, &service_name); - PHALCON_OBS_VAR(dependency_injector); - phalcon_read_property_this(&dependency_injector, this_ptr, SL("_dependencyInjector"), PH_NOISY_CC); + dependency_injector = phalcon_fetch_nproperty_this(this_ptr, SL("_dependencyInjector"), PH_NOISY_CC); if (Z_TYPE_P(dependency_injector) != IS_OBJECT) { - PHALCON_INIT_NVAR(dependency_injector); + PHALCON_INIT_VAR(dependency_injector); object_init_ex(dependency_injector, phalcon_di_factorydefault_ce); phalcon_call_method_noret(dependency_injector, "__construct"); @@ -727,10 +518,9 @@ PHP_METHOD(Phalcon_Mvc_Micro, getService){ phalcon_fetch_params(1, 1, 0, &service_name); - PHALCON_OBS_VAR(dependency_injector); - phalcon_read_property_this(&dependency_injector, this_ptr, SL("_dependencyInjector"), PH_NOISY_CC); + dependency_injector = phalcon_fetch_nproperty_this(this_ptr, SL("_dependencyInjector"), PH_NOISY_CC); if (Z_TYPE_P(dependency_injector) != IS_OBJECT) { - PHALCON_INIT_NVAR(dependency_injector); + PHALCON_INIT_VAR(dependency_injector); object_init_ex(dependency_injector, phalcon_di_factorydefault_ce); phalcon_call_method_noret(dependency_injector, "__construct"); @@ -755,10 +545,9 @@ PHP_METHOD(Phalcon_Mvc_Micro, getSharedService){ phalcon_fetch_params(1, 1, 0, &service_name); - PHALCON_OBS_VAR(dependency_injector); - phalcon_read_property_this(&dependency_injector, this_ptr, SL("_dependencyInjector"), PH_NOISY_CC); + dependency_injector = phalcon_fetch_nproperty_this(this_ptr, SL("_dependencyInjector"), PH_NOISY_CC); if (Z_TYPE_P(dependency_injector) != IS_OBJECT) { - PHALCON_INIT_NVAR(dependency_injector); + PHALCON_INIT_VAR(dependency_injector); object_init_ex(dependency_injector, phalcon_di_factorydefault_ce); phalcon_call_method_noret(dependency_injector, "__construct"); @@ -793,11 +582,10 @@ PHP_METHOD(Phalcon_Mvc_Micro, handle){ phalcon_fetch_params(1, 0, 1, &uri); if (!uri) { - PHALCON_INIT_VAR(uri); + uri = PHALCON_GLOBAL(z_null); } - PHALCON_OBS_VAR(dependency_injector); - phalcon_read_property_this(&dependency_injector, this_ptr, SL("_dependencyInjector"), PH_NOISY_CC); + dependency_injector = phalcon_fetch_nproperty_this(this_ptr, SL("_dependencyInjector"), PH_NOISY_CC); if (Z_TYPE_P(dependency_injector) != IS_OBJECT) { PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_micro_exception_ce, "A dependency injection container is required to access related dispatching services"); return; @@ -806,8 +594,7 @@ PHP_METHOD(Phalcon_Mvc_Micro, handle){ /** * Calling beforeHandle routing */ - PHALCON_OBS_VAR(events_manager); - phalcon_read_property_this(&events_manager, this_ptr, SL("_eventsManager"), PH_NOISY_CC); + events_manager = phalcon_fetch_nproperty_this(this_ptr, SL("_eventsManager"), PH_NOISY_CC); if (Z_TYPE_P(events_manager) == IS_OBJECT) { PHALCON_INIT_VAR(event_name); @@ -842,12 +629,11 @@ PHP_METHOD(Phalcon_Mvc_Micro, handle){ phalcon_call_method(matched_route, router, "getmatchedroute"); if (Z_TYPE_P(matched_route) == IS_OBJECT) { - PHALCON_OBS_VAR(handlers); - phalcon_read_property_this(&handlers, this_ptr, SL("_handlers"), PH_NOISY_CC); + handlers = phalcon_fetch_nproperty_this(this_ptr, SL("_handlers"), PH_NOISY_CC); PHALCON_INIT_VAR(route_id); phalcon_call_method(route_id, matched_route, "getrouteid"); - if (!phalcon_array_isset(handlers, route_id)) { + if (!phalcon_array_isset_fetch(&handler, handlers, route_id)) { PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_micro_exception_ce, "Matched route doesn't have an associate handler"); return; } @@ -855,8 +641,6 @@ PHP_METHOD(Phalcon_Mvc_Micro, handle){ /** * Updating active handler */ - PHALCON_OBS_VAR(handler); - phalcon_array_fetch(&handler, handlers, route_id, PH_NOISY); phalcon_update_property_this(this_ptr, SL("_activeHandler"), handler TSRMLS_CC); /** @@ -872,15 +656,13 @@ PHP_METHOD(Phalcon_Mvc_Micro, handle){ if (PHALCON_IS_FALSE(status)) { RETURN_MM_FALSE; } else { - PHALCON_OBS_NVAR(handler); - phalcon_read_property_this(&handler, this_ptr, SL("_activeHandler"), PH_NOISY_CC); + handler = phalcon_fetch_nproperty_this(this_ptr, SL("_activeHandler"), PH_NOISY_CC); } } - PHALCON_OBS_VAR(before_handlers); - phalcon_read_property_this(&before_handlers, this_ptr, SL("_beforeHandlers"), PH_NOISY_CC); + before_handlers = phalcon_fetch_nproperty_this(this_ptr, SL("_beforeHandlers"), PH_NOISY_CC); if (Z_TYPE_P(before_handlers) == IS_ARRAY) { - phalcon_update_property_bool(this_ptr, SL("_stopped"), 0 TSRMLS_CC); + phalcon_update_property_this(this_ptr, SL("_stopped"), PHALCON_GLOBAL(z_false) TSRMLS_CC); /** * Calls the before handlers @@ -906,8 +688,7 @@ PHP_METHOD(Phalcon_Mvc_Micro, handle){ /** * Reload the status */ - PHALCON_OBS_NVAR(stopped); - phalcon_read_property_this(&stopped, this_ptr, SL("_stopped"), PH_NOISY_CC); + stopped = phalcon_fetch_nproperty_this(this_ptr, SL("_stopped"), PH_NOISY_CC); /** * break the execution if the middleware was stopped @@ -937,8 +718,7 @@ PHP_METHOD(Phalcon_Mvc_Micro, handle){ /** * Reload the 'stopped' status */ - PHALCON_OBS_NVAR(stopped); - phalcon_read_property_this(&stopped, this_ptr, SL("_stopped"), PH_NOISY_CC); + stopped = phalcon_fetch_nproperty_this(this_ptr, SL("_stopped"), PH_NOISY_CC); if (zend_is_true(stopped)) { RETURN_CCTOR(status); } @@ -971,8 +751,7 @@ PHP_METHOD(Phalcon_Mvc_Micro, handle){ phalcon_call_method_p2_noret(events_manager, "fire", event_name, this_ptr); } - PHALCON_OBS_VAR(after_handlers); - phalcon_read_property_this(&after_handlers, this_ptr, SL("_afterHandlers"), PH_NOISY_CC); + after_handlers = phalcon_fetch_nproperty_this(this_ptr, SL("_afterHandlers"), PH_NOISY_CC); if (Z_TYPE_P(after_handlers) == IS_ARRAY) { phalcon_update_property_bool(this_ptr, SL("_stopped"), 0 TSRMLS_CC); @@ -1000,8 +779,7 @@ PHP_METHOD(Phalcon_Mvc_Micro, handle){ /** * Reload the status */ - PHALCON_OBS_NVAR(stopped); - phalcon_read_property_this(&stopped, this_ptr, SL("_stopped"), PH_NOISY_CC); + stopped = phalcon_fetch_nproperty_this(this_ptr, SL("_stopped"), PH_NOISY_CC); /** * break the execution if the middleware was stopped @@ -1030,8 +808,6 @@ PHP_METHOD(Phalcon_Mvc_Micro, handle){ /** * Calling beforeNotFound event */ - PHALCON_OBS_NVAR(events_manager); - phalcon_read_property_this(&events_manager, this_ptr, SL("_eventsManager"), PH_NOISY_CC); if (Z_TYPE_P(events_manager) == IS_OBJECT) { PHALCON_INIT_NVAR(event_name); @@ -1047,8 +823,7 @@ PHP_METHOD(Phalcon_Mvc_Micro, handle){ /** * Check if a notfoundhandler is defined and it's callable */ - PHALCON_OBS_VAR(not_found_handler); - phalcon_read_property_this(¬_found_handler, this_ptr, SL("_notFoundHandler"), PH_NOISY_CC); + not_found_handler = phalcon_fetch_nproperty_this(this_ptr, SL("_notFoundHandler"), PH_NOISY_CC); if (!phalcon_is_callable(not_found_handler TSRMLS_CC)) { PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_micro_exception_ce, "The Not-Found handler is not callable or is not defined"); return; @@ -1057,15 +832,15 @@ PHP_METHOD(Phalcon_Mvc_Micro, handle){ /** * Call the Not-Found handler */ - PHALCON_INIT_NVAR(returned_value); - PHALCON_CALL_USER_FUNC(returned_value, not_found_handler); + PHALCON_CALL_USER_FUNC(return_value, not_found_handler); /** * Update the returned value */ - phalcon_update_property_this(this_ptr, SL("_returnedValue"), returned_value TSRMLS_CC); + phalcon_update_property_this(this_ptr, SL("_returnedValue"), return_value TSRMLS_CC); - RETURN_CCTOR(returned_value); + PHALCON_MM_RESTORE(); + return; } /** @@ -1077,10 +852,9 @@ PHP_METHOD(Phalcon_Mvc_Micro, handle){ phalcon_call_method_p2_noret(events_manager, "fire", event_name, this_ptr); } - PHALCON_OBS_VAR(finish_handlers); - phalcon_read_property_this(&finish_handlers, this_ptr, SL("_finishHandlers"), PH_NOISY_CC); + finish_handlers = phalcon_fetch_nproperty_this(this_ptr, SL("_finishHandlers"), PH_NOISY_CC); if (Z_TYPE_P(finish_handlers) == IS_ARRAY) { - phalcon_update_property_bool(this_ptr, SL("_stopped"), 0 TSRMLS_CC); + phalcon_update_property_this(this_ptr, SL("_stopped"), PHALCON_GLOBAL(z_false) TSRMLS_CC); PHALCON_INIT_NVAR(params); @@ -1111,8 +885,7 @@ PHP_METHOD(Phalcon_Mvc_Micro, handle){ /** * Reload the status */ - PHALCON_OBS_NVAR(stopped); - phalcon_read_property_this(&stopped, this_ptr, SL("_stopped"), PH_NOISY_CC); + stopped = phalcon_fetch_nproperty_this(this_ptr, SL("_stopped"), PH_NOISY_CC); /** * break the execution if the middleware was stopped @@ -1145,8 +918,7 @@ PHP_METHOD(Phalcon_Mvc_Micro, handle){ /** * Reload the status */ - PHALCON_OBS_NVAR(stopped); - phalcon_read_property_this(&stopped, this_ptr, SL("_stopped"), PH_NOISY_CC); + stopped = phalcon_fetch_nproperty_this(this_ptr, SL("_stopped"), PH_NOISY_CC); /** * break the execution if the middleware was stopped @@ -1184,7 +956,7 @@ PHP_METHOD(Phalcon_Mvc_Micro, handle){ PHP_METHOD(Phalcon_Mvc_Micro, stop){ - phalcon_update_property_bool(this_ptr, SL("_stopped"), 1 TSRMLS_CC); + phalcon_update_property_this(this_ptr, SL("_stopped"), PHALCON_GLOBAL(z_true) TSRMLS_CC); } @@ -1272,7 +1044,7 @@ PHP_METHOD(Phalcon_Mvc_Micro, offsetUnset){ phalcon_fetch_params(0, 1, 0, &alias); - RETURN_CCTORW(alias); + RETURN_ZVAL(alias, 1, 0); } /** @@ -1333,4 +1105,3 @@ PHP_METHOD(Phalcon_Mvc_Micro, getHandlers){ RETURN_MEMBER(this_ptr, "_handlers"); } - diff --git a/ext/mvc/micro/collection.c b/ext/mvc/micro/collection.c index 362008128db..982a6407564 100644 --- a/ext/mvc/micro/collection.c +++ b/ext/mvc/micro/collection.c @@ -148,18 +148,15 @@ PHP_METHOD(Phalcon_Mvc_Micro_Collection, setHandler){ zval *handler, *lazy = NULL; - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 1, 1, &handler, &lazy); + phalcon_fetch_params(0, 1, 1, &handler, &lazy); if (!lazy) { - PHALCON_INIT_VAR(lazy); - ZVAL_FALSE(lazy); + lazy = PHALCON_GLOBAL(z_false); } phalcon_update_property_this(this_ptr, SL("_handler"), handler TSRMLS_CC); phalcon_update_property_this(this_ptr, SL("_lazy"), lazy TSRMLS_CC); - RETURN_THIS(); + RETURN_THISW(); } /** diff --git a/ext/mvc/model.c b/ext/mvc/model.c index 33ce40706c4..b9b7e9dd42d 100644 --- a/ext/mvc/model.c +++ b/ext/mvc/model.c @@ -676,7 +676,7 @@ PHP_METHOD(Phalcon_Mvc_Model, assign){ phalcon_fetch_params(1, 1, 1, &data, &column_map); if (!column_map) { - PHALCON_INIT_VAR(column_map); + column_map = PHALCON_GLOBAL(z_null); } if (Z_TYPE_P(data) != IS_ARRAY) { @@ -751,12 +751,11 @@ PHP_METHOD(Phalcon_Mvc_Model, cloneResultMap){ phalcon_fetch_params(1, 3, 2, &base, &data, &column_map, &dirty_state, &keep_snapshots); if (!dirty_state) { - PHALCON_INIT_VAR(dirty_state); - ZVAL_LONG(dirty_state, 0); + dirty_state = PHALCON_GLOBAL(z_zero); } if (!keep_snapshots) { - PHALCON_INIT_VAR(keep_snapshots); + keep_snapshots = PHALCON_GLOBAL(z_null); } if (Z_TYPE_P(data) != IS_ARRAY) { @@ -940,8 +939,7 @@ PHP_METHOD(Phalcon_Mvc_Model, cloneResult){ phalcon_fetch_params(1, 2, 1, &base, &data, &dirty_state); if (!dirty_state) { - PHALCON_INIT_VAR(dirty_state); - ZVAL_LONG(dirty_state, 0); + dirty_state = PHALCON_GLOBAL(z_zero); } if (Z_TYPE_P(data) != IS_ARRAY) { @@ -1029,7 +1027,7 @@ PHP_METHOD(Phalcon_Mvc_Model, find){ phalcon_fetch_params(1, 0, 1, ¶meters); if (!parameters) { - PHALCON_INIT_VAR(parameters); + parameters = PHALCON_GLOBAL(z_null); } PHALCON_INIT_VAR(model_name); @@ -1136,7 +1134,7 @@ PHP_METHOD(Phalcon_Mvc_Model, findFirst){ phalcon_fetch_params(1, 0, 1, ¶meters); if (!parameters) { - PHALCON_INIT_VAR(parameters); + parameters = PHALCON_GLOBAL(z_null); } PHALCON_INIT_VAR(model_name); @@ -1196,8 +1194,7 @@ PHP_METHOD(Phalcon_Mvc_Model, findFirst){ phalcon_call_method_p1_noret(query, "cache", cache); } - PHALCON_INIT_VAR(unique); - ZVAL_BOOL(unique, 1); + unique = PHALCON_GLOBAL(z_true); /** * Return only the first row @@ -1635,7 +1632,7 @@ PHP_METHOD(Phalcon_Mvc_Model, count){ phalcon_fetch_params(1, 0, 1, ¶meters); if (!parameters) { - PHALCON_INIT_VAR(parameters); + parameters = PHALCON_GLOBAL(z_null); } PHALCON_INIT_VAR(function); @@ -1674,7 +1671,7 @@ PHP_METHOD(Phalcon_Mvc_Model, sum){ phalcon_fetch_params(1, 0, 1, ¶meters); if (!parameters) { - PHALCON_INIT_VAR(parameters); + parameters = PHALCON_GLOBAL(z_null); } PHALCON_INIT_VAR(function); @@ -1713,7 +1710,7 @@ PHP_METHOD(Phalcon_Mvc_Model, maximum){ phalcon_fetch_params(1, 0, 1, ¶meters); if (!parameters) { - PHALCON_INIT_VAR(parameters); + parameters = PHALCON_GLOBAL(z_null); } PHALCON_INIT_VAR(function); @@ -1752,7 +1749,7 @@ PHP_METHOD(Phalcon_Mvc_Model, minimum){ phalcon_fetch_params(1, 0, 1, ¶meters); if (!parameters) { - PHALCON_INIT_VAR(parameters); + parameters = PHALCON_GLOBAL(z_null); } PHALCON_INIT_VAR(function); @@ -1791,7 +1788,7 @@ PHP_METHOD(Phalcon_Mvc_Model, average){ phalcon_fetch_params(1, 0, 1, ¶meters); if (!parameters) { - PHALCON_INIT_VAR(parameters); + parameters = PHALCON_GLOBAL(z_null); } PHALCON_INIT_VAR(function); @@ -3610,8 +3607,7 @@ PHP_METHOD(Phalcon_Mvc_Model, _preSaveRelatedRecords){ phalcon_fetch_params(1, 2, 0, &connection, &related); - PHALCON_INIT_VAR(nesting); - ZVAL_BOOL(nesting, 0); + nesting = PHALCON_GLOBAL(z_false); /** * Start an implicit transaction @@ -3982,11 +3978,11 @@ PHP_METHOD(Phalcon_Mvc_Model, save){ phalcon_fetch_params(1, 0, 2, &data, &white_list); if (!data) { - PHALCON_INIT_VAR(data); + data = PHALCON_GLOBAL(z_null); } if (!white_list) { - PHALCON_INIT_VAR(white_list); + white_list = PHALCON_GLOBAL(z_null); } PHALCON_INIT_VAR(meta_data); @@ -4250,11 +4246,11 @@ PHP_METHOD(Phalcon_Mvc_Model, create){ phalcon_fetch_params(1, 0, 2, &data, &white_list); if (!data) { - PHALCON_INIT_VAR(data); + data = PHALCON_GLOBAL(z_null); } if (!white_list) { - PHALCON_INIT_VAR(white_list); + white_list = PHALCON_GLOBAL(z_null); } PHALCON_INIT_VAR(meta_data); @@ -4415,11 +4411,11 @@ PHP_METHOD(Phalcon_Mvc_Model, update){ phalcon_fetch_params(1, 0, 2, &data, &white_list); if (!data) { - PHALCON_INIT_VAR(data); + data = PHALCON_GLOBAL(z_null); } if (!white_list) { - PHALCON_INIT_VAR(white_list); + white_list = PHALCON_GLOBAL(z_null); } PHALCON_INIT_VAR(meta_data); @@ -5027,8 +5023,7 @@ PHP_METHOD(Phalcon_Mvc_Model, skipAttributes){ } if (!replace) { - PHALCON_INIT_VAR(replace); - ZVAL_FALSE(replace); + replace = PHALCON_GLOBAL(z_false); } PHALCON_INIT_VAR(null_value); @@ -5092,11 +5087,11 @@ PHP_METHOD(Phalcon_Mvc_Model, skipAttributesOnCreate){ } if (!replace) { - PHALCON_INIT_VAR(replace); + replace = PHALCON_GLOBAL(z_false); ZVAL_FALSE(replace); } - PHALCON_INIT_VAR(null_value); + null_value = PHALCON_GLOBAL(z_null); PHALCON_INIT_VAR(keys_attributes); array_init(keys_attributes); @@ -5156,11 +5151,10 @@ PHP_METHOD(Phalcon_Mvc_Model, skipAttributesOnUpdate){ } if (!replace) { - PHALCON_INIT_VAR(replace); - ZVAL_FALSE(replace); + replace = PHALCON_GLOBAL(z_false); } - PHALCON_INIT_VAR(null_value); + null_value = PHALCON_GLOBAL(z_null); PHALCON_INIT_VAR(keys_attributes); array_init(keys_attributes); @@ -5171,7 +5165,7 @@ PHP_METHOD(Phalcon_Mvc_Model, skipAttributesOnUpdate){ PHALCON_GET_HVALUE(attribute); - phalcon_array_update_zval(&keys_attributes, attribute, &null_value, PH_COPY | PH_SEPARATE); + phalcon_array_update_zval(&keys_attributes, attribute, &null_value, PH_COPY); zend_hash_move_forward_ex(ah0, &hp0); } @@ -5215,7 +5209,7 @@ PHP_METHOD(Phalcon_Mvc_Model, hasOne){ phalcon_fetch_params(1, 3, 1, &fields, &reference_model, &referenced_fields, &options); if (!options) { - PHALCON_INIT_VAR(options); + options = PHALCON_GLOBAL(z_null); } PHALCON_OBS_VAR(manager); @@ -5256,7 +5250,7 @@ PHP_METHOD(Phalcon_Mvc_Model, belongsTo){ phalcon_fetch_params(1, 3, 1, &fields, &reference_model, &referenced_fields, &options); if (!options) { - PHALCON_INIT_VAR(options); + options = PHALCON_GLOBAL(z_null); } PHALCON_OBS_VAR(manager); @@ -5297,7 +5291,7 @@ PHP_METHOD(Phalcon_Mvc_Model, hasMany){ phalcon_fetch_params(1, 3, 1, &fields, &reference_model, &referenced_fields, &options); if (!options) { - PHALCON_INIT_VAR(options); + options = PHALCON_GLOBAL(z_null); } PHALCON_OBS_VAR(manager); @@ -5449,7 +5443,7 @@ PHP_METHOD(Phalcon_Mvc_Model, setSnapshotData){ phalcon_fetch_params(1, 1, 1, &data, &column_map); if (!column_map) { - PHALCON_INIT_VAR(column_map); + column_map = PHALCON_GLOBAL(z_null); } if (Z_TYPE_P(data) != IS_ARRAY) { @@ -5558,7 +5552,7 @@ PHP_METHOD(Phalcon_Mvc_Model, hasChanged){ phalcon_fetch_params(1, 0, 1, &field_name); if (!field_name) { - PHALCON_INIT_VAR(field_name); + field_name = PHALCON_GLOBAL(z_null); } PHALCON_OBS_VAR(snapshot); @@ -5874,7 +5868,7 @@ PHP_METHOD(Phalcon_Mvc_Model, getRelated){ phalcon_fetch_params(1, 1, 1, &alias, &arguments); if (!arguments) { - PHALCON_INIT_VAR(arguments); + arguments = PHALCON_GLOBAL(z_null); } PHALCON_OBS_VAR(manager); @@ -6067,7 +6061,7 @@ PHP_METHOD(Phalcon_Mvc_Model, __callStatic){ phalcon_fetch_params(1, 1, 1, &method, &arguments); if (!arguments) { - PHALCON_INIT_VAR(arguments); + arguments = PHALCON_GLOBAL(z_null); } PHALCON_INIT_VAR(extra_method); diff --git a/ext/mvc/model/behavior.c b/ext/mvc/model/behavior.c index 0c16552eafe..85f05c2d16c 100644 --- a/ext/mvc/model/behavior.c +++ b/ext/mvc/model/behavior.c @@ -63,17 +63,13 @@ PHP_METHOD(Phalcon_Mvc_Model_Behavior, __construct){ zval *options = NULL; - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 0, 1, &options); + phalcon_fetch_params(0, 0, 1, &options); if (!options) { - PHALCON_INIT_VAR(options); + options = PHALCON_GLOBAL(z_null); } phalcon_update_property_this(this_ptr, SL("_options"), options TSRMLS_CC); - - PHALCON_MM_RESTORE(); } /** @@ -85,17 +81,14 @@ PHP_METHOD(Phalcon_Mvc_Model_Behavior, mustTakeAction){ zval *event_name, *options; - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 1, 0, &event_name); + phalcon_fetch_params(0, 1, 0, &event_name); - PHALCON_OBS_VAR(options); - phalcon_read_property_this(&options, this_ptr, SL("_options"), PH_NOISY_CC); + options = phalcon_fetch_nproperty_this(this_ptr, SL("_options"), PH_NOISY_CC); if (phalcon_array_isset(options, event_name)) { - RETURN_MM_TRUE; + RETURN_TRUE; } - RETURN_MM_FALSE; + RETURN_FALSE; } /** @@ -108,26 +101,17 @@ PHP_METHOD(Phalcon_Mvc_Model_Behavior, getOptions){ zval *event_name = NULL, *options, *event_options; - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 0, 1, &event_name); - - if (!event_name) { - PHALCON_INIT_VAR(event_name); - } + phalcon_fetch_params(0, 0, 1, &event_name); - PHALCON_OBS_VAR(options); - phalcon_read_property_this(&options, this_ptr, SL("_options"), PH_NOISY_CC); - if (Z_TYPE_P(event_name) != IS_NULL) { - if (phalcon_array_isset(options, event_name)) { - PHALCON_OBS_VAR(event_options); - phalcon_array_fetch(&event_options, options, event_name, PH_NOISY); - RETURN_CCTOR(event_options); + options = phalcon_fetch_nproperty_this(this_ptr, SL("_options"), PH_NOISY_CC); + if (event_name && Z_TYPE_P(event_name) != IS_NULL) { + if (phalcon_array_isset_fetch(&event_options, options, event_name)) { + RETURN_ZVAL(event_options, 1, 0); } - RETURN_MM_NULL(); + RETURN_NULL(); } - RETURN_CCTOR(options); + RETURN_ZVAL(options, 1, 0); } /** @@ -156,14 +140,7 @@ PHP_METHOD(Phalcon_Mvc_Model_Behavior, missingMethod){ zval *model, *method, *arguments = NULL; - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 2, 1, &model, &method, &arguments); - - if (!arguments) { - PHALCON_INIT_VAR(arguments); - } + phalcon_fetch_params(0, 2, 1, &model, &method, &arguments); - RETURN_MM_NULL(); + RETURN_NULL(); } - diff --git a/ext/mvc/model/behavior/softdelete.c b/ext/mvc/model/behavior/softdelete.c index f69a84792d6..983f8958e2f 100644 --- a/ext/mvc/model/behavior/softdelete.c +++ b/ext/mvc/model/behavior/softdelete.c @@ -66,7 +66,7 @@ PHALCON_INIT_CLASS(Phalcon_Mvc_Model_Behavior_SoftDelete){ */ PHP_METHOD(Phalcon_Mvc_Model_Behavior_SoftDelete, notify){ - zval *type, *model, *options, *skip, *value, *field, *actual_value; + zval *type, *model, *options, *value, *field, *actual_value; zval *update_model, *status, *messages, *message = NULL; HashTable *ah0; HashPosition hp0; @@ -90,13 +90,10 @@ PHP_METHOD(Phalcon_Mvc_Model_Behavior_SoftDelete, notify){ return; } - PHALCON_INIT_VAR(skip); - ZVAL_BOOL(skip, 1); - /** * Skip the current operation */ - phalcon_call_method_p1_noret(model, "skipoperation", skip); + phalcon_call_method_p1_noret(model, "skipoperation", PHALCON_GLOBAL(z_true)); /** * 'value' is the value to be updated instead of delete the record diff --git a/ext/mvc/model/criteria.c b/ext/mvc/model/criteria.c index b30646dfeca..044e478f1f3 100644 --- a/ext/mvc/model/criteria.c +++ b/ext/mvc/model/criteria.c @@ -42,6 +42,8 @@ #include "kernel/file.h" #include "kernel/hash.h" +#include "interned-strings.h" + /** * Phalcon\Mvc\Model\Criteria * @@ -103,17 +105,12 @@ PHP_METHOD(Phalcon_Mvc_Model_Criteria, getDI){ zval *params, *dependency_injector; - PHALCON_MM_GROW(); - - PHALCON_OBS_VAR(params); - phalcon_read_property_this(¶ms, this_ptr, SL("_params"), PH_NOISY_CC); - if (phalcon_array_isset_string(params, SS("di"))) { - PHALCON_OBS_VAR(dependency_injector); - phalcon_array_fetch_string(&dependency_injector, params, SL("di"), PH_NOISY); - RETURN_CCTOR(dependency_injector); + params = phalcon_fetch_nproperty_this(this_ptr, SL("_params"), PH_NOISY_CC); + if (phalcon_array_isset_string_fetch(&dependency_injector, params, SS("di"))) { + RETURN_ZVAL(dependency_injector, 1, 0); } - RETURN_MM_NULL(); + RETURN_NULL(); } /** @@ -146,11 +143,8 @@ PHP_METHOD(Phalcon_Mvc_Model_Criteria, getModelName){ zval *model; - PHALCON_MM_GROW(); - - PHALCON_OBS_VAR(model); - phalcon_read_property_this(&model, this_ptr, SL("_model"), PH_NOISY_CC); - RETURN_CCTOR(model); + model = phalcon_fetch_nproperty_this(this_ptr, SL("_model"), PH_NOISY_CC); + RETURN_ZVAL(model, 1, 0); } /** @@ -243,23 +237,23 @@ PHP_METHOD(Phalcon_Mvc_Model_Criteria, join){ phalcon_fetch_params(1, 1, 3, &model, &conditions, &alias, &type); if (!conditions) { - PHALCON_INIT_VAR(conditions); + conditions = PHALCON_GLOBAL(z_null); } if (!alias) { - PHALCON_INIT_VAR(alias); + alias = PHALCON_GLOBAL(z_null); } if (!type) { - PHALCON_INIT_VAR(type); + type = PHALCON_GLOBAL(z_null); } PHALCON_INIT_VAR(join); array_init_size(join, 4); - phalcon_array_append(&join, model, PH_SEPARATE); - phalcon_array_append(&join, conditions, PH_SEPARATE); - phalcon_array_append(&join, alias, PH_SEPARATE); - phalcon_array_append(&join, type, PH_SEPARATE); + phalcon_array_append(&join, model, 0); + phalcon_array_append(&join, conditions, 0); + phalcon_array_append(&join, alias, 0); + phalcon_array_append(&join, type, 0); PHALCON_OBS_VAR(params); phalcon_read_property_this(¶ms, this_ptr, SL("_params"), PH_NOISY_CC); @@ -276,7 +270,7 @@ PHP_METHOD(Phalcon_Mvc_Model_Criteria, join){ } else { PHALCON_INIT_NVAR(merged_joins); array_init_size(merged_joins, 1); - phalcon_array_append(&merged_joins, join, PH_SEPARATE); + phalcon_array_append(&merged_joins, join, 0); } phalcon_update_property_array_string(this_ptr, SL("_params"), SS("joins"), merged_joins TSRMLS_CC); @@ -310,11 +304,11 @@ PHP_METHOD(Phalcon_Mvc_Model_Criteria, innerJoin){ phalcon_fetch_params(1, 1, 2, &model, &conditions, &alias); if (!conditions) { - PHALCON_INIT_VAR(conditions); + conditions = PHALCON_GLOBAL(z_null); } if (!alias) { - PHALCON_INIT_VAR(alias); + alias = PHALCON_GLOBAL(z_null); } PHALCON_INIT_VAR(type); @@ -322,10 +316,10 @@ PHP_METHOD(Phalcon_Mvc_Model_Criteria, innerJoin){ PHALCON_INIT_VAR(join); array_init_size(join, 4); - phalcon_array_append(&join, model, PH_SEPARATE); - phalcon_array_append(&join, conditions, PH_SEPARATE); - phalcon_array_append(&join, alias, PH_SEPARATE); - phalcon_array_append(&join, type, PH_SEPARATE); + phalcon_array_append(&join, model, 0); + phalcon_array_append(&join, conditions, 0); + phalcon_array_append(&join, alias, 0); + phalcon_array_append(&join, type, 0); PHALCON_OBS_VAR(params); phalcon_read_property_this(¶ms, this_ptr, SL("_params"), PH_NOISY_CC); @@ -372,11 +366,11 @@ PHP_METHOD(Phalcon_Mvc_Model_Criteria, leftJoin){ phalcon_fetch_params(1, 1, 2, &model, &conditions, &alias); if (!conditions) { - PHALCON_INIT_VAR(conditions); + conditions = PHALCON_GLOBAL(z_null); } if (!alias) { - PHALCON_INIT_VAR(alias); + alias = PHALCON_GLOBAL(z_null); } PHALCON_INIT_VAR(type); @@ -384,10 +378,10 @@ PHP_METHOD(Phalcon_Mvc_Model_Criteria, leftJoin){ PHALCON_INIT_VAR(join); array_init_size(join, 4); - phalcon_array_append(&join, model, PH_SEPARATE); - phalcon_array_append(&join, conditions, PH_SEPARATE); - phalcon_array_append(&join, alias, PH_SEPARATE); - phalcon_array_append(&join, type, PH_SEPARATE); + phalcon_array_append(&join, model, 0); + phalcon_array_append(&join, conditions, 0); + phalcon_array_append(&join, alias, 0); + phalcon_array_append(&join, type, 0); PHALCON_OBS_VAR(params); phalcon_read_property_this(¶ms, this_ptr, SL("_params"), PH_NOISY_CC); @@ -434,11 +428,11 @@ PHP_METHOD(Phalcon_Mvc_Model_Criteria, rightJoin){ phalcon_fetch_params(1, 1, 2, &model, &conditions, &alias); if (!conditions) { - PHALCON_INIT_VAR(conditions); + conditions = PHALCON_GLOBAL(z_null); } if (!alias) { - PHALCON_INIT_VAR(alias); + alias = PHALCON_GLOBAL(z_null); } PHALCON_INIT_VAR(type); @@ -446,10 +440,10 @@ PHP_METHOD(Phalcon_Mvc_Model_Criteria, rightJoin){ PHALCON_INIT_VAR(join); array_init_size(join, 4); - phalcon_array_append(&join, model, PH_SEPARATE); - phalcon_array_append(&join, conditions, PH_SEPARATE); - phalcon_array_append(&join, alias, PH_SEPARATE); - phalcon_array_append(&join, type, PH_SEPARATE); + phalcon_array_append(&join, model, 0); + phalcon_array_append(&join, conditions, 0); + phalcon_array_append(&join, alias, 0); + phalcon_array_append(&join, type, 0); PHALCON_OBS_VAR(params); phalcon_read_property_this(¶ms, this_ptr, SL("_params"), PH_NOISY_CC); @@ -493,11 +487,11 @@ PHP_METHOD(Phalcon_Mvc_Model_Criteria, where){ phalcon_fetch_params(1, 1, 2, &conditions, &bind_params, &bind_types); if (!bind_params) { - PHALCON_INIT_VAR(bind_params); + bind_params = PHALCON_GLOBAL(z_null); } if (!bind_types) { - PHALCON_INIT_VAR(bind_types); + bind_types = PHALCON_GLOBAL(z_null); } if (Z_TYPE_P(conditions) != IS_STRING) { @@ -566,11 +560,11 @@ PHP_METHOD(Phalcon_Mvc_Model_Criteria, addWhere){ phalcon_fetch_params(1, 1, 2, &conditions, &bind_params, &bind_types); if (!bind_params) { - PHALCON_INIT_VAR(bind_params); + bind_params = PHALCON_GLOBAL(z_null); } if (!bind_types) { - PHALCON_INIT_VAR(bind_types); + bind_types = PHALCON_GLOBAL(z_null); } phalcon_call_method_p3_noret(this_ptr, "andwhere", conditions, bind_params, bind_types); @@ -597,11 +591,11 @@ PHP_METHOD(Phalcon_Mvc_Model_Criteria, andWhere){ phalcon_fetch_params(1, 1, 2, &conditions, &bind_params, &bind_types); if (!bind_params) { - PHALCON_INIT_VAR(bind_params); + bind_params = PHALCON_GLOBAL(z_null); } if (!bind_types) { - PHALCON_INIT_VAR(bind_types); + bind_types = PHALCON_GLOBAL(z_null); } if (Z_TYPE_P(conditions) != IS_STRING) { @@ -686,11 +680,11 @@ PHP_METHOD(Phalcon_Mvc_Model_Criteria, orWhere){ phalcon_fetch_params(1, 1, 2, &conditions, &bind_params, &bind_types); if (!bind_params) { - PHALCON_INIT_VAR(bind_params); + bind_params = PHALCON_GLOBAL(z_null); } if (!bind_types) { - PHALCON_INIT_VAR(bind_types); + bind_types = PHALCON_GLOBAL(z_null); } if (Z_TYPE_P(conditions) != IS_STRING) { @@ -769,7 +763,7 @@ PHP_METHOD(Phalcon_Mvc_Model_Criteria, orWhere){ */ PHP_METHOD(Phalcon_Mvc_Model_Criteria, betweenWhere){ - zval *expr, *minimum, *maximum, *hidden_param, *one; + zval *expr, *minimum, *maximum, *hidden_param; zval *next_hidden_param, *minimum_key, *maximum_key; zval *conditions, *bind_params; @@ -780,11 +774,8 @@ PHP_METHOD(Phalcon_Mvc_Model_Criteria, betweenWhere){ PHALCON_OBS_VAR(hidden_param); phalcon_read_property_this(&hidden_param, this_ptr, SL("_hiddenParamNumber"), PH_NOISY_CC); - PHALCON_INIT_VAR(one); - ZVAL_LONG(one, 1); - PHALCON_INIT_VAR(next_hidden_param); - phalcon_add_function(next_hidden_param, hidden_param, one TSRMLS_CC); + phalcon_add_function(next_hidden_param, hidden_param, PHALCON_GLOBAL(z_one) TSRMLS_CC); /** * Minimum key with auto bind-params @@ -806,8 +797,8 @@ PHP_METHOD(Phalcon_Mvc_Model_Criteria, betweenWhere){ PHALCON_INIT_VAR(bind_params); array_init_size(bind_params, 2); - phalcon_array_update_zval(&bind_params, minimum_key, &minimum, PH_COPY | PH_SEPARATE); - phalcon_array_update_zval(&bind_params, maximum_key, &maximum, PH_COPY | PH_SEPARATE); + phalcon_array_update_zval(&bind_params, minimum_key, &minimum, PH_COPY); + phalcon_array_update_zval(&bind_params, maximum_key, &maximum, PH_COPY); /** * Append the BETWEEN to the current conditions using and 'and' @@ -833,7 +824,7 @@ PHP_METHOD(Phalcon_Mvc_Model_Criteria, betweenWhere){ */ PHP_METHOD(Phalcon_Mvc_Model_Criteria, notBetweenWhere){ - zval *expr, *minimum, *maximum, *hidden_param, *one; + zval *expr, *minimum, *maximum, *hidden_param; zval *next_hidden_param, *minimum_key, *maximum_key; zval *conditions, *bind_params; @@ -844,11 +835,8 @@ PHP_METHOD(Phalcon_Mvc_Model_Criteria, notBetweenWhere){ PHALCON_OBS_VAR(hidden_param); phalcon_read_property_this(&hidden_param, this_ptr, SL("_hiddenParamNumber"), PH_NOISY_CC); - PHALCON_INIT_VAR(one); - ZVAL_LONG(one, 1); - PHALCON_INIT_VAR(next_hidden_param); - phalcon_add_function(next_hidden_param, hidden_param, one TSRMLS_CC); + phalcon_add_function(next_hidden_param, hidden_param, PHALCON_GLOBAL(z_one) TSRMLS_CC); /** * Minimum key with auto bind-params @@ -1118,7 +1106,7 @@ PHP_METHOD(Phalcon_Mvc_Model_Criteria, limit){ phalcon_fetch_params(1, 1, 1, &limit, &offset); if (!offset) { - PHALCON_INIT_VAR(offset); + offset = PHALCON_GLOBAL(z_null); } if (!phalcon_is_numeric(limit)) { @@ -1130,8 +1118,8 @@ PHP_METHOD(Phalcon_Mvc_Model_Criteria, limit){ } else { PHALCON_INIT_VAR(limit_clause); array_init_size(limit_clause, 2); - phalcon_array_update_string(&limit_clause, SL("number"), &limit, PH_COPY | PH_SEPARATE); - phalcon_array_update_string(&limit_clause, SL("offset"), &offset, PH_COPY | PH_SEPARATE); + phalcon_array_update_string(&limit_clause, SL("number"), &limit, PH_COPY); + phalcon_array_update_string(&limit_clause, SL("offset"), &offset, PH_COPY); phalcon_update_property_array_string(this_ptr, SL("_params"), SS("limit"), limit_clause TSRMLS_CC); } @@ -1148,17 +1136,14 @@ PHP_METHOD(Phalcon_Mvc_Model_Criteria, forUpdate){ zval *for_update = NULL; - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 0, 1, &for_update); + phalcon_fetch_params(0, 0, 1, &for_update); if (!for_update) { - PHALCON_INIT_VAR(for_update); - ZVAL_BOOL(for_update, 1); + for_update = PHALCON_GLOBAL(z_true); } phalcon_update_property_array_string(this_ptr, SL("_params"), SS("for_update"), for_update TSRMLS_CC); - RETURN_THIS(); + RETURN_THISW(); } /** @@ -1171,17 +1156,14 @@ PHP_METHOD(Phalcon_Mvc_Model_Criteria, sharedLock){ zval *shared_lock = NULL; - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 0, 1, &shared_lock); + phalcon_fetch_params(0, 0, 1, &shared_lock); if (!shared_lock) { - PHALCON_INIT_VAR(shared_lock); - ZVAL_BOOL(shared_lock, 1); + shared_lock = PHALCON_GLOBAL(z_true); } phalcon_update_property_array_string(this_ptr, SL("_params"), SS("shared_lock"), shared_lock TSRMLS_CC); - RETURN_THIS(); + RETURN_THISW(); } /** @@ -1193,17 +1175,12 @@ PHP_METHOD(Phalcon_Mvc_Model_Criteria, getWhere){ zval *params, *conditions; - PHALCON_MM_GROW(); - - PHALCON_OBS_VAR(params); - phalcon_read_property_this(¶ms, this_ptr, SL("_params"), PH_NOISY_CC); - if (phalcon_array_isset_string(params, SS("conditions"))) { - PHALCON_OBS_VAR(conditions); - phalcon_array_fetch_string(&conditions, params, SL("conditions"), PH_NOISY); - RETURN_CCTOR(conditions); + params = phalcon_fetch_nproperty_this(this_ptr, SL("_params"), PH_NOISY_CC); + if (phalcon_array_isset_string_fetch(&conditions, params, SS("conditions"))) { + RETURN_ZVAL(conditions, 1, 0); } - RETURN_MM_NULL(); + RETURN_NULL(); } /** @@ -1215,17 +1192,12 @@ PHP_METHOD(Phalcon_Mvc_Model_Criteria, getColumns){ zval *params, *columns; - PHALCON_MM_GROW(); - - PHALCON_OBS_VAR(params); - phalcon_read_property_this(¶ms, this_ptr, SL("_params"), PH_NOISY_CC); - if (phalcon_array_isset_string(params, SS("columns"))) { - PHALCON_OBS_VAR(columns); - phalcon_array_fetch_string(&columns, params, SL("columns"), PH_NOISY); - RETURN_CCTOR(columns); + params = phalcon_fetch_nproperty_this(this_ptr, SL("_params"), PH_NOISY_CC); + if (phalcon_array_isset_string_fetch(&columns, params, SS("columns"))) { + RETURN_ZVAL(columns, 1, 0); } - RETURN_MM_NULL(); + RETURN_NULL(); } /** @@ -1237,17 +1209,12 @@ PHP_METHOD(Phalcon_Mvc_Model_Criteria, getConditions){ zval *params, *conditions; - PHALCON_MM_GROW(); - - PHALCON_OBS_VAR(params); - phalcon_read_property_this(¶ms, this_ptr, SL("_params"), PH_NOISY_CC); - if (phalcon_array_isset_string(params, SS("conditions"))) { - PHALCON_OBS_VAR(conditions); - phalcon_array_fetch_string(&conditions, params, SL("conditions"), PH_NOISY); - RETURN_CCTOR(conditions); + params = phalcon_fetch_nproperty_this(this_ptr, SL("_params"), PH_NOISY_CC); + if (phalcon_array_isset_string_fetch(&conditions, params, SS("conditions"))) { + RETURN_ZVAL(conditions, 1, 0); } - RETURN_MM_NULL(); + RETURN_NULL(); } /** @@ -1257,19 +1224,14 @@ PHP_METHOD(Phalcon_Mvc_Model_Criteria, getConditions){ */ PHP_METHOD(Phalcon_Mvc_Model_Criteria, getLimit){ - zval *params, *conditions; - - PHALCON_MM_GROW(); + zval *params, *limit; - PHALCON_OBS_VAR(params); - phalcon_read_property_this(¶ms, this_ptr, SL("_params"), PH_NOISY_CC); - if (phalcon_array_isset_string(params, SS("limit"))) { - PHALCON_OBS_VAR(conditions); - phalcon_array_fetch_string(&conditions, params, SL("limit"), PH_NOISY); - RETURN_CCTOR(conditions); + params = phalcon_fetch_nproperty_this(this_ptr, SL("_params"), PH_NOISY_CC); + if (phalcon_array_isset_string_fetch(&limit, params, SS("limit"))) { + RETURN_ZVAL(limit, 1, 0); } - RETURN_MM_NULL(); + RETURN_NULL(); } /** @@ -1279,19 +1241,14 @@ PHP_METHOD(Phalcon_Mvc_Model_Criteria, getLimit){ */ PHP_METHOD(Phalcon_Mvc_Model_Criteria, getOrder){ - zval *params, *conditions; + zval *params, *order; - PHALCON_MM_GROW(); - - PHALCON_OBS_VAR(params); - phalcon_read_property_this(¶ms, this_ptr, SL("_params"), PH_NOISY_CC); - if (phalcon_array_isset_string(params, SS("order"))) { - PHALCON_OBS_VAR(conditions); - phalcon_array_fetch_string(&conditions, params, SL("order"), PH_NOISY); - RETURN_CCTOR(conditions); + params = phalcon_fetch_nproperty_this(this_ptr, SL("_params"), PH_NOISY_CC); + if (phalcon_array_isset_string_fetch(&order, params, SS("order"))) { + RETURN_ZVAL(order, 1, 0); } - RETURN_MM_NULL(); + RETURN_NULL(); } /** @@ -1342,7 +1299,7 @@ PHP_METHOD(Phalcon_Mvc_Model_Criteria, fromInput){ if (phalcon_fast_count_ev(data TSRMLS_CC)) { PHALCON_INIT_VAR(service); - ZVAL_STRING(service, "modelsMetadata", 1); + PHALCON_ZVAL_MAYBE_INTERNED_STRING(service, phalcon_interned_modelsMetadata); PHALCON_INIT_VAR(meta_data); phalcon_call_method_p1(meta_data, dependency_injector, "getshared", service); @@ -1428,12 +1385,11 @@ PHP_METHOD(Phalcon_Mvc_Model_Criteria, fromInput){ */ PHP_METHOD(Phalcon_Mvc_Model_Criteria, execute){ - zval *model, *params, *resultset; + zval *model, *params; PHALCON_MM_GROW(); - PHALCON_OBS_VAR(model); - phalcon_read_property_this(&model, this_ptr, SL("_model"), PH_NOISY_CC); + model = phalcon_fetch_nproperty_this(this_ptr, SL("_model"), PH_NOISY_CC); if (Z_TYPE_P(model) != IS_STRING) { PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "Model name must be string"); return; @@ -1442,9 +1398,7 @@ PHP_METHOD(Phalcon_Mvc_Model_Criteria, execute){ PHALCON_INIT_VAR(params); phalcon_call_method(params, this_ptr, "getparams"); - PHALCON_INIT_VAR(resultset); - phalcon_call_zval_str_static_p1(resultset, model, "find", params); + phalcon_call_zval_str_static_p1(return_value, model, "find", params); - RETURN_CCTOR(resultset); + PHALCON_MM_RESTORE(); } - diff --git a/ext/mvc/model/manager.c b/ext/mvc/model/manager.c index 399b4e81ab4..6f8ff2cd5db 100644 --- a/ext/mvc/model/manager.c +++ b/ext/mvc/model/manager.c @@ -277,23 +277,16 @@ PHP_METHOD(Phalcon_Mvc_Model_Manager, initialize){ PHP_METHOD(Phalcon_Mvc_Model_Manager, isInitialized){ zval *model_name, *initialized, *lowercased; - zval *is_intitialized = NULL; - zval *r0 = NULL; - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 1, 0, &model_name); + phalcon_fetch_params(0, 1, 0, &model_name); - PHALCON_OBS_VAR(initialized); - phalcon_read_property_this(&initialized, this_ptr, SL("_initialized"), PH_NOISY_CC); + initialized = phalcon_fetch_nproperty_this(this_ptr, SL("_initialized"), PH_NOISY_CC); - PHALCON_INIT_VAR(lowercased); + ALLOC_INIT_ZVAL(lowercased); phalcon_fast_strtolower(lowercased, model_name); - PHALCON_INIT_VAR(r0); - ZVAL_BOOL(r0, phalcon_array_isset(initialized, lowercased)); - PHALCON_CPY_WRT(is_intitialized, r0); - RETURN_NCTOR(is_intitialized); + RETVAL_BOOL(phalcon_array_isset(initialized, lowercased)); + zval_ptr_dtor(&lowercased); } /** @@ -326,8 +319,7 @@ PHP_METHOD(Phalcon_Mvc_Model_Manager, load){ phalcon_fetch_params(1, 1, 1, &model_name, &new_instance); if (!new_instance) { - PHALCON_INIT_VAR(new_instance); - ZVAL_BOOL(new_instance, 0); + new_instance = PHALCON_GLOBAL(z_false); } PHALCON_OBS_VAR(initialized); @@ -1127,7 +1119,7 @@ PHP_METHOD(Phalcon_Mvc_Model_Manager, addHasOne){ phalcon_fetch_params(1, 4, 1, &model, &fields, &referenced_model, &referenced_fields, &options); if (!options) { - PHALCON_INIT_VAR(options); + options = PHALCON_GLOBAL(z_null); } PHALCON_INIT_VAR(entity_name); @@ -1258,7 +1250,7 @@ PHP_METHOD(Phalcon_Mvc_Model_Manager, addBelongsTo){ phalcon_fetch_params(1, 4, 1, &model, &fields, &referenced_model, &referenced_fields, &options); if (!options) { - PHALCON_INIT_VAR(options); + options = PHALCON_GLOBAL(z_null); } PHALCON_INIT_VAR(entity_name); @@ -1388,7 +1380,7 @@ PHP_METHOD(Phalcon_Mvc_Model_Manager, addHasMany){ phalcon_fetch_params(1, 4, 1, &model, &fields, &referenced_model, &referenced_fields, &options); if (!options) { - PHALCON_INIT_VAR(options); + options = PHALCON_GLOBAL(z_null); } PHALCON_INIT_VAR(entity_name); @@ -1523,7 +1515,7 @@ PHP_METHOD(Phalcon_Mvc_Model_Manager, addHasManyToMany){ phalcon_fetch_params(1, 7, 1, &model, &fields, &intermediate_model, &intermediate_fields, &intermediate_referenced_fields, &referenced_model, &referenced_fields, &options); if (!options) { - PHALCON_INIT_VAR(options); + options = PHALCON_GLOBAL(z_null); } PHALCON_INIT_VAR(entity_name); @@ -2293,7 +2285,7 @@ PHP_METHOD(Phalcon_Mvc_Model_Manager, getBelongsToRecords){ phalcon_fetch_params(1, 4, 1, &method, &model_name, &model_relation, &record, ¶meters); if (!parameters) { - PHALCON_INIT_VAR(parameters); + parameters = PHALCON_GLOBAL(z_null); } PHALCON_OBS_VAR(belongs_to); @@ -2358,7 +2350,7 @@ PHP_METHOD(Phalcon_Mvc_Model_Manager, getHasManyRecords){ phalcon_fetch_params(1, 4, 1, &method, &model_name, &model_relation, &record, ¶meters); if (!parameters) { - PHALCON_INIT_VAR(parameters); + parameters = PHALCON_GLOBAL(z_null); } PHALCON_OBS_VAR(has_many); @@ -2423,7 +2415,7 @@ PHP_METHOD(Phalcon_Mvc_Model_Manager, getHasOneRecords){ phalcon_fetch_params(1, 4, 1, &method, &model_name, &model_relation, &record, ¶meters); if (!parameters) { - PHALCON_INIT_VAR(parameters); + parameters = PHALCON_GLOBAL(z_null); } PHALCON_OBS_VAR(has_one); @@ -2838,11 +2830,11 @@ PHP_METHOD(Phalcon_Mvc_Model_Manager, executeQuery){ phalcon_fetch_params(1, 1, 2, &phql, &placeholders, &types); if (!placeholders) { - PHALCON_INIT_VAR(placeholders); + placeholders = PHALCON_GLOBAL(z_null); } if (!types) { - PHALCON_INIT_VAR(types); + types = PHALCON_GLOBAL(z_null); } PHALCON_OBS_VAR(dependency_injector); @@ -2884,7 +2876,7 @@ PHP_METHOD(Phalcon_Mvc_Model_Manager, createBuilder){ phalcon_fetch_params(1, 0, 1, ¶ms); if (!params) { - PHALCON_INIT_VAR(params); + params = PHALCON_GLOBAL(z_null); } PHALCON_OBS_VAR(dependency_injector); diff --git a/ext/mvc/model/message.c b/ext/mvc/model/message.c index 6a8574f26f9..14953162372 100644 --- a/ext/mvc/model/message.c +++ b/ext/mvc/model/message.c @@ -95,25 +95,22 @@ PHP_METHOD(Phalcon_Mvc_Model_Message, __construct){ zval *message, *field = NULL, *type = NULL, *model = NULL, *code = NULL; - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 1, 4, &message, &field, &type, &code, &model); + phalcon_fetch_params(0, 1, 4, &message, &field, &type, &code, &model); if (!field) { - PHALCON_INIT_VAR(field); + field = PHALCON_GLOBAL(z_null); } if (!type) { - PHALCON_INIT_VAR(type); + type = PHALCON_GLOBAL(z_null); } if (!model) { - PHALCON_INIT_VAR(model); + model = PHALCON_GLOBAL(z_null); } if (!code) { - PHALCON_INIT_VAR(code); - ZVAL_LONG(code, 0); + code = PHALCON_GLOBAL(z_zero); } phalcon_update_property_this(this_ptr, SL("_message"), message TSRMLS_CC); @@ -123,8 +120,6 @@ PHP_METHOD(Phalcon_Mvc_Model_Message, __construct){ phalcon_update_property_this(this_ptr, SL("_model"), model TSRMLS_CC); } phalcon_update_property_this(this_ptr, SL("_code"), code TSRMLS_CC); - - PHALCON_MM_RESTORE(); } /** diff --git a/ext/mvc/model/metadata/apc.c b/ext/mvc/model/metadata/apc.c index d9e93e35c1f..6b20d277591 100644 --- a/ext/mvc/model/metadata/apc.c +++ b/ext/mvc/model/metadata/apc.c @@ -84,7 +84,7 @@ PHP_METHOD(Phalcon_Mvc_Model_MetaData_Apc, __construct){ phalcon_fetch_params(1, 0, 1, &options); if (!options) { - PHALCON_INIT_VAR(options); + options = PHALCON_GLOBAL(z_null); } if (Z_TYPE_P(options) == IS_ARRAY) { diff --git a/ext/mvc/model/metadata/files.c b/ext/mvc/model/metadata/files.c index d0273d343e3..26abf36a031 100644 --- a/ext/mvc/model/metadata/files.c +++ b/ext/mvc/model/metadata/files.c @@ -82,13 +82,11 @@ PHP_METHOD(Phalcon_Mvc_Model_MetaData_Files, __construct){ phalcon_fetch_params(1, 0, 1, &options); if (!options) { - PHALCON_INIT_VAR(options); + options = PHALCON_GLOBAL(z_null); } if (Z_TYPE_P(options) == IS_ARRAY) { - if (phalcon_array_isset_string(options, SS("metaDataDir"))) { - PHALCON_OBS_VAR(meta_data_dir); - phalcon_array_fetch_string(&meta_data_dir, options, SL("metaDataDir"), PH_NOISY); + if (phalcon_array_isset_string_fetch(&meta_data_dir, options, SS("metaDataDir"))) { phalcon_update_property_this(this_ptr, SL("_metaDataDir"), meta_data_dir TSRMLS_CC); } } @@ -147,7 +145,7 @@ PHP_METHOD(Phalcon_Mvc_Model_MetaData_Files, read){ PHP_METHOD(Phalcon_Mvc_Model_MetaData_Files, write){ zval *key, *data, *separator, *meta_data_dir, *virtual_key; - zval *path, *to_string, *export, *php_export, *status; + zval *path, *export, *php_export, *status; PHALCON_MM_GROW(); @@ -165,11 +163,8 @@ PHP_METHOD(Phalcon_Mvc_Model_MetaData_Files, write){ PHALCON_INIT_VAR(path); PHALCON_CONCAT_VVS(path, meta_data_dir, virtual_key, ".php"); - PHALCON_INIT_VAR(to_string); - ZVAL_BOOL(to_string, 1); - PHALCON_INIT_VAR(export); - phalcon_call_func_p2(export, "var_export", data, to_string); + phalcon_call_func_p2(export, "var_export", data, PHALCON_GLOBAL(z_true)); PHALCON_INIT_VAR(php_export); PHALCON_CONCAT_SVS(php_export, "= 2); + assert(Z_REFCOUNT_P(PHALCON_GLOBAL(z_false)) >= 2); + assert(Z_REFCOUNT_P(PHALCON_GLOBAL(z_true)) >= 2); + assert(Z_REFCOUNT_P(PHALCON_GLOBAL(z_zero)) >= 2); + assert(Z_REFCOUNT_P(PHALCON_GLOBAL(z_one)) >= 2); + + assert(Z_TYPE_P(PHALCON_GLOBAL(z_null)) == IS_NULL); + assert(Z_TYPE_P(PHALCON_GLOBAL(z_false)) == IS_BOOL); + assert(Z_TYPE_P(PHALCON_GLOBAL(z_true)) == IS_BOOL); + assert(Z_TYPE_P(PHALCON_GLOBAL(z_zero)) == IS_LONG); + assert(Z_TYPE_P(PHALCON_GLOBAL(z_one)) == IS_LONG); + + assert(Z_BVAL_P(PHALCON_GLOBAL(z_false)) == 0); + assert(Z_BVAL_P(PHALCON_GLOBAL(z_true)) == 1); + assert(Z_LVAL_P(PHALCON_GLOBAL(z_zero)) == 0); + assert(Z_LVAL_P(PHALCON_GLOBAL(z_one)) == 1); +#endif + return SUCCESS; } @@ -773,6 +792,30 @@ static PHP_GINIT_FUNCTION(phalcon) start->hash_capacity = 8; phalcon_globals->start_memory = start; + + ALLOC_PERMANENT_ZVAL(phalcon_globals->z_null); + INIT_ZVAL(*phalcon_globals->z_null); + Z_ADDREF_P(phalcon_globals->z_null); + + ALLOC_PERMANENT_ZVAL(phalcon_globals->z_false); + INIT_PZVAL(phalcon_globals->z_false); + Z_ADDREF_P(phalcon_globals->z_false); + ZVAL_FALSE(phalcon_globals->z_false); + + ALLOC_PERMANENT_ZVAL(phalcon_globals->z_true); + INIT_PZVAL(phalcon_globals->z_true); + Z_ADDREF_P(phalcon_globals->z_true); + ZVAL_TRUE(phalcon_globals->z_true); + + ALLOC_PERMANENT_ZVAL(phalcon_globals->z_zero); + INIT_PZVAL(phalcon_globals->z_zero); + Z_ADDREF_P(phalcon_globals->z_zero); + ZVAL_LONG(phalcon_globals->z_zero, 0); + + ALLOC_PERMANENT_ZVAL(phalcon_globals->z_one); + INIT_PZVAL(phalcon_globals->z_one); + Z_ADDREF_P(phalcon_globals->z_one); + ZVAL_LONG(phalcon_globals->z_one, 1); } static PHP_GSHUTDOWN_FUNCTION(phalcon) @@ -783,8 +826,63 @@ static PHP_GSHUTDOWN_FUNCTION(phalcon) pefree(phalcon_globals->start_memory->addresses, 1); pefree(phalcon_globals->start_memory, 1); phalcon_globals->start_memory = NULL; + +#ifndef PHALCON_RELEASE + assert(Z_REFCOUNT_P(PHALCON_GLOBAL(z_null)) == 2); + assert(Z_REFCOUNT_P(PHALCON_GLOBAL(z_false)) == 2); + assert(Z_REFCOUNT_P(PHALCON_GLOBAL(z_true)) == 2); + assert(Z_REFCOUNT_P(PHALCON_GLOBAL(z_zero)) == 2); + assert(Z_REFCOUNT_P(PHALCON_GLOBAL(z_one)) == 2); + + assert(Z_TYPE_P(PHALCON_GLOBAL(z_null)) == IS_NULL); + assert(Z_TYPE_P(PHALCON_GLOBAL(z_false)) == IS_BOOL); + assert(Z_TYPE_P(PHALCON_GLOBAL(z_true)) == IS_BOOL); + assert(Z_TYPE_P(PHALCON_GLOBAL(z_zero)) == IS_LONG); + assert(Z_TYPE_P(PHALCON_GLOBAL(z_one)) == IS_LONG); + + assert(Z_BVAL_P(PHALCON_GLOBAL(z_false)) == 0); + assert(Z_BVAL_P(PHALCON_GLOBAL(z_true)) == 1); + assert(Z_LVAL_P(PHALCON_GLOBAL(z_zero)) == 0); + assert(Z_LVAL_P(PHALCON_GLOBAL(z_one)) == 1); +#endif + + free(phalcon_globals->z_null); + free(phalcon_globals->z_false); + free(phalcon_globals->z_true); + free(phalcon_globals->z_zero); + free(phalcon_globals->z_one); } +#ifndef PHALCON_RELEASE + +static ZEND_MODULE_POST_ZEND_DEACTIVATE_D(phalcon) +{ +#ifndef NDEBUG + TSRMLS_FETCH(); + + assert(Z_REFCOUNT_P(PHALCON_GLOBAL(z_null)) == 2); + assert(Z_REFCOUNT_P(PHALCON_GLOBAL(z_false)) == 2); + assert(Z_REFCOUNT_P(PHALCON_GLOBAL(z_true)) == 2); + assert(Z_REFCOUNT_P(PHALCON_GLOBAL(z_zero)) == 2); + assert(Z_REFCOUNT_P(PHALCON_GLOBAL(z_one)) == 2); + + assert(Z_TYPE_P(PHALCON_GLOBAL(z_null)) == IS_NULL); + assert(Z_TYPE_P(PHALCON_GLOBAL(z_false)) == IS_BOOL); + assert(Z_TYPE_P(PHALCON_GLOBAL(z_true)) == IS_BOOL); + assert(Z_TYPE_P(PHALCON_GLOBAL(z_zero)) == IS_LONG); + assert(Z_TYPE_P(PHALCON_GLOBAL(z_one)) == IS_LONG); + + assert(Z_BVAL_P(PHALCON_GLOBAL(z_false)) == 0); + assert(Z_BVAL_P(PHALCON_GLOBAL(z_true)) == 1); + assert(Z_LVAL_P(PHALCON_GLOBAL(z_zero)) == 0); + assert(Z_LVAL_P(PHALCON_GLOBAL(z_one)) == 1); +#endif + + return SUCCESS; +} + +#endif + static #if ZEND_MODULE_API_NO > 20060613 const @@ -839,7 +937,11 @@ zend_module_entry phalcon_module_entry = { ZEND_MODULE_GLOBALS(phalcon), PHP_GINIT(phalcon), PHP_GSHUTDOWN(phalcon), +#ifdef PHALCON_RELEASE NULL, +#else + ZEND_MODULE_POST_ZEND_DEACTIVATE_N(phalcon), +#endif STANDARD_MODULE_PROPERTIES_EX }; diff --git a/ext/php_phalcon.h b/ext/php_phalcon.h index 5dcf00a710a..2f65c324c53 100644 --- a/ext/php_phalcon.h +++ b/ext/php_phalcon.h @@ -82,6 +82,13 @@ ZEND_BEGIN_MODULE_GLOBALS(phalcon) /** Virtual Symbol Tables */ phalcon_symbol_table *active_symbol_table; + /** Frequently used zvals */ + zval *z_null; + zval *z_true; + zval *z_false; + zval *z_zero; + zval *z_one; + /** Function cache */ HashTable *function_cache; diff --git a/ext/queue/beanstalk.c b/ext/queue/beanstalk.c index 90d2ec67af0..fa85a5ada92 100644 --- a/ext/queue/beanstalk.c +++ b/ext/queue/beanstalk.c @@ -78,7 +78,7 @@ PHP_METHOD(Phalcon_Queue_Beanstalk, __construct){ phalcon_fetch_params(1, 0, 1, &options); if (!options) { - PHALCON_INIT_VAR(options); + options = PHALCON_GLOBAL(z_null); } if (Z_TYPE_P(options) != IS_ARRAY) { @@ -164,7 +164,7 @@ PHP_METHOD(Phalcon_Queue_Beanstalk, put){ phalcon_fetch_params(1, 1, 1, &data, &options); if (!options) { - PHALCON_INIT_VAR(options); + options = PHALCON_GLOBAL(z_null); } /** @@ -246,7 +246,7 @@ PHP_METHOD(Phalcon_Queue_Beanstalk, reserve){ phalcon_fetch_params(1, 0, 1, &timeout); if (!timeout) { - PHALCON_INIT_VAR(timeout); + timeout = PHALCON_GLOBAL(z_null); } if (zend_is_true(timeout)) { @@ -438,7 +438,7 @@ PHP_METHOD(Phalcon_Queue_Beanstalk, read){ phalcon_fetch_params(1, 0, 1, &length); if (!length) { - PHALCON_INIT_VAR(length); + length = PHALCON_GLOBAL(z_null); } PHALCON_OBS_VAR(connection); diff --git a/ext/security.c b/ext/security.c index 26e80d35c98..11f73332e3e 100644 --- a/ext/security.c +++ b/ext/security.c @@ -442,7 +442,7 @@ PHP_METHOD(Phalcon_Security, checkToken){ } if (!token_value) { - PHALCON_INIT_VAR(token_value); + token_value = PHALCON_GLOBAL(z_null); } PHALCON_OBS_VAR(dependency_injector); diff --git a/ext/session/adapter.c b/ext/session/adapter.c index 1a42e8df3ab..d6454abb1d5 100644 --- a/ext/session/adapter.c +++ b/ext/session/adapter.c @@ -77,7 +77,7 @@ PHP_METHOD(Phalcon_Session_Adapter, __construct){ phalcon_fetch_params(1, 0, 1, &options); if (!options) { - PHALCON_INIT_VAR(options); + options = PHALCON_GLOBAL(z_null); } if (Z_TYPE_P(options) == IS_ARRAY) { @@ -170,7 +170,7 @@ PHP_METHOD(Phalcon_Session_Adapter, get){ phalcon_fetch_params(1, 1, 1, &index, &default_value); if (!default_value) { - PHALCON_INIT_VAR(default_value); + default_value = PHALCON_GLOBAL(z_null); } PHALCON_OBS_VAR(unique_id); diff --git a/ext/session/bag.c b/ext/session/bag.c index d54289d8fbd..9e660953edc 100644 --- a/ext/session/bag.c +++ b/ext/session/bag.c @@ -274,7 +274,7 @@ PHP_METHOD(Phalcon_Session_Bag, get){ phalcon_fetch_params(1, 1, 1, &property, &default_value); if (!default_value) { - PHALCON_INIT_VAR(default_value); + default_value = PHALCON_GLOBAL(z_null); } /** diff --git a/ext/tag.c b/ext/tag.c index d1873cbe7ed..e1e57a60afd 100644 --- a/ext/tag.c +++ b/ext/tag.c @@ -95,10 +95,8 @@ static void phalcon_tag_get_escaper(zval **return_value_ptr, zval *params TSRMLS } if (zend_is_true(autoescape)) { - ALLOC_INIT_ZVAL(result); - phalcon_call_self_func_params(result, NULL, NULL, SL("getescaperservice") TSRMLS_CC, 0); + phalcon_call_self_func_params(result, &result, NULL, SL("getescaperservice") TSRMLS_CC, 0); if (EG(exception)) { - zval_ptr_dtor(&result); result = NULL; } } @@ -472,7 +470,7 @@ PHP_METHOD(Phalcon_Tag, linkTo){ phalcon_fetch_params(1, 1, 1, ¶meters, &text); if (!text) { - PHALCON_INIT_VAR(text); + text = PHALCON_GLOBAL(z_null); } if (Z_TYPE_P(parameters) != IS_ARRAY) { @@ -538,8 +536,7 @@ PHP_METHOD(Phalcon_Tag, _inputField){ phalcon_fetch_params(1, 2, 1, &type, ¶meters, &as_value); if (!as_value) { - PHALCON_INIT_VAR(as_value); - ZVAL_FALSE(as_value); + as_value = PHALCON_GLOBAL(z_false); } if (Z_TYPE_P(parameters) != IS_ARRAY) { @@ -995,7 +992,7 @@ PHP_METHOD(Phalcon_Tag, selectStatic){ phalcon_fetch_params(1, 1, 1, ¶meters, &data); if (!data) { - PHALCON_INIT_VAR(data); + data = PHALCON_GLOBAL(z_null); } phalcon_call_static_p2(return_value, "phalcon\\tag\\select", "selectfield", parameters, data); @@ -1031,7 +1028,7 @@ PHP_METHOD(Phalcon_Tag, select){ phalcon_fetch_params(1, 1, 1, ¶meters, &data); if (!data) { - PHALCON_INIT_VAR(data); + data = PHALCON_GLOBAL(z_null); } phalcon_call_static_p2(return_value, "phalcon\\tag\\select", "selectfield", parameters, data); @@ -1318,8 +1315,7 @@ PHP_METHOD(Phalcon_Tag, stylesheetLink){ phalcon_fetch_params(1, 0, 2, ¶meters, &local); if (!local) { - PHALCON_INIT_VAR(local); - ZVAL_TRUE(local); + local = PHALCON_GLOBAL(z_true); } if (!parameters || Z_TYPE_P(parameters) != IS_ARRAY) { @@ -1414,8 +1410,7 @@ PHP_METHOD(Phalcon_Tag, javascriptInclude){ phalcon_fetch_params(1, 0, 2, ¶meters, &local); if (!local) { - PHALCON_INIT_VAR(local); - ZVAL_TRUE(local); + local = PHALCON_GLOBAL(z_true); } if (!parameters || Z_TYPE_P(parameters) != IS_ARRAY) { @@ -1500,7 +1495,7 @@ PHP_METHOD(Phalcon_Tag, image){ phalcon_fetch_params(1, 0, 2, ¶meters, &local); if (!parameters) { - PHALCON_INIT_VAR(parameters); + parameters = PHALCON_GLOBAL(z_null); } if (!local) { @@ -1588,8 +1583,7 @@ PHP_METHOD(Phalcon_Tag, friendlyTitle){ } if (!lowercase) { - PHALCON_INIT_VAR(lowercase); - ZVAL_TRUE(lowercase); + lowercase = PHALCON_GLOBAL(z_true); } PHALCON_INIT_VAR(pattern); @@ -1681,18 +1675,15 @@ PHP_METHOD(Phalcon_Tag, tagHtml){ phalcon_fetch_params(1, 1, 4, &tag_name, ¶meters, &self_close, &only_start, &use_eol); if (!self_close) { - PHALCON_INIT_VAR(self_close); - ZVAL_FALSE(self_close); + self_close = PHALCON_GLOBAL(z_false); } if (!only_start) { - PHALCON_INIT_VAR(only_start); - ZVAL_FALSE(only_start); + only_start = PHALCON_GLOBAL(z_false); } if (!use_eol) { - PHALCON_INIT_VAR(use_eol); - ZVAL_FALSE(use_eol); + use_eol = PHALCON_GLOBAL(z_false); } if (!parameters || Z_TYPE_P(parameters) != IS_ARRAY) { @@ -1754,8 +1745,7 @@ PHP_METHOD(Phalcon_Tag, tagHtmlClose){ phalcon_fetch_params(1, 1, 1, &tag_name, &use_eol); if (!use_eol) { - PHALCON_INIT_VAR(use_eol); - ZVAL_FALSE(use_eol); + use_eol = PHALCON_GLOBAL(z_false); } PHALCON_INIT_VAR(local_code); diff --git a/ext/tag/select.c b/ext/tag/select.c index 099acfed52f..a3af4668dac 100644 --- a/ext/tag/select.c +++ b/ext/tag/select.c @@ -79,14 +79,14 @@ PHP_METHOD(Phalcon_Tag_Select, selectField){ phalcon_fetch_params(1, 1, 1, ¶meters, &data); if (!data) { - PHALCON_INIT_VAR(data); + data = PHALCON_GLOBAL(z_null); } if (Z_TYPE_P(parameters) != IS_ARRAY) { PHALCON_INIT_VAR(params); array_init_size(params, 2); - phalcon_array_append(¶ms, parameters, PH_SEPARATE); - phalcon_array_append(¶ms, data, PH_SEPARATE); + phalcon_array_append(¶ms, parameters, 0); + phalcon_array_append(¶ms, data, 0); } else { PHALCON_CPY_WRT(params, parameters); } @@ -130,7 +130,7 @@ PHP_METHOD(Phalcon_Tag_Select, selectField){ } PHALCON_INIT_VAR(use_empty); - ZVAL_BOOL(use_empty, 0); + ZVAL_FALSE(use_empty); if (phalcon_array_isset_string(params, SS("useEmpty"))) { if (!phalcon_array_isset_string(params, SS("emptyValue"))) { PHALCON_INIT_VAR(empty_value); diff --git a/ext/text.c b/ext/text.c index 6faeea5ce90..ec37b8c8632 100644 --- a/ext/text.c +++ b/ext/text.c @@ -197,19 +197,13 @@ PHP_METHOD(Phalcon_Text, startsWith){ zval *str, *start, *ignore_case = NULL; - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 2, 1, &str, &start, &ignore_case); + phalcon_fetch_params(0, 2, 1, &str, &start, &ignore_case); - if (!ignore_case) { - PHALCON_INIT_VAR(ignore_case); - ZVAL_BOOL(ignore_case, 1); + if (phalcon_start_with(str, start, ignore_case ? ignore_case : PHALCON_GLOBAL(z_true))) { + RETURN_TRUE; } - if (phalcon_start_with(str, start, ignore_case)) { - RETURN_MM_TRUE; - } - RETURN_MM_FALSE; + RETURN_FALSE; } /** @@ -230,19 +224,13 @@ PHP_METHOD(Phalcon_Text, endsWith){ zval *str, *end, *ignore_case = NULL; - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 2, 1, &str, &end, &ignore_case); + phalcon_fetch_params(0, 2, 1, &str, &end, &ignore_case); - if (!ignore_case) { - PHALCON_INIT_VAR(ignore_case); - ZVAL_BOOL(ignore_case, 1); + if (phalcon_end_with(str, end, ignore_case ? ignore_case : PHALCON_GLOBAL(z_true))) { + RETURN_TRUE; } - if (phalcon_end_with(str, end, ignore_case)) { - RETURN_MM_TRUE; - } - RETURN_MM_FALSE; + RETURN_FALSE; } /** diff --git a/ext/translate/adapter.c b/ext/translate/adapter.c index 49318694308..38e779c7d08 100644 --- a/ext/translate/adapter.c +++ b/ext/translate/adapter.c @@ -70,7 +70,7 @@ PHP_METHOD(Phalcon_Translate_Adapter, _){ phalcon_fetch_params(1, 1, 1, &translate_key, &placeholders); if (!placeholders) { - PHALCON_INIT_VAR(placeholders); + placeholders = PHALCON_GLOBAL(z_null); } phalcon_call_method_p2(return_value, this_ptr, "query", translate_key, placeholders); diff --git a/ext/translate/adapter/nativearray.c b/ext/translate/adapter/nativearray.c index a76458ee6bb..8ca1208f8ad 100644 --- a/ext/translate/adapter/nativearray.c +++ b/ext/translate/adapter/nativearray.c @@ -117,7 +117,7 @@ PHP_METHOD(Phalcon_Translate_Adapter_NativeArray, query){ phalcon_fetch_params(1, 1, 1, &index, &placeholders); if (!placeholders) { - PHALCON_INIT_VAR(placeholders); + placeholders = PHALCON_GLOBAL(z_null); } PHALCON_OBS_VAR(translate); diff --git a/ext/validation.c b/ext/validation.c index ebd19f7b8b3..92870c996a2 100644 --- a/ext/validation.c +++ b/ext/validation.c @@ -77,7 +77,7 @@ PHP_METHOD(Phalcon_Validation, __construct){ phalcon_fetch_params(1, 0, 1, &validators); if (!validators) { - PHALCON_INIT_VAR(validators); + validators = PHALCON_GLOBAL(z_null); } if (Z_TYPE_P(validators) != IS_NULL) { @@ -119,11 +119,11 @@ PHP_METHOD(Phalcon_Validation, validate){ phalcon_fetch_params(1, 0, 2, &data, &entity); if (!data) { - PHALCON_INIT_VAR(data); + data = PHALCON_GLOBAL(z_null); } if (!entity) { - PHALCON_INIT_VAR(entity); + entity = PHALCON_GLOBAL(z_null); } PHALCON_OBS_VAR(validators); @@ -280,26 +280,18 @@ PHP_METHOD(Phalcon_Validation, getFilters){ zval *attribute = NULL, *filters, *attribute_filters; - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 0, 1, &attribute); + phalcon_fetch_params(0, 0, 1, &attribute); - if (!attribute) { - PHALCON_INIT_VAR(attribute); - } - - PHALCON_OBS_VAR(filters); - phalcon_read_property_this(&filters, this_ptr, SL("_filters"), PH_NOISY_CC); - if (Z_TYPE_P(attribute) == IS_STRING) { - if (phalcon_array_isset(filters, attribute)) { - PHALCON_OBS_VAR(attribute_filters); - phalcon_array_fetch(&attribute_filters, filters, attribute, PH_NOISY); - RETURN_CCTOR(attribute_filters); + filters = phalcon_fetch_nproperty_this(this_ptr, SL("_filters"), PH_NOISY_CC); + if (attribute && Z_TYPE_P(attribute) == IS_STRING) { + if (phalcon_array_isset_fetch(&attribute_filters, filters, attribute)) { + RETURN_ZVAL(attribute_filters, 1, 0); } - RETURN_MM_NULL(); + + RETURN_NULL(); } - RETURN_CCTOR(filters); + RETURN_ZVAL(filters, 1, 0); } /** diff --git a/ext/validation/message.c b/ext/validation/message.c index 597f9885c7e..572d72e8ee7 100644 --- a/ext/validation/message.c +++ b/ext/validation/message.c @@ -70,29 +70,24 @@ PHP_METHOD(Phalcon_Validation_Message, __construct){ zval *message, *field = NULL, *type = NULL, *code = NULL; - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 1, 3, &message, &field, &type, &code); + phalcon_fetch_params(0, 1, 3, &message, &field, &type, &code); if (!field) { - PHALCON_INIT_VAR(field); + field = PHALCON_GLOBAL(z_null); } if (!type) { - PHALCON_INIT_VAR(type); + type = PHALCON_GLOBAL(z_null); } if (!code) { - PHALCON_INIT_VAR(code); - ZVAL_LONG(code, 0); + code = PHALCON_GLOBAL(z_zero); } phalcon_update_property_this(this_ptr, SL("_message"), message TSRMLS_CC); phalcon_update_property_this(this_ptr, SL("_field"), field TSRMLS_CC); phalcon_update_property_this(this_ptr, SL("_type"), type TSRMLS_CC); phalcon_update_property_this(this_ptr, SL("_code"), code TSRMLS_CC); - - PHALCON_MM_RESTORE(); } /** diff --git a/ext/validation/message/group.c b/ext/validation/message/group.c index 73bf359a243..3873c534a76 100644 --- a/ext/validation/message/group.c +++ b/ext/validation/message/group.c @@ -69,19 +69,11 @@ PHP_METHOD(Phalcon_Validation_Message_Group, __construct){ zval *messages = NULL; - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 0, 1, &messages); - - if (!messages) { - PHALCON_INIT_VAR(messages); - } + phalcon_fetch_params(0, 0, 1, &messages); - if (Z_TYPE_P(messages) == IS_ARRAY) { + if (messages && Z_TYPE_P(messages) == IS_ARRAY) { phalcon_update_property_this(this_ptr, SL("_messages"), messages TSRMLS_CC); } - - PHALCON_MM_RESTORE(); } /** diff --git a/ext/validation/validator.c b/ext/validation/validator.c index 2e5a0d9fad2..6ebe45639b8 100644 --- a/ext/validation/validator.c +++ b/ext/validation/validator.c @@ -64,24 +64,20 @@ PHP_METHOD(Phalcon_Validation_Validator, __construct){ zval *options = NULL; - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 0, 1, &options); + phalcon_fetch_params(0, 0, 1, &options); if (!options) { - PHALCON_INIT_VAR(options); + options = PHALCON_GLOBAL(z_null); } if (Z_TYPE_P(options) != IS_ARRAY) { if (Z_TYPE_P(options) != IS_NULL) { - PHALCON_THROW_EXCEPTION_STR(phalcon_validation_exception_ce, "The attribute must be a string"); + PHALCON_THROW_EXCEPTION_STRW(phalcon_validation_exception_ce, "The attribute must be a string"); return; } } else { phalcon_update_property_this(this_ptr, SL("_options"), options TSRMLS_CC); } - - PHALCON_MM_RESTORE(); } /** diff --git a/ext/validation/validator/regex.c b/ext/validation/validator/regex.c index 392e3907c9e..fc1a66f667d 100644 --- a/ext/validation/validator/regex.c +++ b/ext/validation/validator/regex.c @@ -111,7 +111,7 @@ PHP_METHOD(Phalcon_Validation_Validator_Regex, validate){ is_not_equal_function(failed, match_zero, value TSRMLS_CC); } else { PHALCON_INIT_NVAR(failed); - ZVAL_BOOL(failed, 1); + ZVAL_TRUE(failed); } if (PHALCON_IS_TRUE(failed)) { diff --git a/ext/validation/validator/stringlength.c b/ext/validation/validator/stringlength.c index e72434ed5c6..df52698a1aa 100644 --- a/ext/validation/validator/stringlength.c +++ b/ext/validation/validator/stringlength.c @@ -114,19 +114,18 @@ PHP_METHOD(Phalcon_Validation_Validator_StringLength, validate){ /** * Check if mbstring is available to calculate the correct length */ + PHALCON_INIT_VAR(length); if (phalcon_function_exists_ex(SS("mb_strlen") TSRMLS_CC) == SUCCESS) { - PHALCON_INIT_VAR(length); phalcon_call_func_p1(length, "mb_strlen", value); } else { - PHALCON_INIT_NVAR(length); phalcon_fast_strlen(length, value); } PHALCON_INIT_VAR(invalid_maximum); - ZVAL_BOOL(invalid_maximum, 0); + ZVAL_FALSE(invalid_maximum); PHALCON_INIT_VAR(invalid_minimum); - ZVAL_BOOL(invalid_minimum, 0); + ZVAL_FALSE(invalid_minimum); /** * Maximum length From 9e8dac3334ed1843588c380e062b666404167fad Mon Sep 17 00:00:00 2001 From: Vladimir Kolesnikov Date: Fri, 27 Sep 2013 01:46:04 +0300 Subject: [PATCH 2/6] Updated .travis.yml --- .travis.yml | 2 +- ext/tests/issue-1297.phpt | 2 +- unit-tests/ci/run_php_tests.sh | 14 ++++++++++++++ 3 files changed, 16 insertions(+), 2 deletions(-) create mode 100755 unit-tests/ci/run_php_tests.sh diff --git a/.travis.yml b/.travis.yml index c74b248592a..85276f26cb3 100644 --- a/.travis.yml +++ b/.travis.yml @@ -25,7 +25,7 @@ before_script: - ulimit -c unlimited || true script: - - (cd ext; REPORT_EXIT_STATUS=1 NO_INTERACTION=1 make test) + - ./unit-tests/ci/run_php_tests.sh - $(phpenv which php) ./unit-tests/ci/phpunit.php --debug -c unit-tests/phpunit.xml - PHALCON_NO_RVO=1 $(phpenv which php) ./unit-tests/ci/phpunit.php --debug -c unit-tests/phpunit.xml diff --git a/ext/tests/issue-1297.phpt b/ext/tests/issue-1297.phpt index 1727b2808de..01e3e9f1c0d 100644 --- a/ext/tests/issue-1297.phpt +++ b/ext/tests/issue-1297.phpt @@ -1,5 +1,5 @@ --TEST-- -Misleading diagnostocs on exception - https://github.com/phalcon/cphalcon/pull/1297 +Misleading diagnostics on exception - https://github.com/phalcon/cphalcon/pull/1297 --SKIPIF-- --FILE-- diff --git a/unit-tests/ci/run_php_tests.sh b/unit-tests/ci/run_php_tests.sh new file mode 100755 index 00000000000..2d82a88e884 --- /dev/null +++ b/unit-tests/ci/run_php_tests.sh @@ -0,0 +1,14 @@ +#! /bin/bash + +EXT_DIR=$(readlink -enq "$(dirname $0)/../../ext") + +shopt -s nullglob +export NO_INTERACTION=1 +export REPORT_EXIT_STATUS1 +make -C "$EXT_DIR" test +for i in $EXT_DIR/tests/*.log; do + echo "====== $i ======"; + cat "$i"; +done +[ -n "$(echo $EXT_DIR/tests/*.log)" ] && exit 1 +exit 0 From e62161537d5e821a6dc8d4230c2301d436c7abee Mon Sep 17 00:00:00 2001 From: Vladimir Kolesnikov Date: Fri, 27 Sep 2013 19:31:55 +0300 Subject: [PATCH 3/6] Fix segfault when a call with return_value_ptr ends with an exception --- ext/annotations/adapter/apc.c | 2 +- ext/cache/backend.c | 8 +- ext/cache/backend/apc.c | 4 +- ext/cache/backend/file.c | 2 +- ext/cache/backend/libmemcached.c | 6 +- ext/cache/backend/memcache.c | 4 +- ext/cache/backend/memory.c | 2 +- ext/cache/backend/mongo.c | 6 +- ext/cache/backend/xcache.c | 6 +- ext/cache/frontend/base64.c | 4 +- ext/cache/frontend/data.c | 4 +- ext/cache/frontend/igbinary.c | 4 +- ext/config.c | 5 + ext/crypt.c | 6 + ext/di.c | 2 +- ext/forms/element.c | 10 +- ext/forms/element/text.c | 8 +- ext/kernel/fcall.c | 9 +- ext/kernel/fcall.h | 253 ++++++++++++++++++++++++++++++- ext/kernel/session.c | 6 +- ext/kernel/string.c | 19 ++- ext/mvc/collection.c | 2 +- ext/mvc/model.c | 5 +- ext/mvc/model/query.c | 18 +-- ext/tag.c | 240 ++++++++++++++--------------- 25 files changed, 452 insertions(+), 183 deletions(-) diff --git a/ext/annotations/adapter/apc.c b/ext/annotations/adapter/apc.c index ad7b47809fe..6ac16157548 100644 --- a/ext/annotations/adapter/apc.c +++ b/ext/annotations/adapter/apc.c @@ -82,7 +82,7 @@ PHP_METHOD(Phalcon_Annotations_Adapter_Apc, read){ return_value_ptr = &return_value; } - phalcon_call_func_p1_ex(return_value, return_value_ptr, "apc_fetch", prefixed_key); + phalcon_return_call_func_p1("apc_fetch", prefixed_key); if (Z_TYPE_PP(return_value_ptr) != IS_OBJECT) { zval_dtor(*return_value_ptr); ZVAL_NULL(*return_value_ptr); diff --git a/ext/cache/backend.c b/ext/cache/backend.c index c080bd5172c..f412d460b5d 100644 --- a/ext/cache/backend.c +++ b/ext/cache/backend.c @@ -117,16 +117,14 @@ PHP_METHOD(Phalcon_Cache_Backend, start){ /** * Get the cache content verifying if it was expired */ - PHALCON_INIT_VAR(fresh); - - phalcon_call_method_p2_ex(return_value, return_value_ptr, this_ptr, "get", key_name, lifetime); + phalcon_return_call_method_p2(this_ptr, "get", key_name, lifetime); if ((return_value_ptr && Z_TYPE_PP(return_value_ptr) == IS_NULL) || (!return_value_ptr && Z_TYPE_P(return_value) == IS_NULL)) { - ZVAL_TRUE(fresh); + fresh = PHALCON_GLOBAL(z_true); frontend = phalcon_fetch_nproperty_this(this_ptr, SL("_frontend"), PH_NOISY_CC); phalcon_call_method_noret(frontend, "start"); } else { - ZVAL_FALSE(fresh); + fresh = PHALCON_GLOBAL(z_false); } phalcon_update_property_this(this_ptr, SL("_fresh"), fresh TSRMLS_CC); diff --git a/ext/cache/backend/apc.c b/ext/cache/backend/apc.c index eac0eb5efb2..2d246c5b7bc 100644 --- a/ext/cache/backend/apc.c +++ b/ext/cache/backend/apc.c @@ -118,7 +118,7 @@ PHP_METHOD(Phalcon_Cache_Backend_Apc, get){ RETURN_MM_NULL(); } - phalcon_call_method_p1_ex(return_value, return_value_ptr, frontend, "afterretrieve", cached_content); + phalcon_return_call_method_p1(frontend, "afterretrieve", cached_content); RETURN_MM(); } @@ -223,7 +223,7 @@ PHP_METHOD(Phalcon_Cache_Backend_Apc, delete){ PHALCON_INIT_VAR(key); PHALCON_CONCAT_SVV(key, "_PHCA", prefix, key_name); - phalcon_call_func_p1_ex(return_value, return_value_ptr, "apc_delete", key); + phalcon_return_call_func_p1("apc_delete", key); PHALCON_MM_RESTORE(); } diff --git a/ext/cache/backend/file.c b/ext/cache/backend/file.c index 4cab1805f86..5e72bc820fa 100644 --- a/ext/cache/backend/file.c +++ b/ext/cache/backend/file.c @@ -202,7 +202,7 @@ PHP_METHOD(Phalcon_Cache_Backend_File, get){ /** * Use the frontend to process the content of the cache */ - phalcon_call_method_p1_ex(return_value, return_value_ptr, frontend, "afterretrieve", cached_content); + phalcon_return_call_method_p1(frontend, "afterretrieve", cached_content); RETURN_MM(); } } diff --git a/ext/cache/backend/libmemcached.c b/ext/cache/backend/libmemcached.c index e65bbbda1fa..bc77c41549a 100644 --- a/ext/cache/backend/libmemcached.c +++ b/ext/cache/backend/libmemcached.c @@ -168,7 +168,7 @@ PHP_METHOD(Phalcon_Cache_Backend_Libmemcached, _connect){ phalcon_array_isset_string_fetch(&client, options, SS("client")); - phalcon_call_method_p1_ex(return_value, return_value_ptr, memcache, "addservers", servers); + phalcon_return_call_method_p1(memcache, "addservers", servers); if ((return_value_ptr && !zend_is_true(*return_value_ptr)) || (!return_value_ptr && !zend_is_true(return_value))) { PHALCON_THROW_EXCEPTION_STR(phalcon_cache_exception_ce, "Cannot connect to Memcached server"); return; @@ -236,7 +236,7 @@ PHP_METHOD(Phalcon_Cache_Backend_Libmemcached, get){ RETURN_MM_NULL(); } - phalcon_call_method_p1_ex(return_value, return_value_ptr, frontend, "afterretrieve", cached_content); + phalcon_return_call_method_p1(frontend, "afterretrieve", cached_content); RETURN_MM(); } @@ -399,7 +399,7 @@ PHP_METHOD(Phalcon_Cache_Backend_Libmemcached, delete){ /** * Delete the key from memcached */ - phalcon_call_method_p1_ex(return_value, return_value_ptr, memcache, "delete", prefixed_key); + phalcon_return_call_method_p1(memcache, "delete", prefixed_key); RETURN_MM(); } diff --git a/ext/cache/backend/memcache.c b/ext/cache/backend/memcache.c index dda5830b50a..b0e506d3570 100644 --- a/ext/cache/backend/memcache.c +++ b/ext/cache/backend/memcache.c @@ -213,7 +213,7 @@ PHP_METHOD(Phalcon_Cache_Backend_Memcache, get){ RETURN_MM_NULL(); } - phalcon_call_method_p1_ex(return_value, return_value_ptr, frontend, "afterretrieve", cached_content); + phalcon_return_call_method_p1(frontend, "afterretrieve", cached_content); RETURN_MM(); } @@ -382,7 +382,7 @@ PHP_METHOD(Phalcon_Cache_Backend_Memcache, delete){ /** * Delete the key from memcached */ - phalcon_call_method_p1_ex(return_value, return_value_ptr, memcache, "delete", prefixed_key); + phalcon_return_call_method_p1(memcache, "delete", prefixed_key); RETURN_MM(); } diff --git a/ext/cache/backend/memory.c b/ext/cache/backend/memory.c index 7ff366f49dd..42a478628a1 100644 --- a/ext/cache/backend/memory.c +++ b/ext/cache/backend/memory.c @@ -103,7 +103,7 @@ PHP_METHOD(Phalcon_Cache_Backend_Memory, get){ if (phalcon_array_isset_fetch(&cached_content, data, last_key)) { if (Z_TYPE_P(cached_content) != IS_NULL) { frontend = phalcon_fetch_nproperty_this(this_ptr, SL("_frontend"), PH_NOISY_CC); - phalcon_call_method_p1_ex(return_value, return_value_ptr, frontend, "afterretrieve", cached_content); + phalcon_return_call_method_p1(frontend, "afterretrieve", cached_content); } } diff --git a/ext/cache/backend/mongo.c b/ext/cache/backend/mongo.c index 6ecb402e883..642466f1d33 100644 --- a/ext/cache/backend/mongo.c +++ b/ext/cache/backend/mongo.c @@ -192,10 +192,10 @@ PHP_METHOD(Phalcon_Cache_Backend_Mongo, _getCollection){ PHALCON_OBS_VAR(mongo_database); phalcon_call_method_p1_ex(mongo_database, &mongo_database, mongo, "selectdb", database); - phalcon_call_method_p1_ex(return_value, return_value_ptr, mongo_database, "selectcollection", collection); + phalcon_return_call_method_p1(mongo_database, "selectcollection", collection); } else { - ZVAL_ZVAL(return_value, mongo_collection, 1, 0); + RETVAL_ZVAL(mongo_collection, 1, 0); } PHALCON_MM_RESTORE(); @@ -241,7 +241,7 @@ PHP_METHOD(Phalcon_Cache_Backend_Mongo, get){ phalcon_call_method_p1_ex(document, &document, collection, "findone", conditions); if (Z_TYPE_P(document) == IS_ARRAY) { if (likely(phalcon_array_isset_string_fetch(&cached_content, document, SS("data")))) { - phalcon_call_method_p1_ex(return_value, return_value_ptr, frontend, "afterretrieve", cached_content); + phalcon_return_call_method_p1(frontend, "afterretrieve", cached_content); RETURN_MM(); } else { diff --git a/ext/cache/backend/xcache.c b/ext/cache/backend/xcache.c index a18a81eab4c..1e6c5ad9c89 100644 --- a/ext/cache/backend/xcache.c +++ b/ext/cache/backend/xcache.c @@ -142,7 +142,7 @@ PHP_METHOD(Phalcon_Cache_Backend_Xcache, get){ RETURN_MM_NULL(); } - phalcon_call_method_p1_ex(return_value, return_value_ptr, frontend, "afterretrieve", cached_content); + phalcon_return_call_method_p1(frontend, "afterretrieve", cached_content); RETURN_MM(); } @@ -275,7 +275,7 @@ PHP_METHOD(Phalcon_Cache_Backend_Xcache, delete){ PHALCON_INIT_VAR(prefixed_key); PHALCON_CONCAT_SVV(prefixed_key, "_PHCX", prefix, key_name); - phalcon_call_func_p1_ex(return_value, return_value_ptr, "xcache_unset", prefixed_key); + phalcon_return_call_func_p1("xcache_unset", prefixed_key); if (unlikely(!phalcon_array_isset_string_fetch(&special_key, options, SS("statsKey")))) { PHALCON_THROW_EXCEPTION_STR(phalcon_cache_exception_ce, "Unexpected inconsistency in options"); @@ -379,7 +379,7 @@ PHP_METHOD(Phalcon_Cache_Backend_Xcache, exists){ } if (zend_is_true(last_key)) { - phalcon_call_func_p1_ex(return_value, return_value_ptr, "xcache_isset", last_key); + phalcon_return_call_func_p1("xcache_isset", last_key); } else { RETVAL_FALSE; diff --git a/ext/cache/frontend/base64.c b/ext/cache/frontend/base64.c index 6df9014d1cd..693eed415bd 100644 --- a/ext/cache/frontend/base64.c +++ b/ext/cache/frontend/base64.c @@ -99,7 +99,7 @@ PHP_METHOD(Phalcon_Cache_Frontend_Base64, beforeStore){ zval *data; phalcon_fetch_params(0, 1, 0, &data); - phalcon_base64_encode((return_value_ptr ? *return_value_ptr : return_value), data); + phalcon_base64_encode(return_value, data); } /** @@ -113,5 +113,5 @@ PHP_METHOD(Phalcon_Cache_Frontend_Base64, afterRetrieve){ zval *data; phalcon_fetch_params(0, 1, 0, &data); - phalcon_base64_decode((return_value_ptr ? *return_value_ptr : return_value), data); + phalcon_base64_decode(return_value, data); } diff --git a/ext/cache/frontend/data.c b/ext/cache/frontend/data.c index eb0ce69eb70..cd044cf9109 100644 --- a/ext/cache/frontend/data.c +++ b/ext/cache/frontend/data.c @@ -185,7 +185,7 @@ PHP_METHOD(Phalcon_Cache_Frontend_Data, beforeStore){ zval *data; phalcon_fetch_params(0, 1, 0, &data); - phalcon_serialize((return_value_ptr ? *return_value_ptr : return_value), &data TSRMLS_CC); + phalcon_serialize(return_value, &data TSRMLS_CC); } /** @@ -199,5 +199,5 @@ PHP_METHOD(Phalcon_Cache_Frontend_Data, afterRetrieve){ zval *data; phalcon_fetch_params(0, 1, 0, &data); - phalcon_unserialize((return_value_ptr ? *return_value_ptr : return_value), data TSRMLS_CC); + phalcon_unserialize(return_value, data TSRMLS_CC); } diff --git a/ext/cache/frontend/igbinary.c b/ext/cache/frontend/igbinary.c index 92906f5e264..74b57534065 100644 --- a/ext/cache/frontend/igbinary.c +++ b/ext/cache/frontend/igbinary.c @@ -104,7 +104,7 @@ PHP_METHOD(Phalcon_Cache_Frontend_Igbinary, beforeStore){ phalcon_fetch_params(1, 1, 0, &data); - phalcon_call_func_p1_ex(return_value, return_value_ptr, "igbinary_serialize", data); + phalcon_return_call_func_p1("igbinary_serialize", data); RETURN_MM(); } @@ -122,7 +122,7 @@ PHP_METHOD(Phalcon_Cache_Frontend_Igbinary, afterRetrieve){ phalcon_fetch_params(1, 1, 0, &data); - phalcon_call_func_p1_ex(return_value, return_value_ptr, "igbinary_unserialize", data); + phalcon_return_call_func_p1("igbinary_unserialize", data); RETURN_MM(); } diff --git a/ext/config.c b/ext/config.c index 15a109ecf59..8744c0d0079 100644 --- a/ext/config.c +++ b/ext/config.c @@ -414,6 +414,7 @@ static void phalcon_config_toarray_internal(zval **return_value_ptr, zval *this_ { phalcon_config_object *obj = fetchPhalconConfigObject(this_ptr TSRMLS_CC); + assert(!EG(exception)); if (likely(obj->obj.ce == phalcon_config_ce)) { zval *tmp; array_init_size(*return_value_ptr, zend_hash_num_elements(obj->props)); @@ -425,6 +426,10 @@ static void phalcon_config_toarray_internal(zval **return_value_ptr, zval *this_ else { phalcon_call_func_params(*return_value_ptr, return_value_ptr, SL("get_object_vars") TSRMLS_CC, 1, this_ptr); } + + if (EG(exception)) { + ALLOC_INIT_ZVAL(*return_value_ptr); + } } /** diff --git a/ext/crypt.c b/ext/crypt.c index e29fcdb71ef..1fd48a7e2b9 100644 --- a/ext/crypt.c +++ b/ext/crypt.c @@ -637,6 +637,9 @@ PHP_METHOD(Phalcon_Crypt, getAvailableCiphers){ phalcon_call_func_params(return_value, return_value_ptr, SL("mcrypt_list_algorithms") TSRMLS_CC, 0); + if (return_value_ptr && EG(exception)) { + ALLOC_INIT_ZVAL(*return_value_ptr); + } } /** @@ -648,4 +651,7 @@ PHP_METHOD(Phalcon_Crypt, getAvailableModes){ phalcon_call_func_params(return_value, return_value_ptr, SL("mcrypt_list_modes") TSRMLS_CC, 0); + if (return_value_ptr && EG(exception)) { + ALLOC_INIT_ZVAL(*return_value_ptr); + } } diff --git a/ext/di.c b/ext/di.c index 291abb502c1..222f070677f 100644 --- a/ext/di.c +++ b/ext/di.c @@ -272,7 +272,7 @@ PHP_METHOD(Phalcon_DI, getRaw){ services = phalcon_fetch_nproperty_this(this_ptr, SL("_services"), PH_NOISY_CC); if (phalcon_array_isset_fetch(&service, services, name)) { - phalcon_call_method_p0_ex(return_value, return_value_ptr, service, "getdefinition"); + phalcon_return_call_method_p0(service, "getdefinition"); RETURN_MM(); } diff --git a/ext/forms/element.c b/ext/forms/element.c index 73b25995e0b..bcb45e59bf5 100644 --- a/ext/forms/element.c +++ b/ext/forms/element.c @@ -324,7 +324,7 @@ PHP_METHOD(Phalcon_Forms_Element, prepareAttributes){ PHALCON_INIT_VAR(merged_attributes); phalcon_fast_array_merge(merged_attributes, &default_attributes, &widget_attributes TSRMLS_CC); } else { - merged_attributes = widget_attributes; + PHALCON_CPY_WRT(merged_attributes, widget_attributes); } /** @@ -810,7 +810,11 @@ PHP_METHOD(Phalcon_Forms_Element, clear){ * * @return string */ -PHP_METHOD(Phalcon_Forms_Element, __toString){ +PHP_METHOD(Phalcon_Forms_Element, __toString) { - phalcon_call_method_params(return_value, return_value_ptr, this_ptr, SL("render"), zend_inline_hash_func(SS("render")) TSRMLS_CC, 0); + if (FAILURE == phalcon_call_method_params(return_value, return_value_ptr, this_ptr, SL("render"), zend_inline_hash_func(SS("render")) TSRMLS_CC, 0)) { + if (EG(exception) && return_value_ptr) { + ALLOC_INIT_ZVAL(*return_value_ptr); + } + } } diff --git a/ext/forms/element/text.c b/ext/forms/element/text.c index 004ab7ada81..eb59b7c83c0 100644 --- a/ext/forms/element/text.c +++ b/ext/forms/element/text.c @@ -61,7 +61,7 @@ PHALCON_INIT_CLASS(Phalcon_Forms_Element_Text){ */ PHP_METHOD(Phalcon_Forms_Element_Text, render){ - zval *attributes = NULL, *widget_attributes; + zval *attributes = NULL, *widget_attributes, *rv; PHALCON_MM_GROW(); @@ -73,7 +73,7 @@ PHP_METHOD(Phalcon_Forms_Element_Text, render){ PHALCON_INIT_VAR(widget_attributes); phalcon_call_method_p1(widget_attributes, this_ptr, "prepareattributes", attributes); - phalcon_call_static_p1(return_value, "phalcon\\tag", "textfield", widget_attributes); - RETURN_MM(); + PHALCON_INIT_VAR(rv); + phalcon_call_static_p1(rv, "phalcon\\tag", "textfield", widget_attributes); + RETURN_CTOR(rv); } - diff --git a/ext/kernel/fcall.c b/ext/kernel/fcall.c index b04d0e2ef1b..568911fe396 100644 --- a/ext/kernel/fcall.c +++ b/ext/kernel/fcall.c @@ -77,6 +77,8 @@ static int phalcon_call_user_function(HashTable *function_table, zval **object_p *retval_ptr_ptr = NULL; } + assert(retval_ptr != NULL); + phalcon_globals_ptr->recursive_lock++; if (unlikely(phalcon_globals_ptr->recursive_lock > 2048)) { @@ -115,12 +117,7 @@ static int phalcon_call_user_function(HashTable *function_table, zval **object_p ex_retval = PHALCON_ZEND_CALL_FUNCTION_WRAPPER(&fci, NULL TSRMLS_CC); if (local_retval_ptr) { - if (Z_TYPE_P(local_retval_ptr) == IS_NULL) { - zval_ptr_dtor(&local_retval_ptr); - } - else { - COPY_PZVAL_TO_ZVAL(*retval_ptr, local_retval_ptr); - } + COPY_PZVAL_TO_ZVAL(*retval_ptr, local_retval_ptr); } else if (!retval_ptr_ptr) { INIT_ZVAL(*retval_ptr); diff --git a/ext/kernel/fcall.h b/ext/kernel/fcall.h index fce132a245e..32e064a4849 100644 --- a/ext/kernel/fcall.h +++ b/ext/kernel/fcall.h @@ -41,6 +41,28 @@ } \ } while (0) +#define PHALCON_RETURN_CALL_FUNCTION(func_name, nparams, ...) \ + do { \ + if (__builtin_constant_p(func_name)) { \ + if (phalcon_call_func_params(return_value, return_value_ptr, func_name, sizeof(func_name)-1 TSRMLS_CC, nparams, __VA_ARGS__) == FAILURE) { \ + if (return_value_ptr && EG(exception)) { \ + ALLOC_INIT_ZVAL(*return_value_ptr); \ + } \ + PHALCON_MM_RESTORE(); \ + return; \ + } \ + } \ + else { \ + if (phalcon_call_func_params(return_value, return_value_ptr, func_name, strlen(func_name) TSRMLS_CC, nparams, __VA_ARGS__) == FAILURE) { \ + if (return_value_ptr && EG(exception)) { \ + ALLOC_INIT_ZVAL(*return_value_ptr); \ + } \ + PHALCON_MM_RESTORE(); \ + return; \ + } \ + } \ + } while (0) + #define PHALCON_CALL_METHOD(return_value, return_value_ptr, object, method, key, nparams, ...) \ do { \ register ulong _key = key; \ @@ -58,6 +80,29 @@ } \ } while (0) +#define PHALCON_RETURN_CALL_METHOD(object, method, key, nparams, ...) \ + do { \ + register ulong _key = key; \ + if (__builtin_constant_p(method)) { \ + if (phalcon_call_method_params(return_value, return_value_ptr, object, method, sizeof(method)-1, (_key ? _key : zend_inline_hash_func(method, sizeof(method))) TSRMLS_CC, nparams, __VA_ARGS__) == FAILURE) { \ + if (return_value_ptr && EG(exception)) { \ + ALLOC_INIT_ZVAL(*return_value_ptr); \ + } \ + PHALCON_MM_RESTORE(); \ + return; \ + } \ + } \ + else { \ + if (phalcon_call_method_params(return_value, return_value_ptr, object, method, strlen(method), (_key ? _key : (IS_INTERNED(method) ? INTERNED_HASH(method) : 0)) TSRMLS_CC, nparams, __VA_ARGS__) == FAILURE) { \ + if (return_value_ptr && EG(exception)) { \ + ALLOC_INIT_ZVAL(*return_value_ptr); \ + } \ + PHALCON_MM_RESTORE(); \ + return; \ + } \ + } \ + } while (0) + #define PHALCON_CALL_STATIC(return_value, return_value_ptr, class_name, method, nparams, ...) \ do { \ if (__builtin_constant_p(class_name) && __builtin_constant_p(method)) { \ @@ -67,7 +112,29 @@ } \ } \ else { \ - if (phalcon_call_static_func_params(return_value, return_value_ptr, class_name, strlen(class_name), method, strlen(method)-1 TSRMLS_CC, nparams, __VA_ARGS__) == FAILURE) { \ + if (phalcon_call_static_func_params(return_value, return_value_ptr, class_name, strlen(class_name), method, strlen(method) TSRMLS_CC, nparams, __VA_ARGS__) == FAILURE) { \ + PHALCON_MM_RESTORE(); \ + return; \ + } \ + } \ + } while (0) + +#define PHALCON_RETURN_CALL_STATIC(class_name, method, nparams, ...) \ + do { \ + if (__builtin_constant_p(class_name) && __builtin_constant_p(method)) { \ + if (phalcon_call_static_func_params(return_value, return_value_ptr, class_name, sizeof(class_name)-1, method, sizeof(method)-1 TSRMLS_CC, nparams, __VA_ARGS__) == FAILURE) { \ + if (return_value_ptr && EG(exception)) { \ + ALLOC_INIT_ZVAL(*return_value_ptr); \ + } \ + PHALCON_MM_RESTORE(); \ + return; \ + } \ + } \ + else { \ + if (phalcon_call_static_func_params(return_value, return_value_ptr, class_name, strlen(class_name), method, strlen(method) TSRMLS_CC, nparams, __VA_ARGS__) == FAILURE) { \ + if (return_value_ptr && EG(exception)) { \ + ALLOC_INIT_ZVAL(*return_value_ptr); \ + } \ PHALCON_MM_RESTORE(); \ return; \ } \ @@ -90,6 +157,28 @@ } \ } while (0) +#define PHALCON_RETURN_CALL_PARENT(this_ptr, class_entry, method, nparams, ...) \ + do { \ + if (__builtin_constant_p(method)) { \ + if (phalcon_call_parent_func_params(return_value, return_value_ptr, this_ptr, class_entry, method, sizeof(method)-1 TSRMLS_CC, nparams, __VA_ARGS__) == FAILURE) { \ + if (return_value_ptr && EG(exception)) { \ + ALLOC_INIT_ZVAL(*return_value_ptr); \ + } \ + PHALCON_MM_RESTORE(); \ + return; \ + } \ + } \ + else { \ + if (phalcon_call_parent_func_params(return_value, return_value_ptr, this_ptr, class_entry, method, strlen(method) TSRMLS_CC, nparams, __VA_ARGS__) == FAILURE) { \ + if (return_value_ptr && EG(exception)) { \ + ALLOC_INIT_ZVAL(*return_value_ptr); \ + } \ + PHALCON_MM_RESTORE(); \ + return; \ + } \ + } \ + } while (0) + #define PHALCON_CALL_SELF(return_value, return_value_ptr, this_ptr, method, nparams, ...) \ do { \ if (__builtin_constant_p(method)) { \ @@ -106,6 +195,28 @@ } \ } while (0) +#define PHALCON_RETURN_CALL_SELF(this_ptr, method, nparams, ...) \ + do { \ + if (__builtin_constant_p(method)) { \ + if (phalcon_call_self_func_params(return_value, return_value_ptr, this_ptr, method, sizeof(method)-1 TSRMLS_CC, nparams, __VA_ARGS__) == FAILURE) { \ + if (return_value_ptr && EG(exception)) { \ + ALLOC_INIT_ZVAL(*return_value_ptr); \ + } \ + PHALCON_MM_RESTORE(); \ + return; \ + } \ + } \ + else { \ + if (phalcon_call_self_func_params(return_value, return_value_ptr, this_ptr, method, strlen(method) TSRMLS_CC, nparams, __VA_ARGS__) == FAILURE) { \ + if (return_value_ptr && EG(exception)) { \ + ALLOC_INIT_ZVAL(*return_value_ptr); \ + } \ + PHALCON_MM_RESTORE(); \ + return; \ + } \ + } \ + } while (0) + #define PHALCON_CALL_ZSTATIC_STR(return_value, return_value_ptr, zclass, method, nparams, ...) \ do { \ if (__builtin_constant_p(method)) { \ @@ -122,6 +233,28 @@ } \ } while (0) +#define PHALCON_RETURN_CALL_ZSTATIC_STR(zclass, method, nparams, ...) \ + do { \ + if (__builtin_constant_p(method)) { \ + if (phalcon_call_static_zval_str_func_params(return_value, return_value_ptr, zclass, method, sizeof(method)-1 TSRMLS_CC, nparams, __VA_ARGS__) == FAILURE) { \ + if (return_value_ptr && EG(exception)) { \ + ALLOC_INIT_ZVAL(*return_value_ptr); \ + } \ + PHALCON_MM_RESTORE(); \ + return; \ + } \ + } \ + else { \ + if (phalcon_call_static_zval_str_func_params(return_value, return_value_ptr, zclass, method, strlen(method) TSRMLS_CC, nparams, __VA_ARGS__) == FAILURE) { \ + if (return_value_ptr && EG(exception)) { \ + ALLOC_INIT_ZVAL(*return_value_ptr); \ + } \ + PHALCON_MM_RESTORE(); \ + return; \ + } \ + } \ + } while (0) + #else #define PHALCON_CALL_FUNCTION(return_value, return_value_ptr, func_name, nparams, ...) \ @@ -132,10 +265,31 @@ } \ } while (0) +#define PHALCON_RETURN_CALL_FUNCTION(func_name, nparams, ...) \ + do { \ + if (phalcon_call_func_params(return_value, return_value_ptr, func_name, strlen(func_name) TSRMLS_CC, nparams, __VA_ARGS__) == FAILURE) { \ + if (return_value_ptr && EG(exception)) { \ + ALLOC_INIT_ZVAL(*return_value_ptr); \ + } \ + PHALCON_MM_RESTORE(); \ + return; \ + } \ + } while (0) + #define PHALCON_CALL_METHOD(return_value, return_value_ptr, object, method, key, nparams, ...) \ do { \ - register ulong _key = key; \ - if (phalcon_call_method_params(return_value, return_value_ptr, object, method, strlen(method), (_key ? _key : (IS_INTERNED(method) ? INTERNED_HASH(method) : 0)) TSRMLS_CC, nparams, __VA_ARGS__) == FAILURE) { \ + if (phalcon_call_method_params(return_value, return_value_ptr, object, method, strlen(method), key TSRMLS_CC, nparams, __VA_ARGS__) == FAILURE) { \ + PHALCON_MM_RESTORE(); \ + return; \ + } \ + } while (0) + +#define PHALCON_RETURN_CALL_METHOD(object, method, key, nparams, ...) \ + do { \ + if (phalcon_call_method_params(return_value, return_value_ptr, object, method, strlen(method), key TSRMLS_CC, nparams, __VA_ARGS__) == FAILURE) { \ + if (return_value_ptr && EG(exception)) { \ + ALLOC_INIT_ZVAL(*return_value_ptr); \ + } \ PHALCON_MM_RESTORE(); \ return; \ } \ @@ -149,6 +303,17 @@ } \ } while (0) +#define PHALCON_RETURN_CALL_STATIC(class_name, method, nparams, ...) \ + do { \ + if (phalcon_call_static_func_params(return_value, return_value_ptr, class_name, strlen(class_name), method, strlen(method) TSRMLS_CC, nparams, __VA_ARGS__) == FAILURE) { \ + if (return_value_ptr && EG(exception)) { \ + ALLOC_INIT_ZVAL(*return_value_ptr); \ + } \ + PHALCON_MM_RESTORE(); \ + return; \ + } \ + } while (0) + #define PHALCON_CALL_PARENT(return_value, return_value_ptr, this_ptr, class_entry, method, nparams, ...) \ do { \ if (phalcon_call_parent_func_params(return_value, return_value_ptr, this_ptr, class_entry, method, strlen(method) TSRMLS_CC, nparams, __VA_ARGS__) == FAILURE) { \ @@ -157,6 +322,17 @@ } \ } while (0) +#define PHALCON_RETURN_CALL_PARENT(this_ptr, class_entry, method, nparams, ...) \ + do { \ + if (phalcon_call_parent_func_params(return_value, return_value_ptr, this_ptr, class_entry, method, strlen(method) TSRMLS_CC, nparams, __VA_ARGS__) == FAILURE) { \ + if (return_value_ptr && EG(exception)) { \ + ALLOC_INIT_ZVAL(*return_value_ptr); \ + } \ + PHALCON_MM_RESTORE(); \ + return; \ + } \ + } while (0) + #define PHALCON_CALL_SELF(return_value, return_value_ptr, this_ptr, method, nparams, ...) \ do { \ if (phalcon_call_self_func_params(return_value, return_value_ptr, this_ptr, method, strlen(method) TSRMLS_CC, nparams, __VA_ARGS__) == FAILURE) { \ @@ -165,6 +341,17 @@ } \ } while (0) +#define PHALCON_RETURN_CALL_SELF(return_value, return_value_ptr, this_ptr, method, nparams, ...) \ + do { \ + if (phalcon_call_self_func_params(return_value, return_value_ptr, this_ptr, method, strlen(method) TSRMLS_CC, nparams, __VA_ARGS__) == FAILURE) { \ + if (return_value_ptr && EG(exception)) { \ + ALLOC_INIT_ZVAL(*return_value_ptr); \ + } \ + PHALCON_MM_RESTORE(); \ + return; \ + } \ + } while (0) + #define PHALCON_CALL_ZSTATIC_STR(return_value, return_value_ptr, zclass, method, nparams, ...) \ do { \ if (phalcon_call_static_zval_str_func_params(return_value, return_value_ptr, zclass, method, strlen(method) TSRMLS_CC, nparams, __VA_ARGS__) == FAILURE) { \ @@ -173,6 +360,17 @@ } \ } while (0) +#define PHALCON_RETURN_CALL_ZSTATIC_STR(zclass, method, nparams, ...) \ + do { \ + if (phalcon_call_static_zval_str_func_params(return_value, return_value_ptr, zclass, method, strlen(method) TSRMLS_CC, nparams, __VA_ARGS__) == FAILURE) { \ + if (return_value_ptr && EG(exception)) { \ + ALLOC_INIT_ZVAL(*return_value_ptr); \ + } \ + PHALCON_MM_RESTORE(); \ + return; \ + } \ + } while (0) + #endif #define PHALCON_CALL_ZMETHOD(return_value, return_value_ptr, object, method, nparams, ...) \ @@ -183,6 +381,17 @@ } \ } while (0) +#define PHALCON_RETURN_CALL_ZMETHOD(object, method, nparams, ...) \ + do { \ + if (phalcon_call_method_zval_params(return_value, return_value_ptr, object, method TSRMLS_CC, nparams, __VA_ARGS__) == FAILURE) { \ + if (return_value_ptr && EG(exception)) { \ + ALLOC_INIT_ZVAL(*return_value_ptr); \ + } \ + PHALCON_MM_RESTORE(); \ + return; \ + } \ + } while (0) + #define PHALCON_CALL_ZSTATIC(return_value, return_value_ptr, object, method, nparams, ...) \ do { \ if (phalcon_call_static_zval_func_params(return_value, return_value_ptr, object, method TSRMLS_CC, nparams, __VA_ARGS__) == FAILURE) { \ @@ -191,6 +400,16 @@ } \ } while (0) +#define PHALCON_RETURN_CALL_ZSTATIC(return_value, return_value_ptr, object, method, nparams, ...) \ + do { \ + if (phalcon_call_static_zval_func_params(return_value, return_value_ptr, object, method TSRMLS_CC, nparams, __VA_ARGS__) == FAILURE) { \ + if (return_value_ptr && EG(exception)) { \ + ALLOC_INIT_ZVAL(*return_value_ptr); \ + } \ + PHALCON_MM_RESTORE(); \ + return; \ + } \ + } while (0) /** Use these functions to call functions in the PHP userland using an arbitrary zval as callable */ #define PHALCON_CALL_USER_FUNC(return_value, handler) PHALCON_CALL_USER_FUNC_ARRAY(return_value, handler, NULL) @@ -309,6 +528,13 @@ PHALCON_CALL_FUNCTION(return_value, return_value_ptr, func, 8, p1, p2, p3, p4, p5, p6, p7, p8); \ } while (0) +#define phalcon_return_call_func_p0(func) PHALCON_RETURN_CALL_FUNCTION(func, 0, NULL) +#define phalcon_return_call_func_p1(func, p1) PHALCON_RETURN_CALL_FUNCTION(func, 1, p1) +#define phalcon_return_call_func_p2(func, p1, p2) PHALCON_RETURN_CALL_FUNCTION(func, 2, p1, p2) +#define phalcon_return_call_func_p3(func, p1, p2, p3) PHALCON_RETURN_CALL_FUNCTION(func, 3, p1, p2, p3) +#define phalcon_return_call_func_p4(func, p1, p2, p3, p4) PHALCON_RETURN_CALL_FUNCTION(func, 4, p1, p2, p3, p4) +#define phalcon_return_call_func_p5(func, p1, p2, p3, p4, p5) PHALCON_RETURN_CALL_FUNCTION(func, 5, p1, p2, p3, p4, p5) + #define phalcon_call_func(return_value, func) phalcon_call_func_p0_ex(return_value, NULL, func) #define phalcon_call_func_p1(return_value, func, p1) phalcon_call_func_p1_ex(return_value, NULL, func, p1) #define phalcon_call_func_p2(return_value, func, p1, p2) phalcon_call_func_p2_ex(return_value, NULL, func, p1, p2) @@ -385,6 +611,20 @@ PHALCON_CALL_METHOD(return_value, return_value_ptr, object, method_name, key, 5, p1, p2, p3, p4, p5); \ } while (0) +#define phalcon_return_call_method_p0_key(object, method_name, key) PHALCON_RETURN_CALL_METHOD(object, method_name, key, 0, NULL) +#define phalcon_return_call_method_p1_key(object, method_name, key, p1) PHALCON_RETURN_CALL_METHOD(object, method_name, key, 1, p1) +#define phalcon_return_call_method_p2_key(object, method_name, key, p1, p2) PHALCON_RETURN_CALL_METHOD(object, method_name, key, 2, p1, p2) +#define phalcon_return_call_method_p3_key(object, method_name, key, p1, p2, p3) PHALCON_RETURN_CALL_METHOD(object, method_name, key, 3, p1, p2, p3) +#define phalcon_return_call_method_p4_key(object, method_name, key, p1, p2, p3, p4) PHALCON_RETURN_CALL_METHOD(object, method_name, key, 4, p1, p2, p3, p4) +#define phalcon_return_call_method_p5_key(object, method_name, key, p1, p2, p3, p4, p5) PHALCON_RETURN_CALL_METHOD(object, method_name, key, 5, p1, p2, p3, p4, p5) + +#define phalcon_return_call_method_p0(object, method_name) phalcon_return_call_method_p0_key(object, method_name, 0) +#define phalcon_return_call_method_p1(object, method_name, p1) phalcon_return_call_method_p1_key(object, method_name, 0, p1) +#define phalcon_return_call_method_p2(object, method_name, p1, p2) phalcon_return_call_method_p2_key(object, method_name, 0, p1, p2) +#define phalcon_return_call_method_p3(object, method_name, p1, p2, p3) phalcon_return_call_method_p3_key(object, method_name, 0, p1, p2, p3) +#define phalcon_return_call_method_p4(object, method_name, p1, p2, p3, p4) phalcon_return_call_method_p4_key(object, method_name, 0, p1, p2, p3, p4) +#define phalcon_return_call_method_p5(object, method_name, p1, p2, p3, p4, p5) phalcon_return_call_method_p5_key(object, method_name, 0, p1, p2, p3, p4, p5) + #define phalcon_call_method_p0_ex(return_value, return_value_ptr, object, method_name) phalcon_call_method_p0_key_ex(return_value, return_value_ptr, object, method_name, 0) #define phalcon_call_method_p1_ex(return_value, return_value_ptr, object, method_name, p1) phalcon_call_method_p1_key_ex(return_value, return_value_ptr, object, method_name, 0, p1) #define phalcon_call_method_p2_ex(return_value, return_value_ptr, object, method_name, p1, p2) phalcon_call_method_p2_key_ex(return_value, return_value_ptr, object, method_name, 0, p1, p2) @@ -451,6 +691,13 @@ #define phalcon_call_self_p4_noret(object, method, p1, p2, p3, p4) PHALCON_CALL_SELF(NULL, NULL, object, method, 4, p1, p2, p3, p4) /** Use these macros to call functions statically */ +#define phalcon_return_call_static_p0(class_name, method_name) PHALCON_RETURN_CALL_STATIC(class_name, method_name, 0, NULL) +#define phalcon_return_call_static_p1(class_name, method_name, p1) PHALCON_RETURN_CALL_STATIC(class_name, method_name, 1, p1) +#define phalcon_return_call_static_p2(class_name, method_name, p1, p2) PHALCON_RETURN_CALL_STATIC(class_name, method_name, 2, p1, p2) +#define phalcon_return_call_static_p3(class_name, method_name, p1, p2, p3) PHALCON_RETURN_CALL_STATIC(class_name, method_name, 3, p1, p2, p3) +#define phalcon_return_call_static_p4(class_name, method_name, p1, p2, p3, p4) PHALCON_RETURN_CALL_STATIC(class_name, method_name, 4, p1, p2, p3, p4) +#define phalcon_return_call_static_p5(class_name, method_name, p1, p2, p3, p4, p5) PHALCON_RETURN_CALL_STATIC(class_name, method_name, 5, p1, p2, p3, p4, p5) + #define phalcon_call_static(return_value, class_name, method_name) PHALCON_CALL_STATIC(return_value, NULL, class_name, method_name, 0, NULL) #define phalcon_call_static_p1(return_value, class_name, method_name, p1) PHALCON_CALL_STATIC(return_value, NULL, class_name, method_name, 1, p1) #define phalcon_call_static_p2(return_value, class_name, method_name, p1, p2) PHALCON_CALL_STATIC(return_value, NULL, class_name, method_name, 2, p1, p2) diff --git a/ext/kernel/session.c b/ext/kernel/session.c index aad8287330c..01d536bfb53 100644 --- a/ext/kernel/session.c +++ b/ext/kernel/session.c @@ -55,7 +55,11 @@ void phalcon_get_session_id(zval *return_value, zval **return_value_ptr TSRMLS_D RETURN_EMPTY_STRING(); #else - phalcon_call_func_params(return_value, return_value_ptr, SL("session_id") TSRMLS_CC, 0); + if (FAILURE == phalcon_call_func_params(return_value, return_value_ptr, SL("session_id") TSRMLS_CC, 0)) { + if (return_value_ptr && EG(exception)) { + ALLOC_INIT_ZVAL(*return_value_ptr); + } + } #endif } diff --git a/ext/kernel/string.c b/ext/kernel/string.c index 30c7f13dbc8..a616e339691 100644 --- a/ext/kernel/string.c +++ b/ext/kernel/string.c @@ -1173,21 +1173,28 @@ void phalcon_json_encode(zval *return_value, zval **return_value_ptr, zval *v, i { zval *zopts; - ALLOC_INIT_ZVAL(zopts); + MAKE_STD_ZVAL(zopts); ZVAL_LONG(zopts, opts); - phalcon_call_func_params(return_value, return_value_ptr, ZEND_STRL("json_encode") TSRMLS_CC, 2, v, zopts); + if (FAILURE == phalcon_call_func_params(return_value, return_value_ptr, ZEND_STRL("json_encode") TSRMLS_CC, 2, v, zopts)) { + if (return_value_ptr && EG(exception)) { + ALLOC_INIT_ZVAL(*return_value_ptr); + } + } + zval_ptr_dtor(&zopts); } void phalcon_json_decode(zval *return_value, zval **return_value_ptr, zval *v, zend_bool assoc TSRMLS_DC) { - zval *zassoc; + zval *zassoc = assoc ? PHALCON_GLOBAL(z_true) : PHALCON_GLOBAL(z_false); - ALLOC_INIT_ZVAL(zassoc); - ZVAL_BOOL(zassoc, assoc); + if (FAILURE == phalcon_call_func_params(return_value, return_value_ptr, ZEND_STRL("json_decode") TSRMLS_CC, 2, v, zassoc)) { + if (return_value_ptr && EG(exception)) { + ALLOC_INIT_ZVAL(*return_value_ptr); + } + } - phalcon_call_func_params(return_value, return_value_ptr, ZEND_STRL("json_decode") TSRMLS_CC, 2, v, zassoc); zval_ptr_dtor(&zassoc); } diff --git a/ext/mvc/collection.c b/ext/mvc/collection.c index 47a62f3253f..01945adc358 100644 --- a/ext/mvc/collection.c +++ b/ext/mvc/collection.c @@ -406,7 +406,7 @@ PHP_METHOD(Phalcon_Mvc_Collection, getConnectionService){ PHALCON_MM_GROW(); models_manager = phalcon_fetch_nproperty_this(this_ptr, SL("_modelsManager"), PH_NOISY_CC); - phalcon_call_method_p1_ex(return_value, return_value_ptr, models_manager, "getconnectionservice", this_ptr); + phalcon_return_call_method_p1(models_manager, "getconnectionservice", this_ptr); RETURN_MM(); } diff --git a/ext/mvc/model.c b/ext/mvc/model.c index b9b7e9dd42d..5f3c894f2b9 100644 --- a/ext/mvc/model.c +++ b/ext/mvc/model.c @@ -5343,10 +5343,9 @@ PHP_METHOD(Phalcon_Mvc_Model, hasManyToMany){ phalcon_fetch_params(1, 6, 1, &fields, &intermediate_model, &intermediate_fields, &intermediate_referenced_fields, &reference_model, &referenced_fields, &options); - PHALCON_OBS_VAR(manager); - phalcon_read_property_this(&manager, this_ptr, SL("_modelsManager"), PH_NOISY_CC); + manager = phalcon_fetch_nproperty_this(this_ptr, SL("_modelsManager"), PH_NOISY_CC); - PHALCON_CALL_METHOD(return_value, return_value_ptr, manager, "addhasmanytomany", zend_inline_hash_func(SS("addhasmanytomany")), (options ? 8 : 7), this_ptr, fields, intermediate_model, intermediate_fields, intermediate_referenced_fields, reference_model, referenced_fields, options); + PHALCON_RETURN_CALL_METHOD(manager, "addhasmanytomany", zend_inline_hash_func(SS("addhasmanytomany")), (options ? 8 : 7), this_ptr, fields, intermediate_model, intermediate_fields, intermediate_referenced_fields, reference_model, referenced_fields, options); RETURN_MM(); } diff --git a/ext/mvc/model/query.c b/ext/mvc/model/query.c index dc663aba198..9012f9d969c 100644 --- a/ext/mvc/model/query.c +++ b/ext/mvc/model/query.c @@ -694,11 +694,11 @@ PHP_METHOD(Phalcon_Mvc_Model_Query, _getExpression){ break; case PHQL_T_QUALIFIED: - phalcon_call_method_p1_ex(return_value, return_value_ptr, this_ptr, "_getqualified", expr); + phalcon_return_call_method_p1(this_ptr, "_getqualified", expr); break; case 359: /** @todo Is this code returned anywhere? */ - phalcon_call_method_p1_ex(return_value, return_value_ptr, this_ptr, "_getaliased", expr); + phalcon_return_call_method_p1(this_ptr, "_getaliased", expr); break; case PHQL_T_ADD: @@ -993,7 +993,7 @@ PHP_METHOD(Phalcon_Mvc_Model_Query, _getExpression){ break; case PHQL_T_FCALL: - phalcon_call_method_p1_ex(return_value, return_value_ptr, this_ptr, "_getfunctioncall", expr); + phalcon_return_call_method_p1(this_ptr, "_getfunctioncall", expr); break; default: @@ -1011,7 +1011,7 @@ PHP_METHOD(Phalcon_Mvc_Model_Query, _getExpression){ * Is a qualified column */ if (phalcon_array_isset_string(expr, SS("domain"))) { - phalcon_call_method_p1_ex(return_value, return_value_ptr, this_ptr, "_getqualified", expr); + phalcon_return_call_method_p1(this_ptr, "_getqualified", expr); RETURN_MM(); } @@ -4894,11 +4894,11 @@ PHP_METHOD(Phalcon_Mvc_Model_Query, execute){ * Check if only the first row must be returned */ if (zend_is_true(unique_row)) { - phalcon_call_method_p0_ex(return_value, return_value_ptr, result, "getfirst"); + phalcon_return_call_method_p0(result, "getfirst"); RETURN_MM(); - } else { - RETURN_CCTOR(result); } + + RETURN_CCTOR(result); } /** @@ -4931,11 +4931,11 @@ PHP_METHOD(Phalcon_Mvc_Model_Query, getSingleResult){ * The query is already programmed to return just one row */ if (zend_is_true(unique_row)) { - phalcon_call_method_p2_ex(return_value, return_value_ptr, this_ptr, "execute", bind_params, bind_types); + phalcon_return_call_method_p2(this_ptr, "execute", bind_params, bind_types); RETURN_MM(); } - phalcon_call_method_p2_ex(return_value, return_value_ptr, this_ptr, "execute", bind_params, bind_types); + phalcon_return_call_method_p2(this_ptr, "execute", bind_params, bind_types); PHALCON_INIT_VAR(first_result); phalcon_call_method(first_result, return_value, "getfirst"); diff --git a/ext/tag.c b/ext/tag.c index e1e57a60afd..023e5fa6cad 100644 --- a/ext/tag.c +++ b/ext/tag.c @@ -97,7 +97,7 @@ static void phalcon_tag_get_escaper(zval **return_value_ptr, zval *params TSRMLS if (zend_is_true(autoescape)) { phalcon_call_self_func_params(result, &result, NULL, SL("getescaperservice") TSRMLS_CC, 0); if (EG(exception)) { - result = NULL; + assert(result == NULL); } } @@ -114,6 +114,11 @@ static void phalcon_tag_write_attributes(zval *code, zval *attributes TSRMLS_DC) PHALCON_OBS_VAR(escaper); phalcon_tag_get_escaper(&escaper, attributes TSRMLS_CC); + if (EG(exception)) { + assert(escaper == NULL); + PHALCON_MM_RESTORE(); + return; + } if (escaper) { for ( @@ -512,6 +517,10 @@ PHP_METHOD(Phalcon_Tag, linkTo){ ZVAL_STRING(code, "", link_text, ""); @@ -544,7 +553,7 @@ PHP_METHOD(Phalcon_Tag, _inputField){ array_init_size(params, 1); phalcon_array_append(¶ms, parameters, 0); } else { - PHALCON_CPY_WRT(params, parameters); + PHALCON_CPY_WRT_CTOR(params, parameters); } PHALCON_INIT_VAR(value); @@ -552,16 +561,16 @@ PHP_METHOD(Phalcon_Tag, _inputField){ if (!phalcon_array_isset_long_fetch(&id, params, 0)) { PHALCON_OBS_VAR(id); phalcon_array_fetch_string(&id, params, SL("id"), PH_NOISY); - phalcon_array_update_long(¶ms, 0, &id, PH_COPY | PH_SEPARATE); + phalcon_array_update_long(¶ms, 0, &id, PH_COPY); } if (phalcon_array_isset_string_fetch(&name, params, SS("name"))) { if (!zend_is_true(name)) { - phalcon_array_update_string(¶ms, ISL(name), &id, PH_COPY | PH_SEPARATE); + phalcon_array_update_string(¶ms, ISL(name), &id, PH_COPY); } } else { - phalcon_array_update_string(¶ms, ISL(name), &id, PH_COPY | PH_SEPARATE); + phalcon_array_update_string(¶ms, ISL(name), &id, PH_COPY); } /** @@ -569,32 +578,41 @@ PHP_METHOD(Phalcon_Tag, _inputField){ */ if (!phalcon_memnstr_str(id, SL("["))) { if (!phalcon_array_isset_string(params, SS("id"))) { - phalcon_array_update_string(¶ms, SL("id"), &id, PH_COPY | PH_SEPARATE); + phalcon_array_update_string(¶ms, SL("id"), &id, PH_COPY); } } phalcon_call_self_p2(value, this_ptr, "getvalue", id, params); - phalcon_array_update_string(¶ms, ISL(value), &value, PH_COPY | PH_SEPARATE); + phalcon_array_update_string(¶ms, ISL(value), &value, PH_COPY); } else { /** * Use the 'id' as value if the user hadn't set it */ if (!phalcon_array_isset_string(params, SS("value"))) { if (phalcon_array_isset_long_fetch(&value, params, 0)) { - phalcon_array_update_string(¶ms, ISL(value), &value, PH_COPY | PH_SEPARATE); + phalcon_array_update_string(¶ms, ISL(value), &value, PH_COPY); } } } PHALCON_OBS_VAR(escaper); phalcon_tag_get_escaper(&escaper, params TSRMLS_CC); + if (EG(exception)) { + assert(escaper == NULL); + PHALCON_MM_RESTORE(); + return; + } - phalcon_array_update_string(¶ms, ISL(type), &type, PH_COPY | PH_SEPARATE); + phalcon_array_update_string(¶ms, ISL(type), &type, PH_COPY); PHALCON_INIT_VAR(code); ZVAL_STRING(code, "", escaped, ""); @@ -1186,6 +1168,10 @@ PHP_METHOD(Phalcon_Tag, form){ ZVAL_STRING(code, ""); @@ -1367,6 +1353,10 @@ PHP_METHOD(Phalcon_Tag, stylesheetLink){ ZVAL_STRING(code, "" PHP_EOL); PHALCON_MM_RESTORE(); @@ -1542,6 +1536,10 @@ PHP_METHOD(Phalcon_Tag, image){ ZVAL_STRING(code, " Date: Fri, 27 Sep 2013 22:58:33 +0300 Subject: [PATCH 4/6] Fix segfault in zim_Phalcon_Events_Manager_attach --- ext/events/manager.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/ext/events/manager.c b/ext/events/manager.c index 4550d744883..321159200ec 100644 --- a/ext/events/manager.c +++ b/ext/events/manager.c @@ -99,8 +99,7 @@ PHP_METHOD(Phalcon_Events_Manager, attach){ events = phalcon_fetch_nproperty_this(this_ptr, SL("_events"), PH_NOISY_CC); if (Z_TYPE_P(events) != IS_ARRAY) { - SEPARATE_ZVAL_IF_NOT_REF(&events); - zval_dtor(events); + PHALCON_INIT_VAR(events); array_init(events); } From 7dce0862bc660dc8376064221f64f5608d197da4 Mon Sep 17 00:00:00 2001 From: Vladimir Kolesnikov Date: Fri, 27 Sep 2013 23:11:37 +0300 Subject: [PATCH 5/6] issue-1261.phpt requires openssl --- ext/tests/issue-1261.phpt | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/ext/tests/issue-1261.phpt b/ext/tests/issue-1261.phpt index eb0a41034f6..54a0ac2db64 100644 --- a/ext/tests/issue-1261.phpt +++ b/ext/tests/issue-1261.phpt @@ -1,7 +1,12 @@ --TEST-- Ability to restrict the maximum password length for Phalcon\Security::checkHash() - https://github.com/phalcon/cphalcon/pull/1261 --SKIPIF-- - + --FILE-- Date: Fri, 27 Sep 2013 23:25:43 +0300 Subject: [PATCH 6/6] \Phalcon\Security\Exception should not inherit from \Phalcon\DI\Exception --- ext/security/exception.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ext/security/exception.c b/ext/security/exception.c index 85f6cee8088..17554b81af2 100644 --- a/ext/security/exception.c +++ b/ext/security/exception.c @@ -45,7 +45,7 @@ */ PHALCON_INIT_CLASS(Phalcon_Security_Exception){ - PHALCON_REGISTER_CLASS_EX(Phalcon\\Security, Exception, security_exception, phalcon_di_exception_ce, NULL, 0); + PHALCON_REGISTER_CLASS_EX(Phalcon\\Security, Exception, security_exception, phalcon_exception_ce, NULL, 0); return SUCCESS; }