Branch: Tag:

2014-06-24

2014-06-24 14:31:50 by Henrik Grubbström (Grubba) <grubba@grubba.org>

Runtime: Unified struct svalue and struct fast_svalue.

Modern gcc (4.7.3) had aliasing problems with the two structs, which
caused changes performed with SET_SVAL() (which used struct fast_svalue)
to not be reflected in TYPEOF() (which used struct svalue). This in turn
caused eg casts of integers to floats to fail with "Cast failed, wanted
float, got int".

The above problem is now solved by having an actual union for the type
fields in struct svalue. This has the additional benefit of forcing
all code to use the svalue macros.

NB: This code change will cause problems with compilers that don't
support union initializers.

270:      #define push_program(P) do{ \    struct program *_=(P); \ -  struct svalue *_sp_ = (struct svalue*)Pike_sp++; \ +  struct svalue *_sp_ = Pike_sp++; \    debug_malloc_touch(_); \    SET_SVAL_TYPE_SUBTYPE_CHECKER(*_sp_, PIKE_T_PROGRAM,0); \    _sp_->u.program=_; \
278:      #define push_int(I) do{ \    INT_TYPE _=(I); \ -  struct fast_svalue *_sp_ = (struct fast_svalue*)Pike_sp++; \ +  struct svalue *_sp_ = Pike_sp++; \    SET_SVAL_TYPE_SUBTYPE(*_sp_, PIKE_T_INT,NUMBER_NUMBER); \    _sp_->u.integer=_; \    }while(0)      #define push_undefined() do{ \ -  struct fast_svalue *_sp_ = (struct fast_svalue*)Pike_sp++; \ +  struct svalue *_sp_ = Pike_sp++; \    SET_SVAL_TYPE_SUBTYPE(*_sp_, PIKE_T_INT,NUMBER_UNDEFINED); \    _sp_->u.integer=0; \    }while(0)
324:      #define push_string(S) do { \    struct pike_string *_=(S); \ -  struct fast_svalue *_sp_ = (struct fast_svalue*)Pike_sp++; \ +  struct svalue *_sp_ = Pike_sp++; \    debug_malloc_touch(_); \    DO_IF_DEBUG(if(_->size_shift & ~3) { \    Pike_fatal("Pushing string with bad shift: %d\n", \
348:      #define push_object_inherit(O, INH_NUM) do { \    struct object *_ = (O); \ -  struct fast_svalue *_sp_ = (struct fast_svalue*)Pike_sp++; \ +  struct svalue *_sp_ = Pike_sp++; \    int _inh_ = (INH_NUM); \    debug_malloc_touch(_); \    SET_SVAL_TYPE_SUBTYPE(*_sp_, PIKE_T_OBJECT,_inh_); \
365:   PMOD_EXPORT extern void push_text( const char *x );      #define push_constant_text(T) do{ \ -  struct fast_svalue *_sp_ = (struct fast_svalue*)Pike_sp++; \ +  struct svalue *_sp_ = Pike_sp++; \    SET_SVAL_TYPE_SUBTYPE(*_sp_, PIKE_T_STRING,0); \    REF_MAKE_CONST_STRING(_sp_->u.string,T); \    }while(0)
378:      #define push_function(OBJ, FUN) do { \    struct object *_=(OBJ); \ -  struct fast_svalue *_sp_ = (struct fast_svalue*)Pike_sp++; \ +  struct svalue *_sp_ = Pike_sp++; \    debug_malloc_touch(_); \    SET_SVAL_TYPE_SUBTYPE(*_sp_, PIKE_T_FUNCTION,(FUN)); \    _sp_->u.object=_; \
418:      #define ref_push_string(S) do{ \    struct pike_string *_=(S); \ -  struct fast_svalue *_sp_ = (struct fast_svalue*)Pike_sp++; \ +  struct svalue *_sp_ = Pike_sp++; \    DO_IF_DEBUG(if(_->size_shift & ~3) { \    Pike_fatal("Pushing string with bad shift: %d\n", \    _->size_shift); \
430:      #define ref_push_type_value(S) do{ \    struct pike_type *_=(S); \ -  struct fast_svalue *_sp_ = (struct fast_svalue*)Pike_sp++; \ +  struct svalue *_sp_ = Pike_sp++; \    add_ref(_); \    SET_SVAL_TYPE_SUBTYPE(*_sp_, PIKE_T_TYPE,0); \    _sp_->u.type=_; \
440:      #define ref_push_object_inherit(O, INH_NUM) do{ \    struct object *_ = (O); \ -  struct fast_svalue *_sp_ = (struct fast_svalue*)Pike_sp++; \ +  struct svalue *_sp_ = Pike_sp++; \    add_ref(_); \    SET_SVAL_TYPE_SUBTYPE(*_sp_, PIKE_T_OBJECT, (INH_NUM)); \    _sp_->u.object = _; \
448:      #define ref_push_function(OBJ, FUN) do { \    struct object *_=(OBJ); \ -  struct fast_svalue *_sp_ = (struct fast_svalue*)Pike_sp++; \ +  struct svalue *_sp_ = Pike_sp++; \    add_ref(_); \    SET_SVAL_TYPE_SUBTYPE(*_sp_, PIKE_T_FUNCTION,(FUN)); \    _sp_->u.object=_; \
477:    } while(0);   #else   #define push_zeroes(N) do{ \ -  struct fast_svalue *s_=(struct fast_svalue*)Pike_sp; \ +  struct svalue *s_ = Pike_sp; \    ptrdiff_t num_= (N); \    for(;num_-- > 0;s_++) \    { \
489:   #endif      #define push_undefines(N) do{ \ -  struct fast_svalue *s_=(struct fast_svalue*)Pike_sp; \ +  struct svalue *s_ = Pike_sp; \    ptrdiff_t num_= (N); \    for(;num_-- > 0;s_++) \    { \