diff options
26 files changed, 1579 insertions, 2503 deletions
diff --git a/gnu/lib/libobjc/libobjc/ChangeLog b/gnu/lib/libobjc/libobjc/ChangeLog index dcd68585f9e..e8819321c6b 100644 --- a/gnu/lib/libobjc/libobjc/ChangeLog +++ b/gnu/lib/libobjc/libobjc/ChangeLog @@ -1,472 +1,34 @@ -2004-09-30 Release Manager - - * GCC 3.3.5 Released. - -2004-05-31 Release Manager - - * GCC 3.3.4 Released. - -2004-03-02 Gabriel Dos Reis <gdr@integrable-solutions.net> - - PR bootstrap/14348 - Backport - 2003-10-20 Joseph S. Myers <jsm@polyomino.org.uk> - * objc/hash.h (hash_string): Don't use a cast as an lvalue. - -2004-02-14 Release Manager - - * GCC 3.3.3 Released. - -2003-12-01 Zack Weinberg <zack@codesourcery.com> - - PR 11433 - * Protocol.m (descriptionForInstanceMethod): Don't dereference - instance_methods if it's NULL. - (descriptionForClassMethod): Likewise for class_methods. - -2003-10-16 Release Manager - - * GCC 3.3.2 Released. - -2003-09-09 Alan Modra <amodra@bigpond.net.au> - - * configure: Regenerate. - -2003-08-04 Release Manager - - * GCC 3.3.1 Released. - -2003-08-04 Release Manager - - * GCC 3.3.1 Released. - -2003-05-13 Release Manager - - * GCC 3.3 Released. - -2003-05-13 Release Manager - - * GCC 3.3 Released. - -2003-05-13 Release Manager - - * GCC 3.3 Released. - -2003-02-20 Alexandre Oliva <aoliva@redhat.com> - - * configure.in: Propagate ORIGINAL_LD_FOR_MULTILIBS to - config.status. - * configure: Rebuilt. - -2003-01-27 Alexandre Oliva <aoliva@redhat.com> - - * aclocal.m4 (glibcpp_toolexeclibdir): Instead of - $(MULTISUBDIR), use `$CC -print-multi-os-directory`, unless - version_specific_libs is enabled. - * configure: Rebuilt. - -2003-01-26 Christian Cornelssen <ccorn@cs.tu-berlin.de> - - * Makefile.in (FLAGS_TO_PASS): Also pass DESTDIR. - (install-libs, install-headers): Prepend $(DESTDIR) to - destination paths in all (un)installation commands. - -2002-09-22 Kaveh R. Ghazi <ghazi@caip.rutgers.edu> - - * Makefile.in (all): Fix multilib parallel build. - -Thu Sep 12 12:44:37 2002 Nicola Pero <n.pero@mi.flashnet.it> - - * sendmsg.c (nil_method): Declare not to take a variable number of - args. - (objc_msg_lookup): Cast nil_method to IMP before returning it. - (objc_msg_lookup_super): The same. - -2002-09-10 Jan Hubicka <jh@suse.cz> - - * nil_method.c (nil_method): No longer defined with variable - arguments. - -2002-07-02 Rodney Brown <rbrown64@csc.com.au> - - * objc/encoding.h: Fix formatting. - * objc/hash.h: Likewise. - * objc/objc-api.h: Likewise. - * objc/runtime.h: Likewise. - * objc/thr.h: Likewise. - * archive.c: Likewise. - * class.c: Likewise. - * encoding.c: Likewise. - * gc.c: Likewise. - * hash.c: Likewise. - * init.c: Likewise. - * misc.c: Likewise. - * nil_method.c: Likewise. - * objects.c: Likewise. - * sarray.c: Likewise. - * selector.c: Likewise. - * sendmsg.c: Likewise. - * thr-mach.c: Likewise. - * thr.c: Likewise. - -2002-06-25 DJ Delorie <dj@redhat.com> - - * aclocal.m4 (GLIBCPP_CONFIGURE): Split out - GLIBCPP_TOPREL_CONFIGURE. - * configure.in: Call it before AC_CANONICAL_SYSTEM. - * configure: Regenerate. - -2002-06-21 Kaveh R. Ghazi <ghazi@caip.rutgers.edu> - - * Object.m (forward, read, write): Fix unused parameter warnings. - * encoding.c: Include <stdlib.h>. - (target_flags): Mark with attribute unused. - (atoi): Delete. - * runtime.h (__objc_selector_max_index): Change to unsigned int. - (__objc_generate_gc_type_description): Prototype. - * selector.c (__objc_selector_max_index): Change to unsigned int. - -Mon Jun 17 18:37:42 2002 Nicola Pero <n.pero@mi.flashnet.it> - - * sendmsg.c (__objc_get_forward_imp): Fix warning by making sure - we always have a return value: if __objc_msg_forward does not - supply a forwarding implementation, return the default - __builtin_apply based one. - -2002-06-15 Kaveh R. Ghazi <ghazi@caip.rutgers.edu> - - * Object.m: Fix signed/unsigned warning. - * Protocol.m: Likewise. - * archive.c: Always include stdlib.h. - (objc_read_short, objc_read_unsigned_short, objc_read_int, - objc_read_long, __objc_read_nbyte_uint, __objc_read_nbyte_ulong): - Fix signed/unsigned warning. - (objc_write_type, objc_read_type, objc_write_types, - objc_read_types): Ensure ctype 8-bit safety. - (__objc_no_write, __objc_no_read): Mark unused parameters. - * class.c (class_table_setup): Specify void arg. - * encoding.c (atoi, objc_sizeof_type, objc_alignof_type, - objc_skip_typespec, objc_skip_offset, - objc_layout_structure_next_member): Ensure ctype 8-bit safety. - (objc_layout_structure_next_member): Ensure variables are - initialized. - * gc.c (__objc_generate_gc_type_description, - class_ivar_set_gcinvisible): Mark unused parameters. - * init.c (__objc_send_load, __objc_destroy_class_tree_node): Mark - unused parameters. - (__objc_init_protocols) Fix signed/unsigned warning. - * nil_method.c (nil_method): Mark unused parameters. - * thr.h (objc_thread_callback): Specify void arg. - * sarray.c (sarray_new, sarray_realloc, sarray_free): Fix - signed/unsigned warning. - (sarray_free): Fix formatting. - * selector.c (sel_types_match): Ensure ctype 8-bit safety. - * sendmsg.c (__objc_init_install_dtable) Mark unused parameters. - -2002-06-09 Andreas Jaeger <aj@suse.de> - - * encoding.c (objc_layout_structure_next_member): Remove unused - variable. - -2002-05-20 Kaveh R. Ghazi <ghazi@caip.rutgers.edu> - - * Makefile.in (SHELL): Set to @SHELL@. - (WARN_CFLAGS): New. - (ALL_CFLAGS): Add $(WARN_CFLAGS). - -2002-05-16 Rainer Orth <ro@TechFak.Uni-Bielefeld.DE> - - * aclocal.m4: Allow for PWDCMD to override hardcoded pwd. - * configure: Regenerate. - -2002-05-08 Alexandre Oliva <aoliva@redhat.com> - - * configure.in (ORIGINAL_LD_FOR_MULTILIBS): Preserve LD at - script entry, and set LD to it when configuring multilibs. - * configure: Rebuilt. - -2002-04-19 David O'Brien <obrien@FreeBSD.org> - - * encoding.c (MAX, MIN, ROUNDING): #undef before defining. - -2002-04-09 Hans-Peter Nilsson <hp@bitrange.com> - - PR objc/6107 - * objc/objc-api.h (struct objc_protocol_list): Change type of - member count from int to size_t. - -2002-02-11 Franz Sirl <Franz.Sirl-kernel@lauterbach.com> - - PR libobjc/4039 - * aclocal.m4: Replace with version copied from libstdc++-v3. - * configure.in: Update for changes to aclocal and Makefile. - * configure: Regenerate. - * Makefile.in: Correct install of multilibs and shared libs, use - INSTALL_DATA for include files. - -Mon Dec 17 17:02:12 2001 Nicola Pero <nicola@brainstorm.co.uk> - - * init.c (__objc_exec_class): Fixed bug in the loop on unclaimed - categories - when an unclaimed category was found, the loop was - doing two steps forward instead of one, so that in certain cases - it was failing to properly load all the categories. (Reported - with fix by Alexander Malmberg <alexander@malmberg.org>). - -2001-11-14 Aldy Hernandez <aldyh@redhat.com> - - * encoding.c: Add target_flags. - -2001-11-07 Aldy Hernandez <aldyh@redhat.com> - - * objc/objc-api.h (_C_VECTOR): New. - - * encoding.c (VECTOR_TYPE): New. - -Mon Oct 29 21:29:21 2001 Nicola Pero <n.pero@mi.flashnet.it> - - * class.c: Rewritten the class table to use optimized, lock-free - lookup. This more than doubles the speed of class method - invocations. (class_table_setup), (class_table_insert), - (class_table_replace), (class_table_get_safe), - (class_table_next), (class_table_print), - (class_table_print_histogram): New functions. - (__objc_init_class_tables): Use class_table_setup. - (__objc_add_class_to_hash): Use class_table_get_safe and - class_table_insert. (objc_lookup_class), (objc_get_class): Do not - assert the existence of the table; do not lock the runtime; use - class_table_get_safe. (objc_next_class): Use class_table_next. - (__objc_resolve_class_links): Use class_table_next. - (class_pose_as): Use class_table_replace. - -2001-09-10 Ovidiu Predescu <ovidiu@cup.hp.com> - - * gc.c: Removed the DEBUG declaration. - -Wed Jul 18 12:48:56 2001 Nicola Pero <n.pero@mi.flashnet.it> - - * thr.c (objc_mutex_lock): Invoke __objc_thread_id directly, - rather than through objc_thread_id, to save a function call. - (objc_mutex_trylock, objc_mutex_unlock, objc_condition_wait): - Ditto. - -Mon Jul 16 12:15:00 2001 Nicola Pero <n.pero@mi.flashnet.it> - - * objc/objc-api.h (object_is_class): Fixed - buggy code was trying - to cast an id to a Class, which can not be done. Make the check - by using CLS_ISMETA on the class pointer instead. - (object_is_meta_class): Similar fix. - -2001-06-09 Alexandre Oliva <aoliva@redhat.com>, Stephen L Moshier <moshier@mediaone.net> - - * configure.in (AC_EXEEXT): Work around in case it expands to - nothing, as in autoconf 2.50. - * acinclude.m4: Likewise. - * configure: Rebuilt. - -2001-06-08 Nicola Pero <n.pero@mi.flashnet.it> - - * THREADS: Explain that when we compile libobjc inside GCC, we - always use thr-objc.c as a backend, which uses GCC's thread code. - -2001-06-06 Richard Frith-Macdonald <rrfm@gnu.org> - - * init.c (__objc_send_message_in_list): When setting a new entry - in __objc_load_methods use the method IMP as key, but check to see - if the method is in the hashtable by looking at the IMP also. - Also ... call the method after adding it to the hashtable rather - than before ... thus preventing an obscure possibility of infinite - recursion if a +load method itself loads a subclass. - -2001-05-25 Ovidiu Predescu <ovidiu@cup.hp.com> - - * init.c (__objc_send_message_in_list): When setting a new entry - in __objc_load_methods use the method name as key, not the method - IMP (reported by Richard Frith-Macdonald <richard@brainstorm.co.uk>). - -2001-05-09 Joseph S. Myers <jsm28@cam.ac.uk> - - * objc-features.texi: Move to ../gcc/objc.texi. - * fdl.texi: Remove. - * Makefile.in: Don't generate documentation from - objc-features.texi. - -2001-05-01 Mark Mitchell <mark@codesourcery.com> - - * fdl.texi: New file. - * objc-features.texi: Simplify. - * Makefile.in: Adjust accordingly. - -2001-04-30 Mark Mitchell <mark@codesourcery.com> - - * objc-features.texi: Use the GFDL. - -Wed Mar 21 04:44:58 EST 2001 John Wehle (john@feith.com) - - * encoding.c (REAL_TYPE): Define. - -2001-03-19 David Edelsohn <edelsohn@gnu.org> - - * encoding.c (TYPE_MODE): Define. - -2001-03-14 Nicola Pero <n.pero@mi.flashnet.it> - - * thr.c (objc_thread_add): New function. - (objc_thread_remove): Ditto. - * objc/thr.h: Declare them. - * libobjc.def: Mention them. - -2001-02-28 Ovidiu Predescu <ovidiu@cup.hp.com> - - * objc-features.texi: Document the @compatibility_alias compiler - directive (description from Nicola Pero <n.pero@mi.flashnet.it>). - -Fri Feb 23 18:12:00 2001 Rainer Orth <ro@TechFak.Uni-Bielefeld.DE> - - * sendmsg.c (__objc_forward): Delete strlen() declaration. - -2001-02-08 Geoffrey Keating <geoffk@redhat.com> - - * configure.in: Don't run AC_PROG_CC_WORKS or AC_EXEEXT, because - we're not interested in the result and they might fail. - * configure: Regenerated. - -2001-01-12 Joseph S. Myers <jsm28@cam.ac.uk> - - * objc-features.texi: Use @email. - -2001-01-12 Joseph S. Myers <jsm28@cam.ac.uk> +2001-01-11 Joseph S. Myers <jsm28@cam.ac.uk> * sendmsg.c (__objc_print_dtable_stats): Don't use #ifdef inside printf. -2000-01-11 Richard Earnshaw <rearnsha@arm.com> - - * encoding.c (STRUCTURE_SIZE_BOUNDARY): Redefine in a way that - determines the value dynamically. - -Wed Jan 3 00:49:10 2001 Ovidiu Predescu <ovidiu@cup.hp.com> - - * sendmsg.c: Added __objc_msg_forward, a hook that allows external - libraries to provide a function that returns the real forwarding - function. This can alleviate problems __builtin_apply() and - friends have on various platforms. (Solution suggested by Helge - Hess.) - - * objc/objc-api.h: Define __objc_msg_forward. - - * sendmsg.c: Define gen_rtx_REG. - -2000-12-06 Ralf Corsepius <corsepiu@faw.uni-ulm.de> - - * thr-rtems.c: New file. Stub to compile. - -2000-09-06 Alexandre Oliva <aoliva@redhat.com> - - * configure: Rebuilt with new libtool.m4. - -Tue Aug 15 00:38:56 2000 Ovidiu Predescu <ovidiu@cup.hp.com> - - * configure.in: Create a config.h file. Check for <sched.h>. - * configure: Regenerate. - - * config.h.in: Check for <sched.h>. - -2000-08-14 Zack Weinberg <zack@wolery.cumb.org> - - * configure: Regenerate after change to ../libtool.m4. - -2000-08-14 Andreas Schwab <schwab@suse.de> - - * objc-features.texi (Top): Move @menu at end of node. - -2000-08-11 Manfred Hollstein <manfredh@redhat.com> - - * objc-features.texi: Move @node Top before @menu. - -Sun Aug 6 23:27:49 2000 Ovidiu Predescu <ovidiu@cup.hp.com> - - * objc-features.texi: Documented the new -fconstant-string-class - option. - -Sun Aug 6 22:51:16 2000 Ovidiu Predescu <ovidiu@cup.hp.com> - - * thr-posix.c: Integrated Chris Ball's <cball@fmco.com> changes to - improve the Posix thread support for Objective-C. - -2000-08-04 Zack Weinberg <zack@wolery.cumb.org> - - * aclocal.m4: Replace copy of ../libtool.m4 with - sinclude(../libtool.m4). - -Fri Jul 28 08:58:02 2000 Nicola Pero <nicola@brainstorm.co.uk> - - * configure.in: Added libtool support; build shared libraries - if --enable-shared was passed on command line. - * Makefile.in: Modified most compilation commands to use libtool. - * aclocal.m4: New symbolic link to the ../libtool.m4, from the - libtool distribution. - -Sat Jul 29 00:10:21 2000 Ovidiu Predescu <ovidiu@cup.hp.com> - - * sarray.c, Object.m: Removed the explicit prototypes for strlen - and memcpy on 64-bit platforms (Suggested by Rodney Brown - <rdb@cup.hp.com>). - -2000-05-12 H.J. Lu (hjl@gnu.org) - - * Makefile.in (GTHREAD_FLAGS): New. - (ALL_CFLAGS): Add $(GTHREAD_FLAGS). - (OBJC_THREAD_FILE): Changed to thr-objc. - - * configure.in (GTHREAD_FLAGS): New, check and replace it for - Makefile. - (OBJC_THREAD_FILE): Removed. - - * thr-objc.c: New. - -2000-07-13 Kaveh R. Ghazi <ghazi@caip.rutgers.edu> - - * objc/hash.h: Include string.h. - -2000-04-15 David Edelsohn <edelsohn@gnu.org> - - * Object.m (strlen): 64-bit PowerPC is a 64bit platform as well. - -2000-04-12 Jakub Jelinek <jakub@redhat.com> - - * Object.m (strlen): Provide prototype on all 64bit platforms, - not only alpha. - * sarray.c (memcpy): Likewise. - * encoding.c (objc_layout_finish_structure): Don't use - ROUND_TYPE_ALIGN on sparc. - - * encoding.c (objc_layout_structure_next_member): Do the whole - procedure even for the first member, so that we get correct - alignment. - 2000-03-29 Zack Weinberg <zack@wolery.cumb.org> * objc/Protocol.h, objc/objc-list.h: Change #endif labels to comments. -2000-02-23 Zack Weinberg <zack@wolery.cumb.org> - - * Makefile.in: Add -DIN_TARGET_LIBS to ALL_CFLAGS. +Sun Oct 24 23:54:10 PDT 1999 Jeff Law (law@cygnus.com) -Thu Sep 23 07:19:12 1999 Chris Ball <cball@fmco.com> + * gcc-2.95.2 Released. - * thr-posix.c (__objc_mutex_deallocate): made deallocate work. +Mon Aug 16 01:29:24 PDT 1999 Jeff Law (law@cygnus.com) -Tue Sep 21 07:47:10 1999 Jeffrey A Law (law@cygnus.com) - - * Makefile.in (gc.o, gc_gc.o): Do not pass -fgnu-runtime to - the compiler when building C code. + * gcc-2.95.1 Released. Fri Aug 6 23:32:29 1999 Daniel Jacobowitz <drow@drow.them.org> * Makefile.in (FLAGS_TO_PASS): Include prefix, exec_prefix, libdir, libsubdir and tooldir. +Wed Jul 28 21:39:31 PDT 1999 Jeff Law (law@cygnus.com) + + * gcc-2.95 Released. + +Sun Jul 25 23:40:51 PDT 1999 Jeff Law (law@cygnus.com) + + * gcc-2.95 Released. + Mon Jun 21 05:40:15 1999 John David Anglin <dave@hiauly1> * init.c (__objc_force_linking): Make global. @@ -540,7 +102,7 @@ Sat Oct 17 05:21:31 1998 Ovidiu Predescu <ovidiu@slip.net> Mon Oct 11 21:25:27 1998 Ovidiu Predescu <ovidiu@slip.net> * encoding.c: Redefine get_inner_array_type to get the first entry - in the structure. + in the structure. Thu Oct 8 12:21:14 1998 Richard Frith-Macdonald <richard@brainstorm.co.uk> @@ -605,3 +167,4 @@ Mon Sep 21 23:27:10 1998 Ovidiu Predescu <ovidiu@slip.net> 1998-09-21 Ben Elliston <bje@cygnus.com> * New directory. Moved files from ../gcc/objc. + diff --git a/gnu/lib/libobjc/libobjc/Object.m b/gnu/lib/libobjc/libobjc/Object.m index 1882754d605..64b52f48368 100644 --- a/gnu/lib/libobjc/libobjc/Object.m +++ b/gnu/lib/libobjc/libobjc/Object.m @@ -1,5 +1,5 @@ /* The implementation of class Object for Objective-C. - Copyright (C) 1993, 1994, 1995, 1997, 2002 Free Software Foundation, Inc. + Copyright (C) 1993, 1994, 1995, 1997 Free Software Foundation, Inc. This file is part of GNU CC. @@ -199,7 +199,7 @@ extern int errno; + (BOOL) conformsTo: (Protocol*)aProtocol { - size_t i; + int i; struct objc_protocol_list* proto_list; id parent; @@ -271,7 +271,6 @@ extern int errno; - (retval_t)forward:(SEL)aSel :(arglist_t)argFrame { - (void) argFrame; /* UNUSED */ return (retval_t)[self doesNotRecognize: aSel]; } @@ -321,6 +320,10 @@ extern int errno; object_get_class_name(self), sel_get_name(aSel)]; } +#ifdef __alpha__ +extern size_t strlen(const char*); +#endif + - error:(const char *)aString, ... { #define FMT "error: %s (%s)\n%s\n" @@ -365,14 +368,12 @@ extern int errno; - read: (TypedStream*)aStream { - (void) aStream; /* UNUSED */ // [super read: aStream]; return self; } - write: (TypedStream*)aStream { - (void) aStream; /* UNUSED */ // [super write: aStream]; return self; } diff --git a/gnu/lib/libobjc/libobjc/Protocol.m b/gnu/lib/libobjc/libobjc/Protocol.m index ab41bfe2ce7..43ba44eaf4f 100644 --- a/gnu/lib/libobjc/libobjc/Protocol.m +++ b/gnu/lib/libobjc/libobjc/Protocol.m @@ -53,7 +53,7 @@ struct objc_method_description_list { - (BOOL) conformsTo: (Protocol *)aProtocolObject { - size_t i; + int i; struct objc_protocol_list* proto_list; if (!strcmp(aProtocolObject->protocol_name, self->protocol_name)) @@ -80,19 +80,17 @@ struct objc_method_description_list { const char* name = sel_get_name (aSel); struct objc_method_description *result; - if (instance_methods) - for (i = 0; i < instance_methods->count; i++) - { - if (!strcmp ((char*)instance_methods->list[i].name, name)) - return &(instance_methods->list[i]); - } + for (i = 0; i < instance_methods->count; i++) + { + if (!strcmp ((char*)instance_methods->list[i].name, name)) + 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++) + for (i=0; i < proto_list->count; i++) { - if ((result = [proto_list->list[j] + if ((result = [proto_list->list[i] descriptionForInstanceMethod: aSel])) return result; } @@ -108,19 +106,17 @@ struct objc_method_description_list { const char* name = sel_get_name (aSel); struct objc_method_description *result; - if (class_methods) - for (i = 0; i < class_methods->count; i++) - { - if (!strcmp ((char*)class_methods->list[i].name, name)) - return &(class_methods->list[i]); - } + for (i = 0; i < class_methods->count; i++) + { + if (!strcmp ((char*)class_methods->list[i].name, name)) + 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++) + for (i=0; i < proto_list->count; i++) { - if ((result = [proto_list->list[j] + if ((result = [proto_list->list[i] descriptionForClassMethod: aSel])) return result; } diff --git a/gnu/lib/libobjc/libobjc/THREADS b/gnu/lib/libobjc/libobjc/THREADS index 8a436832f6c..9dfbbed97af 100644 --- a/gnu/lib/libobjc/libobjc/THREADS +++ b/gnu/lib/libobjc/libobjc/THREADS @@ -102,33 +102,30 @@ high degree of portability across platforms. The backend is composed of a file with the necessary code to map the ObjC thread and mutex to a platform specific implementation. For example, the -file thr-solaris.c contains the implementation for Solaris. - -If you are compiling libobjc as part of GCC, the thr-objc.c backend is -always used; this backend uses GCC's gthread code. The thread system -is automatically configured when GCC is configured. Important: make -sure you configure GCC using `--enable-threads' if you want threads ! - -If you want to compile libobjc standalone, then you would need to -modify the configure.in and makefiles for it; and you need to pick an -appropriate backend file for the target platform; you make this choice -by assigning the OBJC_THREAD_FILE make variable to the basename of the -backend file. For example, OBJC_THREAD_FILE=thr-posix would indicate -that the generic posix backend file, thr-posix.c, should be compiled -with the ObjC runtime library. If your platform does not support -threads then you should specify the OBJC_THREAD_FILE=thr-single -backend file to compile the ObjC runtime library without thread or -mutex support; note that programs which rely upon the ObjC thread and -mutex functions will compile and link correctly but attempting to -create a thread or mutex will result in an error. - +file thr-solaris.c contains the implementation for Solaris. When you +configure GCC, it attempts to pick an appropriate backend file for the +target platform; however, you can override this choice by assign the +OBJC_THREAD_FILE make variable to the basename of the backend file. This +is especially useful on platforms which have multiple thread libraries. +For example: + + make OBJC_THREAD_FILE=thr-posix + +would indicate that the generic posix backend file, thr-posix.c, should be +compiled with the ObjC runtime library. If your platform does not support +threads then you should specify the OBJC_THREAD_FILE=thr-single backend file +to compile the ObjC runtime library without thread or mutex support; note +that programs which rely upon the ObjC thread and mutex functions will +compile and link correctly but attempting to create a thread or mutex will +result in an error. + It is questionable whether it is really necessary to have both a frontend and backend function for all available functionality. On the one hand, it provides a clear, consistent differentiation between what is public and what is private with the downside of having the overhead -of multiple functions calls. For example, the function to have a -thread yield the processor is objc_thread_yield; in the current -implementation this produces a function call set: +of multiple functions calls. For example, the function to have a thread +yield the processor is objc_thread_yield; in the current implementation +this produces a function call set: objc_thread_yield() -> __objc_thread_yield() -> system yield function diff --git a/gnu/lib/libobjc/libobjc/archive.c b/gnu/lib/libobjc/libobjc/archive.c index f98379bc99d..10106c1145e 100644 --- a/gnu/lib/libobjc/libobjc/archive.c +++ b/gnu/lib/libobjc/libobjc/archive.c @@ -1,5 +1,5 @@ - /* GNU Objective C Runtime archiving - Copyright (C) 1993, 1995, 1996, 1997, 2002 Free Software Foundation, Inc. +/* GNU Objective C Runtime archiving + Copyright (C) 1993, 1995, 1996, 1997 Free Software Foundation, Inc. Contributed by Kresten Krab Thorup This file is part of GNU CC. @@ -28,42 +28,45 @@ Boston, MA 02111-1307, USA. */ #include "runtime.h" #include "typedstream.h" #include "encoding.h" + +#ifdef HAVE_STDLIB_H #include <stdlib.h> +#endif -extern int fflush (FILE *); +extern int fflush(FILE*); #define ROUND(V, A) \ - ({ typeof (V) __v = (V); typeof (A) __a = (A); \ - __a * ((__v + __a - 1)/__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)) +#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); +objc_read_class (struct objc_typed_stream* stream, Class* class); -int objc_sizeof_type (const char *type); +int objc_sizeof_type(const char* type); static int -objc_write_use_common (struct objc_typed_stream *stream, unsigned long key); +objc_write_use_common (struct objc_typed_stream* stream, unsigned long key); static int -objc_write_register_common (struct objc_typed_stream *stream, +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); +objc_write_class (struct objc_typed_stream* stream, + struct objc_class* class); -const char *objc_skip_type (const char *type); +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 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) +__objc_code_unsigned_char (unsigned char* buf, unsigned char val) { if ((val&_B_VALUE) == val) { @@ -79,16 +82,16 @@ __objc_code_unsigned_char (unsigned char *buf, unsigned char val) } int -objc_write_unsigned_char (struct objc_typed_stream *stream, +objc_write_unsigned_char (struct objc_typed_stream* stream, unsigned char value) { - unsigned char buf[sizeof (unsigned char) + 1]; + unsigned char buf[sizeof (unsigned char)+1]; int len = __objc_code_unsigned_char (buf, value); - return (*stream->write) (stream->physical, buf, len); + return (*stream->write)(stream->physical, buf, len); } static __inline__ int -__objc_code_char (unsigned char *buf, signed char val) +__objc_code_char (unsigned char* buf, signed char val) { if (val >= 0) return __objc_code_unsigned_char (buf, val); @@ -101,15 +104,15 @@ __objc_code_char (unsigned char *buf, signed char val) } int -objc_write_char (struct objc_typed_stream *stream, signed char value) +objc_write_char (struct objc_typed_stream* stream, signed char value) { - unsigned char buf[sizeof (char) + 1]; + unsigned char buf[sizeof (char)+1]; int len = __objc_code_char (buf, value); - return (*stream->write) (stream->physical, buf, len); + return (*stream->write)(stream->physical, buf, len); } static __inline__ int -__objc_code_unsigned_short (unsigned char *buf, unsigned short val) +__objc_code_unsigned_short (unsigned char* buf, unsigned short val) { if ((val&_B_VALUE) == val) { @@ -122,15 +125,15 @@ __objc_code_unsigned_short (unsigned char *buf, unsigned short val) buf[0] = _B_NINT; - for (c = sizeof (short); c != 0; c -= 1) - if (((val >> (8*(c - 1)))%0x100) != 0) + 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; + buf[b] = (val >> (8*(c-1)))%0x100; } return b; @@ -138,16 +141,16 @@ __objc_code_unsigned_short (unsigned char *buf, unsigned short val) } int -objc_write_unsigned_short (struct objc_typed_stream *stream, +objc_write_unsigned_short (struct objc_typed_stream* stream, unsigned short value) { - unsigned char buf[sizeof (unsigned short) + 1]; + unsigned char buf[sizeof (unsigned short)+1]; int len = __objc_code_unsigned_short (buf, value); - return (*stream->write) (stream->physical, buf, len); + return (*stream->write)(stream->physical, buf, len); } static __inline__ int -__objc_code_short (unsigned char *buf, short val) +__objc_code_short (unsigned char* buf, short val) { int sign = (val < 0); int size = __objc_code_unsigned_short (buf, sign ? -val : val); @@ -157,16 +160,16 @@ __objc_code_short (unsigned char *buf, short val) } int -objc_write_short (struct objc_typed_stream *stream, short value) +objc_write_short (struct objc_typed_stream* stream, short value) { - unsigned char buf[sizeof (short) + 1]; + unsigned char buf[sizeof (short)+1]; int len = __objc_code_short (buf, value); - return (*stream->write) (stream->physical, buf, len); + return (*stream->write)(stream->physical, buf, len); } static __inline__ int -__objc_code_unsigned_int (unsigned char *buf, unsigned int val) +__objc_code_unsigned_int (unsigned char* buf, unsigned int val) { if ((val&_B_VALUE) == val) { @@ -179,8 +182,8 @@ __objc_code_unsigned_int (unsigned char *buf, unsigned int val) buf[0] = _B_NINT; - for (c = sizeof (int); c != 0; c -= 1) - if (((val >> (8*(c - 1)))%0x100) != 0) + for (c= sizeof(int); c != 0; c -= 1) + if (((val>>(8*(c-1)))%0x100) != 0) break; buf[0] |= c; @@ -195,15 +198,15 @@ __objc_code_unsigned_int (unsigned char *buf, unsigned int val) } int -objc_write_unsigned_int (struct objc_typed_stream *stream, unsigned int value) +objc_write_unsigned_int (struct objc_typed_stream* stream, unsigned int value) { - unsigned char buf[sizeof (unsigned int) + 1]; + unsigned char buf[sizeof(unsigned int)+1]; int len = __objc_code_unsigned_int (buf, value); - return (*stream->write) (stream->physical, buf, len); + return (*stream->write)(stream->physical, buf, len); } static __inline__ int -__objc_code_int (unsigned char *buf, int val) +__objc_code_int (unsigned char* buf, int val) { int sign = (val < 0); int size = __objc_code_unsigned_int (buf, sign ? -val : val); @@ -213,15 +216,15 @@ __objc_code_int (unsigned char *buf, int val) } int -objc_write_int (struct objc_typed_stream *stream, int value) +objc_write_int (struct objc_typed_stream* stream, int value) { - unsigned char buf[sizeof (int) + 1]; + unsigned char buf[sizeof(int)+1]; int len = __objc_code_int (buf, value); - return (*stream->write) (stream->physical, buf, len); + return (*stream->write)(stream->physical, buf, len); } static __inline__ int -__objc_code_unsigned_long (unsigned char *buf, unsigned long val) +__objc_code_unsigned_long (unsigned char* buf, unsigned long val) { if ((val&_B_VALUE) == val) { @@ -234,15 +237,15 @@ __objc_code_unsigned_long (unsigned char *buf, unsigned long val) buf[0] = _B_NINT; - for (c = sizeof (long); c != 0; c -= 1) - if (((val >> (8*(c - 1)))%0x100) != 0) + 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; + buf[b] = (val >> (8*(c-1)))%0x100; } return b; @@ -250,16 +253,16 @@ __objc_code_unsigned_long (unsigned char *buf, unsigned long val) } int -objc_write_unsigned_long (struct objc_typed_stream *stream, +objc_write_unsigned_long (struct objc_typed_stream* stream, unsigned long value) { - unsigned char buf[sizeof (unsigned long) + 1]; + unsigned char buf[sizeof(unsigned long)+1]; int len = __objc_code_unsigned_long (buf, value); - return (*stream->write) (stream->physical, buf, len); + return (*stream->write)(stream->physical, buf, len); } static __inline__ int -__objc_code_long (unsigned char *buf, long val) +__objc_code_long (unsigned char* buf, long val) { int sign = (val < 0); int size = __objc_code_unsigned_long (buf, sign ? -val : val); @@ -269,19 +272,19 @@ __objc_code_long (unsigned char *buf, long val) } int -objc_write_long (struct objc_typed_stream *stream, long value) +objc_write_long (struct objc_typed_stream* stream, long value) { - unsigned char buf[sizeof (long) + 1]; + unsigned char buf[sizeof(long)+1]; int len = __objc_code_long (buf, value); - return (*stream->write) (stream->physical, buf, len); + return (*stream->write)(stream->physical, buf, len); } int -objc_write_string (struct objc_typed_stream *stream, - const unsigned char *string, unsigned int nbytes) +objc_write_string (struct objc_typed_stream* stream, + const unsigned char* string, unsigned int nbytes) { - unsigned char buf[sizeof (unsigned int) + 1]; + unsigned char buf[sizeof(unsigned int)+1]; int len = __objc_code_unsigned_int (buf, nbytes); if ((buf[0]&_B_CODE) == _B_SINT) @@ -290,15 +293,15 @@ objc_write_string (struct objc_typed_stream *stream, else /* _B_NINT */ buf[0] = (buf[0]&_B_VALUE)|_B_NSTR; - if ((*stream->write) (stream->physical, buf, len) != 0) - return (*stream->write) (stream->physical, string, nbytes); + if ((*stream->write)(stream->physical, buf, len) != 0) + return (*stream->write)(stream->physical, string, nbytes); else return 0; } int -objc_write_string_atomic (struct objc_typed_stream *stream, - unsigned char *string, unsigned int nbytes) +objc_write_string_atomic (struct objc_typed_stream* stream, + unsigned char* string, unsigned int nbytes) { unsigned long key; if ((key = PTR2LONG(hash_value_for_key (stream->stream_table, string)))) @@ -314,60 +317,60 @@ objc_write_string_atomic (struct objc_typed_stream *stream, } static int -objc_write_register_common (struct objc_typed_stream *stream, +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); + 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, buf, len + 1); + return (*stream->write)(stream->physical, buf, len+1); } else { buf[1] = (buf[1]&_B_VALUE)|_B_RCOMM; - return (*stream->write) (stream->physical, buf + 1, len); + return (*stream->write)(stream->physical, buf+1, len); } } static int -objc_write_use_common (struct objc_typed_stream *stream, unsigned long key) +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); + 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, buf, 2); + return (*stream->write)(stream->physical, buf, 2); } else { buf[1] = (buf[1]&_B_VALUE)|_B_UCOMM; - return (*stream->write) (stream->physical, buf + 1, len); + return (*stream->write)(stream->physical, buf+1, len); } } static __inline__ int -__objc_write_extension (struct objc_typed_stream *stream, unsigned char code) +__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, &buf, 1); + return (*stream->write)(stream->physical, &buf, 1); } else { - objc_error (nil, OBJC_ERR_BAD_OPCODE, - "__objc_write_extension: bad opcode %c\n", code); + objc_error(nil, OBJC_ERR_BAD_OPCODE, + "__objc_write_extension: bad opcode %c\n", code); return -1; } } __inline__ int -__objc_write_object (struct objc_typed_stream *stream, id object) +__objc_write_object (struct objc_typed_stream* stream, id object) { unsigned char buf = '\0'; SEL write_sel = sel_get_any_uid ("write:"); @@ -375,15 +378,15 @@ __objc_write_object (struct objc_typed_stream *stream, id 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, &buf, 1); + (*objc_msg_lookup(object, write_sel))(object, write_sel, stream); + return (*stream->write)(stream->physical, &buf, 1); } else - return objc_write_use_common (stream, 0); + return objc_write_use_common(stream, 0); } int -objc_write_object_reference (struct objc_typed_stream *stream, id object) +objc_write_object_reference (struct objc_typed_stream* stream, id object) { unsigned long key; if ((key = PTR2LONG(hash_value_for_key (stream->object_table, object)))) @@ -394,7 +397,7 @@ objc_write_object_reference (struct objc_typed_stream *stream, id object) } int -objc_write_root_object (struct objc_typed_stream *stream, id object) +objc_write_root_object (struct objc_typed_stream* stream, id object) { int len = 0; if (stream->writing_root_p) @@ -404,22 +407,22 @@ objc_write_root_object (struct objc_typed_stream *stream, id object) { stream->writing_root_p = 1; __objc_write_extension (stream, _BX_OBJROOT); - if ((len = objc_write_object (stream, object))) - __objc_finish_write_root_object (stream); + 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) +objc_write_object (struct objc_typed_stream* stream, id object) { unsigned long key; if ((key = PTR2LONG(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); + return objc_write_use_common(stream, 0); else { @@ -432,18 +435,18 @@ objc_write_object (struct objc_typed_stream *stream, id object) } __inline__ int -__objc_write_class (struct objc_typed_stream *stream, struct objc_class *class) +__objc_write_class (struct objc_typed_stream* stream, struct objc_class* class) { __objc_write_extension (stream, _BX_CLASS); - objc_write_string_atomic (stream, (char *) class->name, - strlen ((char *) class->name)); + objc_write_string_atomic(stream, (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) +objc_write_class (struct objc_typed_stream* stream, + struct objc_class* class) { unsigned long key; if ((key = PTR2LONG(hash_value_for_key (stream->stream_table, class)))) @@ -451,7 +454,7 @@ objc_write_class (struct objc_typed_stream *stream, else { int length; - hash_add (&stream->stream_table, LONG2PTR(key = PTR2LONG(class)), class); + 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; @@ -460,9 +463,9 @@ objc_write_class (struct objc_typed_stream *stream, __inline__ int -__objc_write_selector (struct objc_typed_stream *stream, SEL selector) +__objc_write_selector (struct objc_typed_stream* stream, SEL selector) { - const char *sel_name; + const char* sel_name; __objc_write_extension (stream, _BX_SEL); /* to handle NULL selectors */ if ((SEL)0 == selector) @@ -472,9 +475,9 @@ __objc_write_selector (struct objc_typed_stream *stream, SEL selector) } int -objc_write_selector (struct objc_typed_stream *stream, SEL selector) +objc_write_selector (struct objc_typed_stream* stream, SEL selector) { - const char *sel_name; + const char* sel_name; unsigned long key; /* to handle NULL selectors */ @@ -488,7 +491,7 @@ objc_write_selector (struct objc_typed_stream *stream, SEL selector) { int length; hash_add (&stream->stream_table, - LONG2PTR(key = PTR2LONG(sel_name)), (char *) sel_name); + LONG2PTR(key=PTR2LONG(sel_name)), (char*)sel_name); if ((length = objc_write_register_common (stream, key))) return __objc_write_selector (stream, selector); return length; @@ -502,11 +505,11 @@ objc_write_selector (struct objc_typed_stream *stream, SEL selector) */ __inline__ int -objc_read_char (struct objc_typed_stream *stream, char *val) +objc_read_char (struct objc_typed_stream* stream, char* val) { unsigned char buf; int len; - len = (*stream->read) (stream->physical, &buf, 1); + len = (*stream->read)(stream->physical, &buf, 1); if (len != 0) { if ((buf & _B_CODE) == _B_SINT) @@ -514,47 +517,47 @@ objc_read_char (struct objc_typed_stream *stream, char *val) else if ((buf & _B_NUMBER) == 1) { - len = (*stream->read) (stream->physical, val, 1); + len = (*stream->read)(stream->physical, val, 1); if (buf&_B_SIGN) - (*val) = -1 * (*val); + (*val) = -1*(*val); } else - objc_error (nil, OBJC_ERR_BAD_DATA, - "expected 8bit signed int, got %dbit int", - (int) (buf&_B_NUMBER)*8); + objc_error(nil, OBJC_ERR_BAD_DATA, + "expected 8bit signed int, got %dbit int", + (int)(buf&_B_NUMBER)*8); } return len; } __inline__ int -objc_read_unsigned_char (struct objc_typed_stream *stream, unsigned char *val) +objc_read_unsigned_char (struct objc_typed_stream* stream, unsigned char* val) { unsigned char buf; int len; - if ((len = (*stream->read) (stream->physical, &buf, 1))) + if ((len = (*stream->read)(stream->physical, &buf, 1))) { if ((buf & _B_CODE) == _B_SINT) (*val) = (buf & _B_VALUE); else if ((buf & _B_NUMBER) == 1) - len = (*stream->read) (stream->physical, val, 1); + len = (*stream->read)(stream->physical, val, 1); else - objc_error (nil, OBJC_ERR_BAD_DATA, - "expected 8bit unsigned int, got %dbit int", - (int) (buf&_B_NUMBER)*8); + objc_error(nil, OBJC_ERR_BAD_DATA, + "expected 8bit unsigned int, got %dbit int", + (int)(buf&_B_NUMBER)*8); } return len; } __inline__ int -objc_read_short (struct objc_typed_stream *stream, short *value) +objc_read_short (struct objc_typed_stream* stream, short* value) { - unsigned char buf[sizeof (short) + 1]; + unsigned char buf[sizeof(short)+1]; int len; - if ((len = (*stream->read) (stream->physical, buf, 1))) + if ((len = (*stream->read)(stream->physical, buf, 1))) { if ((buf[0] & _B_CODE) == _B_SINT) (*value) = (buf[0] & _B_VALUE); @@ -563,10 +566,10 @@ objc_read_short (struct objc_typed_stream *stream, short *value) { int pos = 1; int nbytes = buf[0] & _B_NUMBER; - if (nbytes > (int) sizeof (short)) - objc_error (nil, OBJC_ERR_BAD_DATA, - "expected short, got bigger (%dbits)", nbytes*8); - len = (*stream->read) (stream->physical, buf + 1, nbytes); + if (nbytes > sizeof (short)) + objc_error(nil, OBJC_ERR_BAD_DATA, + "expected short, got bigger (%dbits)", nbytes*8); + len = (*stream->read)(stream->physical, buf+1, nbytes); (*value) = 0; while (pos <= nbytes) (*value) = ((*value)*0x100) + buf[pos++]; @@ -578,12 +581,12 @@ objc_read_short (struct objc_typed_stream *stream, short *value) } __inline__ int -objc_read_unsigned_short (struct objc_typed_stream *stream, - unsigned short *value) +objc_read_unsigned_short (struct objc_typed_stream* stream, + unsigned short* value) { - unsigned char buf[sizeof (unsigned short) + 1]; + unsigned char buf[sizeof(unsigned short)+1]; int len; - if ((len = (*stream->read) (stream->physical, buf, 1))) + if ((len = (*stream->read)(stream->physical, buf, 1))) { if ((buf[0] & _B_CODE) == _B_SINT) (*value) = (buf[0] & _B_VALUE); @@ -592,10 +595,10 @@ objc_read_unsigned_short (struct objc_typed_stream *stream, { int pos = 1; int nbytes = buf[0] & _B_NUMBER; - if (nbytes > (int) sizeof (short)) - objc_error (nil, OBJC_ERR_BAD_DATA, - "expected short, got int or bigger"); - len = (*stream->read) (stream->physical, buf + 1, nbytes); + if (nbytes > sizeof (short)) + objc_error(nil, OBJC_ERR_BAD_DATA, + "expected short, got int or bigger"); + len = (*stream->read)(stream->physical, buf+1, nbytes); (*value) = 0; while (pos <= nbytes) (*value) = ((*value)*0x100) + buf[pos++]; @@ -606,11 +609,11 @@ objc_read_unsigned_short (struct objc_typed_stream *stream, __inline__ int -objc_read_int (struct objc_typed_stream *stream, int *value) +objc_read_int (struct objc_typed_stream* stream, int* value) { - unsigned char buf[sizeof (int) + 1]; + unsigned char buf[sizeof(int)+1]; int len; - if ((len = (*stream->read) (stream->physical, buf, 1))) + if ((len = (*stream->read)(stream->physical, buf, 1))) { if ((buf[0] & _B_CODE) == _B_SINT) (*value) = (buf[0] & _B_VALUE); @@ -619,9 +622,9 @@ objc_read_int (struct objc_typed_stream *stream, int *value) { int pos = 1; int nbytes = buf[0] & _B_NUMBER; - if (nbytes > (int) sizeof (int)) - objc_error (nil, OBJC_ERR_BAD_DATA, "expected int, got bigger"); - len = (*stream->read) (stream->physical, buf + 1, nbytes); + if (nbytes > sizeof (int)) + objc_error(nil, OBJC_ERR_BAD_DATA, "expected int, got bigger"); + len = (*stream->read)(stream->physical, buf+1, nbytes); (*value) = 0; while (pos <= nbytes) (*value) = ((*value)*0x100) + buf[pos++]; @@ -633,11 +636,11 @@ objc_read_int (struct objc_typed_stream *stream, int *value) } __inline__ int -objc_read_long (struct objc_typed_stream *stream, long *value) +objc_read_long (struct objc_typed_stream* stream, long* value) { - unsigned char buf[sizeof (long) + 1]; + unsigned char buf[sizeof(long)+1]; int len; - if ((len = (*stream->read) (stream->physical, buf, 1))) + if ((len = (*stream->read)(stream->physical, buf, 1))) { if ((buf[0] & _B_CODE) == _B_SINT) (*value) = (buf[0] & _B_VALUE); @@ -646,9 +649,9 @@ objc_read_long (struct objc_typed_stream *stream, long *value) { int pos = 1; int nbytes = buf[0] & _B_NUMBER; - if (nbytes > (int) sizeof (long)) - objc_error (nil, OBJC_ERR_BAD_DATA, "expected long, got bigger"); - len = (*stream->read) (stream->physical, buf + 1, nbytes); + if (nbytes > sizeof (long)) + objc_error(nil, OBJC_ERR_BAD_DATA, "expected long, got bigger"); + len = (*stream->read)(stream->physical, buf+1, nbytes); (*value) = 0; while (pos <= nbytes) (*value) = ((*value)*0x100) + buf[pos++]; @@ -660,17 +663,16 @@ objc_read_long (struct objc_typed_stream *stream, long *value) } __inline__ int -__objc_read_nbyte_uint (struct objc_typed_stream *stream, - unsigned int nbytes, unsigned int *val) +__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]; + int len, pos = 0; + unsigned char buf[sizeof(unsigned int)+1]; if (nbytes > sizeof (int)) - objc_error (nil, OBJC_ERR_BAD_DATA, "expected int, got bigger"); + objc_error(nil, OBJC_ERR_BAD_DATA, "expected int, got bigger"); - len = (*stream->read) (stream->physical, buf, nbytes); + len = (*stream->read)(stream->physical, buf, nbytes); (*val) = 0; while (pos < nbytes) (*val) = ((*val)*0x100) + buf[pos++]; @@ -679,12 +681,12 @@ __objc_read_nbyte_uint (struct objc_typed_stream *stream, __inline__ int -objc_read_unsigned_int (struct objc_typed_stream *stream, - unsigned int *value) +objc_read_unsigned_int (struct objc_typed_stream* stream, + unsigned int* value) { - unsigned char buf[sizeof (unsigned int) + 1]; + unsigned char buf[sizeof(unsigned int)+1]; int len; - if ((len = (*stream->read) (stream->physical, buf, 1))) + if ((len = (*stream->read)(stream->physical, buf, 1))) { if ((buf[0] & _B_CODE) == _B_SINT) (*value) = (buf[0] & _B_VALUE); @@ -697,17 +699,16 @@ objc_read_unsigned_int (struct objc_typed_stream *stream, } int -__objc_read_nbyte_ulong (struct objc_typed_stream *stream, - unsigned int nbytes, unsigned long *val) +__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]; + int len, pos = 0; + unsigned char buf[sizeof(unsigned long)+1]; if (nbytes > sizeof (long)) - objc_error (nil, OBJC_ERR_BAD_DATA, "expected long, got bigger"); + objc_error(nil, OBJC_ERR_BAD_DATA, "expected long, got bigger"); - len = (*stream->read) (stream->physical, buf, nbytes); + len = (*stream->read)(stream->physical, buf, nbytes); (*val) = 0; while (pos < nbytes) (*val) = ((*val)*0x100) + buf[pos++]; @@ -716,12 +717,12 @@ __objc_read_nbyte_ulong (struct objc_typed_stream *stream, __inline__ int -objc_read_unsigned_long (struct objc_typed_stream *stream, - unsigned long *value) +objc_read_unsigned_long (struct objc_typed_stream* stream, + unsigned long* value) { - unsigned char buf[sizeof (unsigned long) + 1]; + unsigned char buf[sizeof(unsigned long)+1]; int len; - if ((len = (*stream->read) (stream->physical, buf, 1))) + if ((len = (*stream->read)(stream->physical, buf, 1))) { if ((buf[0] & _B_CODE) == _B_SINT) (*value) = (buf[0] & _B_VALUE); @@ -734,29 +735,29 @@ objc_read_unsigned_long (struct objc_typed_stream *stream, } __inline__ int -objc_read_string (struct objc_typed_stream *stream, - char **string) +objc_read_string (struct objc_typed_stream* stream, + char** string) { - unsigned char buf[sizeof (unsigned int) + 1]; + unsigned char buf[sizeof(unsigned int)+1]; int len; - if ((len = (*stream->read) (stream->physical, buf, 1))) + if ((len = (*stream->read)(stream->physical, 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, buf, 1); + len = __objc_read_nbyte_ulong(stream, (buf[0] & _B_VALUE), &key); + len = (*stream->read)(stream->physical, buf, 1); } switch (buf[0]&_B_CODE) { case _B_SSTR: { int length = buf[0]&_B_VALUE; - (*string) = (char*)objc_malloc (length + 1); + (*string) = (char*)objc_malloc(length+1); if (key) hash_add (&stream->stream_table, LONG2PTR(key), *string); - len = (*stream->read) (stream->physical, *string, length); + len = (*stream->read)(stream->physical, *string, length); (*string)[length] = '\0'; } break; @@ -764,9 +765,9 @@ objc_read_string (struct objc_typed_stream *stream, case _B_UCOMM: { char *tmp; - len = __objc_read_nbyte_ulong (stream, (buf[0] & _B_VALUE), &key); + len = __objc_read_nbyte_ulong(stream, (buf[0] & _B_VALUE), &key); tmp = hash_value_for_key (stream->stream_table, LONG2PTR (key)); - *string = objc_malloc (strlen (tmp) + 1); + *string = objc_malloc (strlen(tmp) + 1); strcpy (*string, tmp); } break; @@ -774,20 +775,20 @@ objc_read_string (struct objc_typed_stream *stream, case _B_NSTR: { unsigned int nbytes = buf[0]&_B_VALUE; - len = __objc_read_nbyte_uint (stream, nbytes, &nbytes); + len = __objc_read_nbyte_uint(stream, nbytes, &nbytes); if (len) { - (*string) = (char*)objc_malloc (nbytes + 1); + (*string) = (char*)objc_malloc(nbytes+1); if (key) hash_add (&stream->stream_table, LONG2PTR(key), *string); - len = (*stream->read) (stream->physical, *string, nbytes); + len = (*stream->read)(stream->physical, *string, nbytes); (*string)[nbytes] = '\0'; } } break; default: - objc_error (nil, OBJC_ERR_BAD_DATA, - "expected string, got opcode %c\n", (buf[0]&_B_CODE)); + objc_error(nil, OBJC_ERR_BAD_DATA, + "expected string, got opcode %c\n", (buf[0]&_B_CODE)); } } @@ -796,19 +797,19 @@ objc_read_string (struct objc_typed_stream *stream, int -objc_read_object (struct objc_typed_stream *stream, id *object) +objc_read_object (struct objc_typed_stream* stream, id* object) { unsigned char buf[sizeof (unsigned int)]; int len; - if ((len = (*stream->read) (stream->physical, buf, 1))) + if ((len = (*stream->read)(stream->physical, 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, buf, 1); + len = __objc_read_nbyte_ulong(stream, (buf[0] & _B_VALUE), &key); + len = (*stream->read)(stream->physical, buf, 1); } if (buf[0] == (_B_EXT | _BX_OBJECT)) @@ -819,7 +820,7 @@ objc_read_object (struct objc_typed_stream *stream, id *object) len = objc_read_class (stream, &class); /* create instance */ - (*object) = class_create_instance (class); + (*object) = class_create_instance(class); /* register? */ if (key) @@ -827,148 +828,148 @@ objc_read_object (struct objc_typed_stream *stream, id *object) /* send -read: */ if (__objc_responds_to (*object, read_sel)) - (*get_imp (class, read_sel)) (*object, read_sel, stream); + (*get_imp(class, read_sel))(*object, read_sel, stream); /* check null-byte */ - len = (*stream->read) (stream->physical, buf, 1); + len = (*stream->read)(stream->physical, buf, 1); if (buf[0] != '\0') - objc_error (nil, OBJC_ERR_BAD_DATA, - "expected null-byte, got opcode %c", buf[0]); + objc_error(nil, OBJC_ERR_BAD_DATA, + "expected null-byte, got opcode %c", buf[0]); } else if ((buf[0]&_B_CODE) == _B_UCOMM) { if (key) - objc_error (nil, OBJC_ERR_BAD_KEY, "cannot register use upcode..."); - len = __objc_read_nbyte_ulong (stream, (buf[0] & _B_VALUE), &key); + objc_error(nil, OBJC_ERR_BAD_KEY, "cannot register use upcode..."); + len = __objc_read_nbyte_ulong(stream, (buf[0] & _B_VALUE), &key); (*object) = hash_value_for_key (stream->object_table, LONG2PTR(key)); } else if (buf[0] == (_B_EXT | _BX_OBJREF)) /* a forward reference */ { - struct objc_list *other; + struct objc_list* other; len = objc_read_unsigned_long (stream, &key); - other = (struct objc_list *) hash_value_for_key (stream->object_refs, - LONG2PTR(key)); + other = (struct objc_list*)hash_value_for_key (stream->object_refs, + LONG2PTR(key)); hash_add (&stream->object_refs, LONG2PTR(key), - (void *)list_cons (object, other)); + (void*)list_cons(object, other)); } else if (buf[0] == (_B_EXT | _BX_OBJROOT)) /* a root object */ { if (key) - objc_error (nil, OBJC_ERR_BAD_KEY, - "cannot register root object..."); + objc_error(nil, OBJC_ERR_BAD_KEY, + "cannot register root object..."); len = objc_read_object (stream, object); __objc_finish_read_root_object (stream); } else - objc_error (nil, OBJC_ERR_BAD_DATA, - "expected object, got opcode %c", buf[0]); + objc_error(nil, OBJC_ERR_BAD_DATA, + "expected object, got opcode %c", buf[0]); } return len; } static int -objc_read_class (struct objc_typed_stream *stream, Class *class) +objc_read_class (struct objc_typed_stream* stream, Class* class) { unsigned char buf[sizeof (unsigned int)]; int len; - if ((len = (*stream->read) (stream->physical, buf, 1))) + if ((len = (*stream->read)(stream->physical, 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, buf, 1); + len = __objc_read_nbyte_ulong(stream, (buf[0] & _B_VALUE), &key); + len = (*stream->read)(stream->physical, buf, 1); } if (buf[0] == (_B_EXT | _BX_CLASS)) { - char *class_name; + char* class_name; unsigned long version; /* get class */ len = objc_read_string (stream, &class_name); - (*class) = objc_get_class (class_name); - objc_free (class_name); + (*class) = objc_get_class(class_name); + objc_free(class_name); /* register */ if (key) hash_add (&stream->stream_table, LONG2PTR(key), *class); - objc_read_unsigned_long (stream, &version); - hash_add (&stream->class_table, (*class)->name, (void *)version); + objc_read_unsigned_long(stream, &version); + hash_add (&stream->class_table, (*class)->name, (void*)version); } else if ((buf[0]&_B_CODE) == _B_UCOMM) { if (key) - objc_error (nil, OBJC_ERR_BAD_KEY, "cannot register use upcode..."); - len = __objc_read_nbyte_ulong (stream, (buf[0] & _B_VALUE), &key); - *class = hash_value_for_key (stream->stream_table, LONG2PTR(key)); - if (! *class) - objc_error (nil, OBJC_ERR_BAD_CLASS, - "cannot find class for key %lu", key); + objc_error(nil, OBJC_ERR_BAD_KEY, "cannot register use upcode..."); + len = __objc_read_nbyte_ulong(stream, (buf[0] & _B_VALUE), &key); + (*class) = hash_value_for_key (stream->stream_table, LONG2PTR(key)); + if (!*class) + objc_error(nil, OBJC_ERR_BAD_CLASS, + "cannot find class for key %lu", key); } else - objc_error (nil, OBJC_ERR_BAD_DATA, - "expected class, got opcode %c", buf[0]); + objc_error(nil, OBJC_ERR_BAD_DATA, + "expected class, got opcode %c", buf[0]); } return len; } int -objc_read_selector (struct objc_typed_stream *stream, SEL* selector) +objc_read_selector (struct objc_typed_stream* stream, SEL* selector) { unsigned char buf[sizeof (unsigned int)]; int len; - if ((len = (*stream->read) (stream->physical, buf, 1))) + if ((len = (*stream->read)(stream->physical, 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, buf, 1); + len = __objc_read_nbyte_ulong(stream, (buf[0] & _B_VALUE), &key); + len = (*stream->read)(stream->physical, buf, 1); } if (buf[0] == (_B_EXT|_BX_SEL)) /* selector! */ { - char *selector_name; + char* selector_name; /* get selector */ len = objc_read_string (stream, &selector_name); /* To handle NULL selectors */ - if (0 == strlen (selector_name)) + if (0 == strlen(selector_name)) { (*selector) = (SEL)0; return 0; } else - (*selector) = sel_get_any_uid (selector_name); - objc_free (selector_name); + (*selector) = sel_get_any_uid(selector_name); + objc_free(selector_name); /* register */ if (key) - hash_add (&stream->stream_table, LONG2PTR(key), (void *) *selector); + hash_add (&stream->stream_table, LONG2PTR(key), (void*)*selector); } else if ((buf[0]&_B_CODE) == _B_UCOMM) { if (key) - objc_error (nil, OBJC_ERR_BAD_KEY, "cannot register use upcode..."); - len = __objc_read_nbyte_ulong (stream, (buf[0] & _B_VALUE), &key); + objc_error(nil, OBJC_ERR_BAD_KEY, "cannot register use upcode..."); + len = __objc_read_nbyte_ulong(stream, (buf[0] & _B_VALUE), &key); (*selector) = hash_value_for_key (stream->stream_table, LONG2PTR(key)); } else - objc_error (nil, OBJC_ERR_BAD_DATA, - "expected selector, got opcode %c", buf[0]); + objc_error(nil, OBJC_ERR_BAD_DATA, + "expected selector, got opcode %c", buf[0]); } return len; } @@ -983,67 +984,66 @@ objc_read_selector (struct objc_typed_stream *stream, SEL* selector) */ int -objc_write_type (TypedStream *stream, const char *type, const void *data) +objc_write_type(TypedStream* stream, const char* type, const void* data) { - switch (*type) { + switch(*type) { case _C_ID: - return objc_write_object (stream, *(id *) data); + return objc_write_object (stream, *(id*)data); break; case _C_CLASS: - return objc_write_class (stream, *(Class *) data); + return objc_write_class (stream, *(Class*)data); break; case _C_SEL: - return objc_write_selector (stream, *(SEL *) data); + return objc_write_selector (stream, *(SEL*)data); break; case _C_CHR: - return objc_write_char (stream, *(signed char *) data); + return objc_write_char(stream, *(signed char*)data); break; case _C_UCHR: - return objc_write_unsigned_char (stream, *(unsigned char *) data); + return objc_write_unsigned_char(stream, *(unsigned char*)data); break; case _C_SHT: - return objc_write_short (stream, *(short *) data); + return objc_write_short(stream, *(short*)data); break; case _C_USHT: - return objc_write_unsigned_short (stream, *(unsigned short *) data); + return objc_write_unsigned_short(stream, *(unsigned short*)data); break; case _C_INT: - return objc_write_int (stream, *(int *) data); + return objc_write_int(stream, *(int*)data); break; case _C_UINT: - return objc_write_unsigned_int (stream, *(unsigned int *) data); + return objc_write_unsigned_int(stream, *(unsigned int*)data); break; case _C_LNG: - return objc_write_long (stream, *(long *) data); + return objc_write_long(stream, *(long*)data); break; case _C_ULNG: - return objc_write_unsigned_long (stream, *(unsigned long *) data); + return objc_write_unsigned_long(stream, *(unsigned long*)data); break; case _C_CHARPTR: - return objc_write_string (stream, - *(char **) data, strlen (*(char **) data)); + return objc_write_string (stream, *(char**)data, strlen(*(char**)data)); break; case _C_ATOM: - return objc_write_string_atomic (stream, *(char **) data, - strlen (*(char **) data)); + return objc_write_string_atomic (stream, *(char**)data, + strlen(*(char**)data)); break; case _C_ARY_B: { - int len = atoi (type + 1); - while (isdigit ((unsigned char) *++type)) + int len = atoi(type+1); + while (isdigit(*++type)) ; return objc_write_array (stream, type, len, data); } @@ -1059,7 +1059,7 @@ objc_write_type (TypedStream *stream, const char *type, const void *data) { align = objc_alignof_type (type); /* padd to alignment */ acc_size += ROUND (acc_size, align); - objc_write_type (stream, type, ((char *) data) + acc_size); + 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 */ } @@ -1068,8 +1068,8 @@ objc_write_type (TypedStream *stream, const char *type, const void *data) default: { - objc_error (nil, OBJC_ERR_BAD_TYPE, - "objc_write_type: cannot parse typespec: %s\n", type); + objc_error(nil, OBJC_ERR_BAD_TYPE, + "objc_write_type: cannot parse typespec: %s\n", type); return 0; } } @@ -1083,10 +1083,10 @@ objc_write_type (TypedStream *stream, const char *type, const void *data) */ int -objc_read_type(TypedStream *stream, const char *type, void *data) +objc_read_type(TypedStream* stream, const char* type, void* data) { char c; - switch (c = *type) { + switch(c = *type) { case _C_ID: return objc_read_object (stream, (id*)data); break; @@ -1138,8 +1138,8 @@ objc_read_type(TypedStream *stream, const char *type, void *data) case _C_ARY_B: { - int len = atoi (type + 1); - while (isdigit ((unsigned char) *++type)) + int len = atoi(type+1); + while (isdigit(*++type)) ; return objc_read_array (stream, type, len, data); } @@ -1164,8 +1164,8 @@ objc_read_type(TypedStream *stream, const char *type, void *data) default: { - objc_error (nil, OBJC_ERR_BAD_TYPE, - "objc_read_type: cannot parse typespec: %s\n", type); + objc_error(nil, OBJC_ERR_BAD_TYPE, + "objc_read_type: cannot parse typespec: %s\n", type); return 0; } } @@ -1182,7 +1182,7 @@ objc_read_type(TypedStream *stream, const char *type, void *data) */ int -objc_write_types (TypedStream *stream, const char *type, ...) +objc_write_types (TypedStream* stream, const char* type, ...) { va_list args; const char *c; @@ -1192,17 +1192,17 @@ objc_write_types (TypedStream *stream, const char *type, ...) for (c = type; *c; c = objc_skip_typespec (c)) { - switch (*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*)); + res = objc_write_class (stream, *va_arg(args, Class*)); break; case _C_SEL: - res = objc_write_selector (stream, *va_arg (args, SEL*)); + res = objc_write_selector (stream, *va_arg(args, SEL*)); break; case _C_CHR: @@ -1215,60 +1215,60 @@ objc_write_types (TypedStream *stream, const char *type, ...) break; case _C_SHT: - res = objc_write_short (stream, *va_arg (args, short*)); + res = objc_write_short (stream, *va_arg(args, short*)); break; case _C_USHT: res = objc_write_unsigned_short (stream, - *va_arg (args, unsigned short*)); + *va_arg(args, unsigned short*)); break; case _C_INT: - res = objc_write_int(stream, *va_arg (args, 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*)); + res = objc_write_unsigned_int(stream, *va_arg(args, unsigned int*)); break; case _C_LNG: - res = objc_write_long(stream, *va_arg (args, long*)); + res = objc_write_long(stream, *va_arg(args, long*)); break; case _C_ULNG: - res = objc_write_unsigned_long(stream, *va_arg (args, unsigned long*)); + res = objc_write_unsigned_long(stream, *va_arg(args, unsigned long*)); break; case _C_CHARPTR: { - char **str = va_arg (args, char **); - res = objc_write_string (stream, *str, strlen (*str)); + char** str = va_arg(args, char**); + res = objc_write_string (stream, *str, strlen(*str)); } break; case _C_ATOM: { - char **str = va_arg (args, char **); - res = objc_write_string_atomic (stream, *str, strlen (*str)); + char** str = va_arg(args, char**); + res = objc_write_string_atomic (stream, *str, strlen(*str)); } break; case _C_ARY_B: { - int len = atoi (c + 1); - const char *t = c; - while (isdigit ((unsigned char) *++t)) + int len = atoi(c+1); + const char* t = c; + while (isdigit(*++t)) ; - res = objc_write_array (stream, t, len, va_arg (args, void *)); + res = objc_write_array (stream, t, len, va_arg(args, void*)); t = objc_skip_typespec (t); if (*t != _C_ARY_E) - objc_error (nil, OBJC_ERR_BAD_TYPE, "expected `]', got: %s", t); + objc_error(nil, OBJC_ERR_BAD_TYPE, "expected `]', got: %s", t); } break; default: - objc_error (nil, OBJC_ERR_BAD_TYPE, - "objc_write_types: cannot parse typespec: %s\n", type); + objc_error(nil, OBJC_ERR_BAD_TYPE, + "objc_write_types: cannot parse typespec: %s\n", type); } } va_end(args); @@ -1282,88 +1282,88 @@ objc_write_types (TypedStream *stream, const char *type, ...) */ int -objc_read_types(TypedStream *stream, const char *type, ...) +objc_read_types(TypedStream* stream, const char* type, ...) { va_list args; const char *c; int res = 0; - va_start (args, type); + va_start(args, type); for (c = type; *c; c = objc_skip_typespec(c)) { - switch (*c) { + switch(*c) { case _C_ID: - res = objc_read_object(stream, va_arg (args, id*)); + res = objc_read_object(stream, va_arg(args, id*)); break; case _C_CLASS: - res = objc_read_class(stream, va_arg (args, Class*)); + res = objc_read_class(stream, va_arg(args, Class*)); break; case _C_SEL: - res = objc_read_selector(stream, va_arg (args, SEL*)); + res = objc_read_selector(stream, va_arg(args, SEL*)); break; case _C_CHR: - res = objc_read_char(stream, va_arg (args, char*)); + res = objc_read_char(stream, va_arg(args, char*)); break; case _C_UCHR: - res = objc_read_unsigned_char(stream, va_arg (args, unsigned char*)); + res = objc_read_unsigned_char(stream, va_arg(args, unsigned char*)); break; case _C_SHT: - res = objc_read_short(stream, va_arg (args, short*)); + res = objc_read_short(stream, va_arg(args, short*)); break; case _C_USHT: - res = objc_read_unsigned_short(stream, va_arg (args, unsigned short*)); + res = objc_read_unsigned_short(stream, va_arg(args, unsigned short*)); break; case _C_INT: - res = objc_read_int(stream, va_arg (args, 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*)); + res = objc_read_unsigned_int(stream, va_arg(args, unsigned int*)); break; case _C_LNG: - res = objc_read_long(stream, va_arg (args, long*)); + res = objc_read_long(stream, va_arg(args, long*)); break; case _C_ULNG: - res = objc_read_unsigned_long(stream, va_arg (args, unsigned long*)); + res = objc_read_unsigned_long(stream, va_arg(args, unsigned long*)); break; case _C_CHARPTR: case _C_ATOM: { - char **str = va_arg (args, char **); + 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)) + int len = atoi(c+1); + const char* t = c; + while (isdigit(*++t)) ; - res = objc_read_array (stream, t, len, va_arg (args, void *)); + res = objc_read_array (stream, t, len, va_arg(args, void*)); t = objc_skip_typespec (t); if (*t != _C_ARY_E) - objc_error (nil, OBJC_ERR_BAD_TYPE, "expected `]', got: %s", t); + objc_error(nil, OBJC_ERR_BAD_TYPE, "expected `]', got: %s", t); } break; default: - objc_error (nil, OBJC_ERR_BAD_TYPE, - "objc_read_types: cannot parse typespec: %s\n", type); + objc_error(nil, OBJC_ERR_BAD_TYPE, + "objc_read_types: cannot parse typespec: %s\n", type); } } - va_end (args); + va_end(args); return res; } @@ -1373,11 +1373,11 @@ objc_read_types(TypedStream *stream, const char *type, ...) */ int -objc_write_array (TypedStream *stream, const char *type, - int count, const void *data) +objc_write_array (TypedStream* stream, const char* type, + int count, const void* data) { int off = objc_sizeof_type(type); - const char *where = data; + const char* where = data; while (count-- > 0) { @@ -1395,11 +1395,11 @@ objc_write_array (TypedStream *stream, const char *type, */ int -objc_read_array (TypedStream *stream, const char *type, - int count, void *data) +objc_read_array (TypedStream* stream, const char* type, + int count, void* data) { int off = objc_sizeof_type(type); - char *where = (char*)data; + char* where = (char*)data; while (count-- > 0) { @@ -1410,48 +1410,44 @@ objc_read_array (TypedStream *stream, const char *type, } static int -__objc_fread (FILE *file, char *data, int len) +__objc_fread(FILE* file, char* data, int len) { return fread(data, len, 1, file); } static int -__objc_fwrite (FILE *file, char *data, int len) +__objc_fwrite(FILE* file, char* data, int len) { return fwrite(data, len, 1, file); } static int -__objc_feof (FILE *file) +__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_no_write(FILE* file, char* data, int len) { objc_error (nil, OBJC_ERR_NO_WRITE, "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_no_read(FILE* file, char* data, int len) { objc_error (nil, OBJC_ERR_NO_READ, "TypedStream not open for reading"); return 0; } static int -__objc_read_typed_stream_signature (TypedStream *stream) +__objc_read_typed_stream_signature (TypedStream* stream) { char buffer[80]; int pos = 0; do - (*stream->read) (stream->physical, buffer+pos, 1); + (*stream->read)(stream->physical, buffer+pos, 1); while (buffer[pos++] != '\0') ; sscanf (buffer, "GNU TypedStream %d", &stream->version); @@ -1462,16 +1458,16 @@ __objc_read_typed_stream_signature (TypedStream *stream) } static int -__objc_write_typed_stream_signature (TypedStream *stream) +__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); + (*stream->write)(stream->physical, buffer, strlen(buffer)+1); return 1; } -static void __objc_finish_write_root_object(struct objc_typed_stream *stream) +static void __objc_finish_write_root_object(struct objc_typed_stream* stream) { hash_delete (stream->object_table); stream->object_table = hash_new(64, @@ -1479,7 +1475,7 @@ static void __objc_finish_write_root_object(struct objc_typed_stream *stream) (compare_func_type)compare_ptrs); } -static void __objc_finish_read_root_object(struct objc_typed_stream *stream) +static void __objc_finish_read_root_object(struct objc_typed_stream* stream) { node_ptr node; SEL awake_sel = sel_get_any_uid ("awake"); @@ -1491,12 +1487,12 @@ static void __objc_finish_read_root_object(struct objc_typed_stream *stream) for (node = hash_next (stream->object_refs, NULL); node; node = hash_next (stream->object_refs, node)) { - struct objc_list *reflist = node->value; - const void *key = node->key; + struct objc_list* reflist = node->value; + const void* key = node->key; id object = hash_value_for_key (stream->object_table, key); - while (reflist) + while(reflist) { - *((id*) reflist->head) = object; + *((id*)reflist->head) = object; if (hash_value_for_key (free_list,reflist) == NULL) hash_add (&free_list,reflist,reflist); @@ -1524,7 +1520,7 @@ static void __objc_finish_read_root_object(struct objc_typed_stream *stream) { id object = node->value; if (__objc_responds_to (object, awake_sel)) - (*objc_msg_lookup (object, awake_sel)) (object, awake_sel); + (*objc_msg_lookup(object, awake_sel))(object, awake_sel); } } @@ -1539,38 +1535,38 @@ static void __objc_finish_read_root_object(struct objc_typed_stream *stream) ** Open the stream PHYSICAL in MODE */ -TypedStream * -objc_open_typed_stream (FILE *physical, int mode) +TypedStream* +objc_open_typed_stream (FILE* physical, int mode) { - TypedStream *s = (TypedStream *) objc_malloc (sizeof (TypedStream)); + TypedStream* s = (TypedStream*)objc_malloc(sizeof(TypedStream)); s->mode = mode; s->physical = physical; - s->stream_table = hash_new (64, - (hash_func_type) hash_ptr, - (compare_func_type) compare_ptrs); - s->object_table = hash_new (64, - (hash_func_type) hash_ptr, - (compare_func_type) compare_ptrs); - s->eof = (objc_typed_eof_func) __objc_feof; - s->flush = (objc_typed_flush_func) fflush; + s->stream_table = hash_new(64, + (hash_func_type)hash_ptr, + (compare_func_type)compare_ptrs); + s->object_table = hash_new(64, + (hash_func_type)hash_ptr, + (compare_func_type)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 = hash_new (8, (hash_func_type) hash_string, - (compare_func_type) compare_strings); - s->object_refs = hash_new (8, (hash_func_type) hash_ptr, - (compare_func_type) compare_ptrs); - s->read = (objc_typed_read_func) __objc_fread; - s->write = (objc_typed_write_func) __objc_no_write; + s->class_table = hash_new(8, (hash_func_type)hash_string, + (compare_func_type)compare_strings); + s->object_refs = hash_new(8, (hash_func_type)hash_ptr, + (compare_func_type)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; + s->read = (objc_typed_read_func)__objc_no_read; + s->write = (objc_typed_write_func)__objc_fwrite; __objc_write_typed_stream_signature (s); } else @@ -1587,10 +1583,10 @@ objc_open_typed_stream (FILE *physical, int mode) */ TypedStream* -objc_open_typed_stream_for_file (const char *file_name, int mode) +objc_open_typed_stream_for_file (const char* file_name, int mode) { - FILE *file = NULL; - TypedStream *s; + FILE* file = NULL; + TypedStream* s; if (mode == OBJC_READONLY) file = fopen (file_name, "r"); @@ -1614,7 +1610,7 @@ objc_open_typed_stream_for_file (const char *file_name, int mode) */ void -objc_close_typed_stream (TypedStream *stream) +objc_close_typed_stream (TypedStream* stream) { if (stream->mode == OBJC_READONLY) { @@ -1627,25 +1623,25 @@ objc_close_typed_stream (TypedStream *stream) hash_delete (stream->object_table); if (stream->type == (OBJC_MANAGED_STREAM | OBJC_FILE_STREAM)) - fclose ((FILE *)stream->physical); + fclose ((FILE*)stream->physical); objc_free(stream); } BOOL -objc_end_of_typed_stream (TypedStream *stream) +objc_end_of_typed_stream (TypedStream* stream) { - return (*stream->eof) (stream->physical); + return (*stream->eof)(stream->physical); } void -objc_flush_typed_stream (TypedStream *stream) +objc_flush_typed_stream (TypedStream* stream) { - (*stream->flush) (stream->physical); + (*stream->flush)(stream->physical); } long -objc_get_stream_class_version (TypedStream *stream, Class class) +objc_get_stream_class_version (TypedStream* stream, Class class) { if (stream->class_table) return PTR2LONG(hash_value_for_key (stream->class_table, class->name)); diff --git a/gnu/lib/libobjc/libobjc/class.c b/gnu/lib/libobjc/libobjc/class.c index 1740f38788e..44aa1b9f98e 100644 --- a/gnu/lib/libobjc/libobjc/class.c +++ b/gnu/lib/libobjc/libobjc/class.c @@ -1,11 +1,7 @@ /* GNU Objective C Runtime class related functions - Copyright (C) 1993, 1995, 1996, 1997, 2001, 2002 - Free Software Foundation, Inc. + Copyright (C) 1993, 1995, 1996, 1997 Free Software Foundation, Inc. Contributed by Kresten Krab Thorup and Dennis Glatting. - Lock-free class table code designed and written from scratch by - Nicola Pero, 2001. - This file is part of GNU CC. GNU CC is free software; you can redistribute it and/or modify it under the @@ -27,490 +23,135 @@ Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ however invalidate any other reasons why the executable file might be covered by the GNU General Public License. */ -/* - The code in this file critically affects class method invocation - speed. This long preamble comment explains why, and the issues - involved. - - - One of the traditional weaknesses of the GNU Objective-C runtime is - that class method invocations are slow. The reason is that when you - write - - array = [NSArray new]; - - this gets basically compiled into the equivalent of - - array = [(objc_get_class ("NSArray")) new]; - - objc_get_class returns the class pointer corresponding to the string - `NSArray'; and because of the lookup, the operation is more - complicated and slow than a simple instance method invocation. - - Most high performance Objective-C code (using the GNU Objc runtime) - I had the opportunity to read (or write) work around this problem by - caching the class pointer: - - Class arrayClass = [NSArray class]; - - ... later on ... - - array = [arrayClass new]; - array = [arrayClass new]; - array = [arrayClass new]; - - In this case, you always perform a class lookup (the first one), but - then all the [arrayClass new] methods run exactly as fast as an - instance method invocation. It helps if you have many class method - invocations to the same class. - - The long-term solution to this problem would be to modify the - compiler to output tables of class pointers corresponding to all the - class method invocations, and to add code to the runtime to update - these tables - that should in the end allow class method invocations - to perform precisely as fast as instance method invocations, because - no class lookup would be involved. I think the Apple Objective-C - runtime uses this technique. Doing this involves synchronized - modifications in the runtime and in the compiler. - - As a first medicine to the problem, I [NP] have redesigned and - rewritten the way the runtime is performing class lookup. This - doesn't give as much speed as the other (definitive) approach, but - at least a class method invocation now takes approximately 4.5 times - an instance method invocation on my machine (it would take approx 12 - times before the rewriting), which is a lot better. - - One of the main reason the new class lookup is so faster is because - I implemented it in a way that can safely run multithreaded without - using locks - a so-called `lock-free' data structure. The atomic - operation is pointer assignment. The reason why in this problem - lock-free data structures work so well is that you never remove - classes from the table - and the difficult thing with lock-free data - structures is freeing data when is removed from the structures. */ - -#include "runtime.h" /* the kitchen sink */ +#include "runtime.h" /* the kitchen sink */ #include "sarray.h" -#include <objc/objc.h> -#include <objc/objc-api.h> -#include <objc/thr.h> - -/* We use a table which maps a class name to the corresponding class - * pointer. The first part of this file defines this table, and - * functions to do basic operations on the table. The second part of - * the file implements some higher level Objective-C functionality for - * classes by using the functions provided in the first part to manage - * the table. */ - -/** - ** Class Table Internals - **/ - -/* A node holding a class */ -typedef struct class_node -{ - struct class_node *next; /* Pointer to next entry on the list. - NULL indicates end of list. */ - - const char *name; /* The class name string */ - int length; /* The class name string length */ - Class pointer; /* The Class pointer */ - -} *class_node_ptr; - -/* A table containing classes is a class_node_ptr (pointing to the - first entry in the table - if it is NULL, then the table is - empty). */ - -/* We have 1024 tables. Each table contains all class names which - have the same hash (which is a number between 0 and 1023). To look - up a class_name, we compute its hash, and get the corresponding - table. Once we have the table, we simply compare strings directly - till we find the one which we want (using the length first). The - number of tables is quite big on purpose (a normal big application - has less than 1000 classes), so that you shouldn't normally get any - collisions, and get away with a single comparison (which we can't - avoid since we need to know that you have got the right thing). */ -#define CLASS_TABLE_SIZE 1024 -#define CLASS_TABLE_MASK 1023 - -static class_node_ptr class_table_array[CLASS_TABLE_SIZE]; - -/* The table writing mutex - we lock on writing to avoid conflicts - between different writers, but we read without locks. That is - possible because we assume pointer assignment to be an atomic - operation. */ -static objc_mutex_t __class_table_lock = NULL; - -/* CLASS_TABLE_HASH is how we compute the hash of a class name. It is - a macro - *not* a function - arguments *are* modified directly. - - INDEX should be a variable holding an int; - HASH should be a variable holding an int; - CLASS_NAME should be a variable holding a (char *) to the class_name. - - After the macro is executed, INDEX contains the length of the - string, and HASH the computed hash of the string; CLASS_NAME is - untouched. */ - -#define CLASS_TABLE_HASH(INDEX, HASH, CLASS_NAME) \ - HASH = 0; \ - for (INDEX = 0; CLASS_NAME[INDEX] != '\0'; INDEX++) \ - { \ - HASH = (HASH << 4) ^ (HASH >> 28) ^ CLASS_NAME[INDEX]; \ - } \ - \ - HASH = (HASH ^ (HASH >> 10) ^ (HASH >> 20)) & CLASS_TABLE_MASK; - -/* Setup the table. */ -static void -class_table_setup (void) -{ - /* Start - nothing in the table. */ - memset (class_table_array, 0, sizeof (class_node_ptr) * CLASS_TABLE_SIZE); - - /* The table writing mutex. */ - __class_table_lock = objc_mutex_allocate (); -} +/* The table of classname->class. Used for objc_lookup_class and friends */ +static cache_ptr __objc_class_hash = 0; /* !T:MUTEX */ +/* This is a hook which is called by objc_get_class and + objc_lookup_class if the runtime is not able to find the class. + This may e.g. try to load in the class using dynamic loading */ +Class (*_objc_lookup_class)(const char* name) = 0; /* !T:SAFE */ -/* Insert a class in the table (used when a new class is registered). */ -static void -class_table_insert (const char *class_name, Class class_pointer) -{ - int hash, length; - class_node_ptr new_node; - - /* Find out the class name's hash and length. */ - CLASS_TABLE_HASH (length, hash, class_name); - - /* Prepare the new node holding the class. */ - new_node = objc_malloc (sizeof (struct class_node)); - new_node->name = class_name; - new_node->length = length; - new_node->pointer = class_pointer; - - /* Lock the table for modifications. */ - objc_mutex_lock (__class_table_lock); - - /* Insert the new node in the table at the beginning of the table at - class_table_array[hash]. */ - new_node->next = class_table_array[hash]; - class_table_array[hash] = new_node; - - 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. */ -static inline Class -class_table_get_safe (const char *class_name) -{ - class_node_ptr node; - int length, hash; - - /* Compute length and hash. */ - CLASS_TABLE_HASH (length, hash, class_name); - - node = class_table_array[hash]; - - if (node != NULL) - { - do - { - if (node->length == length) - { - /* Compare the class names. */ - int i; - - for (i = 0; i < length; i++) - { - if ((node->name)[i] != class_name[i]) - { - break; - } - } - - if (i == length) - { - /* They are equal! */ - return node->pointer; - } - } - } - while ((node = node->next) != NULL); - } - - return Nil; -} - -/* Enumerate over the class table. */ -struct class_table_enumerator -{ - int hash; - class_node_ptr node; -}; - - -static Class -class_table_next (struct class_table_enumerator **e) -{ - struct class_table_enumerator *enumerator = *e; - class_node_ptr next; - - if (enumerator == NULL) - { - *e = objc_malloc (sizeof (struct class_table_enumerator)); - enumerator = *e; - enumerator->hash = 0; - enumerator->node = NULL; +/* True when class links has been resolved */ +BOOL __objc_class_links_resolved = NO; /* !T:UNUSED */ - next = class_table_array[enumerator->hash]; - } - else - { - next = enumerator->node->next; - } - - if (next != NULL) - { - enumerator->node = next; - return enumerator->node->pointer; - } - else - { - enumerator->hash++; - - while (enumerator->hash < CLASS_TABLE_SIZE) - { - next = class_table_array[enumerator->hash]; - if (next != NULL) - { - enumerator->node = next; - return enumerator->node->pointer; - } - enumerator->hash++; - } - - /* Ok - table finished - done. */ - objc_free (enumerator); - return Nil; - } -} -#if 0 /* DEBUGGING FUNCTIONS */ -/* Debugging function - print the class table. */ -void -class_table_print (void) -{ - int i; - - for (i = 0; i < CLASS_TABLE_SIZE; i++) - { - class_node_ptr node; - - printf ("%d:\n", i); - node = class_table_array[i]; - - while (node != NULL) - { - printf ("\t%s\n", node->name); - node = node->next; - } - } -} +/* Initial number of buckets size of class hash table. */ +#define CLASS_HASH_SIZE 32 -/* Debugging function - print an histogram of number of classes in - function of hash key values. Useful to evaluate the hash function - in real cases. */ -void -class_table_print_histogram (void) +void __objc_init_class_tables() { - int i, j; - int counter = 0; - - for (i = 0; i < CLASS_TABLE_SIZE; i++) - { - class_node_ptr node; - - node = class_table_array[i]; - - while (node != NULL) - { - counter++; - node = node->next; - } - if (((i + 1) % 50) == 0) - { - printf ("%4d:", i + 1); - for (j = 0; j < counter; j++) - { - printf ("X"); - } - printf ("\n"); - counter = 0; - } - } - printf ("%4d:", i + 1); - for (j = 0; j < counter; j++) - { - printf ("X"); - } - printf ("\n"); -} -#endif /* DEBUGGING FUNCTIONS */ - -/** - ** Objective-C runtime functions - **/ - -/* From now on, the only access to the class table data structure - should be via the class_table_* functions. */ + /* Allocate the class hash table */ -/* This is a hook which is called by objc_get_class and - objc_lookup_class if the runtime is not able to find the class. - This may e.g. try to load in the class using dynamic loading. */ -Class (*_objc_lookup_class) (const char *name) = 0; /* !T:SAFE */ - - -/* True when class links has been resolved. */ -BOOL __objc_class_links_resolved = NO; /* !T:UNUSED */ + if(__objc_class_hash) + return; + objc_mutex_lock(__objc_runtime_mutex); -void -__objc_init_class_tables (void) -{ - /* Allocate the class hash table. */ - - if (__class_table_lock) - return; - - objc_mutex_lock (__objc_runtime_mutex); - - class_table_setup (); + __objc_class_hash + = hash_new (CLASS_HASH_SIZE, + (hash_func_type) hash_string, + (compare_func_type) compare_strings); - objc_mutex_unlock (__objc_runtime_mutex); + objc_mutex_unlock(__objc_runtime_mutex); } -/* This function adds a class to the class hash table, and assigns the - class a number, unless it's already known. */ +/* This function adds a class to the class hash table, and assigns the + class a number, unless it's already known */ void -__objc_add_class_to_hash (Class class) +__objc_add_class_to_hash(Class class) { Class h_class; - objc_mutex_lock (__objc_runtime_mutex); + objc_mutex_lock(__objc_runtime_mutex); - /* Make sure the table is there. */ - assert (__class_table_lock); + /* make sure the table is there */ + assert(__objc_class_hash); - /* Make sure it's not a meta class. */ - assert (CLS_ISCLASS (class)); + /* make sure it's not a meta class */ + assert(CLS_ISCLASS(class)); /* Check to see if the class is already in the hash table. */ - h_class = class_table_get_safe (class->name); - if (! h_class) + h_class = hash_value_for_key (__objc_class_hash, class->name); + if (!h_class) { /* The class isn't in the hash table. Add the class and assign a class number. */ static unsigned int class_number = 1; - CLS_SETNUMBER (class, class_number); - CLS_SETNUMBER (class->class_pointer, class_number); + CLS_SETNUMBER(class, class_number); + CLS_SETNUMBER(class->class_pointer, class_number); ++class_number; - class_table_insert (class->name, class); + hash_add (&__objc_class_hash, class->name, class); } - objc_mutex_unlock (__objc_runtime_mutex); + objc_mutex_unlock(__objc_runtime_mutex); } /* 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) + this fails, nil is returned */ +Class objc_lookup_class (const char* name) { Class class; - class = class_table_get_safe (name); + objc_mutex_lock(__objc_runtime_mutex); + + /* Make sure the class hash table exists. */ + assert (__objc_class_hash); + + class = hash_value_for_key (__objc_class_hash, name); + + objc_mutex_unlock(__objc_runtime_mutex); if (class) return class; if (_objc_lookup_class) - return (*_objc_lookup_class) (name); + return (*_objc_lookup_class)(name); else return 0; } /* 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, an error message is issued and the system aborts. */ + this fails, an error message is issued and the system aborts */ Class objc_get_class (const char *name) { Class class; - class = class_table_get_safe (name); + objc_mutex_lock(__objc_runtime_mutex); + + /* Make sure the class hash table exists. */ + assert (__objc_class_hash); + + class = hash_value_for_key (__objc_class_hash, name); + + objc_mutex_unlock(__objc_runtime_mutex); if (class) return class; if (_objc_lookup_class) - class = (*_objc_lookup_class) (name); + class = (*_objc_lookup_class)(name); - if (class) + if(class) return class; - objc_error (nil, OBJC_ERR_BAD_CLASS, - "objc runtime: cannot find class %s\n", name); + objc_error(nil, OBJC_ERR_BAD_CLASS, + "objc runtime: cannot find class %s\n", name); return 0; } MetaClass -objc_get_meta_class (const char *name) +objc_get_meta_class(const char *name) { - return objc_get_class (name)->class_pointer; + return objc_get_class(name)->class_pointer; } /* This function provides a way to enumerate all the classes in the @@ -519,57 +160,58 @@ objc_get_meta_class (const char *name) For example: id class; void *es = NULL; - while ((class = objc_next_class (&es))) + while ((class = objc_next_class(&es))) ... do something with class; */ Class -objc_next_class (void **enum_state) +objc_next_class(void **enum_state) { - Class class; + objc_mutex_lock(__objc_runtime_mutex); - objc_mutex_lock (__objc_runtime_mutex); - - /* Make sure the table is there. */ - assert (__class_table_lock); + /* make sure the table is there */ + assert(__objc_class_hash); - class = class_table_next ((struct class_table_enumerator **) enum_state); + *(node_ptr*)enum_state = + hash_next(__objc_class_hash, *(node_ptr*)enum_state); - objc_mutex_unlock (__objc_runtime_mutex); - - return class; + objc_mutex_unlock(__objc_runtime_mutex); + + if (*(node_ptr*)enum_state) + return (*(node_ptr*)enum_state)->value; + return (Class)0; } -/* Resolve super/subclass links for all classes. The only thing we - can be sure of is that the class_pointer for class objects point to - the right meta class objects. */ -void -__objc_resolve_class_links (void) +/* Resolve super/subclass links for all classes. The only thing we + can be sure of is that the class_pointer for class objects point + to the right meta class objects */ +void __objc_resolve_class_links() { - struct class_table_enumerator *es = NULL; + node_ptr node; Class object_class = objc_get_class ("Object"); - Class class1; - assert (object_class); + assert(object_class); - objc_mutex_lock (__objc_runtime_mutex); + objc_mutex_lock(__objc_runtime_mutex); - /* Assign subclass links. */ - while ((class1 = class_table_next (&es))) + /* Assign subclass links */ + for (node = hash_next (__objc_class_hash, NULL); node; + node = hash_next (__objc_class_hash, node)) { + Class class1 = node->value; + /* Make sure we have what we think we have. */ - assert (CLS_ISCLASS (class1)); - assert (CLS_ISMETA (class1->class_pointer)); + assert (CLS_ISCLASS(class1)); + assert (CLS_ISMETA(class1->class_pointer)); - /* The class_pointer of all meta classes point to Object's meta - class. */ + /* The class_pointer of all meta classes point to Object's meta class. */ class1->class_pointer->class_pointer = object_class->class_pointer; - if (! CLS_ISRESOLV (class1)) + if (!(CLS_ISRESOLV(class1))) { - CLS_SETRESOLV (class1); - CLS_SETRESOLV (class1->class_pointer); + CLS_SETRESOLV(class1); + CLS_SETRESOLV(class1->class_pointer); - if (class1->super_class) + if(class1->super_class) { Class a_super_class = objc_get_class ((char *) class1->super_class); @@ -579,11 +221,11 @@ __objc_resolve_class_links (void) DEBUG_PRINTF ("making class connections for: %s\n", class1->name); - /* Assign subclass links for superclass. */ + /* assign subclass links for superclass */ class1->sibling_class = a_super_class->subclass_list; a_super_class->subclass_list = class1; - /* Assign subclass links for meta class of superclass. */ + /* Assign subclass links for meta class of superclass */ if (a_super_class->class_pointer) { class1->class_pointer->sibling_class @@ -592,8 +234,8 @@ __objc_resolve_class_links (void) = class1->class_pointer; } } - else /* A root class, make its meta object be a subclass of - Object. */ + else /* a root class, make its meta object */ + /* be a subclass of Object */ { class1->class_pointer->sibling_class = object_class->subclass_list; @@ -602,21 +244,22 @@ __objc_resolve_class_links (void) } } - /* Assign superclass links. */ - es = NULL; - while ((class1 = class_table_next (&es))) + /* Assign superclass links */ + for (node = hash_next (__objc_class_hash, NULL); node; + node = hash_next (__objc_class_hash, node)) { + Class class1 = node->value; Class sub_class; for (sub_class = class1->subclass_list; sub_class; sub_class = sub_class->sibling_class) { sub_class->super_class = class1; - if (CLS_ISCLASS (sub_class)) + if(CLS_ISCLASS(sub_class)) sub_class->class_pointer->super_class = class1->class_pointer; } } - objc_mutex_unlock (__objc_runtime_mutex); + objc_mutex_unlock(__objc_runtime_mutex); } @@ -626,10 +269,13 @@ __objc_resolve_class_links (void) Class class_pose_as (Class impostor, Class super_class) { - if (! CLS_ISRESOLV (impostor)) + node_ptr node; + Class class1; + + if (!CLS_ISRESOLV (impostor)) __objc_resolve_class_links (); - /* Preconditions */ + /* preconditions */ assert (impostor); assert (super_class); assert (impostor->super_class == super_class); @@ -640,64 +286,73 @@ class_pose_as (Class impostor, Class super_class) { Class *subclass = &(super_class->subclass_list); - /* Move subclasses of super_class to impostor. */ + /* 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; + 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. */ + /* 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. */ + /* 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. */ + /* 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. */ + /* 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); + objc_mutex_lock(__objc_runtime_mutex); - class_table_replace (super_class, impostor); + for (node = hash_next (__objc_class_hash, NULL); node; + node = hash_next (__objc_class_hash, node)) + { + class1 = (Class)node->value; + if (class1 == super_class) + { + node->value = impostor; /* change hash table value */ + } + } - objc_mutex_unlock (__objc_runtime_mutex); + objc_mutex_unlock(__objc_runtime_mutex); - /* Next, we update the dispatch tables... */ + /* 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/gnu/lib/libobjc/libobjc/configure.in b/gnu/lib/libobjc/libobjc/configure.in index ac92c423450..821dcd2a9de 100644 --- a/gnu/lib/libobjc/libobjc/configure.in +++ b/gnu/lib/libobjc/libobjc/configure.in @@ -1,6 +1,5 @@ # Process this file with autoconf to produce a configure script. -# Copyright (C) 1995, 1997, 1998, 1999, 2002, 2003 -# Free Software Foundation, Inc. +# Copyright (C) 1995, 1997, 1998, 1999 Free Software Foundation, Inc. # Contributed by Dave Love (d.love@dl.ac.uk). # #This file is part of GNU Objective C. @@ -22,22 +21,20 @@ AC_PREREQ(2.13) AC_INIT(objc/objc.h) -AC_CONFIG_HEADER(config.h) +#AC_CONFIG_HEADER(config.h) -# This works around the fact that libtool configuration may change LD -# for this particular configuration, but some shells, instead of -# keeping the changes in LD private, export them just because LD is -# exported. -ORIGINAL_LD_FOR_MULTILIBS=$LD - -GLIBCPP_TOPREL_CONFIGURE - -AC_CANONICAL_SYSTEM -target_alias=${target_alias-$target} -AC_SUBST(target_alias) - -GLIBCPP_CONFIGURE(.) -GLIBCPP_EXPORT_INSTALL_INFO +if test "${srcdir}" = "." ; then + if test "${with_target_subdir}" != "." ; then + topsrcdir=${with_multisrctop}../.. + else + topsrcdir=${with_multisrctop}.. + fi +else + topsrcdir=${srcdir}/.. +fi +dnl This is needed for a multilibbed build in the source tree so +dnl that install-sh and config.sub get found. +AC_CONFIG_AUX_DIR($topsrcdir) # If the language specific compiler does not exist, but the "gcc" directory # does, we do not build anything. Note, $r is set by the top-level Makefile. @@ -68,16 +65,10 @@ then fi dnl Checks for programs. +# For ObjC we'll set CC to point at the built gcc, but this will get it into +# the makefiles +AC_PROG_CC -# Disable shared libs by default -AC_DISABLE_SHARED -# Enable Win32 DLL on MS Windows - FIXME -AC_LIBTOOL_WIN32_DLL - -AC_PROG_LIBTOOL - -dnl These should be inherited in the recursive make, but ensure they are -dnl defined: test "$AR" || AR=ar AC_SUBST(AR) if test "$RANLIB"; then : @@ -86,7 +77,8 @@ else AC_PROG_RANLIB fi AC_PROG_INSTALL -AC_PROG_MAKE_SET + +dnl Checks for libraries. dnl Checks for header files. # Sanity check for the cross-compilation case: @@ -99,19 +91,17 @@ the Objective C runtime system. If necessary, install gcc now with AC_HEADER_STDC -AC_CHECK_HEADERS(sched.h) +# Determine the name of the GCC thread file. -# Determine CFLAGS for gthread. - -AC_CACHE_CHECK([for gthread cflags],objc_cv_gthread_flags, +AC_CACHE_CHECK([for thread file],objc_cv_thread_file, [if test -f "$r"/gcc/Makefile then - objc_cv_gthread_flags=`grep \^GTHREAD_FLAGS "$r"/gcc/Makefile | awk -F= '{ print $2 }'` + objc_cv_thread_file=`grep \^GCC_THREAD_FILE "$r"/gcc/Makefile | awk -F= '{ print $2 }'` else AC_MSG_ERROR([not found]) fi]) -GTHREAD_FLAGS=$objc_cv_gthread_flags -AC_SUBST(GTHREAD_FLAGS) +OBJC_THREAD_FILE=$objc_cv_thread_file +AC_SUBST(OBJC_THREAD_FILE) AC_ARG_ENABLE(objc-gc, [ --enable-objc-gc enable the use of Boehm's garbage collector with @@ -119,7 +109,7 @@ AC_ARG_ENABLE(objc-gc, if [[[ x$enable_objc_gc = xno ]]]; then OBJC_BOEHM_GC='' else - OBJC_BOEHM_GC=libobjc_gc.la + OBJC_BOEHM_GC=libobjc_gc.a fi, OBJC_BOEHM_GC='') AC_SUBST(OBJC_BOEHM_GC) @@ -127,13 +117,12 @@ AC_SUBST(OBJC_BOEHM_GC) # We need multilib support, but only if configuring for the target. AC_OUTPUT(Makefile, - [test -z "$CONFIG_HEADERS" || echo timestamp > stamp-h +[test -z "$CONFIG_HEADERS" || echo timestamp > stamp-h if test -n "$CONFIG_FILES"; then if test -n "${with_target_subdir}"; then # FIXME: We shouldn't need to set ac_file ac_file=Makefile - LD="${ORIGINAL_LD_FOR_MULTILIBS}" - . ${toplevel_srcdir}/config-ml.in + . ${topsrcdir}/config-ml.in fi fi], srcdir=${srcdir} @@ -142,12 +131,10 @@ target=${target} with_target_subdir=${with_target_subdir} with_multisubdir=${with_multisubdir} ac_configure_args="--enable-multilib ${ac_configure_args}" -toplevel_srcdir=${toplevel_srcdir} CONFIG_SHELL=${CONFIG_SHELL-/bin/sh} -ORIGINAL_LD_FOR_MULTILIBS="${ORIGINAL_LD_FOR_MULTILIBS}" +topsrcdir=${topsrcdir} ) - dnl Local Variables: dnl comment-start: "dnl " dnl comment-end: "" diff --git a/gnu/lib/libobjc/libobjc/encoding.c b/gnu/lib/libobjc/libobjc/encoding.c index be4c08b423e..4749ba026e9 100644 --- a/gnu/lib/libobjc/libobjc/encoding.c +++ b/gnu/lib/libobjc/libobjc/encoding.c @@ -1,6 +1,5 @@ /* Encoding of types for Objective C. - Copyright (C) 1993, 1995, 1996, 1997, 1998, 2000, 2002 - Free Software Foundation, Inc. + Copyright (C) 1993, 1995, 1996, 1997, 1998 Free Software Foundation, Inc. Contributed by Kresten Krab Thorup Bitfield support by Ovidiu Predescu @@ -30,66 +29,57 @@ Boston, MA 02111-1307, USA. */ #include "tconfig.h" #include "objc-api.h" #include "encoding.h" -#include <stdlib.h> -#undef MAX #define MAX(X, Y) \ - ({ typeof (X) __x = (X), __y = (Y); \ + ({ typeof(X) __x = (X), __y = (Y); \ (__x > __y ? __x : __y); }) -#undef MIN #define MIN(X, Y) \ - ({ typeof (X) __x = (X), __y = (Y); \ + ({ typeof(X) __x = (X), __y = (Y); \ (__x < __y ? __x : __y); }) -#undef ROUND #define ROUND(V, A) \ - ({ typeof (V) __v = (V); typeof (A) __a = (A); \ - __a * ((__v+__a - 1)/__a); }) + ({ typeof(V) __v=(V); typeof(A) __a=(A); \ + __a*((__v+__a-1)/__a); }) /* Various hacks for objc_layout_record. These are used by the target macros. */ -#define TREE_CODE(TYPE) *(TYPE) -#define TREE_TYPE(TREE) (TREE) +#define TREE_CODE(TYPE) *TYPE +#define TREE_TYPE(TREE) TREE #define RECORD_TYPE _C_STRUCT_B #define UNION_TYPE _C_UNION_B #define QUAL_UNION_TYPE _C_UNION_B #define ARRAY_TYPE _C_ARY_B -#define REAL_TYPE _C_DBL - -#define VECTOR_TYPE _C_VECTOR - #define TYPE_FIELDS(TYPE) objc_skip_typespec (TYPE) -#define DECL_MODE(TYPE) *(TYPE) -#define TYPE_MODE(TYPE) *(TYPE) +#define DECL_MODE(TYPE) *(TYPE) #define DFmode _C_DBL #define get_inner_array_type(TYPE) ((TYPE) + 1) -/* Some ports (eg ARM) allow the structure size boundary to be - selected at compile-time. We override the normal definition with - one that has a constant value for this compilation. */ -#undef STRUCTURE_SIZE_BOUNDARY -#define STRUCTURE_SIZE_BOUNDARY (BITS_PER_UNIT * sizeof (struct{char a;})) -/* Some ROUND_TYPE_ALIGN macros use TARGET_foo, and consequently - target_flags. Define a dummy entry here to so we don't die. */ -/* ??? FIXME: As of 2002-06-21, the attribute `unused' doesn't seem to - eliminate the warning. */ -static int __attribute__ ((__unused__)) target_flags = 0; +static inline int +atoi (const char* str) +{ + int res = 0; + + while (isdigit (*str)) + res *= 10, res += (*str++ - '0'); + + return res; +} /* - return the size of an object specified by type + return the size of an object specified by type */ int -objc_sizeof_type (const char *type) +objc_sizeof_type (const char* type) { /* Skip the variable name if any */ if (*type == '"') @@ -98,85 +88,83 @@ objc_sizeof_type (const char *type) /* do nothing */; } - switch (*type) { + switch(*type) { case _C_ID: - return sizeof (id); + return sizeof(id); break; case _C_CLASS: - return sizeof (Class); + return sizeof(Class); break; case _C_SEL: - return sizeof (SEL); + return sizeof(SEL); break; case _C_CHR: - return sizeof (char); + return sizeof(char); break; - + case _C_UCHR: - return sizeof (unsigned char); + return sizeof(unsigned char); break; case _C_SHT: - return sizeof (short); + return sizeof(short); break; case _C_USHT: - return sizeof (unsigned short); + return sizeof(unsigned short); break; case _C_INT: - return sizeof (int); + return sizeof(int); break; case _C_UINT: - return sizeof (unsigned int); + return sizeof(unsigned int); break; case _C_LNG: - return sizeof (long); + return sizeof(long); break; case _C_ULNG: - return sizeof (unsigned long); + return sizeof(unsigned long); break; case _C_LNG_LNG: - return sizeof (long long); + return sizeof(long long); break; case _C_ULNG_LNG: - return sizeof (unsigned long long); + return sizeof(unsigned long long); break; case _C_FLT: - return sizeof (float); + return sizeof(float); break; case _C_DBL: - return sizeof (double); + return sizeof(double); break; case _C_VOID: - return sizeof (void); + return sizeof(void); break; - case _C_PTR: case _C_ATOM: case _C_CHARPTR: - return sizeof (char *); + return sizeof(char*); break; case _C_ARY_B: { - int len = atoi (type + 1); - while (isdigit ((unsigned char)*++type)) - ; - return len * objc_aligned_size (type); + int len = atoi(type+1); + while (isdigit(*++type)); + return len*objc_aligned_size (type); } - break; + break; case _C_BFLD: { @@ -185,8 +173,7 @@ objc_sizeof_type (const char *type) int startByte, endByte; position = atoi (type + 1); - while (isdigit ((unsigned char)*++type)) - ; + while (isdigit (*++type)); size = atoi (type + 1); startByte = position / BITS_PER_UNIT; @@ -210,8 +197,7 @@ objc_sizeof_type (const char *type) case _C_UNION_B: { int max_size = 0; - while (*type != _C_UNION_E && *type++ != '=') - /* do nothing */; + while (*type != _C_UNION_E && *type++ != '=') /* do nothing */; while (*type != _C_UNION_E) { /* Skip the variable name if any */ @@ -225,10 +211,10 @@ objc_sizeof_type (const char *type) } return max_size; } - + default: { - objc_error (nil, OBJC_ERR_BAD_TYPE, "unknown type %s\n", type); + objc_error(nil, OBJC_ERR_BAD_TYPE, "unknown type %s\n", type); return 0; } } @@ -236,11 +222,11 @@ objc_sizeof_type (const char *type) /* - Return the alignment of an object specified by type + Return the alignment of an object specified by type */ int -objc_alignof_type (const char *type) +objc_alignof_type(const char* type) { /* Skip the variable name if any */ if (*type == '"') @@ -248,76 +234,75 @@ objc_alignof_type (const char *type) for (type++; *type++ != '"';) /* do nothing */; } - switch (*type) { + switch(*type) { case _C_ID: - return __alignof__ (id); + return __alignof__(id); break; case _C_CLASS: - return __alignof__ (Class); + return __alignof__(Class); break; - + case _C_SEL: - return __alignof__ (SEL); + return __alignof__(SEL); break; case _C_CHR: - return __alignof__ (char); + return __alignof__(char); break; - + case _C_UCHR: - return __alignof__ (unsigned char); + return __alignof__(unsigned char); break; case _C_SHT: - return __alignof__ (short); + return __alignof__(short); break; case _C_USHT: - return __alignof__ (unsigned short); + return __alignof__(unsigned short); break; case _C_INT: - return __alignof__ (int); + return __alignof__(int); break; case _C_UINT: - return __alignof__ (unsigned int); + return __alignof__(unsigned int); break; case _C_LNG: - return __alignof__ (long); + return __alignof__(long); break; case _C_ULNG: - return __alignof__ (unsigned long); + return __alignof__(unsigned long); break; case _C_LNG_LNG: - return __alignof__ (long long); + return __alignof__(long long); break; case _C_ULNG_LNG: - return __alignof__ (unsigned long long); + return __alignof__(unsigned long long); break; case _C_FLT: - return __alignof__ (float); + return __alignof__(float); break; case _C_DBL: - return __alignof__ (double); + return __alignof__(double); break; case _C_PTR: case _C_ATOM: case _C_CHARPTR: - return __alignof__ (char *); + return __alignof__(char*); break; case _C_ARY_B: - while (isdigit ((unsigned char)*++type)) - /* do nothing */; + while (isdigit(*++type)) /* do nothing */; return objc_alignof_type (type); case _C_STRUCT_B: @@ -336,8 +321,7 @@ objc_alignof_type (const char *type) case _C_UNION_B: { int maxalign = 0; - while (*type != _C_UNION_E && *type++ != '=') - /* do nothing */; + while (*type != _C_UNION_E && *type++ != '=') /* do nothing */; while (*type != _C_UNION_E) { /* Skip the variable name if any */ @@ -354,7 +338,7 @@ objc_alignof_type (const char *type) default: { - objc_error (nil, OBJC_ERR_BAD_TYPE, "unknown type %s\n", type); + objc_error(nil, OBJC_ERR_BAD_TYPE, "unknown type %s\n", type); return 0; } } @@ -365,7 +349,7 @@ objc_alignof_type (const char *type) */ int -objc_aligned_size (const char *type) +objc_aligned_size (const char* type) { int size, align; @@ -384,11 +368,11 @@ objc_aligned_size (const char *type) /* The size rounded up to the nearest integral of the wordsize, taken - to be the size of a void *. + to be the size of a void*. */ -int -objc_promoted_size (const char *type) +int +objc_promoted_size (const char* type) { int size, wordsize; @@ -400,7 +384,7 @@ objc_promoted_size (const char *type) } size = objc_sizeof_type (type); - wordsize = sizeof (void *); + wordsize = sizeof (void*); return ROUND (size, wordsize); } @@ -410,13 +394,13 @@ objc_promoted_size (const char *type) occurring in method prototype encodings. */ -inline const char * -objc_skip_type_qualifiers (const char *type) +inline const char* +objc_skip_type_qualifiers (const char* type) { while (*type == _C_CONST - || *type == _C_IN + || *type == _C_IN || *type == _C_INOUT - || *type == _C_OUT + || *type == _C_OUT || *type == _C_BYCOPY || *type == _C_BYREF || *type == _C_ONEWAY @@ -427,14 +411,14 @@ objc_skip_type_qualifiers (const char *type) return type; } - + /* Skip one typespec element. If the typespec is prepended by type qualifiers, these are skipped as well. */ -const char * -objc_skip_typespec (const char *type) +const char* +objc_skip_typespec (const char* type) { /* Skip the variable name if any */ if (*type == '"') @@ -444,7 +428,7 @@ objc_skip_typespec (const char *type) } type = objc_skip_type_qualifiers (type); - + switch (*type) { case _C_ID: @@ -455,8 +439,7 @@ objc_skip_typespec (const char *type) return type; else { - while (*++type != '"') - /* do nothing */; + while (*++type != '"') /* do nothing */; return type + 1; } @@ -484,56 +467,45 @@ objc_skip_typespec (const char *type) case _C_ARY_B: /* skip digits, typespec and closing ']' */ - - while (isdigit ((unsigned char)*++type)) - ; - type = objc_skip_typespec (type); + + while(isdigit(*++type)); + type = objc_skip_typespec(type); if (*type == _C_ARY_E) return ++type; else { - objc_error (nil, OBJC_ERR_BAD_TYPE, "bad array type %s\n", type); + objc_error(nil, OBJC_ERR_BAD_TYPE, "bad array type %s\n", type); return 0; } case _C_BFLD: /* The new encoding of bitfields is: b 'position' 'type' 'size' */ - while (isdigit ((unsigned char)*++type)) - ; /* skip position */ - while (isdigit ((unsigned char)*++type)) - ; /* skip type and size */ + while (isdigit (*++type)); /* skip position */ + while (isdigit (*++type)); /* skip type and size */ return type; case _C_STRUCT_B: /* skip name, and elements until closing '}' */ - - while (*type != _C_STRUCT_E && *type++ != '=') - ; - while (*type != _C_STRUCT_E) - { - type = objc_skip_typespec (type); - } + + while (*type != _C_STRUCT_E && *type++ != '='); + while (*type != _C_STRUCT_E) { type = objc_skip_typespec (type); } return ++type; case _C_UNION_B: /* skip name, and elements until closing ')' */ - - while (*type != _C_UNION_E && *type++ != '=') - ; - while (*type != _C_UNION_E) - { - type = objc_skip_typespec (type); - } + + while (*type != _C_UNION_E && *type++ != '='); + while (*type != _C_UNION_E) { type = objc_skip_typespec (type); } return ++type; case _C_PTR: /* Just skip the following typespec */ - + return objc_skip_typespec (++type); - + default: { - objc_error (nil, OBJC_ERR_BAD_TYPE, "unknown type %s\n", type); + objc_error(nil, OBJC_ERR_BAD_TYPE, "unknown type %s\n", type); return 0; } } @@ -543,21 +515,19 @@ objc_skip_typespec (const char *type) Skip an offset as part of a method encoding. This is prepended by a '+' if the argument is passed in registers. */ -inline const char * -objc_skip_offset (const char *type) +inline const char* +objc_skip_offset (const char* type) { - if (*type == '+') - type++; - while (isdigit ((unsigned char) *++type)) - ; + if (*type == '+') type++; + while(isdigit(*++type)); return type; } /* Skip an argument specification of a method encoding. */ -const char * -objc_skip_argspec (const char *type) +const char* +objc_skip_argspec (const char* type) { type = objc_skip_typespec (type); type = objc_skip_offset (type); @@ -567,13 +537,13 @@ objc_skip_argspec (const char *type) /* Return the number of arguments that the method MTH expects. Note that all methods need two implicit arguments `self' and - `_cmd'. + `_cmd'. */ int -method_get_number_of_arguments (struct objc_method *mth) +method_get_number_of_arguments (struct objc_method* mth) { int i = 0; - const char *type = mth->method_types; + const char* type = mth->method_types; while (*type) { type = objc_skip_argspec (type); @@ -589,9 +559,9 @@ method_get_number_of_arguments (struct objc_method *mth) */ int -method_get_sizeof_arguments (struct objc_method *mth) +method_get_sizeof_arguments (struct objc_method* mth) { - const char *type = objc_skip_typespec (mth->method_types); + const char* type = objc_skip_typespec (mth->method_types); return atoi (type); } @@ -600,7 +570,7 @@ method_get_sizeof_arguments (struct objc_method *mth) the last argument. Typical use of this look like: { - char *datum, *type; + char *datum, *type; for (datum = method_get_first_argument (method, argframe, &type); datum; datum = method_get_next_argument (argframe, &type)) { @@ -611,14 +581,15 @@ method_get_sizeof_arguments (struct objc_method *mth) else { if ((flags & _F_IN) == _F_IN) - [portal encodeData: *(char **) datum ofType: ++type]; + [portal encodeData: *(char**)datum ofType: ++type]; } } } -*/ +*/ -char * -method_get_next_argument (arglist_t argframe, const char **type) +char* +method_get_next_argument (arglist_t argframe, + const char **type) { const char *t = objc_skip_argspec (*type); @@ -635,15 +606,15 @@ method_get_next_argument (arglist_t argframe, const char **type) } /* - Return a pointer to the value of the first argument of the method + 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 + 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) +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); @@ -652,22 +623,22 @@ method_get_first_argument (struct objc_method *m, /* 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 + is returned in the value-result argument TYPE */ -char * -method_get_nth_argument (struct objc_method *m, - arglist_t argframe, int arg, +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); + 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); @@ -678,7 +649,7 @@ method_get_nth_argument (struct objc_method *m, } unsigned -objc_get_type_qualifiers (const char *type) +objc_get_type_qualifiers (const char* type) { unsigned res = 0; BOOL flag = YES; @@ -731,7 +702,7 @@ objc_layout_structure (const char *type, if (*type++ != _C_STRUCT_B) { - objc_error (nil, OBJC_ERR_BAD_TYPE, + objc_error(nil, OBJC_ERR_BAD_TYPE, "record type expected in objc_layout_structure, got %s\n", type); } @@ -753,22 +724,34 @@ objc_layout_structure (const char *type, layout->record_size = 0; layout->record_align = BITS_PER_UNIT; +#ifdef STRUCTURE_SIZE_BOUNDARY layout->record_align = MAX (layout->record_align, STRUCTURE_SIZE_BOUNDARY); +#endif } BOOL objc_layout_structure_next_member (struct objc_struct_layout *layout) { + register int known_align = layout->record_size; register int desired_align = 0; /* The following are used only if the field is a bitfield */ - register const char *bfld_type = 0; - register int bfld_type_size, bfld_type_align = 0, bfld_field_size = 0; + register const char *bfld_type; + register int bfld_type_size, bfld_type_align, bfld_field_size; /* The current type without the type qualifiers */ const char *type; +#if 1 + if (layout->prev_type == NULL) + { + layout->prev_type = layout->type; + layout->type = objc_skip_typespec (layout->prev_type); + return YES; + } +#endif + /* Add the size of the previous field to the size of the record. */ if (layout->prev_type) { @@ -777,9 +760,10 @@ objc_layout_structure_next_member (struct objc_struct_layout *layout) if (*type != _C_BFLD) layout->record_size += objc_sizeof_type (type) * BITS_PER_UNIT; else { + desired_align = 1; /* Get the bitfield's type */ for (bfld_type = type + 1; - isdigit ((unsigned char)*bfld_type); + isdigit(*bfld_type); bfld_type++) /* do nothing */; @@ -803,14 +787,12 @@ objc_layout_structure_next_member (struct objc_struct_layout *layout) type = objc_skip_type_qualifiers (layout->type); if (*type != _C_BFLD) - desired_align = objc_alignof_type (type) * BITS_PER_UNIT; + desired_align = objc_alignof_type(type) * BITS_PER_UNIT; else { desired_align = 1; /* Skip the bitfield's offset */ - for (bfld_type = type + 1; - isdigit ((unsigned char) *bfld_type); - bfld_type++) + for (bfld_type = type + 1; isdigit(*bfld_type); bfld_type++) /* do nothing */; bfld_type_size = objc_sizeof_type (bfld_type) * BITS_PER_UNIT; @@ -830,7 +812,7 @@ objc_layout_structure_next_member (struct objc_struct_layout *layout) is meaningless. */ #ifndef PCC_BITFIELD_TYPE_MATTERS layout->record_align = MAX (layout->record_align, desired_align); -#else /* PCC_BITFIELD_TYPE_MATTERS */ +#else if (*type == _C_BFLD) { /* For these machines, a zero-length field does not @@ -862,7 +844,7 @@ objc_layout_structure_next_member (struct objc_struct_layout *layout) } else layout->record_align = MAX (layout->record_align, desired_align); -#endif /* PCC_BITFIELD_TYPE_MATTERS */ +#endif /* Does this field automatically have alignment it needs by virtue of the fields that precede it and the record's @@ -876,7 +858,7 @@ objc_layout_structure_next_member (struct objc_struct_layout *layout) Bump the cumulative size to multiple of field alignment. */ layout->record_size = ROUND (layout->record_size, desired_align); } - + /* Jump to the next field in record. */ layout->prev_type = layout->type; @@ -896,7 +878,7 @@ void objc_layout_finish_structure (struct objc_struct_layout *layout, in the record type. Round it up to a multiple of the record's alignment. */ -#if defined (ROUND_TYPE_ALIGN) && ! defined (__sparc__) +#ifdef ROUND_TYPE_ALIGN layout->record_align = ROUND_TYPE_ALIGN (layout->original_type, 1, layout->record_align); diff --git a/gnu/lib/libobjc/libobjc/gc.c b/gnu/lib/libobjc/libobjc/gc.c index 1010508f64c..8ca6de8e946 100644 --- a/gnu/lib/libobjc/libobjc/gc.c +++ b/gnu/lib/libobjc/libobjc/gc.c @@ -1,5 +1,5 @@ /* Basic data types for Objective C. - Copyright (C) 1998, 2002 Free Software Foundation, Inc. + Copyright (C) 1998 Free Software Foundation, Inc. Contributed by Ovidiu Predescu. This file is part of GNU CC. @@ -58,11 +58,11 @@ typedef GC_signed_word signed_word; The offset is incremented with the size of the type. */ #define ROUND(V, A) \ - ({ typeof (V) __v = (V); typeof (A) __a = (A); \ - __a * ((__v+__a - 1)/__a); }) + ({ typeof(V) __v=(V); typeof(A) __a=(A); \ + __a*((__v+__a-1)/__a); }) #define SET_BIT_FOR_OFFSET(mask, offset) \ - GC_set_bit (mask, offset / sizeof (void *)) + GC_set_bit(mask, offset / sizeof (void*)) /* Some prototypes */ static void @@ -74,9 +74,9 @@ __objc_gc_setup_union (GC_bitmap mask, const char *type, int offset); static void __objc_gc_setup_array (GC_bitmap mask, const char *type, int offset) { - int i, len = atoi (type + 1); + int i, len = atoi(type + 1); - while (isdigit (*++type)) + while (isdigit(*++type)) /* do nothing */; /* skip the size of the array */ switch (*type) { @@ -138,8 +138,8 @@ __objc_gc_setup_struct (GC_bitmap mask, const char *type, int offset) case _C_PTR: case _C_CHARPTR: case _C_ATOM: - if (! gc_invisible) - SET_BIT_FOR_OFFSET (mask, position); + if (!gc_invisible) + SET_BIT_FOR_OFFSET(mask, position); break; case _C_ARY_B: @@ -178,11 +178,11 @@ __objc_gc_setup_union (GC_bitmap mask, const char *type, int offset) size = objc_sizeof_type (type); align = objc_alignof_type (type); - offset = ROUND (offset, align); - for (i = 0; i < size; i += sizeof (void *)) + offset = ROUND(offset, align); + for (i = 0; i < size; i += sizeof (void*)) { - SET_BIT_FOR_OFFSET (mask, offset); - offset += sizeof (void *); + SET_BIT_FOR_OFFSET(mask, offset); + offset += sizeof (void*); } } @@ -223,8 +223,8 @@ __objc_gc_type_description_from_type (GC_bitmap mask, const char *type) case _C_SEL: case _C_PTR: case _C_CHARPTR: - if (! gc_invisible) - SET_BIT_FOR_OFFSET (mask, offset); + if (!gc_invisible) + SET_BIT_FOR_OFFSET(mask, offset); break; case _C_ARY_B: @@ -254,9 +254,9 @@ __objc_class_structure_encoding (Class class, char **type, int *size, int *current) { int i, ivar_count; - struct objc_ivar_list *ivars; + struct objc_ivar_list* ivars; - if (! class) + if (!class) { strcat (*type, "{"); *current++; @@ -267,7 +267,7 @@ __objc_class_structure_encoding (Class class, char **type, int *size, __objc_class_structure_encoding (class->super_class, type, size, current); ivars = class->ivars; - if (! ivars) + if (!ivars) return; ivar_count = ivars->ivar_count; @@ -282,7 +282,7 @@ __objc_class_structure_encoding (Class class, char **type, int *size, { /* Increase the size of the encoding string so that it contains this ivar's type. */ - *size = ROUND (*current + len + 1, 10); + *size = ROUND(*current + len + 1, 10); *type = objc_realloc (*type, *size); } strcat (*type + *current, ivar_type); @@ -302,7 +302,7 @@ __objc_generate_gc_type_description (Class class) int type_size = 10, current; char *class_structure_type; - if (! CLS_ISCLASS (class)) + if (!CLS_ISCLASS(class)) return; /* We have to create a mask in which each bit counts for a pointer member. @@ -311,9 +311,9 @@ __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 *)) - / sizeof (void *)); - size = ROUND (bits_no, BITS_PER_WORD) / BITS_PER_WORD; + bits_no = (ROUND(class_get_instance_size (class), sizeof(void*)) + / sizeof (void*)); + size = ROUND(bits_no, BITS_PER_WORD) / BITS_PER_WORD; mask = objc_atomic_malloc (size * sizeof (int)); memset (mask, 0, size * sizeof (int)); @@ -324,13 +324,12 @@ __objc_generate_gc_type_description (Class class) if (current + 1 == type_size) class_structure_type = objc_realloc (class_structure_type, ++type_size); strcat (class_structure_type + current, "}"); -#ifdef DEBUG - printf ("type description for '%s' is %s\n", class->name, class_structure_type); -#endif +// printf ("type description for '%s' is %s\n", class->name, class_structure_type); __objc_gc_type_description_from_type (mask, class_structure_type); objc_free (class_structure_type); +#define DEBUG 1 #ifdef DEBUG printf (" mask for '%s', type '%s' (bits %d, mask size %d) is:", class_structure_type, class->name, bits_no, size); @@ -342,7 +341,7 @@ __objc_generate_gc_type_description (Class class) puts (""); #endif - class->gc_object_type = (void *) GC_make_descriptor (mask, bits_no); + class->gc_object_type = (void*)GC_make_descriptor (mask, bits_no); } @@ -370,17 +369,17 @@ __objc_ivar_pointer (const char *type) This operation only makes sense on instance variables that are pointers. */ void -class_ivar_set_gcinvisible (Class class, const char *ivarname, +class_ivar_set_gcinvisible (Class class, const char* ivarname, BOOL gc_invisible) { int i, ivar_count; - struct objc_ivar_list *ivars; + struct objc_ivar_list* ivars; - if (! class || ! ivarname) + if (!class || !ivarname) return; ivars = class->ivars; - if (! ivars) + if (!ivars) return; ivar_count = ivars->ivar_count; @@ -390,7 +389,7 @@ class_ivar_set_gcinvisible (Class class, const char *ivarname, struct objc_ivar *ivar = &(ivars->ivar_list[i]); const char *type; - if (! ivar->ivar_name || strcmp (ivar->ivar_name, ivarname)) + if (!ivar->ivar_name || strcmp (ivar->ivar_name, ivarname)) continue; assert (ivar->ivar_type); @@ -407,7 +406,7 @@ class_ivar_set_gcinvisible (Class class, const char *ivarname, { char *new_type; - if (gc_invisible || ! __objc_ivar_pointer (type)) + if (gc_invisible || !__objc_ivar_pointer (type)) return; /* The type of the variable already matches the requested gc_invisible type */ @@ -422,7 +421,7 @@ class_ivar_set_gcinvisible (Class class, const char *ivarname, { char *new_type; - if (! gc_invisible || ! __objc_ivar_pointer (type)) + if (!gc_invisible || !__objc_ivar_pointer (type)) return; /* The type of the variable already matches the requested gc_invisible type */ @@ -446,13 +445,13 @@ class_ivar_set_gcinvisible (Class class, const char *ivarname, #else /* !OBJC_WITH_GC */ void -__objc_generate_gc_type_description (Class class __attribute__ ((__unused__))) +__objc_generate_gc_type_description (Class class) { } -void class_ivar_set_gcinvisible (Class class __attribute__ ((__unused__)), - const char *ivarname __attribute__ ((__unused__)), - BOOL gc_invisible __attribute__ ((__unused__))) +void class_ivar_set_gcinvisible (Class class, + const char* ivarname, + BOOL gc_invisible) { } diff --git a/gnu/lib/libobjc/libobjc/hash.c b/gnu/lib/libobjc/libobjc/hash.c index 2f58b2c5472..223991f97f3 100644 --- a/gnu/lib/libobjc/libobjc/hash.c +++ b/gnu/lib/libobjc/libobjc/hash.c @@ -47,7 +47,7 @@ hash_new (unsigned int size, hash_func_type hash_func, /* Pass me a value greater than 0 and a power of 2. */ assert (size); - assert (! (size & (size - 1))); + assert (!(size & (size - 1))); /* Allocate the cache structure. calloc insures its initialization for default values. */ @@ -196,7 +196,7 @@ hash_remove (cache_ptr cache, const void *key) objc_free(node); } else prev = node, node = node->next; - } while (! removed && node); + } while (!removed && node); assert (removed); } @@ -210,7 +210,7 @@ hash_next (cache_ptr cache, node_ptr node) { /* If the scan is being started then reset the last node visitied pointer and bucket index. */ - if (! node) + if (!node) cache->last_bucket = 0; /* If there is a node visited last then check for another @@ -258,7 +258,7 @@ hash_value_for_key (cache_ptr cache, const void *key) break; } else node = node->next; - } while (! retval && node); + } while (!retval && node); return retval; } diff --git a/gnu/lib/libobjc/libobjc/init.c b/gnu/lib/libobjc/libobjc/init.c index 098e253649f..954fc9240ae 100644 --- a/gnu/lib/libobjc/libobjc/init.c +++ b/gnu/lib/libobjc/libobjc/init.c @@ -1,5 +1,5 @@ /* GNU Objective C Runtime initialization - Copyright (C) 1993, 1995, 1996, 1997, 2002 Free Software Foundation, Inc. + Copyright (C) 1993, 1995, 1996, 1997 Free Software Foundation, Inc. Contributed by Kresten Krab Thorup +load support contributed by Ovidiu Predescu <ovidiu@net-community.com> @@ -27,62 +27,62 @@ Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #include "runtime.h" /* The version number of this runtime. This must match the number - defined in gcc (objc-act.c). */ + defined in gcc (objc-act.c) */ #define OBJC_VERSION 8 #define PROTOCOL_VERSION 2 -/* This list contains all modules currently loaded into the runtime. */ -static struct objc_list *__objc_module_list = 0; /* !T:MUTEX */ +/* This list contains all modules currently loaded into the runtime */ +static struct objc_list* __objc_module_list = 0; /* !T:MUTEX */ -/* This list contains all proto_list's not yet assigned class links. */ -static struct objc_list *unclaimed_proto_list = 0; /* !T:MUTEX */ +/* This list contains all proto_list's not yet assigned class links */ +static struct objc_list* unclaimed_proto_list = 0; /* !T:MUTEX */ /* List of unresolved static instances. */ static struct objc_list *uninitialized_statics = 0; /* !T:MUTEX */ -/* Global runtime "write" mutex. */ +/* Global runtime "write" mutex. */ objc_mutex_t __objc_runtime_mutex = 0; -/* Number of threads that are alive. */ +/* Number of threads that are alive. */ int __objc_runtime_threads_alive = 1; /* !T:MUTEX */ -/* Check compiler vs runtime version. */ +/* Check compiler vs runtime version */ static void init_check_module_version (Module_t); -/* Assign isa links to protos. */ -static void __objc_init_protocols (struct objc_protocol_list *protos); +/* Assign isa links to protos */ +static void __objc_init_protocols (struct objc_protocol_list* protos); -/* Add protocol to class. */ -static void __objc_class_add_protocols (Class, struct objc_protocol_list *); +/* Add protocol to class */ +static void __objc_class_add_protocols (Class, struct objc_protocol_list*); -/* 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. */ -void (*_objc_load_callback) (Class class, Category *category); /* !T:SAFE */ +/* 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 */ +void (*_objc_load_callback)(Class class, Category* category); /* !T:SAFE */ -/* Is all categories/classes resolved? */ +/* Is all categories/classes resolved? */ BOOL __objc_dangling_categories = NO; /* !T:UNUSED */ extern SEL __sel_register_typed_name (const char *name, const char *types, struct objc_selector *orig, BOOL is_const); -/* Sends +load to all classes and categories in certain situations. */ +/* Sends +load to all classes and categories in certain situations. */ static void objc_send_load (void); /* Inserts all the classes defined in module in a tree of classes that - resembles the class hierarchy. This tree is traversed in preorder - and the classes in its nodes receive the +load message if these - methods were not executed before. The algorithm ensures that when - the +load method of a class is executed all the superclasses have - been already received the +load message. */ + resembles the class hierarchy. This tree is traversed in preorder and the + classes in its nodes receive the +load message if these methods were not + executed before. The algorithm ensures that when the +load method of a class + is executed all the superclasses have been already received the +load + message. */ static void __objc_create_classes_tree (Module_t module); static void __objc_call_callback (Module_t module); /* A special version that works only before the classes are completely - installed in the runtime. */ + installed in the runtime. */ static BOOL class_is_subclass_of_class (Class class, Class superclass); typedef struct objc_class_tree { @@ -90,26 +90,24 @@ typedef struct objc_class_tree { struct objc_list *subclasses; /* `head' is pointer to an objc_class_tree */ } objc_class_tree; -/* This is a linked list of objc_class_tree trees. The head of these - trees are root classes (their super class is Nil). These different - trees represent different class hierarchies. */ +/* This is a linked list of objc_class_tree trees. The head of these trees + are root classes (their super class is Nil). These different trees + represent different class hierarchies. */ static struct objc_list *__objc_class_tree_list = NULL; -/* Keeps the +load methods who have been already executed. This hash - should not be destroyed during the execution of the program. */ +/* Keeps the +load methods who have been already executed. This hash should + not be destroyed during the execution of the program. */ static cache_ptr __objc_load_methods = NULL; -/* Creates a tree of classes whose topmost class is directly inherited - from `upper' and the bottom class in this tree is - `bottom_class'. The classes in this tree are super classes of - `bottom_class'. `subclasses' member of each tree node point to the - next subclass tree node. */ - +/* Creates a tree of classes whose topmost class is directly inherited from + `upper' and the bottom class in this tree is `bottom_class'. The classes + in this tree are super classes of `bottom_class'. `subclasses' member + of each tree node point to the next subclass tree node. */ static objc_class_tree * create_tree_of_subclasses_inherited_from (Class bottom_class, Class upper) { Class superclass = bottom_class->super_class ? - objc_lookup_class ((char *) bottom_class->super_class) + objc_lookup_class ((char*)bottom_class->super_class) : Nil; objc_class_tree *tree, *prev; @@ -128,7 +126,7 @@ create_tree_of_subclasses_inherited_from (Class bottom_class, Class upper) tree->class = superclass; tree->subclasses = list_cons (prev, tree->subclasses); superclass = (superclass->super_class ? - objc_lookup_class ((char *) superclass->super_class) + objc_lookup_class ((char*)superclass->super_class) : Nil); prev = tree; } @@ -136,13 +134,11 @@ create_tree_of_subclasses_inherited_from (Class bottom_class, Class upper) return tree; } -/* Insert the `class' into the proper place in the `tree' class - hierarchy. This function returns a new tree if the class has been - successfully inserted into the tree or NULL if the class is not - part of the classes hierarchy described by `tree'. This function is - private to objc_tree_insert_class (), you should not call it - directly. */ - +/* Insert the `class' into the proper place in the `tree' class hierarchy. This + function returns a new tree if the class has been successfully inserted into + the tree or NULL if the class is not part of the classes hierarchy described + by `tree'. This function is private to objc_tree_insert_class(), you should + not call it directly. */ static objc_class_tree * __objc_tree_insert_class (objc_class_tree *tree, Class class) { @@ -158,21 +154,21 @@ __objc_tree_insert_class (objc_class_tree *tree, Class class) return tree; } else if ((class->super_class ? - objc_lookup_class ((char *) class->super_class) + objc_lookup_class ((char*)class->super_class) : Nil) == tree->class) { /* If class is a direct subclass of tree->class then add class to the list of subclasses. First check to see if it wasn't already - inserted. */ + inserted. */ struct objc_list *list = tree->subclasses; objc_class_tree *node; while (list) { /* Class has been already inserted; do nothing just return - the tree. */ - if (((objc_class_tree *) list->head)->class == class) + the tree. */ + if (((objc_class_tree*)list->head)->class == class) { DEBUG_PRINTF ("2. class %s was previously inserted\n", class->name); @@ -190,25 +186,24 @@ __objc_tree_insert_class (objc_class_tree *tree, Class class) } else { - /* The class is not a direct subclass of tree->class. Search for - class's superclasses in the list of subclasses. */ + /* The class is not a direct subclass of tree->class. Search for class's + superclasses in the list of subclasses. */ struct objc_list *subclasses = tree->subclasses; - /* Precondition: the class must be a subclass of tree->class; - otherwise return NULL to indicate our caller that it must - take the next tree. */ - if (! class_is_subclass_of_class (class, tree->class)) + /* Precondition: the class must be a subclass of tree->class; otherwise + return NULL to indicate our caller that it must take the next tree. */ + if (!class_is_subclass_of_class (class, tree->class)) return NULL; for (; subclasses != NULL; subclasses = subclasses->tail) { - Class aClass = ((objc_class_tree *) (subclasses->head))->class; + Class aClass = ((objc_class_tree*)(subclasses->head))->class; if (class_is_subclass_of_class (class, aClass)) { - /* If we found one of class's superclasses we insert the - class into its subtree and return the original tree - since nothing has been changed. */ + /* If we found one of class's superclasses we insert the class + into its subtree and return the original tree since nothing + has been changed. */ subclasses->head = __objc_tree_insert_class (subclasses->head, class); DEBUG_PRINTF ("4. class %s inserted\n", class->name); @@ -216,12 +211,12 @@ __objc_tree_insert_class (objc_class_tree *tree, Class class) } } - /* We haven't found a subclass of `class' in the `subclasses' - list. Create a new tree of classes whose topmost class is a - direct subclass of tree->class. */ + /* We haven't found a subclass of `class' in the `subclasses' list. + Create a new tree of classes whose topmost class is a direct subclass + of tree->class. */ { objc_class_tree *new_tree - = create_tree_of_subclasses_inherited_from (class, tree->class); + = create_tree_of_subclasses_inherited_from (class, tree->class); tree->subclasses = list_cons (new_tree, tree->subclasses); DEBUG_PRINTF ("5. class %s inserted\n", class->name); return tree; @@ -229,8 +224,7 @@ __objc_tree_insert_class (objc_class_tree *tree, Class class) } } -/* This function inserts `class' in the right tree hierarchy classes. */ - +/* This function inserts `class' in the right tree hierarchy classes. */ static void objc_tree_insert_class (Class class) { @@ -250,21 +244,20 @@ objc_tree_insert_class (Class class) list_node = list_node->tail; } - /* If the list was finished but the class hasn't been inserted, - insert it here. */ - if (! list_node) + /* If the list was finished but the class hasn't been inserted, insert it + here. */ + if (!list_node) { __objc_class_tree_list = list_cons (NULL, __objc_class_tree_list); __objc_class_tree_list->head = __objc_tree_insert_class (NULL, class); } } -/* Traverse tree in preorder. Used to send +load. */ - +/* Traverse tree in preorder. Used to send +load. */ static void objc_preorder_traverse (objc_class_tree *tree, int level, - void (*function) (objc_class_tree *, int)) + void (*function)(objc_class_tree*, int)) { struct objc_list *node; @@ -273,12 +266,11 @@ objc_preorder_traverse (objc_class_tree *tree, objc_preorder_traverse (node->head, level + 1, function); } -/* Traverse tree in postorder. Used to destroy a tree. */ - +/* Traverse tree in postorder. Used to destroy a tree. */ static void objc_postorder_traverse (objc_class_tree *tree, - int level, - void (*function) (objc_class_tree *, int)) + int level, + void (*function)(objc_class_tree*, int)) { struct objc_list *node; @@ -287,8 +279,7 @@ objc_postorder_traverse (objc_class_tree *tree, (*function) (tree, level); } -/* Used to print a tree class hierarchy. */ - +/* Used to print a tree class hierarchy. */ #ifdef DEBUG static void __objc_tree_print (objc_class_tree *tree, int level) @@ -301,68 +292,63 @@ __objc_tree_print (objc_class_tree *tree, int level) } #endif -/* Walks on a linked list of methods in the reverse order and executes - all the methods corresponding to `op' selector. Walking in the - reverse order assures the +load of class is executed first and then - +load of categories because of the way in which categories are - added to the class methods. */ - +/* Walks on a linked list of methods in the reverse order and executes all + the methods corresponding to `op' selector. Walking in the reverse order + assures the +load of class is executed first and then +load of categories + because of the way in which categories are added to the class methods. */ static void __objc_send_message_in_list (MethodList_t method_list, Class class, SEL op) { int i; - if (! method_list) + if (!method_list) return; /* First execute the `op' message in the following method lists */ __objc_send_message_in_list (method_list->method_next, class, op); - /* Search the method list. */ + /* Search the method list. */ for (i = 0; i < method_list->method_count; i++) { Method_t mth = &method_list->method_list[i]; if (mth->method_name && sel_eq (mth->method_name, op) - && ! hash_is_key_in_hash (__objc_load_methods, mth->method_imp)) + && !hash_is_key_in_hash (__objc_load_methods, mth->method_name)) { + /* The method was found and wasn't previously executed. */ + (*mth->method_imp) ((id)class, mth->method_name); + /* Add this method into the +load hash table */ hash_add (&__objc_load_methods, mth->method_imp, mth->method_imp); DEBUG_PRINTF ("sending +load in class: %s\n", class->name); - /* The method was found and wasn't previously executed. */ - (*mth->method_imp) ((id)class, mth->method_name); - break; } } } static void -__objc_send_load (objc_class_tree *tree, - int level __attribute__ ((__unused__))) +__objc_send_load (objc_class_tree *tree, int level) { static SEL load_sel = 0; Class class = tree->class; MethodList_t method_list = class->class_pointer->methods; - if (! load_sel) + if (!load_sel) load_sel = sel_register_name ("load"); __objc_send_message_in_list (method_list, class, load_sel); } static void -__objc_destroy_class_tree_node (objc_class_tree *tree, - int level __attribute__ ((__unused__))) +__objc_destroy_class_tree_node (objc_class_tree *tree, int level) { objc_free (tree); } -/* This is used to check if the relationship between two classes - before the runtime completely installs the classes. */ - +/* This is used to check if the relationship between two classes before the + runtime completely installs the classes. */ static BOOL class_is_subclass_of_class (Class class, Class superclass) { @@ -371,19 +357,19 @@ class_is_subclass_of_class (Class class, Class superclass) if (class == superclass) return YES; class = (class->super_class ? - objc_lookup_class ((char *) class->super_class) + objc_lookup_class ((char*)class->super_class) : Nil); } return NO; } -/* This list contains all the classes in the runtime system for whom - their superclasses are not yet known to the runtime. */ -static struct objc_list *unresolved_classes = 0; +/* This list contains all the classes in the runtime system for whom their + superclasses are not yet know to the runtime. */ +static struct objc_list* unresolved_classes = 0; -/* Extern function used to reference the Object and NXConstantString - classes. */ +/* Extern function used to reference the Object and NXConstantString classes. + */ extern void __objc_force_linking (void); @@ -394,16 +380,15 @@ __objc_force_linking (void) __objc_linking (); } -/* Run through the statics list, removing modules as soon as all its - statics have been initialized. */ - +/* Run through the statics list, removing modules as soon as all its statics + have been initialized. */ static void objc_init_statics (void) { struct objc_list **cell = &uninitialized_statics; struct objc_static_instances **statics_in_module; - objc_mutex_lock (__objc_runtime_mutex); + objc_mutex_lock(__objc_runtime_mutex); while (*cell) { @@ -415,7 +400,7 @@ objc_init_statics (void) struct objc_static_instances *statics = *statics_in_module; Class class = objc_lookup_class (statics->class_name); - if (! class) + if (!class) module_initialized = 0; /* Actually, the static's class_pointer will be NULL when we haven't been here before. However, the comparison is to be @@ -445,19 +430,19 @@ objc_init_statics (void) /* Remove this module from the uninitialized list. */ struct objc_list *this = *cell; *cell = this->tail; - objc_free (this); + objc_free(this); } else cell = &(*cell)->tail; } - objc_mutex_unlock (__objc_runtime_mutex); + objc_mutex_unlock(__objc_runtime_mutex); } /* objc_init_statics */ /* This function is called by constructor functions generated for each - module compiled. (_GLOBAL_$I$...) The purpose of this function is - to gather the module pointers so that they may be processed by the - initialization routines as soon as possible. */ + module compiled. (_GLOBAL_$I$...) The purpose of this function is to + gather the module pointers so that they may be processed by the + initialization routines as soon as possible */ void __objc_exec_class (Module_t module) @@ -466,7 +451,7 @@ __objc_exec_class (Module_t module) indicate that some global data structures need to be built. */ static BOOL previous_constructors = 0; - static struct objc_list *unclaimed_categories = 0; + static struct objc_list* unclaimed_categories = 0; /* The symbol table (defined in objc-api.h) generated by gcc */ Symtab_t symtab = module->symtab; @@ -476,7 +461,7 @@ __objc_exec_class (Module_t module) = symtab->defs[symtab->cls_def_cnt + symtab->cat_def_cnt]; /* Entry used to traverse hash lists */ - struct objc_list **cell; + struct objc_list** cell; /* The table of selector references for this module */ SEL selectors = symtab->refs; @@ -487,19 +472,19 @@ __objc_exec_class (Module_t module) DEBUG_PRINTF ("received module: %s\n", module->name); /* check gcc version */ - init_check_module_version (module); + init_check_module_version(module); /* On the first call of this routine, initialize some data structures. */ - if (! previous_constructors) + if (!previous_constructors) { /* Initialize thread-safe system */ - __objc_init_thread_system (); + __objc_init_thread_system(); __objc_runtime_threads_alive = 1; - __objc_runtime_mutex = objc_mutex_allocate (); + __objc_runtime_mutex = objc_mutex_allocate(); - __objc_init_selector_tables (); - __objc_init_class_tables (); - __objc_init_dispatch_tables (); + __objc_init_selector_tables(); + __objc_init_class_tables(); + __objc_init_dispatch_tables(); __objc_class_tree_list = list_cons (NULL, __objc_class_tree_list); __objc_load_methods = hash_new (128, (hash_func_type)hash_ptr, compare_ptrs); @@ -507,8 +492,8 @@ __objc_exec_class (Module_t module) } /* Save the module pointer for later processing. (not currently used) */ - objc_mutex_lock (__objc_runtime_mutex); - __objc_module_list = list_cons (module, __objc_module_list); + objc_mutex_lock(__objc_runtime_mutex); + __objc_module_list = list_cons(module, __objc_module_list); /* Replace referenced selectors from names to SEL's. */ if (selectors) @@ -516,12 +501,12 @@ __objc_exec_class (Module_t module) for (i = 0; selectors[i].sel_id; ++i) { const char *name, *type; - name = (char *) selectors[i].sel_id; - type = (char *) selectors[i].sel_types; + name = (char*)selectors[i].sel_id; + type = (char*)selectors[i].sel_types; /* Constructors are constant static data so we can safely store pointers to them in the runtime structures. is_const == YES */ __sel_register_typed_name (name, type, - (struct objc_selector *) &(selectors[i]), + (struct objc_selector*)&(selectors[i]), YES); } } @@ -531,15 +516,15 @@ __objc_exec_class (Module_t module) for (i = 0; i < symtab->cls_def_cnt; ++i) { Class class = (Class) symtab->defs[i]; - const char *superclass = (char *) class->super_class; + const char* superclass = (char*)class->super_class; /* Make sure we have what we think. */ - assert (CLS_ISCLASS (class)); - assert (CLS_ISMETA (class->class_pointer)); + assert (CLS_ISCLASS(class)); + assert (CLS_ISMETA(class->class_pointer)); DEBUG_PRINTF ("phase 1, processing class: %s\n", class->name); /* Initialize the subclass list to be NULL. - In some cases it isn't and this crashes the program. */ + In some cases it isn't and this crashes the program. */ class->subclass_list = NULL; /* Store the class in the class table and assign class numbers. */ @@ -550,19 +535,19 @@ __objc_exec_class (Module_t module) __objc_register_selectors_from_class ((Class) class->class_pointer); /* Install the fake dispatch tables */ - __objc_install_premature_dtable (class); - __objc_install_premature_dtable (class->class_pointer); + __objc_install_premature_dtable(class); + __objc_install_premature_dtable(class->class_pointer); /* Register the instance methods as class methods, this is - only done for root classes. */ - __objc_register_instance_methods_to_class (class); + only done for root classes. */ + __objc_register_instance_methods_to_class(class); if (class->protocols) __objc_init_protocols (class->protocols); /* Check to see if the superclass is known in this point. If it's not - add the class to the unresolved_classes list. */ - if (superclass && ! objc_lookup_class (superclass)) + add the class to the unresolved_classes list. */ + if (superclass && !objc_lookup_class (superclass)) unresolved_classes = list_cons (class, unresolved_classes); } @@ -596,14 +581,14 @@ __objc_exec_class (Module_t module) } /* Register the instance methods as class methods, this is - only done for root classes. */ - __objc_register_instance_methods_to_class (class); + only done for root classes. */ + __objc_register_instance_methods_to_class(class); } else { /* The object to which the category methods belong can't be found. Save the information. */ - unclaimed_categories = list_cons (category, unclaimed_categories); + unclaimed_categories = list_cons(category, unclaimed_categories); } } @@ -614,7 +599,9 @@ __objc_exec_class (Module_t module) /* Scan the unclaimed category hash. Attempt to attach any unclaimed categories to objects. */ - for (cell = &unclaimed_categories; *cell; ) + for (cell = &unclaimed_categories; + *cell; + ({ if (*cell) cell = &(*cell)->tail; })) { Category_t category = (*cell)->head; Class class = objc_lookup_class (category->class_name); @@ -640,41 +627,37 @@ __objc_exec_class (Module_t module) } /* Register the instance methods as class methods, this is - only done for root classes. */ - __objc_register_instance_methods_to_class (class); + only done for root classes. */ + __objc_register_instance_methods_to_class(class); } - else - cell = &(*cell)->tail; } if (unclaimed_proto_list && objc_lookup_class ("Protocol")) { - list_mapcar (unclaimed_proto_list, - (void (*) (void *))__objc_init_protocols); + list_mapcar (unclaimed_proto_list,(void(*)(void*))__objc_init_protocols); list_free (unclaimed_proto_list); unclaimed_proto_list = 0; } objc_send_load (); - objc_mutex_unlock (__objc_runtime_mutex); + objc_mutex_unlock(__objc_runtime_mutex); } -static void -objc_send_load (void) +static void objc_send_load (void) { - if (! __objc_module_list) + if (!__objc_module_list) return; /* Try to find out if all the classes loaded so far also have their - superclasses known to the runtime. We suppose that the objects - that are allocated in the +load method are in general of a class - declared in the same module. */ + superclasses known to the runtime. We suppose that the objects that are + allocated in the +load method are in general of a class declared in the + same module. */ if (unresolved_classes) { Class class = unresolved_classes->head; - while (objc_lookup_class ((char *) class->super_class)) + while (objc_lookup_class ((char*)class->super_class)) { list_remove_head (&unresolved_classes); if (unresolved_classes) @@ -683,25 +666,25 @@ objc_send_load (void) break; } - /* If we still have classes for whom we don't have yet their - super classes known to the runtime we don't send the +load - messages. */ + /* + * If we still have classes for whom we don't have yet their super + * classes known to the runtime we don't send the +load messages. + */ if (unresolved_classes) return; } - /* Special check to allow creating and sending messages to constant - strings in +load methods. If these classes are not yet known, - even if all the other classes are known, delay sending of +load. */ - if (! objc_lookup_class ("NXConstantString") || - ! objc_lookup_class ("Object")) + /* Special check to allow creating and sending messages to constant strings + in +load methods. If these classes are not yet known, even if all the + other classes are known, delay sending of +load. */ + if (!objc_lookup_class ("NXConstantString") || + !objc_lookup_class ("Object")) return; - /* Iterate over all modules in the __objc_module_list and call on - them the __objc_create_classes_tree function. This function - creates a tree of classes that resembles the class hierarchy. */ - list_mapcar (__objc_module_list, - (void (*) (void *)) __objc_create_classes_tree); + /* Iterate over all modules in the __objc_module_list and call on them the + __objc_create_classes_tree function. This function creates a tree of + classes that resembles the class hierarchy. */ + list_mapcar (__objc_module_list, (void(*)(void*))__objc_create_classes_tree); while (__objc_class_tree_list) { @@ -716,7 +699,7 @@ objc_send_load (void) list_remove_head (&__objc_class_tree_list); } - list_mapcar (__objc_module_list, (void (*) (void *)) __objc_call_callback); + list_mapcar (__objc_module_list, (void(*)(void*))__objc_call_callback); list_free (__objc_module_list); __objc_module_list = NULL; } @@ -729,8 +712,8 @@ __objc_create_classes_tree (Module_t module) Symtab_t symtab = module->symtab; int i; - /* Iterate thru classes defined in this module and insert them in - the classes tree hierarchy. */ + /* Iterate thru classes defined in this module and insert them in the classes + tree hierarchy. */ for (i = 0; i < symtab->cls_def_cnt; i++) { Class class = (Class) symtab->defs[i]; @@ -742,74 +725,72 @@ __objc_create_classes_tree (Module_t module) static void __objc_call_callback (Module_t module) { - /* The runtime mutex is locked in this point. */ + /* The runtime mutex is locked in this point */ Symtab_t symtab = module->symtab; int i; - /* Iterate thru classes defined in this module and call the callback - for each one. */ + /* Iterate thru classes defined in this module and call the callback for + each one. */ for (i = 0; i < symtab->cls_def_cnt; i++) { Class class = (Class) symtab->defs[i]; - /* Call the _objc_load_callback for this class. */ + /* Call the _objc_load_callback for this class. */ if (_objc_load_callback) - _objc_load_callback (class, 0); + _objc_load_callback(class, 0); } - /* Call the _objc_load_callback for categories. Don't register the - instance methods as class methods for categories to root classes - since they were already added in the class. */ + /* Call the _objc_load_callback for categories. Don't register the instance + methods as class methods for categories to root classes since they were + already added in the class. */ for (i = 0; i < symtab->cat_def_cnt; i++) { Category_t category = symtab->defs[i + symtab->cls_def_cnt]; Class class = objc_lookup_class (category->class_name); if (_objc_load_callback) - _objc_load_callback (class, category); + _objc_load_callback(class, category); } } -/* Sanity check the version of gcc used to compile `module'. */ - -static void -init_check_module_version (Module_t module) +/* Sanity check the version of gcc used to compile `module'*/ +static void init_check_module_version(Module_t module) { if ((module->version != OBJC_VERSION) || (module->size != sizeof (Module))) { int code; - if (module->version > OBJC_VERSION) + if(module->version > OBJC_VERSION) code = OBJC_ERR_OBJC_VERSION; else if (module->version < OBJC_VERSION) code = OBJC_ERR_GCC_VERSION; else code = OBJC_ERR_MODULE_SIZE; - objc_error (nil, code, "Module %s version %d doesn't match runtime %d\n", - module->name, (int)module->version, OBJC_VERSION); + objc_error(nil, code, "Module %s version %d doesn't match runtime %d\n", + module->name, (int)module->version, OBJC_VERSION); } } static void -__objc_init_protocols (struct objc_protocol_list *protos) +__objc_init_protocols (struct objc_protocol_list* protos) { - size_t i; + int i; static Class proto_class = 0; if (! protos) return; - objc_mutex_lock (__objc_runtime_mutex); + objc_mutex_lock(__objc_runtime_mutex); - if (! proto_class) - proto_class = objc_lookup_class ("Protocol"); + if (!proto_class) + proto_class = objc_lookup_class("Protocol"); - if (! proto_class) + if (!proto_class) { unclaimed_proto_list = list_cons (protos, unclaimed_proto_list); - objc_mutex_unlock (__objc_runtime_mutex); + objc_mutex_unlock(__objc_runtime_mutex); return; } @@ -817,9 +798,9 @@ __objc_init_protocols (struct objc_protocol_list *protos) assert (protos->next == 0); /* only single ones allowed */ #endif - for (i = 0; i < protos->count; i++) + for(i = 0; i < protos->count; i++) { - struct objc_protocol *aProto = protos->list[i]; + struct objc_protocol* aProto = protos->list[i]; if (((size_t)aProto->class_pointer) == PROTOCOL_VERSION) { /* assign class pointer */ @@ -830,25 +811,24 @@ __objc_init_protocols (struct objc_protocol_list *protos) } else if (protos->list[i]->class_pointer != proto_class) { - objc_error (nil, OBJC_ERR_PROTOCOL_VERSION, + objc_error(nil, OBJC_ERR_PROTOCOL_VERSION, "Version %d doesn't match runtime protocol version %d\n", - (int) ((char *) protos->list[i]->class_pointer - - (char *) 0), + (int)((char*)protos->list[i]->class_pointer-(char*)0), PROTOCOL_VERSION); } } - objc_mutex_unlock (__objc_runtime_mutex); + objc_mutex_unlock(__objc_runtime_mutex); } -static void -__objc_class_add_protocols (Class class, struct objc_protocol_list *protos) +static void __objc_class_add_protocols (Class class, + struct objc_protocol_list* protos) { - /* Well... */ + /* Well... */ if (! protos) return; - /* Add it... */ + /* Add it... */ protos->next = class->protocols; class->protocols = protos; } diff --git a/gnu/lib/libobjc/libobjc/libobjc.def b/gnu/lib/libobjc/libobjc/libobjc.def index 7e0a857ecf7..a4a6049e816 100644 --- a/gnu/lib/libobjc/libobjc/libobjc.def +++ b/gnu/lib/libobjc/libobjc/libobjc.def @@ -45,8 +45,6 @@ objc_thread_id objc_thread_set_data objc_thread_set_priority objc_thread_yield -objc_thread_add -objc_thread_remove __objc_class_name_Object __objc_class_name_Protocol __objc_class_name_NXConstantString diff --git a/gnu/lib/libobjc/libobjc/misc.c b/gnu/lib/libobjc/libobjc/misc.c index 9572d3f0050..7339888dc28 100644 --- a/gnu/lib/libobjc/libobjc/misc.c +++ b/gnu/lib/libobjc/libobjc/misc.c @@ -1,6 +1,5 @@ /* GNU Objective C Runtime Miscellaneous - Copyright (C) 1993, 1994, 1995, 1996, 1997, 2002 - Free Software Foundation, Inc. + Copyright (C) 1993, 1994, 1995, 1996, 1997 Free Software Foundation, Inc. Contributed by Kresten Krab Thorup This file is part of GNU CC. @@ -38,25 +37,25 @@ static objc_error_handler _objc_error_handler = NULL; /* Trigger an objc error */ void -objc_error (id object, int code, const char *fmt, ...) +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); + 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) +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); + result = (*_objc_error_handler)(object, code, fmt, ap); else vfprintf (stderr, fmt, ap); @@ -65,12 +64,12 @@ objc_verror (id object, int code, const char *fmt, va_list ap) if (result) return; else - abort (); + abort(); } /* Set the error handler */ objc_error_handler -objc_set_error_handler (objc_error_handler func) +objc_set_error_handler(objc_error_handler func) { objc_error_handler temp = _objc_error_handler; _objc_error_handler = func; @@ -85,54 +84,54 @@ objc_set_error_handler (objc_error_handler func) */ void * -objc_malloc (size_t size) +objc_malloc(size_t size) { - void *res = (void *) (*_objc_malloc) (size); - if (! res) - objc_error (nil, OBJC_ERR_MEMORY, "Virtual memory exhausted\n"); + void* res = (void*) (*_objc_malloc)(size); + if(!res) + objc_error(nil, OBJC_ERR_MEMORY, "Virtual memory exhausted\n"); return res; } void * -objc_atomic_malloc (size_t size) +objc_atomic_malloc(size_t size) { - void *res = (void *) (*_objc_atomic_malloc) (size); - if (! res) - objc_error (nil, OBJC_ERR_MEMORY, "Virtual memory exhausted\n"); + void* res = (void*) (*_objc_atomic_malloc)(size); + if(!res) + objc_error(nil, OBJC_ERR_MEMORY, "Virtual memory exhausted\n"); return res; } void * -objc_valloc (size_t size) +objc_valloc(size_t size) { - void *res = (void *) (*_objc_valloc) (size); - if (! res) - objc_error (nil, OBJC_ERR_MEMORY, "Virtual memory exhausted\n"); + void* res = (void*) (*_objc_valloc)(size); + if(!res) + objc_error(nil, OBJC_ERR_MEMORY, "Virtual memory exhausted\n"); return res; } void * -objc_realloc (void *mem, size_t size) +objc_realloc(void *mem, size_t size) { - void *res = (void *) (*_objc_realloc) (mem, size); - if (! res) - objc_error (nil, OBJC_ERR_MEMORY, "Virtual memory exhausted\n"); + void* res = (void*) (*_objc_realloc)(mem, size); + if(!res) + objc_error(nil, OBJC_ERR_MEMORY, "Virtual memory exhausted\n"); return res; } void * -objc_calloc (size_t nelem, size_t size) +objc_calloc(size_t nelem, size_t size) { - void *res = (void *) (*_objc_calloc) (nelem, size); - if (! res) - objc_error (nil, OBJC_ERR_MEMORY, "Virtual memory exhausted\n"); + void* res = (void*) (*_objc_calloc)(nelem, size); + if(!res) + objc_error(nil, OBJC_ERR_MEMORY, "Virtual memory exhausted\n"); return res; } void -objc_free (void *mem) +objc_free(void *mem) { - (*_objc_free) (mem); + (*_objc_free)(mem); } /* @@ -149,37 +148,33 @@ objc_free (void *mem) #if OBJC_WITH_GC #include <gc.h> -static void * -GC_calloc (size_t nelem, size_t size) +static void *GC_calloc (size_t nelem, size_t size) { - void *p = GC_malloc (nelem * size); - if (! p) + void* p = GC_malloc (nelem * size); + if (!p) objc_error (nil, OBJC_ERR_MEMORY, "Virtual memory exhausted!\n"); memset (p, 0, nelem * size); return p; } -static void -noFree (void *p) -{ -} +static void noFree (void* p) {} -void *(*_objc_malloc) (size_t) = GC_malloc; -void *(*_objc_atomic_malloc) (size_t) = GC_malloc_atomic; -void *(*_objc_valloc) (size_t) = GC_malloc; -void *(*_objc_realloc) (void *, size_t) = GC_realloc; -void *(*_objc_calloc) (size_t, size_t) = GC_calloc; -void (*_objc_free) (void *) = noFree; +void *(*_objc_malloc)(size_t) = GC_malloc; +void *(*_objc_atomic_malloc)(size_t) = GC_malloc_atomic; +void *(*_objc_valloc)(size_t) = GC_malloc; +void *(*_objc_realloc)(void *, size_t) = GC_realloc; +void *(*_objc_calloc)(size_t, size_t) = GC_calloc; +void (*_objc_free)(void *) = noFree; -#else /* !OBJC_WITH_GC */ +#else -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; +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; -#endif /* !OBJC_WITH_GC */ +#endif diff --git a/gnu/lib/libobjc/libobjc/nil_method.c b/gnu/lib/libobjc/libobjc/nil_method.c index 5e37c4d5dfb..1b6212826bd 100644 --- a/gnu/lib/libobjc/libobjc/nil_method.c +++ b/gnu/lib/libobjc/libobjc/nil_method.c @@ -1,5 +1,5 @@ /* GNU Objective C Runtime nil receiver function - Copyright (C) 1993, 1995, 1996, 2002 Free Software Foundation, Inc. + Copyright (C) 1993, 1995, 1996 Free Software Foundation, Inc. Contributed by Kresten Krab Thorup This file is part of GNU CC. @@ -29,27 +29,12 @@ Boston, MA 02111-1307, USA. */ #include "runtime.h" -/* When the receiver of a method invocation is nil, the runtime - returns nil_method() as the method implementation. This function - will be casted to whatever function was supposed to be executed to - execute that method (that function will take an id, followed by a - SEL, followed by who knows what arguments, depends on the method), - and executed. - - For this reason, nil_method() should be a function which can be - called in place of any function taking an 'id' argument followed by - a 'SEL' argument, followed by zero, or one, or any number of - arguments (both a fixed number, or a variable number !). - - There is no "proper" implementation of such a nil_method function - in C, however in all existing implementations it does not matter - when extra arguments are present, so we can simply create a function - taking a receiver and a selector, and all other arguments will be - ignored. :-) -*/ - id -nil_method (id receiver, SEL op __attribute__ ((__unused__))) +nil_method(id receiver, SEL op, ...) { return receiver; } + + + + diff --git a/gnu/lib/libobjc/libobjc/objc/encoding.h b/gnu/lib/libobjc/libobjc/objc/encoding.h index 36a3d892137..b4def4302b5 100644 --- a/gnu/lib/libobjc/libobjc/objc/encoding.h +++ b/gnu/lib/libobjc/libobjc/objc/encoding.h @@ -1,5 +1,5 @@ /* Encoding of types for Objective C. - Copyright (C) 1993, 1997, 2002 Free Software Foundation, Inc. + Copyright (C) 1993, 1997 Free Software Foundation, Inc. Author: Kresten Krab Thorup @@ -50,30 +50,30 @@ Boston, MA 02111-1307, USA. */ #define _F_ONEWAY 0x10 #define _F_GCINVISIBLE 0x20 -int objc_aligned_size (const char *type); -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); +int objc_aligned_size (const char* type); +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); -int method_get_number_of_arguments (struct objc_method *); -int method_get_sizeof_arguments (struct objc_method *); +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); +int method_get_number_of_arguments (struct objc_method*); +int method_get_sizeof_arguments (struct objc_method*); -char *method_get_first_argument (struct objc_method *, +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_next_argument (arglist_t argframe, const char **type); -char *method_get_nth_argument (struct objc_method *m, +char* method_get_nth_argument (struct objc_method* m, arglist_t argframe, int arg, const char **type); -unsigned objc_get_type_qualifiers (const char *type); +unsigned objc_get_type_qualifiers (const char* type); struct objc_struct_layout diff --git a/gnu/lib/libobjc/libobjc/objc/hash.h b/gnu/lib/libobjc/libobjc/objc/hash.h index 446026c821f..bddb791c820 100644 --- a/gnu/lib/libobjc/libobjc/objc/hash.h +++ b/gnu/lib/libobjc/libobjc/objc/hash.h @@ -29,7 +29,6 @@ Boston, MA 02111-1307, USA. */ #define __hash_INCLUDE_GNU #include <stddef.h> -#include <string.h> #include <objc/objc.h> /* @@ -60,7 +59,7 @@ typedef struct cache_node * typedef. Therefore, to remove compiler warnings the functions passed to * hash_new will have to be casted to this type. */ -typedef unsigned int (*hash_func_type) (void *, const void *); +typedef unsigned int (*hash_func_type)(void *, const void *); /* * This data type is the function that compares two hash keys and returns an @@ -69,7 +68,7 @@ typedef unsigned int (*hash_func_type) (void *, const void *); * second. */ -typedef int (*compare_func_type) (const void *, const void *); +typedef int (*compare_func_type)(const void *, const void *); /* @@ -172,10 +171,10 @@ hash_string (cache_ptr cache, const void *key) { unsigned int ret = 0; unsigned int ctr = 0; - const char *ckey = key; - while (*ckey) { - ret ^= *ckey++ << ctr; + + while (*(char*)key) { + ret ^= *(char*)key++ << ctr; ctr = (ctr + 1) % sizeof (void *); } @@ -187,7 +186,7 @@ hash_string (cache_ptr cache, const void *key) static inline int compare_ptrs (const void *k1, const void *k2) { - return ! (k1 - k2); + return !(k1 - k2); } @@ -200,7 +199,7 @@ compare_strings (const void *k1, const void *k2) else if (k1 == 0 || k2 == 0) return 0; else - return ! strcmp (k1, k2); + return !strcmp (k1, k2); } diff --git a/gnu/lib/libobjc/libobjc/objc/objc-api.h b/gnu/lib/libobjc/libobjc/objc/objc-api.h index 92680209eab..fe34dafb895 100644 --- a/gnu/lib/libobjc/libobjc/objc/objc-api.h +++ b/gnu/lib/libobjc/libobjc/objc/objc-api.h @@ -1,5 +1,5 @@ /* GNU Objective-C Runtime API. - Copyright (C) 1993, 1995, 1996, 1997, 2002 Free Software Foundation, Inc. + Copyright (C) 1993, 1995, 1996, 1997 Free Software Foundation, Inc. This file is part of GNU CC. @@ -75,7 +75,6 @@ struct objc_method_description #define _C_UNION_E ')' #define _C_STRUCT_B '{' #define _C_STRUCT_E '}' -#define _C_VECTOR '!' /* @@ -261,7 +260,7 @@ typedef struct objc_method_list { struct objc_protocol_list { struct objc_protocol_list *next; - size_t count; + int count; Protocol *list[1]; }; @@ -415,13 +414,6 @@ extern void *(*_objc_realloc)(void *, size_t); extern void *(*_objc_calloc)(size_t, size_t); extern void (*_objc_free)(void *); -/* -** Hook for method forwarding. This makes it easy to substitute a -** library, such as ffcall, that implements closures, thereby avoiding -** gcc's __builtin_apply problems. -*/ -extern IMP (*__objc_msg_forward)(SEL); - Method_t class_get_class_method(MetaClass class, SEL aSel); Method_t class_get_instance_method(Class class, SEL aSel); @@ -579,23 +571,21 @@ object_get_super_class } static inline BOOL -object_is_class (id object) +object_is_class(id object) { - return ((object != nil) && CLS_ISMETA (object->class_pointer)); + return CLS_ISCLASS((Class)object); } - + static inline BOOL -object_is_instance (id object) +object_is_instance(id object) { - return ((object != nil) && CLS_ISCLASS (object->class_pointer)); + return (object!=nil)&&CLS_ISCLASS(object->class_pointer); } static inline BOOL -object_is_meta_class (id object) +object_is_meta_class(id object) { - return ((object != nil) - && !object_is_instance (object) - && !object_is_class (object)); + return CLS_ISMETA((Class)object); } struct sarray* diff --git a/gnu/lib/libobjc/libobjc/objc/objc.h b/gnu/lib/libobjc/libobjc/objc/objc.h index 699542c493b..79b2519e576 100644 --- a/gnu/lib/libobjc/libobjc/objc/objc.h +++ b/gnu/lib/libobjc/libobjc/objc/objc.h @@ -73,14 +73,7 @@ typedef struct objc_object { /* ** Definition of method type. When retrieving the implementation of a -** method, this is type of the pointer returned. The idea of the -** definition of IMP is to represent a 'pointer to a general function -** taking an id, a SEL, followed by other unspecified arguments'. You -** must always cast an IMP to a pointer to a function taking the -** appropriate, specific types for that function, before calling it - -** to make sure the appropriate arguments are passed to it. The code -** generated by the compiler to perform method calls automatically -** does this cast inside method calls. +** method, this is type of the pointer returned */ typedef id (*IMP)(id, SEL, ...); diff --git a/gnu/lib/libobjc/libobjc/objc/runtime.h b/gnu/lib/libobjc/libobjc/objc/runtime.h index bea9253a8be..b0eae4a222d 100644 --- a/gnu/lib/libobjc/libobjc/objc/runtime.h +++ b/gnu/lib/libobjc/libobjc/objc/runtime.h @@ -1,5 +1,5 @@ /* GNU Objective C Runtime internal declarations - Copyright (C) 1993, 1995, 1996, 1997, 2002 Free Software Foundation, Inc. + Copyright (C) 1993, 1995, 1996, 1997 Free Software Foundation, Inc. Contributed by Kresten Krab Thorup This file is part of GNU CC. @@ -65,7 +65,7 @@ extern Method_t search_for_method_in_list(MethodList_t list, SEL op); extern BOOL __objc_class_links_resolved; /* Number of selectors stored in each of the selector tables */ -extern unsigned int __objc_selector_max_index; +extern int __objc_selector_max_index; /* Mutex locking __objc_selector_max_index and its arrays. */ extern objc_mutex_t __objc_runtime_mutex; @@ -82,7 +82,6 @@ extern int __objc_runtime_threads_alive; BOOL __objc_responds_to (id object, SEL sel); /* for internal use only! */ SEL __sel_register_typed_name (const char*, const char*, struct objc_selector*, BOOL is_const); -extern void __objc_generate_gc_type_description (Class); #endif /* not __objc_runtime_INCLUDE_GNU */ diff --git a/gnu/lib/libobjc/libobjc/objc/thr.h b/gnu/lib/libobjc/libobjc/objc/thr.h index 48ad0befa0d..f904733695a 100644 --- a/gnu/lib/libobjc/libobjc/objc/thr.h +++ b/gnu/lib/libobjc/libobjc/objc/thr.h @@ -1,5 +1,5 @@ /* Thread and mutex controls for Objective C. - Copyright (C) 1996, 1997, 2002 Free Software Foundation, Inc. + Copyright (C) 1996, 1997 Free Software Foundation, Inc. Contributed by Galen C. Hunt (gchunt@cs.rochester.edu) This file is part of GNU CC. @@ -74,30 +74,28 @@ struct objc_condition typedef struct objc_condition *objc_condition_t; /* Frontend mutex functions */ -objc_mutex_t objc_mutex_allocate (void); -int objc_mutex_deallocate (objc_mutex_t mutex); -int objc_mutex_lock (objc_mutex_t mutex); -int objc_mutex_unlock (objc_mutex_t mutex); -int objc_mutex_trylock (objc_mutex_t mutex); +objc_mutex_t objc_mutex_allocate(void); +int objc_mutex_deallocate(objc_mutex_t mutex); +int objc_mutex_lock(objc_mutex_t mutex); +int objc_mutex_unlock(objc_mutex_t mutex); +int objc_mutex_trylock(objc_mutex_t mutex); /* Frontend condition mutex functions */ -objc_condition_t objc_condition_allocate (void); -int objc_condition_deallocate (objc_condition_t condition); -int objc_condition_wait (objc_condition_t condition, objc_mutex_t mutex); -int objc_condition_signal (objc_condition_t condition); -int objc_condition_broadcast (objc_condition_t condition); +objc_condition_t objc_condition_allocate(void); +int objc_condition_deallocate(objc_condition_t condition); +int objc_condition_wait(objc_condition_t condition, objc_mutex_t mutex); +int objc_condition_signal(objc_condition_t condition); +int objc_condition_broadcast(objc_condition_t condition); /* Frontend thread functions */ -objc_thread_t objc_thread_detach (SEL selector, id object, id argument); -void objc_thread_yield (void); -int objc_thread_exit (void); -int objc_thread_set_priority (int priority); -int objc_thread_get_priority (void); -void * objc_thread_get_data (void); -int objc_thread_set_data (void *value); -objc_thread_t objc_thread_id (void); -void objc_thread_add (void); -void objc_thread_remove (void); +objc_thread_t objc_thread_detach(SEL selector, id object, id argument); +void objc_thread_yield(void); +int objc_thread_exit(void); +int objc_thread_set_priority(int priority); +int objc_thread_get_priority(void); +void * objc_thread_get_data(void); +int objc_thread_set_data(void *value); +objc_thread_t objc_thread_id(void); /* Use this to set the hook function that will be called when the @@ -111,35 +109,35 @@ void objc_thread_remove (void); it can be informed; for example, the GNUstep Base Library sets it so it can implement the NSBecomingMultiThreaded notification. */ -typedef void (*objc_thread_callback) (void); -objc_thread_callback objc_set_thread_callback (objc_thread_callback func); +typedef void (*objc_thread_callback)(); +objc_thread_callback objc_set_thread_callback(objc_thread_callback func); /* Backend initialization functions */ -int __objc_init_thread_system (void); -int __objc_fini_thread_system (void); +int __objc_init_thread_system(void); +int __objc_fini_thread_system(void); /* Backend mutex functions */ -int __objc_mutex_allocate (objc_mutex_t mutex); -int __objc_mutex_deallocate (objc_mutex_t mutex); -int __objc_mutex_lock (objc_mutex_t mutex); -int __objc_mutex_trylock (objc_mutex_t mutex); -int __objc_mutex_unlock (objc_mutex_t mutex); +int __objc_mutex_allocate(objc_mutex_t mutex); +int __objc_mutex_deallocate(objc_mutex_t mutex); +int __objc_mutex_lock(objc_mutex_t mutex); +int __objc_mutex_trylock(objc_mutex_t mutex); +int __objc_mutex_unlock(objc_mutex_t mutex); /* Backend condition mutex functions */ -int __objc_condition_allocate (objc_condition_t condition); -int __objc_condition_deallocate (objc_condition_t condition); -int __objc_condition_wait (objc_condition_t condition, objc_mutex_t mutex); -int __objc_condition_broadcast (objc_condition_t condition); -int __objc_condition_signal (objc_condition_t condition); +int __objc_condition_allocate(objc_condition_t condition); +int __objc_condition_deallocate(objc_condition_t condition); +int __objc_condition_wait(objc_condition_t condition, objc_mutex_t mutex); +int __objc_condition_broadcast(objc_condition_t condition); +int __objc_condition_signal(objc_condition_t condition); /* Backend thread functions */ -objc_thread_t __objc_thread_detach (void (*func) (void *arg), void *arg); -int __objc_thread_set_priority (int priority); -int __objc_thread_get_priority (void); -void __objc_thread_yield (void); -int __objc_thread_exit (void); -objc_thread_t __objc_thread_id (void); -int __objc_thread_set_data (void *value); -void * __objc_thread_get_data (void); +objc_thread_t __objc_thread_detach(void (*func)(void *arg), void *arg); +int __objc_thread_set_priority(int priority); +int __objc_thread_get_priority(void); +void __objc_thread_yield(void); +int __objc_thread_exit(void); +objc_thread_t __objc_thread_id(void); +int __objc_thread_set_data(void *value); +void * __objc_thread_get_data(void); #endif /* not __thread_INCLUDE_GNU */ diff --git a/gnu/lib/libobjc/libobjc/objects.c b/gnu/lib/libobjc/libobjc/objects.c index 6858fed2013..df74b85de87 100644 --- a/gnu/lib/libobjc/libobjc/objects.c +++ b/gnu/lib/libobjc/libobjc/objects.c @@ -32,29 +32,29 @@ Boston, MA 02111-1307, USA. */ # include <gc.h> #endif -id __objc_object_alloc (Class); -id __objc_object_dispose (id); -id __objc_object_copy (id); +id __objc_object_alloc(Class); +id __objc_object_dispose(id); +id __objc_object_copy(id); -id (*_objc_object_alloc) (Class) = __objc_object_alloc; /* !T:SINGLE */ -id (*_objc_object_dispose) (id) = __objc_object_dispose; /* !T:SINGLE */ -id (*_objc_object_copy) (id) = __objc_object_copy; /* !T:SINGLE */ +id (*_objc_object_alloc)(Class) = __objc_object_alloc; /* !T:SINGLE */ +id (*_objc_object_dispose)(id) = __objc_object_dispose; /* !T:SINGLE */ +id (*_objc_object_copy)(id) = __objc_object_copy; /* !T:SINGLE */ id -class_create_instance (Class class) +class_create_instance(Class class) { id new = nil; #if OBJC_WITH_GC - if (CLS_ISCLASS (class)) - new = (id) GC_malloc_explicitly_typed (class->instance_size, - class->gc_object_type); + if (CLS_ISCLASS(class)) + new = (id)GC_malloc_explicitly_typed (class->instance_size, + class->gc_object_type); #else - if (CLS_ISCLASS (class)) - new = (*_objc_object_alloc) (class); + if (CLS_ISCLASS(class)) + new = (*_objc_object_alloc)(class); #endif - if (new != nil) + if (new!=nil) { memset (new, 0, class->instance_size); new->class_pointer = class; @@ -63,41 +63,43 @@ class_create_instance (Class class) } id -object_copy (id object) +object_copy(id object) { - if ((object != nil) && CLS_ISCLASS (object->class_pointer)) - return (*_objc_object_copy) (object); + if ((object!=nil)&&CLS_ISCLASS(object->class_pointer)) + return (*_objc_object_copy)(object); else return nil; } id -object_dispose (id object) +object_dispose(id object) { - if ((object != nil) && CLS_ISCLASS (object->class_pointer)) + if ((object!=nil)&&CLS_ISCLASS(object->class_pointer)) { if (_objc_object_dispose) - (*_objc_object_dispose) (object); + (*_objc_object_dispose)(object); else - objc_free (object); + objc_free(object); } return nil; } -id __objc_object_alloc (Class class) +id __objc_object_alloc(Class class) { - return (id) objc_malloc (class->instance_size); + return (id)objc_malloc(class->instance_size); } -id __objc_object_dispose (id object) +id __objc_object_dispose(id object) { - objc_free (object); + objc_free(object); return 0; } -id __objc_object_copy (id object) +id __objc_object_copy(id object) { - id copy = class_create_instance (object->class_pointer); - memcpy (copy, object, object->class_pointer->instance_size); + id copy = class_create_instance(object->class_pointer); + memcpy(copy, object, object->class_pointer->instance_size); return copy; } + + diff --git a/gnu/lib/libobjc/libobjc/sarray.c b/gnu/lib/libobjc/libobjc/sarray.c index e78e36d01f1..f5ace10bf09 100644 --- a/gnu/lib/libobjc/libobjc/sarray.c +++ b/gnu/lib/libobjc/libobjc/sarray.c @@ -1,5 +1,5 @@ /* Sparse Arrays for Objective C dispatch tables - Copyright (C) 1993, 1995, 1996, 2002 Free Software Foundation, Inc. + Copyright (C) 1993, 1995, 1996 Free Software Foundation, Inc. This file is part of GNU CC. @@ -34,36 +34,40 @@ int nindices = 0; /* !T:MUTEX */ int narrays = 0; /* !T:MUTEX */ int idxsize = 0; /* !T:MUTEX */ -static void *first_free_data = NULL; /* !T:MUTEX */ +static void * first_free_data = NULL; /* !T:MUTEX */ #ifdef OBJC_SPARSE2 -const char *__objc_sparse2_id = "2 level sparse indices"; +const char* __objc_sparse2_id = "2 level sparse indices"; #endif #ifdef OBJC_SPARSE3 -const char *__objc_sparse3_id = "3 level sparse indices"; +const char* __objc_sparse3_id = "3 level sparse indices"; +#endif + +#ifdef __alpha__ +const void *memcpy (void*, const void*, size_t); #endif /* This function removes any structures left over from free operations that were not safe in a multi-threaded environment. */ void -sarray_remove_garbage (void) +sarray_remove_garbage(void) { void **vp; void *np; - objc_mutex_lock (__objc_runtime_mutex); + objc_mutex_lock(__objc_runtime_mutex); vp = first_free_data; first_free_data = NULL; while (vp) { np = *vp; - objc_free (vp); + objc_free(vp); vp = np; } - objc_mutex_unlock (__objc_runtime_mutex); + objc_mutex_unlock(__objc_runtime_mutex); } /* Free a block of dynamically allocated memory. If we are in multi-threaded @@ -71,33 +75,33 @@ sarray_remove_garbage (void) freed later. */ static void -sarray_free_garbage (void *vp) +sarray_free_garbage(void *vp) { - objc_mutex_lock (__objc_runtime_mutex); + objc_mutex_lock(__objc_runtime_mutex); if (__objc_runtime_threads_alive == 1) { - objc_free (vp); + objc_free(vp); if (first_free_data) - sarray_remove_garbage (); + sarray_remove_garbage(); } else { *(void **)vp = first_free_data; first_free_data = vp; } - objc_mutex_unlock (__objc_runtime_mutex); + objc_mutex_unlock(__objc_runtime_mutex); } /* sarray_at_put : copies data in such a way as to be thread reader safe. */ void -sarray_at_put (struct sarray *array, sidx index, void *element) +sarray_at_put(struct sarray* array, sidx index, void* element) { #ifdef OBJC_SPARSE3 - struct sindex **the_index; - struct sindex *new_index; + struct sindex** the_index; + struct sindex* new_index; #endif - struct sbucket **the_bucket; - struct sbucket *new_bucket; + struct sbucket** the_bucket; + struct sbucket* new_bucket; #ifdef OBJC_SPARSE3 size_t ioffset; #endif @@ -122,7 +126,7 @@ sarray_at_put (struct sarray *array, sidx index, void *element) #endif #endif /* not PRECOMPUTE_SELECTORS */ - assert (soffset_decode (index) < array->capacity); /* Range check */ + assert(soffset_decode(index) < array->capacity); /* Range check */ #ifdef OBJC_SPARSE3 the_index = &(array->indices[ioffset]); @@ -141,8 +145,8 @@ sarray_at_put (struct sarray *array, sidx index, void *element) if ((*the_index) == array->empty_index) { /* The index was previously empty, allocate a new */ - new_index = (struct sindex *) objc_malloc (sizeof (struct sindex)); - memcpy (new_index, array->empty_index, sizeof (struct sindex)); + new_index = (struct sindex*)objc_malloc(sizeof(struct sindex)); + memcpy(new_index, array->empty_index, sizeof(struct sindex)); new_index->version.version = array->version.version; *the_index = new_index; /* Prepared for install. */ the_bucket = &((*the_index)->buckets[boffset]); @@ -151,9 +155,9 @@ sarray_at_put (struct sarray *array, sidx index, void *element) } else if ((*the_index)->version.version != array->version.version) { /* This index must be lazy copied */ - struct sindex *old_index = *the_index; - new_index = (struct sindex *) objc_malloc (sizeof (struct sindex)); - memcpy (new_index, old_index, sizeof (struct sindex)); + struct sindex* old_index = *the_index; + new_index = (struct sindex*)objc_malloc(sizeof(struct sindex)); + memcpy( new_index, old_index, sizeof(struct sindex)); new_index->version.version = array->version.version; *the_index = new_index; /* Prepared for install. */ the_bucket = &((*the_index)->buckets[boffset]); @@ -169,9 +173,9 @@ sarray_at_put (struct sarray *array, sidx index, void *element) /* The bucket was previously empty (or something like that), */ /* allocate a new. This is the effect of `lazy' allocation */ - new_bucket = (struct sbucket *) objc_malloc (sizeof (struct sbucket)); - memcpy ((void *) new_bucket, (const void *) array->empty_bucket, - sizeof (struct sbucket)); + new_bucket = (struct sbucket*)objc_malloc(sizeof(struct sbucket)); + memcpy((void *) new_bucket, (const void*)array->empty_bucket, + sizeof(struct sbucket)); new_bucket->version.version = array->version.version; *the_bucket = new_bucket; /* Prepared for install. */ @@ -180,9 +184,9 @@ sarray_at_put (struct sarray *array, sidx index, void *element) } else if ((*the_bucket)->version.version != array->version.version) { /* Perform lazy copy. */ - struct sbucket *old_bucket = *the_bucket; - new_bucket = (struct sbucket *) objc_malloc (sizeof (struct sbucket)); - memcpy (new_bucket, old_bucket, sizeof (struct sbucket)); + struct sbucket* old_bucket = *the_bucket; + new_bucket = (struct sbucket*)objc_malloc(sizeof(struct sbucket)); + memcpy( new_bucket, old_bucket, sizeof(struct sbucket)); new_bucket->version.version = array->version.version; *the_bucket = new_bucket; /* Prepared for install. */ @@ -193,39 +197,39 @@ sarray_at_put (struct sarray *array, sidx index, void *element) } void -sarray_at_put_safe (struct sarray *array, sidx index, void *element) +sarray_at_put_safe(struct sarray* array, sidx index, void* element) { - if (soffset_decode (index) >= array->capacity) - sarray_realloc (array, soffset_decode (index) + 1); - sarray_at_put (array, index, element); + if(soffset_decode(index) >= array->capacity) + sarray_realloc(array, soffset_decode(index)+1); + sarray_at_put(array, index, element); } -struct sarray * -sarray_new (int size, void *default_element) +struct sarray* +sarray_new (int size, void* default_element) { - struct sarray *arr; + struct sarray* arr; #ifdef OBJC_SPARSE3 - size_t num_indices = ((size - 1)/(INDEX_CAPACITY)) + 1; - struct sindex **new_indices; + size_t num_indices = ((size-1)/(INDEX_CAPACITY))+1; + struct sindex ** new_indices; #else /* OBJC_SPARSE2 */ - size_t num_indices = ((size - 1)/BUCKET_SIZE) + 1; - struct sbucket **new_buckets; + size_t num_indices = ((size-1)/BUCKET_SIZE)+1; + struct sbucket ** new_buckets; #endif - size_t counter; + int counter; - assert (size > 0); + assert(size > 0); /* Allocate core array */ - arr = (struct sarray *) objc_malloc (sizeof (struct sarray)); + arr = (struct sarray*) objc_malloc(sizeof(struct sarray)); arr->version.version = 0; /* Initialize members */ #ifdef OBJC_SPARSE3 arr->capacity = num_indices*INDEX_CAPACITY; - new_indices = (struct sindex **) - objc_malloc (sizeof (struct sindex *) * num_indices); + new_indices = (struct sindex**) + objc_malloc(sizeof(struct sindex*)*num_indices); - arr->empty_index = (struct sindex *) objc_malloc (sizeof (struct sindex)); + arr->empty_index = (struct sindex*) objc_malloc(sizeof(struct sindex)); arr->empty_index->version.version = 0; narrays += 1; @@ -234,35 +238,35 @@ sarray_new (int size, void *default_element) #else /* OBJC_SPARSE2 */ arr->capacity = num_indices*BUCKET_SIZE; - new_buckets = (struct sbucket **) - objc_malloc (sizeof (struct sbucket *) * num_indices); + new_buckets = (struct sbucket**) + objc_malloc(sizeof(struct sbucket*)*num_indices); narrays += 1; idxsize += num_indices; #endif - arr->empty_bucket = (struct sbucket *) objc_malloc (sizeof (struct sbucket)); + arr->empty_bucket = (struct sbucket*) objc_malloc(sizeof(struct sbucket)); arr->empty_bucket->version.version = 0; nbuckets += 1; arr->ref_count = 1; - arr->is_copy_of = (struct sarray *) 0; + arr->is_copy_of = (struct sarray*)0; - for (counter = 0; counter < BUCKET_SIZE; counter++) + for (counter=0; counter<BUCKET_SIZE; counter++) arr->empty_bucket->elems[counter] = default_element; #ifdef OBJC_SPARSE3 - for (counter = 0; counter < INDEX_SIZE; counter++) + for (counter=0; counter<INDEX_SIZE; counter++) arr->empty_index->buckets[counter] = arr->empty_bucket; - for (counter = 0; counter < num_indices; counter++) + for (counter=0; counter<num_indices; counter++) new_indices[counter] = arr->empty_index; #else /* OBJC_SPARSE2 */ - for (counter = 0; counter < num_indices; counter++) + for (counter=0; counter<num_indices; counter++) new_buckets[counter] = arr->empty_bucket; #endif @@ -282,48 +286,48 @@ sarray_new (int size, void *default_element) any concurrent readers notice the update. */ void -sarray_realloc (struct sarray *array, int newsize) +sarray_realloc(struct sarray* array, int newsize) { #ifdef OBJC_SPARSE3 - size_t old_max_index = (array->capacity - 1)/INDEX_CAPACITY; - size_t new_max_index = ((newsize - 1)/INDEX_CAPACITY); - size_t rounded_size = (new_max_index + 1) * INDEX_CAPACITY; + size_t old_max_index = (array->capacity-1)/INDEX_CAPACITY; + size_t new_max_index = ((newsize-1)/INDEX_CAPACITY); + size_t rounded_size = (new_max_index+1)*INDEX_CAPACITY; - struct sindex **new_indices; - struct sindex **old_indices; + struct sindex ** new_indices; + struct sindex ** old_indices; #else /* OBJC_SPARSE2 */ - size_t old_max_index = (array->capacity - 1)/BUCKET_SIZE; - size_t new_max_index = ((newsize - 1)/BUCKET_SIZE); - size_t rounded_size = (new_max_index + 1) * BUCKET_SIZE; + size_t old_max_index = (array->capacity-1)/BUCKET_SIZE; + size_t new_max_index = ((newsize-1)/BUCKET_SIZE); + size_t rounded_size = (new_max_index+1)*BUCKET_SIZE; - struct sbucket **new_buckets; - struct sbucket **old_buckets; + struct sbucket ** new_buckets; + struct sbucket ** old_buckets; #endif - size_t counter; + int counter; - assert (newsize > 0); + assert(newsize > 0); /* The size is the same, just ignore the request */ - if (rounded_size <= array->capacity) + if(rounded_size <= array->capacity) return; - assert (array->ref_count == 1); /* stop if lazy copied... */ + assert(array->ref_count == 1); /* stop if lazy copied... */ /* We are asked to extend the array -- allocate new bucket table, */ /* and insert empty_bucket in newly allocated places. */ - if (rounded_size > array->capacity) + if(rounded_size > array->capacity) { #ifdef OBJC_SPARSE3 new_max_index += 4; - rounded_size = (new_max_index + 1) * INDEX_CAPACITY; + rounded_size = (new_max_index+1)*INDEX_CAPACITY; #else /* OBJC_SPARSE2 */ new_max_index += 4; - rounded_size = (new_max_index + 1) * BUCKET_SIZE; + rounded_size = (new_max_index+1)*BUCKET_SIZE; #endif /* update capacity */ @@ -332,16 +336,16 @@ sarray_realloc (struct sarray *array, int newsize) #ifdef OBJC_SPARSE3 /* alloc to force re-read by any concurrent readers. */ old_indices = array->indices; - new_indices = (struct sindex **) - objc_malloc ((new_max_index + 1) * sizeof (struct sindex *)); + new_indices = (struct sindex**) + objc_malloc((new_max_index+1)*sizeof(struct sindex*)); #else /* OBJC_SPARSE2 */ old_buckets = array->buckets; - new_buckets = (struct sbucket **) - objc_malloc ((new_max_index + 1) * sizeof (struct sbucket *)); + new_buckets = (struct sbucket**) + objc_malloc((new_max_index+1)*sizeof(struct sbucket*)); #endif /* copy buckets below old_max_index (they are still valid) */ - for (counter = 0; counter <= old_max_index; counter++ ) { + for(counter = 0; counter <= old_max_index; counter++ ) { #ifdef OBJC_SPARSE3 new_indices[counter] = old_indices[counter]; #else /* OBJC_SPARSE2 */ @@ -351,11 +355,11 @@ sarray_realloc (struct sarray *array, int newsize) #ifdef OBJC_SPARSE3 /* reset entries above old_max_index to empty_bucket */ - for (counter = old_max_index + 1; counter <= new_max_index; counter++) + for(counter = old_max_index+1; counter <= new_max_index; counter++) new_indices[counter] = array->empty_index; #else /* OBJC_SPARSE2 */ /* reset entries above old_max_index to empty_bucket */ - for (counter = old_max_index + 1; counter <= new_max_index; counter++) + for(counter = old_max_index+1; counter <= new_max_index; counter++) new_buckets[counter] = array->empty_bucket; #endif @@ -368,9 +372,9 @@ sarray_realloc (struct sarray *array, int newsize) #ifdef OBJC_SPARSE3 /* free the old indices */ - sarray_free_garbage (old_indices); + sarray_free_garbage(old_indices); #else /* OBJC_SPARSE2 */ - sarray_free_garbage (old_buckets); + sarray_free_garbage(old_buckets); #endif idxsize += (new_max_index-old_max_index); @@ -382,19 +386,20 @@ sarray_realloc (struct sarray *array, int newsize) /* Free a sparse array allocated with sarray_new */ void -sarray_free (struct sarray *array) { +sarray_free(struct sarray* array) { + #ifdef OBJC_SPARSE3 - size_t old_max_index = (array->capacity - 1)/INDEX_CAPACITY; - struct sindex **old_indices; + size_t old_max_index = (array->capacity-1)/INDEX_CAPACITY; + struct sindex ** old_indices; #else - size_t old_max_index = (array->capacity - 1)/BUCKET_SIZE; - struct sbucket **old_buckets; + size_t old_max_index = (array->capacity-1)/BUCKET_SIZE; + struct sbucket ** old_buckets; #endif - size_t counter = 0; + int counter = 0; - assert (array->ref_count != 0); /* Freed multiple times!!! */ + assert(array->ref_count != 0); /* Freed multiple times!!! */ - if (--(array->ref_count) != 0) /* There exists copies of me */ + if(--(array->ref_count) != 0) /* There exists copies of me */ return; #ifdef OBJC_SPARSE3 @@ -403,34 +408,34 @@ sarray_free (struct sarray *array) { old_buckets = array->buckets; #endif - if ((array->is_copy_of) && ((array->is_copy_of->ref_count - 1) == 0)) - sarray_free (array->is_copy_of); + if((array->is_copy_of) && ((array->is_copy_of->ref_count - 1) == 0)) + sarray_free(array->is_copy_of); /* Free all entries that do not point to empty_bucket */ - for (counter = 0; counter <= old_max_index; counter++ ) { + for(counter = 0; counter <= old_max_index; counter++ ) { #ifdef OBJC_SPARSE3 - struct sindex *idx = old_indices[counter]; - if ((idx != array->empty_index) && + struct sindex* idx = old_indices[counter]; + if((idx != array->empty_index) && (idx->version.version == array->version.version)) { int c2; - for (c2 = 0; c2 < INDEX_SIZE; c2++) { - struct sbucket *bkt = idx->buckets[c2]; - if ((bkt != array->empty_bucket) && + for(c2=0; c2<INDEX_SIZE; c2++) { + struct sbucket* bkt = idx->buckets[c2]; + if((bkt != array->empty_bucket) && (bkt->version.version == array->version.version)) { - sarray_free_garbage (bkt); + sarray_free_garbage(bkt); nbuckets -= 1; } } - sarray_free_garbage (idx); + sarray_free_garbage(idx); nindices -= 1; } #else /* OBJC_SPARSE2 */ - struct sbucket *bkt = array->buckets[counter]; + struct sbucket* bkt = array->buckets[counter]; if ((bkt != array->empty_bucket) && (bkt->version.version == array->version.version)) { - sarray_free_garbage (bkt); + sarray_free_garbage(bkt); nbuckets -= 1; } #endif @@ -438,52 +443,52 @@ sarray_free (struct sarray *array) { #ifdef OBJC_SPARSE3 /* free empty_index */ - if (array->empty_index->version.version == array->version.version) { - sarray_free_garbage (array->empty_index); + if(array->empty_index->version.version == array->version.version) { + sarray_free_garbage(array->empty_index); nindices -= 1; } #endif /* free empty_bucket */ - if (array->empty_bucket->version.version == array->version.version) { - sarray_free_garbage (array->empty_bucket); + if(array->empty_bucket->version.version == array->version.version) { + sarray_free_garbage(array->empty_bucket); nbuckets -= 1; } - idxsize -= (old_max_index + 1); + idxsize -= (old_max_index+1); narrays -= 1; #ifdef OBJC_SPARSE3 /* free bucket table */ - sarray_free_garbage (array->indices); + sarray_free_garbage(array->indices); #else /* free bucket table */ - sarray_free_garbage (array->buckets); + sarray_free_garbage(array->buckets); #endif /* free array */ - sarray_free_garbage (array); + sarray_free_garbage(array); } /* This is a lazy copy. Only the core of the structure is actually */ /* copied. */ -struct sarray * -sarray_lazy_copy (struct sarray *oarr) +struct sarray* +sarray_lazy_copy(struct sarray* oarr) { - struct sarray *arr; + struct sarray* arr; #ifdef OBJC_SPARSE3 - size_t num_indices = ((oarr->capacity - 1)/INDEX_CAPACITY) + 1; - struct sindex **new_indices; + size_t num_indices = ((oarr->capacity-1)/INDEX_CAPACITY)+1; + struct sindex ** new_indices; #else /* OBJC_SPARSE2 */ - size_t num_indices = ((oarr->capacity - 1)/BUCKET_SIZE) + 1; - struct sbucket **new_buckets; + size_t num_indices = ((oarr->capacity-1)/BUCKET_SIZE)+1; + struct sbucket ** new_buckets; #endif /* Allocate core array */ - arr = (struct sarray *) objc_malloc (sizeof (struct sarray)); /* !!! */ + arr = (struct sarray*) objc_malloc(sizeof(struct sarray)); /* !!! */ arr->version.version = oarr->version.version + 1; #ifdef OBJC_SPARSE3 arr->empty_index = oarr->empty_index; @@ -496,15 +501,17 @@ sarray_lazy_copy (struct sarray *oarr) #ifdef OBJC_SPARSE3 /* Copy bucket table */ - new_indices = (struct sindex **) - objc_malloc (sizeof (struct sindex *) * num_indices); - memcpy (new_indices, oarr->indices, sizeof (struct sindex *) * num_indices); + new_indices = (struct sindex**) + objc_malloc(sizeof(struct sindex*)*num_indices); + memcpy( new_indices,oarr->indices, + sizeof(struct sindex*)*num_indices); arr->indices = new_indices; #else /* Copy bucket table */ - new_buckets = (struct sbucket **) - objc_malloc (sizeof (struct sbucket *) * num_indices); - memcpy (new_buckets, oarr->buckets, sizeof (struct sbucket *) * num_indices); + new_buckets = (struct sbucket**) + objc_malloc(sizeof(struct sbucket*)*num_indices); + memcpy( new_buckets,oarr->buckets, + sizeof(struct sbucket*)*num_indices); arr->buckets = new_buckets; #endif diff --git a/gnu/lib/libobjc/libobjc/selector.c b/gnu/lib/libobjc/libobjc/selector.c index 5f5a26bc9af..470a2c48cdd 100644 --- a/gnu/lib/libobjc/libobjc/selector.c +++ b/gnu/lib/libobjc/libobjc/selector.c @@ -1,5 +1,5 @@ /* GNU Objective C Runtime selector related functions - Copyright (C) 1993, 1995, 1996, 1997, 2002 Free Software Foundation, Inc. + Copyright (C) 1993, 1995, 1996, 1997 Free Software Foundation, Inc. Contributed by Kresten Krab Thorup This file is part of GNU CC. @@ -31,16 +31,16 @@ Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #define SELECTOR_HASH_SIZE 128 /* Tables mapping selector names to uid and opposite */ -static struct sarray *__objc_selector_array = 0; /* uid -> sel !T:MUTEX */ -static struct sarray *__objc_selector_names = 0; /* uid -> name !T:MUTEX */ +static struct sarray* __objc_selector_array = 0; /* uid -> sel !T:MUTEX */ +static struct sarray* __objc_selector_names = 0; /* uid -> name !T:MUTEX */ static cache_ptr __objc_selector_hash = 0; /* name -> uid !T:MUTEX */ -static void register_selectors_from_list (MethodList_t); +static void register_selectors_from_list(MethodList_t); /* Number of selectors stored in each of the above tables */ -unsigned int __objc_selector_max_index = 0; /* !T:MUTEX */ +int __objc_selector_max_index = 0; /* !T:MUTEX */ -void __objc_init_selector_tables () +void __objc_init_selector_tables() { __objc_selector_array = sarray_new (SELECTOR_HASH_SIZE, 0); __objc_selector_names = sarray_new (SELECTOR_HASH_SIZE, 0); @@ -81,15 +81,15 @@ register_selectors_from_list (MethodList_t method_list) { Method_t method = &method_list->method_list[i]; method->method_name - = sel_register_typed_name ((const char *) method->method_name, - method->method_types); + = sel_register_typed_name ((const char*)method->method_name, + method->method_types); i += 1; } } /* Register instance methods as class methods for root classes */ -void __objc_register_instance_methods_to_class (Class class) +void __objc_register_instance_methods_to_class(Class class) { MethodList_t method_list; MethodList_t class_method_list; @@ -98,12 +98,12 @@ void __objc_register_instance_methods_to_class (Class class) Method_t curr_method; /* Only if a root class. */ - if (class->super_class) + if(class->super_class) return; /* Allocate a method list to hold the new class methods */ - new_list = objc_calloc (sizeof (struct objc_method_list) - + sizeof (struct objc_method[max_methods_no]), 1); + new_list = objc_calloc(sizeof(struct objc_method_list) + + sizeof(struct objc_method[max_methods_no]), 1); method_list = class->methods; class_method_list = class->class_pointer->methods; curr_method = &new_list->method_list[0]; @@ -118,7 +118,7 @@ void __objc_register_instance_methods_to_class (Class class) { Method_t mth = &method_list->method_list[i]; if (mth->method_name - && ! search_for_method_in_list (class_method_list, + && !search_for_method_in_list (class_method_list, mth->method_name)) { /* This instance method isn't a class method. @@ -126,10 +126,10 @@ void __objc_register_instance_methods_to_class (Class class) *curr_method = *mth; /* Reallocate the method list if necessary */ - if (++new_list->method_count == max_methods_no) + if(++new_list->method_count == max_methods_no) new_list = - objc_realloc (new_list, sizeof (struct objc_method_list) - + sizeof (struct + objc_realloc(new_list, sizeof(struct objc_method_list) + + sizeof(struct objc_method[max_methods_no += 16])); curr_method = &new_list->method_list[new_list->method_count]; } @@ -143,8 +143,8 @@ void __objc_register_instance_methods_to_class (Class class) if (new_list->method_count) { new_list = - objc_realloc (new_list, sizeof (struct objc_method_list) - + sizeof (struct objc_method[new_list->method_count])); + objc_realloc(new_list, sizeof(struct objc_method_list) + + sizeof(struct objc_method[new_list->method_count])); new_list->method_next = class->class_pointer->methods; class->class_pointer->methods = new_list; } @@ -156,21 +156,21 @@ void __objc_register_instance_methods_to_class (Class class) /* Returns YES iff t1 and t2 have same method types, but we ignore the argframe layout */ BOOL -sel_types_match (const char *t1, const char *t2) +sel_types_match (const char* t1, const char* t2) { - if (! t1 || ! t2) + if (!t1 || !t2) return NO; while (*t1 && *t2) { if (*t1 == '+') t1++; if (*t2 == '+') t2++; - while (isdigit ((unsigned char) *t1)) t1++; - while (isdigit ((unsigned char) *t2)) t2++; + while (isdigit(*t1)) t1++; + while (isdigit(*t2)) t2++; /* xxx Remove these next two lines when qualifiers are put in all selectors, not just Protocol selectors. */ - t1 = objc_skip_type_qualifiers (t1); - t2 = objc_skip_type_qualifiers (t2); - if (! *t1 && ! *t2) + t1 = objc_skip_type_qualifiers(t1); + t2 = objc_skip_type_qualifiers(t2); + if (!*t1 && !*t2) return YES; if (*t1 != *t2) return NO; @@ -187,35 +187,35 @@ sel_get_typed_uid (const char *name, const char *types) struct objc_list *l; sidx i; - objc_mutex_lock (__objc_runtime_mutex); + objc_mutex_lock(__objc_runtime_mutex); i = (sidx) hash_value_for_key (__objc_selector_hash, name); if (i == 0) { - objc_mutex_unlock (__objc_runtime_mutex); + objc_mutex_unlock(__objc_runtime_mutex); return 0; } - for (l = (struct objc_list *) sarray_get_safe (__objc_selector_array, i); + for (l = (struct objc_list*)sarray_get_safe (__objc_selector_array, i); l; l = l->tail) { - SEL s = (SEL) l->head; + SEL s = (SEL)l->head; if (types == 0 || s->sel_types == 0) { if (s->sel_types == types) { - objc_mutex_unlock (__objc_runtime_mutex); + objc_mutex_unlock(__objc_runtime_mutex); return s; } } else if (sel_types_match (s->sel_types, types)) { - objc_mutex_unlock (__objc_runtime_mutex); + objc_mutex_unlock(__objc_runtime_mutex); return s; } } - objc_mutex_unlock (__objc_runtime_mutex); + objc_mutex_unlock(__objc_runtime_mutex); return 0; } @@ -227,27 +227,27 @@ sel_get_any_typed_uid (const char *name) sidx i; SEL s = NULL; - objc_mutex_lock (__objc_runtime_mutex); + objc_mutex_lock(__objc_runtime_mutex); i = (sidx) hash_value_for_key (__objc_selector_hash, name); if (i == 0) { - objc_mutex_unlock (__objc_runtime_mutex); + objc_mutex_unlock(__objc_runtime_mutex); return 0; } - for (l = (struct objc_list *) sarray_get_safe (__objc_selector_array, i); + 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); + objc_mutex_unlock(__objc_runtime_mutex); return s; } } - objc_mutex_unlock (__objc_runtime_mutex); + objc_mutex_unlock(__objc_runtime_mutex); return s; } @@ -258,22 +258,22 @@ sel_get_any_uid (const char *name) struct objc_list *l; sidx i; - objc_mutex_lock (__objc_runtime_mutex); + objc_mutex_lock(__objc_runtime_mutex); i = (sidx) hash_value_for_key (__objc_selector_hash, name); if (soffset_decode (i) == 0) { - objc_mutex_unlock (__objc_runtime_mutex); + objc_mutex_unlock(__objc_runtime_mutex); return 0; } - l = (struct objc_list *) sarray_get_safe (__objc_selector_array, i); - objc_mutex_unlock (__objc_runtime_mutex); + l = (struct objc_list*)sarray_get_safe (__objc_selector_array, i); + objc_mutex_unlock(__objc_runtime_mutex); if (l == 0) return 0; - return (SEL) l->head; + return (SEL)l->head; } /* return selector representing name */ @@ -285,17 +285,18 @@ sel_get_uid (const char *name) /* Get name of selector. If selector is unknown, the empty string "" is returned */ -const char *sel_get_name (SEL selector) +const char* +sel_get_name (SEL selector) { const char *ret; - objc_mutex_lock (__objc_runtime_mutex); - if ((soffset_decode ((sidx)selector->sel_id) > 0) - && (soffset_decode ((sidx)selector->sel_id) <= __objc_selector_max_index)) + objc_mutex_lock(__objc_runtime_mutex); + if ((soffset_decode((sidx)selector->sel_id) > 0) + && (soffset_decode((sidx)selector->sel_id) <= __objc_selector_max_index)) ret = sarray_get_safe (__objc_selector_names, (sidx) selector->sel_id); else ret = 0; - objc_mutex_unlock (__objc_runtime_mutex); + objc_mutex_unlock(__objc_runtime_mutex); return ret; } @@ -307,7 +308,8 @@ sel_is_mapped (SEL selector) } -const char *sel_get_type (SEL selector) +const char* +sel_get_type (SEL selector) { if (selector) return selector->sel_types; @@ -316,7 +318,7 @@ const char *sel_get_type (SEL selector) } /* The uninstalled dispatch table */ -extern struct sarray *__objc_uninstalled_dtable; +extern struct sarray* __objc_uninstalled_dtable; /* Store the passed selector name in the selector record and return its selector value (value returned by sel_get_uid). @@ -329,35 +331,35 @@ SEL __sel_register_typed_name (const char *name, const char *types, struct objc_selector *orig, BOOL is_const) { - struct objc_selector *j; + struct objc_selector* j; sidx i; struct objc_list *l; i = (sidx) hash_value_for_key (__objc_selector_hash, name); if (soffset_decode (i) != 0) { - for (l = (struct objc_list *) sarray_get_safe (__objc_selector_array, i); + for (l = (struct objc_list*)sarray_get_safe (__objc_selector_array, i); l; l = l->tail) { - SEL s = (SEL) l->head; + SEL s = (SEL)l->head; if (types == 0 || s->sel_types == 0) { if (s->sel_types == types) { if (orig) { - orig->sel_id = (void *) i; + orig->sel_id = (void*)i; return orig; } else return s; } } - else if (! strcmp (s->sel_types, types)) + else if (!strcmp (s->sel_types, types)) { if (orig) { - orig->sel_id = (void *) i; + orig->sel_id = (void*)i; return orig; } else @@ -369,32 +371,32 @@ __sel_register_typed_name (const char *name, const char *types, else j = objc_malloc (sizeof (struct objc_selector)); - j->sel_id = (void *) i; + j->sel_id = (void*)i; /* Can we use the pointer or must copy types? Don't copy if NULL */ if ((is_const) || (types == 0)) - j->sel_types = (const char *) types; + j->sel_types = (const char*)types; else { - j->sel_types = (char *) objc_malloc (strlen (types) + 1); - strcpy ((char *) j->sel_types, types); + j->sel_types = (char *) objc_malloc(strlen(types)+1); + strcpy((char *)j->sel_types, types); } - l = (struct objc_list *) sarray_get_safe (__objc_selector_array, i); + l = (struct objc_list*)sarray_get_safe (__objc_selector_array, i); } else { __objc_selector_max_index += 1; - i = soffset_encode (__objc_selector_max_index); + i = soffset_encode(__objc_selector_max_index); if (orig) j = orig; else j = objc_malloc (sizeof (struct objc_selector)); - j->sel_id = (void *) i; + j->sel_id = (void*)i; /* Can we use the pointer or must copy types? Don't copy if NULL */ if ((is_const) || (types == 0)) - j->sel_types = (const char *) types; + j->sel_types = (const char*)types; else { - j->sel_types = (char *) objc_malloc (strlen (types) + 1); - strcpy ((char *) j->sel_types, types); + j->sel_types = (char *) objc_malloc(strlen(types)+1); + strcpy((char *)j->sel_types, types); } l = 0; } @@ -410,18 +412,18 @@ __sel_register_typed_name (const char *name, const char *types, if ((is_const) || (name == 0)) new_name = name; else { - new_name = (char *) objc_malloc (strlen (name) + 1); - strcpy ((char *) new_name, name); + new_name = (char *) objc_malloc(strlen(name)+1); + strcpy((char *)new_name, name); } - l = list_cons ((void *) j, l); + l = list_cons ((void*)j, l); sarray_at_put_safe (__objc_selector_names, i, (void *) new_name); sarray_at_put_safe (__objc_selector_array, i, (void *) l); if (is_new) hash_add (&__objc_selector_hash, (void *) new_name, (void *) i); } - sarray_realloc (__objc_uninstalled_dtable, __objc_selector_max_index + 1); + sarray_realloc(__objc_uninstalled_dtable, __objc_selector_max_index+1); return (SEL) j; } @@ -431,11 +433,11 @@ sel_register_name (const char *name) { SEL ret; - objc_mutex_lock (__objc_runtime_mutex); + objc_mutex_lock(__objc_runtime_mutex); /* Assume that name is not constant static memory and needs to be copied before put into a runtime structure. is_const == NO */ ret = __sel_register_typed_name (name, 0, 0, NO); - objc_mutex_unlock (__objc_runtime_mutex); + objc_mutex_unlock(__objc_runtime_mutex); return ret; } @@ -445,11 +447,12 @@ sel_register_typed_name (const char *name, const char *type) { SEL ret; - objc_mutex_lock (__objc_runtime_mutex); + objc_mutex_lock(__objc_runtime_mutex); /* Assume that name and type are not constant static memory and need to be copied before put into a runtime structure. is_const == NO */ ret = __sel_register_typed_name (name, type, 0, NO); - objc_mutex_unlock (__objc_runtime_mutex); + objc_mutex_unlock(__objc_runtime_mutex); return ret; } + diff --git a/gnu/lib/libobjc/libobjc/sendmsg.c b/gnu/lib/libobjc/libobjc/sendmsg.c index 6ef711b50d3..a4aa4709c7c 100644 --- a/gnu/lib/libobjc/libobjc/sendmsg.c +++ b/gnu/lib/libobjc/libobjc/sendmsg.c @@ -1,6 +1,5 @@ /* GNU Objective C Runtime message lookup - Copyright (C) 1993, 1995, 1996, 1997, 1998, - 2001, 2002 Free Software Foundation, Inc. + Copyright (C) 1993, 1995, 1996, 1997, 1998 Free Software Foundation, Inc. Contributed by Kresten Krab Thorup This file is part of GNU CC. @@ -34,30 +33,24 @@ Boston, MA 02111-1307, USA. */ /* this is how we hack STRUCT_VALUE to be 1 or 0 */ #define gen_rtx(args...) 1 #define gen_rtx_MEM(args...) 1 -#define gen_rtx_REG(args...) 1 #define rtx int -#if ! defined (STRUCT_VALUE) || STRUCT_VALUE == 0 +#if !defined(STRUCT_VALUE) || STRUCT_VALUE == 0 #define INVISIBLE_STRUCT_RETURN 1 #else #define INVISIBLE_STRUCT_RETURN 0 #endif /* The uninstalled dispatch table */ -struct sarray *__objc_uninstalled_dtable = 0; /* !T:MUTEX */ - -/* Hook for method forwarding. If it is set, is invoked to return a - function that performs the real forwarding. Otherwise the libgcc - based functions (__builtin_apply and friends) are used. */ -IMP (*__objc_msg_forward) (SEL) = NULL; +struct sarray* __objc_uninstalled_dtable = 0; /* !T:MUTEX */ /* Send +initialize to class */ -static void __objc_send_initialize (Class); +static void __objc_send_initialize(Class); static void __objc_install_dispatch_table_for_class (Class); /* Forward declare some functions */ -static void __objc_init_install_dtable (id, SEL); +static void __objc_init_install_dtable(id, SEL); /* Various forwarding functions that are used based upon the return type for the selector. @@ -65,49 +58,36 @@ static void __objc_init_install_dtable (id, SEL); __objc_double_forward for floats/doubles. __objc_word_forward for pointers or types that fit in registers. */ -static double __objc_double_forward (id, SEL, ...); -static id __objc_word_forward (id, SEL, ...); +static double __objc_double_forward(id, SEL, ...); +static id __objc_word_forward(id, SEL, ...); typedef struct { id many[8]; } __big; #if INVISIBLE_STRUCT_RETURN static __big #else static id #endif -__objc_block_forward (id, SEL, ...); +__objc_block_forward(id, SEL, ...); static Method_t search_for_method_in_hierarchy (Class class, SEL sel); -Method_t search_for_method_in_list (MethodList_t list, SEL op); -id nil_method (id, SEL); +Method_t search_for_method_in_list(MethodList_t list, SEL op); +id nil_method(id, SEL, ...); /* Given a selector, return the proper forwarding implementation. */ __inline__ IMP __objc_get_forward_imp (SEL sel) { - /* If a custom forwarding hook was registered, try getting a forwarding - * function from it. */ - if (__objc_msg_forward) - { - IMP result; - if ((result = __objc_msg_forward (sel)) != NULL) - return result; - } - - /* In all other cases, use the default forwarding functions built using - * __builtin_apply and friends. */ - { - const char *t = sel->sel_types; + const char *t = sel->sel_types; - if (t && (*t == '[' || *t == '(' || *t == '{') + if (t && (*t == '[' || *t == '(' || *t == '{') #ifdef OBJC_MAX_STRUCT_BY_VALUE - && objc_sizeof_type (t) > OBJC_MAX_STRUCT_BY_VALUE + && objc_sizeof_type(t) > OBJC_MAX_STRUCT_BY_VALUE #endif - ) - return (IMP)__objc_block_forward; - else if (t && (*t == 'f' || *t == 'd')) - return (IMP)__objc_double_forward; - else - return (IMP)__objc_word_forward; - } + ) + return (IMP)__objc_block_forward; + else if (t && (*t == 'f' || *t == 'd')) + return (IMP)__objc_double_forward; + else + return (IMP)__objc_word_forward; } /* Given a class and selector, return the selector's implementation. */ @@ -115,26 +95,26 @@ __inline__ IMP get_imp (Class class, SEL sel) { - void *res = sarray_get_safe (class->dtable, (size_t) sel->sel_id); + 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) + if(class->dtable == __objc_uninstalled_dtable) { /* The dispatch table needs to be installed. */ - objc_mutex_lock (__objc_runtime_mutex); + objc_mutex_lock(__objc_runtime_mutex); __objc_install_dispatch_table_for_class (class); - objc_mutex_unlock (__objc_runtime_mutex); + objc_mutex_unlock(__objc_runtime_mutex); /* Call ourselves with the installed dispatch table and get the real method */ - res = get_imp (class, sel); + res = get_imp(class, sel); } else { /* The dispatch table has been installed so the method just doesn't exist for the class. Return the forwarding implementation. */ - res = __objc_get_forward_imp (sel); + res = __objc_get_forward_imp(sel); } } return res; @@ -147,14 +127,14 @@ __inline__ BOOL __objc_responds_to (id object, SEL sel) { - void *res; + void* res; /* Install dispatch table if need be */ if (object->class_pointer->dtable == __objc_uninstalled_dtable) { - objc_mutex_lock (__objc_runtime_mutex); + objc_mutex_lock(__objc_runtime_mutex); __objc_install_dispatch_table_for_class (object->class_pointer); - objc_mutex_unlock (__objc_runtime_mutex); + objc_mutex_unlock(__objc_runtime_mutex); } /* Get the method from the dispatch table */ @@ -167,37 +147,37 @@ __objc_responds_to (id object, SEL sel) needs to be installed or it doesn't exist and forwarding is attempted. */ __inline__ IMP -objc_msg_lookup (id receiver, SEL op) +objc_msg_lookup(id receiver, SEL op) { IMP result; - if (receiver) + if(receiver) { 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) + 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); + __objc_init_install_dtable(receiver, op); /* Get real method for this in newly installed dtable */ - result = get_imp (receiver->class_pointer, op); + result = get_imp(receiver->class_pointer, op); } else { /* The dispatch table has been installed so the method just doesn't exist for the class. Attempt to forward the method. */ - result = __objc_get_forward_imp (op); + result = __objc_get_forward_imp(op); } } return result; } else - return (IMP)nil_method; + return nil_method; } IMP @@ -206,95 +186,96 @@ objc_msg_lookup_super (Super_t super, SEL sel) if (super->self) return get_imp (super->class, sel); else - return (IMP)nil_method; + return nil_method; } -int method_get_sizeof_arguments (Method *); +int method_get_sizeof_arguments (Method*); retval_t -objc_msg_sendv (id object, SEL op, arglist_t arg_frame) +objc_msg_sendv(id object, SEL op, arglist_t arg_frame) { - Method *m = class_get_instance_method (object->class_pointer, op); + 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)); + *((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 () +__objc_init_dispatch_tables() { - __objc_uninstalled_dtable = sarray_new (200, 0); + __objc_uninstalled_dtable + = sarray_new(200, 0); } /* 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_init_install_dtable(id receiver, SEL op) { /* 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) + if(receiver->class_pointer->dtable != __objc_uninstalled_dtable) return; - objc_mutex_lock (__objc_runtime_mutex); + objc_mutex_lock(__objc_runtime_mutex); - if (CLS_ISCLASS (receiver->class_pointer)) + if(CLS_ISCLASS(receiver->class_pointer)) { /* receiver is an ordinary object */ - assert (CLS_ISCLASS (receiver->class_pointer)); + 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); + __objc_send_initialize(receiver->class_pointer); } else { /* receiver is a class object */ - assert (CLS_ISCLASS ((Class)receiver)); - assert (CLS_ISMETA (receiver->class_pointer)); + 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_send_initialize((Class)receiver); } - objc_mutex_unlock (__objc_runtime_mutex); + 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 */ void -__objc_install_premature_dtable (Class class) +__objc_install_premature_dtable(Class class) { - assert (__objc_uninstalled_dtable); + assert(__objc_uninstalled_dtable); class->dtable = __objc_uninstalled_dtable; } /* Send +initialize to class if not already done */ static void -__objc_send_initialize (Class class) +__objc_send_initialize(Class class) { /* This *must* be a class object */ - assert (CLS_ISCLASS (class)); - assert (! CLS_ISMETA (class)); + assert(CLS_ISCLASS(class)); + assert(!CLS_ISMETA(class)); - if (! CLS_ISINITIALIZED (class)) + if (!CLS_ISINITIALIZED(class)) { - CLS_SETINITIALIZED (class); - CLS_SETINITIALIZED (class->class_pointer); + CLS_SETINITIALIZED(class); + CLS_SETINITIALIZED(class->class_pointer); /* Create the garbage collector type memory description */ __objc_generate_gc_type_description (class); - if (class->super_class) - __objc_send_initialize (class->super_class); + if(class->super_class) + __objc_send_initialize(class->super_class); { SEL op = sel_register_name ("initialize"); @@ -305,7 +286,7 @@ __objc_send_initialize (Class class) int i; Method_t method; - for (i = 0; i < method_list->method_count; i++) { + 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) { @@ -321,7 +302,7 @@ __objc_send_initialize (Class class) } if (imp) - (*imp) ((id) class, op); + (*imp)((id)class, op); } } @@ -338,7 +319,7 @@ __objc_install_methods_in_dtable (Class class, MethodList_t method_list) { int i; - if (! method_list) + if (!method_list) return; if (method_list->method_next) @@ -361,8 +342,8 @@ __objc_install_dispatch_table_for_class (Class class) /* 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 (); + if(!CLS_ISRESOLV(class)) + __objc_resolve_class_links(); super = class->super_class; @@ -372,9 +353,9 @@ __objc_install_dispatch_table_for_class (Class class) /* Allocate dtable if necessary */ if (super == 0) { - objc_mutex_lock (__objc_runtime_mutex); + objc_mutex_lock(__objc_runtime_mutex); class->dtable = sarray_new (__objc_selector_max_index, 0); - objc_mutex_unlock (__objc_runtime_mutex); + objc_mutex_unlock(__objc_runtime_mutex); } else class->dtable = sarray_lazy_copy (super->dtable); @@ -392,7 +373,7 @@ __objc_update_dispatch_table_for_class (Class class) if (class->dtable == __objc_uninstalled_dtable) return; - objc_mutex_lock (__objc_runtime_mutex); + objc_mutex_lock(__objc_runtime_mutex); arr = class->dtable; __objc_install_premature_dtable (class); /* someone might require it... */ @@ -405,7 +386,7 @@ __objc_update_dispatch_table_for_class (Class class) for (next = class->subclass_list; next; next = next->sibling_class) __objc_update_dispatch_table_for_class (next); - objc_mutex_unlock (__objc_runtime_mutex); + objc_mutex_unlock(__objc_runtime_mutex); } @@ -422,7 +403,7 @@ class_add_method_list (Class class, MethodList_t list) int i; /* Passing of a linked list is not allowed. Do multiple calls. */ - assert (! list->method_next); + assert (!list->method_next); /* Check for duplicates. */ for (i = 0; i < list->method_count; ++i) @@ -433,7 +414,7 @@ class_add_method_list (Class class, MethodList_t list) { /* This is where selector names are transmogrified to SEL's */ method->method_name = - sel_register_typed_name ((const char *) method->method_name, + sel_register_typed_name ((const char*)method->method_name, method->method_types); } } @@ -447,15 +428,15 @@ class_add_method_list (Class class, MethodList_t list) } Method_t -class_get_instance_method (Class class, SEL op) +class_get_instance_method(Class class, SEL op) { - return search_for_method_in_hierarchy (class, op); + return search_for_method_in_hierarchy(class, op); } Method_t -class_get_class_method (MetaClass class, SEL op) +class_get_class_method(MetaClass class, SEL op) { - return search_for_method_in_hierarchy (class, op); + return search_for_method_in_hierarchy(class, op); } @@ -579,13 +560,13 @@ __objc_forward (id object, SEL sel, arglist_t args) SEL err_sel; /* first try if the object understands forward:: */ - if (! frwd_sel) - frwd_sel = sel_get_any_uid ("forward::"); + if (!frwd_sel) + frwd_sel = sel_get_any_uid("forward::"); if (__objc_responds_to (object, frwd_sel)) { - imp = get_imp (object->class_pointer, frwd_sel); - return (*imp) (object, frwd_sel, sel, args); + imp = get_imp(object->class_pointer, frwd_sel); + return (*imp)(object, frwd_sel, sel, args); } /* If the object recognizes the doesNotRecognize: method then we're going @@ -600,11 +581,12 @@ __objc_forward (id object, SEL sel, arglist_t args) /* The object doesn't recognize the method. Check for responding to error:. If it does then sent it. */ { - char msg[256 + strlen ((const char *) sel_get_name (sel)) - + strlen ((const char *) object->class_pointer->name)]; + size_t strlen (const char*); + char msg[256 + strlen ((const char*)sel_get_name (sel)) + + strlen ((const char*)object->class_pointer->name)]; sprintf (msg, "(%s) %s does not recognize %s", - (CLS_ISMETA (object->class_pointer) + (CLS_ISMETA(object->class_pointer) ? "class" : "instance" ), object->class_pointer->name, sel_get_name (sel)); @@ -625,41 +607,40 @@ __objc_forward (id object, SEL sel, arglist_t args) } void -__objc_print_dtable_stats () +__objc_print_dtable_stats() { int total = 0; - objc_mutex_lock (__objc_runtime_mutex); + objc_mutex_lock(__objc_runtime_mutex); #ifdef OBJC_SPARSE2 - printf ("memory usage: (%s)\n", "2-level sparse arrays"); + printf("memory usage: (%s)\n", "2-level sparse arrays"); #else - printf ("memory usage: (%s)\n", "3-level sparse arrays"); + printf("memory usage: (%s)\n", "3-level sparse arrays"); #endif - printf ("arrays: %d = %ld bytes\n", narrays, - (long) narrays * sizeof (struct sarray)); - total += narrays * sizeof (struct sarray); - printf ("buckets: %d = %ld bytes\n", nbuckets, - (long) nbuckets * sizeof (struct sbucket)); - total += nbuckets * sizeof (struct sbucket); - - printf ("idxtables: %d = %ld bytes\n", - idxsize, (long) idxsize * sizeof (void *)); - total += idxsize * sizeof (void *); - printf ("-----------------------------------\n"); - printf ("total: %d bytes\n", total); - printf ("===================================\n"); - - objc_mutex_unlock (__objc_runtime_mutex); + printf("arrays: %d = %ld bytes\n", narrays, + (long)narrays*sizeof(struct sarray)); + total += narrays*sizeof(struct sarray); + printf("buckets: %d = %ld bytes\n", nbuckets, + (long)nbuckets*sizeof(struct sbucket)); + total += nbuckets*sizeof(struct sbucket); + + printf("idxtables: %d = %ld bytes\n", idxsize, (long)idxsize*sizeof(void*)); + total += idxsize*sizeof(void*); + printf("-----------------------------------\n"); + printf("total: %d bytes\n", total); + printf("===================================\n"); + + 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. */ __inline__ -struct sarray * -objc_get_uninstalled_dtable () +struct sarray* +objc_get_uninstalled_dtable() { return __objc_uninstalled_dtable; } diff --git a/gnu/lib/libobjc/libobjc/thr-mach.c b/gnu/lib/libobjc/libobjc/thr-mach.c index e95460746d1..44af0c1e286 100644 --- a/gnu/lib/libobjc/libobjc/thr-mach.c +++ b/gnu/lib/libobjc/libobjc/thr-mach.c @@ -1,5 +1,5 @@ /* GNU Objective C Runtime Thread Implementation - Copyright (C) 1996, 1997, 2002 Free Software Foundation, Inc. + Copyright (C) 1996, 1997 Free Software Foundation, Inc. Contributed by Galen C. Hunt (gchunt@cs.rochester.edu) Modified for Mach threads by Bill Bumgarner <bbum@friday.com> Condition functions added by Mircea Oancea <mircea@first.elcom.pub.ro> @@ -37,8 +37,7 @@ Boston, MA 02111-1307, USA. */ maximum priority downward only-- cannot be raised without superuser privileges. Once lowered, it cannot be raised. */ -static int -__mach_get_max_thread_priority (cthread_t t, int *base) +static int __mach_get_max_thread_priority(cthread_t t, int *base) { thread_t threadP; kern_return_t error; @@ -48,10 +47,10 @@ __mach_get_max_thread_priority (cthread_t t, int *base) if (t == NULL) return -1; - threadP = cthread_thread (t); /* get thread underlying */ + threadP = cthread_thread(t); /* get thread underlying */ - error = thread_info (threadP, THREAD_SCHED_INFO, - (thread_info_t) &info, &info_count); + error=thread_info(threadP, THREAD_SCHED_INFO, + (thread_info_t)&info, &info_count); if (error != KERN_SUCCESS) return -1; @@ -66,14 +65,14 @@ __mach_get_max_thread_priority (cthread_t t, int *base) /* Initialize the threads subsystem. */ int -__objc_init_thread_system (void) +__objc_init_thread_system(void) { return 0; } /* Close the threads subsystem. */ int -__objc_close_thread_system (void) +__objc_close_thread_system(void) { return 0; } @@ -82,19 +81,19 @@ __objc_close_thread_system (void) /* Create a new thread of execution. */ objc_thread_t -__objc_thread_detach (void (*func) (void *arg), void *arg) +__objc_thread_detach(void (*func)(void *arg), void *arg) { objc_thread_t thread_id; cthread_t new_thread_handle; /* create thread */ - new_thread_handle = cthread_fork ((cthread_fn_t) func, arg); + new_thread_handle = cthread_fork((cthread_fn_t)func, arg); - if (new_thread_handle) + if(new_thread_handle) { /* this is not terribly portable */ - thread_id = *(objc_thread_t *) &new_thread_handle; - cthread_detach (new_thread_handle); + thread_id = *(objc_thread_t *)&new_thread_handle; + cthread_detach(new_thread_handle); } else thread_id = NULL; @@ -104,11 +103,11 @@ __objc_thread_detach (void (*func) (void *arg), void *arg) /* Set the current thread's priority. */ int -__objc_thread_set_priority (int priority) +__objc_thread_set_priority(int priority) { - objc_thread_t *t = objc_thread_id (); + objc_thread_t *t = objc_thread_id(); cthread_t cT = (cthread_t) t; - int maxPriority = __mach_get_max_thread_priority (cT, NULL); + int maxPriority = __mach_get_max_thread_priority(cT, NULL); int sys_priority = 0; if (maxPriority == -1) @@ -133,7 +132,7 @@ __objc_thread_set_priority (int priority) return -1; /* Change the priority */ - if (cthread_priority (cT, sys_priority, 0) == KERN_SUCCESS) + if (cthread_priority(cT, sys_priority, 0) == KERN_SUCCESS) return 0; else return -1; @@ -141,19 +140,19 @@ __objc_thread_set_priority (int priority) /* Return the current thread's priority. */ int -__objc_thread_get_priority (void) +__objc_thread_get_priority(void) { - objc_thread_t *t = objc_thread_id (); - cthread_t cT = (cthread_t) t; /* see objc_thread_id () */ + objc_thread_t *t = objc_thread_id(); + cthread_t cT = (cthread_t) t; /* see objc_thread_id() */ int basePriority; int maxPriority; int sys_priority = 0; int interactiveT, backgroundT, lowT; /* thresholds */ - maxPriority = __mach_get_max_thread_priority (cT, &basePriority); + maxPriority = __mach_get_max_thread_priority(cT, &basePriority); - if (maxPriority == -1) + if(maxPriority == -1) return -1; if (basePriority > ( (maxPriority * 2) / 3)) @@ -167,17 +166,17 @@ __objc_thread_get_priority (void) /* Yield our process time to another thread. */ void -__objc_thread_yield (void) +__objc_thread_yield(void) { - cthread_yield (); + cthread_yield(); } /* Terminate the current thread. */ int -__objc_thread_exit (void) +__objc_thread_exit(void) { /* exit the thread */ - cthread_exit (&__objc_thread_exit_status); + cthread_exit(&__objc_thread_exit_status); /* Failed if we reached here */ return -1; @@ -185,42 +184,42 @@ __objc_thread_exit (void) /* Returns an integer value which uniquely describes a thread. */ objc_thread_t -__objc_thread_id (void) +__objc_thread_id(void) { - cthread_t self = cthread_self (); + cthread_t self = cthread_self(); - return *(objc_thread_t *) &self; + return *(objc_thread_t *)&self; } /* Sets the thread's local storage pointer. */ int -__objc_thread_set_data (void *value) +__objc_thread_set_data(void *value) { - cthread_set_data (cthread_self (), (any_t) value); + cthread_set_data(cthread_self(), (any_t) value); return 0; } /* Returns the thread's local storage pointer. */ void * -__objc_thread_get_data (void) +__objc_thread_get_data(void) { - return (void *) cthread_data (cthread_self ()); + return (void *) cthread_data(cthread_self()); } /* Backend mutex functions */ /* Allocate a mutex. */ int -__objc_mutex_allocate (objc_mutex_t mutex) +__objc_mutex_allocate(objc_mutex_t mutex) { int err = 0; - mutex->backend = objc_malloc (sizeof (struct mutex)); + mutex->backend = objc_malloc(sizeof(struct mutex)); - err = mutex_init ((mutex_t) (mutex->backend)); + err = mutex_init((mutex_t)(mutex->backend)); if (err != 0) { - objc_free (mutex->backend); + objc_free(mutex->backend); return -1; } else @@ -229,28 +228,28 @@ __objc_mutex_allocate (objc_mutex_t mutex) /* Deallocate a mutex. */ int -__objc_mutex_deallocate (objc_mutex_t mutex) +__objc_mutex_deallocate(objc_mutex_t mutex) { - mutex_clear ((mutex_t) (mutex->backend)); + mutex_clear((mutex_t)(mutex->backend)); - objc_free (mutex->backend); + objc_free(mutex->backend); mutex->backend = NULL; return 0; } /* Grab a lock on a mutex. */ int -__objc_mutex_lock (objc_mutex_t mutex) +__objc_mutex_lock(objc_mutex_t mutex) { - mutex_lock ((mutex_t) (mutex->backend)); + mutex_lock((mutex_t)(mutex->backend)); return 0; } /* Try to grab a lock on a mutex. */ int -__objc_mutex_trylock (objc_mutex_t mutex) +__objc_mutex_trylock(objc_mutex_t mutex) { - if (mutex_try_lock ((mutex_t) (mutex->backend)) == 0) + if (mutex_try_lock((mutex_t)(mutex->backend)) == 0) return -1; else return 0; @@ -258,9 +257,9 @@ __objc_mutex_trylock (objc_mutex_t mutex) /* Unlock the mutex */ int -__objc_mutex_unlock (objc_mutex_t mutex) +__objc_mutex_unlock(objc_mutex_t mutex) { - mutex_unlock ((mutex_t) (mutex->backend)); + mutex_unlock((mutex_t)(mutex->backend)); return 0; } @@ -268,45 +267,45 @@ __objc_mutex_unlock (objc_mutex_t mutex) /* Allocate a condition. */ int -__objc_condition_allocate (objc_condition_t condition) +__objc_condition_allocate(objc_condition_t condition) { - condition->backend = objc_malloc (sizeof (struct condition)); - condition_init ((condition_t) (condition->backend)); + condition->backend = objc_malloc(sizeof(struct condition)); + condition_init((condition_t)(condition->backend)); return 0; } /* Deallocate a condition. */ int -__objc_condition_deallocate (objc_condition_t condition) +__objc_condition_deallocate(objc_condition_t condition) { - condition_clear ((condition_t) (condition->backend)); - objc_free (condition->backend); + condition_clear((condition_t)(condition->backend)); + objc_free(condition->backend); condition->backend = NULL; return 0; } /* Wait on the condition */ int -__objc_condition_wait (objc_condition_t condition, objc_mutex_t mutex) +__objc_condition_wait(objc_condition_t condition, objc_mutex_t mutex) { - condition_wait ((condition_t) (condition->backend), - (mutex_t) (mutex->backend)); + condition_wait((condition_t)(condition->backend), + (mutex_t)(mutex->backend)); return 0; } /* Wake up all threads waiting on this condition. */ int -__objc_condition_broadcast (objc_condition_t condition) +__objc_condition_broadcast(objc_condition_t condition) { - condition_broadcast ((condition_t) (condition->backend)); + condition_broadcast((condition_t)(condition->backend)); return 0; } /* Wake up one thread waiting on this condition. */ int -__objc_condition_signal (objc_condition_t condition) +__objc_condition_signal(objc_condition_t condition) { - condition_signal ((condition_t) (condition->backend)); + condition_signal((condition_t)(condition->backend)); return 0; } diff --git a/gnu/lib/libobjc/libobjc/thr.c b/gnu/lib/libobjc/libobjc/thr.c index bc94473ce68..f1c957aaa15 100644 --- a/gnu/lib/libobjc/libobjc/thr.c +++ b/gnu/lib/libobjc/libobjc/thr.c @@ -48,7 +48,7 @@ objc_thread_callback _objc_became_multi_threaded = NULL; it can be informed; for example, the GNUstep Base Library sets it so it can implement the NSBecomingMultiThreaded notification. */ -objc_thread_callback objc_set_thread_callback (objc_thread_callback func) +objc_thread_callback objc_set_thread_callback(objc_thread_callback func) { objc_thread_callback temp = _objc_became_multi_threaded; _objc_became_multi_threaded = func; @@ -76,44 +76,44 @@ struct __objc_thread_start_state }; static volatile void -__objc_thread_detach_function (struct __objc_thread_start_state *istate) +__objc_thread_detach_function(struct __objc_thread_start_state *istate) { /* Valid state? */ if (istate) { - id (*imp) (id, SEL, id); + id (*imp)(id,SEL,id); SEL selector = istate->selector; id object = istate->object; id argument = istate->argument; /* Don't need anymore so free it */ - objc_free (istate); + objc_free(istate); /* Clear out the thread local storage */ - objc_thread_set_data (NULL); + objc_thread_set_data(NULL); /* Check to see if we just became multi threaded */ - if (! __objc_is_multi_threaded) + if (!__objc_is_multi_threaded) { __objc_is_multi_threaded = 1; /* Call the hook function */ if (_objc_became_multi_threaded != NULL) - (*_objc_became_multi_threaded) (); + (*_objc_became_multi_threaded)(); } /* Call the method */ - if ((imp = (id (*) (id, SEL, id))objc_msg_lookup (object, selector))) - (*imp) (object, selector, argument); + if ((imp = (id(*)(id, SEL, id))objc_msg_lookup(object, selector))) + (*imp)(object, selector, argument); else - objc_error (object, OBJC_ERR_UNIMPLEMENTED, - "objc_thread_detach called with bad selector.\n"); + objc_error(object, OBJC_ERR_UNIMPLEMENTED, + "objc_thread_detach called with bad selector.\n"); } else - objc_error (nil, OBJC_ERR_BAD_STATE, - "objc_thread_detach called with NULL state.\n"); + objc_error(nil, OBJC_ERR_BAD_STATE, + "objc_thread_detach called with NULL state.\n"); /* Exit the thread */ - objc_thread_exit (); + objc_thread_exit(); } /* @@ -131,14 +131,14 @@ __objc_thread_detach_function (struct __objc_thread_start_state *istate) takes a single argument. */ objc_thread_t -objc_thread_detach (SEL selector, id object, id argument) +objc_thread_detach(SEL selector, id object, id argument) { struct __objc_thread_start_state *istate; objc_thread_t thread_id = NULL; /* Allocate the state structure */ - if (! (istate = (struct __objc_thread_start_state *) - objc_malloc (sizeof (*istate)))) + if (!(istate = (struct __objc_thread_start_state *) + objc_malloc(sizeof(*istate)))) return NULL; /* Initialize the state structure */ @@ -147,39 +147,39 @@ objc_thread_detach (SEL selector, id object, id argument) istate->argument = argument; /* lock access */ - objc_mutex_lock (__objc_runtime_mutex); + objc_mutex_lock(__objc_runtime_mutex); /* Call the backend to spawn the thread */ - if ((thread_id = __objc_thread_detach ((void *)__objc_thread_detach_function, - istate)) == NULL) + if ((thread_id = __objc_thread_detach((void *)__objc_thread_detach_function, + istate)) == NULL) { /* failed! */ - objc_mutex_unlock (__objc_runtime_mutex); - objc_free (istate); + objc_mutex_unlock(__objc_runtime_mutex); + objc_free(istate); return NULL; } /* Increment our thread counter */ __objc_runtime_threads_alive++; - objc_mutex_unlock (__objc_runtime_mutex); + objc_mutex_unlock(__objc_runtime_mutex); return thread_id; } /* Set the current thread's priority. */ int -objc_thread_set_priority (int priority) +objc_thread_set_priority(int priority) { /* Call the backend */ - return __objc_thread_set_priority (priority); + return __objc_thread_set_priority(priority); } /* Return the current thread's priority. */ int -objc_thread_get_priority (void) +objc_thread_get_priority(void) { /* Call the backend */ - return __objc_thread_get_priority (); + return __objc_thread_get_priority(); } /* @@ -188,10 +188,10 @@ objc_thread_get_priority (void) make progress even on a lazy uniprocessor system. */ void -objc_thread_yield (void) +objc_thread_yield(void) { /* Call the backend */ - __objc_thread_yield (); + __objc_thread_yield(); } /* @@ -199,15 +199,15 @@ objc_thread_yield (void) Actually, if it failed returns -1. */ int -objc_thread_exit (void) +objc_thread_exit(void) { /* Decrement our counter of the number of threads alive */ - objc_mutex_lock (__objc_runtime_mutex); + objc_mutex_lock(__objc_runtime_mutex); __objc_runtime_threads_alive--; - objc_mutex_unlock (__objc_runtime_mutex); + objc_mutex_unlock(__objc_runtime_mutex); /* Call the backend to terminate the thread */ - return __objc_thread_exit (); + return __objc_thread_exit(); } /* @@ -215,10 +215,10 @@ objc_thread_exit (void) NULL which is reserved as a marker for "no thread". */ objc_thread_t -objc_thread_id (void) +objc_thread_id(void) { /* Call the backend */ - return __objc_thread_id (); + return __objc_thread_id(); } /* @@ -226,20 +226,20 @@ objc_thread_id (void) Returns 0 if successful or -1 if failed. */ int -objc_thread_set_data (void *value) +objc_thread_set_data(void *value) { /* Call the backend */ - return __objc_thread_set_data (value); + return __objc_thread_set_data(value); } /* Returns the thread's local storage pointer. Returns NULL on failure. */ void * -objc_thread_get_data (void) +objc_thread_get_data(void) { /* Call the backend */ - return __objc_thread_get_data (); + return __objc_thread_get_data(); } /* Frontend mutex functions */ @@ -249,19 +249,19 @@ objc_thread_get_data (void) allocation failed for any reason. */ objc_mutex_t -objc_mutex_allocate (void) +objc_mutex_allocate(void) { objc_mutex_t mutex; /* Allocate the mutex structure */ - if (! (mutex = (objc_mutex_t)objc_malloc (sizeof (struct objc_mutex)))) + if (!(mutex = (objc_mutex_t)objc_malloc(sizeof(struct objc_mutex)))) return NULL; /* Call backend to create the mutex */ - if (__objc_mutex_allocate (mutex)) + if (__objc_mutex_allocate(mutex)) { /* failed! */ - objc_free (mutex); + objc_free(mutex); return NULL; } @@ -279,23 +279,23 @@ objc_mutex_allocate (void) Returns the number of locks on the thread. (1 for deallocate). */ int -objc_mutex_deallocate (objc_mutex_t mutex) +objc_mutex_deallocate(objc_mutex_t mutex) { int depth; /* Valid mutex? */ - if (! mutex) + if (!mutex) return -1; /* Acquire lock on mutex */ - depth = objc_mutex_lock (mutex); + depth = objc_mutex_lock(mutex); /* Call backend to destroy mutex */ - if (__objc_mutex_deallocate (mutex)) + if (__objc_mutex_deallocate(mutex)) return -1; /* Free the mutex structure */ - objc_free (mutex); + objc_free(mutex); /* Return last depth */ return depth; @@ -308,22 +308,22 @@ objc_mutex_deallocate (objc_mutex_t mutex) Returns the lock count on the mutex held by this thread. */ int -objc_mutex_lock (objc_mutex_t mutex) +objc_mutex_lock(objc_mutex_t mutex) { objc_thread_t thread_id; int status; /* Valid mutex? */ - if (! mutex) + if (!mutex) return -1; /* If we already own the lock then increment depth */ - thread_id = __objc_thread_id (); + thread_id = objc_thread_id(); if (mutex->owner == thread_id) return ++mutex->depth; /* Call the backend to lock the mutex */ - status = __objc_mutex_lock (mutex); + status = __objc_mutex_lock(mutex); /* Failed? */ if (status) @@ -340,22 +340,22 @@ objc_mutex_lock (objc_mutex_t mutex) thread has a lock on the mutex returns -1. */ int -objc_mutex_trylock (objc_mutex_t mutex) +objc_mutex_trylock(objc_mutex_t mutex) { objc_thread_t thread_id; int status; /* Valid mutex? */ - if (! mutex) + if (!mutex) return -1; /* If we already own the lock then increment depth */ - thread_id = __objc_thread_id (); + thread_id = objc_thread_id(); if (mutex->owner == thread_id) return ++mutex->depth; /* Call the backend to try to lock the mutex */ - status = __objc_mutex_trylock (mutex); + status = __objc_mutex_trylock(mutex); /* Failed? */ if (status) @@ -375,17 +375,17 @@ objc_mutex_trylock (objc_mutex_t mutex) doesn't hold in which case return -1 and the mutex is unaffected. */ int -objc_mutex_unlock (objc_mutex_t mutex) +objc_mutex_unlock(objc_mutex_t mutex) { objc_thread_t thread_id; int status; /* Valid mutex? */ - if (! mutex) + if (!mutex) return -1; /* If another thread owns the lock then abort */ - thread_id = __objc_thread_id (); + thread_id = objc_thread_id(); if (mutex->owner != thread_id) return -1; @@ -398,7 +398,7 @@ objc_mutex_unlock (objc_mutex_t mutex) mutex->owner = NULL; /* Have the backend unlock the mutex */ - status = __objc_mutex_unlock (mutex); + status = __objc_mutex_unlock(mutex); /* Failed? */ if (status) @@ -414,20 +414,20 @@ objc_mutex_unlock (objc_mutex_t mutex) if the allocation failed for any reason. */ objc_condition_t -objc_condition_allocate (void) +objc_condition_allocate(void) { objc_condition_t condition; /* Allocate the condition mutex structure */ - if (! (condition = - (objc_condition_t) objc_malloc (sizeof (struct objc_condition)))) + if (!(condition = + (objc_condition_t)objc_malloc(sizeof(struct objc_condition)))) return NULL; /* Call the backend to create the condition mutex */ - if (__objc_condition_allocate (condition)) + if (__objc_condition_allocate(condition)) { /* failed! */ - objc_free (condition); + objc_free(condition); return NULL; } @@ -443,41 +443,41 @@ objc_condition_allocate (void) waiting but just wake them up. */ int -objc_condition_deallocate (objc_condition_t condition) +objc_condition_deallocate(objc_condition_t condition) { /* Broadcast the condition */ - if (objc_condition_broadcast (condition)) + if (objc_condition_broadcast(condition)) return -1; /* Call the backend to destroy */ - if (__objc_condition_deallocate (condition)) + if (__objc_condition_deallocate(condition)) return -1; /* Free the condition mutex structure */ - objc_free (condition); + objc_free(condition); return 0; } /* - Wait on the condition unlocking the mutex until objc_condition_signal () - or objc_condition_broadcast () are called for the same condition. The + Wait on the condition unlocking the mutex until objc_condition_signal() + or objc_condition_broadcast() are called for the same condition. The given mutex *must* have the depth set to 1 so that it can be unlocked here, so that someone else can lock it and signal/broadcast the condition. The mutex is used to lock access to the shared data that make up the "condition" predicate. */ int -objc_condition_wait (objc_condition_t condition, objc_mutex_t mutex) +objc_condition_wait(objc_condition_t condition, objc_mutex_t mutex) { objc_thread_t thread_id; /* Valid arguments? */ - if (! mutex || ! condition) + if (!mutex || !condition) return -1; /* Make sure we are owner of mutex */ - thread_id = __objc_thread_id (); + thread_id = objc_thread_id(); if (mutex->owner != thread_id) return -1; @@ -490,7 +490,7 @@ objc_condition_wait (objc_condition_t condition, objc_mutex_t mutex) mutex->owner = (objc_thread_t)NULL; /* Call the backend to wait */ - __objc_condition_wait (condition, mutex); + __objc_condition_wait(condition, mutex); /* Make ourselves owner of the mutex */ mutex->owner = thread_id; @@ -506,13 +506,13 @@ objc_condition_wait (objc_condition_t condition, objc_mutex_t mutex) right away after this call. */ int -objc_condition_broadcast (objc_condition_t condition) +objc_condition_broadcast(objc_condition_t condition) { /* Valid condition mutex? */ - if (! condition) + if (!condition) return -1; - return __objc_condition_broadcast (condition); + return __objc_condition_broadcast(condition); } /* @@ -522,42 +522,13 @@ objc_condition_broadcast (objc_condition_t condition) right away after this call. */ int -objc_condition_signal (objc_condition_t condition) +objc_condition_signal(objc_condition_t condition) { /* Valid condition mutex? */ - if (! condition) + if (!condition) return -1; - return __objc_condition_signal (condition); -} - -/* Make the objc thread system aware that a thread which is managed - (started, stopped) by external code could access objc facilities - from now on. This is used when you are interfacing with some - external non-objc-based environment/system - you must call - objc_thread_add () before an alien thread makes any calls to - Objective-C. Do not cause the _objc_became_multi_threaded hook to - be executed. */ -void -objc_thread_add (void) -{ - objc_mutex_lock (__objc_runtime_mutex); - __objc_is_multi_threaded = 1; - __objc_runtime_threads_alive++; - objc_mutex_unlock (__objc_runtime_mutex); -} - -/* Make the objc thread system aware that a thread managed (started, - stopped) by some external code will no longer access objc and thus - can be forgotten by the objc thread system. Call - objc_thread_remove () when your alien thread is done with making - calls to Objective-C. */ -void -objc_thread_remove (void) -{ - objc_mutex_lock (__objc_runtime_mutex); - __objc_runtime_threads_alive--; - objc_mutex_unlock (__objc_runtime_mutex); + return __objc_condition_signal(condition); } /* End of File */ |