diff --git a/src/encode.c b/src/encode.c index b6ef32a87f536b2de083cadd41063fc3d770141e..72fd2e0f7a3b36d1f6633d0e63a4699d21a27709 100644 --- a/src/encode.c +++ b/src/encode.c @@ -1099,149 +1099,6 @@ static void encode_value2(struct svalue *val, struct encode_data *data, int forc } } -#ifdef OLD_PIKE_ENCODE_PROGRAM - - EDB(1, - fprintf(stderr, "%*sencode: encoding program in old style\n", - data->depth, "")); - - /* Type 1 -- Old-style encoding. */ - - code_entry(TAG_PROGRAM, 1, data); - push_compact_version(); - encode_value2(Pike_sp-1,data, 0); - pop_stack(); - code_number(p->flags,data); - code_number(p->storage_needed,data); - code_number(p->xstorage,data); /**/ - code_number(p->parent_info_storage,data); /**/ - - code_number(p->alignment_needed,data); - code_number(p->timestamp.tv_sec,data); - code_number(p->timestamp.tv_usec,data); - - if(p->parent) - ref_push_program(p->parent); - else - push_int(0); - encode_value2(Pike_sp-1,data, 0); /**/ - pop_stack(); - -#define FOO(NUMTYPE,TYPE,ARGTYPE,NAME) \ - code_number( p->PIKE_CONCAT(num_,NAME), data); -#include "program_areas.h" - - code_number(PIKE_BYTECODE_METHOD, data); - -#ifdef ENCODE_PROGRAM -#ifdef PIKE_DEBUG - { - ptrdiff_t bufpos = data->buf.s.len; -#endif /* PIKE_DEBUG */ - ENCODE_PROGRAM(p, &(data->buf)); -#ifdef PIKE_DEBUG - if (p->num_program * sizeof(p->program[0]) != - data->buf.s.len - bufpos) { - Pike_fatal("ENCODE_PROGRAM() failed:\n" - "Encoded data len: %ld\n" - "Expected data len: %ld\n", - DO_NOT_WARN((long)(p->num_program * sizeof(p->program[0]))), - DO_NOT_WARN((long)(data->buf.s.len - bufpos))); - } - } -#endif /* PIKE_DEBUG */ -#else /* !ENCODE_PROGRAM */ - adddata2(p->program, p->num_program); -#endif /* ENCODE_PROGRAM */ - - adddata2(p->relocations, p->num_relocations); - - adddata2(p->linenumbers, p->num_linenumbers); - - for(d=0;d<p->num_identifier_index;d++) - code_number(p->identifier_index[d],data); - - for(d=0;d<p->num_variable_index;d++) - code_number(p->variable_index[d],data); - - for(d=0;d<p->num_identifier_references;d++) - { - code_number(p->identifier_references[d].inherit_offset,data); - code_number(p->identifier_references[d].identifier_offset,data); - code_number(p->identifier_references[d].id_flags,data); - EDB(3,fprintf(stderr,"IDREF%x > %d: { %d, %d, %d }\n", - p->id,d, - p->identifier_references[d].inherit_offset, - p->identifier_references[d].identifier_offset, - p->identifier_references[d].id_flags);); - } - - for(d=0;d<p->num_strings;d++) adddata(p->strings[d]); - - for(d=0;d<p->num_inherits;d++) - { - code_number(p->inherits[d].inherit_level,data); - code_number(p->inherits[d].identifier_level,data); - code_number(p->inherits[d].parent_offset,data); - code_number(p->inherits[d].parent_identifier,data); - code_number(p->inherits[d].storage_offset,data); - - if(p->inherits[d].parent) - { - ref_push_function(p->inherits[d].parent, - p->inherits[d].parent_identifier); - EDB(3,fprintf(stderr,"INHERIT%x coded as func { %p, %d }\n", - p->id, p->inherits[d].parent, - p->inherits[d].parent_identifier);); - }else if(p->inherits[d].prog){ - ref_push_program(p->inherits[d].prog); - }else{ - Pike_error("Failed to encode inherit #%d\n", d); - push_int(0); - } - encode_value2(Pike_sp-1,data, 1); - pop_stack(); - - adddata3(p->inherits[d].name); - - EDB(3,fprintf(stderr,"INHERIT%x > %d: %d id=%d\n", - p->id,d, - p->inherits[d].prog->num_identifiers, - p->inherits[d].prog->id);); - } - - for(d=0;d<p->num_identifiers;d++) - { - adddata(p->identifiers[d].name); - encode_type(p->identifiers[d].type, data); - code_number(p->identifiers[d].identifier_flags,data); - code_number(p->identifiers[d].run_time_type,data); - code_number(p->identifiers[d].opt_flags,data); - code_number(p->identifiers[d].filename_strno, data); - code_number(p->identifiers[d].linenumber, data); - if (IDENTIFIER_IS_ALIAS(p->identifiers[d].identifier_flags)) { - code_number(p->identifiers[d].func.ext_ref.depth,data); - code_number(p->identifiers[d].func.ext_ref.id,data); - } else if (!IDENTIFIER_IS_C_FUNCTION(p->identifiers[d].identifier_flags)) { - code_number(p->identifiers[d].func.offset,data); - } else { - Pike_error("Cannot encode functions implemented in C " - "(identifier=\"%S\").\n", - p->identifiers[d].name); - } - } - - for(d=0;d<NUM_LFUNS;d++) - code_number(p->lfuns[d], data); - - for(d=0;d<p->num_constants;d++) - { - encode_value2(& p->constants[d].sval, data, 0); - adddata3(NULL /* p->constants[d].name */); - } - -#else /* !OLD_PIKE_ENCODE_PROGRAM */ - /* Portable encoding (4 and 5). */ if (!force_encode) { @@ -1933,7 +1790,6 @@ static void encode_value2(struct svalue *val, struct encode_data *data, int forc #endif /* 0 */ } } -#endif /* OLD_PIKE_ENCODE_PROGRAM */ }else{ code_entry(TAG_PROGRAM, 0, data); encode_value2(Pike_sp-1, data, 0); @@ -3258,623 +3114,7 @@ static void decode_value2(struct decode_data *data) case 1: /* Old-style encoding. */ { - int d, in; - size_t size=0; - char *dat=0; - struct program *p; - struct object *placeholder=0; - ONERROR err, err1, err2, err3, err4; - - lock_pike_compiler(); - SET_ONERROR(err, unlock_pike_compiler, 0); - - fprintf (stderr, "Warning: Using old-style encoding\n"); - - EDB(2,fprintf(stderr, "%*sDecoding a program to <%d>: ", - data->depth, "", entry_id.u.integer); - print_svalue(stderr, &entry_id); - fputc('\n', stderr);); - - SETUP_DECODE_MEMOBJ(T_PROGRAM, program, p, low_allocate_program(),;); - - debug_malloc_touch(p); - SET_ONERROR(err3, zap_unfinished_program, p); - - if(data->pass == 1) - { -#if TWO_PASS_DECODE_WORKS - if(! data->supporter.prog) - data->supporter.prog = p; -#endif - - debug_malloc_touch(p); - ref_push_program(p); - apply(decoder_codec (data), "__register_new_program", 1); - - /* return a placeholder */ - if(TYPEOF(Pike_sp[-1]) == T_OBJECT) - { - placeholder=Pike_sp[-1].u.object; - if(placeholder->prog != null_program) - decode_error(data, NULL, "Placeholder object is not " - "a __null_program clone.\n"); - dmalloc_touch_svalue(Pike_sp-1); - Pike_sp--; - } - else if (TYPEOF(Pike_sp[-1]) != T_INT || - Pike_sp[-1].u.integer) - decode_error (data, NULL, "Expected placeholder object or zero " - "from __register_new_program.\n"); - else { - pop_stack(); - } - } - - if(placeholder) - SET_ONERROR(err4, zap_placeholder, placeholder); - - decode_value2(data); - push_compact_version(); - if(!is_eq(Pike_sp-1,Pike_sp-2) -#ifdef ENCODE_DEBUG - && !data->debug -#endif - ) - decode_error(data, NULL, "Cannot decode programs encoded " - "with other pike version %O.\n", Pike_sp - 2); - pop_n_elems(2); - -#ifdef ENCODE_DEBUG - if (!data->debug) -#endif - data->pickyness++; - - debug_malloc_touch(p); - decode_number(p->flags,data); - - if(data->pass == 1) - { - p->flags &= ~(PROGRAM_FINISHED | PROGRAM_OPTIMIZED | - PROGRAM_FIXED | PROGRAM_PASS_1_DONE); - p->flags |= PROGRAM_AVOID_CHECK; - } - decode_number(p->storage_needed,data); - decode_number(p->xstorage,data); - decode_number(p->parent_info_storage,data); - decode_number(p->alignment_needed,data); - decode_number(p->timestamp.tv_sec,data); - decode_number(p->timestamp.tv_usec,data); - - if(data->pass && p->parent) - { - free_program(p->parent); - p->parent=0; - } - - debug_malloc_touch(p); - decode_value2(data); - switch(TYPEOF(Pike_sp[-1])) - { - case T_INT: - p->parent=0; - break; - case T_PROGRAM: - p->parent=Pike_sp[-1].u.program; - break; - case T_FUNCTION: - p->parent=program_from_svalue(Pike_sp-1); - break; - default: - if (data->pickyness) - decode_error(data, NULL, "Program decode failed. Got: %O\n", - Pike_sp - 1); - p->parent = 0; - break; - } - if(p->parent) { - add_ref(p->parent); - } - pop_stack(); - - debug_malloc_touch(p); - -#define FOO(NUMTYPE,TYPE,ARGTYPE,NAME) \ - decode_number( p->PIKE_CONCAT(num_,NAME), data); -#include "program_areas.h" - - - if(data->pass == 1) - { - int overflow = 0; - size_t tmp = 0; -#ifdef PIKE_USE_MACHINE_CODE - /* We want our program to be in mexec-allocated memory... */ -#define BAR(NUMTYPE,TYPE,ARGTYPE,NAME) -#endif /* PIKE_USE_MACHINE_CODE */ -#define FOO(NUMTYPE,TYPE,ARGTYPE,NAME) \ - if (size) { \ - size=DO_ALIGN(size, ALIGNOF(TYPE)); \ - overflow |= !size; \ - } \ - overflow |= DO_SIZE_T_MUL_OVERFLOW(sizeof(p->NAME[0]), p->PIKE_CONCAT(num_,NAME), &tmp)\ - | DO_SIZE_T_ADD_OVERFLOW(size, tmp, &size); -#include "program_areas.h" - - if (overflow) - decode_error(data, NULL, "Program area sizes overflowed.\n"); - - dat=xalloc(size); - debug_malloc_touch(dat); - MEMSET(dat,0,size); - size=0; -#ifdef PIKE_USE_MACHINE_CODE - /* We want our program to be in mexec-allocated memory... */ -#define BAR(NUMTYPE,TYPE,ARGTYPE,NAME) \ - if (DO_SIZE_T_MUL_OVERFLOW(p->PIKE_CONCAT(num_, NAME), sizeof(p->NAME[0]), &tmp))\ - decode_error(data, NULL, "Program area sizes overflowed.\n");\ - p->NAME = (TYPE *)mexec_alloc(tmp); -#endif /* PIKE_USE_MACHINE_CODE */ -#define FOO(NUMTYPE,TYPE,ARGTYPE,NAME) \ - size=DO_ALIGN(size, ALIGNOF(TYPE)); \ - p->NAME=(TYPE *)(dat+size); \ - size+=p->PIKE_CONCAT(num_,NAME)*sizeof(p->NAME[0]); -#include "program_areas.h" - - for(e=0;e<p->num_constants;e++) - mark_free_svalue (&p->constants[e].sval); - - debug_malloc_touch(dat); - debug_malloc_touch(p); - - p->total_size=size + sizeof(struct program); - - p->flags |= PROGRAM_OPTIMIZED; - } - - { - INT32 bytecode_method = 0; - decode_number(bytecode_method, data); - if (bytecode_method != PIKE_BYTECODE_METHOD) { - decode_error(data, NULL, - "Unsupported byte-code method: %d. Expected %d\n", - bytecode_method, PIKE_BYTECODE_METHOD); - } - } - - getdata2(p->program, p->num_program); - getdata2(p->relocations, p->num_relocations); - -#ifdef DECODE_PROGRAM - { - int byteorder = PIKE_BYTEORDER; /* FIXME: Used by bytecode.h */ - DECODE_PROGRAM(p); - } -#endif /* DECODE_PROGRAM */ - make_program_executable(p); - - getdata2(p->linenumbers, p->num_linenumbers); - - /* Now with the linenumber info in place it gets useful to - * include the program in error messages. */ - -#ifdef DEBUG_MALLOC - if(p->num_linenumbers && p->linenumbers && - EXTRACT_UCHAR(p->linenumbers)==127) - { - char *foo = p->linenumbers + 1; - int len = get_small_number(&foo); - int shift = *foo; - char *fname = ++foo; - foo += len << shift; - get_small_number(&foo); /* pc offset */ - /* FIXME: Dmalloc doesn't support wide filenames. */ - debug_malloc_name(p, fname, get_small_number(&foo)); - } -#endif - - - debug_malloc_touch(p); - for(d=0;d<p->num_identifier_index;d++) - { - decode_number(p->identifier_index[d],data); - if(p->identifier_index[d] > p->num_identifier_references) - { - p->identifier_index[d]=0; - ref_push_program (p); - decode_error(data, Pike_sp - 1, "Malformed program in decode.\n"); - } - } - - debug_malloc_touch(p); - for(d=0;d<p->num_variable_index;d++) - { - decode_number(p->variable_index[d],data); - if(p->variable_index[d] > p->num_identifiers) - { - p->variable_index[d]=0; - ref_push_program (p); - decode_error(data, Pike_sp - 1, "Malformed program in decode.\n"); - } - } - - debug_malloc_touch(p); - for(d=0;d<p->num_identifier_references;d++) - { - decode_number(p->identifier_references[d].inherit_offset,data); - if(p->identifier_references[d].inherit_offset > p->num_inherits) - { - p->identifier_references[d].inherit_offset=0; - ref_push_program (p); - decode_error(data, Pike_sp - 1, "Malformed program in decode.\n"); - } - decode_number(p->identifier_references[d].identifier_offset,data); - decode_number(p->identifier_references[d].id_flags,data); - - EDB(3,fprintf(stderr,"IDREF%x < %d: { %d, %d, %d }\n", - p->id,d, - p->identifier_references[d].inherit_offset, - p->identifier_references[d].identifier_offset, - p->identifier_references[d].id_flags); ); - } - - debug_malloc_touch(p); - for(d=0;d<p->num_strings;d++) - getdata(p->strings[d]); - - debug_malloc_touch(p); - debug_malloc_touch(dat); - -/* p->inherits[0].prog=p; - p->inherits[0].parent_offset=1; -*/ - - if(placeholder && data->pass==1) - { - if(placeholder->prog != null_program) - { - debug_malloc_touch(placeholder); - ref_push_program (p); - decode_error(data, Pike_sp - 1, "Placeholder is no longer " - "a __null_program clone.\n"); - }else{ - free_program(placeholder->prog); - add_ref(placeholder->prog = p); - debug_malloc_touch(placeholder); - } - } - - debug_malloc_touch(p); - - in=p->num_inherits; - for(d=0;d<in;d++) - { - decode_number(p->inherits[d].inherit_level,data); - decode_number(p->inherits[d].identifier_level,data); - decode_number(p->inherits[d].parent_offset,data); - decode_number(p->inherits[d].parent_identifier,data); - decode_number(p->inherits[d].storage_offset,data); - - decode_value2(data); - if(d==0) - { - if(TYPEOF(Pike_sp[-1]) != T_PROGRAM || - Pike_sp[-1].u.program != p) { - ref_push_program (p); - decode_error(data, Pike_sp - 1, - "Program decode of self inherit failed. Got: %O\n", - Pike_sp - 2); - } - sub_ref(p); - } - - if(data->pass > 1) - { - if(p->inherits[d].prog) - { - free_program(p->inherits[d].prog); - p->inherits[d].prog=0; - } - - if(p->inherits[d].parent) - { - free_object(p->inherits[d].parent); - p->inherits[d].parent=0; - } - } - - switch(TYPEOF(Pike_sp[-1])) - { - case T_PROGRAM: - EDB(3, fprintf(stderr,"INHERIT%x = prog\n",p->id); ); - p->inherits[d].prog=Pike_sp[-1].u.program; - Pike_sp--; - dmalloc_touch_svalue(Pike_sp); - break; - - case T_FUNCTION: - if(SUBTYPEOF(Pike_sp[-1]) != FUNCTION_BUILTIN) { - EDB(3, fprintf(stderr,"INHERIT%x = func { %p, %d} \n",p->id,Pike_sp[-1].u.object, SUBTYPEOF(Pike_sp[-1])); ); - - p->inherits[d].parent_identifier = SUBTYPEOF(Pike_sp[-1]); - p->inherits[d].prog=program_from_svalue(Pike_sp-1); - if(!p->inherits[d].prog) { - ref_push_program (p); - decode_error(data, Pike_sp - 1, "Failed to decode " - "inherited program. Got: %O\n", Pike_sp - 2); - } - add_ref(p->inherits[d].prog); - p->inherits[d].parent=Pike_sp[-1].u.object; - Pike_sp--; - dmalloc_touch_svalue(Pike_sp); - break; - } - /* Fall through */ - - default: - ref_push_program (p); - decode_error(data, Pike_sp - 1, - "Failed to decode inherited program. Got: %O\n", - Pike_sp - 2); - } - - p->num_inherits=d+1; - - getdata3(p->inherits[d].name); - - EDB(3, fprintf(stderr,"INHERIT%x < %d: %d id=%d\n", - p->id,d, - p->inherits[d].prog->num_identifiers, - p->inherits[d].prog->id); ); - } - - debug_malloc_touch(dat); - - - SET_ONERROR(err1, restore_type_stack, Pike_compiler->type_stackp); - SET_ONERROR(err2, restore_type_mark, Pike_compiler->pike_type_mark_stackp); - - debug_malloc_touch(p); - for(d=0;d<p->num_identifiers;d++) - { - getdata(p->identifiers[d].name); - decode_type(p->identifiers[d].type,data); - decode_number(p->identifiers[d].identifier_flags,data); - decode_number(p->identifiers[d].run_time_type,data); - decode_number(p->identifiers[d].opt_flags,data); - decode_number(p->identifiers[d].filename_strno, data); - decode_number(p->identifiers[d].linenumber, data); - if (IDENTIFIER_IS_ALIAS(p->identifiers[d].identifier_flags)) { - decode_number(p->identifiers[d].func.ext_ref.depth, data); - decode_number(p->identifiers[d].func.ext_ref.id, data); - } else if (!IDENTIFIER_IS_C_FUNCTION(p->identifiers[d].identifier_flags)) - { - decode_number(p->identifiers[d].func.offset,data); - } else { - ref_push_program (p); - decode_error(data, Pike_sp - 1, - "Cannot decode function implemented in C: %S\n", - p->identifiers[d].name); - } - } - - - UNSET_ONERROR(err2); - UNSET_ONERROR(err1); - - debug_malloc_touch(dat); - - debug_malloc_touch(p); - for(d=0;d<NUM_LFUNS;d++) - decode_number(p->lfuns[d],data); - - debug_malloc_touch(dat); - - debug_malloc_touch(p); - - fsort_program_identifier_index(p->identifier_index, - p->identifier_index + - p->num_identifier_index - 1, - p); - - debug_malloc_touch(dat); - debug_malloc_touch(p); - - p->flags |= PROGRAM_PASS_1_DONE | PROGRAM_FIXED; - for(d=0;d<p->num_constants;d++) - { - decode_value2(data); - if(data->pass > 1) - { - assign_svalue(& p->constants[d].sval , Pike_sp -1 ); - pop_stack(); - }else{ - dmalloc_touch_svalue(Pike_sp-1); - p->constants[d].sval=*--Pike_sp; - } - dmalloc_touch_svalue(Pike_sp); - { - struct pike_string *dummy = NULL; - getdata3(dummy /*p->constants[d].name*/); - if (dummy) free_string(dummy); - } - } - -#ifdef PIKE_DEBUG - { - int q; - for(q=0;q<p->num_inherits;q++) - if(!p->inherits[q].prog) - Pike_fatal("FOOBAR!@!!!\n"); - } -#endif - - if(placeholder && data->pass == 1) - { - if(placeholder->storage) - { - ref_push_program (p); - decode_error(data, Pike_sp - 1, - "Placeholder already has storage!\n"); - } else { - placeholder->storage=p->storage_needed ? - xcalloc(p->storage_needed, 1) : - NULL; - call_c_initializers(placeholder); - } - } - -#ifdef ENCODE_DEBUG - if (!data->debug) -#endif - data->pickyness--; - - if(placeholder) - { - free_object(placeholder); - UNSET_ONERROR(err4); - } - UNSET_ONERROR(err3); - - ref_push_program(p); - - if(!(p->flags & PROGRAM_FINISHED) -#if TWO_PASS_DECODE_WORKS - && !data->supporter.depends_on -#endif - ) - { - /* Logic for the PROGRAM_FINISHED flag: - * The purpose of this code is to make sure that the PROGRAM_FINISHED - * flag is not set on the program until all inherited programs also - * have that flag. -Hubbe - */ - for(d=1;d<p->num_inherits;d++) - if(! (p->inherits[d].prog->flags & PROGRAM_FINISHED)) - break; - - if(d == p->num_inherits) - { - p->flags &=~ PROGRAM_AVOID_CHECK; - p->flags |= PROGRAM_FINISHED; - - if (placeholder) - { - if(!init_placeholder(placeholder)) - placeholder=0; - } - - /* Go through the linked list of unfinished programs - * to see what programs are now finished. - */ - { - struct unfinished_prog_link *l, **ptr; - -#ifdef PIKE_DEBUG - check_program(p); -#endif /* PIKE_DEBUG */ - - /* It is possible that we need to restart loop - * in some cases... /Hubbe - */ - for(ptr= &data->unfinished_programs ; (l=*ptr);) - { - struct program *pp=l->prog; - for(d=1;d<pp->num_inherits;d++) - if(! (pp->inherits[d].prog->flags & PROGRAM_FINISHED)) - break; - - if(d == pp->num_inherits) - { - fsort_program_identifier_index(pp->identifier_index, - pp->identifier_index + - pp->num_identifier_index - 1, - pp); - - pp->flags &=~ PROGRAM_AVOID_CHECK; - pp->flags |= PROGRAM_FINISHED; - -#ifdef PIKE_DEBUG - check_program(pp); -#endif /* PIKE_DEBUG */ - - *ptr = l->next; - free(l); - }else{ - ptr=&l->next; - } - } - } - - /* Go through the linked list of unfinished objects - * to see what objects are now finished. - */ - { - int decode_fun = -1; - struct unfinished_obj_link *l, **ptr; - if (data->unfinished_objects) { - decode_fun = find_identifier("decode_object", - decoder_codec (data)->prog); - if (decode_fun < 0) - decode_error(data, Pike_sp - 1, - "Cannot decode objects without a " - "\"decode_object\" function in the codec.\n"); - } - for(ptr= &data->unfinished_objects ; (l=*ptr);) - { - int fun; - struct object *o=l->o; - if(o->prog) - { - if(o->prog->flags & PROGRAM_FINISHED) - { - apply_lfun(o, LFUN___INIT, 0); - pop_stack(); - /* FIXME: Should call LFUN_CREATE here in <= 7.2 - * compatibility mode. */ - }else{ - ptr=&l->next; - continue; - } - } - - /* Note: We steal the references from l. */ - push_object(o); - *(Pike_sp++) = l->decode_arg; - - *ptr = l->next; - free(l); - - /* Let the codec do it's job... */ - apply_low(decoder_codec (data), decode_fun, 2); - if ((TYPEOF(Pike_sp[-1]) == T_ARRAY) && - o->prog && - ((fun = FIND_LFUN(o->prog, LFUN_CREATE)) != -1)) { - /* Call lfun::create(@args). */ - INT32 args; - Pike_sp--; - args = Pike_sp->u.array->size; - if (args) { - /* Note: Eats reference to the array. */ - push_array_items(Pike_sp->u.array); - } else { - free_array(Pike_sp->u.array); - } - apply_low(o, fun, args); - } - pop_stack(); - } - } - }else{ - struct unfinished_prog_link *l; - l=ALLOC_STRUCT(unfinished_prog_link); - l->prog=p; - l->next=data->unfinished_programs; - data->unfinished_programs=l; - } - } - - CALL_AND_UNSET_ONERROR(err); - goto decode_done; + decode_error(data, NULL, "Failed to decode program. Old-style program encoding is not supported, anymore.\n"); } case 2: