@@ -26,181 +26,15 @@ #include #include #include #include -#ifdef OF_OBJFW_RUNTIME -# import "runtime.h" -#else -# import -#endif - -#ifdef OF_APPLE_RUNTIME -# import -# import -#endif +#import "macros.h" +#import "autorelease.h" /*! @file */ -#if defined(__GNUC__) -# define restrict __restrict__ -#elif __STDC_VERSION__ < 199901L -# define restrict -#endif - -#if __STDC_VERSION__ >= 201112L -# ifdef OF_HAVE_STDNORETURN_H -# include -# else -# define noreturn _Noreturn -# endif -#elif defined(__GNUC__) -# define noreturn __attribute__((__noreturn__)) -#else -# define noreturn -#endif - -/* - * Work around Apple's libc headers breaking by defining noreturn. - * They use __attribute__((noreturn)) where they should be using - * __attribute__((__noreturn__)). - */ -#if defined(__APPLE__) && defined(__dead2) -# undef __dead2 -# define __dead2 __attribute__((__noreturn__)) -#endif - -#if defined(OF_HAVE__THREAD_LOCAL) -# define OF_HAVE_COMPILER_TLS -# ifdef OF_HAVE_THREADS_H -# include -# else -# define thread_local _Thread_local -# endif -#elif defined(OF_HAVE___THREAD) -# define OF_HAVE_COMPILER_TLS -# define thread_local __thread -#endif - -#ifndef __has_feature -# define __has_feature(x) 0 -#endif - -#ifndef __has_attribute -# define __has_attribute(x) 0 -#endif - -#ifdef __GNUC__ -# define __GCC_VERSION__ (__GNUC__ * 100 + __GNUC_MINOR__) -#else -# define __GCC_VERSION__ 0 -#endif - -#if defined(__clang__) || __GCC_VERSION__ >= 406 || defined(OBJC_NEW_PROPERTIES) -# define OF_HAVE_PROPERTIES -# define OF_HAVE_OPTIONAL_PROTOCOLS -# if defined(__clang__) || __GCC_VERSION__ >= 406 || defined(OF_APPLE_RUNTIME) -# define OF_HAVE_FAST_ENUMERATION -# endif -# define OF_HAVE_CLASS_EXTENSIONS -#endif - -#if !__has_feature(objc_instancetype) -# define instancetype id -#endif - -#if __has_feature(blocks) -# define OF_HAVE_BLOCKS -#endif - -#if __has_feature(objc_bool) -# undef YES -# define YES __objc_yes -# undef NO -# define NO __objc_no -# ifndef __cplusplus -# undef true -# define true ((bool)1) -# undef false -# define false ((bool)0) -# endif -#endif - -#if defined(__clang__) || __GCC_VERSION__ >= 406 -# define OF_SENTINEL __attribute__((__sentinel__)) -# define OF_METHOD_NORETURN __attribute__((__noreturn__)) -#else -# define OF_SENTINEL -# define OF_METHOD_NORETURN -#endif - -#if __has_attribute(__objc_requires_super__) -# define OF_REQUIRES_SUPER __attribute__((__objc_requires_super__)) -#else -# define OF_REQUIRES_SUPER -#endif - -#if __has_attribute(__objc_root_class__) -# define OF_ROOT_CLASS __attribute__((__objc_root_class__)) -#else -# define OF_ROOT_CLASS -#endif - -#ifdef OF_APPLE_RUNTIME -# if defined(__x86_64__) || defined(__i386__) || defined(__ARM64_ARCH_8__) || \ - defined(__arm__) || defined(__ppc__) -# define OF_HAVE_FORWARDING_TARGET_FOR_SELECTOR -# define OF_HAVE_FORWARDING_TARGET_FOR_SELECTOR_STRET -# endif -#else -# if defined(__ELF__) -# if defined(__x86_64__) || defined(__amd64__) || defined(__i386__) || \ - defined(__arm__) || defined(__ARM__) || defined(__ppc__) || \ - defined(__PPC__) -# define OF_HAVE_FORWARDING_TARGET_FOR_SELECTOR -# if __OBJFW_RUNTIME_ABI__ >= 800 -# define OF_HAVE_FORWARDING_TARGET_FOR_SELECTOR_STRET -# endif -# endif -# if (defined(_MIPS_SIM) && _MIPS_SIM == _ABIO32) || \ - (defined(__mips_eabi) && _MIPS_SZPTR == 32) -# define OF_HAVE_FORWARDING_TARGET_FOR_SELECTOR -# if __OBJFW_RUNTIME_ABI__ >= 800 -# define OF_HAVE_FORWARDING_TARGET_FOR_SELECTOR_STRET -# endif -# endif -# elif defined(_WIN32) -# if defined(__x86_64__) || defined(__i386__) -# define OF_HAVE_FORWARDING_TARGET_FOR_SELECTOR -# if __OBJFW_RUNTIME_ABI__ >= 800 -# define OF_HAVE_FORWARDING_TARGET_FOR_SELECTOR_STRET -# endif -# endif -# endif -#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 -# define __bridge -# define __autoreleasing -#endif - -#define OF_RETAIN_COUNT_MAX UINT_MAX -#define OF_NOT_FOUND SIZE_MAX - /*! * @brief A result of a comparison. */ typedef enum { /*! The left object is smaller than the right */ @@ -230,10 +64,25 @@ /*! The start of the range */ size_t location; /*! The length of the range */ size_t length; } of_range_t; + +/*! + * @brief Creates a new of_range_t. + * + * @param start The starting index of the range + * @param length The length of the range + * @return An of_range with the specified start and length + */ +static OF_INLINE of_range_t OF_CONST_FUNC +of_range(size_t start, size_t length) +{ + of_range_t range = { start, length }; + + return range; +} /*! * @brief A time interval in seconds. */ typedef double of_time_interval_t; @@ -247,10 +96,25 @@ /*! The x coordinate of the point */ float x; /*! The y coordinate of the point */ float y; } of_point_t; + +/*! + * @brief Creates a new of_point_t. + * + * @param x The x coordinate of the point + * @param y The x coordinate of the point + * @return An of_point_t with the specified coordinates + */ +static OF_INLINE of_point_t OF_CONST_FUNC +of_point(float x, float y) +{ + of_point_t point = { x, y }; + + return point; +} /*! * @struct of_dimension_t OFObject.h ObjFW/OFObject.h * * @brief A dimension. @@ -259,10 +123,25 @@ /*! The width of the dimension */ float width; /*! The height of the dimension */ float height; } of_dimension_t; + +/*! + * @brief Creates a new of_dimension_t. + * + * @param width The width of the dimension + * @param height The height of the dimension + * @return An of_dimension_t with the specified width and height + */ +static OF_INLINE of_dimension_t OF_CONST_FUNC +of_dimension(float width, float height) +{ + of_dimension_t dimension = { width, height }; + + return dimension; +} /*! * @struct of_rectangle_t OFObject.h ObjFW/OFObject.h * * @brief A rectangle. @@ -271,10 +150,30 @@ /*! The point from where the rectangle originates */ of_point_t origin; /*! The size of the rectangle */ of_dimension_t size; } of_rectangle_t; + +/*! + * @brief Creates a new of_rectangle_t. + * + * @param x The x coordinate of the top left corner of the rectangle + * @param y The y coordinate of the top left corner of the rectangle + * @param width The width of the rectangle + * @param height The height of the rectangle + * @return An of_rectangle_t with the specified origin and size + */ +static OF_INLINE of_rectangle_t OF_CONST_FUNC +of_rectangle(float x, float y, float width, float height) +{ + of_rectangle_t rectangle = { + of_point(x, y), + of_dimension(width, height) + }; + + return rectangle; +} @class OFString; @class OFThread; /*!