From patchwork Wed Dec 15 17:43:13 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicola Pero X-Patchwork-Id: 75664 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) by ozlabs.org (Postfix) with SMTP id 824641007D1 for ; Thu, 16 Dec 2010 04:44:22 +1100 (EST) Received: (qmail 18779 invoked by alias); 15 Dec 2010 17:44:20 -0000 Received: (qmail 18768 invoked by uid 22791); 15 Dec 2010 17:44:18 -0000 X-SWARE-Spam-Status: No, hits=-1.4 required=5.0 tests=AWL, BAYES_00, TW_BJ, T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from fencepost.gnu.org (HELO fencepost.gnu.org) (140.186.70.10) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Wed, 15 Dec 2010 17:44:12 +0000 Received: from eggs.gnu.org ([140.186.70.92]:50191) by fencepost.gnu.org with esmtps (TLS-1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.69) (envelope-from ) id 1PSvOZ-0007Qo-IV for gcc-patches@gnu.org; Wed, 15 Dec 2010 12:44:07 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1PSvOa-0000Ep-QV for gcc-patches@gnu.org; Wed, 15 Dec 2010 12:44:10 -0500 Received: from smtp181.iad.emailsrvr.com ([207.97.245.181]:58968) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1PSvOa-0000Eh-MX for gcc-patches@gnu.org; Wed, 15 Dec 2010 12:44:08 -0500 Received: from localhost (localhost.localdomain [127.0.0.1]) by smtp48.relay.iad1a.emailsrvr.com (SMTP Server) with ESMTP id 824F5168A09 for ; Wed, 15 Dec 2010 12:44:07 -0500 (EST) Received: from dynamic4.wm-web.iad.mlsrvr.com (dynamic4.wm-web.iad1a.rsapps.net [192.168.2.153]) by smtp48.relay.iad1a.emailsrvr.com (SMTP Server) with ESMTP id 5973C168F73 for ; Wed, 15 Dec 2010 12:43:13 -0500 (EST) Received: from meta-innovation.com (localhost [127.0.0.1]) by dynamic4.wm-web.iad.mlsrvr.com (Postfix) with ESMTP id 1C8D71D4A2B6 for ; Wed, 15 Dec 2010 12:43:13 -0500 (EST) Received: by www2.webmail.us (Authenticated sender: nicola.pero@meta-innovation.com, from: nicola.pero@meta-innovation.com) with HTTP; Wed, 15 Dec 2010 18:43:13 +0100 (CET) Date: Wed, 15 Dec 2010 18:43:13 +0100 (CET) Subject: libobjc: updated comments in objc/message.h From: "Nicola Pero" To: "gcc-patches@gnu.org" MIME-Version: 1.0 X-Type: plain Message-ID: <1292434993.112812059@192.168.2.228> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 3) X-IsSubscribed: yes Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org This patch contains no code changes, only indentations and lots of work on comments. Committed to trunk. Thanks In libobjc/: 2010-12-15 Nicola Pero * objc/message.h: Update comments, reindented code and moved deprecated types and functions at the end of the file. No code changes. Index: ChangeLog =================================================================== --- ChangeLog (revision 167858) +++ ChangeLog (working copy) @@ -1,5 +1,11 @@ 2010-12-15 Nicola Pero + * objc/message.h: Update comments, reindented code and moved + deprecated types and functions at the end of the file. No code + changes. + +2010-12-15 Nicola Pero + * ivars.c (class_addIvar): Use the 'size' argument instead of trying to calculate it using objc_sizeof_type(). * objc/runtime.h (class_addIvar): Updated comments. Index: objc/message.h =================================================================== --- objc/message.h (revision 167858) +++ objc/message.h (working copy) @@ -34,57 +34,108 @@ extern "C" { #endif /* This file includes declarations of the messaging functions and - types. -*/ + types. */ /* Compatibility note: the messaging function is one area where the GNU runtime and the Apple/NeXT runtime differ significantly. If you can, it is recommended that you use higher-level facilities (provided by a Foundation library such as GNUstep Base) to perform - forwarding or other advanced messaging tricks. -*/ + forwarding or other advanced messaging tricks. */ -typedef void* retval_t; /* return value */ -typedef void(*apply_t)(void); /* function pointer */ -typedef union arglist { - char *arg_ptr; - char arg_regs[sizeof (char*)]; -} *arglist_t; /* argument frame */ +/* This function returns the IMP (C function implementing a method) to + use to invoke the method with selector 'op' of receiver 'receiver'. -objc_EXPORT IMP objc_msg_lookup(id receiver, SEL op); + This is the function used by the compiler when compiling method + invocations with the GNU runtime. For example, the method call -/* - * Structure used when a message is send to a class's super class. - * The compiler generates one of these structures and passes it to - * objc_msg_lookup_super. - */ -typedef struct objc_super { - id self; /* Id of the object sending the message. */ + result = [receiver method]; + + is compiled by the compiler (with the GNU runtime) into the + equivalent of: + + { + IMP function = objc_msg_lookup (receiver, @selector (method)); + result = function (receiver, @selector (method)); + } + + so, a call to objc_msg_lookup() determines the IMP (the C function + implementing the method) to call. Then, the function is called. + If the method takes or returns different arguments, the compiler + will cast 'function' to the right type before invoking it, making + sure arguments and return value are handled correctly. + + objc_msg_lookup() must always return a valid function that can be + called with the required method signature (otherwise the + compiler-generated code shown above could segfault). If 'receiver' + is NULL, objc_msg_lookup() returns a C function that does nothing, + ignores all its arguments, and returns NULL (see nil_method.c). If + 'receiver' does not respond to the selector 'op', objc_msg_lookup() + will try to call +resolveClassMethod: or resolveInstanceMethod: as + appropriate, and if they return YES, it will try the lookup again + (+resolveClassMethod: and +resolveInstanceMethod: can thus install + dynamically methods as they are requested). If + +resolveClassMethod: or +resolveInstanceMethod: are either not + available, or return NO, or return YES but 'receiver' still doesn't + implement the 'selector' after calling them, the runtime returns a + generic "forwarding" function that can be called with the required + method signature and which can process the method invocation + according to the forwarding API. There are two runtime hooks that + allow Foundation libraries (such as GNUstep-Base) to return their + own forwarding function in preference to the runtime ones. When + that happens, the Foundation library effectively takes complete + control of the forwarding process; any method invocation where the + selector is not implemented by the receiver will end up calling a + forwarding function chosen by the Foundation library. */ +objc_EXPORT IMP objc_msg_lookup (id receiver, SEL op); + +/* Structure used when a message is send to a class's super class. + The compiler generates one of these structures and passes it to + objc_msg_lookup_super() when a [super method] call is compiled. */ +typedef struct objc_super +{ + id self; /* Id of the object sending the message. */ + + /* The new version of the API will always use 'super_class'. TODO: + Use class only if objc-api.h is included, otherwise always use + super_class. */ #ifdef __cplusplus - /* The new version of the API will always use 'super_class'. */ Class super_class; #else Class class; /* Object's super class. */ #endif } Super, *Super_t; -objc_EXPORT IMP objc_msg_lookup_super(Super_t super, SEL sel); - -objc_EXPORT retval_t objc_msg_sendv(id, SEL, arglist_t); +/* This is used by the compiler instead of objc_msg_lookup () when + compiling a call to 'super', such as [super method]. This requires + sending a message to super->self, but looking up the method as if + super->self was in class super->super_class. */ +objc_EXPORT IMP objc_msg_lookup_super (Super_t super, SEL sel); + +/* Hooks for method forwarding. They make it easy to substitute the + built-in forwarding with one based on a library, such as ffi, that + implement closures, thereby avoiding gcc's __builtin_apply + problems. __objc_msg_forward2's result will be preferred over that + of __objc_msg_forward if both are set and return non-NULL. -/* - * Hooks for method forwarding. This makes it easy to substitute a - * library, such as ffcall, that implements closures, thereby avoiding - * gcc's __builtin_apply problems. __objc_msg_forward2's result will - * be preferred over that of __objc_msg_forward if both are set and - * return non-NULL. - * - * TODO: The API should define objc_set_msg_forward_handler () or - * similar instead of these hooks. - */ + TODO: The API should define objc_set_msg_forward_handler () or + similar instead of these hooks. */ objc_EXPORT IMP (*__objc_msg_forward)(SEL); objc_EXPORT IMP (*__objc_msg_forward2)(id, SEL); + +/* The following types and functions are provided only for + backwards-compatibility and should not be used in new code. They + were deprecated in GCC 4.6 and will be removed in the next + release. */ +typedef void* retval_t; /* return value */ +typedef void(*apply_t)(void); /* function pointer */ +typedef union arglist { + char *arg_ptr; + char arg_regs[sizeof (char*)]; +} *arglist_t; /* argument frame */ + +objc_EXPORT retval_t objc_msg_sendv(id, SEL, arglist_t); + #ifdef __cplusplus } #endif