Set type and value from zval. The source zval is copied and is otherwise not affected.
| 74 | // Set type and value from zval. The source zval is copied and is otherwise not |
| 75 | // affected. |
| 76 | void value_set_zval(engine_value *val, zval *src) { |
| 77 | int kind; |
| 78 | |
| 79 | // Determine concrete type from source zval. |
| 80 | switch (Z_TYPE_P(src)) { |
| 81 | case IS_NULL: kind = KIND_NULL; break; |
| 82 | case IS_LONG: kind = KIND_LONG; break; |
| 83 | case IS_DOUBLE: kind = KIND_DOUBLE; break; |
| 84 | case CASE_BOOL: kind = KIND_BOOL; break; |
| 85 | case IS_STRING: kind = KIND_STRING; break; |
| 86 | case IS_OBJECT: kind = KIND_OBJECT; break; |
| 87 | case IS_ARRAY: |
| 88 | kind = KIND_ARRAY; |
| 89 | HashTable *h = (Z_ARRVAL_P(src)); |
| 90 | |
| 91 | // Determine if array is associative or indexed. In the simplest case, a |
| 92 | // associative array will have different values for the number of elements |
| 93 | // and the index of the next free element. In cases where the number of |
| 94 | // elements and the next free index is equal, we must iterate through |
| 95 | // the hash table and check the keys themselves. |
| 96 | if (h->nNumOfElements != h->nNextFreeElement) { |
| 97 | kind = KIND_MAP; |
| 98 | break; |
| 99 | } |
| 100 | |
| 101 | unsigned long i = 0; |
| 102 | |
| 103 | for (zend_hash_internal_pointer_reset(h); i < h->nNumOfElements; i++) { |
| 104 | unsigned long index; |
| 105 | int type = HASH_GET_CURRENT_KEY(h, NULL, &index); |
| 106 | |
| 107 | if (type == HASH_KEY_IS_STRING || index != i) { |
| 108 | kind = KIND_MAP; |
| 109 | break; |
| 110 | } |
| 111 | |
| 112 | zend_hash_move_forward(h); |
| 113 | } |
| 114 | |
| 115 | break; |
| 116 | default: |
| 117 | errno = 1; |
| 118 | return; |
| 119 | } |
| 120 | |
| 121 | value_copy(val->internal, src); |
| 122 | val->kind = kind; |
| 123 | |
| 124 | errno = 0; |
| 125 | } |
| 126 | |
| 127 | // Set next index of array or map value. |
| 128 | void value_array_next_set(engine_value *arr, engine_value *val) { |
no test coverage detected