zope.hookable 6.0__cp311-cp311-win_amd64.whl → 8.0__cp311-cp311-win_amd64.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of zope.hookable might be problematic. Click here for more details.
- zope/hookable/__init__.py +79 -75
- zope/hookable/_zope_hookable.c +285 -264
- zope/hookable/_zope_hookable.cp311-win_amd64.pyd +0 -0
- zope/hookable/tests/__init__.py +1 -1
- zope/hookable/tests/test_compile_flags.py +29 -29
- zope/hookable/tests/test_hookable.py +203 -198
- {zope.hookable-6.0.dist-info → zope_hookable-8.0.dist-info}/METADATA +50 -15
- zope_hookable-8.0.dist-info/RECORD +11 -0
- {zope.hookable-6.0.dist-info → zope_hookable-8.0.dist-info}/WHEEL +1 -1
- {zope.hookable-6.0.dist-info → zope_hookable-8.0.dist-info/licenses}/LICENSE.txt +44 -44
- zope.hookable-6.0-py3.11-nspkg.pth +0 -1
- zope.hookable-6.0.dist-info/RECORD +0 -13
- zope.hookable-6.0.dist-info/namespace_packages.txt +0 -1
- {zope.hookable-6.0.dist-info → zope_hookable-8.0.dist-info}/top_level.txt +0 -0
zope/hookable/_zope_hookable.c
CHANGED
|
@@ -1,264 +1,285 @@
|
|
|
1
|
-
/*############################################################################
|
|
2
|
-
#
|
|
3
|
-
# Copyright (c) 2003 Zope Foundation and Contributors.
|
|
4
|
-
# All Rights Reserved.
|
|
5
|
-
#
|
|
6
|
-
# This software is subject to the provisions of the Zope Public License,
|
|
7
|
-
# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
|
|
8
|
-
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
|
|
9
|
-
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
10
|
-
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
|
|
11
|
-
# FOR A PARTICULAR PURPOSE.
|
|
12
|
-
#
|
|
13
|
-
############################################################################*/
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
PyObject
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
{
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
static PyObject
|
|
103
|
-
|
|
104
|
-
{
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
/*
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
}
|
|
1
|
+
/*############################################################################
|
|
2
|
+
#
|
|
3
|
+
# Copyright (c) 2003 Zope Foundation and Contributors.
|
|
4
|
+
# All Rights Reserved.
|
|
5
|
+
#
|
|
6
|
+
# This software is subject to the provisions of the Zope Public License,
|
|
7
|
+
# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
|
|
8
|
+
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
|
|
9
|
+
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
10
|
+
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
|
|
11
|
+
# FOR A PARTICULAR PURPOSE.
|
|
12
|
+
#
|
|
13
|
+
############################################################################*/
|
|
14
|
+
|
|
15
|
+
static char module__doc__[] = (
|
|
16
|
+
"Provide an efficient implementation for hookable objects"
|
|
17
|
+
);
|
|
18
|
+
|
|
19
|
+
#include "Python.h"
|
|
20
|
+
#include "structmember.h"
|
|
21
|
+
|
|
22
|
+
typedef struct
|
|
23
|
+
{
|
|
24
|
+
PyObject_HEAD
|
|
25
|
+
PyObject* original;
|
|
26
|
+
PyObject* implementation;
|
|
27
|
+
} hookable;
|
|
28
|
+
|
|
29
|
+
static int
|
|
30
|
+
hookable_init(hookable* self, PyObject* args, PyObject* kwds)
|
|
31
|
+
{
|
|
32
|
+
static char* kwlist[] = { "implementation", NULL };
|
|
33
|
+
PyObject* implementation;
|
|
34
|
+
|
|
35
|
+
if (!PyArg_ParseTupleAndKeywords(
|
|
36
|
+
args, kwds, "O:hookable", kwlist, &implementation))
|
|
37
|
+
return -1;
|
|
38
|
+
|
|
39
|
+
/* Both 'self->original' and 'self->implementation' are originally
|
|
40
|
+
* set to the passed-in 'implementation', hence the need for
|
|
41
|
+
* two increfs.
|
|
42
|
+
*/
|
|
43
|
+
Py_INCREF(implementation);
|
|
44
|
+
Py_XDECREF(self->original);
|
|
45
|
+
self->original = implementation;
|
|
46
|
+
|
|
47
|
+
Py_INCREF(implementation);
|
|
48
|
+
Py_XDECREF(self->implementation);
|
|
49
|
+
self->implementation = implementation;
|
|
50
|
+
|
|
51
|
+
return 0;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
static int
|
|
55
|
+
hookable_traverse(hookable* self, visitproc visit, void* arg)
|
|
56
|
+
{
|
|
57
|
+
#if PY_VERSION_HEX >= 0x03090000
|
|
58
|
+
Py_VISIT(Py_TYPE(self));
|
|
59
|
+
#endif
|
|
60
|
+
Py_VISIT(self->implementation);
|
|
61
|
+
Py_VISIT(self->original);
|
|
62
|
+
return 0;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
static int
|
|
66
|
+
hookable_clear(hookable* self)
|
|
67
|
+
{
|
|
68
|
+
Py_XDECREF(self->original);
|
|
69
|
+
self->original = NULL;
|
|
70
|
+
|
|
71
|
+
Py_XDECREF(self->implementation);
|
|
72
|
+
self->implementation = NULL;
|
|
73
|
+
|
|
74
|
+
return 0;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
static void
|
|
78
|
+
hookable_dealloc(hookable* self)
|
|
79
|
+
{
|
|
80
|
+
PyObject_GC_UnTrack((PyObject*)self);
|
|
81
|
+
PyTypeObject* tp = Py_TYPE(self);
|
|
82
|
+
|
|
83
|
+
Py_XDECREF(self->original);
|
|
84
|
+
Py_XDECREF(self->implementation);
|
|
85
|
+
|
|
86
|
+
tp->tp_free((PyObject*)self);
|
|
87
|
+
|
|
88
|
+
/* heap types must decref their type when dealloc'ed */
|
|
89
|
+
Py_DECREF(tp);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
static PyObject*
|
|
93
|
+
hookable_call(hookable* self, PyObject* args, PyObject* kw)
|
|
94
|
+
{
|
|
95
|
+
if (self->implementation != NULL)
|
|
96
|
+
return PyObject_Call(self->implementation, args, kw);
|
|
97
|
+
|
|
98
|
+
PyErr_SetString(PyExc_TypeError, "Hookable has no implementation");
|
|
99
|
+
return NULL;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
static PyObject*
|
|
103
|
+
hookable_getattro(hookable* self, PyObject* name)
|
|
104
|
+
{
|
|
105
|
+
PyObject* result = NULL;
|
|
106
|
+
const char* name_as_string;
|
|
107
|
+
int maybe_special_name;
|
|
108
|
+
|
|
109
|
+
name_as_string = PyUnicode_AsUTF8(name);
|
|
110
|
+
if (name_as_string == NULL) { return NULL; }
|
|
111
|
+
|
|
112
|
+
maybe_special_name = name_as_string[0] == '_' && name_as_string[1] == '_';
|
|
113
|
+
|
|
114
|
+
if (maybe_special_name) {
|
|
115
|
+
/* pass through __doc__ to the original implementation */
|
|
116
|
+
if (strcmp("__doc__", name_as_string) == 0) {
|
|
117
|
+
return PyObject_GetAttr(self->original, name);
|
|
118
|
+
}
|
|
119
|
+
/* synthesize __bases__ and __dict__ if the original fails */
|
|
120
|
+
if (strcmp("__bases__", name_as_string) == 0) {
|
|
121
|
+
result = PyObject_GetAttr(self->original, name);
|
|
122
|
+
if (result == NULL) {
|
|
123
|
+
PyErr_Clear();
|
|
124
|
+
result = PyTuple_New(0);
|
|
125
|
+
}
|
|
126
|
+
return result;
|
|
127
|
+
}
|
|
128
|
+
if (strcmp("__dict__", name_as_string) == 0) {
|
|
129
|
+
result = PyObject_GetAttr(self->original, name);
|
|
130
|
+
if (result == NULL) {
|
|
131
|
+
PyErr_Clear();
|
|
132
|
+
result = PyDict_New();
|
|
133
|
+
}
|
|
134
|
+
return result;
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
return PyObject_GenericGetAttr((PyObject*)self, name);
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
static char hookable_sethook__doc__[] = (
|
|
142
|
+
"Set the hook implementation for the hookable object\n\n"
|
|
143
|
+
"Return the previous hook implementation, or None."
|
|
144
|
+
);
|
|
145
|
+
|
|
146
|
+
static PyObject*
|
|
147
|
+
hookable_sethook(hookable* self, PyObject* implementation)
|
|
148
|
+
{
|
|
149
|
+
PyObject* current;
|
|
150
|
+
|
|
151
|
+
current = self->implementation;
|
|
152
|
+
Py_INCREF(implementation);
|
|
153
|
+
self->implementation = implementation;
|
|
154
|
+
|
|
155
|
+
if (current == NULL) {
|
|
156
|
+
Py_INCREF(Py_None);
|
|
157
|
+
return Py_None;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
return current;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
static char hookable_reset__doc__[] = (
|
|
164
|
+
"Reset the hook to the original value"
|
|
165
|
+
);
|
|
166
|
+
|
|
167
|
+
static PyObject*
|
|
168
|
+
hookable_reset(hookable* self)
|
|
169
|
+
{
|
|
170
|
+
Py_XINCREF(self->original);
|
|
171
|
+
Py_XDECREF(self->implementation);
|
|
172
|
+
|
|
173
|
+
self->implementation = self->original;
|
|
174
|
+
|
|
175
|
+
Py_INCREF(Py_None);
|
|
176
|
+
return Py_None;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
static struct PyMethodDef hookable_methods[] = {
|
|
180
|
+
{ "sethook",
|
|
181
|
+
(PyCFunction)hookable_sethook, METH_O, hookable_sethook__doc__ },
|
|
182
|
+
{ "reset",
|
|
183
|
+
(PyCFunction)hookable_reset, METH_NOARGS, hookable_reset__doc__},
|
|
184
|
+
{ NULL, NULL } /* sentinel */
|
|
185
|
+
};
|
|
186
|
+
|
|
187
|
+
static PyMemberDef hookable_members[] = {
|
|
188
|
+
{ "original",
|
|
189
|
+
T_OBJECT_EX, offsetof(hookable, original), READONLY },
|
|
190
|
+
{ "implementation",
|
|
191
|
+
T_OBJECT_EX, offsetof(hookable, implementation), READONLY },
|
|
192
|
+
{ NULL } /* Sentinel */
|
|
193
|
+
};
|
|
194
|
+
|
|
195
|
+
static char hookable__name__[] = "zope.hookable.hookable";
|
|
196
|
+
static char hookable__doc__[] =
|
|
197
|
+
"Callable objects that support being overridden";
|
|
198
|
+
|
|
199
|
+
|
|
200
|
+
/*
|
|
201
|
+
* Heap type: hookable
|
|
202
|
+
*/
|
|
203
|
+
static PyType_Slot hookable_type_slots[] = {
|
|
204
|
+
{Py_tp_doc, hookable__doc__},
|
|
205
|
+
{Py_tp_init, hookable_init},
|
|
206
|
+
{Py_tp_call, hookable_call},
|
|
207
|
+
{Py_tp_getattro, hookable_getattro},
|
|
208
|
+
{Py_tp_traverse, hookable_traverse},
|
|
209
|
+
{Py_tp_clear, hookable_clear},
|
|
210
|
+
{Py_tp_dealloc, hookable_dealloc},
|
|
211
|
+
{Py_tp_members, hookable_members},
|
|
212
|
+
{Py_tp_methods, hookable_methods},
|
|
213
|
+
{0, NULL}
|
|
214
|
+
};
|
|
215
|
+
|
|
216
|
+
static PyType_Spec hookable_type_spec = {
|
|
217
|
+
.name = hookable__name__,
|
|
218
|
+
.basicsize = sizeof(hookable),
|
|
219
|
+
.flags = Py_TPFLAGS_DEFAULT |
|
|
220
|
+
Py_TPFLAGS_BASETYPE |
|
|
221
|
+
#if PY_VERSION_HEX >= 0x030c0000
|
|
222
|
+
Py_TPFLAGS_MANAGED_WEAKREF |
|
|
223
|
+
#endif
|
|
224
|
+
Py_TPFLAGS_HAVE_GC,
|
|
225
|
+
.slots = hookable_type_slots
|
|
226
|
+
};
|
|
227
|
+
|
|
228
|
+
/*
|
|
229
|
+
* Module initialization
|
|
230
|
+
*/
|
|
231
|
+
|
|
232
|
+
static struct PyMethodDef hookable_module_methods[] = {
|
|
233
|
+
{ NULL, NULL } /* sentinel */
|
|
234
|
+
};
|
|
235
|
+
|
|
236
|
+
|
|
237
|
+
/* Handler for the 'execute' phase of multi-phase initialization
|
|
238
|
+
*
|
|
239
|
+
* See: https://docs.python.org/3/c-api/module.html#multi-phase-initialization
|
|
240
|
+
* and: https://peps.python.org/pep-0489/#module-execution-phase
|
|
241
|
+
*/
|
|
242
|
+
static int
|
|
243
|
+
hookable_module_exec(PyObject* module)
|
|
244
|
+
{
|
|
245
|
+
PyObject* hookable_type;
|
|
246
|
+
|
|
247
|
+
hookable_type = PyType_FromSpec(&hookable_type_spec);
|
|
248
|
+
if (hookable_type == NULL) { return -1; }
|
|
249
|
+
|
|
250
|
+
if (PyModule_AddObject(module, "hookable", hookable_type) < 0)
|
|
251
|
+
return -1;
|
|
252
|
+
|
|
253
|
+
return 0;
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
|
|
257
|
+
/* Slot definitions for multi-phase initialization
|
|
258
|
+
*
|
|
259
|
+
* See: https://docs.python.org/3/c-api/module.html#multi-phase-initialization
|
|
260
|
+
* and: https://peps.python.org/pep-0489
|
|
261
|
+
*/
|
|
262
|
+
static PyModuleDef_Slot hookable_module_slots[] = {
|
|
263
|
+
{Py_mod_exec, hookable_module_exec},
|
|
264
|
+
{0, NULL}
|
|
265
|
+
};
|
|
266
|
+
|
|
267
|
+
static struct PyModuleDef hookable_module_def = {
|
|
268
|
+
PyModuleDef_HEAD_INIT,
|
|
269
|
+
.m_name = "_zope_hookable",
|
|
270
|
+
.m_doc = module__doc__,
|
|
271
|
+
.m_methods = hookable_module_methods,
|
|
272
|
+
.m_slots = hookable_module_slots
|
|
273
|
+
};
|
|
274
|
+
|
|
275
|
+
static PyObject*
|
|
276
|
+
init(void)
|
|
277
|
+
{
|
|
278
|
+
return PyModuleDef_Init(&hookable_module_def);
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
PyMODINIT_FUNC
|
|
282
|
+
PyInit__zope_hookable(void)
|
|
283
|
+
{
|
|
284
|
+
return init();
|
|
285
|
+
}
|
|
Binary file
|
zope/hookable/tests/__init__.py
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
# This line required to prevent an empty file.
|
|
1
|
+
# This line required to prevent an empty file.
|
|
@@ -1,29 +1,29 @@
|
|
|
1
|
-
##############################################################################
|
|
2
|
-
#
|
|
3
|
-
# Copyright (c) 2022 Zope Foundation and Contributors.
|
|
4
|
-
# All Rights Reserved.
|
|
5
|
-
#
|
|
6
|
-
# This software is subject to the provisions of the Zope Public License,
|
|
7
|
-
# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
|
|
8
|
-
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
|
|
9
|
-
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
10
|
-
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
|
|
11
|
-
# FOR A PARTICULAR PURPOSE
|
|
12
|
-
#
|
|
13
|
-
##############################################################################
|
|
14
|
-
import struct
|
|
15
|
-
import unittest
|
|
16
|
-
|
|
17
|
-
import zope.hookable # noqa: try to load a C module for side effects
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
class TestFloatingPoint(unittest.TestCase):
|
|
21
|
-
|
|
22
|
-
def test_no_fast_math_optimization(self):
|
|
23
|
-
# Building with -Ofast enables -ffast-math, which sets certain FPU
|
|
24
|
-
# flags that can cause breakage elsewhere. A library such as BTrees
|
|
25
|
-
# has no business changing global FPU flags for the entire process.
|
|
26
|
-
zero_bits = struct.unpack("!Q", struct.pack("!d", 0.0))[0]
|
|
27
|
-
next_up = zero_bits + 1
|
|
28
|
-
smallest_subnormal = struct.unpack("!d", struct.pack("!Q", next_up))[0]
|
|
29
|
-
self.assertNotEqual(smallest_subnormal, 0.0)
|
|
1
|
+
##############################################################################
|
|
2
|
+
#
|
|
3
|
+
# Copyright (c) 2022 Zope Foundation and Contributors.
|
|
4
|
+
# All Rights Reserved.
|
|
5
|
+
#
|
|
6
|
+
# This software is subject to the provisions of the Zope Public License,
|
|
7
|
+
# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
|
|
8
|
+
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
|
|
9
|
+
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
10
|
+
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
|
|
11
|
+
# FOR A PARTICULAR PURPOSE
|
|
12
|
+
#
|
|
13
|
+
##############################################################################
|
|
14
|
+
import struct
|
|
15
|
+
import unittest
|
|
16
|
+
|
|
17
|
+
import zope.hookable # noqa: try to load a C module for side effects
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
class TestFloatingPoint(unittest.TestCase):
|
|
21
|
+
|
|
22
|
+
def test_no_fast_math_optimization(self):
|
|
23
|
+
# Building with -Ofast enables -ffast-math, which sets certain FPU
|
|
24
|
+
# flags that can cause breakage elsewhere. A library such as BTrees
|
|
25
|
+
# has no business changing global FPU flags for the entire process.
|
|
26
|
+
zero_bits = struct.unpack("!Q", struct.pack("!d", 0.0))[0]
|
|
27
|
+
next_up = zero_bits + 1
|
|
28
|
+
smallest_subnormal = struct.unpack("!d", struct.pack("!Q", next_up))[0]
|
|
29
|
+
self.assertNotEqual(smallest_subnormal, 0.0)
|