diff --git a/src/constants.c b/src/constants.c index 818180f2e9b46ebbfe704388ef2745529d8c23ed..7aaac6f47b94013c36375b8da73d8a173498c1e5 100644 --- a/src/constants.c +++ b/src/constants.c @@ -15,7 +15,7 @@ #include "error.h" #include "block_alloc.h" -RCSID("$Id: constants.c,v 1.16 1999/04/08 23:54:26 hubbe Exp $"); +RCSID("$Id: constants.c,v 1.17 1999/04/15 04:08:09 hubbe Exp $"); static INT32 num_callable=0; static struct mapping *builtin_constants = 0; @@ -90,6 +90,14 @@ struct callable *low_make_callable(c_fun fun, f->flags=flags; f->docode=docode; f->optimize=optimize; +#ifdef PIKE_DEBUG + { + struct pike_string *z=check_call(function_type_string,type); + f->may_return_void= z == void_type_string; + if(!z) fatal("Gnapp!\n"); + free_string(z); + } +#endif return f; } diff --git a/src/constants.h b/src/constants.h index 6c5c49a11c46f05772bd8c9b79ba92efac6d1531..73ffd33a92d345c55192e87e87b108da83c2292a 100644 --- a/src/constants.h +++ b/src/constants.h @@ -5,7 +5,7 @@ \*/ /* - * $Id: constants.h,v 1.8 1999/02/10 21:46:40 hubbe Exp $ + * $Id: constants.h,v 1.9 1999/04/15 04:08:10 hubbe Exp $ */ #ifndef ADD_EFUN_H #define ADD_EFUN_H @@ -28,6 +28,9 @@ struct callable struct pike_string *type; struct pike_string *name; INT16 flags; +#ifdef PIKE_DEBUG + INT8 may_return_void; +#endif optimize_fun optimize; docode_fun docode; struct callable *next; diff --git a/src/docode.c b/src/docode.c index 1bad0e9152db3295bc4ea6e0d02efdf567856726..27afd985305447db0f30ee4d5b782f5db01c1d52 100644 --- a/src/docode.c +++ b/src/docode.c @@ -4,7 +4,7 @@ ||| See the files COPYING and DISCLAIMER for more information. \*/ #include "global.h" -RCSID("$Id: docode.c,v 1.45 1999/03/11 13:44:27 hubbe Exp $"); +RCSID("$Id: docode.c,v 1.46 1999/04/15 04:08:12 hubbe Exp $"); #include "las.h" #include "program.h" #include "language.h" @@ -676,7 +676,9 @@ static int do_docode2(node *n,int flags) !(CAR(n)->tree_info & OPT_EXTERNAL_DEPEND)); emit(F_APPLY,tmp1); } - if(n->type == void_type_string) return 0; + if(n->type == void_type_string) + return 0; + return 1; }else{ if(CAR(n)->u.sval.u.object == fake_object) diff --git a/src/dynamic_load.c b/src/dynamic_load.c index cedd5ae0efbc394287787a69670f27aa5105e5ad..84c63e292b910195a170e2d455c6c6a03f1c7f23 100644 --- a/src/dynamic_load.c +++ b/src/dynamic_load.c @@ -8,7 +8,7 @@ # include "pike_macros.h" # include "main.h" -RCSID("$Id: dynamic_load.c,v 1.34 1999/02/10 21:46:43 hubbe Exp $"); +RCSID("$Id: dynamic_load.c,v 1.35 1999/04/15 04:08:13 hubbe Exp $"); #endif /* !TESTING */ @@ -279,10 +279,20 @@ void f_load_module(INT32 args) new_module->init=init; new_module->exit=exit; - pop_n_elems(args); start_new_program(); +#ifdef PIKE_DEBUG + { struct svalue *save_sp=sp; +#endif (*(modfun)init)(); +#ifdef PIKE_DEBUG + if(sp != save_sp) + fatal("load_module(%s) left %d droppings on stack!\n", + module_name, + sp-save_sp); + } +#endif + pop_n_elems(args); push_program(end_program()); } diff --git a/src/interpret.c b/src/interpret.c index 99f785f6404524ad80d4ee49aa745b70e7f4f3f4..3d842e95998277eee403f2c51ad1821d44bb07bf 100644 --- a/src/interpret.c +++ b/src/interpret.c @@ -5,7 +5,7 @@ \*/ /**/ #include "global.h" -RCSID("$Id: interpret.c,v 1.119 1999/04/08 23:54:28 hubbe Exp $"); +RCSID("$Id: interpret.c,v 1.120 1999/04/15 04:08:14 hubbe Exp $"); #include "interpret.h" #include "object.h" #include "program.h" @@ -694,6 +694,7 @@ void mega_apply2(enum apply_type type, INT32 args, void *arg1, void *arg2) if(s->subtype == FUNCTION_BUILTIN) { #ifdef PIKE_DEBUG + struct svalue *expected_stack = sp-args; if(t_flag>1) { init_buf(); @@ -702,6 +703,25 @@ void mega_apply2(enum apply_type type, INT32 args, void *arg1, void *arg2) } #endif (*(s->u.efun->function))(args); + +#ifdef PIKE_DEBUG + if(sp != expected_stack + !s->u.efun->may_return_void) + { + if(sp < expected_stack) + fatal("Function popped too many arguments: %s\n", + s->u.efun->name->str); + if(sp>expected_stack+1) + fatal("Function left droppings on stack: %s\n", + s->u.efun->name->str); + if(sp == expected_stack && !s->u.efun->may_return_void) + fatal("Non-void function returned without return value on stack: %s %d\n", + s->u.efun->name->str,s->u.efun->may_return_void); + if(sp==expected_stack+1 && s->u.efun->may_return_void) + fatal("Void function returned with a value on the stack: %s %d\n", + s->u.efun->name->str, s->u.efun->may_return_void); + } +#endif + break; }else{ o=s->u.object; diff --git a/src/modules/Image/encodings/_xpm.c b/src/modules/Image/encodings/_xpm.c index 56931ce4e8541a6f2c8b1e3230c8bb3cd9144060..a04aeb13f67405edd7b9d96b1ac9541157e0f312 100644 --- a/src/modules/Image/encodings/_xpm.c +++ b/src/modules/Image/encodings/_xpm.c @@ -1,5 +1,5 @@ #include "global.h" -RCSID("$Id: _xpm.c,v 1.4 1999/04/09 23:18:21 per Exp $"); +RCSID("$Id: _xpm.c,v 1.5 1999/04/15 04:08:34 hubbe Exp $"); #include "config.h" @@ -400,6 +400,7 @@ void init_image__xpm( ) add_constant(s,sp-1,0); free_string(s); } + pop_stack(); } void exit_image__xpm(void) diff --git a/src/modules/Image/encodings/pcx.c b/src/modules/Image/encodings/pcx.c index 435f305f564d469966782f14f5a2234fce6a75ea..1a732bf309865b08014a3f8f9148ecb4fefe98e9 100644 --- a/src/modules/Image/encodings/pcx.c +++ b/src/modules/Image/encodings/pcx.c @@ -1,5 +1,5 @@ #include "global.h" -RCSID("$Id: pcx.c,v 1.4 1999/04/11 05:37:59 per Exp $"); +RCSID("$Id: pcx.c,v 1.5 1999/04/15 04:08:35 hubbe Exp $"); #include "config.h" @@ -599,6 +599,7 @@ void init_image_pcx( ) add_constant(s,sp-1,0); free_string(s); } + pop_stack(); opt_raw=make_shared_string("raw"); opt_dpy=make_shared_string("dpy"); opt_xdpy=make_shared_string("xdpy"); diff --git a/src/modules/Image/encodings/tga.c b/src/modules/Image/encodings/tga.c index 9fd7e6cf498fded7b26d179fd690a1dc06b0da31..46f2053159cb45e5fb3dd378ad00855e61721b7d 100644 --- a/src/modules/Image/encodings/tga.c +++ b/src/modules/Image/encodings/tga.c @@ -1,6 +1,6 @@ /* - * $Id: tga.c,v 1.4 1999/04/06 03:57:08 per Exp $ + * $Id: tga.c,v 1.5 1999/04/15 04:08:36 hubbe Exp $ * * Targa codec for pike. Based on the tga plugin for gimp. * @@ -72,7 +72,7 @@ #include "image.h" #include "colortable.h" -RCSID("$Id: tga.c,v 1.4 1999/04/06 03:57:08 per Exp $"); +RCSID("$Id: tga.c,v 1.5 1999/04/15 04:08:36 hubbe Exp $"); #ifndef MIN # define MIN(X,Y) ((X)<(Y)?(X):(Y)) @@ -946,6 +946,7 @@ void init_image_tga( ) add_constant(s,sp-1,0); free_string(s); } + pop_stack(); param_alpha=make_shared_string("alpha"); param_raw=make_shared_string("raw"); } diff --git a/src/modules/Image/encodings/xbm.c b/src/modules/Image/encodings/xbm.c index cad8b7b09c99a06039841034d5bfc25bfc98edb3..e5d2241b747d56e239dee9d1e96d774b3dc93290 100644 --- a/src/modules/Image/encodings/xbm.c +++ b/src/modules/Image/encodings/xbm.c @@ -1,5 +1,5 @@ #include "global.h" -RCSID("$Id: xbm.c,v 1.2 1999/04/12 11:41:14 mirar Exp $"); +RCSID("$Id: xbm.c,v 1.3 1999/04/15 04:08:38 hubbe Exp $"); #include "config.h" @@ -438,6 +438,7 @@ void init_image_xbm( ) add_constant(s,sp-1,0); free_string(s); } + pop_stack(); param_name=make_shared_string("name"); param_fg=make_shared_string("fg"); param_bg=make_shared_string("bg"); diff --git a/src/modules/Image/encodings/xcf.c b/src/modules/Image/encodings/xcf.c index 546ba99ab27f53826c513f8e17338b4e8b6b8b18..5c16c5bcc2ae54662d58dc2360bc4cbc03107013 100644 --- a/src/modules/Image/encodings/xcf.c +++ b/src/modules/Image/encodings/xcf.c @@ -1,5 +1,5 @@ #include "global.h" -RCSID("$Id: xcf.c,v 1.6 1999/04/13 12:32:47 mirar Exp $"); +RCSID("$Id: xcf.c,v 1.7 1999/04/15 04:08:39 hubbe Exp $"); #include "config.h" @@ -1320,6 +1320,7 @@ void init_image_xcf() add_constant(s,sp-1,0); free_string(s); } + pop_stack(); #define STRING(X) s_##X = make_shared_binary_string(#X,sizeof( #X )-sizeof("")); #include "xcf_constant_strings.h" #undef STRING diff --git a/src/opcodes.c b/src/opcodes.c index 14ab7ceb8bd9bcb892ce99ebb0b2bebb97a1f269..9bb62807c4aec21ab71ef2259b427d8b7a5d87d1 100644 --- a/src/opcodes.c +++ b/src/opcodes.c @@ -23,7 +23,7 @@ #include "module_support.h" #include "security.h" -RCSID("$Id: opcodes.c,v 1.36 1999/04/13 20:10:08 hubbe Exp $"); +RCSID("$Id: opcodes.c,v 1.37 1999/04/15 04:08:15 hubbe Exp $"); void index_no_free(struct svalue *to,struct svalue *what,struct svalue *ind) { @@ -527,6 +527,8 @@ void f_cast(void) { #ifdef PIKE_DEBUG struct svalue *save_sp=sp; + if(sp[-2].type != T_STRING) + fatal("Cast expression destroyed stack or left droppings!\n"); #endif o_cast(sp[-2].u.string, compile_type_to_runtime_type(sp[-2].u.string));