Fix VarPtr() behaviour.

[INTERPRETER]
* BUG: VarPtr() on local strings are forbidden again.
* BUG: VarPtr() on variants now returns a pointer to the variant contents.
This commit is contained in:
gambas 2020-02-18 20:36:45 +01:00
parent b8952bd393
commit 7bedc9af65

View File

@ -210,24 +210,16 @@ void SUBR_varptr(ushort code)
ptr = &val->_date.date;
break;
case T_STRING:
case T_CSTRING:
ptr = val->_string.addr + val->_string.start;
break;
case T_POINTER:
ptr = &val->_pointer.value;
break;
case T_VARIANT:
if (val->_variant.vtype == T_STRING)
ptr = val->_variant.value._string;
else
ptr = &val->_variant.value.data;
ptr = &val->_variant.value.data;
break;
default:
THROW(E_TYPE, "Number, date, pointer or string", TYPE_get_name(val->type));
THROW(E_TYPE, "Number, date, or pointer", TYPE_get_name(val->type));
}
}
else if ((op & 0xF800) == C_PUSH_DYNAMIC)
@ -238,11 +230,15 @@ void SUBR_varptr(ushort code)
THROW_ILLEGAL();
ptr = &OP[var->pos];
if (var->type.id == T_VARIANT)
ptr = &((VARIANT *)ptr)->value.data;
}
else if ((op & 0xF800) == C_PUSH_STATIC)
{
var = &CP->load->stat[op & 0x7FF];
ptr = (char *)CP->stat + var->pos;
if (var->type.id == T_VARIANT)
ptr = &((VARIANT *)ptr)->value.data;
}
else
THROW_ILLEGAL();