#ifndef _OBJC_OBJC_H_
#define _OBJC_OBJC_H_
-#import <objc/objc-api.h> // for OBJC_EXPORT
-#import <sys/types.h>
-
+#include <sys/types.h> // for __DARWIN_NULL
+#include <Availability.h>
+#include <objc/objc-api.h>
+#include <stdbool.h>
+#if !OBJC_TYPES_DEFINED
+/// An opaque type that represents an Objective-C class.
typedef struct objc_class *Class;
-typedef struct objc_object {
- Class isa;
-} *id;
+/// Represents an instance of a class.
+struct objc_object {
+ Class isa OBJC_ISA_AVAILABILITY;
+};
+
+/// A pointer to an instance of a class.
+typedef struct objc_object *id;
+#endif
+
+/// An opaque type that represents a method selector.
+typedef struct objc_selector *SEL;
+
+/// A pointer to the function of a method implementation.
+#if !OBJC_OLD_DISPATCH_PROTOTYPES
+typedef void (*IMP)(void /* id, SEL, ... */ );
+#else
+typedef id (*IMP)(id, SEL, ...);
+#endif
-typedef struct objc_selector *SEL;
-typedef id (*IMP)(id, SEL, ...);
-typedef signed char BOOL;
-// BOOL is explicitly signed so @encode(BOOL) == "c" rather than "C"
-// even if -funsigned-char is used.
#define OBJC_BOOL_DEFINED
+/// Type to represent a boolean value.
+#if !defined(OBJC_HIDE_64) && TARGET_OS_IPHONE && __LP64__
+typedef bool BOOL;
+#else
+typedef signed char BOOL;
+// BOOL is explicitly signed so @encode(BOOL) == "c" rather than "C"
+// even if -funsigned-char is used.
+#endif
-#define YES (BOOL)1
-#define NO (BOOL)0
+#if __has_feature(objc_bool)
+#define YES __objc_yes
+#define NO __objc_no
+#else
+#define YES ((BOOL)1)
+#define NO ((BOOL)0)
+#endif
#ifndef Nil
-#define Nil __DARWIN_NULL /* id of Nil class */
+# if __has_feature(cxx_nullptr)
+# define Nil nullptr
+# else
+# define Nil __DARWIN_NULL
+# endif
#endif
#ifndef nil
-#define nil __DARWIN_NULL /* id of Nil instance */
+# if __has_feature(cxx_nullptr)
+# define nil nullptr
+# else
+# define nil __DARWIN_NULL
+# endif
#endif
-#ifndef __OBJC_GC__
+#if ! (defined(__OBJC_GC__) || __has_feature(objc_arc))
#define __strong /* empty */
#endif
-OBJC_EXPORT const char *sel_getName(SEL sel);
-OBJC_EXPORT SEL sel_registerName(const char *str);
-OBJC_EXPORT const char *object_getClassName(id obj);
-OBJC_EXPORT void *object_getIndexedIvars(id obj);
+#if !__has_feature(objc_arc)
+#define __unsafe_unretained /* empty */
+#define __autoreleasing /* empty */
+#endif
+
+
+/**
+ * Returns the name of the method specified by a given selector.
+ *
+ * @param sel A pointer of type \c SEL. Pass the selector whose name you wish to determine.
+ *
+ * @return A C string indicating the name of the selector.
+ */
+OBJC_EXPORT const char *sel_getName(SEL sel)
+ __OSX_AVAILABLE_STARTING(__MAC_10_0, __IPHONE_2_0);
+
+/**
+ * Registers a method with the Objective-C runtime system, maps the method
+ * name to a selector, and returns the selector value.
+ *
+ * @param str A pointer to a C string. Pass the name of the method you wish to register.
+ *
+ * @return A pointer of type SEL specifying the selector for the named method.
+ *
+ * @note You must register a method name with the Objective-C runtime system to obtain the
+ * method’s selector before you can add the method to a class definition. If the method name
+ * has already been registered, this function simply returns the selector.
+ */
+OBJC_EXPORT SEL sel_registerName(const char *str)
+ __OSX_AVAILABLE_STARTING(__MAC_10_0, __IPHONE_2_0);
+
+/**
+ * Returns the class name of a given object.
+ *
+ * @param obj An Objective-C object.
+ *
+ * @return The name of the class of which \e obj is an instance.
+ */
+OBJC_EXPORT const char *object_getClassName(id obj)
+ __OSX_AVAILABLE_STARTING(__MAC_10_0, __IPHONE_2_0);
+
+/**
+ * Returns a pointer to any extra bytes allocated with an instance given object.
+ *
+ * @param obj An Objective-C object.
+ *
+ * @return A pointer to any extra bytes allocated with \e obj. If \e obj was
+ * not allocated with any extra bytes, then dereferencing the returned pointer is undefined.
+ *
+ * @note This function returns a pointer to any extra bytes allocated with the instance
+ * (as specified by \c class_createInstance with extraBytes>0). This memory follows the
+ * object's ordinary ivars, but may not be adjacent to the last ivar.
+ * @note The returned pointer is guaranteed to be pointer-size aligned, even if the area following
+ * the object's last ivar is less aligned than that. Alignment greater than pointer-size is never
+ * guaranteed, even if the area following the object's last ivar is more aligned than that.
+ * @note In a garbage-collected environment, the memory is scanned conservatively.
+ */
+OBJC_EXPORT void *object_getIndexedIvars(id obj)
+ __OSX_AVAILABLE_STARTING(__MAC_10_0, __IPHONE_2_0);
+
+/**
+ * Identifies a selector as being valid or invalid.
+ *
+ * @param sel The selector you want to identify.
+ *
+ * @return YES if selector is valid and has a function implementation, NO otherwise.
+ *
+ * @warning On some platforms, an invalid reference (to invalid memory addresses) can cause
+ * a crash.
+ */
+OBJC_EXPORT BOOL sel_isMapped(SEL sel)
+ __OSX_AVAILABLE_STARTING(__MAC_10_0, __IPHONE_2_0);
+
+/**
+ * Registers a method name with the Objective-C runtime system.
+ *
+ * @param str A pointer to a C string. Pass the name of the method you wish to register.
+ *
+ * @return A pointer of type SEL specifying the selector for the named method.
+ *
+ * @note The implementation of this method is identical to the implementation of \c sel_registerName.
+ * @note Prior to OS X version 10.0, this method tried to find the selector mapped to the given name
+ * and returned \c NULL if the selector was not found. This was changed for safety, because it was
+ * observed that many of the callers of this function did not check the return value for \c NULL.
+ */
+OBJC_EXPORT SEL sel_getUid(const char *str)
+ __OSX_AVAILABLE_STARTING(__MAC_10_0, __IPHONE_2_0);
+
+
+// Obsolete ARC conversions. Deprecation forthcoming.
+// Use CFBridgingRetain, CFBridgingRelease, and __bridge casts instead.
+
+typedef const void* objc_objectptr_t;
+
+#if __has_feature(objc_arc)
+# define objc_retainedObject(o) ((__bridge_transfer id)(objc_objectptr_t)(o))
+# define objc_unretainedObject(o) ((__bridge id)(objc_objectptr_t)(o))
+# define objc_unretainedPointer(o) ((__bridge objc_objectptr_t)(id)(o))
+#else
+# define objc_retainedObject(o) ((id)(objc_objectptr_t)(o))
+# define objc_unretainedObject(o) ((id)(objc_objectptr_t)(o))
+# define objc_unretainedPointer(o) ((objc_objectptr_t)(id)(o))
+#endif
#if !__OBJC2__
# define ARITH_SHIFT 16
#endif
-OBJC_EXPORT BOOL sel_isMapped(SEL sel);
-OBJC_EXPORT SEL sel_getUid(const char *str);
-
typedef char *STR;
#define ISSELECTOR(sel) sel_isMapped(sel)