diff options
Diffstat (limited to 'libobjc/objc')
46 files changed, 3725 insertions, 0 deletions
diff --git a/libobjc/objc/NXConstStr.h b/libobjc/objc/NXConstStr.h new file mode 100644 index 000000000..40eb66e32 --- /dev/null +++ b/libobjc/objc/NXConstStr.h @@ -0,0 +1,51 @@ +/* Interface for the NXConstantString class for Objective-C. + Copyright (C) 1995, 2004, 2009 Free Software Foundation, Inc. + Contributed by Pieter J. Schoenmakers <tiggr@es.ele.tue.nl> + +This file is part of GCC. + +GCC is free software; you can redistribute it and/or modify it +under the terms of the GNU General Public License as published by the +Free Software Foundation; either version 3, or (at your option) any +later version. + +GCC is distributed in the hope that it will be useful, but WITHOUT +ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public +License for more details. + +Under Section 7 of GPL version 3, you are granted additional +permissions described in the GCC Runtime Library Exception, version +3.1, as published by the Free Software Foundation. + +You should have received a copy of the GNU General Public License and +a copy of the GCC Runtime Library Exception along with this program; +see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +<http://www.gnu.org/licenses/>. */ + + +#ifndef __nxconstantstring_INCLUDE_GNU +#define __nxconstantstring_INCLUDE_GNU + +#include "Object.h" + +#ifdef __cplusplus +extern "C" { +#endif + +@interface NXConstantString: Object +{ + char *c_string; + unsigned int len; +} + +-(const char *) cString; +-(unsigned int) length; + +@end + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/libobjc/objc/Object.h b/libobjc/objc/Object.h new file mode 100644 index 000000000..f036b76b9 --- /dev/null +++ b/libobjc/objc/Object.h @@ -0,0 +1,68 @@ +/* Interface for the Object class for Objective-C. + Copyright (C) 1993, 1994, 1995, 2009, 2010 Free Software Foundation, Inc. + +This file is part of GCC. + +GCC is free software; you can redistribute it and/or modify it +under the terms of the GNU General Public License as published by the +Free Software Foundation; either version 3, or (at your option) any +later version. + +GCC is distributed in the hope that it will be useful, but WITHOUT +ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public +License for more details. + +Under Section 7 of GPL version 3, you are granted additional +permissions described in the GCC Runtime Library Exception, version +3.1, as published by the Free Software Foundation. + +You should have received a copy of the GNU General Public License and +a copy of the GCC Runtime Library Exception along with this program; +see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +<http://www.gnu.org/licenses/>. */ + + +#ifndef __object_INCLUDE_GNU +#define __object_INCLUDE_GNU + +#include "objc.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/* The Object class is a very minimal root class included with the + runtime. It is used as superclass for the two classes included + with the runtime, Protocol and NXConstantString. + + Because Objective-C allows multiple root classes, you can define + your own root class, different from Object. + + In particular, a Foundation library (such as GNUstep Base) is + expected to provide its own root class (typically called NSObject), + fully integrated with the library's own high-level features. It is + expected that you should always use and interact with NSObject, and + mostly ignore Object. */ + +/* All classes are derived from Object. As such, this is the overhead + tacked onto those objects. */ +@interface Object +{ + Class isa; /* A pointer to the instance's class structure. */ +} +- (Class)class; +- (BOOL)isEqual: (id)anObject; +@end + +/* All of the following includes were deprecated in GCC 4.6 and will + be removed in the next release. */ +#include "deprecated/hash.h" +#include "deprecated/typedstream.h" +#include "deprecated/Object.h" + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/libobjc/objc/Protocol.h b/libobjc/objc/Protocol.h new file mode 100644 index 000000000..1cf9892b2 --- /dev/null +++ b/libobjc/objc/Protocol.h @@ -0,0 +1,56 @@ +/* Declare the class Protocol for Objective C programs. + Copyright (C) 1993, 2004, 2009, 2010 Free Software Foundation, Inc. + +This file is part of GCC. + +GCC is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 3, or (at your option) +any later version. + +GCC is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +Under Section 7 of GPL version 3, you are granted additional +permissions described in the GCC Runtime Library Exception, version +3.1, as published by the Free Software Foundation. + +You should have received a copy of the GNU General Public License and +a copy of the GCC Runtime Library Exception along with this program; +see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +<http://www.gnu.org/licenses/>. */ + + +#ifndef __Protocol_INCLUDE_GNU +#define __Protocol_INCLUDE_GNU + +#include "Object.h" + +#ifdef __cplusplus +extern "C" { +#endif + +@interface Protocol : Object +{ +@private + char *protocol_name; + struct objc_protocol_list *protocol_list; + struct objc_method_description_list *instance_methods, *class_methods; +} +@end + +/* The Protocol methods have been replaced by + protocol_getName() + protocol_conformsToProtocol() + protocol_getMethodDescription() +*/ + +#include "deprecated/Protocol.h" + +#ifdef __cplusplus +} +#endif + +#endif /* not __Protocol_INCLUDE_GNU */ diff --git a/libobjc/objc/README b/libobjc/objc/README new file mode 100644 index 000000000..4a8be6e56 --- /dev/null +++ b/libobjc/objc/README @@ -0,0 +1,13 @@ +This directory contains the public headers that are installed when +libobjc is installed. + +Deprecated parts of the API should be moved into objc/deprecated and +then included by public headers until they are finally removed. For +example, if objc-api.h contains an _objc_unexpected_exception variable +which is then deprecated, it should be moved into a header in +objc/deprecated. This header is then included into objc-api.h. + +The result is that all the deprecated parts of the API are clearly +separated in objc/deprecated, while objc/ retains only the current public +API. + diff --git a/libobjc/objc/deprecated/METHOD_NULL.h b/libobjc/objc/deprecated/METHOD_NULL.h new file mode 100644 index 000000000..6912be345 --- /dev/null +++ b/libobjc/objc/deprecated/METHOD_NULL.h @@ -0,0 +1,2 @@ +/* For functions which return Method_t */ +#define METHOD_NULL (Method_t)0 diff --git a/libobjc/objc/deprecated/MetaClass.h b/libobjc/objc/deprecated/MetaClass.h new file mode 100644 index 000000000..01597782c --- /dev/null +++ b/libobjc/objc/deprecated/MetaClass.h @@ -0,0 +1 @@ +typedef struct objc_class *MetaClass; diff --git a/libobjc/objc/deprecated/Object.h b/libobjc/objc/deprecated/Object.h new file mode 100644 index 000000000..e15cf7dd9 --- /dev/null +++ b/libobjc/objc/deprecated/Object.h @@ -0,0 +1,84 @@ +/* The following methods were deprecated in GCC 4.6.0 and will be + removed in the next GCC release. */ +@interface Object (Deprecated) +/* Initializing classes and instances */ ++ initialize; +- init; + +/* Creating, freeing, and copying instances */ ++ new; ++ alloc; +- free; +- copy; +- shallowCopy; +- deepen; +- deepCopy; + +/* Identifying classes */ +- (Class)superClass; +- (MetaClass)metaClass; +- (const char *)name; + +/* Identifying and comparing objects */ +- self; +- (unsigned int)hash; +- (int)compare:(id)anotherObject; + +/* Testing object type */ +- (BOOL)isMetaClass; +- (BOOL)isClass; +- (BOOL)isInstance; + +/* Testing inheritance relationships */ +- (BOOL)isKindOf:(Class)aClassObject; +- (BOOL)isMemberOf:(Class)aClassObject; +- (BOOL)isKindOfClassNamed:(const char *)aClassName; +- (BOOL)isMemberOfClassNamed:(const char *)aClassName; + +/* Testing class functionality */ ++ (BOOL)instancesRespondTo:(SEL)aSel; +- (BOOL)respondsTo:(SEL)aSel; + +/* Testing protocol conformance */ +- (BOOL)conformsTo:(Protocol*)aProtocol; + +/* Introspection */ ++ (IMP)instanceMethodFor:(SEL)aSel; +- (IMP)methodFor:(SEL)aSel; ++ (struct objc_method_description *)descriptionForInstanceMethod:(SEL)aSel; +- (struct objc_method_description *)descriptionForMethod:(SEL)aSel; + +/* Sending messages determined at run time */ +- perform:(SEL)aSel; +- perform:(SEL)aSel with:anObject; +- perform:(SEL)aSel with:anObject1 with:anObject2; + +/* Forwarding */ +- (retval_t)forward:(SEL)aSel :(arglist_t)argFrame; +- (retval_t)performv:(SEL)aSel :(arglist_t)argFrame; + +/* Posing */ ++ poseAs:(Class)aClassObject; +- (Class)transmuteClassTo:(Class)aClassObject; + +/* Enforcing intentions */ +- subclassResponsibility:(SEL)aSel; +- notImplemented:(SEL)aSel; +- shouldNotImplement:(SEL)aSel; + +/* Error handling */ +- doesNotRecognize:(SEL)aSel; +- error:(const char *)aString, ...; + +/* Archiving */ ++ (int)version; ++ setVersion:(int)aVersion; + ++ (int)streamVersion: (TypedStream*)aStream; /* __attribute__ ((deprecated)) */ + +- read: (TypedStream*)aStream; /* __attribute__ ((deprecated)) */ +- write: (TypedStream*)aStream; /* __attribute__ ((deprecated)) */ +- awake; /* __attribute__ ((deprecated)) */ + +@end + diff --git a/libobjc/objc/deprecated/Protocol.h b/libobjc/objc/deprecated/Protocol.h new file mode 100644 index 000000000..7a77f51a0 --- /dev/null +++ b/libobjc/objc/deprecated/Protocol.h @@ -0,0 +1,13 @@ +/* The following methods were deprecated in GCC 4.6.0 and will be + removed in the next GCC release. */ +@interface Protocol (Deprecated) +/* Obtaining attributes intrinsic to the protocol */ +- (const char *)name; + +/* Testing protocol conformance */ +- (BOOL) conformsTo: (Protocol *)aProtocolObject; + +/* Looking up information specific to a protocol */ +- (struct objc_method_description *) descriptionForInstanceMethod:(SEL)aSel; +- (struct objc_method_description *) descriptionForClassMethod:(SEL)aSel; +@end diff --git a/libobjc/objc/deprecated/README b/libobjc/objc/deprecated/README new file mode 100644 index 000000000..3f105196e --- /dev/null +++ b/libobjc/objc/deprecated/README @@ -0,0 +1,11 @@ +This directory contains declarations and features that are deprecated +and that will be removed in future versions of the compiler. + +Note that files in this directory are not really usable headers on +their own - they shouldn't be included directly by end users. They +are header fragments containing deprecated APIs that are still +included (until removed) from the real headers in objc/. + +Files in this directory should not #include any other objc header. +Any include that they need should be done in the real objc/ headers +before including these fragments. diff --git a/libobjc/objc/deprecated/STR.h b/libobjc/objc/deprecated/STR.h new file mode 100644 index 000000000..17c20e2d6 --- /dev/null +++ b/libobjc/objc/deprecated/STR.h @@ -0,0 +1,2 @@ +/* Incredibly obsolete. */ +typedef char *STR; /* String alias */ diff --git a/libobjc/objc/deprecated/hash.h b/libobjc/objc/deprecated/hash.h new file mode 100644 index 000000000..8b718a441 --- /dev/null +++ b/libobjc/objc/deprecated/hash.h @@ -0,0 +1,211 @@ +/* Hash tables for Objective C method dispatch. + Copyright (C) 1993, 1995, 1996, 2004, 2009 Free Software Foundation, Inc. + +This file is part of GCC. + +GCC is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 3, or (at your option) +any later version. + +GCC is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +Under Section 7 of GPL version 3, you are granted additional +permissions described in the GCC Runtime Library Exception, version +3.1, as published by the Free Software Foundation. + +You should have received a copy of the GNU General Public License and +a copy of the GCC Runtime Library Exception along with this program; +see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +<http://www.gnu.org/licenses/>. */ + + + +#ifndef __hash_INCLUDE_GNU +#define __hash_INCLUDE_GNU + +#include <stddef.h> +#include <string.h> + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + +/* + * This data structure is used to hold items + * stored in a hash table. Each node holds + * a key/value pair. + * + * Items in the cache are really of type void *. + */ +typedef struct cache_node +{ + struct cache_node *next; /* Pointer to next entry on the list. + NULL indicates end of list. */ + const void *key; /* Key used to locate the value. Used + to locate value when more than one + key computes the same hash + value. */ + void *value; /* Value stored for the key. */ +} *node_ptr; + + +/* + * This data type is the function that computes a hash code given a key. + * Therefore, the key can be a pointer to anything and the function specific + * to the key type. + * + * Unfortunately there is a mutual data structure reference problem with this + * typedef. Therefore, to remove compiler warnings the functions passed to + * objc_hash_new will have to be casted to this type. + */ +typedef unsigned int (*hash_func_type) (void *, const void *); + +/* + * This data type is the function that compares two hash keys and returns an + * integer greater than, equal to, or less than 0, according as the first + * parameter is lexicographically greater than, equal to, or less than the + * second. + */ + +typedef int (*compare_func_type) (const void *, const void *); + + +/* + * This data structure is the cache. + * + * It must be passed to all of the hashing routines + * (except for new). + */ +typedef struct cache +{ + /* Variables used to implement the hash itself. */ + node_ptr *node_table; /* Pointer to an array of hash nodes. */ + /* Variables used to track the size of the hash table so to determine + when to resize it. */ + unsigned int size; /* Number of buckets allocated for the hash table + (number of array entries allocated for + "node_table"). Must be a power of two. */ + unsigned int used; /* Current number of entries in the hash table. */ + unsigned int mask; /* Precomputed mask. */ + + /* Variables used to implement indexing through the hash table. */ + + unsigned int last_bucket; /* Tracks which entry in the array where + the last value was returned. */ + /* Function used to compute a hash code given a key. + This function is specified when the hash table is created. */ + hash_func_type hash_func; + /* Function used to compare two hash keys to see if they are equal. */ + compare_func_type compare_func; +} *cache_ptr; + + +/* Allocate and initialize a hash table. */ + +cache_ptr objc_hash_new (unsigned int size, + hash_func_type hash_func, + compare_func_type compare_func); + +/* Deallocate all of the hash nodes and the cache itself. */ + +void objc_hash_delete (cache_ptr cache); + +/* Add the key/value pair to the hash table. If the + hash table reaches a level of fullness then it will be resized. + + assert if the key is already in the hash. */ + +void objc_hash_add (cache_ptr *cachep, const void *key, void *value); + +/* Remove the key/value pair from the hash table. + assert if the key isn't in the table. */ + +void objc_hash_remove (cache_ptr cache, const void *key); + +/* Used to index through the hash table. Start with NULL + to get the first entry. + + Successive calls pass the value returned previously. + ** Don't modify the hash during this operation *** + + Cache nodes are returned such that key or value can + be extracted. */ + +node_ptr objc_hash_next (cache_ptr cache, node_ptr node); + +/* Used to return a value from a hash table using a given key. */ + +void *objc_hash_value_for_key (cache_ptr cache, const void *key); + +/* Used to determine if the given key exists in the hash table */ + +BOOL objc_hash_is_key_in_hash (cache_ptr cache, const void *key); + +/************************************************ + + Useful hashing functions. + + Declared inline for your pleasure. + +************************************************/ + +/* Calculate a hash code by performing some + manipulation of the key pointer. (Use the lowest bits + except for those likely to be 0 due to alignment.) */ + +static inline unsigned int +objc_hash_ptr (cache_ptr cache, const void *key) +{ + return ((size_t)key / sizeof (void *)) & cache->mask; +} + + +/* Calculate a hash code by iterating over a NULL + terminate string. */ +static inline unsigned int +objc_hash_string (cache_ptr cache, const void *key) +{ + unsigned int ret = 0; + unsigned int ctr = 0; + const char *ckey = (const char *) key; + + while (*ckey) { + ret ^= *ckey++ << ctr; + ctr = (ctr + 1) % sizeof (void *); + } + + return ret & cache->mask; +} + + +/* Compare two pointers for equality. */ +static inline int +objc_compare_ptrs (const void *k1, const void *k2) +{ + return (k1 == k2); +} + + +/* Compare two strings. */ +static inline int +objc_compare_strings (const void *k1, const void *k2) +{ + if (k1 == k2) + return 1; + else if (k1 == 0 || k2 == 0) + return 0; + else + return ! strcmp ((const char *) k1, (const char *) k2); +} + + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + + +#endif /* not __hash_INCLUDE_GNU */ diff --git a/libobjc/objc/deprecated/objc-list.h b/libobjc/objc/deprecated/objc-list.h new file mode 100644 index 000000000..e542bfc04 --- /dev/null +++ b/libobjc/objc/deprecated/objc-list.h @@ -0,0 +1,155 @@ +/* Generic single linked list to keep various information + Copyright (C) 1993, 1994, 1996, 2009 Free Software Foundation, Inc. + Contributed by Kresten Krab Thorup. + +This file is part of GCC. + +GCC is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 3, or (at your option) +any later version. + +GCC is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +Under Section 7 of GPL version 3, you are granted additional +permissions described in the GCC Runtime Library Exception, version +3.1, as published by the Free Software Foundation. + +You should have received a copy of the GNU General Public License and +a copy of the GCC Runtime Library Exception along with this program; +see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +<http://www.gnu.org/licenses/>. */ + + +#ifndef __GNU_OBJC_LIST_H +#define __GNU_OBJC_LIST_H + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + +struct objc_list { + void *head; + struct objc_list *tail; +}; + +/* Return a cons cell produced from (head . tail) */ + +static inline struct objc_list* +list_cons(void* head, struct objc_list* tail) +{ + struct objc_list* cell; + + cell = (struct objc_list*)objc_malloc(sizeof(struct objc_list)); + cell->head = head; + cell->tail = tail; + return cell; +} + +/* Return the length of a list, list_length(NULL) returns zero */ + +static inline int +list_length(struct objc_list* list) +{ + int i = 0; + while(list) + { + i += 1; + list = list->tail; + } + return i; +} + +/* Return the Nth element of LIST, where N count from zero. If N + larger than the list length, NULL is returned */ + +static inline void* +list_nth(int indx, struct objc_list* list) +{ + while(indx-- != 0) + { + if(list->tail) + list = list->tail; + else + return 0; + } + return list->head; +} + +/* Remove the element at the head by replacing it by its successor */ + +static inline void +list_remove_head(struct objc_list** list) +{ + if ((*list)->tail) + { + struct objc_list* tail = (*list)->tail; /* fetch next */ + *(*list) = *tail; /* copy next to list head */ + objc_free(tail); /* free next */ + } + else /* only one element in list */ + { + objc_free(*list); + (*list) = 0; + } +} + + +/* Remove the element with `car' set to ELEMENT */ + +static inline void +list_remove_elem(struct objc_list** list, void* elem) +{ + while (*list) { + if ((*list)->head == elem) + list_remove_head(list); + list = &((*list)->tail); + } +} + +/* Map FUNCTION over all elements in LIST */ + +static inline void +list_mapcar(struct objc_list* list, void(*function)(void*)) +{ + while(list) + { + (*function)(list->head); + list = list->tail; + } +} + +/* Return element that has ELEM as car */ + +static inline struct objc_list** +list_find(struct objc_list** list, void* elem) +{ + while(*list) + { + if ((*list)->head == elem) + return list; + list = &((*list)->tail); + } + return NULL; +} + +/* Free list (backwards recursive) */ + +static inline void +list_free(struct objc_list* list) +{ + if(list) + { + list_free(list->tail); + objc_free(list); + } +} + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + +#endif /* not __GNU_OBJC_LIST_H */ diff --git a/libobjc/objc/deprecated/objc_error.h b/libobjc/objc/deprecated/objc_error.h new file mode 100644 index 000000000..7a7ebe941 --- /dev/null +++ b/libobjc/objc/deprecated/objc_error.h @@ -0,0 +1,56 @@ +/* This API is incredibly limited and unsophisticated. objc_error() + generally causes the program to abort, so it should only be used + when something so dramatic happens that it could be pointless to + continue. Only two cases I can think of: failure to allocate new + memory or failure to load an Objective-C module. +*/ +/* Error handling + + Call objc_error() or objc_verror() to record an error; this error + routine will generally exit the program but not necessarily if the + user has installed his own error handler. + + Call objc_set_error_handler to assign your own function for + handling errors. The function should return YES if it is ok + to continue execution, or return NO or just abort if the + program should be stopped. The default error handler is just to + print a message on stderr. + + The error handler function should be of type objc_error_handler + The first parameter is an object instance of relevance. + The second parameter is an error code. + The third parameter is a format string in the printf style. + The fourth parameter is a variable list of arguments. */ +void objc_error(id object, int code, const char* fmt, ...); +void objc_verror(id object, int code, const char* fmt, va_list ap); +typedef BOOL (*objc_error_handler)(id, int code, const char *fmt, va_list ap); +objc_error_handler objc_set_error_handler(objc_error_handler func); + +/* Error codes + These are used by the runtime library, and your + error handling may use them to determine if the error is + hard or soft thus whether execution can continue or abort. */ +#define OBJC_ERR_UNKNOWN 0 /* Generic error */ + +#define OBJC_ERR_OBJC_VERSION 1 /* Incorrect runtime version */ +#define OBJC_ERR_GCC_VERSION 2 /* Incorrect compiler version */ +#define OBJC_ERR_MODULE_SIZE 3 /* Bad module size */ +#define OBJC_ERR_PROTOCOL_VERSION 4 /* Incorrect protocol version */ + +#define OBJC_ERR_MEMORY 10 /* Out of memory */ + +#define OBJC_ERR_RECURSE_ROOT 20 /* Attempt to archive the root + object more than once. */ +#define OBJC_ERR_BAD_DATA 21 /* Didn't read expected data */ +#define OBJC_ERR_BAD_KEY 22 /* Bad key for object */ +#define OBJC_ERR_BAD_CLASS 23 /* Unknown class */ +#define OBJC_ERR_BAD_TYPE 24 /* Bad type specification */ +#define OBJC_ERR_NO_READ 25 /* Cannot read stream */ +#define OBJC_ERR_NO_WRITE 26 /* Cannot write stream */ +#define OBJC_ERR_STREAM_VERSION 27 /* Incorrect stream version */ +#define OBJC_ERR_BAD_OPCODE 28 /* Bad opcode */ + +#define OBJC_ERR_UNIMPLEMENTED 30 /* Method is not implemented */ + +#define OBJC_ERR_BAD_STATE 40 /* Bad thread state */ + diff --git a/libobjc/objc/deprecated/objc_get_uninstalled_dtable.h b/libobjc/objc/deprecated/objc_get_uninstalled_dtable.h new file mode 100644 index 000000000..48d508a15 --- /dev/null +++ b/libobjc/objc/deprecated/objc_get_uninstalled_dtable.h @@ -0,0 +1,2 @@ +objc_EXPORT struct sarray* +objc_get_uninstalled_dtable(void); diff --git a/libobjc/objc/deprecated/objc_malloc.h b/libobjc/objc/deprecated/objc_malloc.h new file mode 100644 index 000000000..cf6c6e9d0 --- /dev/null +++ b/libobjc/objc/deprecated/objc_malloc.h @@ -0,0 +1,17 @@ +/* +** Hook functions for memory allocation and disposal. +** This makes it easy to substitute garbage collection systems +** such as Boehm's GC by assigning these function pointers +** to the GC's allocation routines. By default these point +** to the ANSI standard malloc, realloc, free, etc. +** +** Users should call the normal objc routines above for +** memory allocation and disposal within their programs. +*/ +objc_EXPORT void *(*_objc_malloc)(size_t); +objc_EXPORT void *(*_objc_atomic_malloc)(size_t); +objc_EXPORT void *(*_objc_valloc)(size_t); +objc_EXPORT void *(*_objc_realloc)(void *, size_t); +objc_EXPORT void *(*_objc_calloc)(size_t, size_t); +objc_EXPORT void (*_objc_free)(void *); + diff --git a/libobjc/objc/deprecated/objc_msg_sendv.h b/libobjc/objc/deprecated/objc_msg_sendv.h new file mode 100644 index 000000000..825d9a766 --- /dev/null +++ b/libobjc/objc/deprecated/objc_msg_sendv.h @@ -0,0 +1,12 @@ +/* The following types and functions are provided only for + backwards-compatibility and should not be used in new code. They + were deprecated in GCC 4.6 and will be removed in the next + release. */ +typedef void* retval_t; /* return value */ +typedef void(*apply_t)(void); /* function pointer */ +typedef union arglist { + char *arg_ptr; + char arg_regs[sizeof (char*)]; +} *arglist_t; /* argument frame */ + +objc_EXPORT retval_t objc_msg_sendv(id, SEL, arglist_t); diff --git a/libobjc/objc/deprecated/objc_object_alloc.h b/libobjc/objc/deprecated/objc_object_alloc.h new file mode 100644 index 000000000..f6336ca8e --- /dev/null +++ b/libobjc/objc/deprecated/objc_object_alloc.h @@ -0,0 +1,8 @@ +/* These functions are deprecated and currently ignored. */ +/* +** Hook functions for allocating, copying and disposing of instances +*/ +objc_EXPORT id (*_objc_object_alloc)(Class _class); +objc_EXPORT id (*_objc_object_copy)(id object); +objc_EXPORT id (*_objc_object_dispose)(id object); + diff --git a/libobjc/objc/deprecated/objc_unexpected_exception.h b/libobjc/objc/deprecated/objc_unexpected_exception.h new file mode 100644 index 000000000..69ffd4e87 --- /dev/null +++ b/libobjc/objc/deprecated/objc_unexpected_exception.h @@ -0,0 +1,9 @@ +/* +** Hook for uncaught exceptions. This hook is called when an +** exception is thrown and no valid exception handler is in place. +** The function is expected never to return. If the function returns +** the result is currently undefined. This is deprecated. Please use +** objc_set_uncaught_exception_handler() from objc/objc-exception.h +** instead. +*/ +objc_EXPORT void (*_objc_unexpected_exception)(id) __attribute__ ((deprecated)); diff --git a/libobjc/objc/deprecated/objc_valloc.h b/libobjc/objc/deprecated/objc_valloc.h new file mode 100644 index 000000000..a715f1a73 --- /dev/null +++ b/libobjc/objc/deprecated/objc_valloc.h @@ -0,0 +1,2 @@ +void * +objc_valloc(size_t size); diff --git a/libobjc/objc/deprecated/sarray.h b/libobjc/objc/deprecated/sarray.h new file mode 100644 index 000000000..aa2f3350a --- /dev/null +++ b/libobjc/objc/deprecated/sarray.h @@ -0,0 +1,240 @@ +/* Sparse Arrays for Objective C dispatch tables + Copyright (C) 1993, 1995, 1996, 2004, 2009 Free Software Foundation, Inc. + Contributed by Kresten Krab Thorup. + +This file is part of GCC. + +GCC is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 3, or (at your option) +any later version. + +GCC is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +Under Section 7 of GPL version 3, you are granted additional +permissions described in the GCC Runtime Library Exception, version +3.1, as published by the Free Software Foundation. + +You should have received a copy of the GNU General Public License and +a copy of the GCC Runtime Library Exception along with this program; +see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +<http://www.gnu.org/licenses/>. */ + + +#ifndef __sarray_INCLUDE_GNU +#define __sarray_INCLUDE_GNU + +#define OBJC_SPARSE2 /* 2-level sparse array */ +/* #define OBJC_SPARSE3 */ /* 3-level sparse array */ + +#ifdef OBJC_SPARSE2 +extern const char* __objc_sparse2_id; +#endif + +#ifdef OBJC_SPARSE3 +extern const char* __objc_sparse3_id; +#endif + +#include <stddef.h> + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + +extern int nbuckets; /* for stats */ +extern int nindices; +extern int narrays; +extern int idxsize; + +/* An unsigned integer of same size as a pointer */ +#define SIZET_BITS (sizeof(size_t)*8) + +#if defined(__sparc__) || defined(OBJC_SPARSE2) +#define PRECOMPUTE_SELECTORS +#endif + +#ifdef OBJC_SPARSE3 + +/* Buckets are 8 words each */ +#define BUCKET_BITS 3 +#define BUCKET_SIZE (1<<BUCKET_BITS) +#define BUCKET_MASK (BUCKET_SIZE-1) + +/* Indices are 16 words each */ +#define INDEX_BITS 4 +#define INDEX_SIZE (1<<INDEX_BITS) +#define INDEX_MASK (INDEX_SIZE-1) + +#define INDEX_CAPACITY (BUCKET_SIZE*INDEX_SIZE) + +#else /* OBJC_SPARSE2 */ + +/* Buckets are 32 words each */ +#define BUCKET_BITS 5 +#define BUCKET_SIZE (1<<BUCKET_BITS) +#define BUCKET_MASK (BUCKET_SIZE-1) + +#endif /* OBJC_SPARSE2 */ + +typedef size_t sidx; + +#ifdef PRECOMPUTE_SELECTORS + +struct soffset { +#ifdef OBJC_SPARSE3 + unsigned int unused : SIZET_BITS/4; + unsigned int eoffset : SIZET_BITS/4; + unsigned int boffset : SIZET_BITS/4; + unsigned int ioffset : SIZET_BITS/4; +#else /* OBJC_SPARSE2 */ +#ifdef __sparc__ + unsigned long boffset : (SIZET_BITS - 2) - BUCKET_BITS; + unsigned int eoffset : BUCKET_BITS; + unsigned int unused : 2; +#else + unsigned int boffset : SIZET_BITS/2; + unsigned int eoffset : SIZET_BITS/2; +#endif +#endif /* OBJC_SPARSE2 */ +}; + +union sofftype { + struct soffset off; + sidx idx; +}; + +#endif /* not PRECOMPUTE_SELECTORS */ + +union sversion { + int version; + void *next_free; +}; + +struct sbucket { + void* elems[BUCKET_SIZE]; /* elements stored in array */ + union sversion version; /* used for copy-on-write */ +}; + +#ifdef OBJC_SPARSE3 + +struct sindex { + struct sbucket* buckets[INDEX_SIZE]; + union sversion version; /* used for copy-on-write */ +}; + +#endif /* OBJC_SPARSE3 */ + +struct sarray { +#ifdef OBJC_SPARSE3 + struct sindex** indices; + struct sindex* empty_index; +#else /* OBJC_SPARSE2 */ + struct sbucket** buckets; +#endif /* OBJC_SPARSE2 */ + struct sbucket* empty_bucket; + union sversion version; /* used for copy-on-write */ + short ref_count; + struct sarray* is_copy_of; + size_t capacity; +}; + +struct sarray* sarray_new(int, void* default_element); +void sarray_free(struct sarray*); +struct sarray* sarray_lazy_copy(struct sarray*); +void sarray_realloc(struct sarray*, int new_size); +void sarray_at_put(struct sarray*, sidx indx, void* elem); +void sarray_at_put_safe(struct sarray*, sidx indx, void* elem); + +struct sarray* sarray_hard_copy(struct sarray*); /* ... like the name? */ +void sarray_remove_garbage(void); + + +#ifdef PRECOMPUTE_SELECTORS +/* Transform soffset values to ints and vica verca */ +static inline unsigned int +soffset_decode(sidx indx) +{ + union sofftype x; + x.idx = indx; +#ifdef OBJC_SPARSE3 + return x.off.eoffset + + (x.off.boffset*BUCKET_SIZE) + + (x.off.ioffset*INDEX_CAPACITY); +#else /* OBJC_SPARSE2 */ + return x.off.eoffset + (x.off.boffset*BUCKET_SIZE); +#endif /* OBJC_SPARSE2 */ +} + +static inline sidx +soffset_encode(size_t offset) +{ + union sofftype x; + x.off.eoffset = offset%BUCKET_SIZE; +#ifdef OBJC_SPARSE3 + x.off.boffset = (offset/BUCKET_SIZE)%INDEX_SIZE; + x.off.ioffset = offset/INDEX_CAPACITY; +#else /* OBJC_SPARSE2 */ + x.off.boffset = offset/BUCKET_SIZE; +#endif + return (sidx)x.idx; +} + +#else /* not PRECOMPUTE_SELECTORS */ + +static inline size_t +soffset_decode(sidx indx) +{ + return indx; +} + +static inline sidx +soffset_encode(size_t offset) +{ + return offset; +} +#endif /* not PRECOMPUTE_SELECTORS */ + +/* Get element from the Sparse array `array' at offset `indx' */ + +static inline void* sarray_get(struct sarray* array, sidx indx) +{ +#ifdef PRECOMPUTE_SELECTORS + union sofftype x; + x.idx = indx; +#ifdef OBJC_SPARSE3 + return + array-> + indices[x.off.ioffset]-> + buckets[x.off.boffset]-> + elems[x.off.eoffset]; +#else /* OBJC_SPARSE2 */ + return array->buckets[x.off.boffset]->elems[x.off.eoffset]; +#endif /* OBJC_SPARSE2 */ +#else /* not PRECOMPUTE_SELECTORS */ +#ifdef OBJC_SPARSE3 + return array-> + indices[indx/INDEX_CAPACITY]-> + buckets[(indx/BUCKET_SIZE)%INDEX_SIZE]-> + elems[indx%BUCKET_SIZE]; +#else /* OBJC_SPARSE2 */ + return array->buckets[indx/BUCKET_SIZE]->elems[indx%BUCKET_SIZE]; +#endif /* not OBJC_SPARSE3 */ +#endif /* not PRECOMPUTE_SELECTORS */ +} + +static inline void* sarray_get_safe(struct sarray* array, sidx indx) +{ + if(soffset_decode(indx) < array->capacity) + return sarray_get(array, indx); + else + return (array->empty_bucket->elems[0]); +} + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + +#endif /* __sarray_INCLUDE_GNU */ diff --git a/libobjc/objc/deprecated/struct_objc_category.h b/libobjc/objc/deprecated/struct_objc_category.h new file mode 100644 index 000000000..6de3980a9 --- /dev/null +++ b/libobjc/objc/deprecated/struct_objc_category.h @@ -0,0 +1,21 @@ +/* +** The compiler generates one of these structures for each category. A class +** may have many categories and contain both instance and factory methods. +*/ +struct objc_category { + const char* category_name; /* Name of the category. Name + contained in the () of the + category definition. */ + const char* class_name; /* Name of the class to which + the category belongs. */ + MethodList_t instance_methods; /* Linked list of instance + methods defined in the + category. NULL indicates no + instance methods defined. */ + MethodList_t class_methods; /* Linked list of factory + methods defined in the + category. NULL indicates no + class methods defined. */ + struct objc_protocol_list *protocols; /* List of Protocols + conformed to */ +}; diff --git a/libobjc/objc/deprecated/struct_objc_class.h b/libobjc/objc/deprecated/struct_objc_class.h new file mode 100644 index 000000000..07927feb6 --- /dev/null +++ b/libobjc/objc/deprecated/struct_objc_class.h @@ -0,0 +1,56 @@ +/* This structure used to be public, but is now private to the runtime. */ +#define __objc_STRUCT_OBJC_CLASS_defined + +/* +** The compiler generates one of these structures for each class. +** +** This structure is the definition for classes. +** +** This structure is generated by the compiler in the executable and used by +** the run-time during normal messaging operations. Therefore some members +** change type. The compiler generates "char* const" and places a string in +** the following member variables: super_class. +*/ +struct objc_class { + MetaClass class_pointer; /* Pointer to the class's + meta class. */ + struct objc_class* super_class; /* Pointer to the super + class. NULL for class + Object. */ + const char* name; /* Name of the class. */ + long version; /* Unknown. */ + unsigned long info; /* Bit mask. See class masks + defined above. */ + long instance_size; /* Size in bytes of the class. + The sum of the class + definition and all super + class definitions. */ +#ifdef _WIN64 + /* We pad the structure manually to prevent warning when -Wpadded + is used. The compiler automatically pads the structures that it + generates, so this manually padded structure still matches the one + generated by the compiler, but if we don't pad manually, -Wpadded + detects that padding is being added and generates annoying warnings. + This hack is necessary as on LLP64 targets sizeof (long) isn't equal + to sizeof (void *). */ + long pad; +#endif + struct objc_ivar_list* ivars; /* Pointer to a structure that + describes the instance + variables in the class + definition. NULL indicates + no instance variables. Does + not include super class + variables. */ + struct objc_method_list* methods; /* Linked list of instance + methods defined for the + class. */ + struct sarray * dtable; /* Pointer to instance + method dispatch table. */ + struct objc_class* subclass_list; /* Subclasses */ + struct objc_class* sibling_class; + + struct objc_protocol_list *protocols; /* Protocols conformed to */ + void* gc_object_type; +}; + diff --git a/libobjc/objc/deprecated/struct_objc_ivar.h b/libobjc/objc/deprecated/struct_objc_ivar.h new file mode 100644 index 000000000..57170ad11 --- /dev/null +++ b/libobjc/objc/deprecated/struct_objc_ivar.h @@ -0,0 +1,15 @@ +/* +** The compiler generates one of these structures for a class that has +** instance variables defined in its specification. +*/ +typedef struct objc_ivar { + const char* ivar_name; /* Name of the instance + variable as entered in the + class definition. */ + const char* ivar_type; /* Description of the Ivar's + type. Useful for + debuggers. */ + int ivar_offset; /* Byte offset from the base + address of the instance + structure to the variable. */ +} *Ivar_t; diff --git a/libobjc/objc/deprecated/struct_objc_ivar_list.h b/libobjc/objc/deprecated/struct_objc_ivar_list.h new file mode 100644 index 000000000..8f5051fb9 --- /dev/null +++ b/libobjc/objc/deprecated/struct_objc_ivar_list.h @@ -0,0 +1,10 @@ +typedef struct objc_ivar_list { + int ivar_count; /* Number of structures (Ivar) + contained in the list. One + structure per instance + variable defined in the + class. */ + struct objc_ivar ivar_list[1]; /* Variable length + structure. */ +} IvarList, *IvarList_t; + diff --git a/libobjc/objc/deprecated/struct_objc_method.h b/libobjc/objc/deprecated/struct_objc_method.h new file mode 100644 index 000000000..af83c07b6 --- /dev/null +++ b/libobjc/objc/deprecated/struct_objc_method.h @@ -0,0 +1,22 @@ +/* +** The compiler generates one (or more) of these structures for a class that +** has methods defined in its specification. +** +** The implementation of a class can be broken into separate pieces in a file +** and categories can break them across modules. To handle this problem is a +** singly linked list of methods. +*/ +struct objc_method { + SEL method_name; /* This variable is the method's + name. It is a char*. + The unique integer passed to + objc_msg_send is a char* too. + It is compared against + method_name using strcmp. */ + const char* method_types; /* Description of the method's + parameter list. Useful for + debuggers. */ + IMP method_imp; /* Address of the method in the + executable. */ +}; + diff --git a/libobjc/objc/deprecated/struct_objc_method_list.h b/libobjc/objc/deprecated/struct_objc_method_list.h new file mode 100644 index 000000000..5156cabbf --- /dev/null +++ b/libobjc/objc/deprecated/struct_objc_method_list.h @@ -0,0 +1,9 @@ +typedef struct objc_method_list { + struct objc_method_list* method_next; /* This variable is used to link + a method list to another. It + is a singly linked list. */ + int method_count; /* Number of methods defined in + this structure. */ + Method method_list[1]; /* Variable length + structure. */ +} MethodList, *MethodList_t; diff --git a/libobjc/objc/deprecated/struct_objc_module.h b/libobjc/objc/deprecated/struct_objc_module.h new file mode 100644 index 000000000..57950851f --- /dev/null +++ b/libobjc/objc/deprecated/struct_objc_module.h @@ -0,0 +1,24 @@ +/* +** The compiler generates one of these structures for each module that +** composes the executable (eg main.m). +** +** This data structure is the root of the definition tree for the module. +** +** A collect program runs between ld stages and creates a ObjC ctor array. +** That array holds a pointer to each module structure of the executable. +*/ +typedef struct objc_module { + unsigned long version; /* Version of the Module data structure. */ + unsigned long size; /* sizeof(Module) according to the compiler - + only used to sanity check that it matches + sizeof(Module) according to the + runtime. */ + const char* name; /* Name of the file used to compile the + module - not set by modern compilers for + security reasons. */ + Symtab_t symtab; /* Pointer to the Symtab of the module. The + Symtab holds an array of pointers to the + classes and categories defined in the + module. */ +} Module, *Module_t; + diff --git a/libobjc/objc/deprecated/struct_objc_protocol.h b/libobjc/objc/deprecated/struct_objc_protocol.h new file mode 100644 index 000000000..5344e3f54 --- /dev/null +++ b/libobjc/objc/deprecated/struct_objc_protocol.h @@ -0,0 +1,6 @@ +typedef struct objc_protocol { + struct objc_class* class_pointer; + char *protocol_name; + struct objc_protocol_list *protocol_list; + struct objc_method_description_list *instance_methods, *class_methods; +} Protocol; diff --git a/libobjc/objc/deprecated/struct_objc_protocol_list.h b/libobjc/objc/deprecated/struct_objc_protocol_list.h new file mode 100644 index 000000000..5e5788b50 --- /dev/null +++ b/libobjc/objc/deprecated/struct_objc_protocol_list.h @@ -0,0 +1,5 @@ +struct objc_protocol_list { + struct objc_protocol_list *next; + size_t count; + Protocol *list[1]; +}; diff --git a/libobjc/objc/deprecated/struct_objc_selector.h b/libobjc/objc/deprecated/struct_objc_selector.h new file mode 100644 index 000000000..34aaf0d8b --- /dev/null +++ b/libobjc/objc/deprecated/struct_objc_selector.h @@ -0,0 +1,20 @@ +/* This struct used to be public, but is now private to the runtime. */ + +/* +** Definition of a selector. Selectors themselves are not unique, but +** the sel_id is a unique identifier. +*/ +struct objc_selector +{ + void *sel_id; + const char *sel_types; +}; + +inline static BOOL +sel_eq (SEL s1, SEL s2) +{ + if (s1 == 0 || s2 == 0) + return s1 == s2; + else + return s1->sel_id == s2->sel_id; +} diff --git a/libobjc/objc/deprecated/struct_objc_static_instances.h b/libobjc/objc/deprecated/struct_objc_static_instances.h new file mode 100644 index 000000000..9d889bfc0 --- /dev/null +++ b/libobjc/objc/deprecated/struct_objc_static_instances.h @@ -0,0 +1,14 @@ +/* For every class which happens to have statically allocated instances in + this module, one OBJC_STATIC_INSTANCES is allocated by the compiler. + INSTANCES is NULL terminated and points to all statically allocated + instances of this class. */ +struct objc_static_instances +{ + char *class_name; +#ifdef __cplusplus + id instances[1]; +#else + id instances[0]; +#endif +}; + diff --git a/libobjc/objc/deprecated/struct_objc_symtab.h b/libobjc/objc/deprecated/struct_objc_symtab.h new file mode 100644 index 000000000..75bb27f1b --- /dev/null +++ b/libobjc/objc/deprecated/struct_objc_symtab.h @@ -0,0 +1,26 @@ +/* Whereas a Module (defined further down) is the root (typically) of a file, + a Symtab is the root of the class and category definitions within the + module. + + A Symtab contains a variable length array of pointers to classes and + categories defined in the module. */ +typedef struct objc_symtab { + unsigned long sel_ref_cnt; /* Unused (always set to 0). */ + SEL refs; /* The table of selectors referenced in + this module. This is terminated by a + selector with NULL sel_id and NULL + sel_types. */ + unsigned short cls_def_cnt; /* Number of classes compiled + (defined) in the module. */ + unsigned short cat_def_cnt; /* Number of categories + compiled (defined) in the + module. */ + + void *defs[1]; /* Variable array of pointers. + cls_def_cnt of type Class + followed by cat_def_cnt of + type Category_t, followed + by a NULL terminated array + of objc_static_instances. */ +} Symtab, *Symtab_t; + diff --git a/libobjc/objc/deprecated/typedstream.h b/libobjc/objc/deprecated/typedstream.h new file mode 100644 index 000000000..4d948d5fb --- /dev/null +++ b/libobjc/objc/deprecated/typedstream.h @@ -0,0 +1,141 @@ +/* GNU Objective-C Typed Streams interface. + Copyright (C) 1993, 1995, 2004, 2009 Free Software Foundation, Inc. + +This file is part of GCC. + +GCC is free software; you can redistribute it and/or modify it +under the terms of the GNU General Public License as published by the +Free Software Foundation; either version 3, or (at your option) any +later version. + +GCC is distributed in the hope that it will be useful, but WITHOUT +ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public +License for more details. + +Under Section 7 of GPL version 3, you are granted additional +permissions described in the GCC Runtime Library Exception, version +3.1, as published by the Free Software Foundation. + +You should have received a copy of the GNU General Public License and +a copy of the GCC Runtime Library Exception along with this program; +see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +<http://www.gnu.org/licenses/>. */ + + +#ifndef __typedstream_INCLUDE_GNU +#define __typedstream_INCLUDE_GNU + +/* The API in this file was entirely deprecated in GCC 4.6.0 and will + be removed in the following GCC release. +*/ + +#include <stdio.h> + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + +typedef int (*objc_typed_read_func)(void*, char*, int); +typedef int (*objc_typed_write_func)(void*, const char*, int); +typedef int (*objc_typed_flush_func)(void*); +typedef int (*objc_typed_eof_func)(void*); + +#define OBJC_READONLY 0x01 +#define OBJC_WRITEONLY 0x02 + +#define OBJC_MANAGED_STREAM 0x01 +#define OBJC_FILE_STREAM 0x02 +#define OBJC_MEMORY_STREAM 0x04 + +#define OBJC_TYPED_STREAM_VERSION 0x01 + +typedef struct objc_typed_stream { + void* physical; + cache_ptr object_table; /* read/written objects */ + cache_ptr stream_table; /* other read/written but shared things.. */ + cache_ptr class_table; /* class version mapping */ + cache_ptr object_refs; /* forward references */ + int mode; /* OBJC_READONLY or OBJC_WRITEONLY */ + int type; /* MANAGED, FILE, MEMORY etc bit string */ + int version; /* version used when writing */ + int writing_root_p; + objc_typed_read_func read; + objc_typed_write_func write; + objc_typed_eof_func eof; + objc_typed_flush_func flush; +} TypedStream; + +/* opcode masks */ +#define _B_VALUE 0x1fU +#define _B_CODE 0xe0U +#define _B_SIGN 0x10U +#define _B_NUMBER 0x0fU + +/* standard opcodes */ +#define _B_INVALID 0x00U +#define _B_SINT 0x20U +#define _B_NINT 0x40U +#define _B_SSTR 0x60U +#define _B_NSTR 0x80U +#define _B_RCOMM 0xa0U +#define _B_UCOMM 0xc0U +#define _B_EXT 0xe0U + +/* eXtension opcodes */ +#define _BX_OBJECT 0x00U +#define _BX_CLASS 0x01U +#define _BX_SEL 0x02U +#define _BX_OBJREF 0x03U +#define _BX_OBJROOT 0x04U +#define _BX_EXT 0x1fU + +/* +** Read and write objects as specified by TYPE. All the `last' +** arguments are pointers to the objects to read/write. +*/ + +int objc_write_type (TypedStream* stream, const char* type, const void* data) __attribute__ ((deprecated)); +int objc_read_type (TypedStream* stream, const char* type, void* data) __attribute__ ((deprecated)); + +int objc_write_types (TypedStream* stream, const char* type, ...) __attribute__ ((deprecated)); +int objc_read_types (TypedStream* stream, const char* type, ...) __attribute__ ((deprecated)); + +int objc_write_object_reference (TypedStream* stream, id object) __attribute__ ((deprecated)); +int objc_write_root_object (TypedStream* stream, id object) __attribute__ ((deprecated)); + +long objc_get_stream_class_version (TypedStream* stream, Class class_type) __attribute__ ((deprecated)); + + +/* +** Convenience functions +*/ + +int objc_write_array (TypedStream* stream, const char* type, + int count, const void* data) __attribute__ ((deprecated)); +int objc_read_array (TypedStream* stream, const char* type, + int count, void* data) __attribute__ ((deprecated)); + +int objc_write_object (TypedStream* stream, id object) __attribute__ ((deprecated)); +int objc_read_object (TypedStream* stream, id* object) __attribute__ ((deprecated)); + + + +/* +** Open a typed stream for reading or writing. MODE may be either of +** OBJC_READONLY or OBJC_WRITEONLY. +*/ + +TypedStream* objc_open_typed_stream (FILE* physical, int mode) __attribute__ ((deprecated)); +TypedStream* objc_open_typed_stream_for_file (const char* file_name, int mode) __attribute__ ((deprecated)); + +void objc_close_typed_stream (TypedStream* stream) __attribute__ ((deprecated)); + +BOOL objc_end_of_typed_stream (TypedStream* stream) __attribute__ ((deprecated)); +void objc_flush_typed_stream (TypedStream* stream) __attribute__ ((deprecated)); + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + +#endif /* not __typedstream_INCLUDE_GNU */ diff --git a/libobjc/objc/encoding.h b/libobjc/objc/encoding.h new file mode 100644 index 000000000..7852466b8 --- /dev/null +++ b/libobjc/objc/encoding.h @@ -0,0 +1,117 @@ +/* Encoding of types for Objective C. + Copyright (C) 1993, 1997, 2002, 2004, 2009, 2010 + Free Software Foundation, Inc. + +Author: Kresten Krab Thorup + +This file is part of GCC. + +GCC is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 3, or (at your option) +any later version. + +GCC is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +Under Section 7 of GPL version 3, you are granted additional +permissions described in the GCC Runtime Library Exception, version +3.1, as published by the Free Software Foundation. + +You should have received a copy of the GNU General Public License and +a copy of the GCC Runtime Library Exception along with this program; +see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +<http://www.gnu.org/licenses/>. */ + + +#ifndef __encoding_INCLUDE_GNU +#define __encoding_INCLUDE_GNU + +/* This file is to be used with the "traditional" GNU Objective-C + Runtime API (the one declared in objc/objc-api.h). If you are + using the "modern" GNU Objective-C Runtime API, then the useful + functions from this file are declared in objc/runtime.h. */ + +#include "objc-api.h" +#include <ctype.h> + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + +/* The following are used in encode strings to describe some + qualifiers of method and ivar types. */ +#define _C_CONST 'r' +#define _C_IN 'n' +#define _C_INOUT 'N' +#define _C_OUT 'o' +#define _C_BYCOPY 'O' +#define _C_BYREF 'R' +#define _C_ONEWAY 'V' +#define _C_GCINVISIBLE '|' + +/* The same when used as flags. */ +#define _F_CONST 0x01 +#define _F_IN 0x01 +#define _F_OUT 0x02 +#define _F_INOUT 0x03 +#define _F_BYCOPY 0x04 +#define _F_BYREF 0x08 +#define _F_ONEWAY 0x10 +#define _F_GCINVISIBLE 0x20 + +int objc_sizeof_type (const char *type); +int objc_alignof_type (const char *type); +int objc_aligned_size (const char *type); +int objc_promoted_size (const char *type); + +const char *objc_skip_type_qualifiers (const char *type); +const char *objc_skip_typespec (const char *type); +const char *objc_skip_offset (const char *type); +const char *objc_skip_argspec (const char *type); +unsigned objc_get_type_qualifiers (const char *type); + +/* The following functions are replaced, in the modern API, by + method_getNumberOfArguments(), method_getArgumentType(). */ +int method_get_number_of_arguments (struct objc_method *); +int method_get_sizeof_arguments (struct objc_method *); + +/* The following functions are deprecated and they use arglist_t which + is deprecated. */ +char *method_get_first_argument (struct objc_method *, + arglist_t argframe, + const char **type); +char *method_get_next_argument (arglist_t argframe, + const char **type); +char *method_get_nth_argument (struct objc_method *m, + arglist_t argframe, + int arg, + const char **type); + +struct objc_struct_layout +{ + const char *original_type; + const char *type; + const char *prev_type; + unsigned int record_size; + unsigned int record_align; +}; + +void objc_layout_structure (const char *type, + struct objc_struct_layout *layout); +BOOL objc_layout_structure_next_member (struct objc_struct_layout *layout); +void objc_layout_finish_structure (struct objc_struct_layout *layout, + unsigned int *size, + unsigned int *align); +void objc_layout_structure_get_info (struct objc_struct_layout *layout, + unsigned int *offset, + unsigned int *align, + const char **type); + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + +#endif /* __encoding_INCLUDE_GNU */ diff --git a/libobjc/objc/hash.h b/libobjc/objc/hash.h new file mode 100644 index 000000000..8225a0992 --- /dev/null +++ b/libobjc/objc/hash.h @@ -0,0 +1,3 @@ +#include "objc.h" +#include "deprecated/hash.h" + diff --git a/libobjc/objc/message.h b/libobjc/objc/message.h new file mode 100644 index 000000000..8d03fefe4 --- /dev/null +++ b/libobjc/objc/message.h @@ -0,0 +1,141 @@ +/* GNU Objective C Runtime messaging declarations + Copyright (C) 1993, 1995, 1996, 2004, 2009, + 2010 Free Software Foundation, Inc. + +This file is part of GCC. + +GCC is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 3, or (at your option) +any later version. + +GCC is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +Under Section 7 of GPL version 3, you are granted additional +permissions described in the GCC Runtime Library Exception, version +3.1, as published by the Free Software Foundation. + +You should have received a copy of the GNU General Public License and +a copy of the GCC Runtime Library Exception along with this program; +see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +<http://www.gnu.org/licenses/>. */ + +#ifndef __objc_message_INCLUDE_GNU +#define __objc_message_INCLUDE_GNU + +#include "objc.h" +#include "objc-decls.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/* This file includes declarations of the messaging functions and + 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. */ + +/* This function returns the IMP (C function implementing a method) to + use to invoke the method with selector 'op' of receiver 'receiver'. + + This is the function used by the compiler when compiling method + invocations with the GNU runtime. For example, the method call + + 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. */ + +/* In the traditional API, the super class field is called 'class' in + Objective-C and 'super_class' in Objective-C++. In the new API + (objc/runtime.h) it is always called 'super_class'. We detect the + "traditional API" by the fact that the objc/objc-api.h header + include guards are defined, which means objc/objc-api.h has been + included. This works because objc/message.h does not exist in the + Traditional API and is only read because objc-api.h itself includes + it. */ +#ifdef __objc_api_INCLUDE_GNU +/* Traditional API. */ +typedef struct objc_super +{ + id self; /* Id of the object sending the message. */ +#ifdef __cplusplus + Class super_class; +#else + Class class; /* Object's super class. */ +#endif +} Super, *Super_t; +#else +/* Modern API. */ +struct objc_super +{ + id self; /* The receiver of the message. */ + Class super_class; /* The superclass of the receiver. */ +}; +#endif + +/* This is used by the compiler instead of objc_msg_lookup () when + compiling a call to 'super', such as [super method]. This requires + 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 (struct objc_super *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. */ +objc_EXPORT IMP (*__objc_msg_forward)(SEL); +objc_EXPORT IMP (*__objc_msg_forward2)(id, SEL); + +#ifdef __cplusplus +} +#endif + +#endif /* not __objc_message_INCLUDE_GNU */ diff --git a/libobjc/objc/objc-api.h b/libobjc/objc/objc-api.h new file mode 100644 index 000000000..521f79efb --- /dev/null +++ b/libobjc/objc/objc-api.h @@ -0,0 +1,411 @@ +/* GNU Objective-C Runtime API - Traditional API + Copyright (C) 1993, 1995, 1996, 1997, 2001, 2002, 2003, 2004, 2005, + 2007, 2009, 2010 Free Software Foundation, Inc. + +This file is part of GCC. + +GCC is free software; you can redistribute it and/or modify it +under the terms of the GNU General Public License as published by the +Free Software Foundation; either version 3, or (at your option) any +later version. + +GCC is distributed in the hope that it will be useful, but WITHOUT +ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public +License for more details. + +Under Section 7 of GPL version 3, you are granted additional +permissions described in the GCC Runtime Library Exception, version +3.1, as published by the Free Software Foundation. + +You should have received a copy of the GNU General Public License and +a copy of the GCC Runtime Library Exception along with this program; +see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +<http://www.gnu.org/licenses/>. */ + +#ifndef __objc_api_INCLUDE_GNU +#define __objc_api_INCLUDE_GNU + +/* This file declares the "traditional" GNU Objective-C Runtime API. + It is the API supported by older versions of the GNU Objective-C + Runtime. Include this file to use it. + + This API is being replaced by the "modern" GNU Objective-C Runtime + API, which is declared in objc/runtime.h. The "modern" API is very + similar to the API used by the modern Apple/NeXT runtime. + + The last version of GCC supporting the traditional API is GCC 4.6. + This file will not exist in later versions of GCC. + + Because the two APIs have some conflicting definitions (in + particular, Method and Category are defined differently) you should + include either objc/objc-api.h (to use the traditional GNU + Objective-C Runtime API) or objc/runtime.h (to use the modern GNU + Objective-C Runtime API), but not both. */ +#ifdef __objc_runtime_INCLUDE_GNU +# error You can not include both objc/objc-api.h and objc/runtime.h. Include objc/objc-api.h for the traditional GNU Objective-C Runtime API and objc/runtime.h for the modern one. +#endif + +/* TODO: A deprecation warning any time the file is included ? */ + +#include "objc.h" +#ifndef GNU_LIBOBJC_COMPILING_LIBOBJC_ITSELF +# include "deprecated/hash.h" +#endif +#include "thr.h" +#include "objc-decls.h" +#include <stdio.h> +#include <stdarg.h> + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + +#include "deprecated/METHOD_NULL.h" + +/* Method descriptor returned by introspective Object methods. + This is really just the first part of the more complete objc_method + structure defined below and used internally by the runtime. */ +struct objc_method_description +{ + SEL name; /* this is a selector, not a string */ + char *types; /* type encoding */ +}; + +/* The following are used in encode strings to describe the type of + Ivars and Methods. */ +#define _C_ID '@' +#define _C_CLASS '#' +#define _C_SEL ':' +#define _C_CHR 'c' +#define _C_UCHR 'C' +#define _C_SHT 's' +#define _C_USHT 'S' +#define _C_INT 'i' +#define _C_UINT 'I' +#define _C_LNG 'l' +#define _C_ULNG 'L' +#define _C_LNG_LNG 'q' +#define _C_ULNG_LNG 'Q' +#define _C_FLT 'f' +#define _C_DBL 'd' +#define _C_LNG_DBL 'D' +#define _C_BFLD 'b' +#define _C_BOOL 'B' +#define _C_VOID 'v' +#define _C_UNDEF '?' +#define _C_PTR '^' +#define _C_CHARPTR '*' +#define _C_ARY_B '[' +#define _C_ARY_E ']' +#define _C_UNION_B '(' +#define _C_UNION_E ')' +#define _C_STRUCT_B '{' +#define _C_STRUCT_E '}' +#define _C_VECTOR '!' +#define _C_COMPLEX 'j' + +/* _C_ATOM is never generated by the compiler. You can treat it as + equivalent to "*". */ +#define _C_ATOM '%' + +#include "deprecated/objc_error.h" + +#include "deprecated/struct_objc_static_instances.h" +#include "deprecated/struct_objc_symtab.h" +#include "deprecated/struct_objc_module.h" +#include "deprecated/struct_objc_ivar.h" +#include "deprecated/struct_objc_ivar_list.h" +#include "deprecated/struct_objc_method.h" +typedef struct objc_method Method, *Method_t; + +#include "deprecated/struct_objc_method_list.h" +#include "deprecated/struct_objc_protocol_list.h" + +/* +** This is used to assure consistent access to the info field of +** classes +*/ +#ifndef HOST_BITS_PER_LONG +#define HOST_BITS_PER_LONG (sizeof(long)*8) +#endif + +#define __CLS_INFO(cls) ((cls)->info) +#define __CLS_ISINFO(cls, mask) ((__CLS_INFO(cls)&mask)==mask) +#define __CLS_SETINFO(cls, mask) (__CLS_INFO(cls) |= mask) + +/* The structure is of type MetaClass */ +#define _CLS_META 0x2L +#define CLS_ISMETA(cls) ((cls)&&__CLS_ISINFO(cls, _CLS_META)) + + +/* The structure is of type Class */ +#define _CLS_CLASS 0x1L +#define CLS_ISCLASS(cls) ((cls)&&__CLS_ISINFO(cls, _CLS_CLASS)) + +/* +** The class is initialized within the runtime. This means that +** it has had correct super and sublinks assigned +*/ +#define _CLS_RESOLV 0x8L +#define CLS_ISRESOLV(cls) __CLS_ISINFO(cls, _CLS_RESOLV) +#define CLS_SETRESOLV(cls) __CLS_SETINFO(cls, _CLS_RESOLV) + +/* +** The class has been send a +initialize message or a such is not +** defined for this class +*/ +#define _CLS_INITIALIZED 0x04L +#define CLS_ISINITIALIZED(cls) __CLS_ISINFO(cls, _CLS_INITIALIZED) +#define CLS_SETINITIALIZED(cls) __CLS_SETINFO(cls, _CLS_INITIALIZED) + +/* +** The class number of this class. This must be the same for both the +** class and its meta class object +*/ +#define CLS_GETNUMBER(cls) (__CLS_INFO(cls) >> (HOST_BITS_PER_LONG/2)) +#define CLS_SETNUMBER(cls, num) \ + ({ (cls)->info <<= (HOST_BITS_PER_LONG/2); \ + (cls)->info >>= (HOST_BITS_PER_LONG/2); \ + __CLS_SETINFO(cls, (((unsigned long)num) << (HOST_BITS_PER_LONG/2))); }) + +#include "deprecated/struct_objc_category.h" + +typedef struct objc_category Category, *Category_t; + +/* We include message.h for compatibility with the old objc-api.h + which included the declarations currently in message.h. The + Apple/NeXT runtime does not do this and only includes message.h in + objc-runtime.h. It does not matter that much since most of the + definitions in message.h are runtime-specific. */ +#include "message.h" + +/* +** This is a hook which is called by objc_lookup_class and +** objc_get_class if the runtime is not able to find the class. +** This may e.g. try to load in the class using dynamic loading. +** The function is guaranteed to be passed a non-NULL name string. +** In the Modern API, this is replaced by +** objc_setGetUnknownClassHandler (). +*/ +objc_EXPORT Class (*_objc_lookup_class)(const char *name); + +/* +** This is a hook which is called by __objc_exec_class every time a class +** or a category is loaded into the runtime. This may e.g. help a +** dynamic loader determine the classes that have been loaded when +** an object file is dynamically linked in. +*/ +objc_EXPORT void (*_objc_load_callback)(Class _class, Category* category); + +#include "deprecated/objc_object_alloc.h" + +/* + Standard functions for memory allocation and disposal. Users should + use these functions in their ObjC programs so that they work so that + they work properly with garbage collectors. +*/ +objc_EXPORT void * +objc_malloc(size_t size); + +/* FIXME: Shouldn't the following be called objc_malloc_atomic ? The + GC function is GC_malloc_atomic() which makes sense. + */ +objc_EXPORT void * +objc_atomic_malloc(size_t size); + +objc_EXPORT void * +objc_realloc(void *mem, size_t size); + +objc_EXPORT void * +objc_calloc(size_t nelem, size_t size); + +objc_EXPORT void +objc_free(void *mem); + +#include "deprecated/objc_valloc.h" +#include "deprecated/objc_malloc.h" + +#include "deprecated/objc_unexpected_exception.h" + +objc_EXPORT Method_t class_get_class_method(MetaClass _class, SEL aSel); + +objc_EXPORT Method_t class_get_instance_method(Class _class, SEL aSel); + +objc_EXPORT Class class_pose_as(Class impostor, Class superclass); + +objc_EXPORT Class objc_get_class(const char *name); + +objc_EXPORT Class objc_lookup_class(const char *name); + +objc_EXPORT Class objc_next_class(void **enum_state); + +objc_EXPORT const char *sel_get_name(SEL selector); + +objc_EXPORT const char *sel_get_type(SEL selector); + +objc_EXPORT SEL sel_get_uid(const char *name); + +objc_EXPORT SEL sel_get_any_uid(const char *name); + +objc_EXPORT SEL sel_get_any_typed_uid(const char *name); + +objc_EXPORT SEL sel_get_typed_uid(const char *name, const char*); + +objc_EXPORT SEL sel_register_name(const char *name); + +objc_EXPORT SEL sel_register_typed_name(const char *name, const char*type); + + +objc_EXPORT BOOL sel_is_mapped (SEL aSel); + +extern id class_create_instance(Class _class); + +static inline const char * +class_get_class_name(Class _class) +{ + return CLS_ISCLASS(_class)?_class->name:((_class==Nil)?"Nil":0); +} + +static inline long +class_get_instance_size(Class _class) +{ + return CLS_ISCLASS(_class)?_class->instance_size:0; +} + +static inline MetaClass +class_get_meta_class(Class _class) +{ + return CLS_ISCLASS(_class)?_class->class_pointer:Nil; +} + +static inline Class +class_get_super_class(Class _class) +{ + return CLS_ISCLASS(_class)?_class->super_class:Nil; +} + +static inline int +class_get_version(Class _class) +{ + return CLS_ISCLASS(_class)?_class->version:-1; +} + +static inline BOOL +class_is_class(Class _class) +{ + return CLS_ISCLASS(_class); +} + +static inline BOOL +class_is_meta_class(Class _class) +{ + return CLS_ISMETA(_class); +} + + +static inline void +class_set_version(Class _class, long version) +{ + if (CLS_ISCLASS(_class)) + _class->version = version; +} + +static inline void * +class_get_gc_object_type (Class _class) +{ + return CLS_ISCLASS(_class) ? _class->gc_object_type : NULL; +} + +/* Mark the instance variable as innaccessible to the garbage collector */ +extern void class_ivar_set_gcinvisible (Class _class, + const char* ivarname, + BOOL gcInvisible); + +objc_EXPORT IMP method_get_imp(Method_t method); + +objc_EXPORT IMP get_imp (Class _class, SEL sel); + +/* object_copy used to take a single argument in the traditional GNU + Objective-C Runtime API (the one declared here), but takes 2 in the + modern API (implemented in the actual runtime). Define the old + object_copy in terms of the new one. */ +objc_EXPORT id object_copy (id object, size_t size); +#define object_copy(X) (object_copy ((X), 0)) + +objc_EXPORT id object_dispose(id object); + +static inline Class +object_get_class(id object) +{ + return ((object!=nil) + ? (CLS_ISCLASS(object->class_pointer) + ? object->class_pointer + : (CLS_ISMETA(object->class_pointer) + ? (Class)object + : Nil)) + : Nil); +} + +static inline const char * +object_get_class_name(id object) +{ + return ((object!=nil)?(CLS_ISCLASS(object->class_pointer) + ?object->class_pointer->name + :((Class)object)->name) + :"Nil"); +} + +static inline MetaClass +object_get_meta_class(id object) +{ + return ((object!=nil)?(CLS_ISCLASS(object->class_pointer) + ?object->class_pointer->class_pointer + :(CLS_ISMETA(object->class_pointer) + ?object->class_pointer + :Nil)) + :Nil); +} + +static inline Class +object_get_super_class +(id object) +{ + return ((object!=nil)?(CLS_ISCLASS(object->class_pointer) + ?object->class_pointer->super_class + :(CLS_ISMETA(object->class_pointer) + ?((Class)object)->super_class + :Nil)) + :Nil); +} + +static inline BOOL +object_is_class (id object) +{ + return ((object != nil) && CLS_ISMETA (object->class_pointer)); +} + +static inline BOOL +object_is_instance (id object) +{ + return ((object != nil) && CLS_ISCLASS (object->class_pointer)); +} + +static inline BOOL +object_is_meta_class (id object) +{ + return ((object != nil) + && !object_is_instance (object) + && !object_is_class (object)); +} + +#include "deprecated/objc_get_uninstalled_dtable.h" + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + +#endif /* not __objc_api_INCLUDE_GNU */ + + + diff --git a/libobjc/objc/objc-decls.h b/libobjc/objc/objc-decls.h new file mode 100644 index 000000000..44df64397 --- /dev/null +++ b/libobjc/objc/objc-decls.h @@ -0,0 +1,46 @@ +/* GNU Objective-C Extern helpers for Win32. + Copyright (C) 2004, 2009, 2010 Free Software Foundation, Inc. + +This file is part of GCC. + +GCC is free software; you can redistribute it and/or modify it +under the terms of the GNU General Public License as published by the +Free Software Foundation; either version 3, or (at your option) any +later version. + +GCC is distributed in the hope that it will be useful, but WITHOUT +ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public +License for more details. + +Under Section 7 of GPL version 3, you are granted additional +permissions described in the GCC Runtime Library Exception, version +3.1, as published by the Free Software Foundation. + +You should have received a copy of the GNU General Public License and +a copy of the GCC Runtime Library Exception along with this program; +see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +<http://www.gnu.org/licenses/>. */ + + +#ifndef __objc_decls_INCLUDE_GNU +#define __objc_decls_INCLUDE_GNU + +#if defined (_WIN32) || defined (__WIN32__) || defined (WIN32) + +# ifdef DLL_EXPORT /* defined by libtool (if required) */ +# define objc_EXPORT +# define objc_DECLARE +# else +# define objc_EXPORT extern __declspec(dllimport) +# define objc_DECLARE extern __declspec(dllimport) +# endif + +#else + +# define objc_EXPORT extern +# define objc_DECLARE + +#endif + +#endif /* __objc_decls_INCLUDE_GNU */ diff --git a/libobjc/objc/objc-exception.h b/libobjc/objc/objc-exception.h new file mode 100644 index 000000000..4f3ee4fbf --- /dev/null +++ b/libobjc/objc/objc-exception.h @@ -0,0 +1,109 @@ +/* GNU Objective C Runtime native exceptions + Copyright (C) 2010 Free Software Foundation, Inc. + Contributed by Nicola Pero <nicola.pero@meta-innovation.com> + +This file is part of GCC. + +GCC is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 3, or (at your option) +any later version. + +GCC is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +Under Section 7 of GPL version 3, you are granted additional +permissions described in the GCC Runtime Library Exception, version +3.1, as published by the Free Software Foundation. + +You should have received a copy of the GNU General Public License and +a copy of the GCC Runtime Library Exception along with this program; +see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +<http://www.gnu.org/licenses/>. */ + +#ifndef __objc_exception_INCLUDE_GNU +#define __objc_exception_INCLUDE_GNU + +#include "objc.h" +#include "objc-decls.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/* 'objc_exception_throw' throws the exception 'exception', which is + an exception object. + + Calls to 'objc_exception_throw' are automatically generated by the + compiler: an Objective-C "@throw exception;" statement gets + compiled into the equivalent of "objc_exception_throw + (exception);". + + 'objc_exception_throw' searches for a @catch() that can catch the + exception. By default, @catch (MyClass object) will catch all + exception objects that are of class MyClass or of a subclass of + MyClass; if the exception object is 'nil', then the exception can + only be caught with a catch-all exception handler where no + exception class is specified (such as @catch(id object)). This + behaviour can be customized by setting an 'objc_exception_matcher' + function (using objc_set_exception_matcher(), see below); if one is + set, it is used instead of the default one. + + If the exception is uncaught (there is no @catch() to catch it), + the program aborts. It is possible to customize this behaviour by + setting an 'objc_uncaught_exception_handler' function (using + objc_set_uncaught_exception_handler(), see below); if one is set, + it is executed before abort() is called. An uncaught exception + handler is expected to never return. */ +objc_EXPORT void objc_exception_throw (id exception); + +/* Compatibility note: the Apple/NeXT runtime seems to also have + objc_exception_rethrow(), objc_begin_catch() and objc_end_catch(). + Currently the GNU runtime does not use them. */ + +/* The following functions allow customizing to a certain extent the + exception handling. They are not thread safe and should be called + during the program initialization before threads are started. They + are mostly reserved for "Foundation" libraries; in the case of + GNUstep, GNUstep Base may be using these functions to improve the + standard exception handling. You probably shouldn't use these + functions unless you are writing your own Foundation library. */ + +/* Compatibility note: objc_set_exception_preprocessor() (available on + the Apple/NeXT runtime) is not available on the GNU runtime. */ + +/* An 'objc_exception_matcher' function is used to match an exception + to a @catch clause. 'catch_class' is the class of objects caught + by the @catch clause (for example, in "@catch (Object *o)", the + catch_class is Object). It should return 1 if the exception should + be caught by a @catch with a catch_class argument, and 0 if + not. */ +typedef int (*objc_exception_matcher)(Class catch_class, id exception); + +/* Sets a new exception matcher function, and returns the previous + exception matcher function. This function is not safe to call in a + multi-threaded environment because other threads may be trying to + invoke the exception matcher while you change it! */ +objc_EXPORT objc_exception_matcher +objc_setExceptionMatcher (objc_exception_matcher new_matcher); + + +/* An 'objc_uncaught_exception_handler' function is a function that + handles uncaught exceptions. It should never return. */ +typedef void (*objc_uncaught_exception_handler)(id exception); + +/* Sets a new uncaught exception handler function, and returns the + previous exception handler function. This function is not safe to + call in a multi-threaded environment because other threads may be + trying to invoke the uncaught exception handler while you change + it. */ +objc_EXPORT objc_uncaught_exception_handler +objc_setUncaughtExceptionHandler (objc_uncaught_exception_handler new_handler); + +#ifdef __cplusplus +} +#endif + +#endif /* not __objc_exception_INCLUDE_GNU */ diff --git a/libobjc/objc/objc-list.h b/libobjc/objc/objc-list.h new file mode 100644 index 000000000..b713a3c0e --- /dev/null +++ b/libobjc/objc/objc-list.h @@ -0,0 +1,2 @@ +#include "deprecated/objc-list.h" + diff --git a/libobjc/objc/objc-sync.h b/libobjc/objc/objc-sync.h new file mode 100644 index 000000000..04d1db653 --- /dev/null +++ b/libobjc/objc/objc-sync.h @@ -0,0 +1,69 @@ +/* GNU Objective C Runtime @synchronized implementation + Copyright (C) 2010 Free Software Foundation, Inc. + Contributed by Nicola Pero <nicola.pero@meta-innovation.com> + +This file is part of GCC. + +GCC is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 3, or (at your option) +any later version. + +GCC is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +Under Section 7 of GPL version 3, you are granted additional +permissions described in the GCC Runtime Library Exception, version +3.1, as published by the Free Software Foundation. + +You should have received a copy of the GNU General Public License and +a copy of the GCC Runtime Library Exception along with this program; +see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +<http://www.gnu.org/licenses/>. */ + +#ifndef __objc_sync_INCLUDE_GNU +#define __objc_sync_INCLUDE_GNU + +#include "objc.h" +#include "objc-decls.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/* These functions are automatically called by @synchronized(). */ + +/* 'objc_sync_enter' is automatically called when entering a + @synchronized() block. It locks the recursive lock associated with + 'object'. If 'object' is nil, it does nothing. It returns + OBJC_SYNC_SUCCESS on success; see the enumeration below for error + values. + + Note that you should not rely on the behaviour when 'object' is nil + because it could change. */ +objc_EXPORT int objc_sync_enter (id object); + +/* 'objc_sync_exit' is automatically called when exiting from a + @synchronized() block. It unlocks the recursive lock associated + with 'object'. If 'object' is nil, it does nothing. It returns + OBJC_SYNC_SUCCESS on success; see the enumeration below for error + values. */ +objc_EXPORT int objc_sync_exit (id object); + +/* All the possible return values for objc_sync_enter() and + objc_sync_exit(). + */ +enum { + OBJC_SYNC_SUCCESS = 0, + OBJC_SYNC_NOT_OWNING_THREAD_ERROR = -1, + OBJC_SYNC_TIMED_OUT = -2, + OBJC_SYNC_NOT_INITIALIZED = -3 +}; + +#ifdef __cplusplus +} +#endif + +#endif /* not __objc_sync_INCLUDE_GNU */ diff --git a/libobjc/objc/objc.h b/libobjc/objc/objc.h new file mode 100644 index 000000000..ece0f8841 --- /dev/null +++ b/libobjc/objc/objc.h @@ -0,0 +1,169 @@ +/* Basic data types for Objective C. + Copyright (C) 1993, 1995, 1996, 2004, 2009, + 2010 Free Software Foundation, Inc. + +This file is part of GCC. + +GCC is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 3, or (at your option) +any later version. + +GCC is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +Under Section 7 of GPL version 3, you are granted additional +permissions described in the GCC Runtime Library Exception, version +3.1, as published by the Free Software Foundation. + +You should have received a copy of the GNU General Public License and +a copy of the GCC Runtime Library Exception along with this program; +see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +<http://www.gnu.org/licenses/>. */ + +#ifndef __objc_INCLUDE_GNU +#define __objc_INCLUDE_GNU + +/* This file contains the definition of the basic types used by the + Objective-C language. It needs to be included to do almost + anything with Objective-C. */ + +#ifdef __cplusplus +extern "C" { +#endif + +#include <stddef.h> + +/* objc-decls.h is included because deprecated/objc_msg_sendv.h needs + it. When that goes away, the include of objc-decls.h should be + removed. */ +#include "objc-decls.h" + +/* The current version of the GNU Objective-C Runtime library in + compressed ISO date format. This should be updated any time a new + version is released with changes to the public API (there is no + need to update it if there were no API changes since the previous + release). This macro is only defined starting with the GNU + Objective-C Runtime shipped with GCC 4.6.0. If it is not defined, + it is either an older version of the runtime, or another runtime. */ +#define __GNU_LIBOBJC__ 20100911 + +/* Definition of the boolean type. + + Compatibility note: the Apple/NeXT runtime defines a BOOL as a + 'signed char'. The GNU runtime uses an 'unsigned char'. + + Important: this could change and we could switch to 'typedef bool + BOOL' in the future. Do not depend on the type of BOOL. */ +#undef BOOL +typedef unsigned char BOOL; + +#define YES (BOOL)1 +#define NO (BOOL)0 + +/* The basic Objective-C types (SEL, Class, id) are defined as pointer + to opaque structures. The details of the structures are private to + the runtime and may potentially change from one version to the + other. */ + +/* A SEL (selector) represents an abstract method (in the + object-oriented sense) and includes all the details of how to + invoke the method (which means its name, arguments and return + types) but provides no implementation of its own. You can check + whether a class implements a selector or not, and if you have a + selector and know that the class implements it, you can use it to + call the method for an object in the class. */ +typedef const struct objc_selector *SEL; +#include "deprecated/struct_objc_selector.h" + +/* A Class is a class (in the object-oriented sense). In Objective-C + there is the complication that each Class is an object itself, and + so belongs to a class too. This class that a class belongs to is + called its 'meta class'. */ +typedef struct objc_class *Class; +#include "deprecated/MetaClass.h" +#include "deprecated/struct_objc_class.h" + +/* An 'id' is an object of an unknown class. The way the object data + is stored inside the object is private and what you see here is + only the beginning of the actual struct. The first field is always + a pointer to the Class that the object belongs to. */ +typedef struct objc_object +{ + /* 'class_pointer' is the Class that the object belongs to. In case + of a Class object, this pointer points to the meta class. + + Compatibility Note: The Apple/NeXT runtime calls this field + 'isa'. To access this field, use object_getClass() from + runtime.h, which is an inline function so does not add any + overhead and is also portable to other runtimes. */ + Class class_pointer; +} *id; + +/* 'IMP' is a C function that implements a method. When retrieving + the implementation of a method from the runtime, this is the 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. */ +typedef id (*IMP)(id, SEL, ...); + +/* 'nil' is the null object. Messages to nil do nothing and always + return 0. */ +#define nil (id)0 + +/* 'Nil' is the null class. Since classes are objects too, this is + actually the same object as 'nil' (and behaves in the same way), + but it has a type of Class, so it is good to use it instead of + 'nil' if you are comparing a Class object to nil as it enables the + compiler to do some type-checking. */ +#define Nil (Class)0 + +#include "deprecated/STR.h" + +/* TODO: Move the 'Protocol' declaration into objc/runtime.h. A + Protocol is simply an object, not a basic Objective-C type. The + Apple runtime defines Protocol in objc/runtime.h too, so it's good + to move it there for API compatibility. */ + +/* A 'Protocol' is a formally defined list of selectors (normally + created using the @protocol Objective-C syntax). It is mostly used + at compile-time to check that classes implement all the methods + that they are supposed to. Protocols are also available in the + runtime system as Protocol objects. */ +#ifndef __OBJC__ + /* Once we stop including the deprecated struct_objc_protocol.h + there is no reason to even define a 'struct objc_protocol'. As + all the structure details will be hidden, a Protocol basically is + simply an object (as it should be). */ + /* typedef struct objc_object Protocol; */ + #include "deprecated/struct_objc_protocol.h" +#else /* __OBJC__ */ + @class Protocol; +#endif + +/* Deprecated include - here temporarily, for backwards-compatibility + as reval_t, apply_t, arglist_t and objc_msg_lookup() used to be + defined here. objc_msg_lookup() is now defined in message.h, + included by objc-api.h or runtime.h. */ +#include "deprecated/objc_msg_sendv.h" + +/* Compatibility note: the Apple/NeXT runtime defines sel_getName(), + sel_registerName(), object_getClassName(), object_getIndexedIvars() + in this file while the GNU runtime defines them in runtime.h. + + The reason the GNU runtime does not define them here is that they + are not basic Objective-C types (defined in this file), but are + part of the runtime API (defined in runtime.h). */ + +#ifdef __cplusplus +} +#endif + +#endif /* not __objc_INCLUDE_GNU */ diff --git a/libobjc/objc/runtime.h b/libobjc/objc/runtime.h new file mode 100644 index 000000000..6e1f1ec36 --- /dev/null +++ b/libobjc/objc/runtime.h @@ -0,0 +1,1153 @@ +/* GNU Objective-C Runtime API - Modern API + Copyright (C) 2010 Free Software Foundation, Inc. + Contributed by Nicola Pero <nicola.pero@meta-innovation.com> + +This file is part of GCC. + +GCC is free software; you can redistribute it and/or modify it +under the terms of the GNU General Public License as published by the +Free Software Foundation; either version 3, or (at your option) any +later version. + +GCC is distributed in the hope that it will be useful, but WITHOUT +ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public +License for more details. + +Under Section 7 of GPL version 3, you are granted additional +permissions described in the GCC Runtime Library Exception, version +3.1, as published by the Free Software Foundation. + +You should have received a copy of the GNU General Public License and +a copy of the GCC Runtime Library Exception along with this program; +see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +<http://www.gnu.org/licenses/>. */ + +#ifndef __objc_runtime_INCLUDE_GNU +#define __objc_runtime_INCLUDE_GNU + +/* + This file declares the "modern" GNU Objective-C Runtime API. + Include this file to use it. + + This API is replacing the "traditional" GNU Objective-C Runtime API + (declared in objc/objc-api.h) which is the one supported by older + versions of the GNU Objective-C Runtime. The "modern" API is very + similar to the API used by the modern Apple/NeXT runtime. + + Because the two APIs have some conflicting definitions (in + particular, Method and Category are defined differently) you should + include either objc/objc-api.h (to use the traditional GNU + Objective-C Runtime API) or objc/runtime.h (to use the modern GNU + Objective-C Runtime API), but not both. +*/ +#ifdef __objc_api_INCLUDE_GNU +# error You can not include both objc/objc-api.h and objc/runtime.h. Include objc/objc-api.h for the traditional GNU Objective-C Runtime API and objc/runtime.h for the modern one. +#endif + +#include "objc.h" +#include "objc-decls.h" + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + +/* An 'Ivar' represents an instance variable. It holds information + about the name, type and offset of the instance variable. */ +typedef struct objc_ivar *Ivar; + +/* A 'Property' represents a property. It holds information about the + name of the property, and its attributes. + + Compatibility Note: the Apple/NeXT runtime defines this as + objc_property_t, so we define it that way as well, but obviously + Property is the right name. */ +typedef struct objc_property *Property; +typedef struct objc_property *objc_property_t; + +/* A 'Method' represents a method. It holds information about the + name, types and the IMP of the method. */ +typedef struct objc_method *Method; + +/* A 'Category' represents a category. It holds information about the + name of the category, the class it belongs to, and the methods, + protocols and such like provided by the category. */ +typedef struct objc_category *Category; + +/* 'Protocol' is defined in objc/objc.h (which is included by this + file). */ + +/* Method descriptor returned by introspective Object methods. At the + moment, this is really just the first part of the more complete + objc_method structure used internally by the runtime. (PS: In the + GNU Objective-C Runtime, selectors already include a type, so an + objc_method_description does not add much to a SEL. But in other + runtimes, that is not the case, which is why + objc_method_description exists). */ +struct objc_method_description +{ + SEL name; /* Selector (name and signature) */ + char *types; /* Type encoding */ +}; + +/* The following are used in encode strings to describe the type of + Ivars and Methods. */ +#define _C_ID '@' +#define _C_CLASS '#' +#define _C_SEL ':' +#define _C_CHR 'c' +#define _C_UCHR 'C' +#define _C_SHT 's' +#define _C_USHT 'S' +#define _C_INT 'i' +#define _C_UINT 'I' +#define _C_LNG 'l' +#define _C_ULNG 'L' +#define _C_LNG_LNG 'q' +#define _C_ULNG_LNG 'Q' +#define _C_FLT 'f' +#define _C_DBL 'd' +#define _C_LNG_DBL 'D' +#define _C_BFLD 'b' +#define _C_BOOL 'B' +#define _C_VOID 'v' +#define _C_UNDEF '?' +#define _C_PTR '^' +#define _C_CHARPTR '*' +#define _C_ARY_B '[' +#define _C_ARY_E ']' +#define _C_UNION_B '(' +#define _C_UNION_E ')' +#define _C_STRUCT_B '{' +#define _C_STRUCT_E '}' +#define _C_VECTOR '!' +#define _C_COMPLEX 'j' + +/* _C_ATOM is never generated by the compiler. You can treat it as + equivalent to "*". */ +#define _C_ATOM '%' + +/* The following are used in encode strings to describe some + qualifiers of method and ivar types. */ +#define _C_CONST 'r' +#define _C_IN 'n' +#define _C_INOUT 'N' +#define _C_OUT 'o' +#define _C_BYCOPY 'O' +#define _C_BYREF 'R' +#define _C_ONEWAY 'V' +#define _C_GCINVISIBLE '|' + +/* The same when used as flags. */ +#define _F_CONST 0x01 +#define _F_IN 0x01 +#define _F_OUT 0x02 +#define _F_INOUT 0x03 +#define _F_BYCOPY 0x04 +#define _F_BYREF 0x08 +#define _F_ONEWAY 0x10 +#define _F_GCINVISIBLE 0x20 + + +/** Implementation: the following functions are defined inline. */ + +/* Return the class of 'object', or Nil if the object is nil. If + 'object' is a class, the meta class is returned; if 'object' is a + meta class, the root meta class is returned (note that this is + different from the traditional GNU Objective-C Runtime API function + object_get_class(), which for a meta class would return the meta + class itself). This function is inline, so it is really fast and + should be used instead of accessing object->class_pointer + directly. */ +static inline Class +object_getClass (id object) +{ + if (object != nil) + return object->class_pointer; + else + return Nil; +} + + +/** Implementation: the following functions are in selector.c. */ + +/* Return the name of a given selector. If 'selector' is NULL, return + "<null selector>". */ +objc_EXPORT const char *sel_getName (SEL selector); + +/* Return the type of a given selector. Return NULL if selector is + NULL. + + Compatibility Note: the Apple/NeXT runtime has untyped selectors, + so it does not have this function, which is specific to the GNU + Runtime. */ +objc_EXPORT const char *sel_getTypeEncoding (SEL selector); + +/* This is the same as sel_registerName (). Please use + sel_registerName () instead. */ +objc_EXPORT SEL sel_getUid (const char *name); + +/* Register a selector with a given name (but unspecified types). If + you know the types, it is better to call sel_registerTypedName(). + If a selector with this name and no types already exists, it is + returned. Note that this function should really be called + 'objc_registerSelector'. Return NULL if 'name' is NULL. */ +objc_EXPORT SEL sel_registerName (const char *name); + +/* Register a selector with a given name and types. If a selector + with this name and types already exists, it is returned. Note that + this function should really be called 'objc_registerTypedSelector', + and it's called 'sel_registerTypedName' only for consistency with + 'sel_registerName'. Return NULL if 'name' is NULL. + + Compatibility Note: the Apple/NeXT runtime has untyped selectors, + so it does not have this function, which is specific to the GNU + Runtime. */ +objc_EXPORT SEL sel_registerTypedName (const char *name, const char *type); + +/* Return YES if first_selector is the same as second_selector, and NO + if not. */ +objc_EXPORT BOOL sel_isEqual (SEL first_selector, SEL second_selector); + +/* Return all the selectors with the supplied name. In the GNU + runtime, selectors are typed and there may be multiple selectors + with the same name but a different type. The return value of the + function is a pointer to an area, allocated with malloc(), that + contains all the selectors with the supplier name known to the + runtime. The list is terminated by NULL. Optionally, if you pass + a non-NULL 'numberOfReturnedSelectors' pointer, the unsigned int + that it points to will be filled with the number of selectors + returned. + + Compatibility Note: the Apple/NeXT runtime has untyped selectors, + so it does not have this function, which is specific to the GNU + Runtime. */ +objc_EXPORT SEL * sel_copyTypedSelectorList (const char *name, + unsigned int *numberOfReturnedSelectors); + +/* Return a selector with name 'name' and a non-zero type encoding, if + there is a single selector with a type, and with that name, + registered with the runtime. If there is no such selector, or if + there are multiple selectors with the same name but conflicting + types, NULL is returned. Return NULL if 'name' is NULL. + + This is useful if you have the name of the selector, and would + really like to get a selector for it that includes the type + encoding. Unfortunately, if the program contains multiple selector + with the same name but different types, sel_getTypedSelector can + not possibly know which one you need, and so will return NULL. + + Compatibility Note: the Apple/NeXT runtime has untyped selectors, + so it does not have this function, which is specific to the GNU + Runtime. */ +objc_EXPORT SEL sel_getTypedSelector (const char *name); + + +/** Implementation: the following functions are in objects.c. */ + +/* Create an instance of class 'class_', adding extraBytes to the size + of the returned object. This method allocates the appropriate + amount of memory for the instance, initializes it to zero, then + calls all the C++ constructors on appropriate C++ instance + variables of the instance (if any) (TODO: The C++ constructors bit + is not implemented yet). */ +objc_EXPORT id class_createInstance (Class class_, size_t extraBytes); + +/* Copy an object and return the copy. extraBytes should be identical + to the extraBytes parameter that was passed when creating the + original object. */ +objc_EXPORT id object_copy (id object, size_t extraBytes); + +/* Dispose of an object. This method calls the appropriate C++ + destructors on appropriate C++ instance variables of the instance + (if any) (TODO: This is not implemented yet), then frees the memory + for the instance. */ +objc_EXPORT id object_dispose (id object); + +/* Return the name of the class of 'object'. If 'object' is 'nil', + returns "Nil". */ +objc_EXPORT const char * object_getClassName (id object); + +/* Change the class of object to be class_. Return the previous class + of object. This is currently not really thread-safe. */ +objc_EXPORT Class object_setClass (id object, Class class_); + + +/** Implementation: the following functions are in ivars.c. */ + +/* Return an instance variable given the class and the instance + variable name. This is an expensive function to call, so try to + reuse the returned Ivar if you can. */ +objc_EXPORT Ivar class_getInstanceVariable (Class class_, const char *name); + +/* Return a class variable given the class and the class variable + name. This is an expensive function to call, so try to reuse the + returned Ivar if you can. + + This function always returns NULL since class variables are + currently unavailable in Objective-C. */ +objc_EXPORT Ivar class_getClassVariable (Class class_, const char *name); + +/* If the object was created in class_createInstance() with some + extraBytes, returns a pointer to them. If it was not, then the + returned pointer may make no sense. */ +objc_EXPORT void * object_getIndexedIvars (id object); + +/* Get the value of an instance variable of type 'id'. The function + returns the instance variable. To get the value of the instance + variable, you should pass as 'returnValue' a pointer to an 'id'; + the value will be copied there. Note that 'returnValue' is really + a 'void *', not a 'void **'. This function really works only with + instance variables of type 'id'; for other types of instance + variables, access directly the data at (char *)object + + ivar_getOffset (ivar). */ +objc_EXPORT Ivar object_getInstanceVariable (id object, const char *name, void **returnValue); + +/* Set the value of an instance variable. The value to set is passed + in 'newValue' (which really is an 'id', not a 'void *'). The + function returns the instance variable. This function really works + only with instance variables of type 'id'; for other types of + instance variables, access directly the data at (char *)object + + ivar_getOffset (ivar). */ +objc_EXPORT Ivar object_setInstanceVariable (id object, const char *name, void *newValue); + +/* Get the value of an instance variable of type 'id' of the object + 'object'. This is faster than object_getInstanceVariable if you + already have the instance variable because it avoids the expensive + call to class_getInstanceVariable that is done by + object_getInstanceVariable. */ +objc_EXPORT id object_getIvar (id object, Ivar variable); + +/* Set the value of an instance variable of type 'id' of the object + 'object'. This is faster than object_setInstanceVariable if you + already have the instance variable because it avoids the expensive + call to class_getInstanceVariable that is done by + object_setInstanceVariable. */ +objc_EXPORT void object_setIvar (id object, Ivar variable, id value); + +/* Return the name of the instance variable. Return NULL if + 'variable' is NULL. */ +objc_EXPORT const char * ivar_getName (Ivar variable); + +/* Return the offset of the instance variable from the start of the + object data. Return 0 if 'variable' is NULL. */ +objc_EXPORT ptrdiff_t ivar_getOffset (Ivar variable); + +/* Return the type encoding of the variable. Return NULL if + 'variable' is NULL. */ +objc_EXPORT const char * ivar_getTypeEncoding (Ivar variable); + +/* Return all the instance variables of the class. The return value + of the function is a pointer to an area, allocated with malloc(), + that contains all the instance variables of the class. It does not + include instance variables 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 instance variables returned. + Return NULL for classes still in construction (ie, allocated using + objc_allocatedClassPair() but not yet registered with the runtime + using objc_registerClassPair()). */ +objc_EXPORT Ivar * class_copyIvarList (Class class_, unsigned int *numberOfReturnedIvars); + +/* Add an instance variable with name 'ivar_name' to class 'class_', + where 'class_' is a class in construction that has been created + using objc_allocateClassPair() and has not been registered with the + runtime using objc_registerClassPair() yet. You can not add + instance variables to classes already registered with the runtime. + 'size' is the size of the instance variable, 'log_2_of_alignment' + the alignment as a power of 2 (so 0 means alignment to a 1 byte + boundary, 1 means alignment to a 2 byte boundary, 2 means alignment + to a 4 byte boundary, etc), and 'type' the type encoding of the + variable type. You can use sizeof(), log2(__alignof__()) and + @encode() to determine the right 'size', 'alignment' and 'type' for + your instance variable. For example, to add an instance variable + name "my_variable" and of type 'id', you can use: + + class_addIvar (class, "my_variable", sizeof (id), log2 ( __alignof__ (id)), + @encode (id)); + + Return YES if the variable was added, and NO if not. In + particular, return NO if 'class_' is Nil, or a meta-class or a + class not in construction. Return Nil also if 'ivar_name' or + 'type' is NULL, or 'size' is 0. + */ +objc_EXPORT BOOL class_addIvar (Class class_, const char * ivar_name, size_t size, + unsigned char log_2_of_alignment, const char *type); + +/* 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); + +/* Return the ivar layout for class 'class_'. + + At the moment this function always returns NULL. */ +objc_EXPORT const char * class_getIvarLayout (Class class_); + +/* Return the weak ivar layout for class 'class_'. + + At the moment this function always returns NULL. */ +objc_EXPORT const char * class_getWeakIvarLayout (Class class_); + +/* Set the ivar layout for class 'class_'. + + At the moment, this function does nothing. */ +objc_EXPORT void class_setIvarLayout (Class class_, const char *layout); + +/* Set the weak ivar layout for class 'class_'. + + At the moment, this function does nothing. With the GNU runtime, + you should use class_ivar_set_gcinvisible () to hide variables from + the Garbage Collector. */ +objc_EXPORT void class_setWeakIvarLayout (Class class_, const char *layout); + + +/** Implementation: the following functions are in class.c. */ + +/* Compatibility Note: The Apple/NeXT runtime does not have + objc_get_unknown_class_handler and + objc_setGetUnknownClassHandler(). They provide functionality that + the traditional GNU Objective-C Runtime API used to provide via the + _objc_lookup_class hook. */ + +/* An 'objc_get_unknown_class_handler' function is used by + objc_getClass() to get a class that is currently unknown to the + compiler. You could use it for example to have the class loaded by + dynamically loading a library. 'class_name' is the name of the + class. The function should return the Class object if it manages to + load the class, and Nil if not. */ +typedef Class (*objc_get_unknown_class_handler)(const char *class_name); + +/* Sets a new handler function for getting unknown classes (to be used + by objc_getClass () and related), and returns the previous one. + This function is not safe to call in a multi-threaded environment + because other threads may be trying to use the get unknown class + handler while you change it! */ +objc_EXPORT +objc_get_unknown_class_handler +objc_setGetUnknownClassHandler (objc_get_unknown_class_handler new_handler); + +/* Return the class with name 'name', if it is already registered with + the runtime. If it is not registered, and + objc_setGetUnknownClassHandler() has been called to set a handler + for unknown classes, the handler is called to give it a chance to + load the class in some other way. If the class is not known to the + runtime and the handler is not set or returns Nil, objc_getClass() + returns Nil. */ +objc_EXPORT Class objc_getClass (const char *name); + +/* Return the class with name 'name', if it is already registered with + the runtime. Return Nil if not. This function does not call the + objc_get_unknown_class_handler function if the class is not + found. */ +objc_EXPORT Class objc_lookUpClass (const char *name); + +/* Return the meta class associated to the class with name 'name', if + it is already registered with the runtime. First, it finds the + class using objc_getClass(). Then, it returns the associated meta + class. If the class could not be found using objc_getClass(), + returns Nil. */ +objc_EXPORT Class objc_getMetaClass (const char *name); + +/* This is identical to objc_getClass(), but if the class is not found, + it aborts the process instead of returning Nil. */ +objc_EXPORT Class objc_getRequiredClass (const char *name); + +/* If 'returnValue' is NULL, 'objc_getClassList' returns the number of + classes currently registered with the runtime. If 'returnValue' is + not NULL, it should be a (Class *) pointer to an area of memory + which can contain up to 'maxNumberOfClassesToReturn' Class records. + 'objc_getClassList' will fill the area pointed to by 'returnValue' + with all the Classes registered with the runtime (or up to + maxNumberOfClassesToReturn if there are more than + maxNumberOfClassesToReturn). The function return value is the + number of classes actually returned in 'returnValue'. */ +objc_EXPORT int objc_getClassList (Class *returnValue, int maxNumberOfClassesToReturn); + +/* Compatibility Note: The Apple/NeXT runtime also has + + Class objc_getFutureClass (const char *name); + void objc_setFutureClass (Class class_, const char *name); + + the documentation is unclear on what they are supposed to do, and + the GNU Objective-C Runtime currently does not provide them. */ + +/* Return the name of the class 'class_', or the string "nil" if the + class_ is Nil. */ +objc_EXPORT const char * class_getName (Class class_); + +/* Return YES if 'class_' is a meta class, and NO if not. If 'class_' + is Nil, return NO. */ +objc_EXPORT BOOL class_isMetaClass (Class class_); + +/* Return the superclass of 'class_'. If 'class_' is Nil, or it is a + root class, return Nil. If 'class_' is a class being constructed, + that is, a class returned by objc_allocateClassPair() but before it + has been registered with the runtime using + objc_registerClassPair(), return Nil. */ +objc_EXPORT Class class_getSuperclass (Class class_); + +/* Return the 'version' number of the class, which is an integer that + can be used to track changes in the class API, methods and + variables. If class_ is Nil, return 0. If class_ is not Nil, the + version is 0 unless class_setVersion() has been called to set a + different one. + + Please note that internally the version is a long, but the API only + allows you to set and retrieve int values. */ +objc_EXPORT int class_getVersion (Class class_); + +/* Set the 'version' number of the class, which is an integer that can + be used to track changes in the class API, methods and variables. + If 'class_' is Nil, does nothing. + + This is typically used internally by "Foundation" libraries such as + GNUstep Base to support serialization / deserialization of objects + that work across changes in the classes. If you are using such a + library, you probably want to use their versioning API, which may + be based on this one, but is integrated with the rest of the + library. + + Please note that internally the version is a long, but the API only + allows you to set and retrieve int values. */ +objc_EXPORT void class_setVersion (Class class_, int version); + +/* Return the size in bytes (a byte is the size of a char) of an + instance of the class. If class_ is Nil, return 0; else it return + a non-zero number (since the 'isa' instance variable is required + 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); + +/* Create a new class/meta-class pair. This function is called to + create a new class at runtime. The class is created with + superclass 'superclass' (use 'Nil' to create a new root class) and + name 'class_name'. 'extraBytes' can be used to specify some extra + space for indexed variables to be added at the end of the class and + meta-class objects (it is recommended that you set extraBytes to + 0). Once you have created the class, it is not usable yet. You + need to add any instance variables (by using class_addIvar()), any + instance methods (by using class_addMethod()) and any class methods + (by using class_addMethod() on the meta-class, as in + class_addMethod (object_getClass (class), method)) that are + required, and then you need to call objc_registerClassPair() to + activate the class. If you need to create a hierarchy of classes, + you need to create and register them one at a time. You can not + create a new class using another class in construction as + superclass. Return Nil if 'class-name' is NULL or if a class with + that name already exists or 'superclass' is a class still in + construction. + + Implementation Note: in the GNU runtime, allocating a class pair + only creates the structures for the class pair, but does not + register anything with the runtime. The class is registered with + the runtime only when objc_registerClassPair() is called. In + particular, if a class is in construction, objc_getClass() will not + find it, the superclass will not know about it, + class_getSuperclass() will return Nil and another thread may + allocate a class pair with the same name; the conflict will only be + detected when the classes are registered with the runtime. + */ +objc_EXPORT Class +objc_allocateClassPair (Class super_class, const char *class_name, + size_t extraBytes); + +/* Register a class pair that was created with + objc_allocateClassPair(). After you register a class, you can no + longer make changes to its instance variables, but you can start + creating instances of it. Do nothing if 'class_' is NULL or if it + is not a class allocated by objc_allocateClassPair() and still in + construction. */ +objc_EXPORT void +objc_registerClassPair (Class class_); + +/* Dispose of a class pair created using objc_allocateClassPair(). + Call this function if you started creating a new class with + objc_allocateClassPair() but then want to abort the process. You + should not access 'class_' after calling this method. Note that if + 'class_' has already been registered with the runtime via + objc_registerClassPair(), this function does nothing; you can only + dispose of class pairs that are still being constructed. Do + nothing if class is 'Nil' or if 'class_' is not a class being + constructed. */ +objc_EXPORT void +objc_disposeClassPair (Class class_); + +/* Compatibility Note: The Apple/NeXT runtime has the function + objc_duplicateClass () but it's undocumented. The GNU runtime does + not have it. */ + + +/** Implementation: the following functions are in sendmsg.c. */ + +/* Return the instance method with selector 'selector' of class + 'class_', or NULL if the class (or one of its superclasses) does + not implement the method. Return NULL if class_ is Nil or selector + is NULL. Calling this function may trigger a call to + +resolveInstanceMethod:, but does not return a forwarding + function. */ +objc_EXPORT Method class_getInstanceMethod (Class class_, SEL selector); + +/* Return the class method with selector 'selector' of class 'class_', + or NULL if the class (or one of its superclasses) does not + implement the method. Return NULL if class_ is Nil or selector is + NULL. Calling this function may trigger a call to + +resolveClassMethod:, but does not return a forwarding + function. */ +objc_EXPORT Method class_getClassMethod (Class class_, SEL selector); + +/* Return the IMP (pointer to the function implementing a method) for + the instance method with selector 'selector' in class 'class_'. + This is the same routine that is used while messaging, and should + be very fast. Note that you most likely would need to cast the + return function pointer to a function pointer with the appropriate + arguments and return type before calling it. To get a class + method, you can pass the meta-class as the class_ argument (ie, use + class_getMethodImplementation (object_getClass (class_), + selector)). Return NULL if class_ is Nil or selector is NULL. + This function first looks for an existing method; if it is not + found, it calls +resolveClassMethod: or +resolveInstanceMethod: + (depending on whether a class or instance method is being looked + up) if it is implemented. If the method returns YES, then it tries + the look up again (the assumption being that +resolveClassMethod: + or resolveInstanceMethod: will add the method using + class_addMethod()). If it is still not found, it returns a + forwarding function. */ +objc_EXPORT IMP class_getMethodImplementation (Class class_, SEL selector); + +/* Compatibility Note: the Apple/NeXT runtime has the function + class_getMethodImplementation_stret () which currently does not + exist on the GNU runtime because the messaging implementation is + different. */ + +/* Return YES if class 'class_' has an instance method implementing + selector 'selector', and NO if not. Return NO if class_ is Nil or + selector is NULL. If you need to check a class method, use the + meta-class as the class_ argument (ie, use class_respondsToSelector + (object_getClass (class_), selector)). */ +objc_EXPORT BOOL class_respondsToSelector (Class class_, SEL selector); + +/* Add a method to a class. Use this function to add a new method to + a class (potentially overriding a method with the same selector in + the superclass); if you want to modify an existing method, use + method_setImplementation() instead (or class_replaceMethod ()). + This method adds an instance method to 'class_'; to add a class + method, get the meta class first, then add the method to the meta + class, that is, use + + class_addMethod (object_getClass (class_), selector, + implementation, type); + + Return YES if the method was added, and NO if not. Do nothing if + one of the arguments is NULL. */ +objc_EXPORT BOOL class_addMethod (Class class_, SEL selector, IMP implementation, + const char *method_types); + +/* Replace a method in a class. If the class already have a method + with this 'selector', find it and use method_setImplementation() to + replace the implementation with 'implementation' (method_types is + ignored in that case). If the class does not already have a method + with this 'selector', call 'class_addMethod() to add it. + + Return the previous implementation of the method, or NULL if none + was found. Return NULL if any of the arguments is NULL. */ +objc_EXPORT IMP class_replaceMethod (Class class_, SEL selector, IMP implementation, + const char *method_types); + + +/** Implementation: the following functions are in methods.c. */ + +/* Return the selector for method 'method'. Return NULL if 'method' + is NULL. + + This function is misnamed; it should be called + 'method_getSelector'. To get the actual name, get the selector, + then the name from the selector (ie, use sel_getName + (method_getName (method))). */ +objc_EXPORT SEL method_getName (Method method); + +/* Return the IMP of the method. Return NULL if 'method' is NULL. */ +objc_EXPORT IMP method_getImplementation (Method method); + +/* Return the type encoding of the method. Return NULL if 'method' is + NULL. */ +objc_EXPORT const char * method_getTypeEncoding (Method method); + +/* Return a method description for the method. Return NULL if + 'method' is NULL. */ +objc_EXPORT struct objc_method_description * method_getDescription (Method method); + +/* Return all the instance methods of the class. The return value of + the function is a pointer to an area, allocated with malloc(), that + contains all the instance methods of the class. It does not + include instance methods of superclasses. The list is terminated + by NULL. Optionally, if you pass a non-NULL + 'numberOfReturnedMethods' pointer, the unsigned int that it points + to will be filled with the number of instance methods returned. To + get the list of class methods, pass the meta-class in the 'class_' + argument, (ie, use class_copyMethodList (object_getClass (class_), + &numberOfReturnedMethods)). */ +objc_EXPORT Method * class_copyMethodList (Class class_, unsigned int *numberOfReturnedMethods); + + +/** Implementation: the following functions are in encoding.c. */ + +/* Return the number of arguments that the method 'method' expects. + Note that all methods need two implicit arguments ('self' for the + receiver, and '_cmd' for the selector). Return 0 if 'method' is + NULL. */ +objc_EXPORT unsigned int method_getNumberOfArguments (Method method); + +/* Return the string encoding for the return type of method 'method'. + The string is a standard zero-terminated string in an area of + memory allocated with malloc(); you should free it with free() when + you finish using it. Return an empty string if method is NULL. */ +objc_EXPORT char * method_copyReturnType (Method method); + +/* Return the string encoding for the argument type of method + 'method', argument number 'argumentNumber' ('argumentNumber' is 0 + for self, 1 for _cmd, and 2 or more for the additional arguments if + any). The string is a standard zero-terminated string in an area + of memory allocated with malloc(); you should free it with free() + when you finish using it. Return an empty string if method is NULL + or if 'argumentNumber' refers to a non-existing argument. */ +objc_EXPORT char * method_copyArgumentType (Method method, unsigned int argumentNumber); + +/* Return the string encoding for the return type of method 'method'. + The string is returned by copying it into the supplied + 'returnValue' string, which is of size 'returnValueSize'. No more + than 'returnValueSize' characters are copied; if the encoding is + smaller than 'returnValueSize', the rest of 'returnValue' is filled + with zeros. If it is bigger, it is truncated (and would not be + zero-terminated). You should supply a big enough + 'returnValueSize'. If the method is NULL, returnValue is set to a + string of zeros. */ +objc_EXPORT void method_getReturnType (Method method, char *returnValue, + size_t returnValueSize); + +/* Return the string encoding for the argument type of method + 'method', argument number 'argumentNumber' ('argumentNumber' is 0 + for self, 1 for _cmd, and 2 or more for the additional arguments if + any). The string is returned by copying it into the supplied + 'returnValue' string, which is of size 'returnValueSize'. No more + than 'returnValueSize' characters are copied; if the encoding is + smaller than 'returnValueSize', the rest of 'returnValue' is filled + with zeros. If it is bigger, it is truncated (and would not be + zero-terminated). You should supply a big enough + 'returnValueSize'. If the method is NULL, returnValue is set to a + string of zeros. */ +objc_EXPORT void method_getArgumentType (Method method, unsigned int argumentNumber, + char *returnValue, size_t returnValueSize); + + +/** Implementation: the following functions are in protocols.c. */ + +/* Return the protocol with name 'name', or nil if it the protocol is + not known to the runtime. */ +objc_EXPORT Protocol *objc_getProtocol (const char *name); + +/* Return all the protocols known to the runtime. The return value of + the function is a pointer to an area, allocated with malloc(), that + contains all the protocols known to the runtime; the list is + terminated by NULL. You should free this area using free() once + you no longer need it. Optionally, if you pass a non-NULL + 'numberOfReturnedProtocols' pointer, the unsigned int that it + points to will be filled with the number of protocols returned. If + there are no protocols known to the runtime, NULL is returned. */ +objc_EXPORT Protocol **objc_copyProtocolList (unsigned int *numberOfReturnedProtocols); + +/* Add a protocol to a class, and return YES if it was done + succesfully, and NO if not. At the moment, NO should only happen + if class_ or protocol are nil, if the protocol is not a Protocol + object or if the class already conforms to the protocol. */ +objc_EXPORT BOOL class_addProtocol (Class class_, Protocol *protocol); + +/* Return YES if the class 'class_' conforms to Protocol 'protocol', + and NO if not. This function does not check superclasses; if you + want to check for superclasses (in the way that [NSObject + +conformsToProtocol:] does) you need to iterate over the class + hierarchy using class_getSuperclass(), and call + class_conformsToProtocol() for each of them. */ +objc_EXPORT BOOL class_conformsToProtocol (Class class_, Protocol *protocol); + +/* Return all the protocols that the class conforms to. The return + value of the function is a pointer to an area, allocated with + malloc(), that contains all the protocols formally adopted by the + class. It does not include protocols adopted by superclasses. The + list is terminated by NULL. Optionally, if you pass a non-NULL + 'numberOfReturnedProtocols' pointer, the unsigned int that it + points to will be filled with the number of protocols returned. + This function does not return protocols that superclasses conform + to. */ +objc_EXPORT Protocol **class_copyProtocolList (Class class_, unsigned int *numberOfReturnedProtocols); + +/* Return YES if protocol 'protocol' conforms to protocol + 'anotherProtocol', and NO if not. Note that if one of the two + protocols is nil, it returns NO. */ +objc_EXPORT BOOL protocol_conformsToProtocol (Protocol *protocol, Protocol *anotherProtocol); + +/* Return YES if protocol 'protocol' is the same as protocol + 'anotherProtocol', and 'NO' if not. Note that it returns YES if + the two protocols are both nil. */ +objc_EXPORT BOOL protocol_isEqual (Protocol *protocol, Protocol *anotherProtocol); + +/* Return the name of protocol 'protocol'. If 'protocol' is nil or is + not a Protocol, return NULL. */ +objc_EXPORT const char *protocol_getName (Protocol *protocol); + +/* Return the method description for the method with selector + 'selector' in protocol 'protocol'; if 'requiredMethod' is YES, the + function searches the list of required methods; if NO, the list of + optional methods. If 'instanceMethod' is YES, the function search + for an instance method; if NO, for a class method. If there is no + matching method, an objc_method_description structure with both + name and types set to NULL is returned. This function will only + find methods that are directly declared in the protocol itself, not + in other protocols that this protocol adopts. + + Note that the traditional ABI does not store the list of optional + methods of a protocol in a compiled module, so the traditional ABI + will always return (NULL, NULL) when requiredMethod == NO. */ +objc_EXPORT struct objc_method_description protocol_getMethodDescription (Protocol *protocol, + SEL selector, + BOOL requiredMethod, + BOOL instanceMethod); + +/* Return the method descriptions of all the methods of the protocol. + The return value of the function is a pointer to an area, allocated + with malloc(), that contains all the method descriptions of the + methods of the protocol. It does not recursively include methods + of the protocols adopted by this protocol. The list is terminated + by a NULL objc_method_description (one with both fields set to + NULL). Optionally, if you pass a non-NULL + 'numberOfReturnedMethods' 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 optional + methods of a protocol in a compiled module, so the traditional ABI + will always return an empty list if requiredMethod is set to + NO. */ +objc_EXPORT struct objc_method_description *protocol_copyMethodDescriptionList (Protocol *protocol, + BOOL requiredMethod, + BOOL instanceMethod, + unsigned int *numberOfReturnedMethods); + +/* Return the property with name 'propertyName' of the protocol + 'protocol'. If 'requiredProperty' is YES, the function searches + the list of required properties; if NO, the list of optional + properties. If 'instanceProperty' is YES, the function searches + the list of instance properties; if NO, the list of class + properties. At the moment, optional properties and class + properties are not part of the Objective-C language, so both + 'requiredProperty' and 'instanceProperty' should be set to YES. + This function returns NULL if the required property can not be + found. + + Note that the traditional ABI does not store the list of properties + of a protocol in a compiled module, so the traditional ABI will + always return NULL. */ +objc_EXPORT Property protocol_getProperty (Protocol *protocol, const char *propertyName, + BOOL requiredProperty, BOOL instanceProperty); + +/* Return all the properties of the protocol. The return value of the + function is a pointer to an area, allocated with malloc(), that + contains all the properties of the protocol. It does not + recursively include properties of the protocols adopted by this + protocol. The list is terminated by NULL. Optionally, if you pass + a non-NULL 'numberOfReturnedProperties' 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 protocol in a compiled module, so the traditional ABI will + always return NULL and store 0 in numberOfReturnedProperties. */ +objc_EXPORT Property *protocol_copyPropertyList (Protocol *protocol, unsigned int *numberOfReturnedProperties); + +/* Return all the protocols that the protocol conforms to. The return + value of the function is a pointer to an area, allocated with + malloc(), that contains all the protocols formally adopted by the + protocol. It does not recursively include protocols adopted by the + protocols adopted by this protocol. The list is terminated by + NULL. Optionally, if you pass a non-NULL + 'numberOfReturnedProtocols' pointer, the unsigned int that it + points to will be filled with the number of protocols returned. */ +objc_EXPORT Protocol **protocol_copyProtocolList (Protocol *protocol, unsigned int *numberOfReturnedProtocols); + + +/** Implementation: the following hook is in init.c. */ + +/* This is a hook which is called by __objc_exec_class every time a + class or a category is loaded into the runtime. This may e.g. help + a dynamic loader determine the classes that have been loaded when + an object file is dynamically linked in. */ +objc_EXPORT void (*_objc_load_callback)(Class _class, struct objc_category *category); + + +/** Implementation: the following functions are in objc-foreach.c. */ + +/* 'objc_enumerationMutation()' is called when a collection is + mutated while being "fast enumerated". That is a hard error, and + objc_enumerationMutation is called to deal with it. 'collection' + is the collection object that was mutated during an enumeration. + + objc_enumerationMutation() will invoke the mutation handler if any + is set. Then, it will abort the program. + + Compatibility note: the Apple runtime will not abort the program + after calling the mutation handler. */ +objc_EXPORT void objc_enumerationMutation (id collection); + +/* 'objc_set_enumeration_mutation_handler' can be used to set a + function that will be called (instead of aborting) when a fast + enumeration is mutated during enumeration. The handler will be + called with the 'collection' being mutated as the only argument and + it should not return; it should either exit the program, or could + throw an exception. The recommended implementation is to throw an + exception - the user can then use exception handlers to deal with + it. + + This function is not thread safe (other threads may be trying to + invoke the enumeration mutation handler while you are changing it!) + and should be called during during the program initialization + before threads are started. It is mostly reserved for "Foundation" + libraries; in the case of GNUstep, GNUstep Base may be using this + function to improve the standard enumeration mutation handling. + You probably shouldn't use this function unless you are writing + your own Foundation library. */ +objc_EXPORT void objc_setEnumerationMutationHandler (void (*handler)(id)); + +/* This structure (used during fast enumeration) is automatically + defined by the compiler (it is as if this definition was always + included in all Objective-C files). Note that it is usually + defined again with the name of NSFastEnumeration by "Foundation" + libraries such as GNUstep Base. And if NSFastEnumeration is + defined, the compiler will use it instead of + __objcFastEnumerationState when doing fast enumeration. */ +/* +struct __objcFastEnumerationState +{ + unsigned long state; + id *itemsPtr; + unsigned long *mutationsPtr; + unsigned long extra[5]; +}; +*/ + + +/* Compatibility Note: The Apple/NeXT runtime has the functions + objc_copyImageNames (), class_getImageName () and + objc_copyClassNamesForImage () but they are undocumented. The GNU + runtime does not have them at the moment. */ + +/* Compatibility Note: The Apple/NeXT runtime has the functions + objc_setAssociatedObject (), objc_getAssociatedObject (), + objc_removeAssociatedObjects () and the objc_AssociationPolicy type + and related enum. The GNU runtime does not have them yet. + TODO: Implement them. */ + +/* Compatibility Note: The Apple/NeXT runtime has the function + objc_setForwardHandler (). The GNU runtime does not have it + because messaging (and, in particular, forwarding) works in a + different (incompatible) way with the GNU runtime. If you need to + customize message forwarding at the Objective-C runtime level (that + is, if you are implementing your own "Foundation" library such as + GNUstep Base on top of the Objective-C runtime), in objc/message.h + there are hooks (that work in the framework of the GNU runtime) to + do so. */ + + +/** Implementation: the following functions are in memory.c. */ + +/* Traditional GNU Objective-C Runtime functions that are used for + memory allocation and disposal. These functions are used in the + same way as you use malloc, realloc, calloc and free and make sure + that memory allocation works properly with the garbage + collector. + + Compatibility Note: these functions are not available with the + Apple/NeXT runtime. */ + +objc_EXPORT void *objc_malloc(size_t size); + +/* FIXME: Shouldn't the following be called objc_malloc_atomic ? The + GC function is GC_malloc_atomic() which makes sense. + */ +objc_EXPORT void *objc_atomic_malloc(size_t size); + +objc_EXPORT void *objc_realloc(void *mem, size_t size); + +objc_EXPORT void *objc_calloc(size_t nelem, size_t size); + +objc_EXPORT void objc_free(void *mem); + + +/** Implementation: the following functions are in gc.c. */ + +/* The GNU Objective-C Runtime has a different implementation of + garbage collection. + + Compatibility Note: these functions are not available with the + Apple/NeXT runtime. */ + +/* Mark the instance variable as inaccessible to the garbage + collector. */ +objc_EXPORT void class_ivar_set_gcinvisible (Class _class, + const char* ivarname, + BOOL gcInvisible); + + +/** Implementation: the following functions are in encoding.c. */ + +/* Traditional GNU Objective-C Runtime functions that are currently + used to implement method forwarding. + + Compatibility Note: these functions are not available with the + Apple/NeXT runtime. */ + +/* Return the size of a variable which has the specified 'type' + encoding. */ +objc_EXPORT int objc_sizeof_type (const char *type); + +/* Return the align of a variable which has the specified 'type' + encoding. */ +objc_EXPORT int objc_alignof_type (const char *type); + +/* Return the aligned size of a variable which has the specified + 'type' encoding. The aligned size is the size rounded up to the + nearest alignment. */ +objc_EXPORT int objc_aligned_size (const char *type); + +/* Return the promoted size of a variable which has the specified + 'type' encoding. This is the size rounded up to the nearest + integral of the wordsize, taken to be the size of a void *. */ +objc_EXPORT int objc_promoted_size (const char *type); + + +/* The following functions are used when parsing the type encoding of + methods, to skip over parts that are ignored. They take as + argument a pointer to a location inside the type encoding of a + method (which is a string) and return a new pointer, pointing to a + new location inside the string after having skipped the unwanted + information. */ + +/* Skip some type qualifiers (_C_CONST, _C_IN, etc). These may + eventually precede typespecs occurring in method prototype + encodings. */ +objc_EXPORT const char *objc_skip_type_qualifiers (const char *type); + +/* Skip one typespec element (_C_CLASS, _C_SEL, etc). If the typespec + is prepended by type qualifiers, these are skipped as well. */ +objc_EXPORT const char *objc_skip_typespec (const char *type); + +/* Skip an offset. */ +objc_EXPORT const char *objc_skip_offset (const char *type); + +/* Skip an argument specification (ie, skipping a typespec, which may + include qualifiers, and an offset too). */ +objc_EXPORT const char *objc_skip_argspec (const char *type); + +/* Read type qualifiers (_C_CONST, _C_IN, etc) from string 'type' + (stopping at the first non-type qualifier found) and return an + unsigned int which is the logical OR of all the corresponding flags + (_F_CONST, _F_IN etc). */ +objc_EXPORT unsigned objc_get_type_qualifiers (const char *type); + + +/* Note that the following functions work for very simple structures, + but get easily confused by more complicated ones (for example, + containing vectors). A better solution is required. These + functions are likely to change in the next GCC release. */ + +/* The following three functions can be used to determine how a + structure is laid out by the compiler. For example: + + struct objc_struct_layout layout; + int i; + + objc_layout_structure (type, &layout); + while (objc_layout_structure_next_member (&layout)) + { + int position, align; + const char *type; + + objc_layout_structure_get_info (&layout, &position, &align, &type); + printf ("element %d has offset %d, alignment %d\n", + i++, position, align); + } + + These functions are used by objc_sizeof_type and objc_alignof_type + functions to compute the size and alignment of structures. The + previous method of computing the size and alignment of a structure + was not working on some architectures, particulary on AIX, and in + the presence of bitfields inside the structure. */ +struct objc_struct_layout +{ + const char *original_type; + const char *type; + const char *prev_type; + unsigned int record_size; + unsigned int record_align; +}; + +objc_EXPORT void objc_layout_structure (const char *type, + struct objc_struct_layout *layout); +objc_EXPORT BOOL objc_layout_structure_next_member (struct objc_struct_layout *layout); +objc_EXPORT void objc_layout_finish_structure (struct objc_struct_layout *layout, + unsigned int *size, + unsigned int *align); +objc_EXPORT void objc_layout_structure_get_info (struct objc_struct_layout *layout, + unsigned int *offset, + unsigned int *align, + const char **type); + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + +#endif diff --git a/libobjc/objc/sarray.h b/libobjc/objc/sarray.h new file mode 100644 index 000000000..ff51e47f9 --- /dev/null +++ b/libobjc/objc/sarray.h @@ -0,0 +1,2 @@ +#include "deprecated/sarray.h" + diff --git a/libobjc/objc/thr.h b/libobjc/objc/thr.h new file mode 100644 index 000000000..d5ddf9b2f --- /dev/null +++ b/libobjc/objc/thr.h @@ -0,0 +1,117 @@ +/* Thread and mutex controls for Objective C. + Copyright (C) 1996, 1997, 2002, 2004, 2009, 2010 + Free Software Foundation, Inc. + Contributed by Galen C. Hunt (gchunt@cs.rochester.edu) + +This file is part of GCC. + +GCC is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 3, or (at your option) +any later version. + +GCC is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +Under Section 7 of GPL version 3, you are granted additional +permissions described in the GCC Runtime Library Exception, version +3.1, as published by the Free Software Foundation. + +You should have received a copy of the GNU General Public License and +a copy of the GCC Runtime Library Exception along with this program; +see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +<http://www.gnu.org/licenses/>. */ + +#ifndef __thread_INCLUDE_GNU +#define __thread_INCLUDE_GNU + +#include "objc.h" + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + +/************************************************************************* + * Universal static variables: + */ +extern int __objc_thread_exit_status; /* Global exit status. */ + +/******** + * Thread safe implementation types and functions. + */ + +/* Thread priorities */ +#define OBJC_THREAD_INTERACTIVE_PRIORITY 2 +#define OBJC_THREAD_BACKGROUND_PRIORITY 1 +#define OBJC_THREAD_LOW_PRIORITY 0 + +/* A thread */ +typedef void * objc_thread_t; + +/* This structure represents a single mutual exclusion lock. */ +struct objc_mutex +{ + volatile objc_thread_t owner; /* Id of thread that owns. */ + volatile int depth; /* # of acquires. */ + void * backend; /* Specific to backend */ +}; +typedef struct objc_mutex *objc_mutex_t; + +/* This structure represents a single condition mutex */ +struct objc_condition +{ + void * backend; /* Specific to backend */ +}; +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); + +/* 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); + +/* 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); + +/* + Use this to set the hook function that will be called when the + runtime initially becomes multi threaded. + The hook function is only called once, meaning only when the + 2nd thread is spawned, not for each and every thread. + + It returns the previous hook function or NULL if there is none. + + A program outside of the runtime could set this to some function so + 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); + +/* Backend initialization functions */ +int __objc_init_thread_system (void); + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + +#endif /* not __thread_INCLUDE_GNU */ diff --git a/libobjc/objc/typedstream.h b/libobjc/objc/typedstream.h new file mode 100644 index 000000000..a39c51b29 --- /dev/null +++ b/libobjc/objc/typedstream.h @@ -0,0 +1,4 @@ +#include "objc.h" +#include "deprecated/hash.h" +#include "deprecated/typedstream.h" + |