I'm looking at init_string_assignment_storage() in operators.c that initialized the object used when assigning individual characters in a string. Since the object is created with low_clone() the C init function is never called, so this code is currently not active.
Since the object storage is zeroed, not calling the initializer is typically fine, but this initializer does
SET_SVAL(THIS->lval[0], T_INT, PIKE_T_FREE, integer, 0);
where PIKE_T_FREE isn't 0, so enabling this code would make a difference.
However, all uses of PIKE_T_FREE in svalue.c looks for TYPEOF(x)==PIKE_T_FREE, not SUBTYPEOF(x). What is the desired behaviour here?
A related question is if we should disable all init-code that just sets storage fields to 0/NULL?
A NULL pointer does not necessarily have a binary representation that is all zeroes, so removal of 0/NULL settings for pointer types should be guarded with a configure test.
Is there an example of this in practice?
Yes, but I don't remember one of the top of my head. Usually some kind of pointer tagging is involved when this happens.
Affter all, NULL==(void*)0;
Yes, but the type conversion is allowed to change the bitpattern, just like
1==(int)1.0
does not guarantee that the bit pattern for floating 1.0 is the same as for integer 1 (hint: it isn't).
On second thought, even if the bit pattern is different, it wouldn't matter when the practical uses are only THIS->x==NULL and !THIS->x, where 0 and NULL are interchangable as x.
Yes it would. If x is a pointer type, then THIS->x=0 and THIS->x=NULL will both store the bit pattern for a NULL pointer of the correct type in x, whereas memset(THIS, 0, sizeof(*THIS)) whould store a bit pattern of all zeroes in x. Only the former would compare equal to NULL/0 (!x is equivalent to x==0), because in the comparison the NULL/0 would be converted to a pointer of the correct type and only then the bit patterns compared. (See §6.5.9:5.)
| Bit pattern | THIS->x==NULL | !THIS->x | ----------------------------+-------------+---------------+----------+ THIS->x=0 | XXXXXXXX | TRUE | TRUE | THIS->x=NULL | XXXXXXXX | TRUE | TRUE | memset(THIS,0,sizeof(*THIS) | 00000000 | FALSE | FALSE |
pike-devel@lists.lysator.liu.se