mirror of
https://github.com/gnustep/libs-base.git
synced 2025-04-23 17:10:48 +00:00
Import feature test function from libobjc2 into ObjectiveC2 framework. Returns 0 for all of the new features. May return the wrong value for exception support, if the runtime is really ancient and does not support exceptions. Returns 1 for features that the framework adds.
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@31252 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
3564932935
commit
daecca9270
3 changed files with 92 additions and 0 deletions
|
@ -42,11 +42,13 @@ ObjectiveC2_OBJC_FILES += sync.m
|
|||
endif
|
||||
|
||||
ObjectiveC2_C_FILES = \
|
||||
caps.c\
|
||||
runtime.c
|
||||
|
||||
ObjectiveC2_HEADER_FILES = \
|
||||
Availability.h\
|
||||
blocks_runtime.h\
|
||||
capabilities.h\
|
||||
runtime.h
|
||||
|
||||
ifeq ($(CC), clang)
|
||||
|
|
71
Source/ObjectiveC2/capabilities.h
Normal file
71
Source/ObjectiveC2/capabilities.h
Normal file
|
@ -0,0 +1,71 @@
|
|||
/**
|
||||
* capabilities.h - This file defines the list of capabilities. Runtime
|
||||
* capabilities can be checked. You may use #ifdef to test at compile time
|
||||
* whether the runtime on the current platform understands the capability.
|
||||
* This does not mean that the runtime implements the capability, however.
|
||||
*
|
||||
* A copy of this file exists for compatibility in GNUstep's Objective-C
|
||||
* framework. When using this framework in conjunction with the GNU
|
||||
* Objective-C runtime, most of the features will not be supported at run time,
|
||||
* even if the corresponding macros are available at compile time.
|
||||
* Additionally, several are compile-time options in the GNUstep runtime, so
|
||||
* although they are present in the header and understood by the runtime, they
|
||||
* may not be supported by the installed runtime.
|
||||
*/
|
||||
|
||||
/**
|
||||
* The runtime supports zero-cost exceptions.
|
||||
*/
|
||||
#define OBJC_CAP_EXCEPTIONS 0
|
||||
/**
|
||||
* The runtime supports the @synchronize directive.
|
||||
*/
|
||||
#define OBJC_CAP_SYNCRONIZE 1
|
||||
/**
|
||||
* The runtime supports property accessors.
|
||||
*/
|
||||
#define OBJC_CAP_PROPERTIES 2
|
||||
/**
|
||||
* The runtime supports introspection on declared properties.
|
||||
*/
|
||||
#define OBJC_CAP_PROPERTY_INTROSPECTION 3
|
||||
/**
|
||||
* The runtime supports optional methods and declared properties in protocols.
|
||||
*/
|
||||
#define OBJC_CAP_OPTIONAL_PROTOCOLS 4
|
||||
/**
|
||||
* The runtime supports non-fragile instance variables.
|
||||
*/
|
||||
#define OBJC_CAP_NONFRAGILE_IVARS 5
|
||||
/**
|
||||
* The runtime supports making method lookup dependent on the types, as well as
|
||||
* the name, of the selector.
|
||||
*/
|
||||
#define OBJC_CAP_TYPE_DEPENDENT_DISPATCH 6
|
||||
/**
|
||||
* The runtime was compiled in the low-memory profile. This trades some speed
|
||||
* for reduced memory consumption.
|
||||
*/
|
||||
#define OBJC_CAP_LOW_MEMORY 7
|
||||
|
||||
|
||||
/**
|
||||
* Macro used to require the existence of a specific capability. This creates
|
||||
* a function that is called by the loader and tests that the runtime supports
|
||||
* the required capability, aborting if it does not.
|
||||
*/
|
||||
#define OBJC_REQUIRE_CAPABILITY(x) \
|
||||
__attribute__((constructor)) static void objc_test ## x(void)\
|
||||
{\
|
||||
if (!objc_test_capability(x))\
|
||||
{\
|
||||
fprintf(stderr, "Runtime does not support required property: " #x "\n");\
|
||||
exit(1);\
|
||||
}\
|
||||
}
|
||||
|
||||
/**
|
||||
* Run time feature test. This function returns 1 if the runtime supports the
|
||||
* specified feature or 0 if it does not.
|
||||
*/
|
||||
int objc_test_capability(int x);
|
19
Source/ObjectiveC2/caps.c
Normal file
19
Source/ObjectiveC2/caps.c
Normal file
|
@ -0,0 +1,19 @@
|
|||
#include "capabilities.h"
|
||||
#include <stdint.h>
|
||||
|
||||
/**
|
||||
* Bitmask of all of the capabilities compiled into this version of the
|
||||
* runtime.
|
||||
*/
|
||||
static const int32_t caps =
|
||||
(1<<OBJC_CAP_EXCEPTIONS) |
|
||||
(1<<OBJC_CAP_SYNCRONIZE) |
|
||||
(1<<OBJC_CAP_PROPERTIES) |
|
||||
0;
|
||||
|
||||
int objc_test_capability(int x)
|
||||
{
|
||||
if (x >= 32) { return 0; }
|
||||
if (caps & (1<<x)) { return 1; }
|
||||
return 0;
|
||||
}
|
Loading…
Reference in a new issue