| @@ -1,14 +1,14 @@ | | | @@ -1,14 +1,14 @@ |
1 | $NetBSD: patch-Modules_timemodule.c,v 1.1 2020/11/17 19:33:15 sjmulder Exp $ | | 1 | $NetBSD: patch-Modules_timemodule.c,v 1.2 2020/11/18 10:51:01 sjmulder Exp $ |
2 | | | 2 | |
3 | Support for macOS 11 and Apple Silicon (ARM). Mostly backported from: | | 3 | Support for macOS 11 and Apple Silicon (ARM). Mostly backported from: |
4 | https://github.com/python/cpython/pull/22855 | | 4 | https://github.com/python/cpython/pull/22855 |
5 | | | 5 | |
6 | --- Modules/timemodule.c.orig 2020-09-23 12:36:32.000000000 +0000 | | 6 | --- Modules/timemodule.c.orig 2020-09-23 12:36:32.000000000 +0000 |
7 | +++ Modules/timemodule.c | | 7 | +++ Modules/timemodule.c |
8 | @@ -48,6 +48,15 @@ | | 8 | @@ -48,6 +48,15 @@ |
9 | #define _Py_tzname tzname | | 9 | #define _Py_tzname tzname |
10 | #endif | | 10 | #endif |
11 | | | 11 | |
12 | +#if defined(__APPLE__ ) && defined(__has_builtin) | | 12 | +#if defined(__APPLE__ ) && defined(__has_builtin) |
13 | +# if __has_builtin(__builtin_available) | | 13 | +# if __has_builtin(__builtin_available) |
14 | +# define HAVE_CLOCK_GETTIME_RUNTIME __builtin_available(macOS 10.12, iOS 10.0, tvOS 10.0, watchOS 3.0, *) | | 14 | +# define HAVE_CLOCK_GETTIME_RUNTIME __builtin_available(macOS 10.12, iOS 10.0, tvOS 10.0, watchOS 3.0, *) |
| @@ -94,93 +94,95 @@ https://github.com/python/cpython/pull/2 | | | @@ -94,93 +94,95 @@ https://github.com/python/cpython/pull/2 |
94 | - } | | 94 | - } |
95 | | | 95 | |
96 | - if (_PyTime_FromTimespec(tp, &ts) < 0) { | | 96 | - if (_PyTime_FromTimespec(tp, &ts) < 0) { |
97 | - return -1; | | 97 | - return -1; |
98 | + if (_PyTime_FromTimespec(tp, &ts) < 0) { | | 98 | + if (_PyTime_FromTimespec(tp, &ts) < 0) { |
99 | + return -1; | | 99 | + return -1; |
100 | + } | | 100 | + } |
101 | + return 0; | | 101 | + return 0; |
102 | } | | 102 | } |
103 | - return 0; | | 103 | - return 0; |
104 | } | | 104 | } |
105 | #endif | | 105 | #endif |
106 | | | 106 | |
107 | @@ -1346,6 +1374,16 @@ _PyTime_GetThreadTimeWithInfo(_PyTime_t | | 107 | @@ -1346,6 +1374,18 @@ _PyTime_GetThreadTimeWithInfo(_PyTime_t |
108 | | | 108 | |
109 | #elif defined(HAVE_CLOCK_GETTIME) && defined(CLOCK_PROCESS_CPUTIME_ID) | | 109 | #elif defined(HAVE_CLOCK_GETTIME) && defined(CLOCK_PROCESS_CPUTIME_ID) |
110 | #define HAVE_THREAD_TIME | | 110 | #define HAVE_THREAD_TIME |
111 | + | | 111 | + |
112 | +#if defined(__APPLE__) && defined(__has_attribute) && __has_attribute(availability) | | 112 | +#if defined(__APPLE__) && defined(__has_attribute) |
| | | 113 | +# if __has_attribute(availability) |
113 | +static int | | 114 | +static int |
114 | +_PyTime_GetThreadTimeWithInfo(_PyTime_t *tp, _Py_clock_info_t *info) | | 115 | +_PyTime_GetThreadTimeWithInfo(_PyTime_t *tp, _Py_clock_info_t *info) |
115 | + __attribute__((availability(macos, introduced=10.12))) | | 116 | + __attribute__((availability(macos, introduced=10.12))) |
116 | + __attribute__((availability(ios, introduced=10.0))) | | 117 | + __attribute__((availability(ios, introduced=10.0))) |
117 | + __attribute__((availability(tvos, introduced=10.0))) | | 118 | + __attribute__((availability(tvos, introduced=10.0))) |
118 | + __attribute__((availability(watchos, introduced=3.0))); | | 119 | + __attribute__((availability(watchos, introduced=3.0))); |
| | | 120 | +# endif |
119 | +#endif | | 121 | +#endif |
120 | + | | 122 | + |
121 | static int | | 123 | static int |
122 | _PyTime_GetThreadTimeWithInfo(_PyTime_t *tp, _Py_clock_info_t *info) | | 124 | _PyTime_GetThreadTimeWithInfo(_PyTime_t *tp, _Py_clock_info_t *info) |
123 | { | | 125 | { |
124 | @@ -1377,6 +1415,15 @@ _PyTime_GetThreadTimeWithInfo(_PyTime_t | | 126 | @@ -1377,6 +1417,15 @@ _PyTime_GetThreadTimeWithInfo(_PyTime_t |
125 | #endif | | 127 | #endif |
126 | | | 128 | |
127 | #ifdef HAVE_THREAD_TIME | | 129 | #ifdef HAVE_THREAD_TIME |
128 | +#ifdef __APPLE__ | | 130 | +#ifdef __APPLE__ |
129 | +/* | | 131 | +/* |
130 | + * The clock_* functions will be removed from the module | | 132 | + * The clock_* functions will be removed from the module |
131 | + * dict entirely when the C API is not available. | | 133 | + * dict entirely when the C API is not available. |
132 | + */ | | 134 | + */ |
133 | +#pragma clang diagnostic push | | 135 | +#pragma clang diagnostic push |
134 | +#pragma clang diagnostic ignored "-Wunguarded-availability" | | 136 | +#pragma clang diagnostic ignored "-Wunguarded-availability" |
135 | +#endif | | 137 | +#endif |
136 | + | | 138 | + |
137 | static PyObject * | | 139 | static PyObject * |
138 | time_thread_time(PyObject *self, PyObject *unused) | | 140 | time_thread_time(PyObject *self, PyObject *unused) |
139 | { | | 141 | { |
140 | @@ -1407,6 +1454,11 @@ PyDoc_STRVAR(thread_time_ns_doc, | | 142 | @@ -1407,6 +1456,11 @@ PyDoc_STRVAR(thread_time_ns_doc, |
141 | \n\ | | 143 | \n\ |
142 | Thread time for profiling as nanoseconds:\n\ | | 144 | Thread time for profiling as nanoseconds:\n\ |
143 | sum of the kernel and user-space CPU time."); | | 145 | sum of the kernel and user-space CPU time."); |
144 | + | | 146 | + |
145 | +#ifdef __APPLE__ | | 147 | +#ifdef __APPLE__ |
146 | +#pragma clang diagnostic pop | | 148 | +#pragma clang diagnostic pop |
147 | +#endif | | 149 | +#endif |
148 | + | | 150 | + |
149 | #endif | | 151 | #endif |
150 | | | 152 | |
151 | | | 153 | |
152 | @@ -1456,9 +1508,19 @@ time_get_clock_info(PyObject *self, PyOb | | 154 | @@ -1456,9 +1510,19 @@ time_get_clock_info(PyObject *self, PyOb |
153 | } | | 155 | } |
154 | #ifdef HAVE_THREAD_TIME | | 156 | #ifdef HAVE_THREAD_TIME |
155 | else if (strcmp(name, "thread_time") == 0) { | | 157 | else if (strcmp(name, "thread_time") == 0) { |
156 | - if (_PyTime_GetThreadTimeWithInfo(&t, &info) < 0) { | | 158 | - if (_PyTime_GetThreadTimeWithInfo(&t, &info) < 0) { |
157 | + | | 159 | + |
158 | +#ifdef __APPLE__ | | 160 | +#ifdef __APPLE__ |
159 | + if (HAVE_CLOCK_GETTIME_RUNTIME) { | | 161 | + if (HAVE_CLOCK_GETTIME_RUNTIME) { |
160 | +#endif | | 162 | +#endif |
161 | + if (_PyTime_GetThreadTimeWithInfo(&t, &info) < 0) { | | 163 | + if (_PyTime_GetThreadTimeWithInfo(&t, &info) < 0) { |
162 | + return NULL; | | 164 | + return NULL; |
163 | + } | | 165 | + } |
164 | +#ifdef __APPLE__ | | 166 | +#ifdef __APPLE__ |
165 | + } else { | | 167 | + } else { |
166 | + PyErr_SetString(PyExc_ValueError, "unknown clock"); | | 168 | + PyErr_SetString(PyExc_ValueError, "unknown clock"); |
167 | return NULL; | | 169 | return NULL; |
168 | } | | 170 | } |
169 | +#endif | | 171 | +#endif |
170 | } | | 172 | } |
171 | #endif | | 173 | #endif |
172 | else { | | 174 | else { |
173 | @@ -1757,43 +1819,88 @@ PyInit_time(void) | | 175 | @@ -1757,43 +1821,88 @@ PyInit_time(void) |
174 | if (m == NULL) | | 176 | if (m == NULL) |
175 | return NULL; | | 177 | return NULL; |
176 | | | 178 | |
177 | +#if defined(__APPLE__) && defined(HAVE_CLOCK_GETTIME) | | 179 | +#if defined(__APPLE__) && defined(HAVE_CLOCK_GETTIME) |
178 | + if (HAVE_CLOCK_GETTIME_RUNTIME) { | | 180 | + if (HAVE_CLOCK_GETTIME_RUNTIME) { |
179 | + /* pass: ^^^ cannot use '!' here */ | | 181 | + /* pass: ^^^ cannot use '!' here */ |
180 | + } else { | | 182 | + } else { |
181 | + PyObject* dct = PyModule_GetDict(m); | | 183 | + PyObject* dct = PyModule_GetDict(m); |
182 | + if (dct == NULL) { | | 184 | + if (dct == NULL) { |
183 | + return -1; | | 185 | + return -1; |
184 | + } | | 186 | + } |
185 | + | | 187 | + |
186 | + if (PyDict_DelItemString(dct, "clock_gettime") == -1) { | | 188 | + if (PyDict_DelItemString(dct, "clock_gettime") == -1) { |