Index: src/OFArray.h ================================================================== --- src/OFArray.h +++ src/OFArray.h @@ -151,11 +151,11 @@ * \brief Copies the objects at the specified range to the specified buffer. * * \param buffer The buffer to copy the objects to * \param range The range to copy */ -- (void)getObjects: (id*)buffer +- (void)getObjects: (__unsafe_unretained id*)buffer inRange: (of_range_t)range; /** * \brief Returns the objects of the array as a C array. * Index: src/OFDataArray.h ================================================================== --- src/OFDataArray.h +++ src/OFDataArray.h @@ -149,33 +149,33 @@ * Modifying the returned array directly is allowed and will change the contents * of the data array. * * \return All elements of the OFDataArray as a C array */ -- (void*)cArray; +- (void*)cArray OF_RETURNS_INNER_POINTER; /** * \brief Returns a specific item of the OFDataArray. * * \param index The number of the item to return * \return The specified item of the OFDataArray */ -- (void*)itemAtIndex: (size_t)index; +- (void*)itemAtIndex: (size_t)index OF_RETURNS_INNER_POINTER; /** * \brief Returns the first item of the OFDataArray. * * \return The first item of the OFDataArray or NULL */ -- (void*)firstItem; +- (void*)firstItem OF_RETURNS_INNER_POINTER; /** * \brief Returns the last item of the OFDataArray. * * \return The last item of the OFDataArray or NULL */ -- (void*)lastItem; +- (void*)lastItem OF_RETURNS_INNER_POINTER; /** * \brief Adds an item to the OFDataArray. * * \param item A pointer to an arbitrary item Index: src/OFEnumerator.h ================================================================== --- src/OFEnumerator.h +++ src/OFEnumerator.h @@ -88,8 +88,8 @@ * \param count The number of objects that can be stored at objects * \return The number of objects returned in objects or 0 when the enumeration * finished. */ - (int)countByEnumeratingWithState: (of_fast_enumeration_state_t*)state - objects: (id*)objects + objects: (__unsafe_unretained id*)objects count: (int)count; @end Index: src/OFObject.h ================================================================== --- src/OFObject.h +++ src/OFObject.h @@ -35,17 +35,34 @@ #ifdef OF_APPLE_RUNTIME # import #endif -#ifdef __has_feature -# if __has_feature(objc_bool) -# undef YES -# define YES __objc_yes -# undef NO -# define NO __objc_no -# endif +#ifndef __has_feature +# define __has_feature(x) 0 +#endif + +#if __has_feature(objc_bool) +# undef YES +# define YES __objc_yes +# undef NO +# define NO __objc_no +#endif + +#if __has_feature(objc_arc) +# define OF_RETURNS_RETAINED __attribute__((ns_returns_retained)) +# define OF_RETURNS_NOT_RETAINED __attribute__((ns_returns_not_retained)) +# define OF_RETURNS_INNER_POINTER __attribute__((objc_returns_inner_pointer)) +# define OF_CONSUMED __attribute__((ns_consumed)) +# define OF_WEAK_UNAVAILABLE __attribute__((objc_arc_weak_unavailable)) +#else +# define OF_RETURNS_RETAINED +# define OF_RETURNS_NOT_RETAINED +# define OF_RETURNS_INNER_POINTER +# define OF_CONSUMED +# define OF_WEAK_UNAVAILABLE +# define __unsafe_unretained #endif #define OF_RETAIN_COUNT_MAX UINT_MAX #define OF_INVALID_INDEX SIZE_MAX Index: src/OFString.h ================================================================== --- src/OFString.h +++ src/OFString.h @@ -530,11 +530,11 @@ * use the result outside the scope of the current autorelease pool, you have to * copy it. * * \return The OFString as a UTF-8 encoded C string */ -- (const char*)UTF8String; +- (const char*)UTF8String OF_RETURNS_INNER_POINTER; /** * \brief Returns the OFString as a C string in the specified encoding. * * The result is valid until the autorelease pool is released. If you want to @@ -542,11 +542,12 @@ * copy it. * * \param encoding The encoding for the C string * \return The OFString as a C string in the specified encoding */ -- (const char*)cStringWithEncoding: (of_string_encoding_t)encoding;; +- (const char*)cStringWithEncoding: (of_string_encoding_t)encoding + OF_RETURNS_INNER_POINTER; /** * \brief Returns the length of the string in Unicode characters. * * \return The length of the string in Unicode characters @@ -837,11 +838,11 @@ * use the result outside the scope of the current autorelease pool, you have to * copy it. * * \return The string as an array of Unicode characters */ -- (const of_unichar_t*)unicodeString; +- (const of_unichar_t*)unicodeString OF_RETURNS_INNER_POINTER; /** * \brief Returns the string in big endian UTF-16 encoding. * * The result is valid until the autorelease pool is released. If you want to @@ -848,11 +849,11 @@ * use the result outside the scope of the current autorelease pool, you have to * copy it. * * \return The string in big endian UTF-16 encoding */ -- (const uint16_t*)UTF16String; +- (const uint16_t*)UTF16String OF_RETURNS_INNER_POINTER; /** * \brief Writes the string into the specified file using UTF-8 encoding. * * \param path The path of the file to write to Index: src/runtime/runtime.h ================================================================== --- src/runtime/runtime.h +++ src/runtime/runtime.h @@ -15,10 +15,16 @@ */ #ifndef __OBJFW_RUNTIME_H__ #define __OBJFW_RUNTIME_H__ #include + +#if defined(__has_feature) && __has_feature(objc_arc) +# define OBJC_BRIDGE __bridge +#else +# define OBJC_BRIDGE +#endif typedef struct objc_class *Class; typedef struct objc_object *id; typedef const struct objc_selector *SEL; typedef signed char BOOL; @@ -183,19 +189,19 @@ extern id _objc_rootAutorelease(id); static inline Class object_getClass(id obj_) { - struct objc_object *obj = (struct objc_object*)obj_; + struct objc_object *obj = (OBJC_BRIDGE struct objc_object*)obj_; return obj->isa; } static inline Class object_setClass(id obj_, Class cls) { - struct objc_object *obj = (struct objc_object*)obj_; + struct objc_object *obj = (OBJC_BRIDGE struct objc_object*)obj_; Class old = obj->isa; obj->isa = cls; return old; @@ -204,7 +210,9 @@ static inline const char* object_getClassName(id obj) { return class_getName(object_getClass(obj)); } + +#undef OBJC_BRIDGE #endif