Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Use preallocated permanent zvals instead of null, true, false, 0 and 1 #1302

Merged
merged 6 commits into from Sep 28, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
49 changes: 18 additions & 31 deletions ext/acl/adapter/memory.c
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -160,15 +157,15 @@ 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();

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) {
Expand All @@ -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, "!*!*");
Expand Down Expand Up @@ -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) {
Expand All @@ -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);
Expand All @@ -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;
Expand All @@ -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) {
Expand All @@ -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);
Expand All @@ -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);
}
}
}
Expand Down Expand Up @@ -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();
}

/**
Expand Down
15 changes: 4 additions & 11 deletions ext/acl/resource.c
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

/**
Expand Down
13 changes: 3 additions & 10 deletions ext/acl/role.c
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

/**
Expand Down
2 changes: 1 addition & 1 deletion ext/annotations/adapter/apc.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions ext/annotations/base.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
2 changes: 1 addition & 1 deletion ext/annotations/collection.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
4 changes: 2 additions & 2 deletions ext/annotations/parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
5 changes: 3 additions & 2 deletions ext/annotations/reader.c
Original file line number Diff line number Diff line change
Expand Up @@ -273,16 +273,17 @@ PHP_METHOD(Phalcon_Annotations_Reader, parseDocBlock){
}

if (!line) {
PHALCON_INIT_VAR(line);
line = PHALCON_GLOBAL(z_null);
}

if (Z_TYPE_P(file) != IS_STRING) {
PHALCON_INIT_NVAR(file);
ZVAL_STRING(file, "eval code", 1);
}
if (phannot_parse_annotations(return_value, doc_block, file, line TSRMLS_CC) == FAILURE) {
return;
RETURN_MM();
}

RETURN_MM();
}

14 changes: 3 additions & 11 deletions ext/annotations/reflection.c
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

/**
Expand Down Expand Up @@ -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;
}

Expand Down
Loading