--- gcc/objc/archive.c 2018/04/24 18:20:12 1.1.1.3 +++ gcc/objc/archive.c 2018/04/24 18:26:48 1.1.1.4 @@ -1,22 +1,22 @@ /* GNU Objective C Runtime archiving - Copyright (C) 1993 Free Software Foundation, Inc. - -Author: Kresten Krab Thorup + Copyright (C) 1993, 1995 Free Software Foundation, Inc. + Contributed by Kresten Krab Thorup This file is part of GNU CC. GNU CC is free software; you can redistribute it and/or modify it under the - terms of the GNU General Public License as published by the Free Software - Foundation; either version 2, or (at your option) any later version. +terms of the GNU General Public License as published by the Free Software +Foundation; either version 2, or (at your option) any later version. GNU CC is distributed in the hope that it will be useful, but WITHOUT ANY - WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - FOR A PARTICULAR PURPOSE. See the GNU General Public License for more - details. +WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +FOR A PARTICULAR PURPOSE. See the GNU General Public License for more +details. You should have received a copy of the GNU General Public License along with - GNU CC; see the file COPYING. If not, write to the Free Software - Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ +GNU CC; see the file COPYING. If not, write to the Free Software +Foundation, 59 Temple Place - Suite 330, +Boston, MA 02111-1307, USA. */ /* As a special exception, if you link this library with files compiled with GCC to produce an executable, this does not cause the resulting executable @@ -45,7 +45,7 @@ extern int fflush(FILE*); /* Declare some functions... */ static int -objc_read_class (struct objc_typed_stream* stream, Class** class); +objc_read_class (struct objc_typed_stream* stream, Class* class); int objc_sizeof_type(const char* type); @@ -438,7 +438,7 @@ __objc_write_class (struct objc_typed_st __objc_write_extension (stream, _BX_CLASS); objc_write_string_atomic(stream, (char*)class->name, strlen((char*)class->name)); - return objc_write_unsigned_long (stream, CLS_GETNUMBER(class)); + return objc_write_unsigned_long (stream, class->version); } @@ -463,16 +463,26 @@ objc_write_class (struct objc_typed_stre __inline__ int __objc_write_selector (struct objc_typed_stream* stream, SEL selector) { - const char* sel_name = sel_get_name (selector); + const char* sel_name; __objc_write_extension (stream, _BX_SEL); + /* to handle NULL selectors */ + if ((SEL)0 == selector) + return objc_write_string (stream, "", 0); + sel_name = sel_get_name (selector); return objc_write_string (stream, sel_name, strlen ((char*)sel_name)); } int objc_write_selector (struct objc_typed_stream* stream, SEL selector) { - const char* sel_name = sel_get_name (selector); + const char* sel_name; unsigned long key; + + /* to handle NULL selectors */ + if ((SEL)0 == selector) + return __objc_write_selector (stream, selector); + + sel_name = sel_get_name (selector); if ((key = PTR2LONG(hash_value_for_key (stream->stream_table, sel_name)))) return objc_write_use_common (stream, key); else @@ -796,7 +806,7 @@ objc_read_object (struct objc_typed_stre if (buf[0] == (_B_EXT | _BX_OBJECT)) { - Class* class; + Class class; /* get class */ len = objc_read_class (stream, &class); @@ -849,7 +859,7 @@ objc_read_object (struct objc_typed_stre } static int -objc_read_class (struct objc_typed_stream* stream, Class** class) +objc_read_class (struct objc_typed_stream* stream, Class* class) { unsigned char buf[sizeof (unsigned int)]; int len; @@ -918,7 +928,14 @@ objc_read_selector (struct objc_typed_st /* get selector */ len = objc_read_string (stream, &selector_name); - (*selector) = sel_get_any_uid(selector_name); + /* To handle NULL selectors */ + if (0 == strlen(selector_name)) + { + (*selector) = (SEL)0; + return 0; + } + else + (*selector) = sel_get_any_uid(selector_name); free (selector_name); /* register */ @@ -958,7 +975,7 @@ objc_write_type(TypedStream* stream, con break; case _C_CLASS: - return objc_write_class (stream, *(Class**)data); + return objc_write_class (stream, *(Class*)data); break; case _C_SEL: @@ -1052,7 +1069,7 @@ objc_read_type(TypedStream* stream, cons break; case _C_CLASS: - return objc_read_class (stream, (Class**)data); + return objc_read_class (stream, (Class*)data); break; case _C_SEL: @@ -1153,7 +1170,7 @@ objc_write_types (TypedStream* stream, c break; case _C_CLASS: - res = objc_write_class (stream, *va_arg(args, Class**)); + res = objc_write_class (stream, *va_arg(args, Class*)); break; case _C_SEL: @@ -1252,7 +1269,7 @@ objc_read_types(TypedStream* stream, con break; case _C_CLASS: - res = objc_read_class(stream, va_arg(args, Class**)); + res = objc_read_class(stream, va_arg(args, Class*)); break; case _C_SEL: @@ -1589,7 +1606,7 @@ objc_flush_typed_stream (TypedStream* st } long -objc_get_stream_class_version (TypedStream* stream, Class* class) +objc_get_stream_class_version (TypedStream* stream, Class class) { if (stream->class_table) return PTR2LONG(hash_value_for_key (stream->class_table, class->name));