From a72e63f759e98fc57cec030ff2248991e8980d57 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Grubbstr=C3=B6m=20=28Grubba=29?= <grubba@grubba.org> Date: Thu, 1 Jul 2010 13:25:21 +0200 Subject: [PATCH] Allocate object storage with xcalloc() to reduce the amount of work for call_c_initializers(). Rev: src/encode.c:1.294 Rev: src/object.c:1.309 Rev: src/program.c:1.778 --- src/encode.c | 6 +++--- src/object.c | 30 ++++++++++++++++-------------- src/program.c | 4 ++-- 3 files changed, 21 insertions(+), 19 deletions(-) diff --git a/src/encode.c b/src/encode.c index 0d91af17cc..31a41abd96 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 95e436b91b..4cab48822c 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 3b161e5991..3e7b2ff83c 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); } -- GitLab