Skip to content

Commit 9083746

Browse files
author
theraven
committed
Make OBJC_SMALL_OBJECT_SHIFT / OBJC_SMALL_OBJECT_MASK constants.
1 parent 8e34dcc commit 9083746

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

objc/runtime.h

+15-2
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,13 @@ extern "C" {
2121
# endif
2222
#endif
2323

24+
// Make sure we get the limit macros, even in C++ mode
25+
#ifndef __STDC_LIMIT_MACROS
26+
# define __STDC_LIMIT_MACROS
27+
#endif
2428

2529
#include <stdint.h>
30+
#include <limits.h>
2631
#include <stddef.h>
2732
#include <sys/types.h>
2833
#include "Availability.h"
@@ -751,11 +756,19 @@ BOOL objc_registerSmallObjectClass_np(Class cls, uintptr_t classId);
751756
* systems, we use the low 3 bits. In both cases, the lowest bit must be 1.
752757
* This restriction may be relaxed in the future on 64-bit systems.
753758
*/
754-
#define OBJC_SMALL_OBJECT_MASK ((sizeof(id) == 4) ? 1 : 7)
759+
#if UINTPTR_MAX < UINT64_MAX
760+
# define OBJC_SMALL_OBJECT_MASK 1
761+
#else
762+
# define OBJC_SMALL_OBJECT_MASK 7
763+
#endif
755764
/**
756765
* The number of bits reserved for the class identifier in a small object.
757766
*/
758-
#define OBJC_SMALL_OBJECT_SHIFT ((sizeof(id) == 4) ? 1 : 3)
767+
#if UINTPTR_MAX < UINT64_MAX
768+
# define OBJC_SMALL_OBJECT_SHIFT 1
769+
#else
770+
# define OBJC_SMALL_OBJECT_SHIFT 3
771+
#endif
759772

760773

761774
/**

0 commit comments

Comments
 (0)