Branch: Tag:

2014-07-28

2014-07-28 13:09:42 by Per Hedbor <ph@opera.com>

Added a few OBJECT_CLEAR_ON_EXIT clears.

Images, String.Buffer objects and Gmp.mpz objects now honor the flag
for not only the object structure, but also the data in the object.

1031:      /* protected int(0..1) _is_type(string type)    */ - static void mpzmod__is_type(INT32 args) + static void mpzmod__is_type(INT32 UNUSED(args))   {    struct pike_string *int_t;    int is_int;
2239:    PUSH_REDUCED(res);   }    + #ifdef MPZ_T_HAS__MP_ALLOC + #define LIMBS(X) THIS->_mp_alloc + #else + #define LIMBS(X) mpz_size(THIS) + #endif +  +  + static void mpzmod__size_object(INT32 UNUSED(args)) + { +  push_int(LIMBS(THIS)*sizeof(mp_limb_t)+sizeof(mpz_t)); + } +    static void init_mpz_glue(struct object * UNUSED(o))   { - #ifdef PIKE_DEBUG -  if(!fp) Pike_fatal("ZERO FP\n"); -  if(!THIS) Pike_fatal("ZERO THIS\n"); - #endif +     mpz_init(THIS);   }      static void exit_mpz_glue(struct object *UNUSED(o))   { - #ifdef PIKE_DEBUG -  if(!fp) Pike_fatal("ZERO FP\n"); -  if(!THIS) Pike_fatal("ZERO THIS\n"); - #endif +  if( Pike_fp->current_object->flags & OBJECT_CLEAR_ON_EXIT ) +  memset( THIS->_mp_d, 0,LIMBS(THIS) * sizeof(mp_limb_t));    mpz_clear(THIS);   }      static void gc_recurse_mpz (struct object *o)   {    if (mc_count_bytes (o)) -  mc_counted_bytes += - #ifdef MPZ_T_HAS__MP_ALLOC -  THIS[0]._mp_alloc * sizeof (mp_limb_t) + - #else -  mpz_size (THIS) * sizeof (mp_limb_t) + - #endif -  sizeof (mpz_t); +  mc_counted_bytes += LIMBS(THIS)*sizeof (mp_limb_t) + sizeof (mpz_t);   } - #endif + #endif /* USE_GMP || defined(USE_GMP2) */      PIKE_MODULE_EXIT   {
2301:   #endif   }    -  +    static void *pike_mp_alloc (size_t alloc_size)   {    void *ret = malloc (alloc_size);
2397:    tFunc(tOr(tVoid,tInt) tOr(tVoid,tInt),tStr7), 0); \    ADD_FUNCTION("_sprintf", mpzmod__sprintf, tFunc(tInt tMapping,tStr), \    ID_PROTECTED); \ +  ADD_FUNCTION("_size_object",mpzmod__size_object, tFunc(tVoid,tInt),0);\    ADD_FUNCTION("size", mpzmod_size,tFunc(tOr(tVoid,tInt),tIntPos), 0); \    \    ADD_FUNCTION("cast_to_int",mpzmod_get_int,tFunc(tNone,tInt),0); \