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

Remove duplicate macros #1794

Merged
merged 7 commits into from Jan 13, 2014
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 CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
1.3.0
- Make the source code compatible with PHP 5.6-dev and PHP 5.7-dev (#1762)
- Code cleanup: get rid of compiler warnings, dead code elimination, code deduplication, use static code analysers to eliminate possible bugs
(#801, #802, #810, #825, #827, #838, #849, #942, #968, #1001, #1093, #1169, #1214, #1223, #1224, #1375, #1430, #1787)
(#801, #802, #810, #825, #827, #838, #849, #942, #968, #1001, #1093, #1169, #1214, #1223, #1224, #1375, #1430, #1787, #1794)
- Fixed various memory leaks (#469, #860, #910, #914, #916, #1031, #1067, #1249, #1273, #1291, #1309, #1345, #1455, #1470, #1700)
- Fixed memory access violations / segmentation faults / etc (#469, #849, #851, #852, #858, #860, #861, #895, #911, #918, #927, #928, #1000, #1077, #1112, #1113, #1131, #1149, #1173,
#1272, #1284, #1302, #1340, #1343, #1368, #1369, #1371, #1376, #1379, #1392, #1451, #1466, #1485, #1494, #1501, #1504, #1509, #1567, #1607)
Expand Down
8 changes: 4 additions & 4 deletions ext/db/adapter/pdo.c
Original file line number Diff line number Diff line change
Expand Up @@ -246,8 +246,8 @@ PHP_METHOD(Phalcon_Db_Adapter_Pdo, connect){

while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) {

PHALCON_GET_FOREACH_KEY(key, ah0, hp0);
PHALCON_GET_FOREACH_VALUE(value);
PHALCON_GET_HKEY(key, ah0, hp0);
PHALCON_GET_HVALUE(value);

PHALCON_INIT_NVAR(dsn_attribute);
PHALCON_CONCAT_VSV(dsn_attribute, key, "=", value);
Expand Down Expand Up @@ -359,8 +359,8 @@ PHP_METHOD(Phalcon_Db_Adapter_Pdo, executePrepared){

while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) {

PHALCON_GET_FOREACH_KEY(wildcard, ah0, hp0);
PHALCON_GET_FOREACH_VALUE(value);
PHALCON_GET_HKEY(wildcard, ah0, hp0);
PHALCON_GET_HVALUE(value);

if (Z_TYPE_P(wildcard) == IS_LONG) {
PHALCON_INIT_NVAR(parameter);
Expand Down
12 changes: 6 additions & 6 deletions ext/db/dialect/oracle.c
Original file line number Diff line number Diff line change
Expand Up @@ -875,7 +875,7 @@ PHP_METHOD(Phalcon_Db_Dialect_Oracle, select){

while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) {

PHALCON_GET_FOREACH_VALUE(column);
PHALCON_GET_HVALUE(column);

/**
* Escape column name
Expand Down Expand Up @@ -967,7 +967,7 @@ PHP_METHOD(Phalcon_Db_Dialect_Oracle, select){

while (zend_hash_get_current_data_ex(ah1, (void**) &hd, &hp1) == SUCCESS) {

PHALCON_GET_FOREACH_VALUE(table);
PHALCON_GET_HVALUE(table);

PHALCON_INIT_NVAR(sql_table);
phalcon_call_method_p2(sql_table, this_ptr, "getsqltable", table, escape_char);
Expand Down Expand Up @@ -1011,7 +1011,7 @@ PHP_METHOD(Phalcon_Db_Dialect_Oracle, select){

while (zend_hash_get_current_data_ex(ah2, (void**) &hd, &hp2) == SUCCESS) {

PHALCON_GET_FOREACH_VALUE(join);
PHALCON_GET_HVALUE(join);

PHALCON_OBS_NVAR(type);
phalcon_array_fetch_string(&type, join, SL("type"), PH_NOISY);
Expand Down Expand Up @@ -1042,7 +1042,7 @@ PHP_METHOD(Phalcon_Db_Dialect_Oracle, select){

while (zend_hash_get_current_data_ex(ah3, (void**) &hd, &hp3) == SUCCESS) {

PHALCON_GET_FOREACH_VALUE(join_condition);
PHALCON_GET_HVALUE(join_condition);

PHALCON_INIT_NVAR(join_expression);
phalcon_call_method_p2(join_expression, this_ptr, "getsqlexpression", join_condition, escape_char);
Expand Down Expand Up @@ -1095,7 +1095,7 @@ PHP_METHOD(Phalcon_Db_Dialect_Oracle, select){

while (zend_hash_get_current_data_ex(ah4, (void**) &hd, &hp4) == SUCCESS) {

PHALCON_GET_FOREACH_VALUE(group_field);
PHALCON_GET_HVALUE(group_field);

PHALCON_INIT_NVAR(group_expression);
phalcon_call_method_p2(group_expression, this_ptr, "getsqlexpression", group_field, escape_char);
Expand Down Expand Up @@ -1139,7 +1139,7 @@ PHP_METHOD(Phalcon_Db_Dialect_Oracle, select){

while (zend_hash_get_current_data_ex(ah5, (void**) &hd, &hp5) == SUCCESS) {

PHALCON_GET_FOREACH_VALUE(order_item);
PHALCON_GET_HVALUE(order_item);

PHALCON_OBS_NVAR(order_expression);
phalcon_array_fetch_long(&order_expression, order_item, 0, PH_NOISY);
Expand Down
3 changes: 2 additions & 1 deletion ext/debug.c
Original file line number Diff line number Diff line change
Expand Up @@ -817,11 +817,12 @@ PHP_METHOD(Phalcon_Debug, showTraceItem){
} else {
PHALCON_OBS_NVAR(function_name);
phalcon_array_fetch_string(&function_name, trace, SL("function"), PH_NOISY);
convert_to_string(function_name);

/**
* Check if the function exists
*/
if (phalcon_function_exists(function_name TSRMLS_CC) == SUCCESS) {
if (phalcon_function_exists_ex(Z_STRVAL_P(function_name), Z_STRLEN_P(function_name)+1 TSRMLS_CC) == SUCCESS) {
ce1 = zend_fetch_class(SL("ReflectionFunction"), ZEND_FETCH_CLASS_AUTO TSRMLS_CC);
PHALCON_INIT_VAR(function_reflection);
object_init_ex(function_reflection, ce1);
Expand Down
55 changes: 1 addition & 54 deletions ext/kernel/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -78,25 +78,6 @@ zend_class_entry *phalcon_register_internal_interface_ex(zend_class_entry *orig_
return ce;
}

/**
* Initilializes super global variables if doesn't
*/
int phalcon_init_global(char *global, unsigned int global_length TSRMLS_DC) {

#if PHP_VERSION_ID < 50400
zend_bool jit_initialization = (PG(auto_globals_jit) && !PG(register_globals) && !PG(register_long_arrays));
if (jit_initialization) {
return zend_is_auto_global(global, global_length - 1 TSRMLS_CC);
}
#else
if (PG(auto_globals_jit)) {
return zend_is_auto_global(global, global_length - 1 TSRMLS_CC);
}
#endif

return SUCCESS;
}

/**
* Gets the global zval into PG macro
*/
Expand Down Expand Up @@ -260,39 +241,12 @@ int phalcon_fast_count_ev(zval *value TSRMLS_DC) {
return 1;
}

/**
* Check if a function exists
*/
int phalcon_function_exists(const zval *function_name TSRMLS_DC) {

return phalcon_function_quick_exists_ex(
Z_STRVAL_P(function_name),
Z_STRLEN_P(function_name) + 1,
zend_inline_hash_func(Z_STRVAL_P(function_name), Z_STRLEN_P(function_name) + 1) TSRMLS_CC
);
}

/**
* Check if a function exists using explicit char param
*
* @param function_name
* @param function_len strlen(function_name)+1
*/
int phalcon_function_exists_ex(const char *function_name, unsigned int function_len TSRMLS_DC) {

return phalcon_function_quick_exists_ex(function_name, function_len, zend_inline_hash_func(function_name, function_len) TSRMLS_CC);
}

/**
* Check if a function exists using explicit char param (using precomputed hash key)
*/
int phalcon_function_quick_exists_ex(const char *method_name, unsigned int method_len, unsigned long key TSRMLS_DC) {

if (zend_hash_quick_exists(CG(function_table), method_name, method_len, key)) {
return SUCCESS;
}

return FAILURE;
return (zend_hash_quick_exists(CG(function_table), method_name, method_len, key)) ? SUCCESS : FAILURE;
}

/**
Expand Down Expand Up @@ -337,13 +291,6 @@ int phalcon_is_iterable_ex(zval *arr, HashTable **arr_hash, HashPosition *hash_p
return 1;
}

void phalcon_safe_zval_ptr_dtor(zval *pzval)
{
if (pzval) {
zval_ptr_dtor(&pzval);
}
}

/**
* Parses method parameters with minimum overhead
*/
Expand Down
102 changes: 41 additions & 61 deletions ext/kernel/main.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,17 @@
+------------------------------------------------------------------------+
*/

#ifndef PHALCON_KERNEL_MAIN_H
#define PHALCON_KERNEL_MAIN_H

#include "php_phalcon.h"

#include <Zend/zend_exceptions.h>
#include <Zend/zend_interfaces.h>

#include <ext/spl/spl_exceptions.h>
#include <ext/spl/spl_iterators.h>

#include "php_phalcon.h"

#include "kernel/memory.h"
#include "kernel/backtrace.h"

Expand All @@ -35,7 +38,6 @@
#define PH_SILENT 1

#define PH_NOISY_CC PH_NOISY TSRMLS_CC
#define PH_SILENT_CC PH_SILENT TSRMLS_CC

#define PH_SEPARATE 256
#define PH_COPY 1024
Expand All @@ -48,30 +50,54 @@


/* Startup functions */
extern void php_phalcon_init_globals(zend_phalcon_globals *phalcon_globals TSRMLS_DC);
extern zend_class_entry *phalcon_register_internal_interface_ex(zend_class_entry *orig_ce, zend_class_entry *parent_ce TSRMLS_DC);
void php_phalcon_init_globals(zend_phalcon_globals *phalcon_globals TSRMLS_DC);
zend_class_entry *phalcon_register_internal_interface_ex(zend_class_entry *orig_ce, zend_class_entry *parent_ce TSRMLS_DC);

/* Globals functions */
int phalcon_init_global(char *global, unsigned int global_length TSRMLS_DC);
zval* phalcon_get_global(const char *global, unsigned int global_length TSRMLS_DC);

extern int phalcon_is_callable(zval *var TSRMLS_DC);
extern int phalcon_function_exists(const zval *function_name TSRMLS_DC);
extern int phalcon_function_exists_ex(const char *func_name, unsigned int func_len TSRMLS_DC);
extern int phalcon_function_quick_exists_ex(const char *func_name, unsigned int func_len, unsigned long key TSRMLS_DC);
int phalcon_is_callable(zval *var TSRMLS_DC);
int phalcon_function_quick_exists_ex(const char *func_name, unsigned int func_len, unsigned long key TSRMLS_DC);

/**
* Check if a function exists using explicit char param
*
* @param function_name
* @param function_len strlen(function_name)+1
*/
PHALCON_ATTR_NONNULL static inline int phalcon_function_exists_ex(const char *function_name, unsigned int function_len TSRMLS_DC)
{
#ifdef __GNUC__
if (__builtin_constant_p(function_name) && __builtin_constant_p(function_len)) {
return phalcon_function_quick_exists_ex(function_name, function_len, zend_inline_hash_func(function_name, function_len) TSRMLS_CC);
}
#endif

return phalcon_function_quick_exists_ex(function_name, function_len, zend_hash_func(function_name, function_len) TSRMLS_CC);
}

/* Count */
long int phalcon_fast_count_int(zval *value TSRMLS_DC);
void phalcon_fast_count(zval *result, zval *array TSRMLS_DC);
int phalcon_fast_count_ev(zval *array TSRMLS_DC);

/* Utils functions */
extern int phalcon_is_iterable_ex(zval *arr, HashTable **arr_hash, HashPosition *hash_position, int duplicate, int reverse);
void phalcon_safe_zval_ptr_dtor(zval *pzval);
int phalcon_is_iterable_ex(zval *arr, HashTable **arr_hash, HashPosition *hash_position, int duplicate, int reverse);

/**
* @brief destroys @c pzval if it is not @c NULL
* @param pzval
*/
static inline void phalcon_safe_zval_ptr_dtor(zval *pzval)
{
if (pzval) {
zval_ptr_dtor(&pzval);
}
}


/* Fetch Parameters */
extern int phalcon_fetch_parameters(int num_args TSRMLS_DC, int required_args, int optional_args, ...);
int phalcon_fetch_parameters(int num_args TSRMLS_DC, int required_args, int optional_args, ...);
int phalcon_fetch_parameters_ex(int dummy TSRMLS_DC, int n_req, int n_opt, ...);

/* Compatibility macros for PHP 5.3 */
Expand All @@ -87,14 +113,6 @@ int phalcon_fetch_parameters_ex(int dummy TSRMLS_DC, int n_req, int n_opt, ...);
Z_TYPE_P(z) = Z_TYPE_P(v);
#endif

/** Symbols */
#define PHALCON_READ_SYMBOL(var, auxarr, name) \
if (EG(active_symbol_table) && zend_hash_find(EG(active_symbol_table), name, sizeof(name), (void **)&auxarr) == SUCCESS) { \
var = *auxarr; \
} else { \
ZVAL_NULL(var); \
}

/**
* Return zval checking if it's needed to ctor
*/
Expand Down Expand Up @@ -162,15 +180,6 @@ int phalcon_fetch_parameters_ex(int dummy TSRMLS_DC, int n_req, int n_opt, ...);
PHALCON_MM_RESTORE(); \
return;

/**
* Returns variables without ctor, without restoring the memory stack
*/
#define RETURN_NCTORW(var) { \
*(return_value) = *(var); \
INIT_PZVAL(return_value) \
} \
return;

/**
* Returns a zval in an object member
*/
Expand Down Expand Up @@ -212,32 +221,6 @@ int phalcon_fetch_parameters_ex(int dummy TSRMLS_DC, int n_req, int n_opt, ...);
#define PHALCON_GET_HKEY(var, hash, hash_position) \
phalcon_get_current_key(&var, hash, &hash_position TSRMLS_CC);

/** Get current hash key copying the hash_value if needed */
#define PHALCON_GET_HMKEY(var, hash, hash_pointer) \
{\
int hash_type; \
char *hash_index; \
uint hash_index_len; \
ulong hash_num; \
\
PHALCON_INIT_NVAR(var); \
hash_type = zend_hash_get_current_key_ex(hash, &hash_index, &hash_index_len, &hash_num, 0, &hash_pointer); \
if (hash_type == HASH_KEY_IS_STRING) { \
if (IS_INTERNED(hash_index)) { \
ZVAL_STRINGL(var, hash_index, hash_index_len - 1, 0); \
} else { \
ZVAL_STRINGL(var, hash_index, hash_index_len - 1, 1); \
} \
} else { \
if (hash_type == HASH_KEY_IS_LONG) { \
ZVAL_LONG(var, hash_num); \
}\
}\
}

/** Foreach */
#define PHALCON_GET_FOREACH_KEY(var, hash, hash_pointer) PHALCON_GET_HMKEY(var, hash, hash_pointer)

/** Check if an array is iterable or not */
#define phalcon_is_iterable(var, array_hash, hash_pointer, duplicate, reverse) \
if (!phalcon_is_iterable_ex(var, array_hash, hash_pointer, duplicate, reverse)) { \
Expand All @@ -246,11 +229,6 @@ int phalcon_fetch_parameters_ex(int dummy TSRMLS_DC, int n_req, int n_opt, ...);
return; \
}

#define PHALCON_GET_FOREACH_VALUE(var) \
PHALCON_OBS_NVAR(var); \
var = *hd; \
Z_ADDREF_P(var);

#define PHALCON_GET_HVALUE(var) \
PHALCON_OBS_NVAR(var); \
var = *hd; \
Expand Down Expand Up @@ -418,3 +396,5 @@ int phalcon_fetch_parameters_ex(int dummy TSRMLS_DC, int n_req, int n_opt, ...);
#define PHALCON_ENSURE_IS_DOUBLE(ppzv) convert_to_explicit_type_ex(ppzv, IS_DOUBLE)
#define PHALCON_ENSURE_IS_BOOL(ppzv) convert_to_explicit_type_ex(ppzv, IS_BOOL)
#define PHALCON_ENSURE_IS_ARRAY(ppzv) convert_to_explicit_type_ex(ppzv, IS_ARRAY)

#endif /* PHALCON_KERNEL_MAIN_H */
4 changes: 3 additions & 1 deletion ext/mvc/model/query.c
Original file line number Diff line number Diff line change
Expand Up @@ -3842,7 +3842,9 @@ PHP_METHOD(Phalcon_Mvc_Model_Query, _executeSelect){

while (zend_hash_get_current_data_ex(ah2, (void**) &hd, &hp2) == SUCCESS) {

PHALCON_GET_HMKEY(alias_copy, ah2, hp2);
zval key = phalcon_get_current_key_w(ah2, &hp2);
PHALCON_CPY_WRT_CTOR(alias_copy, &key);

PHALCON_GET_HVALUE(column);

PHALCON_OBS_NVAR(type);
Expand Down
Loading