diff --git a/src/encode.c b/src/encode.c index 0d91af17ccda7e23ca986b0f0302a0ce238dac56..31a41abd96de343866bdcd84b9219cc0ab5173de 100644 --- a/src/encode.c +++ b/src/encode.c @@ -2,7 +2,7 @@ || This file is part of Pike. For copyright information see COPYRIGHT. || Pike is distributed under GPL, LGPL and MPL. See the file COPYING || for more information. -|| $Id: encode.c,v 1.293 2010/02/11 17:03:08 grubba Exp $ +|| $Id: encode.c,v 1.294 2010/07/01 11:25:18 grubba Exp $ */ #include "global.h" @@ -3572,7 +3572,7 @@ static void decode_value2(struct decode_data *data) decode_error(Pike_sp - 1, NULL, "Placeholder already has storage!\n"); } else { placeholder->storage=p->storage_needed ? - (char *)xalloc(p->storage_needed) : + (char *)xcalloc(p->storage_needed, 1) : (char *)NULL; call_c_initializers(placeholder); } @@ -4681,7 +4681,7 @@ static void decode_value2(struct decode_data *data) free_program(placeholder->prog); add_ref(placeholder->prog = p); placeholder->storage = p->storage_needed ? - (char *)xalloc(p->storage_needed) : + (char *)xcalloc(p->storage_needed, 1) : (char *)NULL; call_c_initializers(placeholder); if (!data->delay_counter) { diff --git a/src/object.c b/src/object.c index 95e436b91b1ba4cb4d4c733351fa38244a10f7e0..4cab48822c6d252bf7549ba8f51ce8a2fe68d7a0 100644 --- a/src/object.c +++ b/src/object.c @@ -2,7 +2,7 @@ || This file is part of Pike. For copyright information see COPYRIGHT. || Pike is distributed under GPL, LGPL and MPL. See the file COPYING || for more information. -|| $Id: object.c,v 1.308 2010/04/19 13:50:10 mast Exp $ +|| $Id: object.c,v 1.309 2010/07/01 11:25:18 grubba Exp $ */ #include "global.h" @@ -114,7 +114,7 @@ PMOD_EXPORT struct object *low_clone(struct program *p) o=alloc_object(); - o->storage=p->storage_needed ? (char *)xalloc(p->storage_needed) : (char *)NULL; + o->storage=p->storage_needed ? (char *)xcalloc(p->storage_needed, 1) : (char *)NULL; GC_ALLOC(o); @@ -236,6 +236,13 @@ PMOD_EXPORT void call_c_initializers(struct object *o) struct program *p=o->prog; struct pike_frame *pike_frame=0; int frame_pushed = 0; + + /* NOTE: This function is only called for objects straight after + * low_clone(), or after an explicit xcalloc(), which implies + * that the storage (if any) has been zeroed. + */ + + if (!p->storage_needed) return; /* clear globals and call C initializers */ for(e=p->num_inherits-1; e>=0; e--) @@ -258,20 +265,15 @@ PMOD_EXPORT void call_c_initializers(struct object *o) struct svalue *s; s=(struct svalue *)(storage + prog->identifiers[d].func.offset); s->type=T_INT; - s->u.integer=0; - s->subtype=0; - } else { +#ifdef NEED_CUSTOM_IEEE + } else if (prog->identifiers[d].run_time_type == T_FLOAT) { + /* Note: In IEEE representations the value 0.0 is represented as all + * zeros, and the default initialization is thus sufficient. + */ union anything *u; u=(union anything *)(storage + prog->identifiers[d].func.offset); - switch(prog->identifiers[d].run_time_type) - { - case PIKE_T_FREE: - case PIKE_T_GET_SET: - break; - case T_INT: u->integer=0; break; - case T_FLOAT: u->float_number=0.0; break; - default: u->refs=0; break; - } + u->float_number=0.0; +#endif /* NEED_CUSTOM_IEEE */ } (void) debug_malloc_update_location(o, DMALLOC_NAMED_LOCATION(" clear_global")); } diff --git a/src/program.c b/src/program.c index 3b161e59910c39e1632cc6cbd2a25fcf8a9672c7..3e7b2ff83c47ee17b24e4fb910f5315f49c2aed5 100644 --- a/src/program.c +++ b/src/program.c @@ -2,7 +2,7 @@ || This file is part of Pike. For copyright information see COPYRIGHT. || Pike is distributed under GPL, LGPL and MPL. See the file COPYING || for more information. -|| $Id: program.c,v 1.777 2010/05/19 09:32:22 grubba Exp $ +|| $Id: program.c,v 1.778 2010/07/01 11:25:21 grubba Exp $ */ #include "global.h" @@ -8262,7 +8262,7 @@ static int run_pass1(struct compilation *c) #endif debug_malloc_touch(c->placeholder); c->placeholder->storage=c->p->storage_needed ? - (char *)xalloc(c->p->storage_needed) : + (char *)xcalloc(c->p->storage_needed, 1) : (char *)NULL; call_c_initializers(c->placeholder); }