« first day (1746 days earlier)      last day (3196 days later) » 

11:00 PM
PHP_FUNCTION(getAtOffset) {
	HashTable* v1;
	zend_bool free_v1 = 0;
	long v2;
	ZEND_PARSE_PARAMETERS_START(2, 2)
		Z_PARAM_ARRAY_HT(v1)
		Z_PARAM_LONG(v2)
	ZEND_PARSE_PARAMETERS_END();
	zval v3;
l1:
	do {
		zval* tmp = zend_hash_index_find(v1, v2);
		if (tmp == NULL) {
			ZVAL_NULL(&v3);
			zend_error(E_NOTICE, "Uninitialized offset: %pd", v2);
		} else {
			ZVAL_COPY(&v3, tmp);
		}
	} while(0);
	RETURN_ZVAL(&v3, 1, 0);

}
 
okay, but then don't copy again in RETURN_ZVAL. (should be , 0, 0)
 
@bwoebi it should copy again, since it's stack allocated
 
@ircmaxell but the zval contents fetched from the array aren't.
ZVAL_COPY(&v3, tmp);
^^ or do `v3 = *tmp;` here.
the zval itself is on stack, the zend_array* or whatever the zval has a pointer to is on heap…
 
that's saner
done
 
@ircmaxell yeah. Just make attention then when you want a write fetch…
 
11:05 PM
it's in SSA mode, meaning that no var is written to more than once
 
@ircmaxell you mean, you duplicate the arrays on every write? (currently?)
 
the variable, yes
 
yeah, that's probably the issue with going directly off from SSA, that we need much more duplication…
 
yes, however GCC should be able to remove that for me
 
@ircmaxell yeah, but not for arrays where you copy the whole. If it's a zval, no problem… but big things like arrays?
 
11:10 PM
it's copying the pointer
 
but when you fetch from hashtable… oh, well… I think you'll see yourself soon enough anyway.
 
/**
 * @param int[] $array
 * @param int $offset
 * @return int
 */
function getAtOffset(array $array, int $offset) {
	return $array[$offset];
}
PHP_FUNCTION(getAtOffset) {
	HashTable* v1;
	zend_bool free_v1 = 0;
	long v2;
	ZEND_PARSE_PARAMETERS_START(2, 2)
		Z_PARAM_ARRAY_HT(v1)
		Z_PARAM_LONG(v2)
	ZEND_PARSE_PARAMETERS_END();
	long v3;
l1:
	do {
		zval* tmp = zend_hash_index_find(v1, v2);
		if (tmp == NULL) {
			v3 = 0;
			zend_error(E_NOTICE, "Uninitialized offset: %pd", v2);
		} else if (Z_TYPE_P(tmp) != IS_LONG) {
			zend_throw_error(NULL, "Offset is not an int: %pd", v2);
		} else {
			v3 = Z_LVAL_P(tmp);
		}
	} while(0);
	RETURN_LONG(v3);
@bwoebi ...?
 
@ircmaxell I'm not sure, maybe I just misunderstood something.
 
I don't expect array writing to work just yet
as long as reading works, I'm happy
 

« first day (1746 days earlier)      last day (3196 days later) »