diff options
author | Lorry Tar Creator <lorry-tar-importer@baserock.org> | 2013-04-11 09:13:11 +0000 |
---|---|---|
committer | <> | 2014-04-23 12:05:38 +0000 |
commit | 6af3fdec2262dd94954acc5e426ef71cbd4521d3 (patch) | |
tree | 9be02de9a80f7935892a2d03741adee44723e65d /libobjc | |
parent | 19be2b4342ac32e9edc78ce6fed8f61b63ae98d1 (diff) | |
download | gcc-tarball-6af3fdec2262dd94954acc5e426ef71cbd4521d3.tar.gz |
Imported from /home/lorry/working-area/delta_gcc-tarball/gcc-4.7.3.tar.bz2.gcc-4.7.3
Diffstat (limited to 'libobjc')
68 files changed, 867 insertions, 4911 deletions
diff --git a/libobjc/ChangeLog b/libobjc/ChangeLog index 3c7a761c4a..fc3b5c0aeb 100644 --- a/libobjc/ChangeLog +++ b/libobjc/ChangeLog @@ -1,11 +1,38 @@ -2011-10-26 Release Manager +2013-04-11 Release Manager - * GCC 4.6.2 released. + * GCC 4.7.3 released. -2011-10-14 Nicola Pero <nicola.pero@meta-innovation.com> +2012-09-20 Release Manager - Backport from mainline - 2011-10-09 Nicola Pero <nicola.pero@meta-innovation.com> + * GCC 4.7.2 released. + +2012-06-14 Release Manager + + * GCC 4.7.1 released. + +2012-03-22 Release Manager + + * GCC 4.7.0 released. + +2011-11-21 Andreas Tobler <andreast@fgznet.ch> + + * configure: Regenerate. + +2011-11-02 Rainer Orth <ro@CeBiTec.Uni-Bielefeld.DE> + + * Makefile.in (INCLUDES): Add -I$(MULTIBUILDTOP)../libgcc. + * configure.ac (target_thread_file, HAVE_GTHR_DEFAULT): Remove. + * configure: Regenerate. + * config.h.in: Regenerate. + +2011-10-17 Paul Brook <paul@codesourcery.com> + Matthias Klose <doko@ubuntu.com> + + * exception.c (parse_lsda_header): hardcode ttype_encoding for older + ARM EABI toolchains. + (get_ttype_entry) Remove __ARM_EABI_UNWINDER__ variant. + +2011-10-09 Nicola Pero <nicola.pero@meta-innovation.com> PR libobjc/49883 * init.c (__objc_exec_class): Work around a bug in clang's code @@ -15,33 +42,355 @@ this breaks backwards compatibility. Wipe out all the bits in the fields other than the first two upon loading a class. -2011-10-14 Nicola Pero <nicola.pero@meta-innovation.com> +2011-10-09 Nicola Pero <nicola.pero@meta-innovation.com> + + * class.c (objc_lookup_class): Added back for compatibility with + clang which seems to emit calls to it. + +2011-10-08 Richard Frith-Macdonald <rfm@gnu.org> + Nicola Pero <nicola.pero@meta-innovation.com> + + PR libobjc/50428 + * sendmsg.c (__objc_send_initialize): If a class does not have an + +initialize method, search for an +initialize method in the + superclass and in the ancestor classes and execute the first one + that is found. This makes the GNU runtime behave in the same way + as the Apple/NeXT runtime with respect to +initialize methods and + subclassing. - Backport from mainline - 2011-08-06 Nicola Pero <nicola.pero@meta-innovation.com> +2011-08-06 Nicola Pero <nicola.pero@meta-innovation.com> PR libobjc/50002 * class.c (__objc_update_classes_with_methods): Iterate over meta classes as well as normal classes when refreshing the method implementations. This fixes replacing class methods. -2011-06-27 Release Manager +2011-08-06 Nicola Pero <nicola.pero@meta-innovation.com> + + * class.c (class_getSuperclass): Fixed to work with meta classes + still in construction too. + +2011-08-06 Nicola Pero <nicola.pero@meta-innovation.com> + + * class.c (class_getSuperclass): Fixed typo in comment. + +2011-08-06 Nicola Pero <nicola.pero@meta-innovation.com> + + PR libobjc/49882 + * class.c (class_getSuperclass): Return the superclass if the + class is in construction. + * objc/runtime.h (class_getSuperclass): Updated documentation. + +2011-08-05 Rainer Orth <ro@CeBiTec.Uni-Bielefeld.DE> + + * Makefile.in (INCLUDES): Search + $(srcdir)/$(MULTISRCTOP)../libgcc. - * GCC 4.6.1 released. +2011-06-08 Nicola Pero <nicola.pero@meta-innovation.com> -2011-05-25 Nicola Pero <nicola.pero@meta-innovation.com> + * objc/objc.h (__GNU_LIBOBJC__): Bumped to 20110608. - Backport from mainline - 2011-05-24 Nicola Pero <nicola.pero@meta-innovation.com> +2011-06-08 Nicola Pero <nicola.pero@meta-innovation.com> + + * configure.ac (VERSION): Bumped to 4:0:0. + * configure (VERSION): Likewise. + +2011-06-08 Nicola Pero <nicola.pero@meta-innovation.com> + + * objc/README: Updated. + * objc-private/selector.h: Updated comments. + +2011-06-07 Nicola Pero <nicola.pero@meta-innovation.com> + + * sendmsg.c (class_get_instance_method): Removed. + (class_get_class_method): Removed. + (objc_get_uninstalled_dtable): Removed. + +2011-06-07 Nicola Pero <nicola.pero@meta-innovation.com> + + * objc-private/module-abi-8.h (class_get_instance_size): Removed. + * objects.c (class_create_instance): Removed. + * error.c (__USE_FIXED_PROTOTYPES__): Removed. + * gc.c (__objc_generate_gc_type_description): Use + class_getInstanceSize() instead of class_get_instance_size(). + * selector.c (sel_types_match): Made static. + (sel_get_typed_uid): Removed. + (sel_get_any_typed_uid): Removed. + (sel_get_name): Removed. + (sel_get_type): Removed. + (sel_register_name): Removed. + (sel_register_typed_name): Removed. + (sel_get_uid): Removed. + +2011-06-07 Nicola Pero <nicola.pero@meta-innovation.com> + + * encoding.c (method_get_number_of_arguments): Removed. + (method_get_sizeof_arguments): Removed. + +2011-06-07 Nicola Pero <nicola.pero@meta-innovation.com> + + * class.c (objc_next_class): Removed. + (class_pose_as): Removed. + (CLASSOF): Removed. + (class_table_replace): Removed. + (objc_lookup_class): Removed. + +2011-06-07 Nicola Pero <nicola.pero@meta-innovation.com> + + Removed the Traditional Objective-C runtime public API. + * Makefile.in (OBJC_DEPRECATED_H): Variable removed. + (install-headers): Do not create the objc/deprecated directory and + do not install the deprecated headers. + (OBJC_H): Removed encoding.h and objc-api.h. + * Object.m: Removed all methods with the exception of -class and + -isEqual:. Updated includes. ([-class]): Use Modern API. + * objc/Object.h: Do not include deprecated/Object.h. + * objc/deprecated/Object.h: Removed. + * linking.m (__objc_linking): Call [Object class] instead of + [Object name]. + * Protocol.m: Removed all methods with the exception of -isEqual:. + Updated includes. + * objc/Protocol.h: Do not include deprecated/Protocol.h. + * objc/deprecated/Protocol.h: Removed. + * objc/deprecated/struct_objc_symtab.h: Removed. + * objc/deprecated/struct_objc_module.h: Removed. + * objc/deprecated/struct_objc_ivar.h: Removed. + * objc/deprecated/struct_objc_ivar_list.h: Removed. + * objc/deprecated/struct_objc_method.h: Removed. + * objc/deprecated/struct_objc_method_list.h: Removed. + * objc/deprecated/struct_objc_protocol_list.h: Removed. + * objc/deprecated/struct_objc_category.h: Removed. + * objc/deprecated/MetaClass.h: Removed. + * objc/deprecated/objc_msg_sendv.h: Removed. + * objc/deprecated/README: Removed. + * objc/deprecated/struct_objc_class.h: Removed. + * objc/deprecated/struct_objc_protocol.h: Removed. + * objc/deprecated/struct_objc_selector.h: Removed. + * objc/encoding.h: Removed. + * objc/message.h (struct objc_super): Removed the definition for + the Traditional Objective-C runtime API. + * objc/objc.h: Do not include objc/objc-decls.h. + deprecated/struct_objc_selector.h, deprecated/MetaClass.h, + deprecated/struct_objc_class.h, deprecated/struct_objc_protocol.h + and deprecated/objc_msg_sendv.h. Uncommented new definition of + Protocol *. + * objc/objc-api.h: Removed. + * objc/runtime.h: Updated comments. Removed check to detect + concurrent usage of Traditional and Modern APIs. + * objc-private/module-abi-8.h: Always define struct objc_class and + struct objc_protocol. (struct objc_protocol_list): Changed type + of 'list' argument from 'Protocol *' to 'struct objc_protocol *'. + (class_get_instance_size): Added. + * objc-private/protocols.h (__objc_protocols_add_protocol): Take a + 'struct objc_protocol *' as argument, not a 'Protocol *'. + * objc-private/runtime.h: Updated comments. + * objc-private/selector.h (struct objc_selector, sel_eq): Added. + * class.c: Include objc-private/selector.h. + (objc_get_meta_class): Return a Class instead of a MetaClass. + * encoding.c (method_get_next_argument): Removed. + (method_get_first_argument): Removed. + (method_get_nth_argument): Removed. + * gc.c: Include objc/runtime.h instead of objc/encoding.h. + Include objc-private/module-abi-8.h and ctype.h. + * protocols.c (__objc_protocols_add_protocol): Take a 'struct + objc_protocl *' as argument, not a 'Protocol *'. + (class_addProtocol): Added casts to 'struct objc_protocol *' and + 'Protocol *'. + (class_copyProtocolList): Likewise. + (protocol_conformsToProtocol): Likewise. + (protocol_copyProtocolList): Likewise. + * sarray.c: Include objc-private/module-abi-8.h. + * sendmsg.c (method_get_next_argument): Removed. + (method_get_first_argument): Removed. + (method_get_nth_argument): Removed. + (objc_msg_sendv): Removed. + (arglist_t, retval_t): New. (class_get_class_method): Take a + 'Class', not 'MetaClass', argument. + * thr.c: Include module-abi-8.h. + +2011-06-03 Nicola Pero <nicola.pero@meta-innovation.com> + + * Makefile.in (OBJC_DEPRECATED_H): Removed struct_objc_static_instances.h + and objc_get_uninstalled_dtable.h. + * objc/deprecated/struct_objc_static_instances.h: Removed. + * objc/deprecated/objc_get_uninstalled_dtable.h: Removed. + * objc/objc-api.h: Do not include deprecated/objc_static_instances.h + and deprecated/objc_get_uninstalled_dtable.h. + +2011-06-03 Nicola Pero <nicola.pero@meta-innovation.com> + + * Makefile.in (OBJC_DEPRECATED_H): Removed objc_object_alloc.h. + * objc/deprecated/objc_object_alloc.h: Removed. + * objc/objc-api.h: Do not include deprecated/objc_object_alloc.h. + * objects.c (_objc_object_alloc, _objc_object_dispose, + _objc_object_copy): Removed. + * libobjc.def (__objc_object_alloc, __objc_object_copy, + __objc_object_dispose): Removed. + +2011-06-03 Nicola Pero <nicola.pero@meta-innovation.com> + + * Makefile.in (OBJC_DEPRECATED_H): Removed METHOD_NULL.h. + * objc/objc-api.h: Do not include deprecated/METHOD_NULL.h. + * objc/deprecated/METHOD_NULL.h: Removed. + +2011-06-03 Nicola Pero <nicola.pero@meta-innovation.com> + + * Makefile.in (OBJC_DEPRECATED_H): Removed objc_valloc.h, + objc_malloc.h and objc_unexpected_exception.h. + (exception.lo): Do not use -Wno-deprecated-declarations. + (exception_gc.lo): Likewise. + * objc/objc-api.h: Do not include deprecated/objc_valloc.h, + deprecated/objc_malloc.h and + deprecated/objc_unexpected_exception.h. + * objc/deprecated/objc_valloc.h: Removed. + * objc/deprecated/objc_malloc.h: Removed. + * objc/deprecated/objc_unexpected_exception.h: Removed. + * exception.c (_objc_unexpected_exception): Removed. + (objc_exception_throw): Do not check for + _objc_unexpected_exception. + * memory.c (objc_valloc, _objc_malloc, _objc_atomic_malloc, + _objc_valloc, _objc_realloc, _objc_calloc, _objc_free): Removed. + * libobjc.def (_objc_unexpected_exception, objc_valloc): Removed. + +2011-06-03 Nicola Pero <nicola.pero@meta-innovation.com> + + * objc/objc.h: Do not include deprecated/STR.h. + * objc/deprecated/STR.h: Removed. + * Makefile.in (OBJC_DEPRECATED_H): removed STR.h. + +2011-06-03 Nicola Pero <nicola.pero@meta-innovation.com> + + * Makefile.in (OBJC_H): Removed hash.h and sarray.h. + (OBJC_DEPRECATED_H): Likewise. + * libobjc.def (objc_hash_new, objc_hash_delete, objc_hash_add, + objc_hash_remove, objc_hash_next, objc_hash_value_for_key, + objc_hash_is_key_in_hash, hash_add, hash_delete, hash_new, + hash_next, hash_remove, hash_value_for_key, hash_is_key_in_hash, + sarray_at_put, sarray_at_put_safe, sarray_free, sarray_lazy_copy, + sarray_new, sarray_realloc, sarray_remove_garbage): Removed. + * objc/sarray.h: Removed. + * objc/hash.h: Removed. + * objc/deprecated/sarray.h: Removed. + * objc/deprecated/hash.h: Removed. + * objc/Object.h: Do not include objc/deprecated/hash.h + * Object.m: Include string.h. + * objc/objc-api.h: Do not include objc/deprecated/hash.h. + * objc-private/common.h (GNU_LIBOBJC_COMPILING_LIBOBJC_ITSELF): + Removed. + +2011-06-03 Nicola Pero <nicola.pero@meta-innovation.com> + + * Object.m ([-forward::]): Removed. + * objc/deprecated/Object.h ([-forward::]): Removed. + * sendmsg.c (__objc_forward): Updated comments. + +2011-06-03 Nicola Pero <nicola.pero@meta-innovation.com> + + * Makefile.in (OBJC_H): Removed objc-list.h. + (OBJC_DEPRECATED_H): Removed objc-list.h. + * objc/objc-list.h: File removed. + * objc/deprecated/objc-list.h: File removed. + +2011-06-03 Nicola Pero <nicola.pero@meta-innovation.com> + + * Makefile.in (OBJC_H): Removed typedstream.h. + (OBJC_DEPRECATED_H): Removed typedstream.h. + (C_SOURCE_FILES): Removed archive.c. + (Object.lo): Rule removed. + (Object_gc.lo): Likewise. + (archive.lo): Likewise. + (archive_gc.lo): Likewise. + * objc/deprecated/Object.h ([+streamVersion:], [-read], [-write], + [-awake]): Removed. + Do not include deprecated/typedstream.h. + * Object.m: Removed the same methods. + * archive.c: File removed. + * objc/typedstream.h: File removed. + * objc/deprecated/typedstream.h: File removed. + * libobjc.def (__objc_read_nbyte_uint, __objc_read_nbyte_ulong, + __objc_write_class, __objc_write_object, __objc_write_selector, + objc_close_typed_stream, objc_end_of_typed_stream, + objc_flush_typed_stream, objc_get_stream_class_version, + objc_open_typed_stream, objc_open_typed_stream_for_file, + objc_read_array, objc_read_char, objc_read_int, objc_read_long, + objc_read_object, objc_read_selector, objc_read_short, + objc_read_string, objc_read_type, objc_read_types, + objc_read_unsigned_char, objc_read_unsigned_int, + objc_read_unsigned_long, objc_read_unsigned_short, + objc_write_array, objc_write_char, objc_write_int, + objc_write_long, objc_write_object, objc_write_object_reference, + objc_write_root_object, objc_write_selector, objc_write_short, + objc_write_string, objc_write_string_atomic, objc_write_type, + objc_write_types, objc_write_unsigned_char, + objc_write_unsigned_int, objc_write_unsigned_long, + objc_write_unsigned_short): Removed. + +2011-06-02 Nicola Pero <nicola.pero@meta-innovation.com> + + * Makefile.in (OBJC_DEPRECATED_H): Removed objc_error.h. + * objc/deprecated/objc_error.h: Removed. + * objc/objc-api.h: Do not include deprecated/objc_error.h. + * libobjc.def (objc_error, objc_verror): Removed. + * error.c (_objc_error_handler, objc_error, objc_verror, + objc_set_error_handler): Removed. + * Object.m ([-error:], [-perform:], [-perform:with:], + [-perform:with:with], [-subclassResponsibility:], + [-notImplemented:], [-shouldNotImplement:], [-doesNotRecognize:]): + Removed. + * objc/deprecated/Object.h: Removed the same methods. + * sendmsg.c (__objc_forward): Do not try to invoke the "error:" + method after trying to invoke the "doesNotRecognize:" method. + +2011-05-26 Nicola Pero <nicola.pero@meta-innovation.com> + + * sendmsg.c: Reindented part of the file. No non-trivial changes + in code. + +2011-05-26 Nicola Pero <nicola.pero@meta-innovation.com> + + * sendmsg.c (__objc_install_dtable_for_class): Use objc_getClass, + not objc_lookup_class. + +2011-05-25 Richard Frith-Macdonald <rfm@gnu.org> + David Ayers <ayers@fsfe.org> + + PR libobjc/38307 + * sendmsg.c: Include objc/hash.h. + (get_implementation): New function, mostly with code from get_imp + updated to support the new +initialize dispatch table logic. + (get_imp): Use get_implementation. + (__objc_responds_to): Updated to support the new +initialize + dispatch table logic. + (class_respondsToSelector): Likewise. + (objc_msg_lookup): Use get_implementation. + (__objc_init_install_dtable): Removed. + (__objc_install_methods_in_dtable): Updated arguments. + (__objc_install_dispatch_table_for_class): Renamed to + __objc_install_dtable_for_class and updated to support the new + +initialize dispatch table logic. + (__objc_update_dispatch_table_for_class): Updated to support the + new +initialize dispatch table logic. + (__objc_forward): Call get_implementation instead of get_imp. + (prepared_dtable_table): New. + (__objc_prepare_dtable_for_class): New. + (__objc_prepared_dtable_for_class): New. + (__objc_get_prepared_imp): New. + (__objc_install_prepared_dtable_for_class): New. + +2011-05-24 Nicola Pero <nicola.pero@meta-innovation.com> PR libobjc/48177 * selector.c (__sel_register_typed_name): Use sel_types_match() instead of strcmp() to compare selector types (Suggestion by Richard Frith-Macdonald <rfm@gnu.org>). -2011-03-25 Release Manager +2011-04-15 Rainer Orth <ro@CeBiTec.Uni-Bielefeld.DE> - * GCC 4.6.0 released. + PR libobjc/32037 + * Makefile.in (OBJC_GCFLAGS): Move ... + * configure.ac (enable_objc_gc): ... here. + Add $(libsuffix) to OBJC_BOEHM_GC. + * configure: Regenerate. 2011-02-28 Nicola Pero <nicola.pero@meta-innovation.com> diff --git a/libobjc/Makefile.in b/libobjc/Makefile.in index b33c989e6d..1427bac43b 100644 --- a/libobjc/Makefile.in +++ b/libobjc/Makefile.in @@ -93,7 +93,7 @@ LIBTOOL_INSTALL = $(LIBTOOL) --mode=install LIBTOOL_CLEAN = $(LIBTOOL) --mode=clean #LIBTOOL_UNINSTALL = $(LIBTOOL) --mode=uninstall -OBJC_GCFLAGS=-DOBJC_WITH_GC=1 +OBJC_GCFLAGS=@OBJC_GCFLAGS@ OBJC_BOEHM_GC=@OBJC_BOEHM_GC@ OBJC_BOEHM_GC_INCLUDES=@OBJC_BOEHM_GC_INCLUDES@ OBJC_BOEHM_GC_LIBS=../boehm-gc/libgcjgc_convenience.la $(thread_libs_and_flags) @@ -101,6 +101,8 @@ OBJC_BOEHM_GC_LIBS=../boehm-gc/libgcjgc_convenience.la $(thread_libs_and_flags) INCLUDES = -I$(srcdir)/$(MULTISRCTOP)../gcc \ -I$(srcdir)/$(MULTISRCTOP)../gcc/config \ -I$(MULTIBUILDTOP)../../$(host_subdir)/gcc \ + -I$(srcdir)/$(MULTISRCTOP)../libgcc \ + -I$(MULTIBUILDTOP)../libgcc \ -I$(srcdir)/$(MULTISRCTOP)../include \ $(OBJC_BOEHM_GC_INCLUDES) @@ -117,49 +119,10 @@ OBJC_H = \ NXConstStr.h \ Object.h \ Protocol.h \ - encoding.h \ message.h \ - objc-api.h \ objc-decls.h \ runtime.h \ - thr.h \ - \ - hash.h \ - objc-list.h \ - sarray.h \ - typedstream.h - -# User-visible header files containing deprecated APIs, from the -# objc/deprecated directory -OBJC_DEPRECATED_H = \ - METHOD_NULL.h \ - MetaClass.h \ - Object.h \ - Protocol.h \ - STR.h \ - hash.h \ - objc-list.h \ - objc_error.h \ - objc_get_uninstalled_dtable.h \ - objc_malloc.h \ - objc_msg_sendv.h \ - objc_object_alloc.h \ - objc_unexpected_exception.h \ - objc_valloc.h \ - sarray.h \ - struct_objc_category.h \ - struct_objc_class.h \ - struct_objc_ivar.h \ - struct_objc_ivar_list.h \ - struct_objc_method.h \ - struct_objc_method_list.h \ - struct_objc_module.h \ - struct_objc_protocol.h \ - struct_objc_protocol_list.h \ - struct_objc_selector.h \ - struct_objc_static_instances.h \ - struct_objc_symtab.h \ - typedstream.h + thr.h # Objective-C source files to compile OBJC_SOURCE_FILES = \ @@ -171,7 +134,6 @@ OBJC_SOURCE_FILES = \ # C source files to compile C_SOURCE_FILES = \ - archive.c \ class.c \ encoding.c \ error.c \ @@ -279,38 +241,15 @@ sendmsg_gc.lo: sendmsg.c runtime-info.h # These files have separate rules because they require special # compiler flags. -archive.lo: archive.c - $(LIBTOOL_COMPILE) $(CC) $< -c \ - $(ALL_CFLAGS) $(INCLUDES) -Wno-deprecated-declarations \ - -o $@ - -archive_gc.lo: archive.c - $(LIBTOOL_COMPILE) $(CC) $< -c \ - $(ALL_CFLAGS) $(INCLUDES) $(OBJC_GCFLAGS) -Wno-deprecated-declarations \ - -o $@ -# -Wno-deprecated-declarations is for the objc/typedstream.h functions. -Object.lo: Object.m - $(LIBTOOL_COMPILE) $(CC) $< -c \ - $(ALL_CFLAGS) $(INCLUDES) -fgnu-runtime -Wno-deprecated-declarations \ - -o $@ - -# -Wno-deprecated-declarations is for the objc/typedstream.h functions. -Object_gc.lo: Object.m - $(LIBTOOL_COMPILE) $(CC) $< -c \ - $(ALL_CFLAGS) $(INCLUDES) $(OBJC_GCFLAGS) -fgnu-runtime -Wno-deprecated-declarations \ - -o $@ - -# -Wno-deprecated-declarations is to silence warnings from using -# _objc_unexpected_exception. exception.lo: exception.c $(LIBTOOL_COMPILE) $(CC) $< -c \ - $(ALL_CFLAGS) $(INCLUDES) -fexceptions -Wno-deprecated-declarations \ + $(ALL_CFLAGS) $(INCLUDES) -fexceptions \ -o $@ exception_gc.lo: exception.c $(LIBTOOL_COMPILE) $(CC) $< -c \ - $(ALL_CFLAGS) $(INCLUDES) $(OBJC_GCFLAGS) -fexceptions -Wno-deprecated-declarations \ + $(ALL_CFLAGS) $(INCLUDES) $(OBJC_GCFLAGS) -fexceptions \ -o $@ doc: info dvi pdf html @@ -387,11 +326,6 @@ install-headers: realfile=$(srcdir)/objc/$${file}; \ $(INSTALL_DATA) $${realfile} $(DESTDIR)$(libsubdir)/$(includedirname)/objc; \ done - $(multi_basedir)/mkinstalldirs $(DESTDIR)$(libsubdir)/$(includedirname)/objc/deprecated - for file in $(OBJC_DEPRECATED_H); do \ - realfile=$(srcdir)/objc/deprecated/$${file}; \ - $(INSTALL_DATA) $${realfile} $(DESTDIR)$(libsubdir)/$(includedirname)/objc/deprecated; \ - done check uninstall install-strip dist installcheck installdirs: diff --git a/libobjc/Object.m b/libobjc/Object.m index 224c0aa66b..552acb037f 100644 --- a/libobjc/Object.m +++ b/libobjc/Object.m @@ -24,17 +24,14 @@ see the files COPYING3 and COPYING.RUNTIME respectively. If not, see <http://www.gnu.org/licenses/>. */ #include "objc-private/common.h" -#include <stdarg.h> -#include <errno.h> #include "objc/Object.h" -#include "objc/Protocol.h" -#include "objc/objc-api.h" +#include "objc/runtime.h" @implementation Object - (Class)class { - return object_get_class (self); + return object_getClass (self); } - (BOOL)isEqual: (id)anObject @@ -43,347 +40,3 @@ see the files COPYING3 and COPYING.RUNTIME respectively. If not, see } @end - -/* The following methods were deprecated in GCC 4.6.0 and will be - removed in the next GCC release. */ -@implementation Object (Deprecated) - -+ initialize -{ - return self; -} - -- init -{ - return self; -} - -+ new -{ - return [[self alloc] init]; -} - -+ alloc -{ - return class_create_instance(self); -} - -- free -{ - return object_dispose(self); -} - -- copy -{ - return [[self shallowCopy] deepen]; -} - -- shallowCopy -{ - return object_copy(self); -} - -- deepen -{ - return self; -} - -- deepCopy -{ - return [self copy]; -} - -- (Class)superClass -{ - return object_get_super_class(self); -} - -- (MetaClass)metaClass -{ - return object_get_meta_class(self); -} - -- (const char *)name -{ - return object_get_class_name(self); -} - -- self -{ - return self; -} - -- (unsigned int)hash -{ - return (size_t)self; -} - -- (int)compare:(id)anotherObject; -{ - if ([self isEqual:anotherObject]) - return 0; - // Ordering objects by their address is pretty useless, - // so subclasses should override this is some useful way. - else if ((id)self > anotherObject) - return 1; - else - return -1; -} - -- (BOOL)isMetaClass -{ - return NO; -} - -- (BOOL)isClass -{ - return object_is_class(self); -} - -- (BOOL)isInstance -{ - return object_is_instance(self); -} - -- (BOOL)isKindOf:(Class)aClassObject -{ - Class class; - - for (class = self->isa; class!=Nil; class = class_get_super_class(class)) - if (class==aClassObject) - return YES; - return NO; -} - -- (BOOL)isMemberOf:(Class)aClassObject -{ - return self->isa==aClassObject; -} - -- (BOOL)isKindOfClassNamed:(const char *)aClassName -{ - Class class; - - if (aClassName!=NULL) - for (class = self->isa; class!=Nil; class = class_get_super_class(class)) - if (!strcmp(class_get_class_name(class), aClassName)) - return YES; - return NO; -} - -- (BOOL)isMemberOfClassNamed:(const char *)aClassName -{ - return ((aClassName!=NULL) - &&!strcmp(class_get_class_name(self->isa), aClassName)); -} - -+ (BOOL)instancesRespondTo:(SEL)aSel -{ - return class_get_instance_method(self, aSel) != (Method_t)0; -} - -- (BOOL)respondsTo:(SEL)aSel -{ - return ((object_is_instance(self) - ?class_get_instance_method(self->isa, aSel) - :class_get_class_method(self->isa, aSel)) != (Method_t)0); -} - -+ (IMP)instanceMethodFor:(SEL)aSel -{ - return method_get_imp(class_get_instance_method(self, aSel)); -} - -// Indicates if the receiving class or instance conforms to the given protocol -// not usually overridden by subclasses -// -// Modified 9/5/94 to always search the class object's protocol list, rather -// than the meta class. - -+ (BOOL) conformsTo: (Protocol*)aProtocol -{ - size_t i; - struct objc_protocol_list* proto_list; - id parent; - - for (proto_list = ((Class)self)->protocols; - proto_list; proto_list = proto_list->next) - { - for (i=0; i < proto_list->count; i++) - { - if ([proto_list->list[i] conformsTo: aProtocol]) - return YES; - } - } - - if ((parent = [self superClass])) - return [parent conformsTo: aProtocol]; - else - return NO; -} - -- (BOOL) conformsTo: (Protocol*)aProtocol -{ - return [[self class] conformsTo:aProtocol]; -} - -- (IMP)methodFor:(SEL)aSel -{ - return (method_get_imp(object_is_instance(self) - ?class_get_instance_method(self->isa, aSel) - :class_get_class_method(self->isa, aSel))); -} - -+ (struct objc_method_description *)descriptionForInstanceMethod:(SEL)aSel -{ - return ((struct objc_method_description *) - class_get_instance_method(self, aSel)); -} - -- (struct objc_method_description *)descriptionForMethod:(SEL)aSel -{ - return ((struct objc_method_description *) - (object_is_instance(self) - ?class_get_instance_method(self->isa, aSel) - :class_get_class_method(self->isa, aSel))); -} - -- perform:(SEL)aSel -{ - IMP msg = objc_msg_lookup(self, aSel); - if (!msg) - return [self error:"invalid selector passed to %s", sel_get_name(_cmd)]; - return (*msg)(self, aSel); -} - -- perform:(SEL)aSel with:anObject -{ - IMP msg = objc_msg_lookup(self, aSel); - if (!msg) - return [self error:"invalid selector passed to %s", sel_get_name(_cmd)]; - return (*msg)(self, aSel, anObject); -} - -- perform:(SEL)aSel with:anObject1 with:anObject2 -{ - IMP msg = objc_msg_lookup(self, aSel); - if (!msg) - return [self error:"invalid selector passed to %s", sel_get_name(_cmd)]; - return (*msg)(self, aSel, anObject1, anObject2); -} - -- (retval_t)forward:(SEL)aSel :(arglist_t)argFrame -{ - (void) argFrame; /* UNUSED */ - return (retval_t)[self doesNotRecognize: aSel]; -} - -- (retval_t)performv:(SEL)aSel :(arglist_t)argFrame -{ - return objc_msg_sendv(self, aSel, argFrame); -} - -+ poseAs:(Class)aClassObject -{ - return class_pose_as(self, aClassObject); -} - -- (Class)transmuteClassTo:(Class)aClassObject -{ - if (object_is_instance(self)) - if (class_is_class(aClassObject)) - if (class_get_instance_size(aClassObject)==class_get_instance_size(isa)) - if ([self isKindOf:aClassObject]) - { - Class old_isa = isa; - isa = aClassObject; - return old_isa; - } - return nil; -} - -- subclassResponsibility:(SEL)aSel -{ - return [self error:"subclass should override %s", sel_get_name(aSel)]; -} - -- notImplemented:(SEL)aSel -{ - return [self error:"method %s not implemented", sel_get_name(aSel)]; -} - -- shouldNotImplement:(SEL)aSel -{ - return [self error:"%s should not implement %s", - object_get_class_name(self), sel_get_name(aSel)]; -} - -- doesNotRecognize:(SEL)aSel -{ - return [self error:"%s does not recognize %s", - object_get_class_name(self), sel_get_name(aSel)]; -} - -- error:(const char *)aString, ... -{ -#define FMT "error: %s (%s)\n%s\n" - char fmt[(strlen((char*)FMT)+strlen((char*)object_get_class_name(self)) - +((aString!=NULL)?strlen((char*)aString):0)+8)]; - va_list ap; - - sprintf(fmt, FMT, object_get_class_name(self), - object_is_instance(self)?"instance":"class", - (aString!=NULL)?aString:""); - va_start(ap, aString); - objc_verror(self, OBJC_ERR_UNKNOWN, fmt, ap); - va_end(ap); - return nil; -#undef FMT -} - -+ (int)version -{ - return class_get_version(self); -} - -+ setVersion:(int)aVersion -{ - class_set_version(self, aVersion); - return self; -} - -+ (int)streamVersion: (TypedStream*)aStream -{ - if (aStream->mode == OBJC_READONLY) - return objc_get_stream_class_version (aStream, self); - else - return class_get_version (self); -} - -// These are used to write or read the instance variables -// declared in this particular part of the object. Subclasses -// should extend these, by calling [super read/write: aStream] -// before doing their own archiving. These methods are private, in -// the sense that they should only be called from subclasses. - -- read: (TypedStream*)aStream -{ - (void) aStream; /* UNUSED */ - // [super read: aStream]; - return self; -} - -- write: (TypedStream*)aStream -{ - (void) aStream; /* UNUSED */ - // [super write: aStream]; - return self; -} - -- awake -{ - // [super awake]; - return self; -} - -@end diff --git a/libobjc/Protocol.m b/libobjc/Protocol.m index 7c92075106..400f2a2087 100644 --- a/libobjc/Protocol.m +++ b/libobjc/Protocol.m @@ -24,7 +24,6 @@ see the files COPYING3 and COPYING.RUNTIME respectively. If not, see #include "objc-private/common.h" #include "objc/runtime.h" -#include "objc-private/module-abi-8.h" #include "objc/Protocol.h" @implementation Protocol @@ -33,88 +32,3 @@ see the files COPYING3 and COPYING.RUNTIME respectively. If not, see return protocol_isEqual (self, obj); } @end - -@implementation Protocol (Deprecated) - -- (const char *)name -{ - return protocol_name; -} - -- (BOOL) conformsTo: (Protocol *)aProtocolObject -{ - return protocol_conformsToProtocol (self, aProtocolObject); -} - -- (struct objc_method_description *) descriptionForInstanceMethod:(SEL)aSel -{ - int i; - struct objc_protocol_list* proto_list; - struct objc_method_description *result; - - if (instance_methods) - for (i = 0; i < instance_methods->count; i++) - { - if (sel_isEqual (instance_methods->list[i].name, aSel)) - return &(instance_methods->list[i]); - } - - for (proto_list = protocol_list; proto_list; proto_list = proto_list->next) - { - size_t j; - for (j=0; j < proto_list->count; j++) - { - if ((result = [proto_list->list[j] - descriptionForInstanceMethod: aSel])) - return result; - } - } - - return NULL; -} - -- (struct objc_method_description *) descriptionForClassMethod:(SEL)aSel; -{ - int i; - struct objc_protocol_list* proto_list; - struct objc_method_description *result; - - if (class_methods) - for (i = 0; i < class_methods->count; i++) - { - if (sel_isEqual (class_methods->list[i].name, aSel)) - return &(class_methods->list[i]); - } - - for (proto_list = protocol_list; proto_list; proto_list = proto_list->next) - { - size_t j; - for (j=0; j < proto_list->count; j++) - { - if ((result = [proto_list->list[j] - descriptionForClassMethod: aSel])) - return result; - } - } - - return NULL; -} - -- (unsigned) hash -{ - /* Compute a hash of the protocol_name; use the same hash algorithm - that we use for class names; protocol names and class names are - somewhat similar types of string spaces. */ - int hash = 0, index; - - for (index = 0; protocol_name[index] != '\0'; index++) - { - hash = (hash << 4) ^ (hash >> 28) ^ protocol_name[index]; - } - - hash = (hash ^ (hash >> 10) ^ (hash >> 20)); - - return hash; -} - -@end diff --git a/libobjc/archive.c b/libobjc/archive.c deleted file mode 100644 index f691b13b60..0000000000 --- a/libobjc/archive.c +++ /dev/null @@ -1,1656 +0,0 @@ - /* GNU Objective C Runtime archiving - Copyright (C) 1993, 1995, 1996, 1997, 2002, 2004, 2009, - 2010 Free Software Foundation, Inc. - Contributed by Kresten Krab Thorup - -This file is part of GCC. - -GCC 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 3, or (at your option) any later version. - -GCC 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. - -Under Section 7 of GPL version 3, you are granted additional -permissions described in the GCC Runtime Library Exception, version -3.1, as published by the Free Software Foundation. - -You should have received a copy of the GNU General Public License and -a copy of the GCC Runtime Library Exception along with this program; -see the files COPYING3 and COPYING.RUNTIME respectively. If not, see -<http://www.gnu.org/licenses/>. */ - -/* This file is entirely deprecated and will be removed. */ - -#include "objc-private/common.h" -#include "objc-private/error.h" -#include "tconfig.h" -#include "objc/objc-api.h" -#include "objc/hash.h" -#include "objc/objc-list.h" -#include "objc-private/runtime.h" -#include "objc/typedstream.h" -#include "objc/encoding.h" -#include <stdlib.h> - -extern int fflush (FILE *); - -#define ROUND(V, A) \ - ({ typeof (V) __v = (V); typeof (A) __a = (A); \ - __a * ((__v + __a - 1)/__a); }) - -#define PTR2LONG(P) (((char *) (P))-(char *) 0) -#define LONG2PTR(L) (((char *) 0) + (L)) - -/* Declare some functions... */ - -static int -objc_read_class (struct objc_typed_stream *stream, Class *class); - -int objc_sizeof_type (const char *type); - -static int -objc_write_use_common (struct objc_typed_stream *stream, unsigned long key); - -static int -objc_write_register_common (struct objc_typed_stream *stream, - unsigned long key); - -static int -objc_write_class (struct objc_typed_stream *stream, - struct objc_class *class); - -const char *objc_skip_type (const char *type); - -static void __objc_finish_write_root_object (struct objc_typed_stream *); -static void __objc_finish_read_root_object (struct objc_typed_stream *); - -static inline int -__objc_code_unsigned_char (unsigned char *buf, unsigned char val) -{ - if ((val&_B_VALUE) == val) - { - buf[0] = val|_B_SINT; - return 1; - } - else - { - buf[0] = _B_NINT|0x01; - buf[1] = val; - return 2; - } -} - -int -objc_write_unsigned_char (struct objc_typed_stream *stream, - unsigned char value) -{ - unsigned char buf[sizeof (unsigned char) + 1]; - int len = __objc_code_unsigned_char (buf, value); - return (*stream->write) (stream->physical, (char*)buf, len); -} - -static inline int -__objc_code_char (unsigned char *buf, signed char val) -{ - if (val >= 0) - return __objc_code_unsigned_char (buf, val); - else - { - buf[0] = _B_NINT|_B_SIGN|0x01; - buf[1] = -val; - return 2; - } -} - -int -objc_write_char (struct objc_typed_stream *stream, signed char value) -{ - unsigned char buf[sizeof (char) + 1]; - int len = __objc_code_char (buf, value); - return (*stream->write) (stream->physical, (char*)buf, len); -} - -static inline int -__objc_code_unsigned_short (unsigned char *buf, unsigned short val) -{ - if ((val&_B_VALUE) == val) - { - buf[0] = val|_B_SINT; - return 1; - } - else - { - int c, b; - - buf[0] = _B_NINT; - - for (c = sizeof (short); c != 0; c -= 1) - if (((val >> (8*(c - 1)))%0x100) != 0) - break; - - buf[0] |= c; - - for (b = 1; c != 0; c--, b++) - { - buf[b] = (val >> (8*(c - 1)))%0x100; - } - - return b; - } -} - -int -objc_write_unsigned_short (struct objc_typed_stream *stream, - unsigned short value) -{ - unsigned char buf[sizeof (unsigned short) + 1]; - int len = __objc_code_unsigned_short (buf, value); - return (*stream->write) (stream->physical, (char*)buf, len); -} - -static inline int -__objc_code_short (unsigned char *buf, short val) -{ - int sign = (val < 0); - int size = __objc_code_unsigned_short (buf, sign ? -val : val); - if (sign) - buf[0] |= _B_SIGN; - return size; -} - -int -objc_write_short (struct objc_typed_stream *stream, short value) -{ - unsigned char buf[sizeof (short) + 1]; - int len = __objc_code_short (buf, value); - return (*stream->write) (stream->physical, (char*)buf, len); -} - - -static inline int -__objc_code_unsigned_int (unsigned char *buf, unsigned int val) -{ - if ((val&_B_VALUE) == val) - { - buf[0] = val|_B_SINT; - return 1; - } - else - { - int c, b; - - buf[0] = _B_NINT; - - for (c = sizeof (int); c != 0; c -= 1) - if (((val >> (8*(c - 1)))%0x100) != 0) - break; - - buf[0] |= c; - - for (b = 1; c != 0; c--, b++) - { - buf[b] = (val >> (8*(c-1)))%0x100; - } - - return b; - } -} - -int -objc_write_unsigned_int (struct objc_typed_stream *stream, unsigned int value) -{ - unsigned char buf[sizeof (unsigned int) + 1]; - int len = __objc_code_unsigned_int (buf, value); - return (*stream->write) (stream->physical, (char*)buf, len); -} - -static inline int -__objc_code_int (unsigned char *buf, int val) -{ - int sign = (val < 0); - int size = __objc_code_unsigned_int (buf, sign ? -val : val); - if (sign) - buf[0] |= _B_SIGN; - return size; -} - -int -objc_write_int (struct objc_typed_stream *stream, int value) -{ - unsigned char buf[sizeof (int) + 1]; - int len = __objc_code_int (buf, value); - return (*stream->write) (stream->physical, (char*)buf, len); -} - -static inline int -__objc_code_unsigned_long (unsigned char *buf, unsigned long val) -{ - if ((val&_B_VALUE) == val) - { - buf[0] = val|_B_SINT; - return 1; - } - else - { - int c, b; - - buf[0] = _B_NINT; - - for (c = sizeof (long); c != 0; c -= 1) - if (((val >> (8*(c - 1)))%0x100) != 0) - break; - - buf[0] |= c; - - for (b = 1; c != 0; c--, b++) - { - buf[b] = (val >> (8*(c - 1)))%0x100; - } - - return b; - } -} - -int -objc_write_unsigned_long (struct objc_typed_stream *stream, - unsigned long value) -{ - unsigned char buf[sizeof (unsigned long) + 1]; - int len = __objc_code_unsigned_long (buf, value); - return (*stream->write) (stream->physical, (char*)buf, len); -} - -static inline int -__objc_code_long (unsigned char *buf, long val) -{ - int sign = (val < 0); - int size = __objc_code_unsigned_long (buf, sign ? -val : val); - if (sign) - buf[0] |= _B_SIGN; - return size; -} - -int -objc_write_long (struct objc_typed_stream *stream, long value) -{ - unsigned char buf[sizeof (long) + 1]; - int len = __objc_code_long (buf, value); - return (*stream->write) (stream->physical, (char*)buf, len); -} - - -int -objc_write_string (struct objc_typed_stream *stream, - const unsigned char *string, unsigned int nbytes) -{ - unsigned char buf[sizeof (unsigned int) + 1]; - int len = __objc_code_unsigned_int (buf, nbytes); - - if ((buf[0]&_B_CODE) == _B_SINT) - buf[0] = (buf[0]&_B_VALUE)|_B_SSTR; - - else /* _B_NINT */ - buf[0] = (buf[0]&_B_VALUE)|_B_NSTR; - - if ((*stream->write) (stream->physical, (char*)buf, len) != 0) - return (*stream->write) (stream->physical, (char*)string, nbytes); - else - return 0; -} - -int -objc_write_string_atomic (struct objc_typed_stream *stream, - unsigned char *string, unsigned int nbytes) -{ - unsigned long key; - if ((key = PTR2LONG(objc_hash_value_for_key (stream->stream_table, string)))) - return objc_write_use_common (stream, key); - else - { - int length; - objc_hash_add (&stream->stream_table, - LONG2PTR(key=PTR2LONG(string)), string); - if ((length = objc_write_register_common (stream, key))) - return objc_write_string (stream, string, nbytes); - return length; - } -} - -static int -objc_write_register_common (struct objc_typed_stream *stream, - unsigned long key) -{ - unsigned char buf[sizeof (unsigned long)+2]; - int len = __objc_code_unsigned_long (buf + 1, key); - if (len == 1) - { - buf[0] = _B_RCOMM|0x01; - buf[1] &= _B_VALUE; - return (*stream->write) (stream->physical, (char*)buf, len + 1); - } - else - { - buf[1] = (buf[1]&_B_VALUE)|_B_RCOMM; - return (*stream->write) (stream->physical, (char*)buf + 1, len); - } -} - -static int -objc_write_use_common (struct objc_typed_stream *stream, unsigned long key) -{ - unsigned char buf[sizeof (unsigned long)+2]; - int len = __objc_code_unsigned_long (buf + 1, key); - if (len == 1) - { - buf[0] = _B_UCOMM|0x01; - buf[1] &= _B_VALUE; - return (*stream->write) (stream->physical, (char*)buf, 2); - } - else - { - buf[1] = (buf[1]&_B_VALUE)|_B_UCOMM; - return (*stream->write) (stream->physical, (char*)buf + 1, len); - } -} - -static inline int -__objc_write_extension (struct objc_typed_stream *stream, unsigned char code) -{ - if (code <= _B_VALUE) - { - unsigned char buf = code|_B_EXT; - return (*stream->write) (stream->physical, (char*)&buf, 1); - } - else - { - _objc_abort ("__objc_write_extension: bad opcode %c\n", code); - return -1; - } -} - -int -__objc_write_object (struct objc_typed_stream *stream, id object) -{ - unsigned char buf = '\0'; - SEL write_sel = sel_get_any_uid ("write:"); - if (object) - { - __objc_write_extension (stream, _BX_OBJECT); - objc_write_class (stream, object->class_pointer); - (*objc_msg_lookup (object, write_sel)) (object, write_sel, stream); - return (*stream->write) (stream->physical, (char*)&buf, 1); - } - else - return objc_write_use_common (stream, 0); -} - -int -objc_write_object_reference (struct objc_typed_stream *stream, id object) -{ - unsigned long key; - if ((key = PTR2LONG(objc_hash_value_for_key (stream->object_table, object)))) - return objc_write_use_common (stream, key); - - __objc_write_extension (stream, _BX_OBJREF); - return objc_write_unsigned_long (stream, PTR2LONG (object)); -} - -int -objc_write_root_object (struct objc_typed_stream *stream, id object) -{ - int len = 0; - if (stream->writing_root_p) - _objc_abort ("objc_write_root_object called recursively"); - else - { - stream->writing_root_p = 1; - __objc_write_extension (stream, _BX_OBJROOT); - if ((len = objc_write_object (stream, object))) - __objc_finish_write_root_object (stream); - stream->writing_root_p = 0; - } - return len; -} - -int -objc_write_object (struct objc_typed_stream *stream, id object) -{ - unsigned long key; - if ((key = PTR2LONG(objc_hash_value_for_key (stream->object_table, object)))) - return objc_write_use_common (stream, key); - - else if (object == nil) - return objc_write_use_common (stream, 0); - - else - { - int length; - objc_hash_add (&stream->object_table, - LONG2PTR(key=PTR2LONG(object)), object); - if ((length = objc_write_register_common (stream, key))) - return __objc_write_object (stream, object); - return length; - } -} - -int -__objc_write_class (struct objc_typed_stream *stream, struct objc_class *class) -{ - __objc_write_extension (stream, _BX_CLASS); - objc_write_string_atomic (stream, (unsigned char *) class->name, - strlen ((char *) class->name)); - return objc_write_unsigned_long (stream, class->version); -} - - -static int -objc_write_class (struct objc_typed_stream *stream, - struct objc_class *class) -{ - unsigned long key; - if ((key = PTR2LONG(objc_hash_value_for_key (stream->stream_table, class)))) - return objc_write_use_common (stream, key); - else - { - int length; - objc_hash_add (&stream->stream_table, - LONG2PTR(key = PTR2LONG(class)), class); - if ((length = objc_write_register_common (stream, key))) - return __objc_write_class (stream, class); - return length; - } -} - - -int -__objc_write_selector (struct objc_typed_stream *stream, SEL selector) -{ - const char *sel_name; - __objc_write_extension (stream, _BX_SEL); - /* to handle NULL selectors */ - if ((SEL)0 == selector) - return objc_write_string (stream, (unsigned char*)"", 0); - sel_name = sel_get_name (selector); - return objc_write_string (stream, (unsigned char*)sel_name, strlen ((char*)sel_name)); -} - -int -objc_write_selector (struct objc_typed_stream *stream, SEL 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(objc_hash_value_for_key (stream->stream_table, - sel_name)))) - return objc_write_use_common (stream, key); - else - { - int length; - objc_hash_add (&stream->stream_table, - LONG2PTR(key = PTR2LONG(sel_name)), (char *) sel_name); - if ((length = objc_write_register_common (stream, key))) - return __objc_write_selector (stream, selector); - return length; - } -} - - - -/* -** Read operations -*/ - -int -objc_read_char (struct objc_typed_stream *stream, char *val) -{ - unsigned char buf; - int len; - len = (*stream->read) (stream->physical, (char*)&buf, 1); - if (len != 0) - { - if ((buf & _B_CODE) == _B_SINT) - (*val) = (buf & _B_VALUE); - - else if ((buf & _B_NUMBER) == 1) - { - len = (*stream->read) (stream->physical, val, 1); - if (buf&_B_SIGN) - (*val) = -1 * (*val); - } - - else - _objc_abort ("expected 8bit signed int, got %dbit int", - (int) (buf&_B_NUMBER)*8); - } - return len; -} - - -int -objc_read_unsigned_char (struct objc_typed_stream *stream, unsigned char *val) -{ - unsigned char buf; - int len; - if ((len = (*stream->read) (stream->physical, (char*)&buf, 1))) - { - if ((buf & _B_CODE) == _B_SINT) - (*val) = (buf & _B_VALUE); - - else if ((buf & _B_NUMBER) == 1) - len = (*stream->read) (stream->physical, (char*)val, 1); - - else - _objc_abort ("expected 8bit unsigned int, got %dbit int", - (int) (buf&_B_NUMBER)*8); - } - return len; -} - -int -objc_read_short (struct objc_typed_stream *stream, short *value) -{ - unsigned char buf[sizeof (short) + 1]; - int len; - if ((len = (*stream->read) (stream->physical, (char*)buf, 1))) - { - if ((buf[0] & _B_CODE) == _B_SINT) - (*value) = (buf[0] & _B_VALUE); - - else - { - int pos = 1; - int nbytes = buf[0] & _B_NUMBER; - if (nbytes > (int) sizeof (short)) - _objc_abort ("expected short, got bigger (%dbits)", nbytes*8); - len = (*stream->read) (stream->physical, (char*)buf + 1, nbytes); - (*value) = 0; - while (pos <= nbytes) - (*value) = ((*value)*0x100) + buf[pos++]; - if (buf[0] & _B_SIGN) - (*value) = -(*value); - } - } - return len; -} - -int -objc_read_unsigned_short (struct objc_typed_stream *stream, - unsigned short *value) -{ - unsigned char buf[sizeof (unsigned short) + 1]; - int len; - if ((len = (*stream->read) (stream->physical, (char*)buf, 1))) - { - if ((buf[0] & _B_CODE) == _B_SINT) - (*value) = (buf[0] & _B_VALUE); - - else - { - int pos = 1; - int nbytes = buf[0] & _B_NUMBER; - if (nbytes > (int) sizeof (short)) - _objc_abort ("expected short, got int or bigger"); - len = (*stream->read) (stream->physical, (char*)buf + 1, nbytes); - (*value) = 0; - while (pos <= nbytes) - (*value) = ((*value)*0x100) + buf[pos++]; - } - } - return len; -} - - -int -objc_read_int (struct objc_typed_stream *stream, int *value) -{ - unsigned char buf[sizeof (int) + 1]; - int len; - if ((len = (*stream->read) (stream->physical, (char*)buf, 1))) - { - if ((buf[0] & _B_CODE) == _B_SINT) - (*value) = (buf[0] & _B_VALUE); - - else - { - int pos = 1; - int nbytes = buf[0] & _B_NUMBER; - if (nbytes > (int) sizeof (int)) - _objc_abort ("expected int, got bigger"); - len = (*stream->read) (stream->physical, (char*)buf + 1, nbytes); - (*value) = 0; - while (pos <= nbytes) - (*value) = ((*value)*0x100) + buf[pos++]; - if (buf[0] & _B_SIGN) - (*value) = -(*value); - } - } - return len; -} - -int -objc_read_long (struct objc_typed_stream *stream, long *value) -{ - unsigned char buf[sizeof (long) + 1]; - int len; - if ((len = (*stream->read) (stream->physical, (char*)buf, 1))) - { - if ((buf[0] & _B_CODE) == _B_SINT) - (*value) = (buf[0] & _B_VALUE); - - else - { - int pos = 1; - int nbytes = buf[0] & _B_NUMBER; - if (nbytes > (int) sizeof (long)) - _objc_abort ("expected long, got bigger"); - len = (*stream->read) (stream->physical, (char*)buf + 1, nbytes); - (*value) = 0; - while (pos <= nbytes) - (*value) = ((*value)*0x100) + buf[pos++]; - if (buf[0] & _B_SIGN) - (*value) = -(*value); - } - } - return len; -} - -int -__objc_read_nbyte_uint (struct objc_typed_stream *stream, - unsigned int nbytes, unsigned int *val) -{ - int len; - unsigned int pos = 0; - unsigned char buf[sizeof (unsigned int) + 1]; - - if (nbytes > sizeof (int)) - _objc_abort ("expected int, got bigger"); - - len = (*stream->read) (stream->physical, (char*)buf, nbytes); - (*val) = 0; - while (pos < nbytes) - (*val) = ((*val)*0x100) + buf[pos++]; - return len; -} - - -int -objc_read_unsigned_int (struct objc_typed_stream *stream, - unsigned int *value) -{ - unsigned char buf[sizeof (unsigned int) + 1]; - int len; - if ((len = (*stream->read) (stream->physical, (char*)buf, 1))) - { - if ((buf[0] & _B_CODE) == _B_SINT) - (*value) = (buf[0] & _B_VALUE); - - else - len = __objc_read_nbyte_uint (stream, (buf[0] & _B_VALUE), value); - - } - return len; -} - -int -__objc_read_nbyte_ulong (struct objc_typed_stream *stream, - unsigned int nbytes, unsigned long *val) -{ - int len; - unsigned int pos = 0; - unsigned char buf[sizeof (unsigned long) + 1]; - - if (nbytes > sizeof (long)) - _objc_abort ("expected long, got bigger"); - - len = (*stream->read) (stream->physical, (char*)buf, nbytes); - (*val) = 0; - while (pos < nbytes) - (*val) = ((*val)*0x100) + buf[pos++]; - return len; -} - - -int -objc_read_unsigned_long (struct objc_typed_stream *stream, - unsigned long *value) -{ - unsigned char buf[sizeof (unsigned long) + 1]; - int len; - if ((len = (*stream->read) (stream->physical, (char*)buf, 1))) - { - if ((buf[0] & _B_CODE) == _B_SINT) - (*value) = (buf[0] & _B_VALUE); - - else - len = __objc_read_nbyte_ulong (stream, (buf[0] & _B_VALUE), value); - - } - return len; -} - -int -objc_read_string (struct objc_typed_stream *stream, - char **string) -{ - unsigned char buf[sizeof (unsigned int) + 1]; - int len; - if ((len = (*stream->read) (stream->physical, (char*)buf, 1))) - { - unsigned long key = 0; - - if ((buf[0]&_B_CODE) == _B_RCOMM) /* register following */ - { - len = __objc_read_nbyte_ulong (stream, (buf[0] & _B_VALUE), &key); - len = (*stream->read) (stream->physical, (char*)buf, 1); - } - - switch (buf[0]&_B_CODE) { - case _B_SSTR: - { - int length = buf[0]&_B_VALUE; - (*string) = (char*)objc_malloc (length + 1); - if (key) - objc_hash_add (&stream->stream_table, LONG2PTR(key), *string); - len = (*stream->read) (stream->physical, *string, length); - (*string)[length] = '\0'; - } - break; - - case _B_UCOMM: - { - char *tmp; - len = __objc_read_nbyte_ulong (stream, (buf[0] & _B_VALUE), &key); - tmp = objc_hash_value_for_key (stream->stream_table, LONG2PTR (key)); - *string = objc_malloc (strlen (tmp) + 1); - strcpy (*string, tmp); - } - break; - - case _B_NSTR: - { - unsigned int nbytes = buf[0]&_B_VALUE; - len = __objc_read_nbyte_uint (stream, nbytes, &nbytes); - if (len) { - (*string) = (char*)objc_malloc (nbytes + 1); - if (key) - objc_hash_add (&stream->stream_table, LONG2PTR(key), *string); - len = (*stream->read) (stream->physical, *string, nbytes); - (*string)[nbytes] = '\0'; - } - } - break; - - default: - _objc_abort ("expected string, got opcode %c\n", (buf[0]&_B_CODE)); - } - } - - return len; -} - - -int -objc_read_object (struct objc_typed_stream *stream, id *object) -{ - unsigned char buf[sizeof (unsigned int)]; - int len; - if ((len = (*stream->read) (stream->physical, (char*)buf, 1))) - { - SEL read_sel = sel_get_any_uid ("read:"); - unsigned long key = 0; - - if ((buf[0]&_B_CODE) == _B_RCOMM) /* register common */ - { - len = __objc_read_nbyte_ulong (stream, (buf[0] & _B_VALUE), &key); - len = (*stream->read) (stream->physical, (char*)buf, 1); - } - - if (buf[0] == (_B_EXT | _BX_OBJECT)) - { - Class class; - - /* get class */ - len = objc_read_class (stream, &class); - - /* create instance */ - (*object) = class_create_instance (class); - - /* register? */ - if (key) - objc_hash_add (&stream->object_table, LONG2PTR(key), *object); - - /* send -read: */ - if (__objc_responds_to (*object, read_sel)) - (*get_imp (class, read_sel)) (*object, read_sel, stream); - - /* check null-byte */ - len = (*stream->read) (stream->physical, (char*)buf, 1); - if (buf[0] != '\0') - _objc_abort ("expected null-byte, got opcode %c", buf[0]); - } - - else if ((buf[0]&_B_CODE) == _B_UCOMM) - { - if (key) - _objc_abort ("cannot register use upcode..."); - len = __objc_read_nbyte_ulong (stream, (buf[0] & _B_VALUE), &key); - (*object) = objc_hash_value_for_key (stream->object_table, - LONG2PTR(key)); - } - - else if (buf[0] == (_B_EXT | _BX_OBJREF)) /* a forward reference */ - { - struct objc_list *other; - len = objc_read_unsigned_long (stream, &key); - other - = (struct objc_list *) objc_hash_value_for_key (stream->object_refs, - LONG2PTR(key)); - objc_hash_add (&stream->object_refs, LONG2PTR(key), - (void *)list_cons (object, other)); - } - - else if (buf[0] == (_B_EXT | _BX_OBJROOT)) /* a root object */ - { - if (key) - _objc_abort ("cannot register root object..."); - len = objc_read_object (stream, object); - __objc_finish_read_root_object (stream); - } - - else - _objc_abort ("expected object, got opcode %c", buf[0]); - } - return len; -} - -static int -objc_read_class (struct objc_typed_stream *stream, Class *class) -{ - unsigned char buf[sizeof (unsigned int)]; - int len; - if ((len = (*stream->read) (stream->physical, (char*)buf, 1))) - { - unsigned long key = 0; - - if ((buf[0]&_B_CODE) == _B_RCOMM) /* register following */ - { - len = __objc_read_nbyte_ulong (stream, (buf[0] & _B_VALUE), &key); - len = (*stream->read) (stream->physical, (char*)buf, 1); - } - - if (buf[0] == (_B_EXT | _BX_CLASS)) - { - char temp[1] = ""; - char *class_name = temp; - unsigned long version; - - /* get class */ - len = objc_read_string (stream, &class_name); - (*class) = objc_get_class (class_name); - objc_free (class_name); - - /* register */ - if (key) - objc_hash_add (&stream->stream_table, LONG2PTR(key), *class); - - objc_read_unsigned_long (stream, &version); - objc_hash_add (&stream->class_table, - (*class)->name, (void *) ((size_t) version)); - } - - else if ((buf[0]&_B_CODE) == _B_UCOMM) - { - if (key) - _objc_abort ("cannot register use upcode..."); - len = __objc_read_nbyte_ulong (stream, (buf[0] & _B_VALUE), &key); - *class = objc_hash_value_for_key (stream->stream_table, - LONG2PTR(key)); - if (! *class) - _objc_abort ("cannot find class for key %lu", key); - } - - else - _objc_abort ("expected class, got opcode %c", buf[0]); - } - return len; -} - -int -objc_read_selector (struct objc_typed_stream *stream, SEL* selector) -{ - unsigned char buf[sizeof (unsigned int)]; - int len; - if ((len = (*stream->read) (stream->physical, (char*)buf, 1))) - { - unsigned long key = 0; - - if ((buf[0]&_B_CODE) == _B_RCOMM) /* register following */ - { - len = __objc_read_nbyte_ulong (stream, (buf[0] & _B_VALUE), &key); - len = (*stream->read) (stream->physical, (char*)buf, 1); - } - - if (buf[0] == (_B_EXT|_BX_SEL)) /* selector! */ - { - char temp[1] = ""; - char *selector_name = temp; - - /* get selector */ - len = objc_read_string (stream, &selector_name); - /* To handle NULL selectors */ - if (0 == strlen (selector_name)) - { - (*selector) = (SEL)0; - return 0; - } - else - (*selector) = sel_get_any_uid (selector_name); - objc_free (selector_name); - - /* register */ - if (key) - objc_hash_add (&stream->stream_table, - LONG2PTR(key), (void *) *selector); - } - - else if ((buf[0]&_B_CODE) == _B_UCOMM) - { - if (key) - _objc_abort ("cannot register use upcode..."); - len = __objc_read_nbyte_ulong (stream, (buf[0] & _B_VALUE), &key); - (*selector) = objc_hash_value_for_key (stream->stream_table, - LONG2PTR(key)); - } - - else - _objc_abort ("expected selector, got opcode %c", buf[0]); - } - return len; -} - -/* -** USER LEVEL FUNCTIONS -*/ - -/* -** Write one object, encoded in TYPE and pointed to by DATA to the -** typed stream STREAM. -*/ - -int -objc_write_type (TypedStream *stream, const char *type, const void *data) -{ - switch (*type) { - case _C_ID: - return objc_write_object (stream, *(id *) data); - break; - - case _C_CLASS: - return objc_write_class (stream, *(Class *) data); - break; - - case _C_SEL: - return objc_write_selector (stream, *(SEL *) data); - break; - - case _C_CHR: - return objc_write_char (stream, *(signed char *) data); - break; - - case _C_UCHR: - return objc_write_unsigned_char (stream, *(unsigned char *) data); - break; - - case _C_SHT: - return objc_write_short (stream, *(short *) data); - break; - - case _C_USHT: - return objc_write_unsigned_short (stream, *(unsigned short *) data); - break; - - case _C_INT: - return objc_write_int (stream, *(int *) data); - break; - - case _C_UINT: - return objc_write_unsigned_int (stream, *(unsigned int *) data); - break; - - case _C_LNG: - return objc_write_long (stream, *(long *) data); - break; - - case _C_ULNG: - return objc_write_unsigned_long (stream, *(unsigned long *) data); - break; - - case _C_CHARPTR: - return objc_write_string (stream, - *(unsigned char **) data, strlen (*(char **) data)); - break; - - case _C_ATOM: - return objc_write_string_atomic (stream, *(unsigned char **) data, - strlen (*(char **) data)); - break; - - case _C_ARY_B: - { - int len = atoi (type + 1); - while (isdigit ((unsigned char) *++type)) - ; - return objc_write_array (stream, type, len, data); - } - break; - - case _C_STRUCT_B: - { - int acc_size = 0; - int align; - while (*type != _C_STRUCT_E && *type++ != '=') - ; /* skip "<name>=" */ - while (*type != _C_STRUCT_E) - { - align = objc_alignof_type (type); /* padd to alignment */ - acc_size = ROUND (acc_size, align); - objc_write_type (stream, type, ((char *) data) + acc_size); - acc_size += objc_sizeof_type (type); /* add component size */ - type = objc_skip_typespec (type); /* skip component */ - } - return 1; - } - - default: - { - _objc_abort ("objc_write_type: cannot parse typespec: %s\n", type); - return 0; - } - } -} - -/* -** Read one object, encoded in TYPE and pointed to by DATA to the -** typed stream STREAM. DATA specifies the address of the types to -** read. Expected type is checked against the type actually present -** on the stream. -*/ - -int -objc_read_type(TypedStream *stream, const char *type, void *data) -{ - char c; - switch (c = *type) { - case _C_ID: - return objc_read_object (stream, (id*)data); - break; - - case _C_CLASS: - return objc_read_class (stream, (Class*)data); - break; - - case _C_SEL: - return objc_read_selector (stream, (SEL*)data); - break; - - case _C_CHR: - return objc_read_char (stream, (char*)data); - break; - - case _C_UCHR: - return objc_read_unsigned_char (stream, (unsigned char*)data); - break; - - case _C_SHT: - return objc_read_short (stream, (short*)data); - break; - - case _C_USHT: - return objc_read_unsigned_short (stream, (unsigned short*)data); - break; - - case _C_INT: - return objc_read_int (stream, (int*)data); - break; - - case _C_UINT: - return objc_read_unsigned_int (stream, (unsigned int*)data); - break; - - case _C_LNG: - return objc_read_long (stream, (long*)data); - break; - - case _C_ULNG: - return objc_read_unsigned_long (stream, (unsigned long*)data); - break; - - case _C_CHARPTR: - case _C_ATOM: - return objc_read_string (stream, (char**)data); - break; - - case _C_ARY_B: - { - int len = atoi (type + 1); - while (isdigit ((unsigned char) *++type)) - ; - return objc_read_array (stream, type, len, data); - } - break; - - case _C_STRUCT_B: - { - int acc_size = 0; - int align; - while (*type != _C_STRUCT_E && *type++ != '=') - ; /* skip "<name>=" */ - while (*type != _C_STRUCT_E) - { - align = objc_alignof_type (type); /* padd to alignment */ - acc_size = ROUND (acc_size, align); - objc_read_type (stream, type, ((char*)data)+acc_size); - acc_size += objc_sizeof_type (type); /* add component size */ - type = objc_skip_typespec (type); /* skip component */ - } - return 1; - } - - default: - { - _objc_abort ("objc_read_type: cannot parse typespec: %s\n", type); - return 0; - } - } -} - -/* -** Write the object specified by the template TYPE to STREAM. Last -** arguments specify addresses of values to be written. It might -** seem surprising to specify values by address, but this is extremely -** convenient for copy-paste with objc_read_types calls. A more -** down-to-the-earth cause for this passing of addresses is that values -** of arbitrary size is not well supported in ANSI C for functions with -** variable number of arguments. -*/ - -int -objc_write_types (TypedStream *stream, const char *type, ...) -{ - va_list args; - const char *c; - int res = 0; - - va_start(args, type); - - for (c = type; *c; c = objc_skip_typespec (c)) - { - switch (*c) { - case _C_ID: - res = objc_write_object (stream, *va_arg (args, id*)); - break; - - case _C_CLASS: - res = objc_write_class (stream, *va_arg (args, Class*)); - break; - - case _C_SEL: - res = objc_write_selector (stream, *va_arg (args, SEL*)); - break; - - case _C_CHR: - res = objc_write_char (stream, *va_arg (args, char*)); - break; - - case _C_UCHR: - res = objc_write_unsigned_char (stream, - *va_arg (args, unsigned char*)); - break; - - case _C_SHT: - res = objc_write_short (stream, *va_arg (args, short*)); - break; - - case _C_USHT: - res = objc_write_unsigned_short (stream, - *va_arg (args, unsigned short*)); - break; - - case _C_INT: - res = objc_write_int(stream, *va_arg (args, int*)); - break; - - case _C_UINT: - res = objc_write_unsigned_int(stream, *va_arg (args, unsigned int*)); - break; - - case _C_LNG: - res = objc_write_long(stream, *va_arg (args, long*)); - break; - - case _C_ULNG: - res = objc_write_unsigned_long(stream, *va_arg (args, unsigned long*)); - break; - - case _C_CHARPTR: - { - unsigned char **str = va_arg (args, unsigned char **); - res = objc_write_string (stream, *str, strlen ((char*)*str)); - } - break; - - case _C_ATOM: - { - unsigned char **str = va_arg (args, unsigned char **); - res = objc_write_string_atomic (stream, *str, strlen ((char*)*str)); - } - break; - - case _C_ARY_B: - { - int len = atoi (c + 1); - const char *t = c; - while (isdigit ((unsigned char) *++t)) - ; - res = objc_write_array (stream, t, len, va_arg (args, void *)); - t = objc_skip_typespec (t); - if (*t != _C_ARY_E) - _objc_abort ("expected `]', got: %s", t); - } - break; - - default: - _objc_abort ("objc_write_types: cannot parse typespec: %s\n", type); - } - } - va_end(args); - return res; -} - - -/* -** Last arguments specify addresses of values to be read. Expected -** type is checked against the type actually present on the stream. -*/ - -int -objc_read_types(TypedStream *stream, const char *type, ...) -{ - va_list args; - const char *c; - int res = 0; - - va_start (args, type); - - for (c = type; *c; c = objc_skip_typespec(c)) - { - switch (*c) { - case _C_ID: - res = objc_read_object(stream, va_arg (args, id*)); - break; - - case _C_CLASS: - res = objc_read_class(stream, va_arg (args, Class*)); - break; - - case _C_SEL: - res = objc_read_selector(stream, va_arg (args, SEL*)); - break; - - case _C_CHR: - res = objc_read_char(stream, va_arg (args, char*)); - break; - - case _C_UCHR: - res = objc_read_unsigned_char(stream, va_arg (args, unsigned char*)); - break; - - case _C_SHT: - res = objc_read_short(stream, va_arg (args, short*)); - break; - - case _C_USHT: - res = objc_read_unsigned_short(stream, va_arg (args, unsigned short*)); - break; - - case _C_INT: - res = objc_read_int(stream, va_arg (args, int*)); - break; - - case _C_UINT: - res = objc_read_unsigned_int(stream, va_arg (args, unsigned int*)); - break; - - case _C_LNG: - res = objc_read_long(stream, va_arg (args, long*)); - break; - - case _C_ULNG: - res = objc_read_unsigned_long(stream, va_arg (args, unsigned long*)); - break; - - case _C_CHARPTR: - case _C_ATOM: - { - char **str = va_arg (args, char **); - res = objc_read_string (stream, str); - } - break; - - case _C_ARY_B: - { - int len = atoi (c + 1); - const char *t = c; - while (isdigit ((unsigned char) *++t)) - ; - res = objc_read_array (stream, t, len, va_arg (args, void *)); - t = objc_skip_typespec (t); - if (*t != _C_ARY_E) - _objc_abort ("expected `]', got: %s", t); - } - break; - - default: - _objc_abort ("objc_read_types: cannot parse typespec: %s\n", type); - } - } - va_end (args); - return res; -} - -/* -** Write an array of COUNT elements of TYPE from the memory address DATA. -** This is equivalent of objc_write_type (stream, "[N<type>]", data) -*/ - -int -objc_write_array (TypedStream *stream, const char *type, - int count, const void *data) -{ - int off = objc_sizeof_type(type); - const char *where = data; - - while (count-- > 0) - { - objc_write_type(stream, type, where); - where += off; - } - return 1; -} - -/* -** Read an array of COUNT elements of TYPE into the memory address -** DATA. The memory pointed to by data is supposed to be allocated -** by the callee. This is equivalent of -** objc_read_type (stream, "[N<type>]", data) -*/ - -int -objc_read_array (TypedStream *stream, const char *type, - int count, void *data) -{ - int off = objc_sizeof_type(type); - char *where = (char*)data; - - while (count-- > 0) - { - objc_read_type(stream, type, where); - where += off; - } - return 1; -} - -static int -__objc_fread (FILE *file, char *data, int len) -{ - return fread(data, len, 1, file); -} - -static int -__objc_fwrite (FILE *file, char *data, int len) -{ - return fwrite(data, len, 1, file); -} - -static int -__objc_feof (FILE *file) -{ - return feof(file); -} - -static int -__objc_no_write (FILE *file __attribute__ ((__unused__)), - const char *data __attribute__ ((__unused__)), - int len __attribute__ ((__unused__))) -{ - _objc_abort ("TypedStream not open for writing"); - return 0; -} - -static int -__objc_no_read (FILE *file __attribute__ ((__unused__)), - const char *data __attribute__ ((__unused__)), - int len __attribute__ ((__unused__))) -{ - _objc_abort ("TypedStream not open for reading"); - return 0; -} - -static int -__objc_read_typed_stream_signature (TypedStream *stream) -{ - char buffer[80]; - int pos = 0; - do - (*stream->read) (stream->physical, buffer+pos, 1); - while (buffer[pos++] != '\0') - ; - sscanf (buffer, "GNU TypedStream %d", &stream->version); - if (stream->version != OBJC_TYPED_STREAM_VERSION) - _objc_abort ("cannot handle TypedStream version %d", stream->version); - return 1; -} - -static int -__objc_write_typed_stream_signature (TypedStream *stream) -{ - char buffer[80]; - sprintf(buffer, "GNU TypedStream %d", OBJC_TYPED_STREAM_VERSION); - stream->version = OBJC_TYPED_STREAM_VERSION; - (*stream->write) (stream->physical, buffer, strlen (buffer) + 1); - return 1; -} - -static void __objc_finish_write_root_object(struct objc_typed_stream *stream) -{ - objc_hash_delete (stream->object_table); - stream->object_table = objc_hash_new (64, - (hash_func_type) objc_hash_ptr, - (compare_func_type) objc_compare_ptrs); -} - -static void __objc_finish_read_root_object(struct objc_typed_stream *stream) -{ - node_ptr node; - SEL awake_sel = sel_get_any_uid ("awake"); - cache_ptr free_list = objc_hash_new (64, - (hash_func_type) objc_hash_ptr, - (compare_func_type) objc_compare_ptrs); - - /* resolve object forward references */ - for (node = objc_hash_next (stream->object_refs, NULL); node; - node = objc_hash_next (stream->object_refs, node)) - { - struct objc_list *reflist = node->value; - const void *key = node->key; - id object = objc_hash_value_for_key (stream->object_table, key); - while (reflist) - { - *((id*) reflist->head) = object; - if (objc_hash_value_for_key (free_list,reflist) == NULL) - objc_hash_add (&free_list,reflist,reflist); - - reflist = reflist->tail; - } - } - - /* apply __objc_free to all objects stored in free_list */ - for (node = objc_hash_next (free_list, NULL); node; - node = objc_hash_next (free_list, node)) - objc_free ((void *) node->key); - - objc_hash_delete (free_list); - - /* empty object reference table */ - objc_hash_delete (stream->object_refs); - stream->object_refs = objc_hash_new (8, (hash_func_type) objc_hash_ptr, - (compare_func_type) objc_compare_ptrs); - - /* call -awake for all objects read */ - if (awake_sel) - { - for (node = objc_hash_next (stream->object_table, NULL); node; - node = objc_hash_next (stream->object_table, node)) - { - id object = node->value; - if (__objc_responds_to (object, awake_sel)) - (*objc_msg_lookup (object, awake_sel)) (object, awake_sel); - } - } - - /* empty object table */ - objc_hash_delete (stream->object_table); - stream->object_table = objc_hash_new(64, - (hash_func_type)objc_hash_ptr, - (compare_func_type)objc_compare_ptrs); -} - -/* -** Open the stream PHYSICAL in MODE -*/ - -TypedStream * -objc_open_typed_stream (FILE *physical, int mode) -{ - TypedStream *s = (TypedStream *) objc_malloc (sizeof (TypedStream)); - - s->mode = mode; - s->physical = physical; - s->stream_table = objc_hash_new (64, - (hash_func_type) objc_hash_ptr, - (compare_func_type) objc_compare_ptrs); - s->object_table = objc_hash_new (64, - (hash_func_type) objc_hash_ptr, - (compare_func_type) objc_compare_ptrs); - s->eof = (objc_typed_eof_func) __objc_feof; - s->flush = (objc_typed_flush_func) fflush; - s->writing_root_p = 0; - if (mode == OBJC_READONLY) - { - s->class_table - = objc_hash_new (8, (hash_func_type) objc_hash_string, - (compare_func_type) objc_compare_strings); - s->object_refs = objc_hash_new (8, (hash_func_type) objc_hash_ptr, - (compare_func_type) objc_compare_ptrs); - s->read = (objc_typed_read_func) __objc_fread; - s->write = (objc_typed_write_func) __objc_no_write; - __objc_read_typed_stream_signature (s); - } - else if (mode == OBJC_WRITEONLY) - { - s->class_table = 0; - s->object_refs = 0; - s->read = (objc_typed_read_func) __objc_no_read; - s->write = (objc_typed_write_func) __objc_fwrite; - __objc_write_typed_stream_signature (s); - } - else - { - objc_close_typed_stream (s); - return NULL; - } - s->type = OBJC_FILE_STREAM; - return s; -} - -/* -** Open the file named by FILE_NAME in MODE -*/ - -TypedStream* -objc_open_typed_stream_for_file (const char *file_name, int mode) -{ - FILE *file = NULL; - TypedStream *s; - - if (mode == OBJC_READONLY) - file = fopen (file_name, "r"); - else - file = fopen (file_name, "w"); - - if (file) - { - s = objc_open_typed_stream (file, mode); - if (s) - s->type |= OBJC_MANAGED_STREAM; - return s; - } - else - return NULL; -} - -/* -** Close STREAM freeing the structure it self. If it was opened with -** objc_open_typed_stream_for_file, the file will also be closed. -*/ - -void -objc_close_typed_stream (TypedStream *stream) -{ - if (stream->mode == OBJC_READONLY) - { - __objc_finish_read_root_object (stream); /* Just in case... */ - objc_hash_delete (stream->class_table); - objc_hash_delete (stream->object_refs); - } - - objc_hash_delete (stream->stream_table); - objc_hash_delete (stream->object_table); - - if (stream->type == (OBJC_MANAGED_STREAM | OBJC_FILE_STREAM)) - fclose ((FILE *)stream->physical); - - objc_free(stream); -} - -BOOL -objc_end_of_typed_stream (TypedStream *stream) -{ - return (*stream->eof) (stream->physical); -} - -void -objc_flush_typed_stream (TypedStream *stream) -{ - (*stream->flush) (stream->physical); -} - -long -objc_get_stream_class_version (TypedStream *stream, Class class) -{ - if (stream->class_table) - return PTR2LONG(objc_hash_value_for_key (stream->class_table, - class->name)); - else - return class_get_version (class); -} - diff --git a/libobjc/class.c b/libobjc/class.c index fb57293a1e..3b750829f3 100644 --- a/libobjc/class.c +++ b/libobjc/class.c @@ -92,6 +92,7 @@ see the files COPYING3 and COPYING.RUNTIME respectively. If not, see #include "objc-private/module-abi-8.h" /* For CLS_ISCLASS and similar. */ #include "objc-private/runtime.h" /* the kitchen sink */ #include "objc-private/sarray.h" /* For sarray_put_at_safe. */ +#include "objc-private/selector.h" /* For sarray_put_at_safe. */ #include <string.h> /* For memset */ /* We use a table which maps a class name to the corresponding class @@ -202,41 +203,6 @@ class_table_insert (const char *class_name, Class class_pointer) objc_mutex_unlock (__class_table_lock); } -/* Replace a class in the table (used only by poseAs:). */ -static void -class_table_replace (Class old_class_pointer, Class new_class_pointer) -{ - int hash; - class_node_ptr node; - - objc_mutex_lock (__class_table_lock); - - hash = 0; - node = class_table_array[hash]; - - while (hash < CLASS_TABLE_SIZE) - { - if (node == NULL) - { - hash++; - if (hash < CLASS_TABLE_SIZE) - node = class_table_array[hash]; - } - else - { - Class class1 = node->pointer; - - if (class1 == old_class_pointer) - node->pointer = new_class_pointer; - - node = node->next; - } - } - - objc_mutex_unlock (__class_table_lock); -} - - /* Get a class from the table. This does not need mutex protection. Currently, this function is called each time you call a static method, this is why it must be very fast. */ @@ -759,16 +725,6 @@ objc_disposeClassPair (Class class_) objc_free (class_); } -/* Traditional GNU Objective-C Runtime API. */ -/* Get the class object for the class named NAME. If NAME does not - identify a known class, the hook _objc_lookup_class is called. If - this fails, nil is returned. */ -Class -objc_lookup_class (const char *name) -{ - return objc_getClass (name); -} - /* Traditional GNU Objective-C Runtime API. Important: this method is called automatically by the compiler while messaging (if using the traditional ABI), so it is worth keeping it fast; don't make it @@ -801,36 +757,20 @@ objc_get_class (const char *name) return 0; } -MetaClass +/* This is used by the compiler too. */ +Class objc_get_meta_class (const char *name) { return objc_get_class (name)->class_pointer; } -/* This function provides a way to enumerate all the classes in the - executable. Pass *ENUM_STATE == NULL to start the enumeration. The - function will return 0 when there are no more classes. - For example: - id class; - void *es = NULL; - while ((class = objc_next_class (&es))) - ... do something with class; -*/ +/* This is not used by GCC, but the clang compiler seems to use it + when targetting the GNU runtime. That's wrong, but we have it to + be compatible. */ Class -objc_next_class (void **enum_state) +objc_lookup_class (const char *name) { - Class class; - - objc_mutex_lock (__objc_runtime_mutex); - - /* Make sure the table is there. */ - assert (__class_table_lock); - - class = class_table_next ((struct class_table_enumerator **) enum_state); - - objc_mutex_unlock (__objc_runtime_mutex); - - return class; + return objc_getClass (name); } /* This is used when the implementation of a method changes. It goes @@ -1014,10 +954,18 @@ class_getSuperclass (Class class_) if (class_ == Nil) return Nil; - /* Classes that are in construction are not resolved and can not be - resolved! */ + /* Classes that are in construction are not resolved, and still have + the class name (instead of a class pointer) in the + class_->super_class field. In that case we need to lookup the + superclass name to return the superclass. We can not resolve the + class until it is registered. */ if (CLS_IS_IN_CONSTRUCTION (class_)) - return Nil; + { + if (CLS_ISMETA (class_)) + return object_getClass ((id)objc_lookUpClass ((const char *)(class_->super_class))); + else + return objc_lookUpClass ((const char *)(class_->super_class)); + } /* If the class is not resolved yet, super_class would point to a string (the name of the super class) as opposed to the actual @@ -1056,83 +1004,3 @@ class_getInstanceSize (Class class_) return class_->instance_size; } -#define CLASSOF(c) ((c)->class_pointer) - -Class -class_pose_as (Class impostor, Class super_class) -{ - if (! CLS_ISRESOLV (impostor)) - __objc_resolve_class_links (); - - /* Preconditions */ - assert (impostor); - assert (super_class); - assert (impostor->super_class == super_class); - assert (CLS_ISCLASS (impostor)); - assert (CLS_ISCLASS (super_class)); - assert (impostor->instance_size == super_class->instance_size); - - { - Class *subclass = &(super_class->subclass_list); - - /* Move subclasses of super_class to impostor. */ - while (*subclass) - { - Class nextSub = (*subclass)->sibling_class; - - if (*subclass != impostor) - { - Class sub = *subclass; - - /* Classes */ - sub->sibling_class = impostor->subclass_list; - sub->super_class = impostor; - impostor->subclass_list = sub; - - /* It will happen that SUB is not a class object if it is - the top of the meta class hierarchy chain (root - meta-class objects inherit their class object). If - that is the case... don't mess with the meta-meta - class. */ - if (CLS_ISCLASS (sub)) - { - /* Meta classes */ - CLASSOF (sub)->sibling_class = - CLASSOF (impostor)->subclass_list; - CLASSOF (sub)->super_class = CLASSOF (impostor); - CLASSOF (impostor)->subclass_list = CLASSOF (sub); - } - } - - *subclass = nextSub; - } - - /* Set subclasses of superclass to be impostor only. */ - super_class->subclass_list = impostor; - CLASSOF (super_class)->subclass_list = CLASSOF (impostor); - - /* Set impostor to have no sibling classes. */ - impostor->sibling_class = 0; - CLASSOF (impostor)->sibling_class = 0; - } - - /* Check relationship of impostor and super_class is kept. */ - assert (impostor->super_class == super_class); - assert (CLASSOF (impostor)->super_class == CLASSOF (super_class)); - - /* This is how to update the lookup table. Regardless of what the - keys of the hashtable is, change all values that are superclass - into impostor. */ - - objc_mutex_lock (__objc_runtime_mutex); - - class_table_replace (super_class, impostor); - - objc_mutex_unlock (__objc_runtime_mutex); - - /* Next, we update the dispatch tables... */ - __objc_update_dispatch_table_for_class (CLASSOF (impostor)); - __objc_update_dispatch_table_for_class (impostor); - - return impostor; -} diff --git a/libobjc/config.h.in b/libobjc/config.h.in index d9c8172d25..c055e7c190 100644 --- a/libobjc/config.h.in +++ b/libobjc/config.h.in @@ -6,9 +6,6 @@ /* Define to 1 if you have the <dlfcn.h> header file. */ #undef HAVE_DLFCN_H -/* Define if the compiler has a thread header that is non single. */ -#undef HAVE_GTHR_DEFAULT - /* Define to 1 if you have the <inttypes.h> header file. */ #undef HAVE_INTTYPES_H diff --git a/libobjc/configure b/libobjc/configure index 8f670e132e..8c07356af0 100755 --- a/libobjc/configure +++ b/libobjc/configure @@ -656,6 +656,7 @@ host multi_basedir OBJC_BOEHM_GC_INCLUDES OBJC_BOEHM_GC +OBJC_GCFLAGS VERSION target_subdir host_subdir @@ -2273,7 +2274,7 @@ target_subdir=${target_noncanonical} # We need the following definitions because AC_PROG_LIBTOOL relies on them PACKAGE=libobjc # Version is pulled out to make it a bit easier to change using sed. -VERSION=3:0:0 +VERSION=4:0:0 # This works around the fact that libtool configuration may change LD @@ -2320,21 +2321,31 @@ $as_echo "$version_specific_libs" >&6; } if test "${enable_objc_gc+set}" = set; then : enableval=$enable_objc_gc; case $enable_objc_gc in no) + OBJC_GCFLAGS='' OBJC_BOEHM_GC='' OBJC_BOEHM_GC_INCLUDES='' ;; *) - OBJC_BOEHM_GC=libobjc_gc.la + OBJC_GCFLAGS='-DOBJC_WITH_GC=1' + OBJC_BOEHM_GC='libobjc_gc$(libsuffix).la' OBJC_BOEHM_GC_INCLUDES='-I$(top_srcdir)/../boehm-gc/include -I../boehm-gc/include' + case "${host}" in + alpha*-dec-osf*) + # boehm-gc headers include <pthread.h>, which needs to be compiled + # with -pthread on Tru64 UNIX. + OBJC_GCFLAGS="${OBJC_GCFLAGS} -pthread" + ;; + esac ;; esac else - OBJC_BOEHM_GC=''; OBJC_BOEHM_GC_INCLUDES='' + OBJC_GCFLAGS=''; OBJC_BOEHM_GC=''; OBJC_BOEHM_GC_INCLUDES='' fi + # ----------- # Directories # ----------- @@ -8797,7 +8808,7 @@ if test -z "$aix_libpath"; then aix_libpath="/usr/lib:/lib"; fi ;; # Unfortunately, older versions of FreeBSD 2 do not have this feature. - freebsd2*) + freebsd2.*) archive_cmds='$LD -Bshareable -o $lib $libobjs $deplibs $linker_flags' hardcode_direct=yes hardcode_minus_L=yes @@ -9713,7 +9724,7 @@ freebsd* | dragonfly*) objformat=`/usr/bin/objformat` else case $host_os in - freebsd[123]*) objformat=aout ;; + freebsd[23].*) objformat=aout ;; *) objformat=elf ;; esac fi @@ -9731,7 +9742,7 @@ freebsd* | dragonfly*) esac shlibpath_var=LD_LIBRARY_PATH case $host_os in - freebsd2*) + freebsd2.*) shlibpath_overrides_runpath=yes ;; freebsd3.[01]* | freebsdelf3.[01]*) @@ -10583,7 +10594,7 @@ else lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2 lt_status=$lt_dlunknown cat > conftest.$ac_ext <<_LT_EOF -#line 10586 "configure" +#line 10597 "configure" #include "confdefs.h" #if HAVE_DLFCN_H @@ -10689,7 +10700,7 @@ else lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2 lt_status=$lt_dlunknown cat > conftest.$ac_ext <<_LT_EOF -#line 10692 "configure" +#line 10703 "configure" #include "confdefs.h" #if HAVE_DLFCN_H @@ -11237,18 +11248,6 @@ done # Miscellanea # ----------- -{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for thread model used by GCC" >&5 -$as_echo_n "checking for thread model used by GCC... " >&6; } -target_thread_file=`$CC -v 2>&1 | sed -n 's/^Thread model: //p'` -{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $target_thread_file" >&5 -$as_echo "$target_thread_file" >&6; } - -if test $target_thread_file != single; then - -$as_echo "#define HAVE_GTHR_DEFAULT 1" >>confdefs.h - -fi - # Check if we have thread-local storage @@ -11472,7 +11471,7 @@ if test "${enable_sjlj_exceptions+set}" = set; then : enableval=$enable_sjlj_exceptions; : else cat > conftest.$ac_ext << EOF -#line 11475 "configure" +#line 11474 "configure" @interface Frob @end @implementation Frob diff --git a/libobjc/configure.ac b/libobjc/configure.ac index 494a289ec6..52599e6019 100644 --- a/libobjc/configure.ac +++ b/libobjc/configure.ac @@ -1,6 +1,6 @@ # Process this file with autoconf to produce a configure script. # Copyright 1994, 1995, 1996, 1997, 1998, 1999, 2001, 2002, 2003, 2004 -# 2005, 2006, 2009 Free Software Foundation, Inc. +# 2005, 2006, 2009, 2011 Free Software Foundation, Inc. # Originally contributed by Dave Love (d.love@dl.ac.uk). # #This file is part of GCC. @@ -27,7 +27,7 @@ GCC_TOPLEV_SUBDIRS # We need the following definitions because AC_PROG_LIBTOOL relies on them PACKAGE=libobjc # Version is pulled out to make it a bit easier to change using sed. -VERSION=3:0:0 +VERSION=4:0:0 AC_SUBST(VERSION) # This works around the fact that libtool configuration may change LD @@ -63,15 +63,25 @@ AC_ARG_ENABLE(objc-gc, the GNU Objective-C runtime.], [case $enable_objc_gc in no) + OBJC_GCFLAGS='' OBJC_BOEHM_GC='' OBJC_BOEHM_GC_INCLUDES='' ;; *) - OBJC_BOEHM_GC=libobjc_gc.la + OBJC_GCFLAGS='-DOBJC_WITH_GC=1' + OBJC_BOEHM_GC='libobjc_gc$(libsuffix).la' OBJC_BOEHM_GC_INCLUDES='-I$(top_srcdir)/../boehm-gc/include -I../boehm-gc/include' + case "${host}" in + alpha*-dec-osf*) + # boehm-gc headers include <pthread.h>, which needs to be compiled + # with -pthread on Tru64 UNIX. + OBJC_GCFLAGS="${OBJC_GCFLAGS} -pthread" + ;; + esac ;; esac], -[OBJC_BOEHM_GC=''; OBJC_BOEHM_GC_INCLUDES='']) +[OBJC_GCFLAGS=''; OBJC_BOEHM_GC=''; OBJC_BOEHM_GC_INCLUDES='']) +AC_SUBST(OBJC_GCFLAGS) AC_SUBST(OBJC_BOEHM_GC) AC_SUBST(OBJC_BOEHM_GC_INCLUDES) @@ -207,15 +217,6 @@ AC_CHECK_HEADERS(sched.h) # Miscellanea # ----------- -AC_MSG_CHECKING([for thread model used by GCC]) -target_thread_file=`$CC -v 2>&1 | sed -n 's/^Thread model: //p'` -AC_MSG_RESULT([$target_thread_file]) - -if test $target_thread_file != single; then - AC_DEFINE(HAVE_GTHR_DEFAULT, 1, - [Define if the compiler has a thread header that is non single.]) -fi - # Check if we have thread-local storage GCC_CHECK_TLS diff --git a/libobjc/encoding.c b/libobjc/encoding.c index 985ba0771b..bd8b67e0e8 100644 --- a/libobjc/encoding.c +++ b/libobjc/encoding.c @@ -993,98 +993,6 @@ method_getNumberOfArguments (struct objc_method *method) } } -int -method_get_number_of_arguments (struct objc_method *mth) -{ - return method_getNumberOfArguments (mth); -} - -/* Return the size of the argument block needed on the stack to invoke - the method MTH. This may be zero, if all arguments are passed in - registers. */ -int -method_get_sizeof_arguments (struct objc_method *mth) -{ - const char *type = objc_skip_typespec (mth->method_types); - return atoi (type); -} - -/* - Return a pointer to the next argument of ARGFRAME. type points to - the last argument. Typical use of this look like: - - { - char *datum, *type; - for (datum = method_get_first_argument (method, argframe, &type); - datum; datum = method_get_next_argument (argframe, &type)) - { - unsigned flags = objc_get_type_qualifiers (type); - type = objc_skip_type_qualifiers (type); - if (*type != _C_PTR) - [portal encodeData: datum ofType: type]; - else - { - if ((flags & _F_IN) == _F_IN) - [portal encodeData: *(char **) datum ofType: ++type]; - } - } - } -*/ -char * -method_get_next_argument (arglist_t argframe, const char **type) -{ - const char *t = objc_skip_argspec (*type); - - if (*t == '\0') - return 0; - - *type = t; - t = objc_skip_typespec (t); - - if (*t == '+') - return argframe->arg_regs + atoi (++t); - else - return argframe->arg_ptr + atoi (t); -} - -/* Return a pointer to the value of the first argument of the method - described in M with the given argumentframe ARGFRAME. The type - is returned in TYPE. type must be passed to successive calls of - method_get_next_argument. */ -char * -method_get_first_argument (struct objc_method *m, - arglist_t argframe, - const char **type) -{ - *type = m->method_types; - return method_get_next_argument (argframe, type); -} - -/* Return a pointer to the ARGth argument of the method - M from the frame ARGFRAME. The type of the argument - is returned in the value-result argument TYPE. */ -char * -method_get_nth_argument (struct objc_method *m, - arglist_t argframe, int arg, - const char **type) -{ - const char *t = objc_skip_argspec (m->method_types); - - if (arg > method_get_number_of_arguments (m)) - return 0; - - while (arg--) - t = objc_skip_argspec (t); - - *type = t; - t = objc_skip_typespec (t); - - if (*t == '+') - return argframe->arg_regs + atoi (++t); - else - return argframe->arg_ptr + atoi (t); -} - unsigned objc_get_type_qualifiers (const char *type) { diff --git a/libobjc/error.c b/libobjc/error.c index 1dae36594f..b56aa4da66 100644 --- a/libobjc/error.c +++ b/libobjc/error.c @@ -26,10 +26,6 @@ see the files COPYING3 and COPYING.RUNTIME respectively. If not, see #include "objc-private/common.h" #include "objc-private/error.h" -/* __USE_FIXED_PROTOTYPES__ used to be required to get prototypes for - malloc, free, etc. on some platforms. It is unclear if we still - need it, but it can't hurt. */ -#define __USE_FIXED_PROTOTYPES__ #include <stdlib.h> #include <stdio.h> #include <stdarg.h> @@ -45,53 +41,3 @@ _objc_abort (const char *fmt, ...) abort (); va_end (ap); } - -/* The rest of the file is deprecated. */ -#include "objc/objc-api.h" /* For objc_error_handler. */ - -/* -** Error handler function -** NULL so that default is to just print to stderr -*/ -static objc_error_handler _objc_error_handler = NULL; - -/* Trigger an objc error */ -void -objc_error (id object, int code, const char *fmt, ...) -{ - va_list ap; - - va_start (ap, fmt); - objc_verror (object, code, fmt, ap); - va_end (ap); -} - -/* Trigger an objc error */ -void -objc_verror (id object, int code, const char *fmt, va_list ap) -{ - BOOL result = NO; - - /* Call the error handler if its there - Otherwise print to stderr */ - if (_objc_error_handler) - result = (*_objc_error_handler) (object, code, fmt, ap); - else - vfprintf (stderr, fmt, ap); - - /* Continue if the error handler says its ok - Otherwise abort the program */ - if (result) - return; - else - abort (); -} - -/* Set the error handler */ -objc_error_handler -objc_set_error_handler (objc_error_handler func) -{ - objc_error_handler temp = _objc_error_handler; - _objc_error_handler = func; - return temp; -} diff --git a/libobjc/exception.c b/libobjc/exception.c index 1ffb80b535..04308ce13e 100644 --- a/libobjc/exception.c +++ b/libobjc/exception.c @@ -31,12 +31,6 @@ see the files COPYING3 and COPYING.RUNTIME respectively. If not, see #include "unwind-pe.h" #include <string.h> /* For memcpy */ -/* This hook allows libraries to sepecify special actions when an - exception is thrown without a handler in place. This is deprecated - in favour of objc_set_uncaught_exception_handler (). */ -void (*_objc_unexpected_exception) (id exception); /* !T:SAFE */ - - /* 'is_kind_of_exception_matcher' is our default exception matcher - it determines if the object 'exception' is of class 'catch_class', or of a subclass. */ @@ -165,6 +159,11 @@ parse_lsda_header (struct _Unwind_Context *context, const unsigned char *p, info->ttype_encoding = *p++; if (info->ttype_encoding != DW_EH_PE_omit) { +#if _GLIBCXX_OVERRIDE_TTYPE_ENCODING + /* Older ARM EABI toolchains set this value incorrectly, so use a + hardcoded OS-specific format. */ + info->ttype_encoding = _GLIBCXX_OVERRIDE_TTYPE_ENCODING; +#endif p = read_uleb128 (p, &tmp); info->TType = p + tmp; } @@ -180,26 +179,6 @@ parse_lsda_header (struct _Unwind_Context *context, const unsigned char *p, return p; } -#ifdef __ARM_EABI_UNWINDER__ - -static Class -get_ttype_entry (struct lsda_header_info *info, _uleb128_t i) -{ - _Unwind_Ptr ptr; - - ptr = (_Unwind_Ptr) (info->TType - (i * 4)); - ptr = _Unwind_decode_target2 (ptr); - - /* NULL ptr means catch-all. Note that if the class is not found, - this will abort the program. */ - if (ptr) - return objc_getRequiredClass ((const char *) ptr); - else - return 0; -} - -#else - static Class get_ttype_entry (struct lsda_header_info *info, _Unwind_Word i) { @@ -217,8 +196,6 @@ get_ttype_entry (struct lsda_header_info *info, _Unwind_Word i) return 0; } -#endif - /* Using a different personality function name causes link failures when trying to mix code using different exception handling models. */ @@ -539,13 +516,6 @@ objc_exception_throw (id exception) (*__objc_uncaught_exception_handler) (exception); } - /* As a last resort support the old, deprecated way of setting an - uncaught exception handler. */ - if (_objc_unexpected_exception != 0) - { - (*_objc_unexpected_exception) (exception); - } - abort (); } diff --git a/libobjc/gc.c b/libobjc/gc.c index 5ea4f8a091..d009230b78 100644 --- a/libobjc/gc.c +++ b/libobjc/gc.c @@ -31,9 +31,11 @@ see the files COPYING3 and COPYING.RUNTIME respectively. If not, see #include "tconfig.h" #include <assert.h> +#include <ctype.h> /* For isdigit. */ #include <string.h> #include <stdlib.h> -#include "objc/encoding.h" +#include "objc/runtime.h" +#include "objc-private/module-abi-8.h" #include <gc.h> #include <limits.h> @@ -302,7 +304,7 @@ __objc_generate_gc_type_description (Class class) /* The number of bits in the mask is the size of an instance in bytes divided by the size of a pointer. */ - bits_no = (ROUND (class_get_instance_size (class), sizeof (void *)) + bits_no = (ROUND (class_getInstanceSize (class), sizeof (void *)) / sizeof (void *)); size = ROUND (bits_no, BITS_PER_WORD) / BITS_PER_WORD; mask = objc_atomic_malloc (size * sizeof (int)); diff --git a/libobjc/libobjc.def b/libobjc/libobjc.def index e84d839ad1..8a295c824f 100644 --- a/libobjc/libobjc.def +++ b/libobjc/libobjc.def @@ -23,13 +23,9 @@ LIBRARY libobjc EXPORTS search_for_method_in_list objc_get_uninstalled_dtable -objc_hash_is_key_in_hash -hash_is_key_in_hash -objc_verror _objc_load_callback objc_malloc objc_atomic_malloc -objc_valloc objc_realloc objc_calloc objc_free @@ -39,7 +35,6 @@ objc_mutex_deallocate objc_mutex_lock objc_mutex_trylock objc_mutex_unlock -_objc_unexpected_exception objc_thread_detach objc_thread_exit objc_thread_get_data @@ -53,10 +48,6 @@ objc_thread_remove __objc_class_name_Object __objc_class_name_Protocol __objc_class_name_NXConstantString -objc_error -__objc_object_alloc -__objc_object_copy -__objc_object_dispose class_create_instance object_copy object_dispose @@ -87,48 +78,6 @@ objc_skip_argspec objc_skip_offset objc_skip_type_qualifiers objc_skip_typespec -__objc_read_nbyte_uint -__objc_read_nbyte_ulong -__objc_write_class -__objc_write_object -__objc_write_selector -objc_close_typed_stream -objc_end_of_typed_stream -objc_flush_typed_stream -objc_get_stream_class_version -objc_open_typed_stream -objc_open_typed_stream_for_file -objc_read_array -objc_read_char -objc_read_int -objc_read_long -objc_read_object -objc_read_selector -objc_read_short -objc_read_string -objc_read_type -objc_read_types -objc_read_unsigned_char -objc_read_unsigned_int -objc_read_unsigned_long -objc_read_unsigned_short -objc_write_array -objc_write_char -objc_write_int -objc_write_long -objc_write_object -objc_write_object_reference -objc_write_root_object -objc_write_selector -objc_write_short -objc_write_string -objc_write_string_atomic -objc_write_type -objc_write_types -objc_write_unsigned_char -objc_write_unsigned_int -objc_write_unsigned_long -objc_write_unsigned_short __objc_exec_class __objc_init_dispatch_tables __objc_install_premature_dtable @@ -150,22 +99,3 @@ objc_get_class objc_get_meta_class objc_lookup_class objc_next_class -sarray_at_put -sarray_at_put_safe -sarray_free -sarray_lazy_copy -sarray_new -sarray_realloc -sarray_remove_garbage -objc_hash_add -hash_add -objc_hash_delete -hash_delete -objc_hash_new -hash_new -objc_hash_next -hash_next -objc_hash_remove -hash_remove -objc_hash_value_for_key -hash_value_for_key diff --git a/libobjc/linking.m b/libobjc/linking.m index ba8e0649f4..cf28e56965 100644 --- a/libobjc/linking.m +++ b/libobjc/linking.m @@ -31,6 +31,6 @@ see the files COPYING3 and COPYING.RUNTIME respectively. If not, see void __objc_linking (void) { - [Object name]; + [Object class]; } diff --git a/libobjc/memory.c b/libobjc/memory.c index b0519fc87a..c02176ef87 100644 --- a/libobjc/memory.c +++ b/libobjc/memory.c @@ -133,38 +133,3 @@ objc_free (void *mem) } #endif /* !OBJC_WITH_GC */ - -/* The rest of the file contains deprecated code. */ - -#if OBJC_WITH_GC - -void * -objc_valloc (size_t size) -{ - void *res = (void *)(GC_malloc (size)); - if (! res) - _objc_abort ("Virtual memory exhausted\n"); - return res; -} - -#else - -void * -objc_valloc (size_t size) -{ - void *res = (void *)(malloc (size)); - if (! res) - _objc_abort ("Virtual memory exhausted\n"); - return res; -} - -#endif /* !OBJC_WITH_GC */ - -/* Hook functions for memory allocation and disposal. Deprecated and - currently unused. */ -void *(*_objc_malloc) (size_t) = malloc; -void *(*_objc_atomic_malloc) (size_t) = malloc; -void *(*_objc_valloc) (size_t) = malloc; -void *(*_objc_realloc) (void *, size_t) = realloc; -void *(*_objc_calloc) (size_t, size_t) = calloc; -void (*_objc_free) (void *) = free; diff --git a/libobjc/objc-private/common.h b/libobjc/objc-private/common.h index 4f4ec5cd07..d1f071114e 100644 --- a/libobjc/objc-private/common.h +++ b/libobjc/objc-private/common.h @@ -28,11 +28,6 @@ see the files COPYING3 and COPYING.RUNTIME respectively. If not, see /* This file contains definitions that should be included by all .c and .m files in libobjc. */ -/* This variable allows the public headers to determine when they are - being included by a file inside libobjc itself, or when they are - being included by an external file. */ -#define GNU_LIBOBJC_COMPILING_LIBOBJC_ITSELF 1 - /* When debugging libobjc, add #define DEBUG 1 diff --git a/libobjc/objc-private/module-abi-8.h b/libobjc/objc-private/module-abi-8.h index 0c9574bb49..06846e7969 100644 --- a/libobjc/objc-private/module-abi-8.h +++ b/libobjc/objc-private/module-abi-8.h @@ -149,34 +149,30 @@ struct objc_method_list structure. */ }; -/* Currently defined in Protocol.m (that definition should go away - once we include this file). Note that a 'struct - objc_method_description' as embedded inside a Protocol uses the - same trick as a 'struct objc_method': the method_name is a 'char *' - according to the compiler, who puts the method name as a string in - there. At runtime, the selectors need to be registered, and the - method_name then becomes a SEL. */ +/* Note that a 'struct objc_method_description' as embedded inside a + Protocol uses the same trick as a 'struct objc_method': the + method_name is a 'char *' according to the compiler, who puts the + method name as a string in there. At runtime, the selectors need + to be registered, and the method_name then becomes a SEL. */ struct objc_method_description_list { int count; struct objc_method_description list[1]; }; -/* Currently defined by objc/objc.h. */ -/* struct objc_protocol { struct objc_class* class_pointer; char *protocol_name; struct objc_protocol_list *protocol_list; struct objc_method_description_list *instance_methods, *class_methods; }; -*/ + struct objc_protocol_list { struct objc_protocol_list *next; size_t count; - Protocol *list[1]; + struct objc_protocol *list[1]; }; /* @@ -189,7 +185,6 @@ struct objc_protocol_list some members change type. The compiler generates "char* const" and places a string in the following member variables: super_class. */ -#ifndef __objc_STRUCT_OBJC_CLASS_defined struct objc_class { struct objc_class* class_pointer; /* Pointer to the class's meta class. */ @@ -232,7 +227,6 @@ struct objc_class { struct objc_protocol_list *protocols; /* Protocols conformed to */ void* gc_object_type; }; -#endif /* __objc_STRUCT_OBJC_CLASS_defined */ /* This is used to assure consistent access to the info field of classes. */ @@ -283,7 +277,6 @@ struct objc_class { (cls)->info >>= (HOST_BITS_PER_LONG/2); \ __CLS_SETINFO(cls, (((unsigned long)num) << (HOST_BITS_PER_LONG/2))); }) - /* The compiler generates one of these structures for each category. A class may have many categories and contain both instance and factory methods. */ diff --git a/libobjc/objc-private/protocols.h b/libobjc/objc-private/protocols.h index 87f8fc8487..3219ff2893 100644 --- a/libobjc/objc-private/protocols.h +++ b/libobjc/objc-private/protocols.h @@ -33,6 +33,6 @@ __objc_protocols_init (void); protocols by name, which allows objc_getProtocol(name) to be implemented efficiently. */ void -__objc_protocols_add_protocol (const char *name, Protocol *object); +__objc_protocols_add_protocol (const char *name, struct objc_protocol *object); #endif /* not __objc_private_protocols_INCLUDE_GNU */ diff --git a/libobjc/objc-private/runtime.h b/libobjc/objc-private/runtime.h index 5406294f2c..bd11392ebe 100644 --- a/libobjc/objc-private/runtime.h +++ b/libobjc/objc-private/runtime.h @@ -32,10 +32,7 @@ The original list was: #include "objc/hash.h" #include "objc/objc-list.h" -but can almost certainly be shrinked down. - -Note that you can use this file both with objc/objc-api.h and with -objc/runtime.h. */ +but can almost certainly be shrinked down. */ #ifndef __objc_private_runtime_INCLUDE_GNU #define __objc_private_runtime_INCLUDE_GNU diff --git a/libobjc/objc-private/selector.h b/libobjc/objc-private/selector.h index 490e17105a..32223b9d69 100644 --- a/libobjc/objc-private/selector.h +++ b/libobjc/objc-private/selector.h @@ -28,6 +28,24 @@ see the files COPYING3 and COPYING.RUNTIME respectively. If not, see /* Private runtime functions that may go away or be rewritten or replaced. */ +/* Definition of a selector. Selectors themselves are not unique, but + the sel_id is a unique identifier. */ +struct objc_selector +{ + void *sel_id; + const char *sel_types; +}; + +/* An inline, fast version of sel_isEqual(). */ +inline static BOOL +sel_eq (SEL s1, SEL s2) +{ + if (s1 == 0 || s2 == 0) + return s1 == s2; + else + return s1->sel_id == s2->sel_id; +} + /* Number of selectors stored in each of the selector tables. */ extern unsigned int __objc_selector_max_index; diff --git a/libobjc/objc/Object.h b/libobjc/objc/Object.h index f036b76b9a..e2fa926e7b 100644 --- a/libobjc/objc/Object.h +++ b/libobjc/objc/Object.h @@ -55,12 +55,6 @@ extern "C" { - (BOOL)isEqual: (id)anObject; @end -/* All of the following includes were deprecated in GCC 4.6 and will - be removed in the next release. */ -#include "deprecated/hash.h" -#include "deprecated/typedstream.h" -#include "deprecated/Object.h" - #ifdef __cplusplus } #endif diff --git a/libobjc/objc/Protocol.h b/libobjc/objc/Protocol.h index 1cf9892b27..f2b7b78963 100644 --- a/libobjc/objc/Protocol.h +++ b/libobjc/objc/Protocol.h @@ -47,8 +47,6 @@ extern "C" { protocol_getMethodDescription() */ -#include "deprecated/Protocol.h" - #ifdef __cplusplus } #endif diff --git a/libobjc/objc/README b/libobjc/objc/README index 4a8be6e563..69f17e581a 100644 --- a/libobjc/objc/README +++ b/libobjc/objc/README @@ -1,13 +1,2 @@ This directory contains the public headers that are installed when libobjc is installed. - -Deprecated parts of the API should be moved into objc/deprecated and -then included by public headers until they are finally removed. For -example, if objc-api.h contains an _objc_unexpected_exception variable -which is then deprecated, it should be moved into a header in -objc/deprecated. This header is then included into objc-api.h. - -The result is that all the deprecated parts of the API are clearly -separated in objc/deprecated, while objc/ retains only the current public -API. - diff --git a/libobjc/objc/deprecated/METHOD_NULL.h b/libobjc/objc/deprecated/METHOD_NULL.h deleted file mode 100644 index 6912be345e..0000000000 --- a/libobjc/objc/deprecated/METHOD_NULL.h +++ /dev/null @@ -1,2 +0,0 @@ -/* For functions which return Method_t */ -#define METHOD_NULL (Method_t)0 diff --git a/libobjc/objc/deprecated/MetaClass.h b/libobjc/objc/deprecated/MetaClass.h deleted file mode 100644 index 01597782c5..0000000000 --- a/libobjc/objc/deprecated/MetaClass.h +++ /dev/null @@ -1 +0,0 @@ -typedef struct objc_class *MetaClass; diff --git a/libobjc/objc/deprecated/Object.h b/libobjc/objc/deprecated/Object.h deleted file mode 100644 index e15cf7dd99..0000000000 --- a/libobjc/objc/deprecated/Object.h +++ /dev/null @@ -1,84 +0,0 @@ -/* The following methods were deprecated in GCC 4.6.0 and will be - removed in the next GCC release. */ -@interface Object (Deprecated) -/* Initializing classes and instances */ -+ initialize; -- init; - -/* Creating, freeing, and copying instances */ -+ new; -+ alloc; -- free; -- copy; -- shallowCopy; -- deepen; -- deepCopy; - -/* Identifying classes */ -- (Class)superClass; -- (MetaClass)metaClass; -- (const char *)name; - -/* Identifying and comparing objects */ -- self; -- (unsigned int)hash; -- (int)compare:(id)anotherObject; - -/* Testing object type */ -- (BOOL)isMetaClass; -- (BOOL)isClass; -- (BOOL)isInstance; - -/* Testing inheritance relationships */ -- (BOOL)isKindOf:(Class)aClassObject; -- (BOOL)isMemberOf:(Class)aClassObject; -- (BOOL)isKindOfClassNamed:(const char *)aClassName; -- (BOOL)isMemberOfClassNamed:(const char *)aClassName; - -/* Testing class functionality */ -+ (BOOL)instancesRespondTo:(SEL)aSel; -- (BOOL)respondsTo:(SEL)aSel; - -/* Testing protocol conformance */ -- (BOOL)conformsTo:(Protocol*)aProtocol; - -/* Introspection */ -+ (IMP)instanceMethodFor:(SEL)aSel; -- (IMP)methodFor:(SEL)aSel; -+ (struct objc_method_description *)descriptionForInstanceMethod:(SEL)aSel; -- (struct objc_method_description *)descriptionForMethod:(SEL)aSel; - -/* Sending messages determined at run time */ -- perform:(SEL)aSel; -- perform:(SEL)aSel with:anObject; -- perform:(SEL)aSel with:anObject1 with:anObject2; - -/* Forwarding */ -- (retval_t)forward:(SEL)aSel :(arglist_t)argFrame; -- (retval_t)performv:(SEL)aSel :(arglist_t)argFrame; - -/* Posing */ -+ poseAs:(Class)aClassObject; -- (Class)transmuteClassTo:(Class)aClassObject; - -/* Enforcing intentions */ -- subclassResponsibility:(SEL)aSel; -- notImplemented:(SEL)aSel; -- shouldNotImplement:(SEL)aSel; - -/* Error handling */ -- doesNotRecognize:(SEL)aSel; -- error:(const char *)aString, ...; - -/* Archiving */ -+ (int)version; -+ setVersion:(int)aVersion; - -+ (int)streamVersion: (TypedStream*)aStream; /* __attribute__ ((deprecated)) */ - -- read: (TypedStream*)aStream; /* __attribute__ ((deprecated)) */ -- write: (TypedStream*)aStream; /* __attribute__ ((deprecated)) */ -- awake; /* __attribute__ ((deprecated)) */ - -@end - diff --git a/libobjc/objc/deprecated/Protocol.h b/libobjc/objc/deprecated/Protocol.h deleted file mode 100644 index 7a77f51a0d..0000000000 --- a/libobjc/objc/deprecated/Protocol.h +++ /dev/null @@ -1,13 +0,0 @@ -/* The following methods were deprecated in GCC 4.6.0 and will be - removed in the next GCC release. */ -@interface Protocol (Deprecated) -/* Obtaining attributes intrinsic to the protocol */ -- (const char *)name; - -/* Testing protocol conformance */ -- (BOOL) conformsTo: (Protocol *)aProtocolObject; - -/* Looking up information specific to a protocol */ -- (struct objc_method_description *) descriptionForInstanceMethod:(SEL)aSel; -- (struct objc_method_description *) descriptionForClassMethod:(SEL)aSel; -@end diff --git a/libobjc/objc/deprecated/README b/libobjc/objc/deprecated/README deleted file mode 100644 index 3f105196e6..0000000000 --- a/libobjc/objc/deprecated/README +++ /dev/null @@ -1,11 +0,0 @@ -This directory contains declarations and features that are deprecated -and that will be removed in future versions of the compiler. - -Note that files in this directory are not really usable headers on -their own - they shouldn't be included directly by end users. They -are header fragments containing deprecated APIs that are still -included (until removed) from the real headers in objc/. - -Files in this directory should not #include any other objc header. -Any include that they need should be done in the real objc/ headers -before including these fragments. diff --git a/libobjc/objc/deprecated/STR.h b/libobjc/objc/deprecated/STR.h deleted file mode 100644 index 17c20e2d6e..0000000000 --- a/libobjc/objc/deprecated/STR.h +++ /dev/null @@ -1,2 +0,0 @@ -/* Incredibly obsolete. */ -typedef char *STR; /* String alias */ diff --git a/libobjc/objc/deprecated/hash.h b/libobjc/objc/deprecated/hash.h deleted file mode 100644 index 8b718a4417..0000000000 --- a/libobjc/objc/deprecated/hash.h +++ /dev/null @@ -1,211 +0,0 @@ -/* Hash tables for Objective C method dispatch. - Copyright (C) 1993, 1995, 1996, 2004, 2009 Free Software Foundation, Inc. - -This file is part of GCC. - -GCC 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 3, or (at your option) -any later version. - -GCC 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. - -Under Section 7 of GPL version 3, you are granted additional -permissions described in the GCC Runtime Library Exception, version -3.1, as published by the Free Software Foundation. - -You should have received a copy of the GNU General Public License and -a copy of the GCC Runtime Library Exception along with this program; -see the files COPYING3 and COPYING.RUNTIME respectively. If not, see -<http://www.gnu.org/licenses/>. */ - - - -#ifndef __hash_INCLUDE_GNU -#define __hash_INCLUDE_GNU - -#include <stddef.h> -#include <string.h> - -#ifdef __cplusplus -extern "C" { -#endif /* __cplusplus */ - -/* - * This data structure is used to hold items - * stored in a hash table. Each node holds - * a key/value pair. - * - * Items in the cache are really of type void *. - */ -typedef struct cache_node -{ - struct cache_node *next; /* Pointer to next entry on the list. - NULL indicates end of list. */ - const void *key; /* Key used to locate the value. Used - to locate value when more than one - key computes the same hash - value. */ - void *value; /* Value stored for the key. */ -} *node_ptr; - - -/* - * This data type is the function that computes a hash code given a key. - * Therefore, the key can be a pointer to anything and the function specific - * to the key type. - * - * Unfortunately there is a mutual data structure reference problem with this - * typedef. Therefore, to remove compiler warnings the functions passed to - * objc_hash_new will have to be casted to this type. - */ -typedef unsigned int (*hash_func_type) (void *, const void *); - -/* - * This data type is the function that compares two hash keys and returns an - * integer greater than, equal to, or less than 0, according as the first - * parameter is lexicographically greater than, equal to, or less than the - * second. - */ - -typedef int (*compare_func_type) (const void *, const void *); - - -/* - * This data structure is the cache. - * - * It must be passed to all of the hashing routines - * (except for new). - */ -typedef struct cache -{ - /* Variables used to implement the hash itself. */ - node_ptr *node_table; /* Pointer to an array of hash nodes. */ - /* Variables used to track the size of the hash table so to determine - when to resize it. */ - unsigned int size; /* Number of buckets allocated for the hash table - (number of array entries allocated for - "node_table"). Must be a power of two. */ - unsigned int used; /* Current number of entries in the hash table. */ - unsigned int mask; /* Precomputed mask. */ - - /* Variables used to implement indexing through the hash table. */ - - unsigned int last_bucket; /* Tracks which entry in the array where - the last value was returned. */ - /* Function used to compute a hash code given a key. - This function is specified when the hash table is created. */ - hash_func_type hash_func; - /* Function used to compare two hash keys to see if they are equal. */ - compare_func_type compare_func; -} *cache_ptr; - - -/* Allocate and initialize a hash table. */ - -cache_ptr objc_hash_new (unsigned int size, - hash_func_type hash_func, - compare_func_type compare_func); - -/* Deallocate all of the hash nodes and the cache itself. */ - -void objc_hash_delete (cache_ptr cache); - -/* Add the key/value pair to the hash table. If the - hash table reaches a level of fullness then it will be resized. - - assert if the key is already in the hash. */ - -void objc_hash_add (cache_ptr *cachep, const void *key, void *value); - -/* Remove the key/value pair from the hash table. - assert if the key isn't in the table. */ - -void objc_hash_remove (cache_ptr cache, const void *key); - -/* Used to index through the hash table. Start with NULL - to get the first entry. - - Successive calls pass the value returned previously. - ** Don't modify the hash during this operation *** - - Cache nodes are returned such that key or value can - be extracted. */ - -node_ptr objc_hash_next (cache_ptr cache, node_ptr node); - -/* Used to return a value from a hash table using a given key. */ - -void *objc_hash_value_for_key (cache_ptr cache, const void *key); - -/* Used to determine if the given key exists in the hash table */ - -BOOL objc_hash_is_key_in_hash (cache_ptr cache, const void *key); - -/************************************************ - - Useful hashing functions. - - Declared inline for your pleasure. - -************************************************/ - -/* Calculate a hash code by performing some - manipulation of the key pointer. (Use the lowest bits - except for those likely to be 0 due to alignment.) */ - -static inline unsigned int -objc_hash_ptr (cache_ptr cache, const void *key) -{ - return ((size_t)key / sizeof (void *)) & cache->mask; -} - - -/* Calculate a hash code by iterating over a NULL - terminate string. */ -static inline unsigned int -objc_hash_string (cache_ptr cache, const void *key) -{ - unsigned int ret = 0; - unsigned int ctr = 0; - const char *ckey = (const char *) key; - - while (*ckey) { - ret ^= *ckey++ << ctr; - ctr = (ctr + 1) % sizeof (void *); - } - - return ret & cache->mask; -} - - -/* Compare two pointers for equality. */ -static inline int -objc_compare_ptrs (const void *k1, const void *k2) -{ - return (k1 == k2); -} - - -/* Compare two strings. */ -static inline int -objc_compare_strings (const void *k1, const void *k2) -{ - if (k1 == k2) - return 1; - else if (k1 == 0 || k2 == 0) - return 0; - else - return ! strcmp ((const char *) k1, (const char *) k2); -} - - -#ifdef __cplusplus -} -#endif /* __cplusplus */ - - -#endif /* not __hash_INCLUDE_GNU */ diff --git a/libobjc/objc/deprecated/objc-list.h b/libobjc/objc/deprecated/objc-list.h deleted file mode 100644 index e542bfc049..0000000000 --- a/libobjc/objc/deprecated/objc-list.h +++ /dev/null @@ -1,155 +0,0 @@ -/* Generic single linked list to keep various information - Copyright (C) 1993, 1994, 1996, 2009 Free Software Foundation, Inc. - Contributed by Kresten Krab Thorup. - -This file is part of GCC. - -GCC 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 3, or (at your option) -any later version. - -GCC 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. - -Under Section 7 of GPL version 3, you are granted additional -permissions described in the GCC Runtime Library Exception, version -3.1, as published by the Free Software Foundation. - -You should have received a copy of the GNU General Public License and -a copy of the GCC Runtime Library Exception along with this program; -see the files COPYING3 and COPYING.RUNTIME respectively. If not, see -<http://www.gnu.org/licenses/>. */ - - -#ifndef __GNU_OBJC_LIST_H -#define __GNU_OBJC_LIST_H - -#ifdef __cplusplus -extern "C" { -#endif /* __cplusplus */ - -struct objc_list { - void *head; - struct objc_list *tail; -}; - -/* Return a cons cell produced from (head . tail) */ - -static inline struct objc_list* -list_cons(void* head, struct objc_list* tail) -{ - struct objc_list* cell; - - cell = (struct objc_list*)objc_malloc(sizeof(struct objc_list)); - cell->head = head; - cell->tail = tail; - return cell; -} - -/* Return the length of a list, list_length(NULL) returns zero */ - -static inline int -list_length(struct objc_list* list) -{ - int i = 0; - while(list) - { - i += 1; - list = list->tail; - } - return i; -} - -/* Return the Nth element of LIST, where N count from zero. If N - larger than the list length, NULL is returned */ - -static inline void* -list_nth(int indx, struct objc_list* list) -{ - while(indx-- != 0) - { - if(list->tail) - list = list->tail; - else - return 0; - } - return list->head; -} - -/* Remove the element at the head by replacing it by its successor */ - -static inline void -list_remove_head(struct objc_list** list) -{ - if ((*list)->tail) - { - struct objc_list* tail = (*list)->tail; /* fetch next */ - *(*list) = *tail; /* copy next to list head */ - objc_free(tail); /* free next */ - } - else /* only one element in list */ - { - objc_free(*list); - (*list) = 0; - } -} - - -/* Remove the element with `car' set to ELEMENT */ - -static inline void -list_remove_elem(struct objc_list** list, void* elem) -{ - while (*list) { - if ((*list)->head == elem) - list_remove_head(list); - list = &((*list)->tail); - } -} - -/* Map FUNCTION over all elements in LIST */ - -static inline void -list_mapcar(struct objc_list* list, void(*function)(void*)) -{ - while(list) - { - (*function)(list->head); - list = list->tail; - } -} - -/* Return element that has ELEM as car */ - -static inline struct objc_list** -list_find(struct objc_list** list, void* elem) -{ - while(*list) - { - if ((*list)->head == elem) - return list; - list = &((*list)->tail); - } - return NULL; -} - -/* Free list (backwards recursive) */ - -static inline void -list_free(struct objc_list* list) -{ - if(list) - { - list_free(list->tail); - objc_free(list); - } -} - -#ifdef __cplusplus -} -#endif /* __cplusplus */ - -#endif /* not __GNU_OBJC_LIST_H */ diff --git a/libobjc/objc/deprecated/objc_error.h b/libobjc/objc/deprecated/objc_error.h deleted file mode 100644 index 7a7ebe941b..0000000000 --- a/libobjc/objc/deprecated/objc_error.h +++ /dev/null @@ -1,56 +0,0 @@ -/* This API is incredibly limited and unsophisticated. objc_error() - generally causes the program to abort, so it should only be used - when something so dramatic happens that it could be pointless to - continue. Only two cases I can think of: failure to allocate new - memory or failure to load an Objective-C module. -*/ -/* Error handling - - Call objc_error() or objc_verror() to record an error; this error - routine will generally exit the program but not necessarily if the - user has installed his own error handler. - - Call objc_set_error_handler to assign your own function for - handling errors. The function should return YES if it is ok - to continue execution, or return NO or just abort if the - program should be stopped. The default error handler is just to - print a message on stderr. - - The error handler function should be of type objc_error_handler - The first parameter is an object instance of relevance. - The second parameter is an error code. - The third parameter is a format string in the printf style. - The fourth parameter is a variable list of arguments. */ -void objc_error(id object, int code, const char* fmt, ...); -void objc_verror(id object, int code, const char* fmt, va_list ap); -typedef BOOL (*objc_error_handler)(id, int code, const char *fmt, va_list ap); -objc_error_handler objc_set_error_handler(objc_error_handler func); - -/* Error codes - These are used by the runtime library, and your - error handling may use them to determine if the error is - hard or soft thus whether execution can continue or abort. */ -#define OBJC_ERR_UNKNOWN 0 /* Generic error */ - -#define OBJC_ERR_OBJC_VERSION 1 /* Incorrect runtime version */ -#define OBJC_ERR_GCC_VERSION 2 /* Incorrect compiler version */ -#define OBJC_ERR_MODULE_SIZE 3 /* Bad module size */ -#define OBJC_ERR_PROTOCOL_VERSION 4 /* Incorrect protocol version */ - -#define OBJC_ERR_MEMORY 10 /* Out of memory */ - -#define OBJC_ERR_RECURSE_ROOT 20 /* Attempt to archive the root - object more than once. */ -#define OBJC_ERR_BAD_DATA 21 /* Didn't read expected data */ -#define OBJC_ERR_BAD_KEY 22 /* Bad key for object */ -#define OBJC_ERR_BAD_CLASS 23 /* Unknown class */ -#define OBJC_ERR_BAD_TYPE 24 /* Bad type specification */ -#define OBJC_ERR_NO_READ 25 /* Cannot read stream */ -#define OBJC_ERR_NO_WRITE 26 /* Cannot write stream */ -#define OBJC_ERR_STREAM_VERSION 27 /* Incorrect stream version */ -#define OBJC_ERR_BAD_OPCODE 28 /* Bad opcode */ - -#define OBJC_ERR_UNIMPLEMENTED 30 /* Method is not implemented */ - -#define OBJC_ERR_BAD_STATE 40 /* Bad thread state */ - diff --git a/libobjc/objc/deprecated/objc_get_uninstalled_dtable.h b/libobjc/objc/deprecated/objc_get_uninstalled_dtable.h deleted file mode 100644 index 48d508a159..0000000000 --- a/libobjc/objc/deprecated/objc_get_uninstalled_dtable.h +++ /dev/null @@ -1,2 +0,0 @@ -objc_EXPORT struct sarray* -objc_get_uninstalled_dtable(void); diff --git a/libobjc/objc/deprecated/objc_malloc.h b/libobjc/objc/deprecated/objc_malloc.h deleted file mode 100644 index cf6c6e9d09..0000000000 --- a/libobjc/objc/deprecated/objc_malloc.h +++ /dev/null @@ -1,17 +0,0 @@ -/* -** Hook functions for memory allocation and disposal. -** This makes it easy to substitute garbage collection systems -** such as Boehm's GC by assigning these function pointers -** to the GC's allocation routines. By default these point -** to the ANSI standard malloc, realloc, free, etc. -** -** Users should call the normal objc routines above for -** memory allocation and disposal within their programs. -*/ -objc_EXPORT void *(*_objc_malloc)(size_t); -objc_EXPORT void *(*_objc_atomic_malloc)(size_t); -objc_EXPORT void *(*_objc_valloc)(size_t); -objc_EXPORT void *(*_objc_realloc)(void *, size_t); -objc_EXPORT void *(*_objc_calloc)(size_t, size_t); -objc_EXPORT void (*_objc_free)(void *); - diff --git a/libobjc/objc/deprecated/objc_msg_sendv.h b/libobjc/objc/deprecated/objc_msg_sendv.h deleted file mode 100644 index 825d9a7661..0000000000 --- a/libobjc/objc/deprecated/objc_msg_sendv.h +++ /dev/null @@ -1,12 +0,0 @@ -/* The following types and functions are provided only for - backwards-compatibility and should not be used in new code. They - were deprecated in GCC 4.6 and will be removed in the next - release. */ -typedef void* retval_t; /* return value */ -typedef void(*apply_t)(void); /* function pointer */ -typedef union arglist { - char *arg_ptr; - char arg_regs[sizeof (char*)]; -} *arglist_t; /* argument frame */ - -objc_EXPORT retval_t objc_msg_sendv(id, SEL, arglist_t); diff --git a/libobjc/objc/deprecated/objc_object_alloc.h b/libobjc/objc/deprecated/objc_object_alloc.h deleted file mode 100644 index f6336ca8ef..0000000000 --- a/libobjc/objc/deprecated/objc_object_alloc.h +++ /dev/null @@ -1,8 +0,0 @@ -/* These functions are deprecated and currently ignored. */ -/* -** Hook functions for allocating, copying and disposing of instances -*/ -objc_EXPORT id (*_objc_object_alloc)(Class _class); -objc_EXPORT id (*_objc_object_copy)(id object); -objc_EXPORT id (*_objc_object_dispose)(id object); - diff --git a/libobjc/objc/deprecated/objc_unexpected_exception.h b/libobjc/objc/deprecated/objc_unexpected_exception.h deleted file mode 100644 index 69ffd4e87d..0000000000 --- a/libobjc/objc/deprecated/objc_unexpected_exception.h +++ /dev/null @@ -1,9 +0,0 @@ -/* -** Hook for uncaught exceptions. This hook is called when an -** exception is thrown and no valid exception handler is in place. -** The function is expected never to return. If the function returns -** the result is currently undefined. This is deprecated. Please use -** objc_set_uncaught_exception_handler() from objc/objc-exception.h -** instead. -*/ -objc_EXPORT void (*_objc_unexpected_exception)(id) __attribute__ ((deprecated)); diff --git a/libobjc/objc/deprecated/objc_valloc.h b/libobjc/objc/deprecated/objc_valloc.h deleted file mode 100644 index a715f1a733..0000000000 --- a/libobjc/objc/deprecated/objc_valloc.h +++ /dev/null @@ -1,2 +0,0 @@ -void * -objc_valloc(size_t size); diff --git a/libobjc/objc/deprecated/sarray.h b/libobjc/objc/deprecated/sarray.h deleted file mode 100644 index aa2f3350a4..0000000000 --- a/libobjc/objc/deprecated/sarray.h +++ /dev/null @@ -1,240 +0,0 @@ -/* Sparse Arrays for Objective C dispatch tables - Copyright (C) 1993, 1995, 1996, 2004, 2009 Free Software Foundation, Inc. - Contributed by Kresten Krab Thorup. - -This file is part of GCC. - -GCC 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 3, or (at your option) -any later version. - -GCC 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. - -Under Section 7 of GPL version 3, you are granted additional -permissions described in the GCC Runtime Library Exception, version -3.1, as published by the Free Software Foundation. - -You should have received a copy of the GNU General Public License and -a copy of the GCC Runtime Library Exception along with this program; -see the files COPYING3 and COPYING.RUNTIME respectively. If not, see -<http://www.gnu.org/licenses/>. */ - - -#ifndef __sarray_INCLUDE_GNU -#define __sarray_INCLUDE_GNU - -#define OBJC_SPARSE2 /* 2-level sparse array */ -/* #define OBJC_SPARSE3 */ /* 3-level sparse array */ - -#ifdef OBJC_SPARSE2 -extern const char* __objc_sparse2_id; -#endif - -#ifdef OBJC_SPARSE3 -extern const char* __objc_sparse3_id; -#endif - -#include <stddef.h> - -#ifdef __cplusplus -extern "C" { -#endif /* __cplusplus */ - -extern int nbuckets; /* for stats */ -extern int nindices; -extern int narrays; -extern int idxsize; - -/* An unsigned integer of same size as a pointer */ -#define SIZET_BITS (sizeof(size_t)*8) - -#if defined(__sparc__) || defined(OBJC_SPARSE2) -#define PRECOMPUTE_SELECTORS -#endif - -#ifdef OBJC_SPARSE3 - -/* Buckets are 8 words each */ -#define BUCKET_BITS 3 -#define BUCKET_SIZE (1<<BUCKET_BITS) -#define BUCKET_MASK (BUCKET_SIZE-1) - -/* Indices are 16 words each */ -#define INDEX_BITS 4 -#define INDEX_SIZE (1<<INDEX_BITS) -#define INDEX_MASK (INDEX_SIZE-1) - -#define INDEX_CAPACITY (BUCKET_SIZE*INDEX_SIZE) - -#else /* OBJC_SPARSE2 */ - -/* Buckets are 32 words each */ -#define BUCKET_BITS 5 -#define BUCKET_SIZE (1<<BUCKET_BITS) -#define BUCKET_MASK (BUCKET_SIZE-1) - -#endif /* OBJC_SPARSE2 */ - -typedef size_t sidx; - -#ifdef PRECOMPUTE_SELECTORS - -struct soffset { -#ifdef OBJC_SPARSE3 - unsigned int unused : SIZET_BITS/4; - unsigned int eoffset : SIZET_BITS/4; - unsigned int boffset : SIZET_BITS/4; - unsigned int ioffset : SIZET_BITS/4; -#else /* OBJC_SPARSE2 */ -#ifdef __sparc__ - unsigned long boffset : (SIZET_BITS - 2) - BUCKET_BITS; - unsigned int eoffset : BUCKET_BITS; - unsigned int unused : 2; -#else - unsigned int boffset : SIZET_BITS/2; - unsigned int eoffset : SIZET_BITS/2; -#endif -#endif /* OBJC_SPARSE2 */ -}; - -union sofftype { - struct soffset off; - sidx idx; -}; - -#endif /* not PRECOMPUTE_SELECTORS */ - -union sversion { - int version; - void *next_free; -}; - -struct sbucket { - void* elems[BUCKET_SIZE]; /* elements stored in array */ - union sversion version; /* used for copy-on-write */ -}; - -#ifdef OBJC_SPARSE3 - -struct sindex { - struct sbucket* buckets[INDEX_SIZE]; - union sversion version; /* used for copy-on-write */ -}; - -#endif /* OBJC_SPARSE3 */ - -struct sarray { -#ifdef OBJC_SPARSE3 - struct sindex** indices; - struct sindex* empty_index; -#else /* OBJC_SPARSE2 */ - struct sbucket** buckets; -#endif /* OBJC_SPARSE2 */ - struct sbucket* empty_bucket; - union sversion version; /* used for copy-on-write */ - short ref_count; - struct sarray* is_copy_of; - size_t capacity; -}; - -struct sarray* sarray_new(int, void* default_element); -void sarray_free(struct sarray*); -struct sarray* sarray_lazy_copy(struct sarray*); -void sarray_realloc(struct sarray*, int new_size); -void sarray_at_put(struct sarray*, sidx indx, void* elem); -void sarray_at_put_safe(struct sarray*, sidx indx, void* elem); - -struct sarray* sarray_hard_copy(struct sarray*); /* ... like the name? */ -void sarray_remove_garbage(void); - - -#ifdef PRECOMPUTE_SELECTORS -/* Transform soffset values to ints and vica verca */ -static inline unsigned int -soffset_decode(sidx indx) -{ - union sofftype x; - x.idx = indx; -#ifdef OBJC_SPARSE3 - return x.off.eoffset - + (x.off.boffset*BUCKET_SIZE) - + (x.off.ioffset*INDEX_CAPACITY); -#else /* OBJC_SPARSE2 */ - return x.off.eoffset + (x.off.boffset*BUCKET_SIZE); -#endif /* OBJC_SPARSE2 */ -} - -static inline sidx -soffset_encode(size_t offset) -{ - union sofftype x; - x.off.eoffset = offset%BUCKET_SIZE; -#ifdef OBJC_SPARSE3 - x.off.boffset = (offset/BUCKET_SIZE)%INDEX_SIZE; - x.off.ioffset = offset/INDEX_CAPACITY; -#else /* OBJC_SPARSE2 */ - x.off.boffset = offset/BUCKET_SIZE; -#endif - return (sidx)x.idx; -} - -#else /* not PRECOMPUTE_SELECTORS */ - -static inline size_t -soffset_decode(sidx indx) -{ - return indx; -} - -static inline sidx -soffset_encode(size_t offset) -{ - return offset; -} -#endif /* not PRECOMPUTE_SELECTORS */ - -/* Get element from the Sparse array `array' at offset `indx' */ - -static inline void* sarray_get(struct sarray* array, sidx indx) -{ -#ifdef PRECOMPUTE_SELECTORS - union sofftype x; - x.idx = indx; -#ifdef OBJC_SPARSE3 - return - array-> - indices[x.off.ioffset]-> - buckets[x.off.boffset]-> - elems[x.off.eoffset]; -#else /* OBJC_SPARSE2 */ - return array->buckets[x.off.boffset]->elems[x.off.eoffset]; -#endif /* OBJC_SPARSE2 */ -#else /* not PRECOMPUTE_SELECTORS */ -#ifdef OBJC_SPARSE3 - return array-> - indices[indx/INDEX_CAPACITY]-> - buckets[(indx/BUCKET_SIZE)%INDEX_SIZE]-> - elems[indx%BUCKET_SIZE]; -#else /* OBJC_SPARSE2 */ - return array->buckets[indx/BUCKET_SIZE]->elems[indx%BUCKET_SIZE]; -#endif /* not OBJC_SPARSE3 */ -#endif /* not PRECOMPUTE_SELECTORS */ -} - -static inline void* sarray_get_safe(struct sarray* array, sidx indx) -{ - if(soffset_decode(indx) < array->capacity) - return sarray_get(array, indx); - else - return (array->empty_bucket->elems[0]); -} - -#ifdef __cplusplus -} -#endif /* __cplusplus */ - -#endif /* __sarray_INCLUDE_GNU */ diff --git a/libobjc/objc/deprecated/struct_objc_category.h b/libobjc/objc/deprecated/struct_objc_category.h deleted file mode 100644 index 6de3980a90..0000000000 --- a/libobjc/objc/deprecated/struct_objc_category.h +++ /dev/null @@ -1,21 +0,0 @@ -/* -** The compiler generates one of these structures for each category. A class -** may have many categories and contain both instance and factory methods. -*/ -struct objc_category { - const char* category_name; /* Name of the category. Name - contained in the () of the - category definition. */ - const char* class_name; /* Name of the class to which - the category belongs. */ - MethodList_t instance_methods; /* Linked list of instance - methods defined in the - category. NULL indicates no - instance methods defined. */ - MethodList_t class_methods; /* Linked list of factory - methods defined in the - category. NULL indicates no - class methods defined. */ - struct objc_protocol_list *protocols; /* List of Protocols - conformed to */ -}; diff --git a/libobjc/objc/deprecated/struct_objc_class.h b/libobjc/objc/deprecated/struct_objc_class.h deleted file mode 100644 index 07927feb69..0000000000 --- a/libobjc/objc/deprecated/struct_objc_class.h +++ /dev/null @@ -1,56 +0,0 @@ -/* This structure used to be public, but is now private to the runtime. */ -#define __objc_STRUCT_OBJC_CLASS_defined - -/* -** The compiler generates one of these structures for each class. -** -** This structure is the definition for classes. -** -** This structure is generated by the compiler in the executable and used by -** the run-time during normal messaging operations. Therefore some members -** change type. The compiler generates "char* const" and places a string in -** the following member variables: super_class. -*/ -struct objc_class { - MetaClass class_pointer; /* Pointer to the class's - meta class. */ - struct objc_class* super_class; /* Pointer to the super - class. NULL for class - Object. */ - const char* name; /* Name of the class. */ - long version; /* Unknown. */ - unsigned long info; /* Bit mask. See class masks - defined above. */ - long instance_size; /* Size in bytes of the class. - The sum of the class - definition and all super - class definitions. */ -#ifdef _WIN64 - /* We pad the structure manually to prevent warning when -Wpadded - is used. The compiler automatically pads the structures that it - generates, so this manually padded structure still matches the one - generated by the compiler, but if we don't pad manually, -Wpadded - detects that padding is being added and generates annoying warnings. - This hack is necessary as on LLP64 targets sizeof (long) isn't equal - to sizeof (void *). */ - long pad; -#endif - struct objc_ivar_list* ivars; /* Pointer to a structure that - describes the instance - variables in the class - definition. NULL indicates - no instance variables. Does - not include super class - variables. */ - struct objc_method_list* methods; /* Linked list of instance - methods defined for the - class. */ - struct sarray * dtable; /* Pointer to instance - method dispatch table. */ - struct objc_class* subclass_list; /* Subclasses */ - struct objc_class* sibling_class; - - struct objc_protocol_list *protocols; /* Protocols conformed to */ - void* gc_object_type; -}; - diff --git a/libobjc/objc/deprecated/struct_objc_ivar.h b/libobjc/objc/deprecated/struct_objc_ivar.h deleted file mode 100644 index 57170ad116..0000000000 --- a/libobjc/objc/deprecated/struct_objc_ivar.h +++ /dev/null @@ -1,15 +0,0 @@ -/* -** The compiler generates one of these structures for a class that has -** instance variables defined in its specification. -*/ -typedef struct objc_ivar { - const char* ivar_name; /* Name of the instance - variable as entered in the - class definition. */ - const char* ivar_type; /* Description of the Ivar's - type. Useful for - debuggers. */ - int ivar_offset; /* Byte offset from the base - address of the instance - structure to the variable. */ -} *Ivar_t; diff --git a/libobjc/objc/deprecated/struct_objc_ivar_list.h b/libobjc/objc/deprecated/struct_objc_ivar_list.h deleted file mode 100644 index 8f5051fb96..0000000000 --- a/libobjc/objc/deprecated/struct_objc_ivar_list.h +++ /dev/null @@ -1,10 +0,0 @@ -typedef struct objc_ivar_list { - int ivar_count; /* Number of structures (Ivar) - contained in the list. One - structure per instance - variable defined in the - class. */ - struct objc_ivar ivar_list[1]; /* Variable length - structure. */ -} IvarList, *IvarList_t; - diff --git a/libobjc/objc/deprecated/struct_objc_method.h b/libobjc/objc/deprecated/struct_objc_method.h deleted file mode 100644 index af83c07b6f..0000000000 --- a/libobjc/objc/deprecated/struct_objc_method.h +++ /dev/null @@ -1,22 +0,0 @@ -/* -** The compiler generates one (or more) of these structures for a class that -** has methods defined in its specification. -** -** The implementation of a class can be broken into separate pieces in a file -** and categories can break them across modules. To handle this problem is a -** singly linked list of methods. -*/ -struct objc_method { - SEL method_name; /* This variable is the method's - name. It is a char*. - The unique integer passed to - objc_msg_send is a char* too. - It is compared against - method_name using strcmp. */ - const char* method_types; /* Description of the method's - parameter list. Useful for - debuggers. */ - IMP method_imp; /* Address of the method in the - executable. */ -}; - diff --git a/libobjc/objc/deprecated/struct_objc_method_list.h b/libobjc/objc/deprecated/struct_objc_method_list.h deleted file mode 100644 index 5156cabbf2..0000000000 --- a/libobjc/objc/deprecated/struct_objc_method_list.h +++ /dev/null @@ -1,9 +0,0 @@ -typedef struct objc_method_list { - struct objc_method_list* method_next; /* This variable is used to link - a method list to another. It - is a singly linked list. */ - int method_count; /* Number of methods defined in - this structure. */ - Method method_list[1]; /* Variable length - structure. */ -} MethodList, *MethodList_t; diff --git a/libobjc/objc/deprecated/struct_objc_module.h b/libobjc/objc/deprecated/struct_objc_module.h deleted file mode 100644 index 57950851fa..0000000000 --- a/libobjc/objc/deprecated/struct_objc_module.h +++ /dev/null @@ -1,24 +0,0 @@ -/* -** The compiler generates one of these structures for each module that -** composes the executable (eg main.m). -** -** This data structure is the root of the definition tree for the module. -** -** A collect program runs between ld stages and creates a ObjC ctor array. -** That array holds a pointer to each module structure of the executable. -*/ -typedef struct objc_module { - unsigned long version; /* Version of the Module data structure. */ - unsigned long size; /* sizeof(Module) according to the compiler - - only used to sanity check that it matches - sizeof(Module) according to the - runtime. */ - const char* name; /* Name of the file used to compile the - module - not set by modern compilers for - security reasons. */ - Symtab_t symtab; /* Pointer to the Symtab of the module. The - Symtab holds an array of pointers to the - classes and categories defined in the - module. */ -} Module, *Module_t; - diff --git a/libobjc/objc/deprecated/struct_objc_protocol.h b/libobjc/objc/deprecated/struct_objc_protocol.h deleted file mode 100644 index 5344e3f549..0000000000 --- a/libobjc/objc/deprecated/struct_objc_protocol.h +++ /dev/null @@ -1,6 +0,0 @@ -typedef struct objc_protocol { - struct objc_class* class_pointer; - char *protocol_name; - struct objc_protocol_list *protocol_list; - struct objc_method_description_list *instance_methods, *class_methods; -} Protocol; diff --git a/libobjc/objc/deprecated/struct_objc_protocol_list.h b/libobjc/objc/deprecated/struct_objc_protocol_list.h deleted file mode 100644 index 5e5788b503..0000000000 --- a/libobjc/objc/deprecated/struct_objc_protocol_list.h +++ /dev/null @@ -1,5 +0,0 @@ -struct objc_protocol_list { - struct objc_protocol_list *next; - size_t count; - Protocol *list[1]; -}; diff --git a/libobjc/objc/deprecated/struct_objc_selector.h b/libobjc/objc/deprecated/struct_objc_selector.h deleted file mode 100644 index 34aaf0d8b4..0000000000 --- a/libobjc/objc/deprecated/struct_objc_selector.h +++ /dev/null @@ -1,20 +0,0 @@ -/* This struct used to be public, but is now private to the runtime. */ - -/* -** Definition of a selector. Selectors themselves are not unique, but -** the sel_id is a unique identifier. -*/ -struct objc_selector -{ - void *sel_id; - const char *sel_types; -}; - -inline static BOOL -sel_eq (SEL s1, SEL s2) -{ - if (s1 == 0 || s2 == 0) - return s1 == s2; - else - return s1->sel_id == s2->sel_id; -} diff --git a/libobjc/objc/deprecated/struct_objc_static_instances.h b/libobjc/objc/deprecated/struct_objc_static_instances.h deleted file mode 100644 index 9d889bfc08..0000000000 --- a/libobjc/objc/deprecated/struct_objc_static_instances.h +++ /dev/null @@ -1,14 +0,0 @@ -/* For every class which happens to have statically allocated instances in - this module, one OBJC_STATIC_INSTANCES is allocated by the compiler. - INSTANCES is NULL terminated and points to all statically allocated - instances of this class. */ -struct objc_static_instances -{ - char *class_name; -#ifdef __cplusplus - id instances[1]; -#else - id instances[0]; -#endif -}; - diff --git a/libobjc/objc/deprecated/struct_objc_symtab.h b/libobjc/objc/deprecated/struct_objc_symtab.h deleted file mode 100644 index 75bb27f1b5..0000000000 --- a/libobjc/objc/deprecated/struct_objc_symtab.h +++ /dev/null @@ -1,26 +0,0 @@ -/* Whereas a Module (defined further down) is the root (typically) of a file, - a Symtab is the root of the class and category definitions within the - module. - - A Symtab contains a variable length array of pointers to classes and - categories defined in the module. */ -typedef struct objc_symtab { - unsigned long sel_ref_cnt; /* Unused (always set to 0). */ - SEL refs; /* The table of selectors referenced in - this module. This is terminated by a - selector with NULL sel_id and NULL - sel_types. */ - unsigned short cls_def_cnt; /* Number of classes compiled - (defined) in the module. */ - unsigned short cat_def_cnt; /* Number of categories - compiled (defined) in the - module. */ - - void *defs[1]; /* Variable array of pointers. - cls_def_cnt of type Class - followed by cat_def_cnt of - type Category_t, followed - by a NULL terminated array - of objc_static_instances. */ -} Symtab, *Symtab_t; - diff --git a/libobjc/objc/deprecated/typedstream.h b/libobjc/objc/deprecated/typedstream.h deleted file mode 100644 index 4d948d5fb2..0000000000 --- a/libobjc/objc/deprecated/typedstream.h +++ /dev/null @@ -1,141 +0,0 @@ -/* GNU Objective-C Typed Streams interface. - Copyright (C) 1993, 1995, 2004, 2009 Free Software Foundation, Inc. - -This file is part of GCC. - -GCC 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 3, or (at your option) any -later version. - -GCC 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. - -Under Section 7 of GPL version 3, you are granted additional -permissions described in the GCC Runtime Library Exception, version -3.1, as published by the Free Software Foundation. - -You should have received a copy of the GNU General Public License and -a copy of the GCC Runtime Library Exception along with this program; -see the files COPYING3 and COPYING.RUNTIME respectively. If not, see -<http://www.gnu.org/licenses/>. */ - - -#ifndef __typedstream_INCLUDE_GNU -#define __typedstream_INCLUDE_GNU - -/* The API in this file was entirely deprecated in GCC 4.6.0 and will - be removed in the following GCC release. -*/ - -#include <stdio.h> - -#ifdef __cplusplus -extern "C" { -#endif /* __cplusplus */ - -typedef int (*objc_typed_read_func)(void*, char*, int); -typedef int (*objc_typed_write_func)(void*, const char*, int); -typedef int (*objc_typed_flush_func)(void*); -typedef int (*objc_typed_eof_func)(void*); - -#define OBJC_READONLY 0x01 -#define OBJC_WRITEONLY 0x02 - -#define OBJC_MANAGED_STREAM 0x01 -#define OBJC_FILE_STREAM 0x02 -#define OBJC_MEMORY_STREAM 0x04 - -#define OBJC_TYPED_STREAM_VERSION 0x01 - -typedef struct objc_typed_stream { - void* physical; - cache_ptr object_table; /* read/written objects */ - cache_ptr stream_table; /* other read/written but shared things.. */ - cache_ptr class_table; /* class version mapping */ - cache_ptr object_refs; /* forward references */ - int mode; /* OBJC_READONLY or OBJC_WRITEONLY */ - int type; /* MANAGED, FILE, MEMORY etc bit string */ - int version; /* version used when writing */ - int writing_root_p; - objc_typed_read_func read; - objc_typed_write_func write; - objc_typed_eof_func eof; - objc_typed_flush_func flush; -} TypedStream; - -/* opcode masks */ -#define _B_VALUE 0x1fU -#define _B_CODE 0xe0U -#define _B_SIGN 0x10U -#define _B_NUMBER 0x0fU - -/* standard opcodes */ -#define _B_INVALID 0x00U -#define _B_SINT 0x20U -#define _B_NINT 0x40U -#define _B_SSTR 0x60U -#define _B_NSTR 0x80U -#define _B_RCOMM 0xa0U -#define _B_UCOMM 0xc0U -#define _B_EXT 0xe0U - -/* eXtension opcodes */ -#define _BX_OBJECT 0x00U -#define _BX_CLASS 0x01U -#define _BX_SEL 0x02U -#define _BX_OBJREF 0x03U -#define _BX_OBJROOT 0x04U -#define _BX_EXT 0x1fU - -/* -** Read and write objects as specified by TYPE. All the `last' -** arguments are pointers to the objects to read/write. -*/ - -int objc_write_type (TypedStream* stream, const char* type, const void* data) __attribute__ ((deprecated)); -int objc_read_type (TypedStream* stream, const char* type, void* data) __attribute__ ((deprecated)); - -int objc_write_types (TypedStream* stream, const char* type, ...) __attribute__ ((deprecated)); -int objc_read_types (TypedStream* stream, const char* type, ...) __attribute__ ((deprecated)); - -int objc_write_object_reference (TypedStream* stream, id object) __attribute__ ((deprecated)); -int objc_write_root_object (TypedStream* stream, id object) __attribute__ ((deprecated)); - -long objc_get_stream_class_version (TypedStream* stream, Class class_type) __attribute__ ((deprecated)); - - -/* -** Convenience functions -*/ - -int objc_write_array (TypedStream* stream, const char* type, - int count, const void* data) __attribute__ ((deprecated)); -int objc_read_array (TypedStream* stream, const char* type, - int count, void* data) __attribute__ ((deprecated)); - -int objc_write_object (TypedStream* stream, id object) __attribute__ ((deprecated)); -int objc_read_object (TypedStream* stream, id* object) __attribute__ ((deprecated)); - - - -/* -** Open a typed stream for reading or writing. MODE may be either of -** OBJC_READONLY or OBJC_WRITEONLY. -*/ - -TypedStream* objc_open_typed_stream (FILE* physical, int mode) __attribute__ ((deprecated)); -TypedStream* objc_open_typed_stream_for_file (const char* file_name, int mode) __attribute__ ((deprecated)); - -void objc_close_typed_stream (TypedStream* stream) __attribute__ ((deprecated)); - -BOOL objc_end_of_typed_stream (TypedStream* stream) __attribute__ ((deprecated)); -void objc_flush_typed_stream (TypedStream* stream) __attribute__ ((deprecated)); - -#ifdef __cplusplus -} -#endif /* __cplusplus */ - -#endif /* not __typedstream_INCLUDE_GNU */ diff --git a/libobjc/objc/encoding.h b/libobjc/objc/encoding.h deleted file mode 100644 index 7852466b82..0000000000 --- a/libobjc/objc/encoding.h +++ /dev/null @@ -1,117 +0,0 @@ -/* Encoding of types for Objective C. - Copyright (C) 1993, 1997, 2002, 2004, 2009, 2010 - Free Software Foundation, Inc. - -Author: Kresten Krab Thorup - -This file is part of GCC. - -GCC 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 3, or (at your option) -any later version. - -GCC 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. - -Under Section 7 of GPL version 3, you are granted additional -permissions described in the GCC Runtime Library Exception, version -3.1, as published by the Free Software Foundation. - -You should have received a copy of the GNU General Public License and -a copy of the GCC Runtime Library Exception along with this program; -see the files COPYING3 and COPYING.RUNTIME respectively. If not, see -<http://www.gnu.org/licenses/>. */ - - -#ifndef __encoding_INCLUDE_GNU -#define __encoding_INCLUDE_GNU - -/* This file is to be used with the "traditional" GNU Objective-C - Runtime API (the one declared in objc/objc-api.h). If you are - using the "modern" GNU Objective-C Runtime API, then the useful - functions from this file are declared in objc/runtime.h. */ - -#include "objc-api.h" -#include <ctype.h> - -#ifdef __cplusplus -extern "C" { -#endif /* __cplusplus */ - -/* The following are used in encode strings to describe some - qualifiers of method and ivar types. */ -#define _C_CONST 'r' -#define _C_IN 'n' -#define _C_INOUT 'N' -#define _C_OUT 'o' -#define _C_BYCOPY 'O' -#define _C_BYREF 'R' -#define _C_ONEWAY 'V' -#define _C_GCINVISIBLE '|' - -/* The same when used as flags. */ -#define _F_CONST 0x01 -#define _F_IN 0x01 -#define _F_OUT 0x02 -#define _F_INOUT 0x03 -#define _F_BYCOPY 0x04 -#define _F_BYREF 0x08 -#define _F_ONEWAY 0x10 -#define _F_GCINVISIBLE 0x20 - -int objc_sizeof_type (const char *type); -int objc_alignof_type (const char *type); -int objc_aligned_size (const char *type); -int objc_promoted_size (const char *type); - -const char *objc_skip_type_qualifiers (const char *type); -const char *objc_skip_typespec (const char *type); -const char *objc_skip_offset (const char *type); -const char *objc_skip_argspec (const char *type); -unsigned objc_get_type_qualifiers (const char *type); - -/* The following functions are replaced, in the modern API, by - method_getNumberOfArguments(), method_getArgumentType(). */ -int method_get_number_of_arguments (struct objc_method *); -int method_get_sizeof_arguments (struct objc_method *); - -/* The following functions are deprecated and they use arglist_t which - is deprecated. */ -char *method_get_first_argument (struct objc_method *, - arglist_t argframe, - const char **type); -char *method_get_next_argument (arglist_t argframe, - const char **type); -char *method_get_nth_argument (struct objc_method *m, - arglist_t argframe, - int arg, - const char **type); - -struct objc_struct_layout -{ - const char *original_type; - const char *type; - const char *prev_type; - unsigned int record_size; - unsigned int record_align; -}; - -void objc_layout_structure (const char *type, - struct objc_struct_layout *layout); -BOOL objc_layout_structure_next_member (struct objc_struct_layout *layout); -void objc_layout_finish_structure (struct objc_struct_layout *layout, - unsigned int *size, - unsigned int *align); -void objc_layout_structure_get_info (struct objc_struct_layout *layout, - unsigned int *offset, - unsigned int *align, - const char **type); - -#ifdef __cplusplus -} -#endif /* __cplusplus */ - -#endif /* __encoding_INCLUDE_GNU */ diff --git a/libobjc/objc/hash.h b/libobjc/objc/hash.h deleted file mode 100644 index 8225a0992e..0000000000 --- a/libobjc/objc/hash.h +++ /dev/null @@ -1,3 +0,0 @@ -#include "objc.h" -#include "deprecated/hash.h" - diff --git a/libobjc/objc/message.h b/libobjc/objc/message.h index 8d03fefe4b..92b52633aa 100644 --- a/libobjc/objc/message.h +++ b/libobjc/objc/message.h @@ -92,33 +92,12 @@ objc_EXPORT IMP objc_msg_lookup (id receiver, SEL op); The compiler generates one of these structures and passes it to objc_msg_lookup_super() when a [super method] call is compiled. */ -/* In the traditional API, the super class field is called 'class' in - Objective-C and 'super_class' in Objective-C++. In the new API - (objc/runtime.h) it is always called 'super_class'. We detect the - "traditional API" by the fact that the objc/objc-api.h header - include guards are defined, which means objc/objc-api.h has been - included. This works because objc/message.h does not exist in the - Traditional API and is only read because objc-api.h itself includes - it. */ -#ifdef __objc_api_INCLUDE_GNU -/* Traditional API. */ -typedef struct objc_super -{ - id self; /* Id of the object sending the message. */ -#ifdef __cplusplus - Class super_class; -#else - Class class; /* Object's super class. */ -#endif -} Super, *Super_t; -#else /* Modern API. */ struct objc_super { id self; /* The receiver of the message. */ Class super_class; /* The superclass of the receiver. */ }; -#endif /* This is used by the compiler instead of objc_msg_lookup () when compiling a call to 'super', such as [super method]. This requires diff --git a/libobjc/objc/objc-api.h b/libobjc/objc/objc-api.h deleted file mode 100644 index 521f79efb3..0000000000 --- a/libobjc/objc/objc-api.h +++ /dev/null @@ -1,411 +0,0 @@ -/* GNU Objective-C Runtime API - Traditional API - Copyright (C) 1993, 1995, 1996, 1997, 2001, 2002, 2003, 2004, 2005, - 2007, 2009, 2010 Free Software Foundation, Inc. - -This file is part of GCC. - -GCC 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 3, or (at your option) any -later version. - -GCC 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. - -Under Section 7 of GPL version 3, you are granted additional -permissions described in the GCC Runtime Library Exception, version -3.1, as published by the Free Software Foundation. - -You should have received a copy of the GNU General Public License and -a copy of the GCC Runtime Library Exception along with this program; -see the files COPYING3 and COPYING.RUNTIME respectively. If not, see -<http://www.gnu.org/licenses/>. */ - -#ifndef __objc_api_INCLUDE_GNU -#define __objc_api_INCLUDE_GNU - -/* This file declares the "traditional" GNU Objective-C Runtime API. - It is the API supported by older versions of the GNU Objective-C - Runtime. Include this file to use it. - - This API is being replaced by the "modern" GNU Objective-C Runtime - API, which is declared in objc/runtime.h. The "modern" API is very - similar to the API used by the modern Apple/NeXT runtime. - - The last version of GCC supporting the traditional API is GCC 4.6. - This file will not exist in later versions of GCC. - - Because the two APIs have some conflicting definitions (in - particular, Method and Category are defined differently) you should - include either objc/objc-api.h (to use the traditional GNU - Objective-C Runtime API) or objc/runtime.h (to use the modern GNU - Objective-C Runtime API), but not both. */ -#ifdef __objc_runtime_INCLUDE_GNU -# error You can not include both objc/objc-api.h and objc/runtime.h. Include objc/objc-api.h for the traditional GNU Objective-C Runtime API and objc/runtime.h for the modern one. -#endif - -/* TODO: A deprecation warning any time the file is included ? */ - -#include "objc.h" -#ifndef GNU_LIBOBJC_COMPILING_LIBOBJC_ITSELF -# include "deprecated/hash.h" -#endif -#include "thr.h" -#include "objc-decls.h" -#include <stdio.h> -#include <stdarg.h> - -#ifdef __cplusplus -extern "C" { -#endif /* __cplusplus */ - -#include "deprecated/METHOD_NULL.h" - -/* Method descriptor returned by introspective Object methods. - This is really just the first part of the more complete objc_method - structure defined below and used internally by the runtime. */ -struct objc_method_description -{ - SEL name; /* this is a selector, not a string */ - char *types; /* type encoding */ -}; - -/* The following are used in encode strings to describe the type of - Ivars and Methods. */ -#define _C_ID '@' -#define _C_CLASS '#' -#define _C_SEL ':' -#define _C_CHR 'c' -#define _C_UCHR 'C' -#define _C_SHT 's' -#define _C_USHT 'S' -#define _C_INT 'i' -#define _C_UINT 'I' -#define _C_LNG 'l' -#define _C_ULNG 'L' -#define _C_LNG_LNG 'q' -#define _C_ULNG_LNG 'Q' -#define _C_FLT 'f' -#define _C_DBL 'd' -#define _C_LNG_DBL 'D' -#define _C_BFLD 'b' -#define _C_BOOL 'B' -#define _C_VOID 'v' -#define _C_UNDEF '?' -#define _C_PTR '^' -#define _C_CHARPTR '*' -#define _C_ARY_B '[' -#define _C_ARY_E ']' -#define _C_UNION_B '(' -#define _C_UNION_E ')' -#define _C_STRUCT_B '{' -#define _C_STRUCT_E '}' -#define _C_VECTOR '!' -#define _C_COMPLEX 'j' - -/* _C_ATOM is never generated by the compiler. You can treat it as - equivalent to "*". */ -#define _C_ATOM '%' - -#include "deprecated/objc_error.h" - -#include "deprecated/struct_objc_static_instances.h" -#include "deprecated/struct_objc_symtab.h" -#include "deprecated/struct_objc_module.h" -#include "deprecated/struct_objc_ivar.h" -#include "deprecated/struct_objc_ivar_list.h" -#include "deprecated/struct_objc_method.h" -typedef struct objc_method Method, *Method_t; - -#include "deprecated/struct_objc_method_list.h" -#include "deprecated/struct_objc_protocol_list.h" - -/* -** This is used to assure consistent access to the info field of -** classes -*/ -#ifndef HOST_BITS_PER_LONG -#define HOST_BITS_PER_LONG (sizeof(long)*8) -#endif - -#define __CLS_INFO(cls) ((cls)->info) -#define __CLS_ISINFO(cls, mask) ((__CLS_INFO(cls)&mask)==mask) -#define __CLS_SETINFO(cls, mask) (__CLS_INFO(cls) |= mask) - -/* The structure is of type MetaClass */ -#define _CLS_META 0x2L -#define CLS_ISMETA(cls) ((cls)&&__CLS_ISINFO(cls, _CLS_META)) - - -/* The structure is of type Class */ -#define _CLS_CLASS 0x1L -#define CLS_ISCLASS(cls) ((cls)&&__CLS_ISINFO(cls, _CLS_CLASS)) - -/* -** The class is initialized within the runtime. This means that -** it has had correct super and sublinks assigned -*/ -#define _CLS_RESOLV 0x8L -#define CLS_ISRESOLV(cls) __CLS_ISINFO(cls, _CLS_RESOLV) -#define CLS_SETRESOLV(cls) __CLS_SETINFO(cls, _CLS_RESOLV) - -/* -** The class has been send a +initialize message or a such is not -** defined for this class -*/ -#define _CLS_INITIALIZED 0x04L -#define CLS_ISINITIALIZED(cls) __CLS_ISINFO(cls, _CLS_INITIALIZED) -#define CLS_SETINITIALIZED(cls) __CLS_SETINFO(cls, _CLS_INITIALIZED) - -/* -** The class number of this class. This must be the same for both the -** class and its meta class object -*/ -#define CLS_GETNUMBER(cls) (__CLS_INFO(cls) >> (HOST_BITS_PER_LONG/2)) -#define CLS_SETNUMBER(cls, num) \ - ({ (cls)->info <<= (HOST_BITS_PER_LONG/2); \ - (cls)->info >>= (HOST_BITS_PER_LONG/2); \ - __CLS_SETINFO(cls, (((unsigned long)num) << (HOST_BITS_PER_LONG/2))); }) - -#include "deprecated/struct_objc_category.h" - -typedef struct objc_category Category, *Category_t; - -/* We include message.h for compatibility with the old objc-api.h - which included the declarations currently in message.h. The - Apple/NeXT runtime does not do this and only includes message.h in - objc-runtime.h. It does not matter that much since most of the - definitions in message.h are runtime-specific. */ -#include "message.h" - -/* -** This is a hook which is called by objc_lookup_class and -** objc_get_class if the runtime is not able to find the class. -** This may e.g. try to load in the class using dynamic loading. -** The function is guaranteed to be passed a non-NULL name string. -** In the Modern API, this is replaced by -** objc_setGetUnknownClassHandler (). -*/ -objc_EXPORT Class (*_objc_lookup_class)(const char *name); - -/* -** This is a hook which is called by __objc_exec_class every time a class -** or a category is loaded into the runtime. This may e.g. help a -** dynamic loader determine the classes that have been loaded when -** an object file is dynamically linked in. -*/ -objc_EXPORT void (*_objc_load_callback)(Class _class, Category* category); - -#include "deprecated/objc_object_alloc.h" - -/* - Standard functions for memory allocation and disposal. Users should - use these functions in their ObjC programs so that they work so that - they work properly with garbage collectors. -*/ -objc_EXPORT void * -objc_malloc(size_t size); - -/* FIXME: Shouldn't the following be called objc_malloc_atomic ? The - GC function is GC_malloc_atomic() which makes sense. - */ -objc_EXPORT void * -objc_atomic_malloc(size_t size); - -objc_EXPORT void * -objc_realloc(void *mem, size_t size); - -objc_EXPORT void * -objc_calloc(size_t nelem, size_t size); - -objc_EXPORT void -objc_free(void *mem); - -#include "deprecated/objc_valloc.h" -#include "deprecated/objc_malloc.h" - -#include "deprecated/objc_unexpected_exception.h" - -objc_EXPORT Method_t class_get_class_method(MetaClass _class, SEL aSel); - -objc_EXPORT Method_t class_get_instance_method(Class _class, SEL aSel); - -objc_EXPORT Class class_pose_as(Class impostor, Class superclass); - -objc_EXPORT Class objc_get_class(const char *name); - -objc_EXPORT Class objc_lookup_class(const char *name); - -objc_EXPORT Class objc_next_class(void **enum_state); - -objc_EXPORT const char *sel_get_name(SEL selector); - -objc_EXPORT const char *sel_get_type(SEL selector); - -objc_EXPORT SEL sel_get_uid(const char *name); - -objc_EXPORT SEL sel_get_any_uid(const char *name); - -objc_EXPORT SEL sel_get_any_typed_uid(const char *name); - -objc_EXPORT SEL sel_get_typed_uid(const char *name, const char*); - -objc_EXPORT SEL sel_register_name(const char *name); - -objc_EXPORT SEL sel_register_typed_name(const char *name, const char*type); - - -objc_EXPORT BOOL sel_is_mapped (SEL aSel); - -extern id class_create_instance(Class _class); - -static inline const char * -class_get_class_name(Class _class) -{ - return CLS_ISCLASS(_class)?_class->name:((_class==Nil)?"Nil":0); -} - -static inline long -class_get_instance_size(Class _class) -{ - return CLS_ISCLASS(_class)?_class->instance_size:0; -} - -static inline MetaClass -class_get_meta_class(Class _class) -{ - return CLS_ISCLASS(_class)?_class->class_pointer:Nil; -} - -static inline Class -class_get_super_class(Class _class) -{ - return CLS_ISCLASS(_class)?_class->super_class:Nil; -} - -static inline int -class_get_version(Class _class) -{ - return CLS_ISCLASS(_class)?_class->version:-1; -} - -static inline BOOL -class_is_class(Class _class) -{ - return CLS_ISCLASS(_class); -} - -static inline BOOL -class_is_meta_class(Class _class) -{ - return CLS_ISMETA(_class); -} - - -static inline void -class_set_version(Class _class, long version) -{ - if (CLS_ISCLASS(_class)) - _class->version = version; -} - -static inline void * -class_get_gc_object_type (Class _class) -{ - return CLS_ISCLASS(_class) ? _class->gc_object_type : NULL; -} - -/* Mark the instance variable as innaccessible to the garbage collector */ -extern void class_ivar_set_gcinvisible (Class _class, - const char* ivarname, - BOOL gcInvisible); - -objc_EXPORT IMP method_get_imp(Method_t method); - -objc_EXPORT IMP get_imp (Class _class, SEL sel); - -/* object_copy used to take a single argument in the traditional GNU - Objective-C Runtime API (the one declared here), but takes 2 in the - modern API (implemented in the actual runtime). Define the old - object_copy in terms of the new one. */ -objc_EXPORT id object_copy (id object, size_t size); -#define object_copy(X) (object_copy ((X), 0)) - -objc_EXPORT id object_dispose(id object); - -static inline Class -object_get_class(id object) -{ - return ((object!=nil) - ? (CLS_ISCLASS(object->class_pointer) - ? object->class_pointer - : (CLS_ISMETA(object->class_pointer) - ? (Class)object - : Nil)) - : Nil); -} - -static inline const char * -object_get_class_name(id object) -{ - return ((object!=nil)?(CLS_ISCLASS(object->class_pointer) - ?object->class_pointer->name - :((Class)object)->name) - :"Nil"); -} - -static inline MetaClass -object_get_meta_class(id object) -{ - return ((object!=nil)?(CLS_ISCLASS(object->class_pointer) - ?object->class_pointer->class_pointer - :(CLS_ISMETA(object->class_pointer) - ?object->class_pointer - :Nil)) - :Nil); -} - -static inline Class -object_get_super_class -(id object) -{ - return ((object!=nil)?(CLS_ISCLASS(object->class_pointer) - ?object->class_pointer->super_class - :(CLS_ISMETA(object->class_pointer) - ?((Class)object)->super_class - :Nil)) - :Nil); -} - -static inline BOOL -object_is_class (id object) -{ - return ((object != nil) && CLS_ISMETA (object->class_pointer)); -} - -static inline BOOL -object_is_instance (id object) -{ - return ((object != nil) && CLS_ISCLASS (object->class_pointer)); -} - -static inline BOOL -object_is_meta_class (id object) -{ - return ((object != nil) - && !object_is_instance (object) - && !object_is_class (object)); -} - -#include "deprecated/objc_get_uninstalled_dtable.h" - -#ifdef __cplusplus -} -#endif /* __cplusplus */ - -#endif /* not __objc_api_INCLUDE_GNU */ - - - diff --git a/libobjc/objc/objc-list.h b/libobjc/objc/objc-list.h deleted file mode 100644 index b713a3c0ec..0000000000 --- a/libobjc/objc/objc-list.h +++ /dev/null @@ -1,2 +0,0 @@ -#include "deprecated/objc-list.h" - diff --git a/libobjc/objc/objc.h b/libobjc/objc/objc.h index ece0f88410..1fa43737e4 100644 --- a/libobjc/objc/objc.h +++ b/libobjc/objc/objc.h @@ -36,11 +36,6 @@ extern "C" { #include <stddef.h> -/* objc-decls.h is included because deprecated/objc_msg_sendv.h needs - it. When that goes away, the include of objc-decls.h should be - removed. */ -#include "objc-decls.h" - /* The current version of the GNU Objective-C Runtime library in compressed ISO date format. This should be updated any time a new version is released with changes to the public API (there is no @@ -48,7 +43,7 @@ extern "C" { release). This macro is only defined starting with the GNU Objective-C Runtime shipped with GCC 4.6.0. If it is not defined, it is either an older version of the runtime, or another runtime. */ -#define __GNU_LIBOBJC__ 20100911 +#define __GNU_LIBOBJC__ 20110608 /* Definition of the boolean type. @@ -76,15 +71,12 @@ typedef unsigned char BOOL; selector and know that the class implements it, you can use it to call the method for an object in the class. */ typedef const struct objc_selector *SEL; -#include "deprecated/struct_objc_selector.h" /* A Class is a class (in the object-oriented sense). In Objective-C there is the complication that each Class is an object itself, and so belongs to a class too. This class that a class belongs to is called its 'meta class'. */ typedef struct objc_class *Class; -#include "deprecated/MetaClass.h" -#include "deprecated/struct_objc_class.h" /* An 'id' is an object of an unknown class. The way the object data is stored inside the object is private and what you see here is @@ -125,8 +117,6 @@ typedef id (*IMP)(id, SEL, ...); compiler to do some type-checking. */ #define Nil (Class)0 -#include "deprecated/STR.h" - /* TODO: Move the 'Protocol' declaration into objc/runtime.h. A Protocol is simply an object, not a basic Objective-C type. The Apple runtime defines Protocol in objc/runtime.h too, so it's good @@ -142,18 +132,11 @@ typedef id (*IMP)(id, SEL, ...); there is no reason to even define a 'struct objc_protocol'. As all the structure details will be hidden, a Protocol basically is simply an object (as it should be). */ - /* typedef struct objc_object Protocol; */ - #include "deprecated/struct_objc_protocol.h" + typedef struct objc_object Protocol; #else /* __OBJC__ */ @class Protocol; #endif -/* Deprecated include - here temporarily, for backwards-compatibility - as reval_t, apply_t, arglist_t and objc_msg_lookup() used to be - defined here. objc_msg_lookup() is now defined in message.h, - included by objc-api.h or runtime.h. */ -#include "deprecated/objc_msg_sendv.h" - /* Compatibility note: the Apple/NeXT runtime defines sel_getName(), sel_registerName(), object_getClassName(), object_getIndexedIvars() in this file while the GNU runtime defines them in runtime.h. diff --git a/libobjc/objc/runtime.h b/libobjc/objc/runtime.h index 6e1f1ec36e..c649e239d9 100644 --- a/libobjc/objc/runtime.h +++ b/libobjc/objc/runtime.h @@ -28,23 +28,13 @@ see the files COPYING3 and COPYING.RUNTIME respectively. If not, see /* This file declares the "modern" GNU Objective-C Runtime API. - Include this file to use it. - - This API is replacing the "traditional" GNU Objective-C Runtime API - (declared in objc/objc-api.h) which is the one supported by older - versions of the GNU Objective-C Runtime. The "modern" API is very - similar to the API used by the modern Apple/NeXT runtime. - - Because the two APIs have some conflicting definitions (in - particular, Method and Category are defined differently) you should - include either objc/objc-api.h (to use the traditional GNU - Objective-C Runtime API) or objc/runtime.h (to use the modern GNU - Objective-C Runtime API), but not both. -*/ -#ifdef __objc_api_INCLUDE_GNU -# error You can not include both objc/objc-api.h and objc/runtime.h. Include objc/objc-api.h for the traditional GNU Objective-C Runtime API and objc/runtime.h for the modern one. -#endif + This API replaced the "traditional" GNU Objective-C Runtime API + (which used to be declared in objc/objc-api.h) which is the one + supported by older versions of the GNU Objective-C Runtime. The + "modern" API is very similar to the API used by the modern + Apple/NeXT runtime. +*/ #include "objc.h" #include "objc-decls.h" @@ -507,10 +497,10 @@ objc_EXPORT const char * class_getName (Class class_); objc_EXPORT BOOL class_isMetaClass (Class class_); /* Return the superclass of 'class_'. If 'class_' is Nil, or it is a - root class, return Nil. If 'class_' is a class being constructed, - that is, a class returned by objc_allocateClassPair() but before it - has been registered with the runtime using - objc_registerClassPair(), return Nil. */ + root class, return Nil. This function also works if 'class_' is a + class being constructed, that is, a class returned by + objc_allocateClassPair() but before it has been registered with the + runtime using objc_registerClassPair(). */ objc_EXPORT Class class_getSuperclass (Class class_); /* Return the 'version' number of the class, which is an integer that diff --git a/libobjc/objc/sarray.h b/libobjc/objc/sarray.h deleted file mode 100644 index ff51e47f91..0000000000 --- a/libobjc/objc/sarray.h +++ /dev/null @@ -1,2 +0,0 @@ -#include "deprecated/sarray.h" - diff --git a/libobjc/objc/typedstream.h b/libobjc/objc/typedstream.h deleted file mode 100644 index a39c51b29d..0000000000 --- a/libobjc/objc/typedstream.h +++ /dev/null @@ -1,4 +0,0 @@ -#include "objc.h" -#include "deprecated/hash.h" -#include "deprecated/typedstream.h" - diff --git a/libobjc/objects.c b/libobjc/objects.c index 1c69456a63..fe11062835 100644 --- a/libobjc/objects.c +++ b/libobjc/objects.c @@ -67,12 +67,6 @@ class_createInstance (Class class, size_t extraBytes) /* Traditional GNU Objective-C Runtime API. */ id -class_create_instance (Class class) -{ - return class_createInstance (class, 0); -} - -id object_copy (id object, size_t extraBytes) { if ((object != nil) && CLS_ISCLASS (object->class_pointer)) @@ -122,9 +116,3 @@ object_setClass (id object, Class class_) return old_class; } } - -/* Hook functions for memory allocation and disposal. Deprecated and - currently unused. */ -id (*_objc_object_alloc) (Class) = 0; -id (*_objc_object_dispose) (id) = 0; -id (*_objc_object_copy) (id) = 0; diff --git a/libobjc/protocols.c b/libobjc/protocols.c index 3ff6fbaa1c..a02f2cd999 100644 --- a/libobjc/protocols.c +++ b/libobjc/protocols.c @@ -55,7 +55,7 @@ __objc_protocols_init (void) /* Add a protocol to the hashtable. */ void -__objc_protocols_add_protocol (const char *name, Protocol *object) +__objc_protocols_add_protocol (const char *name, struct objc_protocol *object) { objc_mutex_lock (__protocols_hashtable_lock); @@ -153,7 +153,7 @@ class_addProtocol (Class class_, Protocol *protocol) /* Create the objc_protocol_list. */ protocols = malloc (sizeof (struct objc_protocol_list)); protocols->count = 1; - protocols->list[0] = protocol; + protocols->list[0] = (struct objc_protocol *)protocol; /* Attach it to the list of class protocols. */ protocols->next = class_->protocols; @@ -189,8 +189,8 @@ class_conformsToProtocol (Class class_, Protocol *protocol) size_t i; for (i = 0; i < proto_list->count; i++) { - if (proto_list->list[i] == protocol - || protocol_conformsToProtocol (proto_list->list[i], + if (proto_list->list[i] == (struct objc_protocol *)protocol + || protocol_conformsToProtocol ((Protocol *)proto_list->list[i], protocol)) { objc_mutex_unlock (__objc_runtime_mutex); @@ -246,7 +246,7 @@ class_copyProtocolList (Class class_, unsigned int *numberOfReturnedProtocols) size_t j; for (j = 0; j < proto_list->count; j++) { - returnValue[i] = proto_list->list[j]; + returnValue[i] = (Protocol *)proto_list->list[j]; i++; } proto_list = proto_list->next; @@ -294,7 +294,7 @@ protocol_conformsToProtocol (Protocol *protocol, Protocol *anotherProtocol) for (i = 0; i < proto_list->count; i++) { - if (protocol_conformsToProtocol (proto_list->list[i], anotherProtocol)) + if (protocol_conformsToProtocol ((Protocol *)proto_list->list[i], anotherProtocol)) return YES; } proto_list = proto_list->next; @@ -541,7 +541,7 @@ Protocol **protocol_copyProtocolList (Protocol *protocol, unsigned int *numberOf size_t j; for (j = 0; j < proto_list->count; j++) { - returnValue[i] = proto_list->list[j]; + returnValue[i] = (Protocol *)proto_list->list[j]; i++; } proto_list = proto_list->next; diff --git a/libobjc/sarray.c b/libobjc/sarray.c index ea4aa93b78..f58c416a22 100644 --- a/libobjc/sarray.c +++ b/libobjc/sarray.c @@ -27,6 +27,7 @@ see the files COPYING3 and COPYING.RUNTIME respectively. If not, see #include "objc-private/sarray.h" #include "objc/runtime.h" /* For objc_malloc */ #include "objc/thr.h" /* For objc_mutex_lock */ +#include "objc-private/module-abi-8.h" #include "objc-private/runtime.h" #include <stdio.h> #include <string.h> /* For memset */ diff --git a/libobjc/selector.c b/libobjc/selector.c index 628b4f6f46..55ca7064bd 100644 --- a/libobjc/selector.c +++ b/libobjc/selector.c @@ -227,7 +227,7 @@ sel_isEqual (SEL s1, SEL s2) /* Return YES iff t1 and t2 have same method types. Ignore the argframe layout. */ -BOOL +static BOOL sel_types_match (const char *t1, const char *t2) { if (! t1 || ! t2) @@ -252,83 +252,6 @@ sel_types_match (const char *t1, const char *t2) return NO; } -/* Return selector representing name. In the Modern API, you'd - normally use sel_registerTypedName() for this, which does the same - but would register the selector with the runtime if not registered - yet (if you only want to check for selectors without registering, - use sel_copyTypedSelectorList()). */ -SEL -sel_get_typed_uid (const char *name, const char *types) -{ - struct objc_list *l; - sidx i; - - objc_mutex_lock (__objc_runtime_mutex); - - i = (sidx) objc_hash_value_for_key (__objc_selector_hash, name); - if (i == 0) - { - objc_mutex_unlock (__objc_runtime_mutex); - return 0; - } - - for (l = (struct objc_list *) sarray_get_safe (__objc_selector_array, i); - l; l = l->tail) - { - SEL s = (SEL) l->head; - if (types == 0 || s->sel_types == 0) - { - if (s->sel_types == types) - { - objc_mutex_unlock (__objc_runtime_mutex); - return s; - } - } - else if (sel_types_match (s->sel_types, types)) - { - objc_mutex_unlock (__objc_runtime_mutex); - return s; - } - } - - objc_mutex_unlock (__objc_runtime_mutex); - return 0; -} - -/* Return selector representing name; prefer a selector with non-NULL - type. In the Modern API, sel_getTypedSelector() is similar but - returns NULL if a typed selector couldn't be found. */ -SEL -sel_get_any_typed_uid (const char *name) -{ - struct objc_list *l; - sidx i; - SEL s = NULL; - - objc_mutex_lock (__objc_runtime_mutex); - - i = (sidx) objc_hash_value_for_key (__objc_selector_hash, name); - if (i == 0) - { - objc_mutex_unlock (__objc_runtime_mutex); - return 0; - } - - for (l = (struct objc_list *) sarray_get_safe (__objc_selector_array, i); - l; l = l->tail) - { - s = (SEL) l->head; - if (s->sel_types) - { - objc_mutex_unlock (__objc_runtime_mutex); - return s; - } - } - - objc_mutex_unlock (__objc_runtime_mutex); - return s; -} - /* Return selector representing name. */ SEL sel_get_any_uid (const char *name) @@ -493,15 +416,6 @@ const char *sel_getName (SEL selector) return ret; } -/* Traditional GNU Objective-C Runtime API. */ -const char *sel_get_name (SEL selector) -{ - if (selector == NULL) - return 0; - - return sel_getName (selector); -} - BOOL sel_is_mapped (SEL selector) { @@ -517,12 +431,6 @@ const char *sel_getTypeEncoding (SEL selector) return 0; } -/* Traditional GNU Objective-C Runtime API. */ -const char *sel_get_type (SEL selector) -{ - return sel_getTypeEncoding (selector); -} - /* The uninstalled dispatch table. */ extern struct sarray *__objc_uninstalled_dtable; @@ -707,13 +615,6 @@ sel_registerName (const char *name) return ret; } -/* Traditional GNU Objective-C Runtime API. */ -SEL -sel_register_name (const char *name) -{ - return sel_registerName (name); -} - SEL sel_registerTypedName (const char *name, const char *type) { @@ -732,22 +633,9 @@ sel_registerTypedName (const char *name, const char *type) return ret; } -SEL -sel_register_typed_name (const char *name, const char *type) -{ - return sel_registerTypedName (name, type); -} - /* Return the selector representing name. */ SEL sel_getUid (const char *name) { return sel_registerTypedName (name, 0); } - -/* Traditional GNU Objective-C Runtime API. */ -SEL -sel_get_uid (const char *name) -{ - return sel_getUid (name); -} diff --git a/libobjc/sendmsg.c b/libobjc/sendmsg.c index 0cb375db39..ea8ea97026 100644 --- a/libobjc/sendmsg.c +++ b/libobjc/sendmsg.c @@ -41,6 +41,7 @@ see the files COPYING3 and COPYING.RUNTIME respectively. If not, see #include "objc/thr.h" #include "objc-private/module-abi-8.h" #include "objc-private/runtime.h" +#include "objc-private/hash.h" #include "objc-private/sarray.h" #include "objc-private/selector.h" /* For sel_is_mapped() */ #include "runtime-info.h" @@ -61,7 +62,9 @@ see the files COPYING3 and COPYING.RUNTIME respectively. If not, see #define INVISIBLE_STRUCT_RETURN 0 #endif -/* The uninstalled dispatch table. */ +/* The uninstalled dispatch table. If a class' dispatch table points + to __objc_uninstalled_dtable then that means it needs its dispatch + table to be installed. */ struct sarray *__objc_uninstalled_dtable = 0; /* !T:MUTEX */ /* Two hooks for method forwarding. If either is set, it is invoked to @@ -75,10 +78,14 @@ IMP (*__objc_msg_forward2) (id, SEL) = NULL; /* Send +initialize to class. */ static void __objc_send_initialize (Class); -static void __objc_install_dispatch_table_for_class (Class); +/* Forward declare some functions */ +static void __objc_install_dtable_for_class (Class cls); +static void __objc_prepare_dtable_for_class (Class cls); +static void __objc_install_prepared_dtable_for_class (Class cls); -/* Forward declare some functions. */ -static void __objc_init_install_dtable (id, SEL); +static struct sarray *__objc_prepared_dtable_for_class (Class cls); +static IMP __objc_get_prepared_imp (Class cls,SEL sel); + /* Various forwarding functions that are used based upon the return type for the selector. @@ -117,7 +124,7 @@ __objc_get_forward_imp (id rcv, SEL sel) { IMP result; if ((result = __objc_msg_forward (sel)) != NULL) - return result; + return result; } /* In all other cases, use the default forwarding functions built @@ -210,7 +217,7 @@ __objc_resolve_instance_method (Class class, SEL sel) { objc_mutex_lock (__objc_runtime_mutex); if (class->class_pointer->dtable == __objc_uninstalled_dtable) - __objc_install_dispatch_table_for_class (class->class_pointer); + __objc_install_dtable_for_class (class->class_pointer); objc_mutex_unlock (__objc_runtime_mutex); } resolveMethodIMP = sarray_get_safe (class->class_pointer->dtable, @@ -231,8 +238,89 @@ __objc_resolve_instance_method (Class class, SEL sel) return NULL; } -/* Given a class and selector, return the selector's - implementation. */ +/* Given a CLASS and selector, return the implementation corresponding + to the method of the selector. + + If CLASS is a class, the instance method is returned. + If CLASS is a meta class, the class method is returned. + + Since this requires the dispatch table to be installed, this function + will implicitly invoke +initialize for CLASS if it hasn't been + invoked yet. This also insures that +initialize has been invoked + when the returned implementation is called directly. + + The forwarding hooks require the receiver as an argument (if they are to + perform dynamic lookup in proxy objects etc), so this function has a + receiver argument to be used with those hooks. */ +static inline +IMP +get_implementation (id receiver, Class class, SEL sel) +{ + void *res; + + if (class->dtable == __objc_uninstalled_dtable) + { + /* The dispatch table needs to be installed. */ + objc_mutex_lock (__objc_runtime_mutex); + + /* Double-checked locking pattern: Check + __objc_uninstalled_dtable again in case another thread + installed the dtable while we were waiting for the lock to be + released. */ + if (class->dtable == __objc_uninstalled_dtable) + __objc_install_dtable_for_class (class); + + /* If the dispatch table is not yet installed, we are still in + the process of executing +initialize. But the implementation + pointer should be available in the prepared ispatch table if + it exists at all. */ + if (class->dtable == __objc_uninstalled_dtable) + { + assert (__objc_prepared_dtable_for_class (class) != 0); + res = __objc_get_prepared_imp (class, sel); + } + else + res = 0; + + objc_mutex_unlock (__objc_runtime_mutex); + /* Call ourselves with the installed dispatch table and get the + real method. */ + if (!res) + res = get_implementation (receiver, class, sel); + } + else + { + /* The dispatch table has been installed. */ + res = sarray_get_safe (class->dtable, (size_t) sel->sel_id); + if (res == 0) + { + /* The dispatch table has been installed, and the method is + not in the dispatch table. So the method just doesn't + exist for the class. */ + + /* Try going through the +resolveClassMethod: or + +resolveInstanceMethod: process. */ + if (CLS_ISMETA (class)) + { + /* We have the meta class, but we need to invoke the + +resolveClassMethod: method on the class. So, we + need to obtain the class from the meta class, which + we do using the fact that both the class and the + meta-class have the same name. */ + Class realClass = objc_lookUpClass (class->name); + if (realClass) + res = __objc_resolve_class_method (realClass, sel); + } + else + res = __objc_resolve_instance_method (class, sel); + + if (res == 0) + res = __objc_get_forward_imp (receiver, sel); + } + } + return res; +} + inline IMP get_imp (Class class, SEL sel) @@ -248,70 +336,7 @@ get_imp (Class class, SEL sel) void *res = sarray_get_safe (class->dtable, (size_t) sel->sel_id); if (res == 0) { - /* Not a valid method. */ - if (class->dtable == __objc_uninstalled_dtable) - { - /* The dispatch table needs to be installed. */ - objc_mutex_lock (__objc_runtime_mutex); - - /* Double-checked locking pattern: Check - __objc_uninstalled_dtable again in case another thread - installed the dtable while we were waiting for the lock - to be released. */ - if (class->dtable == __objc_uninstalled_dtable) - { - __objc_install_dispatch_table_for_class (class); - } - - objc_mutex_unlock (__objc_runtime_mutex); - /* Call ourselves with the installed dispatch table and get - the real method. */ - res = get_imp (class, sel); - } - else - { - /* The dispatch table has been installed. */ - - /* Get the method from the dispatch table (we try to get it - again in case another thread has installed the dtable just - after we invoked sarray_get_safe, but before we checked - class->dtable == __objc_uninstalled_dtable). */ - res = sarray_get_safe (class->dtable, (size_t) sel->sel_id); - if (res == 0) - { - /* The dispatch table has been installed, and the method - is not in the dispatch table. So the method just - doesn't exist for the class. */ - - /* Try going through the +resolveClassMethod: or - +resolveInstanceMethod: process. */ - if (CLS_ISMETA (class)) - { - /* We have the meta class, but we need to invoke the - +resolveClassMethod: method on the class. So, we - need to obtain the class from the meta class, - which we do using the fact that both the class - and the meta-class have the same name. */ - Class realClass = objc_lookUpClass (class->name); - if (realClass) - res = __objc_resolve_class_method (realClass, sel); - } - else - res = __objc_resolve_instance_method (class, sel); - - if (res == 0) - { - /* If that fails, then return the forwarding - implementation. We don't know the receiver (only - its class), so we have to pass 'nil' as the first - argument. Passing the class as first argument is - wrong because the class is not the receiver; it - can result in us calling a class method when we - want an instance method of the same name. */ - res = __objc_get_forward_imp (nil, sel); - } - } - } + res = get_implementation(nil, class, sel); } return res; } @@ -337,51 +362,77 @@ method_get_imp (struct objc_method * method) /* Query if an object can respond to a selector, returns YES if the object implements the selector otherwise NO. Does not check if the - method can be forwarded. */ + method can be forwarded. Since this requires the dispatch table to + installed, this function will implicitly invoke +initialize for the + class of OBJECT if it hasn't been invoked yet. */ inline BOOL __objc_responds_to (id object, SEL sel) { void *res; + struct sarray *dtable; - /* Install dispatch table if need be. */ - if (object->class_pointer->dtable == __objc_uninstalled_dtable) + /* Install dispatch table if need be */ + dtable = object->class_pointer->dtable; + if (dtable == __objc_uninstalled_dtable) { objc_mutex_lock (__objc_runtime_mutex); if (object->class_pointer->dtable == __objc_uninstalled_dtable) - { - __objc_install_dispatch_table_for_class (object->class_pointer); - } + __objc_install_dtable_for_class (object->class_pointer); + + /* If the dispatch table is not yet installed, we are still in + the process of executing +initialize. Yet the dispatch table + should be available. */ + if (object->class_pointer->dtable == __objc_uninstalled_dtable) + { + dtable = __objc_prepared_dtable_for_class (object->class_pointer); + assert (dtable); + } + else + dtable = object->class_pointer->dtable; + objc_mutex_unlock (__objc_runtime_mutex); } /* Get the method from the dispatch table. */ - res = sarray_get_safe (object->class_pointer->dtable, (size_t) sel->sel_id); - return (res != 0); + res = sarray_get_safe (dtable, (size_t) sel->sel_id); + return (res != 0) ? YES : NO; } BOOL class_respondsToSelector (Class class_, SEL selector) { + struct sarray *dtable; void *res; if (class_ == Nil || selector == NULL) return NO; /* Install dispatch table if need be. */ - if (class_->dtable == __objc_uninstalled_dtable) + dtable = class_->dtable; + if (dtable == __objc_uninstalled_dtable) { objc_mutex_lock (__objc_runtime_mutex); if (class_->dtable == __objc_uninstalled_dtable) - { - __objc_install_dispatch_table_for_class (class_); - } + __objc_install_dtable_for_class (class_); + + /* If the dispatch table is not yet installed, + we are still in the process of executing +initialize. + Yet the dispatch table should be available. */ + if (class_->dtable == __objc_uninstalled_dtable) + { + dtable = __objc_prepared_dtable_for_class (class_); + assert (dtable); + } + else + dtable = class_->dtable; + objc_mutex_unlock (__objc_runtime_mutex); } /* Get the method from the dispatch table. */ - res = sarray_get_safe (class_->dtable, (size_t) selector->sel_id); - return (res != 0); + res = sarray_get_safe (dtable, (size_t) selector->sel_id); + return (res != 0) ? YES : NO; } /* This is the lookup function. All entries in the table are either a @@ -394,48 +445,16 @@ objc_msg_lookup (id receiver, SEL op) IMP result; if (receiver) { + /* First try a quick lookup assuming the dispatch table exists. */ result = sarray_get_safe (receiver->class_pointer->dtable, (sidx)op->sel_id); if (result == 0) { - /* Not a valid method. */ - if (receiver->class_pointer->dtable == __objc_uninstalled_dtable) - { - /* The dispatch table needs to be installed. This - happens on the very first method call to the - class. */ - __objc_init_install_dtable (receiver, op); - - /* Get real method for this in newly installed - dtable. */ - result = get_imp (receiver->class_pointer, op); - } - else - { - /* The dispatch table has been installed. Check again - if the method exists (just in case the dispatch table - has been installed by another thread after we did the - previous check that the method exists). */ - result = sarray_get_safe (receiver->class_pointer->dtable, - (sidx)op->sel_id); - if (result == 0) - { - /* Try going through the +resolveClassMethod: or - +resolveInstanceMethod: process. */ - if (CLS_ISMETA (receiver->class_pointer)) - result = __objc_resolve_class_method ((Class)receiver, op); - else - result = __objc_resolve_instance_method (receiver->class_pointer, - op); - - if (result == 0) - { - /* If the method still just doesn't exist for - the class, attempt to forward the method. */ - result = __objc_get_forward_imp (receiver, op); - } - } - } + /* Not found ... call get_implementation () to install the + dispatch table and call +initialize as required, + providing the method implementation or a forwarding + function. */ + result = get_implementation (receiver, receiver->class_pointer, op); } return result; } @@ -452,29 +471,6 @@ objc_msg_lookup_super (struct objc_super *super, SEL sel) return (IMP)nil_method; } -/* Temporarily defined here until objc_msg_sendv() goes away. */ -char *method_get_first_argument (struct objc_method *, - arglist_t argframe, - const char **type); -char *method_get_next_argument (arglist_t argframe, - const char **type); -int method_get_sizeof_arguments (struct objc_method *); - -struct objc_method * -class_get_instance_method (Class class, SEL op); - -retval_t -objc_msg_sendv (id object, SEL op, arglist_t arg_frame) -{ - struct objc_method *m = class_get_instance_method (object->class_pointer, op); - const char *type; - *((id *) method_get_first_argument (m, arg_frame, &type)) = object; - *((SEL *) method_get_next_argument (arg_frame, &type)) = op; - return __builtin_apply ((apply_t) m->method_imp, - arg_frame, - method_get_sizeof_arguments (m)); -} - void __objc_init_dispatch_tables () { @@ -482,50 +478,9 @@ __objc_init_dispatch_tables () /* TODO: It would be cool to register typed selectors here. */ selector_resolveClassMethod = sel_registerName ("resolveClassMethod:"); - selector_resolveInstanceMethod =sel_registerName ("resolveInstanceMethod:"); + selector_resolveInstanceMethod = sel_registerName ("resolveInstanceMethod:"); } -/* This function is called by objc_msg_lookup when the dispatch table - needs to be installed; thus it is called once for each class, - namely when the very first message is sent to it. */ -static void -__objc_init_install_dtable (id receiver, SEL op __attribute__ ((__unused__))) -{ - objc_mutex_lock (__objc_runtime_mutex); - - /* This may happen, if the programmer has taken the address of a - method before the dtable was initialized... too bad for him! */ - if (receiver->class_pointer->dtable != __objc_uninstalled_dtable) - { - objc_mutex_unlock (__objc_runtime_mutex); - return; - } - - if (CLS_ISCLASS (receiver->class_pointer)) - { - /* receiver is an ordinary object. */ - assert (CLS_ISCLASS (receiver->class_pointer)); - - /* Install instance methods table. */ - __objc_install_dispatch_table_for_class (receiver->class_pointer); - - /* Call +initialize -- this will in turn install the factory - dispatch table if not already done. :-) */ - __objc_send_initialize (receiver->class_pointer); - } - else - { - /* receiver is a class object. */ - assert (CLS_ISCLASS ((Class)receiver)); - assert (CLS_ISMETA (receiver->class_pointer)); - - /* Install real dtable for factory methods. */ - __objc_install_dispatch_table_for_class (receiver->class_pointer); - - __objc_send_initialize ((Class)receiver); - } - objc_mutex_unlock (__objc_runtime_mutex); -} /* Install dummy table for class which causes the first message to that class (or instances hereof) to be initialized properly. */ @@ -544,6 +499,9 @@ __objc_send_initialize (Class class) assert (CLS_ISCLASS (class)); assert (! CLS_ISMETA (class)); + /* class_add_method_list/__objc_update_dispatch_table_for_class may + have reset the dispatch table. The canonical way to insure that + we send +initialize just once, is this flag. */ if (! CLS_ISINITIALIZED (class)) { DEBUG_PRINTF ("+initialize: need to initialize class '%s'\n", class->name); @@ -558,34 +516,13 @@ __objc_send_initialize (Class class) { SEL op = sel_registerName ("initialize"); - IMP imp = 0; - struct objc_method_list * method_list = class->class_pointer->methods; - - while (method_list) - { - int i; - struct objc_method * method; - - for (i = 0; i < method_list->method_count; i++) - { - method = &(method_list->method_list[i]); - if (method->method_name - && method->method_name->sel_id == op->sel_id) - { - imp = method->method_imp; - break; - } - } - - if (imp) - break; - - method_list = method_list->method_next; - } - if (imp) + struct objc_method *method = search_for_method_in_hierarchy (class->class_pointer, + op); + + if (method) { DEBUG_PRINTF (" begin of [%s +initialize]\n", class->name); - (*imp) ((id) class, op); + (*method->method_imp) ((id)class, op); DEBUG_PRINTF (" end of [%s +initialize]\n", class->name); } #ifdef DEBUG @@ -606,7 +543,7 @@ __objc_send_initialize (Class class) guaranteed about what method will be used. Assumes that __objc_runtime_mutex is locked down. */ static void -__objc_install_methods_in_dtable (Class class, struct objc_method_list * method_list) +__objc_install_methods_in_dtable (struct sarray *dtable, struct objc_method_list * method_list) { int i; @@ -614,68 +551,46 @@ __objc_install_methods_in_dtable (Class class, struct objc_method_list * method_ return; if (method_list->method_next) - __objc_install_methods_in_dtable (class, method_list->method_next); + __objc_install_methods_in_dtable (dtable, method_list->method_next); for (i = 0; i < method_list->method_count; i++) { struct objc_method * method = &(method_list->method_list[i]); - sarray_at_put_safe (class->dtable, + sarray_at_put_safe (dtable, (sidx) method->method_name->sel_id, method->method_imp); } } -/* Assumes that __objc_runtime_mutex is locked down. */ -static void -__objc_install_dispatch_table_for_class (Class class) -{ - Class super; - - /* If the class has not yet had its class links resolved, we must - re-compute all class links. */ - if (! CLS_ISRESOLV (class)) - __objc_resolve_class_links (); - - DEBUG_PRINTF ("__objc_install_dispatch_table_for_class (%s)\n", class->name); - - super = class->super_class; - - if (super != 0 && (super->dtable == __objc_uninstalled_dtable)) - __objc_install_dispatch_table_for_class (super); - - /* Allocate dtable if necessary. */ - if (super == 0) - { - objc_mutex_lock (__objc_runtime_mutex); - class->dtable = sarray_new (__objc_selector_max_index, 0); - objc_mutex_unlock (__objc_runtime_mutex); - } - else - class->dtable = sarray_lazy_copy (super->dtable); - - __objc_install_methods_in_dtable (class, class->methods); -} - void __objc_update_dispatch_table_for_class (Class class) { Class next; struct sarray *arr; - /* Not yet installed -- skip it. */ - if (class->dtable == __objc_uninstalled_dtable) - return; - - DEBUG_PRINTF (" _objc_update_dispatch_table_for_class (%s)\n", class->name); + DEBUG_PRINTF (" _objc_update_dtable_for_class (%s)\n", class->name); objc_mutex_lock (__objc_runtime_mutex); + /* Not yet installed -- skip it unless in +initialize. */ + if (class->dtable == __objc_uninstalled_dtable) + { + if (__objc_prepared_dtable_for_class (class)) + { + /* There is a prepared table so we must be initialising this + class ... we must re-do the table preparation. */ + __objc_prepare_dtable_for_class (class); + } + objc_mutex_unlock (__objc_runtime_mutex); + return; + } + arr = class->dtable; __objc_install_premature_dtable (class); /* someone might require it... */ sarray_free (arr); /* release memory */ /* Could have been lazy... */ - __objc_install_dispatch_table_for_class (class); + __objc_install_dtable_for_class (class); if (class->subclass_list) /* Traverse subclasses. */ for (next = class->subclass_list; next; next = next->sibling_class) @@ -708,18 +623,6 @@ class_add_method_list (Class class, struct objc_method_list * list) } struct objc_method * -class_get_instance_method (Class class, SEL op) -{ - return search_for_method_in_hierarchy (class, op); -} - -struct objc_method * -class_get_class_method (MetaClass class, SEL op) -{ - return search_for_method_in_hierarchy (class, op); -} - -struct objc_method * class_getInstanceMethod (Class class_, SEL selector) { struct objc_method *m; @@ -926,6 +829,9 @@ search_for_method_in_list (struct objc_method_list * list, SEL op) return NULL; } +typedef void * retval_t; +typedef void * arglist_t; + static retval_t __objc_forward (id object, SEL sel, arglist_t args); /* Forwarding pointers/integers through the normal registers. */ @@ -979,9 +885,12 @@ __objc_block_forward (id rcv, SEL op, ...) } -/* This function is installed in the dispatch table for all methods - which are not implemented. Thus, it is called when a selector is - not recognized. */ +/* This function is called for methods which are not implemented, + unless a custom forwarding routine has been installed. Please note + that most serious users of libobjc (eg, GNUstep base) do install + their own forwarding routines, and hence this is never actually + used. But, if no custom forwarding routine is installed, this is + called when a selector is not recognized. */ static retval_t __objc_forward (id object, SEL sel, arglist_t args) { @@ -995,7 +904,7 @@ __objc_forward (id object, SEL sel, arglist_t args) if (__objc_responds_to (object, frwd_sel)) { - imp = get_imp (object->class_pointer, frwd_sel); + imp = get_implementation (object, object->class_pointer, frwd_sel); return (*imp) (object, frwd_sel, sel, args); } @@ -1004,7 +913,7 @@ __objc_forward (id object, SEL sel, arglist_t args) err_sel = sel_get_any_uid ("doesNotRecognize:"); if (__objc_responds_to (object, err_sel)) { - imp = get_imp (object->class_pointer, err_sel); + imp = get_implementation (object, object->class_pointer, err_sel); return (*imp) (object, err_sel, sel); } @@ -1020,16 +929,8 @@ __objc_forward (id object, SEL sel, arglist_t args) : "instance" ), object->class_pointer->name, sel_getName (sel)); - /* TODO: support for error: is surely deprecated ? */ - err_sel = sel_get_any_uid ("error:"); - if (__objc_responds_to (object, err_sel)) - { - imp = get_imp (object->class_pointer, err_sel); - return (*imp) (object, sel_get_any_uid ("error:"), msg); - } - - /* The object doesn't respond to doesNotRecognize: or error:; - Therefore, a default action is taken. */ + /* The object doesn't respond to doesNotRecognize:. Therefore, a + default action is taken. */ _objc_abort ("%s\n", msg); return 0; @@ -1066,11 +967,205 @@ __objc_print_dtable_stats (void) objc_mutex_unlock (__objc_runtime_mutex); } -/* Returns the uninstalled dispatch table indicator. If a class' - dispatch table points to __objc_uninstalled_dtable then that means - it needs its dispatch table to be installed. */ -struct sarray * -objc_get_uninstalled_dtable (void) +static cache_ptr prepared_dtable_table = 0; + +/* This function is called by: objc_msg_lookup, get_imp and + __objc_responds_to (and the dispatch table installation functions + themselves) to install a dispatch table for a class. + + If CLS is a class, it installs instance methods. + If CLS is a meta class, it installs class methods. + + In either case +initialize is invoked for the corresponding class. + + The implementation must insure that the dispatch table is not + installed until +initialize completes. Otherwise it opens a + potential race since the installation of the dispatch table is used + as gate in regular method dispatch and we need to guarantee that + +initialize is the first method invoked an that no other thread my + dispatch messages to the class before +initialize completes. */ +static void +__objc_install_dtable_for_class (Class cls) +{ + /* If the class has not yet had its class links resolved, we must + re-compute all class links. */ + if (! CLS_ISRESOLV (cls)) + __objc_resolve_class_links (); + + /* Make sure the super class has its dispatch table installed or is + at least preparing. We do not need to send initialize for the + super class since __objc_send_initialize will insure that. */ + if (cls->super_class + && cls->super_class->dtable == __objc_uninstalled_dtable + && !__objc_prepared_dtable_for_class (cls->super_class)) + { + __objc_install_dtable_for_class (cls->super_class); + /* The superclass initialisation may have also initialised the + current class, in which case there is no more to do. */ + if (cls->dtable != __objc_uninstalled_dtable) + return; + } + + /* We have already been prepared but +initialize hasn't completed. + The +initialize implementation is probably sending 'self' + messages. We rely on _objc_get_prepared_imp to retrieve the + implementation pointers. */ + if (__objc_prepared_dtable_for_class (cls)) + return; + + /* We have this function cache the implementation pointers for + _objc_get_prepared_imp but the dispatch table won't be initilized + until __objc_send_initialize completes. */ + __objc_prepare_dtable_for_class (cls); + + /* We may have already invoked +initialize but + __objc_update_dispatch_table_for_class invoked by + class_add_method_list may have reset dispatch table. */ + + /* Call +initialize. If we are a real class, we are installing + instance methods. If we are a meta class, we are installing + class methods. The __objc_send_initialize itself will insure + that the message is called only once per class. */ + if (CLS_ISCLASS (cls)) + __objc_send_initialize (cls); + else + { + /* Retrieve the class from the meta class. */ + Class c = objc_getClass (cls->name); + assert (CLS_ISMETA (cls)); + assert (c); + __objc_send_initialize (c); + } + + /* We install the dispatch table correctly when +initialize completed. */ + __objc_install_prepared_dtable_for_class (cls); +} + +/* Builds the dispatch table for the class CLS and stores it in a + place where it can be retrieved by __objc_get_prepared_imp until + __objc_install_prepared_dtable_for_class installs it into the + class. The dispatch table should not be installed into the class + until +initialize has completed. */ +static void +__objc_prepare_dtable_for_class (Class cls) +{ + struct sarray *dtable; + struct sarray *super_dtable; + + /* This table could be initialized in init.c. We can not use the + class name since the class maintains the instance methods and the + meta class maintains the the class methods yet both share the + same name. Classes should be unique in any program. */ + if (! prepared_dtable_table) + prepared_dtable_table + = objc_hash_new (32, + (hash_func_type) objc_hash_ptr, + (compare_func_type) objc_compare_ptrs); + + /* If the class has not yet had its class links resolved, we must + re-compute all class links. */ + if (! CLS_ISRESOLV (cls)) + __objc_resolve_class_links (); + + assert (cls); + assert (cls->dtable == __objc_uninstalled_dtable); + + /* If there is already a prepared dtable for this class, we must + replace it with a new version (since there must have been methods + added to or otherwise modified in the class while executing + +initialize, and the table needs to be recomputed. */ + dtable = __objc_prepared_dtable_for_class (cls); + if (dtable != 0) + { + objc_hash_remove (prepared_dtable_table, cls); + sarray_free (dtable); + } + + /* Now prepare the dtable for population. */ + assert (cls != cls->super_class); + if (cls->super_class) + { + /* Inherit the method list from the super class. Yet the super + class may still be initializing in the case when a class + cluster sub class initializes its super classes. */ + if (cls->super_class->dtable == __objc_uninstalled_dtable) + __objc_install_dtable_for_class (cls->super_class); + + super_dtable = cls->super_class->dtable; + /* If the dispatch table is not yet installed, we are still in + the process of executing +initialize. Yet the dispatch table + should be available. */ + if (super_dtable == __objc_uninstalled_dtable) + super_dtable = __objc_prepared_dtable_for_class (cls->super_class); + + assert (super_dtable); + dtable = sarray_lazy_copy (super_dtable); + } + else + dtable = sarray_new (__objc_selector_max_index, 0); + + __objc_install_methods_in_dtable (dtable, cls->methods); + + objc_hash_add (&prepared_dtable_table, + cls, + dtable); +} + +/* This wrapper only exists to allow an easy replacement of the lookup + implementation and it is expected that the compiler will optimize + it away. */ +static struct sarray * +__objc_prepared_dtable_for_class (Class cls) { - return __objc_uninstalled_dtable; + struct sarray *dtable = 0; + assert (cls); + if (prepared_dtable_table) + dtable = objc_hash_value_for_key (prepared_dtable_table, cls); + /* dtable my be nil, since we call this to check whether we are + currently preparing before we start preparing. */ + return dtable; +} + +/* Helper function for messages sent to CLS or implementation pointers + retrieved from CLS during +initialize before the dtable is + installed. When a class implicitly initializes another class which + in turn implicitly invokes methods in this class, before the + implementation of +initialize of CLS completes, this returns the + expected implementation. Forwarding remains the responsibility of + objc_msg_lookup. This function should only be called under the + global lock. */ +static IMP +__objc_get_prepared_imp (Class cls,SEL sel) +{ + struct sarray *dtable; + IMP imp; + + assert (cls); + assert (sel); + assert (cls->dtable == __objc_uninstalled_dtable); + dtable = __objc_prepared_dtable_for_class (cls); + + assert (dtable); + assert (dtable != __objc_uninstalled_dtable); + imp = sarray_get_safe (dtable, (size_t) sel->sel_id); + + /* imp may be Nil if the method does not exist and we may fallback + to the forwarding implementation later. */ + return imp; +} + +/* When this function is called +initialize should be completed. So + now we are safe to install the dispatch table for the class so that + they become available for other threads that may be waiting in the + lock. */ +static void +__objc_install_prepared_dtable_for_class (Class cls) +{ + assert (cls); + assert (cls->dtable == __objc_uninstalled_dtable); + cls->dtable = __objc_prepared_dtable_for_class (cls); + + assert (cls->dtable); + assert (cls->dtable != __objc_uninstalled_dtable); + objc_hash_remove (prepared_dtable_table, cls); } diff --git a/libobjc/thr.c b/libobjc/thr.c index 3f7e5c525f..095b9403a4 100644 --- a/libobjc/thr.c +++ b/libobjc/thr.c @@ -40,6 +40,7 @@ see the files COPYING3 and COPYING.RUNTIME respectively. If not, see #include "objc/thr.h" #include "objc/message.h" /* For objc_msg_lookup(). */ #include "objc/runtime.h" +#include "objc-private/module-abi-8.h" #include "objc-private/runtime.h" #include <gthr.h> |