-------------------------------------------------------------------------------------------
|if((_compare_p_a_wo_p_a_wo(_decoded_ustring_7,((unsigned short *)0))==0))
|{
|_code_3=3;
|}
-------------------------------------------------------------------------------------------
The first is called as a function (is nil), but is written inline, as we would except "xxx == nil" to be written. And if we write "xxx == nil", it calls a function, try to access a memory area pointed to by a nul pointer.... and then the crash.
The code which is called when "xxx == nil" occurs in a Zinc source code:
-------------------------------------------------------------------------------------------
|static int _compare_p_a_wo_p_a_wo(unsigned short *_s1, unsigned short *_s2)
|{
|unsigned short _c_1;
|while(1)
|{
|_c_1=(_s1[0]);
|if((_c_1!=(_s2[0])))
|{
|break;
|}
|if((_c_1==((unsigned short)0)))
|{
|break;
|}
|(++_s1);
|(++_s2);
|}
|return ((int )((char )(_c_1-(_s2[0]))));
|}
-------------------------------------------------------------------------------------------
Strange behaviour... isn't it ?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Halo,
I've meet a bug with Zinc. A source written with "if xxx == nil" comit a crash, while writing
"if is nil (xxx)" is ok.
Here is an exemple of what Zinc do when using "is nil (xxx)" :
-------------------------------------------------------------------------------------------
| if(((void*)_decoded_ustring_7==(void*)0))
| {
| _code_3=3;
| }
-------------------------------------------------------------------------------------------
And now here is what is do with "xxx == nil"
-------------------------------------------------------------------------------------------
|if((_compare_p_a_wo_p_a_wo(_decoded_ustring_7,((unsigned short *)0))==0))
|{
|_code_3=3;
|}
-------------------------------------------------------------------------------------------
The first is called as a function (is nil), but is written inline, as we would except "xxx == nil" to be written. And if we write "xxx == nil", it calls a function, try to access a memory area pointed to by a nul pointer.... and then the crash.
The code which is called when "xxx == nil" occurs in a Zinc source code:
-------------------------------------------------------------------------------------------
|static int _compare_p_a_wo_p_a_wo(unsigned short *_s1, unsigned short *_s2)
|{
|unsigned short _c_1;
|while(1)
|{
|_c_1=(_s1[0]);
|if((_c_1!=(_s2[0])))
|{
|break;
|}
|if((_c_1==((unsigned short)0)))
|{
|break;
|}
|(++_s1);
|(++_s2);
|}
|return ((int )((char )(_c_1-(_s2[0]))));
|}
-------------------------------------------------------------------------------------------
Strange behaviour... isn't it ?
It's not a bug, it's a feature ;-)
'is nil (x)' is a builtin function to check a null pointer.
But the '==' operator is overridable just like in C++ and is overridden
for the string type in string.zc:
public equ @equal (s1: string, s2: string) = compare (s1, s2) == 0
Is there a built in function to allocate memory on the stack ?
Do you mean a alloca() C equivalent ? no there isn't, but it could be easily exposed (today, zinc just generates C source).