diff options
author | Martijn Otto <martijn.otto@copernica.com> | 2016-05-11 17:34:40 +0200 |
---|---|---|
committer | Martijn Otto <martijn.otto@copernica.com> | 2016-05-11 17:34:40 +0200 |
commit | 9f2e816c787c30ceeb139623c8dae594c4b4443d (patch) | |
tree | e434ebd2ff37c98bdc5934120b48cda1bf3899c2 /zend/traverseiterator.h | |
parent | 570590058d16274005a4994fd8f1046d0eaf7f74 (diff) |
Work in progress on PHP7 compatibility
Diffstat (limited to 'zend/traverseiterator.h')
-rw-r--r-- | zend/traverseiterator.h | 93 |
1 files changed, 29 insertions, 64 deletions
diff --git a/zend/traverseiterator.h b/zend/traverseiterator.h index a65f909..27c4832 100644 --- a/zend/traverseiterator.h +++ b/zend/traverseiterator.h @@ -30,20 +30,20 @@ public: { // leap out if this iterator starts at the end if (!begin) return; - + // we need the class entry - auto *entry = zend_get_class_entry(object TSRMLS_CC); - + auto *entry = Z_OBJCE_P(object); + // create the iterator _iter = entry->get_iterator(entry, object, false TSRMLS_CC); - + // rewind the iterator _iter->funcs->rewind(_iter TSRMLS_CC); - + // read the first key/value pair read(TSRMLS_C); } - + /** * Copy constructor * @param that @@ -54,7 +54,7 @@ public: // @todo this is a broken implementation, the copy is at the start // position, while we'd like to be at the same position } - + /** * Destructor */ @@ -62,10 +62,10 @@ public: { // do nothing if iterator is already invalid if (!_iter) return; - + // we need the tsrm pointer TSRMLS_FETCH(); - + // call the iterator destructor if (_iter) _iter->funcs->dtor(_iter TSRMLS_CC); } @@ -79,7 +79,7 @@ public: { // we need the tsrm_ls variable TSRMLS_FETCH(); - + // construct iterator return new TraverseIterator(*this TSRMLS_CC); } @@ -96,17 +96,17 @@ public: // we need the tsrm_ls variable TSRMLS_FETCH(); - + // movw it forward _iter->funcs->move_forward(_iter TSRMLS_CC); - + // and read current data read(TSRMLS_C); - + // done return true; } - + /** * Decrement position (pre-decrement) * @return bool @@ -115,7 +115,7 @@ public: { // not possible with PHP iterators throw Exception("Impossible to iterate backwards"); - + // unreachable return false; } @@ -129,13 +129,13 @@ public: { // of course if the objects are identical if (this == that) return true; - + // cast to traverse-iterator TraverseIterator *other = (TraverseIterator *)that; - + // if both objects are in an invalid state we consider them to be identical if (!_iter && !other->_iter) return true; - + // although the iterators could be at the same pos, for simplicity // we consider them different here return false; @@ -156,7 +156,7 @@ private: * @var _val */ zval *_object = nullptr; - + /** * The iterator from Zend * @var zend_object_iterator @@ -183,60 +183,25 @@ private: // is the iterator at a valid position? if (_iter->funcs->valid(_iter TSRMLS_CC) == FAILURE) return invalidate(TSRMLS_C); -#if PHP_VERSION_ID >= 50500 - // create a value object Value val; - + // call the function to get the key _iter->funcs->get_current_key(_iter, val._val TSRMLS_CC); - + // store the key _data.first = val; -#else - - // variable we need for fetching the key, and that will be assigned by - // the PHP engine (this is php 5.3 code) - char *str_key; unsigned int str_key_len; unsigned long int_key; - - // php 5.4 or php 5.3 code, fetch the current key - int type = _iter->funcs->get_current_key(_iter, &str_key, &str_key_len, &int_key TSRMLS_CC); - - // what sort of key do we have? - if (type == HASH_KEY_IS_LONG) - { - // we have an int key - _data.first = (int64_t)int_key; - } - else - { - // we have a string key that is already allocated - _data.first = str_key; - - // deallocate the data - efree(str_key); - } - -#endif - - // now we're going to fetch the value, for this we need a strange zval - // it is strange that this is a pointer-to-pointer, but that is how - // the Zend engine implements this. It is going to be filled with - // a pointer to a memory address that is guaranteed to hold a valid - // zval. - zval **zval; - // get the current value - _iter->funcs->get_current_data(_iter, &zval TSRMLS_CC); - + auto *zval = _iter->funcs->get_current_data(_iter); + // wrap the zval in a value object - _data.second = Value(*zval); - + _data.second = Value(zval); + // done return true; } - + /** * Invalidate the object * @param tsrm_ls @@ -246,13 +211,13 @@ private: { // skip if already invalid if (!_iter) return false; - + // reset the iterator _iter->funcs->dtor(_iter TSRMLS_CC); - + // set back to null _iter = nullptr; - + // done return false; } |