From patchwork Fri Oct 15 23:45: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: 68012 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 09AADB70E5 for ; Sat, 16 Oct 2010 10:45:29 +1100 (EST) Received: (qmail 22265 invoked by alias); 15 Oct 2010 23:45:27 -0000 Received: (qmail 22257 invoked by uid 22791); 15 Oct 2010 23:45:25 -0000 X-SWARE-Spam-Status: No, hits=-1.2 required=5.0 tests=AWL, BAYES_00, SARE_SUB_ENC_UTF8, 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; Fri, 15 Oct 2010 23:45:17 +0000 Received: from eggs.gnu.org ([140.186.70.92]:55393) by fencepost.gnu.org with esmtps (TLS-1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.69) (envelope-from ) id 1P6txb-0007sf-Rg for gcc-patches@gnu.org; Fri, 15 Oct 2010 19:45:15 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1P6txa-0002JX-7O for gcc-patches@gnu.org; Fri, 15 Oct 2010 19:45:15 -0400 Received: from smtp161.iad.emailsrvr.com ([207.97.245.161]:49704) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1P6txa-0002JP-35 for gcc-patches@gnu.org; Fri, 15 Oct 2010 19:45:14 -0400 Received: from localhost (localhost.localdomain [127.0.0.1]) by smtp46.relay.iad1a.emailsrvr.com (SMTP Server) with ESMTP id 68A80E87CF for ; Fri, 15 Oct 2010 19:45:13 -0400 (EDT) X-Orig-To: gcc-patches@gnu.org Received: from dynamic8.wm-web.iad.mlsrvr.com (dynamic8.wm-web.iad1a.rsapps.net [192.168.2.149]) by smtp46.relay.iad1a.emailsrvr.com (SMTP Server) with ESMTP id 57366E8656 for ; Fri, 15 Oct 2010 19:45:13 -0400 (EDT) Received: from meta-innovation.com (localhost [127.0.0.1]) by dynamic8.wm-web.iad.mlsrvr.com (Postfix) with ESMTP id 4925D305006C for ; Fri, 15 Oct 2010 19:45:13 -0400 (EDT) Received: by www2.webmail.us (Authenticated sender: nicola.pero@meta-innovation.com, from: nicola.pero@meta-innovation.com) with HTTP; Sat, 16 Oct 2010 01:45:13 +0200 (CEST) Date: Sat, 16 Oct 2010 01:45:13 +0200 (CEST) Subject: =?UTF-8?Q?libobjc=20-=20more=20modern=20Objective-C=20runtime=20API=20(9?= =?UTF-8?Q?)?= From: "Nicola Pero" To: "gcc-patches@gnu.org" MIME-Version: 1.0 X-Type: plain Message-ID: <1287186313.29812162@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 adds the missing property functions (actually, placeholders for them, since they need a new ABI to work). Committed to trunk. Thanks In libobjc/: 2010-10-15 Nicola Pero * objc/runtime.h (class_copyPropertyList): New. (class_getProperty): New. (property_getAttributes): New. (property_getName): New. * ivars.c (class_copyPropertyList): New. (class_getProperty): New. (property_getAttributes): New. (property_getName): New. In gcc/testsuite/: 2010-10-15 Nicola Pero * objc.dg/gnu-api-2-property.m: New. Index: ChangeLog =================================================================== --- ChangeLog (revision 165525) +++ ChangeLog (working copy) @@ -1,4 +1,15 @@ 2010-10-15 Nicola Pero + + * objc/runtime.h (class_copyPropertyList): New. + (class_getProperty): New. + (property_getAttributes): New. + (property_getName): New. + * ivars.c (class_copyPropertyList): New. + (class_getProperty): New. + (property_getAttributes): New. + (property_getName): New. + +2010-10-15 Nicola Pero * objc-private/runtime.h (__objc_update_classes_with_methods): New. * class.c (__objc_update_classes_with_methods): New. Index: ivars.c =================================================================== --- ivars.c (revision 165524) +++ ivars.c (working copy) @@ -228,3 +228,56 @@ struct objc_ivar ** class_copyIvarList (Class clas return returnValue; } + +const char * +property_getName (struct objc_property * property __attribute__ ((__unused__))) +{ + if (property == NULL) + return NULL; + + /* TODO: New ABI. */ + /* The current ABI does not have any information on properties. */ + return NULL; +} + +const char * +property_getAttributes (struct objc_property * property __attribute__ ((__unused__))) +{ + if (property == NULL) + return NULL; + + /* TODO: New ABI. */ + /* The current ABI does not have any information on properties. */ + return NULL; +} + +struct objc_property * +class_getProperty (Class class_ __attribute__ ((__unused__)), + const char *propertyName __attribute__ ((__unused__))) +{ + if (class_ == NULL || propertyName == NULL) + return NULL; + + /* TODO: New ABI. */ + /* The current ABI does not have any information on class properties. */ + return NULL; +} + +struct objc_property ** +class_copyPropertyList (Class class_ __attribute__ ((__unused__)), + unsigned int *numberOfReturnedProperties __attribute__ ((__unused__))) +{ + if (class_ == Nil) + { + if (numberOfReturnedProperties) + *numberOfReturnedProperties = 0; + return NULL; + } + + /* TODO: New ABI. */ + /* The current ABI does not have any information on class properties. */ + if (numberOfReturnedProperties) + *numberOfReturnedProperties = 0; + + return NULL; +} Index: objc/runtime.h =================================================================== --- objc/runtime.h (revision 165525) +++ objc/runtime.h (working copy) @@ -305,7 +305,38 @@ objc_EXPORT const char * ivar_getTypeEncoding (Iva will be filled with the number of instance variables returned. */ objc_EXPORT Ivar * class_copyIvarList (Class class_, unsigned int *numberOfReturnedIvars); +/* Return the name of the property. Return NULL if 'property' is + NULL. */ +objc_EXPORT const char * property_getName (Property property); +/* Return the attributes of the property as a string. Return NULL if + 'property' is NULL. */ +objc_EXPORT const char * property_getAttributes (Property property); + +/* Return the property with name 'propertyName' of the class 'class_'. + This function returns NULL if the required property can not be + found. Return NULL if 'class_' or 'propertyName' is NULL. + + Note that the traditional ABI does not store the list of properties + of a class in a compiled module, so the traditional ABI will always + return NULL. */ +objc_EXPORT Property class_getProperty (Class class_, const char *propertyName); + +/* Return all the properties of the class. The return value + of the function is a pointer to an area, allocated with malloc(), + that contains all the properties of the class. It does not + include properties of superclasses. The list is terminated + by NULL. Optionally, if you pass a non-NULL + 'numberOfReturnedIvars' pointer, the unsigned int that it points to + will be filled with the number of properties returned. + + Note that the traditional ABI does not store the list of properties + of a class in a compiled module, so the traditional ABI will always + return an empty list. */ +objc_EXPORT Property * class_copyPropertyList +(Class class_, unsigned int *numberOfReturnedProperties); + + /** Implementation: the following functions are in class.c. */ /* Compatibility Note: The Apple/NeXT runtime does not have @@ -422,7 +453,28 @@ objc_EXPORT void class_setVersion (Class class_, i for all classes). */ objc_EXPORT size_t class_getInstanceSize (Class class_); +/* Change the implementation of the method. It also searches all + classes for any class implementing the method, and replaces the + existing implementation with the new one. For that to work, + 'method' must be a method returned by class_getInstanceMethod() or + class_getClassMethod() as the matching is done by comparing the + pointers; in that case, only the implementation in the class is + modified. Return the previous implementation that has been + replaced. If method or implementation is NULL, do nothing and + return NULL. */ +objc_EXPORT IMP +method_setImplementation (Method method, IMP implementation); +/* Swap the implementation of two methods in a single, atomic + operation. This is equivalent to getting the implementation of + each method and then calling method_setImplementation() on the + other one. For this to work, the two methods must have been + returned by class_getInstanceMethod() or class_getClassMethod(). + If 'method_a' or 'method_b' is NULL, do nothing. */ +objc_EXPORT void +method_exchangeImplementations (Method method_a, Method method_b); + + /** Implementation: the following functions are in sendmsg.c. */ /* Return the instance method with selector 'selector' of class @@ -545,27 +597,7 @@ objc_EXPORT void method_getReturnType (Method meth objc_EXPORT void method_getArgumentType (Method method, unsigned int argumentNumber, char *returnValue, size_t returnValueSize); -/* Change the implementation of the method. It also searches all - classes for any class implementing the method, and replaces the - existing implementation with the new one. For that to work, - 'method' must be a method returned by class_getInstanceMethod() or - class_getClassMethod() as the matching is done by comparing the - pointers; in that case, only the implementation in the class is - modified. Return the previous implementation that has been - replaced. If method or implementation is NULL, do nothing and - return NULL. */ -objc_EXPORT IMP -method_setImplementation (Method method, IMP implementation); -/* Swap the implementation of two methods in a single, atomic - operation. This is equivalent to getting the implementation of - each method and then calling method_setImplementation() on the - other one. For this to work, the two methods must have been - returned by class_getInstanceMethod() or class_getClassMethod(). - If 'method_a' or 'method_b' is NULL, do nothing. */ -objc_EXPORT void -method_exchangeImplementations (Method method_a, Method method_b); - /** Implementation: the following functions are in protocols.c. */ /* Return the protocol with name 'name', or nil if it the protocol is Index: ChangeLog =================================================================== --- ChangeLog (revision 165530) +++ ChangeLog (working copy) @@ -1,3 +1,7 @@ +2010-10-15 Nicola Pero + + * objc.dg/gnu-api-2-property.m: New. + 2010-10-15 Xinliang David Li * g++.dg/uninit-pred-3_a.C: New test. Index: objc.dg/gnu-api-2-property.m =================================================================== --- objc.dg/gnu-api-2-property.m (revision 0) +++ objc.dg/gnu-api-2-property.m (revision 0) @@ -0,0 +1,65 @@ +/* Test the Modern GNU Objective-C Runtime API. + + This is test 'property', covering all functions starting with 'property'. */ + +/* { dg-do run } */ +/* { dg-skip-if "" { *-*-* } { "-fnext-runtime" } { "" } } */ + +/* To get the modern GNU Objective-C Runtime API, you include + objc/runtime.h. */ +#include +#include +#include +#include + +@interface MyRootClass +{ Class isa; } ++ alloc; +- init; +@end + +@implementation MyRootClass ++ alloc { return class_createInstance (self, 0); } +- init { return self; } +@end + +@protocol MyProtocol +- (id) variable; +@end + +@protocol MySecondProtocol +- (id) setVariable: (id)value; +@end + +@interface MySubClass : MyRootClass +{ id variable_ivar; } +- (void) setVariable: (id)value; +- (id) variable; +@end + +@implementation MySubClass +- (void) setVariable: (id)value { variable_ivar = value; } +- (id) variable { return variable_ivar; } +@end + + +int main(int argc, void **args) +{ + /* Functions are tested in alphabetical order. */ + + /* TODO: Test new ABI (when available). */ + printf ("Testing property_getAttributes () ...\n"); + { + if (property_getAttributes (NULL) != NULL) + abort (); + } + + /* TODO: Test new ABI (when available). */ + printf ("Testing property_getName () ...\n"); + { + if (property_getName (NULL) != NULL) + abort (); + } + + return 0; +}