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

Fix notices when phalcon.orm.column_renaming is 0 and implement reset() for metadata adapters #1952

Merged
merged 7 commits into from Feb 4, 2014
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Implement reset() for metadata adapters other than memory
Close #1934
  • Loading branch information
sjinks committed Feb 2, 2014
commit 52a2a21727eaeeb3ed746faf4532421188447ecf
14 changes: 7 additions & 7 deletions ext/cache/backend/apc.c
Original file line number Diff line number Diff line change
Expand Up @@ -80,19 +80,19 @@ static const zend_function_entry phalcon_cache_backend_apc_method_entry[] = {
PHP_FE_END
};

static int phalcon_cache_backend_is_apcu = -1;
static int phalcon_cache_backend_is_old_apcu = -1;

/**
* Phalcon\Cache\Backend\Apc initializer
*/
PHALCON_INIT_CLASS(Phalcon_Cache_Backend_Apc){

if (-1 == phalcon_cache_backend_is_apcu) {
phalcon_cache_backend_is_apcu = zend_hash_exists(&module_registry, SS("apcu"));
if (phalcon_cache_backend_is_apcu) {
if (-1 == phalcon_cache_backend_is_old_apcu) {
phalcon_cache_backend_is_old_apcu = zend_hash_exists(&module_registry, SS("apcu"));
if (phalcon_cache_backend_is_old_apcu) {
zend_constant *c;
if (zend_hash_find(EG(zend_constants), SS("APCU_APC_FULL_BC"), (void**)&c) == SUCCESS) {
phalcon_cache_backend_is_apcu = !zend_is_true(&c->value);
phalcon_cache_backend_is_old_apcu = !zend_is_true(&c->value);
}
}
}
Expand Down Expand Up @@ -390,7 +390,7 @@ PHP_METHOD(Phalcon_Cache_Backend_Apc, queryKeys){
PHALCON_INIT_VAR(iterator);
object_init_ex(iterator, apciterator_ce);
assert(phalcon_has_constructor(iterator TSRMLS_CC));
if (!phalcon_cache_backend_is_apcu) {
if (!phalcon_cache_backend_is_old_apcu) {
PHALCON_ALLOC_GHOST_ZVAL(type);
ZVAL_STRING(type, "user", 1);
phalcon_call_method_p2_noret(iterator, "__construct", type, prefix_pattern);
Expand Down Expand Up @@ -512,7 +512,7 @@ PHP_METHOD(Phalcon_Cache_Backend_Apc, flush){
PHALCON_INIT_VAR(iterator);
object_init_ex(iterator, apciterator_ce);
assert(phalcon_has_constructor(iterator TSRMLS_CC));
if (!phalcon_cache_backend_is_apcu) {
if (!phalcon_cache_backend_is_old_apcu) {
PHALCON_ALLOC_GHOST_ZVAL(type);
ZVAL_STRING(type, "user", 1);
phalcon_call_method_p2_noret(iterator, "__construct", type, prefix_pattern);
Expand Down
38 changes: 30 additions & 8 deletions ext/kernel/file.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,13 @@
+------------------------------------------------------------------------+
*/

#include "php_phalcon.h"
#include "kernel/file.h"
#include "kernel/main.h"
#include "kernel/memory.h"
#include "kernel/concat.h"
#include "kernel/operators.h"

#include <ctype.h>

#include <main/php_streams.h>
#include <Zend/zend_exceptions.h>
Expand All @@ -27,12 +33,6 @@
#include <ext/standard/php_filestat.h>
#include <ext/standard/php_string.h>

#include "kernel/main.h"
#include "kernel/memory.h"
#include "kernel/concat.h"
#include "kernel/operators.h"
#include "kernel/file.h"

/**
* Checks if a file exist
*
Expand Down Expand Up @@ -140,7 +140,7 @@ void phalcon_prepare_virtual_path(zval *return_value, zval *path, zval *virtual_
if (ch == '\0') {
break;
}
if (ch == '/' || ch == '\\' || ch == ':') {
if (ch == '/' || ch == '\\' || ch == ':' || !isprint(ch)) {
smart_str_appendl(&virtual_str, Z_STRVAL_P(virtual_separator), Z_STRLEN_P(virtual_separator));
}
else {
Expand All @@ -157,6 +157,28 @@ void phalcon_prepare_virtual_path(zval *return_value, zval *path, zval *virtual_
}
}

/**
* Faster version of phalcon_prepare_virtual_path()
*/
void phalcon_prepare_virtual_path_ex(zval *return_value, const char *path, size_t path_len, char virtual_separator TSRMLS_DC)
{
char *copy = ecalloc(path_len+1, 1);
size_t i;

for (i=0; i<path_len; ++i) {
char c = path[i];

if (c == '/' || c == '\\' || c == ':' || !isprint(c)) {
copy[i] = virtual_separator;
}
else {
copy[i] = tolower(c);
}
}

ZVAL_STRINGL(return_value, copy, path_len, 0);
}

/**
* Generates a unique id for a path
*/
Expand Down
8 changes: 3 additions & 5 deletions ext/kernel/file.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
#ifndef PHALCON_KERNEL_FILE_H
#define PHALCON_KERNEL_FILE_H

#include "php_phalcon.h"

int phalcon_file_exists(zval *filename TSRMLS_DC);
int phalcon_compare_mtime(zval *filename1, zval *filename2 TSRMLS_DC);
void phalcon_fix_path(zval **return_value, zval *path, zval *directory_separator TSRMLS_DC);
Expand All @@ -35,10 +37,6 @@ void phalcon_unlink(zval *return_value, zval *path TSRMLS_DC);
void phalcon_filemtime(zval *return_value, zval *path TSRMLS_DC);
void phalcon_basename(zval *return_value, zval *path TSRMLS_DC);

#ifdef TSRM_WIN32
#define PHALCON_DIRECTORY_SEPARATOR "\\"
#else
#define PHALCON_DIRECTORY_SEPARATOR "/"
#endif
void phalcon_prepare_virtual_path_ex(zval *return_value, const char *path, size_t path_len, char virtual_separator TSRMLS_DC);

#endif /* PHALCON_KERNEL_FILE_H */
3 changes: 2 additions & 1 deletion ext/loader.c
Original file line number Diff line number Diff line change
Expand Up @@ -481,6 +481,7 @@ PHP_METHOD(Phalcon_Loader, autoLoad){
HashTable *ah0, *ah1, *ah2, *ah3, *ah4, *ah5;
HashPosition hp0, hp1, hp2, hp3, hp4, hp5;
zval **hd;
char slash[2] = {DEFAULT_SLASH, 0};

PHALCON_MM_GROW();

Expand Down Expand Up @@ -522,7 +523,7 @@ PHP_METHOD(Phalcon_Loader, autoLoad){
phalcon_read_property_this(&extensions, this_ptr, SL("_extensions"), PH_NOISY_CC);

PHALCON_INIT_VAR(ds);
ZVAL_STRING(ds, PHALCON_DIRECTORY_SEPARATOR, 1);
ZVAL_STRING(ds, slash, 1);

PHALCON_INIT_VAR(namespace_separator);
ZVAL_STRING(namespace_separator, "\\", 1);
Expand Down
4 changes: 2 additions & 2 deletions ext/mvc/model/metadata.c
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,8 @@ static const zend_function_entry phalcon_mvc_model_metadata_method_entry[] = {
PHP_ME(Phalcon_Mvc_Model_MetaData, getColumnMap, arginfo_phalcon_mvc_model_metadatainterface_getcolumnmap, ZEND_ACC_PUBLIC)
PHP_ME(Phalcon_Mvc_Model_MetaData, getReverseColumnMap, arginfo_phalcon_mvc_model_metadatainterface_getreversecolumnmap, ZEND_ACC_PUBLIC)
PHP_ME(Phalcon_Mvc_Model_MetaData, hasAttribute, arginfo_phalcon_mvc_model_metadatainterface_hasattribute, ZEND_ACC_PUBLIC)
PHP_ME(Phalcon_Mvc_Model_MetaData, isEmpty, NULL, ZEND_ACC_PUBLIC)
PHP_ME(Phalcon_Mvc_Model_MetaData, reset, NULL, ZEND_ACC_PUBLIC)
PHP_ME(Phalcon_Mvc_Model_MetaData, isEmpty, arginfo_phalcon_mvc_model_metadatainterface_isempty, ZEND_ACC_PUBLIC)
PHP_ME(Phalcon_Mvc_Model_MetaData, reset, arginfo_phalcon_mvc_model_metadatainterface_reset, ZEND_ACC_PUBLIC)
PHP_FE_END
};

Expand Down
71 changes: 46 additions & 25 deletions ext/mvc/model/metadata/apc.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include "kernel/object.h"
#include "kernel/concat.h"
#include "kernel/fcall.h"
#include "kernel/hash.h"

/**
* Phalcon\Mvc\Model\MetaData\Apc
Expand All @@ -49,6 +50,7 @@ zend_class_entry *phalcon_mvc_model_metadata_apc_ce;
PHP_METHOD(Phalcon_Mvc_Model_MetaData_Apc, __construct);
PHP_METHOD(Phalcon_Mvc_Model_MetaData_Apc, read);
PHP_METHOD(Phalcon_Mvc_Model_MetaData_Apc, write);
PHP_METHOD(Phalcon_Mvc_Model_MetaData_Apc, reset);

ZEND_BEGIN_ARG_INFO_EX(arginfo_phalcon_mvc_model_metadata_apc___construct, 0, 0, 0)
ZEND_ARG_INFO(0, options)
Expand All @@ -58,6 +60,7 @@ static const zend_function_entry phalcon_mvc_model_metadata_apc_method_entry[] =
PHP_ME(Phalcon_Mvc_Model_MetaData_Apc, __construct, arginfo_phalcon_mvc_model_metadata_apc___construct, ZEND_ACC_PUBLIC|ZEND_ACC_CTOR)
PHP_ME(Phalcon_Mvc_Model_MetaData_Apc, read, arginfo_phalcon_mvc_model_metadatainterface_read, ZEND_ACC_PUBLIC)
PHP_ME(Phalcon_Mvc_Model_MetaData_Apc, write, arginfo_phalcon_mvc_model_metadatainterface_write, ZEND_ACC_PUBLIC)
PHP_ME(Phalcon_Mvc_Model_MetaData_Apc, reset, arginfo_phalcon_mvc_model_metadatainterface_reset, ZEND_ACC_PUBLIC)
PHP_FE_END
};

Expand All @@ -83,34 +86,25 @@ PHALCON_INIT_CLASS(Phalcon_Mvc_Model_MetaData_Apc){
*/
PHP_METHOD(Phalcon_Mvc_Model_MetaData_Apc, __construct){

zval *options = NULL, *prefix, *ttl, *empty_array;
zval *options = NULL, *empty_array;

PHALCON_MM_GROW();

phalcon_fetch_params(1, 0, 1, &options);
phalcon_fetch_params(0, 0, 1, &options);

if (!options) {
options = PHALCON_GLOBAL(z_null);
}

if (Z_TYPE_P(options) == IS_ARRAY) {
if (phalcon_array_isset_string(options, SS("prefix"))) {
PHALCON_OBS_VAR(prefix);
phalcon_array_fetch_string(&prefix, options, SL("prefix"), PH_NOISY);
if (options && Z_TYPE_P(options) == IS_ARRAY) {
zval *prefix, *ttl;

if (phalcon_array_isset_string_fetch(&prefix, options, SS("prefix"))) {
phalcon_update_property_this(this_ptr, SL("_prefix"), prefix TSRMLS_CC);
}
if (phalcon_array_isset_string(options, SS("lifetime"))) {
PHALCON_OBS_VAR(ttl);
phalcon_array_fetch_string(&ttl, options, SL("lifetime"), PH_NOISY);

if (phalcon_array_isset_string_fetch(&ttl, options, SS("lifetime"))) {
phalcon_update_property_this(this_ptr, SL("_ttl"), ttl TSRMLS_CC);
}
}

PHALCON_INIT_VAR(empty_array);
PHALCON_ALLOC_GHOST_ZVAL(empty_array);
array_init(empty_array);
phalcon_update_property_this(this_ptr, SL("_metaData"), empty_array TSRMLS_CC);

PHALCON_MM_RESTORE();
}

/**
Expand All @@ -119,16 +113,15 @@ PHP_METHOD(Phalcon_Mvc_Model_MetaData_Apc, __construct){
* @param string $key
* @return array
*/
PHP_METHOD(Phalcon_Mvc_Model_MetaData_Apc, read){

PHP_METHOD(Phalcon_Mvc_Model_MetaData_Apc, read)
{
zval *key, *prefix, *apc_key, *data;

PHALCON_MM_GROW();

phalcon_fetch_params(1, 1, 0, &key);

PHALCON_OBS_VAR(prefix);
phalcon_read_property_this(&prefix, this_ptr, SL("_prefix"), PH_NOISY_CC);
prefix = phalcon_fetch_nproperty_this(this_ptr, SL("_prefix"), PH_NOISY TSRMLS_CC);

PHALCON_INIT_VAR(apc_key);
PHALCON_CONCAT_SVV(apc_key, "$PMM$", prefix, key);
Expand Down Expand Up @@ -156,15 +149,43 @@ PHP_METHOD(Phalcon_Mvc_Model_MetaData_Apc, write){

phalcon_fetch_params(1, 2, 0, &key, &data);

PHALCON_OBS_VAR(prefix);
phalcon_read_property_this(&prefix, this_ptr, SL("_prefix"), PH_NOISY_CC);
prefix = phalcon_fetch_nproperty_this(this_ptr, SL("_prefix"), PH_NOISY TSRMLS_CC);

PHALCON_INIT_VAR(apc_key);
PHALCON_CONCAT_SVV(apc_key, "$PMM$", prefix, key);

PHALCON_OBS_VAR(ttl);
phalcon_read_property_this(&ttl, this_ptr, SL("_ttl"), PH_NOISY_CC);
phalcon_read_property_this(&ttl, this_ptr, SL("_ttl"), PH_NOISY TSRMLS_CC);
PHALCON_CALL_FUNCTION_NORET("apc_store", apc_key, data, ttl);

PHALCON_MM_RESTORE();
}

PHP_METHOD(Phalcon_Mvc_Model_MetaData_Apc, reset)
{
zval *meta = phalcon_fetch_nproperty_this(this_ptr, SL("_metaData"), PH_NOISY TSRMLS_CC);
zval *real_key = NULL;

PHALCON_MM_GROW();

if (Z_TYPE_P(meta) == IS_ARRAY) {
HashTable *ht = Z_ARRVAL_P(meta);
HashPosition hp;
zval *prefix = phalcon_fetch_nproperty_this(this_ptr, SL("_prefix"), PH_NOISY TSRMLS_CC);

for (
zend_hash_internal_pointer_reset_ex(ht, &hp);
zend_hash_get_current_key_type_ex(ht, &hp) != HASH_KEY_NON_EXISTENT;
zend_hash_move_forward_ex(ht, &hp)
) {
zval key = phalcon_get_current_key_w(ht, &hp);

PHALCON_INIT_NVAR(real_key);
phalcon_concat_svsv(&real_key, SL("$PMM$"), prefix, SL("meta-"), &key, 0 TSRMLS_CC);
PHALCON_CALL_FUNCTION_NORET("apc_delete", real_key);
}
}

PHALCON_CALL_PARENT_NORET(phalcon_mvc_model_metadata_apc_ce, getThis(), "reset");
PHALCON_MM_RESTORE();
}
Loading