pytest-codspeed 2.0.0__tar.gz → 2.0.1__tar.gz

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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: pytest-codspeed
3
- Version: 2.0.0
3
+ Version: 2.0.1
4
4
  Summary: Pytest plugin to create CodSpeed benchmarks
5
5
  Project-URL: Homepage, https://codspeed.io/
6
6
  Project-URL: Documentation, https://docs.codspeed.io/
@@ -48,7 +48,7 @@ Classifier: Typing :: Typed
48
48
  Requires-Python: >=3.7
49
49
  Requires-Dist: cffi~=1.15.1
50
50
  Requires-Dist: pytest>=3.8
51
- Requires-Dist: setuptools~=67.8.0; python_version >= '3.12'
51
+ Requires-Dist: setuptools~=67.8.0; python_full_version >= '3.12.0b1'
52
52
  Provides-Extra: compat
53
53
  Requires-Dist: pytest-benchmark~=4.0.0; extra == 'compat'
54
54
  Provides-Extra: lint
@@ -37,7 +37,7 @@ classifiers = [
37
37
  dependencies = [
38
38
  "cffi ~= 1.15.1",
39
39
  "pytest>=3.8",
40
- "setuptools ~= 67.8.0; python_version >= '3.12'", # FIXME: remove when cffi supports directly python 3.12
40
+ "setuptools ~= 67.8.0; python_full_version >= '3.12.0b1'", # FIXME: remove when cffi supports directly python 3.12
41
41
  ]
42
42
 
43
43
  [project.optional-dependencies]
@@ -49,7 +49,7 @@ test = ["pytest ~= 7.0", "pytest-cov ~= 4.0.0"]
49
49
  pytest11 = { codspeed = "pytest_codspeed.plugin" }
50
50
 
51
51
  [tool.hatch.envs.default]
52
- python = "3.12"
52
+ python = "3.11"
53
53
  features = ["lint", "test", "compat"]
54
54
 
55
55
  [tool.hatch.envs.test]
@@ -0,0 +1,5 @@
1
+ __version__ = "2.0.1"
2
+
3
+ from .plugin import BenchmarkFixture
4
+
5
+ __all__ = ["BenchmarkFixture", "__version__"]
@@ -3,7 +3,17 @@ import os
3
3
  import pkgutil
4
4
  import sys
5
5
  from dataclasses import dataclass, field
6
- from typing import TYPE_CHECKING, Any, Callable, Dict, List, Optional, Tuple, Union
6
+ from typing import (
7
+ TYPE_CHECKING,
8
+ Any,
9
+ Callable,
10
+ Dict,
11
+ List,
12
+ Optional,
13
+ Tuple,
14
+ TypeVar,
15
+ Union,
16
+ )
7
17
 
8
18
  import pytest
9
19
  from _pytest.fixtures import FixtureManager
@@ -166,8 +176,11 @@ def _run_with_instrumentation(
166
176
  gc.collect()
167
177
  gc.disable()
168
178
 
179
+ result = None
180
+
169
181
  def __codspeed_root_frame__():
170
- fn(*args, **kwargs)
182
+ nonlocal result
183
+ result = fn(*args, **kwargs)
171
184
 
172
185
  if SUPPORTS_PERF_TRAMPOLINE:
173
186
  # Warmup CPython performance map cache
@@ -181,6 +194,8 @@ def _run_with_instrumentation(
181
194
  if is_gc_enabled:
182
195
  gc.enable()
183
196
 
197
+ return result
198
+
184
199
 
185
200
  @pytest.hookimpl(tryfirst=True)
186
201
  def pytest_runtest_protocol(item: "pytest.Item", nextitem: Union["pytest.Item", None]):
@@ -230,22 +245,27 @@ def pytest_runtest_protocol(item: "pytest.Item", nextitem: Union["pytest.Item",
230
245
  return reports # Deny further protocol hooks execution
231
246
 
232
247
 
248
+ T = TypeVar("T")
249
+
250
+
233
251
  class BenchmarkFixture:
252
+ """The fixture that can be used to benchmark a function."""
253
+
234
254
  def __init__(self, request: "pytest.FixtureRequest"):
235
255
  self.extra_info: Dict = {}
236
256
 
237
257
  self._request = request
238
258
 
239
- def __call__(self, func: Callable[..., Any], *args: Any, **kwargs: Any) -> Any:
259
+ def __call__(self, func: Callable[..., T], *args: Any, **kwargs: Any) -> T:
240
260
  plugin = get_plugin(self._request.config)
241
261
  plugin.benchmark_count += 1
242
262
  if plugin.is_codspeed_enabled and plugin.should_measure:
243
263
  assert plugin.lib is not None
244
- _run_with_instrumentation(
264
+ return _run_with_instrumentation(
245
265
  plugin.lib, self._request.node.nodeid, func, *args, **kwargs
246
266
  )
247
267
  else:
248
- func(*args, **kwargs)
268
+ return func(*args, **kwargs)
249
269
 
250
270
 
251
271
  @pytest.fixture(scope="function")
@@ -1 +0,0 @@
1
- __version__ = "2.0.0"
@@ -1,802 +0,0 @@
1
- #define _CFFI_
2
-
3
- /* We try to define Py_LIMITED_API before including Python.h.
4
-
5
- Mess: we can only define it if Py_DEBUG, Py_TRACE_REFS and
6
- Py_REF_DEBUG are not defined. This is a best-effort approximation:
7
- we can learn about Py_DEBUG from pyconfig.h, but it is unclear if
8
- the same works for the other two macros. Py_DEBUG implies them,
9
- but not the other way around.
10
-
11
- The implementation is messy (issue #350): on Windows, with _MSC_VER,
12
- we have to define Py_LIMITED_API even before including pyconfig.h.
13
- In that case, we guess what pyconfig.h will do to the macros above,
14
- and check our guess after the #include.
15
-
16
- Note that on Windows, with CPython 3.x, you need >= 3.5 and virtualenv
17
- version >= 16.0.0. With older versions of either, you don't get a
18
- copy of PYTHON3.DLL in the virtualenv. We can't check the version of
19
- CPython *before* we even include pyconfig.h. ffi.set_source() puts
20
- a ``#define _CFFI_NO_LIMITED_API'' at the start of this file if it is
21
- running on Windows < 3.5, as an attempt at fixing it, but that's
22
- arguably wrong because it may not be the target version of Python.
23
- Still better than nothing I guess. As another workaround, you can
24
- remove the definition of Py_LIMITED_API here.
25
-
26
- See also 'py_limited_api' in cffi/setuptools_ext.py.
27
- */
28
- #if !defined(_CFFI_USE_EMBEDDING) && !defined(Py_LIMITED_API)
29
- # ifdef _MSC_VER
30
- # if !defined(_DEBUG) && !defined(Py_DEBUG) && !defined(Py_TRACE_REFS) && !defined(Py_REF_DEBUG) && !defined(_CFFI_NO_LIMITED_API)
31
- # define Py_LIMITED_API
32
- # endif
33
- # include <pyconfig.h>
34
- /* sanity-check: Py_LIMITED_API will cause crashes if any of these
35
- are also defined. Normally, the Python file PC/pyconfig.h does not
36
- cause any of these to be defined, with the exception that _DEBUG
37
- causes Py_DEBUG. Double-check that. */
38
- # ifdef Py_LIMITED_API
39
- # if defined(Py_DEBUG)
40
- # error "pyconfig.h unexpectedly defines Py_DEBUG, but Py_LIMITED_API is set"
41
- # endif
42
- # if defined(Py_TRACE_REFS)
43
- # error "pyconfig.h unexpectedly defines Py_TRACE_REFS, but Py_LIMITED_API is set"
44
- # endif
45
- # if defined(Py_REF_DEBUG)
46
- # error "pyconfig.h unexpectedly defines Py_REF_DEBUG, but Py_LIMITED_API is set"
47
- # endif
48
- # endif
49
- # else
50
- # include <pyconfig.h>
51
- # if !defined(Py_DEBUG) && !defined(Py_TRACE_REFS) && !defined(Py_REF_DEBUG) && !defined(_CFFI_NO_LIMITED_API)
52
- # define Py_LIMITED_API
53
- # endif
54
- # endif
55
- #endif
56
-
57
- #include <Python.h>
58
- #ifdef __cplusplus
59
- extern "C" {
60
- #endif
61
- #include <stddef.h>
62
-
63
- /* This part is from file 'cffi/parse_c_type.h'. It is copied at the
64
- beginning of C sources generated by CFFI's ffi.set_source(). */
65
-
66
- typedef void *_cffi_opcode_t;
67
-
68
- #define _CFFI_OP(opcode, arg) (_cffi_opcode_t)(opcode | (((uintptr_t)(arg)) << 8))
69
- #define _CFFI_GETOP(cffi_opcode) ((unsigned char)(uintptr_t)cffi_opcode)
70
- #define _CFFI_GETARG(cffi_opcode) (((intptr_t)cffi_opcode) >> 8)
71
-
72
- #define _CFFI_OP_PRIMITIVE 1
73
- #define _CFFI_OP_POINTER 3
74
- #define _CFFI_OP_ARRAY 5
75
- #define _CFFI_OP_OPEN_ARRAY 7
76
- #define _CFFI_OP_STRUCT_UNION 9
77
- #define _CFFI_OP_ENUM 11
78
- #define _CFFI_OP_FUNCTION 13
79
- #define _CFFI_OP_FUNCTION_END 15
80
- #define _CFFI_OP_NOOP 17
81
- #define _CFFI_OP_BITFIELD 19
82
- #define _CFFI_OP_TYPENAME 21
83
- #define _CFFI_OP_CPYTHON_BLTN_V 23 // varargs
84
- #define _CFFI_OP_CPYTHON_BLTN_N 25 // noargs
85
- #define _CFFI_OP_CPYTHON_BLTN_O 27 // O (i.e. a single arg)
86
- #define _CFFI_OP_CONSTANT 29
87
- #define _CFFI_OP_CONSTANT_INT 31
88
- #define _CFFI_OP_GLOBAL_VAR 33
89
- #define _CFFI_OP_DLOPEN_FUNC 35
90
- #define _CFFI_OP_DLOPEN_CONST 37
91
- #define _CFFI_OP_GLOBAL_VAR_F 39
92
- #define _CFFI_OP_EXTERN_PYTHON 41
93
-
94
- #define _CFFI_PRIM_VOID 0
95
- #define _CFFI_PRIM_BOOL 1
96
- #define _CFFI_PRIM_CHAR 2
97
- #define _CFFI_PRIM_SCHAR 3
98
- #define _CFFI_PRIM_UCHAR 4
99
- #define _CFFI_PRIM_SHORT 5
100
- #define _CFFI_PRIM_USHORT 6
101
- #define _CFFI_PRIM_INT 7
102
- #define _CFFI_PRIM_UINT 8
103
- #define _CFFI_PRIM_LONG 9
104
- #define _CFFI_PRIM_ULONG 10
105
- #define _CFFI_PRIM_LONGLONG 11
106
- #define _CFFI_PRIM_ULONGLONG 12
107
- #define _CFFI_PRIM_FLOAT 13
108
- #define _CFFI_PRIM_DOUBLE 14
109
- #define _CFFI_PRIM_LONGDOUBLE 15
110
-
111
- #define _CFFI_PRIM_WCHAR 16
112
- #define _CFFI_PRIM_INT8 17
113
- #define _CFFI_PRIM_UINT8 18
114
- #define _CFFI_PRIM_INT16 19
115
- #define _CFFI_PRIM_UINT16 20
116
- #define _CFFI_PRIM_INT32 21
117
- #define _CFFI_PRIM_UINT32 22
118
- #define _CFFI_PRIM_INT64 23
119
- #define _CFFI_PRIM_UINT64 24
120
- #define _CFFI_PRIM_INTPTR 25
121
- #define _CFFI_PRIM_UINTPTR 26
122
- #define _CFFI_PRIM_PTRDIFF 27
123
- #define _CFFI_PRIM_SIZE 28
124
- #define _CFFI_PRIM_SSIZE 29
125
- #define _CFFI_PRIM_INT_LEAST8 30
126
- #define _CFFI_PRIM_UINT_LEAST8 31
127
- #define _CFFI_PRIM_INT_LEAST16 32
128
- #define _CFFI_PRIM_UINT_LEAST16 33
129
- #define _CFFI_PRIM_INT_LEAST32 34
130
- #define _CFFI_PRIM_UINT_LEAST32 35
131
- #define _CFFI_PRIM_INT_LEAST64 36
132
- #define _CFFI_PRIM_UINT_LEAST64 37
133
- #define _CFFI_PRIM_INT_FAST8 38
134
- #define _CFFI_PRIM_UINT_FAST8 39
135
- #define _CFFI_PRIM_INT_FAST16 40
136
- #define _CFFI_PRIM_UINT_FAST16 41
137
- #define _CFFI_PRIM_INT_FAST32 42
138
- #define _CFFI_PRIM_UINT_FAST32 43
139
- #define _CFFI_PRIM_INT_FAST64 44
140
- #define _CFFI_PRIM_UINT_FAST64 45
141
- #define _CFFI_PRIM_INTMAX 46
142
- #define _CFFI_PRIM_UINTMAX 47
143
- #define _CFFI_PRIM_FLOATCOMPLEX 48
144
- #define _CFFI_PRIM_DOUBLECOMPLEX 49
145
- #define _CFFI_PRIM_CHAR16 50
146
- #define _CFFI_PRIM_CHAR32 51
147
-
148
- #define _CFFI__NUM_PRIM 52
149
- #define _CFFI__UNKNOWN_PRIM (-1)
150
- #define _CFFI__UNKNOWN_FLOAT_PRIM (-2)
151
- #define _CFFI__UNKNOWN_LONG_DOUBLE (-3)
152
-
153
- #define _CFFI__IO_FILE_STRUCT (-1)
154
-
155
-
156
- struct _cffi_global_s {
157
- const char *name;
158
- void *address;
159
- _cffi_opcode_t type_op;
160
- void *size_or_direct_fn; // OP_GLOBAL_VAR: size, or 0 if unknown
161
- // OP_CPYTHON_BLTN_*: addr of direct function
162
- };
163
-
164
- struct _cffi_getconst_s {
165
- unsigned long long value;
166
- const struct _cffi_type_context_s *ctx;
167
- int gindex;
168
- };
169
-
170
- struct _cffi_struct_union_s {
171
- const char *name;
172
- int type_index; // -> _cffi_types, on a OP_STRUCT_UNION
173
- int flags; // _CFFI_F_* flags below
174
- size_t size;
175
- int alignment;
176
- int first_field_index; // -> _cffi_fields array
177
- int num_fields;
178
- };
179
- #define _CFFI_F_UNION 0x01 // is a union, not a struct
180
- #define _CFFI_F_CHECK_FIELDS 0x02 // complain if fields are not in the
181
- // "standard layout" or if some are missing
182
- #define _CFFI_F_PACKED 0x04 // for CHECK_FIELDS, assume a packed struct
183
- #define _CFFI_F_EXTERNAL 0x08 // in some other ffi.include()
184
- #define _CFFI_F_OPAQUE 0x10 // opaque
185
-
186
- struct _cffi_field_s {
187
- const char *name;
188
- size_t field_offset;
189
- size_t field_size;
190
- _cffi_opcode_t field_type_op;
191
- };
192
-
193
- struct _cffi_enum_s {
194
- const char *name;
195
- int type_index; // -> _cffi_types, on a OP_ENUM
196
- int type_prim; // _CFFI_PRIM_xxx
197
- const char *enumerators; // comma-delimited string
198
- };
199
-
200
- struct _cffi_typename_s {
201
- const char *name;
202
- int type_index; /* if opaque, points to a possibly artificial
203
- OP_STRUCT which is itself opaque */
204
- };
205
-
206
- struct _cffi_type_context_s {
207
- _cffi_opcode_t *types;
208
- const struct _cffi_global_s *globals;
209
- const struct _cffi_field_s *fields;
210
- const struct _cffi_struct_union_s *struct_unions;
211
- const struct _cffi_enum_s *enums;
212
- const struct _cffi_typename_s *typenames;
213
- int num_globals;
214
- int num_struct_unions;
215
- int num_enums;
216
- int num_typenames;
217
- const char *const *includes;
218
- int num_types;
219
- int flags; /* future extension */
220
- };
221
-
222
- struct _cffi_parse_info_s {
223
- const struct _cffi_type_context_s *ctx;
224
- _cffi_opcode_t *output;
225
- unsigned int output_size;
226
- size_t error_location;
227
- const char *error_message;
228
- };
229
-
230
- struct _cffi_externpy_s {
231
- const char *name;
232
- size_t size_of_result;
233
- void *reserved1, *reserved2;
234
- };
235
-
236
- #ifdef _CFFI_INTERNAL
237
- static int parse_c_type(struct _cffi_parse_info_s *info, const char *input);
238
- static int search_in_globals(const struct _cffi_type_context_s *ctx,
239
- const char *search, size_t search_len);
240
- static int search_in_struct_unions(const struct _cffi_type_context_s *ctx,
241
- const char *search, size_t search_len);
242
- #endif
243
-
244
- /* this block of #ifs should be kept exactly identical between
245
- c/_cffi_backend.c, cffi/vengine_cpy.py, cffi/vengine_gen.py
246
- and cffi/_cffi_include.h */
247
- #if defined(_MSC_VER)
248
- # include <malloc.h> /* for alloca() */
249
- # if _MSC_VER < 1600 /* MSVC < 2010 */
250
- typedef __int8 int8_t;
251
- typedef __int16 int16_t;
252
- typedef __int32 int32_t;
253
- typedef __int64 int64_t;
254
- typedef unsigned __int8 uint8_t;
255
- typedef unsigned __int16 uint16_t;
256
- typedef unsigned __int32 uint32_t;
257
- typedef unsigned __int64 uint64_t;
258
- typedef __int8 int_least8_t;
259
- typedef __int16 int_least16_t;
260
- typedef __int32 int_least32_t;
261
- typedef __int64 int_least64_t;
262
- typedef unsigned __int8 uint_least8_t;
263
- typedef unsigned __int16 uint_least16_t;
264
- typedef unsigned __int32 uint_least32_t;
265
- typedef unsigned __int64 uint_least64_t;
266
- typedef __int8 int_fast8_t;
267
- typedef __int16 int_fast16_t;
268
- typedef __int32 int_fast32_t;
269
- typedef __int64 int_fast64_t;
270
- typedef unsigned __int8 uint_fast8_t;
271
- typedef unsigned __int16 uint_fast16_t;
272
- typedef unsigned __int32 uint_fast32_t;
273
- typedef unsigned __int64 uint_fast64_t;
274
- typedef __int64 intmax_t;
275
- typedef unsigned __int64 uintmax_t;
276
- # else
277
- # include <stdint.h>
278
- # endif
279
- # if _MSC_VER < 1800 /* MSVC < 2013 */
280
- # ifndef __cplusplus
281
- typedef unsigned char _Bool;
282
- # endif
283
- # endif
284
- #else
285
- # include <stdint.h>
286
- # if (defined (__SVR4) && defined (__sun)) || defined(_AIX) || defined(__hpux)
287
- # include <alloca.h>
288
- # endif
289
- #endif
290
-
291
- #ifdef __GNUC__
292
- # define _CFFI_UNUSED_FN __attribute__((unused))
293
- #else
294
- # define _CFFI_UNUSED_FN /* nothing */
295
- #endif
296
-
297
- #ifdef __cplusplus
298
- # ifndef _Bool
299
- typedef bool _Bool; /* semi-hackish: C++ has no _Bool; bool is builtin */
300
- # endif
301
- #endif
302
-
303
- /********** CPython-specific section **********/
304
- #ifndef PYPY_VERSION
305
-
306
-
307
- #if PY_MAJOR_VERSION >= 3
308
- # define PyInt_FromLong PyLong_FromLong
309
- #endif
310
-
311
- #define _cffi_from_c_double PyFloat_FromDouble
312
- #define _cffi_from_c_float PyFloat_FromDouble
313
- #define _cffi_from_c_long PyInt_FromLong
314
- #define _cffi_from_c_ulong PyLong_FromUnsignedLong
315
- #define _cffi_from_c_longlong PyLong_FromLongLong
316
- #define _cffi_from_c_ulonglong PyLong_FromUnsignedLongLong
317
- #define _cffi_from_c__Bool PyBool_FromLong
318
-
319
- #define _cffi_to_c_double PyFloat_AsDouble
320
- #define _cffi_to_c_float PyFloat_AsDouble
321
-
322
- #define _cffi_from_c_int(x, type) \
323
- (((type)-1) > 0 ? /* unsigned */ \
324
- (sizeof(type) < sizeof(long) ? \
325
- PyInt_FromLong((long)x) : \
326
- sizeof(type) == sizeof(long) ? \
327
- PyLong_FromUnsignedLong((unsigned long)x) : \
328
- PyLong_FromUnsignedLongLong((unsigned long long)x)) : \
329
- (sizeof(type) <= sizeof(long) ? \
330
- PyInt_FromLong((long)x) : \
331
- PyLong_FromLongLong((long long)x)))
332
-
333
- #define _cffi_to_c_int(o, type) \
334
- ((type)( \
335
- sizeof(type) == 1 ? (((type)-1) > 0 ? (type)_cffi_to_c_u8(o) \
336
- : (type)_cffi_to_c_i8(o)) : \
337
- sizeof(type) == 2 ? (((type)-1) > 0 ? (type)_cffi_to_c_u16(o) \
338
- : (type)_cffi_to_c_i16(o)) : \
339
- sizeof(type) == 4 ? (((type)-1) > 0 ? (type)_cffi_to_c_u32(o) \
340
- : (type)_cffi_to_c_i32(o)) : \
341
- sizeof(type) == 8 ? (((type)-1) > 0 ? (type)_cffi_to_c_u64(o) \
342
- : (type)_cffi_to_c_i64(o)) : \
343
- (Py_FatalError("unsupported size for type " #type), (type)0)))
344
-
345
- #define _cffi_to_c_i8 \
346
- ((int(*)(PyObject *))_cffi_exports[1])
347
- #define _cffi_to_c_u8 \
348
- ((int(*)(PyObject *))_cffi_exports[2])
349
- #define _cffi_to_c_i16 \
350
- ((int(*)(PyObject *))_cffi_exports[3])
351
- #define _cffi_to_c_u16 \
352
- ((int(*)(PyObject *))_cffi_exports[4])
353
- #define _cffi_to_c_i32 \
354
- ((int(*)(PyObject *))_cffi_exports[5])
355
- #define _cffi_to_c_u32 \
356
- ((unsigned int(*)(PyObject *))_cffi_exports[6])
357
- #define _cffi_to_c_i64 \
358
- ((long long(*)(PyObject *))_cffi_exports[7])
359
- #define _cffi_to_c_u64 \
360
- ((unsigned long long(*)(PyObject *))_cffi_exports[8])
361
- #define _cffi_to_c_char \
362
- ((int(*)(PyObject *))_cffi_exports[9])
363
- #define _cffi_from_c_pointer \
364
- ((PyObject *(*)(char *, struct _cffi_ctypedescr *))_cffi_exports[10])
365
- #define _cffi_to_c_pointer \
366
- ((char *(*)(PyObject *, struct _cffi_ctypedescr *))_cffi_exports[11])
367
- #define _cffi_get_struct_layout \
368
- not used any more
369
- #define _cffi_restore_errno \
370
- ((void(*)(void))_cffi_exports[13])
371
- #define _cffi_save_errno \
372
- ((void(*)(void))_cffi_exports[14])
373
- #define _cffi_from_c_char \
374
- ((PyObject *(*)(char))_cffi_exports[15])
375
- #define _cffi_from_c_deref \
376
- ((PyObject *(*)(char *, struct _cffi_ctypedescr *))_cffi_exports[16])
377
- #define _cffi_to_c \
378
- ((int(*)(char *, struct _cffi_ctypedescr *, PyObject *))_cffi_exports[17])
379
- #define _cffi_from_c_struct \
380
- ((PyObject *(*)(char *, struct _cffi_ctypedescr *))_cffi_exports[18])
381
- #define _cffi_to_c_wchar_t \
382
- ((_cffi_wchar_t(*)(PyObject *))_cffi_exports[19])
383
- #define _cffi_from_c_wchar_t \
384
- ((PyObject *(*)(_cffi_wchar_t))_cffi_exports[20])
385
- #define _cffi_to_c_long_double \
386
- ((long double(*)(PyObject *))_cffi_exports[21])
387
- #define _cffi_to_c__Bool \
388
- ((_Bool(*)(PyObject *))_cffi_exports[22])
389
- #define _cffi_prepare_pointer_call_argument \
390
- ((Py_ssize_t(*)(struct _cffi_ctypedescr *, \
391
- PyObject *, char **))_cffi_exports[23])
392
- #define _cffi_convert_array_from_object \
393
- ((int(*)(char *, struct _cffi_ctypedescr *, PyObject *))_cffi_exports[24])
394
- #define _CFFI_CPIDX 25
395
- #define _cffi_call_python \
396
- ((void(*)(struct _cffi_externpy_s *, char *))_cffi_exports[_CFFI_CPIDX])
397
- #define _cffi_to_c_wchar3216_t \
398
- ((int(*)(PyObject *))_cffi_exports[26])
399
- #define _cffi_from_c_wchar3216_t \
400
- ((PyObject *(*)(int))_cffi_exports[27])
401
- #define _CFFI_NUM_EXPORTS 28
402
-
403
- struct _cffi_ctypedescr;
404
-
405
- static void *_cffi_exports[_CFFI_NUM_EXPORTS];
406
-
407
- #define _cffi_type(index) ( \
408
- assert((((uintptr_t)_cffi_types[index]) & 1) == 0), \
409
- (struct _cffi_ctypedescr *)_cffi_types[index])
410
-
411
- static PyObject *_cffi_init(const char *module_name, Py_ssize_t version,
412
- const struct _cffi_type_context_s *ctx)
413
- {
414
- PyObject *module, *o_arg, *new_module;
415
- void *raw[] = {
416
- (void *)module_name,
417
- (void *)version,
418
- (void *)_cffi_exports,
419
- (void *)ctx,
420
- };
421
-
422
- module = PyImport_ImportModule("_cffi_backend");
423
- if (module == NULL)
424
- goto failure;
425
-
426
- o_arg = PyLong_FromVoidPtr((void *)raw);
427
- if (o_arg == NULL)
428
- goto failure;
429
-
430
- new_module = PyObject_CallMethod(
431
- module, (char *)"_init_cffi_1_0_external_module", (char *)"O", o_arg);
432
-
433
- Py_DECREF(o_arg);
434
- Py_DECREF(module);
435
- return new_module;
436
-
437
- failure:
438
- Py_XDECREF(module);
439
- return NULL;
440
- }
441
-
442
-
443
- #ifdef HAVE_WCHAR_H
444
- typedef wchar_t _cffi_wchar_t;
445
- #else
446
- typedef uint16_t _cffi_wchar_t; /* same random pick as _cffi_backend.c */
447
- #endif
448
-
449
- _CFFI_UNUSED_FN static uint16_t _cffi_to_c_char16_t(PyObject *o)
450
- {
451
- if (sizeof(_cffi_wchar_t) == 2)
452
- return (uint16_t)_cffi_to_c_wchar_t(o);
453
- else
454
- return (uint16_t)_cffi_to_c_wchar3216_t(o);
455
- }
456
-
457
- _CFFI_UNUSED_FN static PyObject *_cffi_from_c_char16_t(uint16_t x)
458
- {
459
- if (sizeof(_cffi_wchar_t) == 2)
460
- return _cffi_from_c_wchar_t((_cffi_wchar_t)x);
461
- else
462
- return _cffi_from_c_wchar3216_t((int)x);
463
- }
464
-
465
- _CFFI_UNUSED_FN static int _cffi_to_c_char32_t(PyObject *o)
466
- {
467
- if (sizeof(_cffi_wchar_t) == 4)
468
- return (int)_cffi_to_c_wchar_t(o);
469
- else
470
- return (int)_cffi_to_c_wchar3216_t(o);
471
- }
472
-
473
- _CFFI_UNUSED_FN static PyObject *_cffi_from_c_char32_t(unsigned int x)
474
- {
475
- if (sizeof(_cffi_wchar_t) == 4)
476
- return _cffi_from_c_wchar_t((_cffi_wchar_t)x);
477
- else
478
- return _cffi_from_c_wchar3216_t((int)x);
479
- }
480
-
481
- union _cffi_union_alignment_u {
482
- unsigned char m_char;
483
- unsigned short m_short;
484
- unsigned int m_int;
485
- unsigned long m_long;
486
- unsigned long long m_longlong;
487
- float m_float;
488
- double m_double;
489
- long double m_longdouble;
490
- };
491
-
492
- struct _cffi_freeme_s {
493
- struct _cffi_freeme_s *next;
494
- union _cffi_union_alignment_u alignment;
495
- };
496
-
497
- _CFFI_UNUSED_FN static int
498
- _cffi_convert_array_argument(struct _cffi_ctypedescr *ctptr, PyObject *arg,
499
- char **output_data, Py_ssize_t datasize,
500
- struct _cffi_freeme_s **freeme)
501
- {
502
- char *p;
503
- if (datasize < 0)
504
- return -1;
505
-
506
- p = *output_data;
507
- if (p == NULL) {
508
- struct _cffi_freeme_s *fp = (struct _cffi_freeme_s *)PyObject_Malloc(
509
- offsetof(struct _cffi_freeme_s, alignment) + (size_t)datasize);
510
- if (fp == NULL)
511
- return -1;
512
- fp->next = *freeme;
513
- *freeme = fp;
514
- p = *output_data = (char *)&fp->alignment;
515
- }
516
- memset((void *)p, 0, (size_t)datasize);
517
- return _cffi_convert_array_from_object(p, ctptr, arg);
518
- }
519
-
520
- _CFFI_UNUSED_FN static void
521
- _cffi_free_array_arguments(struct _cffi_freeme_s *freeme)
522
- {
523
- do {
524
- void *p = (void *)freeme;
525
- freeme = freeme->next;
526
- PyObject_Free(p);
527
- } while (freeme != NULL);
528
- }
529
-
530
- /********** end CPython-specific section **********/
531
- #else
532
- _CFFI_UNUSED_FN
533
- static void (*_cffi_call_python_org)(struct _cffi_externpy_s *, char *);
534
- # define _cffi_call_python _cffi_call_python_org
535
- #endif
536
-
537
-
538
- #define _cffi_array_len(array) (sizeof(array) / sizeof((array)[0]))
539
-
540
- #define _cffi_prim_int(size, sign) \
541
- ((size) == 1 ? ((sign) ? _CFFI_PRIM_INT8 : _CFFI_PRIM_UINT8) : \
542
- (size) == 2 ? ((sign) ? _CFFI_PRIM_INT16 : _CFFI_PRIM_UINT16) : \
543
- (size) == 4 ? ((sign) ? _CFFI_PRIM_INT32 : _CFFI_PRIM_UINT32) : \
544
- (size) == 8 ? ((sign) ? _CFFI_PRIM_INT64 : _CFFI_PRIM_UINT64) : \
545
- _CFFI__UNKNOWN_PRIM)
546
-
547
- #define _cffi_prim_float(size) \
548
- ((size) == sizeof(float) ? _CFFI_PRIM_FLOAT : \
549
- (size) == sizeof(double) ? _CFFI_PRIM_DOUBLE : \
550
- (size) == sizeof(long double) ? _CFFI__UNKNOWN_LONG_DOUBLE : \
551
- _CFFI__UNKNOWN_FLOAT_PRIM)
552
-
553
- #define _cffi_check_int(got, got_nonpos, expected) \
554
- ((got_nonpos) == (expected <= 0) && \
555
- (got) == (unsigned long long)expected)
556
-
557
- #ifdef MS_WIN32
558
- # define _cffi_stdcall __stdcall
559
- #else
560
- # define _cffi_stdcall /* nothing */
561
- #endif
562
-
563
- #ifdef __cplusplus
564
- }
565
- #endif
566
-
567
- /************************************************************/
568
-
569
- #include "wrapper.h"
570
-
571
- /************************************************************/
572
-
573
- static void *_cffi_types[] = {
574
- /* 0 */ _CFFI_OP(_CFFI_OP_FUNCTION, 6), // void()(char *)
575
- /* 1 */ _CFFI_OP(_CFFI_OP_POINTER, 5), // char *
576
- /* 2 */ _CFFI_OP(_CFFI_OP_FUNCTION_END, 0),
577
- /* 3 */ _CFFI_OP(_CFFI_OP_FUNCTION, 6), // void()(void)
578
- /* 4 */ _CFFI_OP(_CFFI_OP_FUNCTION_END, 0),
579
- /* 5 */ _CFFI_OP(_CFFI_OP_PRIMITIVE, 2), // char
580
- /* 6 */ _CFFI_OP(_CFFI_OP_PRIMITIVE, 0), // void
581
- };
582
-
583
- static void _cffi_d_dump_stats(void)
584
- {
585
- dump_stats();
586
- }
587
- #ifndef PYPY_VERSION
588
- static PyObject *
589
- _cffi_f_dump_stats(PyObject *self, PyObject *noarg)
590
- {
591
-
592
- Py_BEGIN_ALLOW_THREADS
593
- _cffi_restore_errno();
594
- { dump_stats(); }
595
- _cffi_save_errno();
596
- Py_END_ALLOW_THREADS
597
-
598
- (void)self; /* unused */
599
- (void)noarg; /* unused */
600
- Py_INCREF(Py_None);
601
- return Py_None;
602
- }
603
- #else
604
- # define _cffi_f_dump_stats _cffi_d_dump_stats
605
- #endif
606
-
607
- static void _cffi_d_dump_stats_at(char * x0)
608
- {
609
- dump_stats_at(x0);
610
- }
611
- #ifndef PYPY_VERSION
612
- static PyObject *
613
- _cffi_f_dump_stats_at(PyObject *self, PyObject *arg0)
614
- {
615
- char * x0;
616
- Py_ssize_t datasize;
617
- struct _cffi_freeme_s *large_args_free = NULL;
618
-
619
- datasize = _cffi_prepare_pointer_call_argument(
620
- _cffi_type(1), arg0, (char **)&x0);
621
- if (datasize != 0) {
622
- x0 = ((size_t)datasize) <= 640 ? (char *)alloca((size_t)datasize) : NULL;
623
- if (_cffi_convert_array_argument(_cffi_type(1), arg0, (char **)&x0,
624
- datasize, &large_args_free) < 0)
625
- return NULL;
626
- }
627
-
628
- Py_BEGIN_ALLOW_THREADS
629
- _cffi_restore_errno();
630
- { dump_stats_at(x0); }
631
- _cffi_save_errno();
632
- Py_END_ALLOW_THREADS
633
-
634
- (void)self; /* unused */
635
- if (large_args_free != NULL) _cffi_free_array_arguments(large_args_free);
636
- Py_INCREF(Py_None);
637
- return Py_None;
638
- }
639
- #else
640
- # define _cffi_f_dump_stats_at _cffi_d_dump_stats_at
641
- #endif
642
-
643
- static void _cffi_d_start_instrumentation(void)
644
- {
645
- start_instrumentation();
646
- }
647
- #ifndef PYPY_VERSION
648
- static PyObject *
649
- _cffi_f_start_instrumentation(PyObject *self, PyObject *noarg)
650
- {
651
-
652
- Py_BEGIN_ALLOW_THREADS
653
- _cffi_restore_errno();
654
- { start_instrumentation(); }
655
- _cffi_save_errno();
656
- Py_END_ALLOW_THREADS
657
-
658
- (void)self; /* unused */
659
- (void)noarg; /* unused */
660
- Py_INCREF(Py_None);
661
- return Py_None;
662
- }
663
- #else
664
- # define _cffi_f_start_instrumentation _cffi_d_start_instrumentation
665
- #endif
666
-
667
- static void _cffi_d_stop_instrumentation(void)
668
- {
669
- stop_instrumentation();
670
- }
671
- #ifndef PYPY_VERSION
672
- static PyObject *
673
- _cffi_f_stop_instrumentation(PyObject *self, PyObject *noarg)
674
- {
675
-
676
- Py_BEGIN_ALLOW_THREADS
677
- _cffi_restore_errno();
678
- { stop_instrumentation(); }
679
- _cffi_save_errno();
680
- Py_END_ALLOW_THREADS
681
-
682
- (void)self; /* unused */
683
- (void)noarg; /* unused */
684
- Py_INCREF(Py_None);
685
- return Py_None;
686
- }
687
- #else
688
- # define _cffi_f_stop_instrumentation _cffi_d_stop_instrumentation
689
- #endif
690
-
691
- static void _cffi_d_toggle_collect(void)
692
- {
693
- toggle_collect();
694
- }
695
- #ifndef PYPY_VERSION
696
- static PyObject *
697
- _cffi_f_toggle_collect(PyObject *self, PyObject *noarg)
698
- {
699
-
700
- Py_BEGIN_ALLOW_THREADS
701
- _cffi_restore_errno();
702
- { toggle_collect(); }
703
- _cffi_save_errno();
704
- Py_END_ALLOW_THREADS
705
-
706
- (void)self; /* unused */
707
- (void)noarg; /* unused */
708
- Py_INCREF(Py_None);
709
- return Py_None;
710
- }
711
- #else
712
- # define _cffi_f_toggle_collect _cffi_d_toggle_collect
713
- #endif
714
-
715
- static void _cffi_d_zero_stats(void)
716
- {
717
- zero_stats();
718
- }
719
- #ifndef PYPY_VERSION
720
- static PyObject *
721
- _cffi_f_zero_stats(PyObject *self, PyObject *noarg)
722
- {
723
-
724
- Py_BEGIN_ALLOW_THREADS
725
- _cffi_restore_errno();
726
- { zero_stats(); }
727
- _cffi_save_errno();
728
- Py_END_ALLOW_THREADS
729
-
730
- (void)self; /* unused */
731
- (void)noarg; /* unused */
732
- Py_INCREF(Py_None);
733
- return Py_None;
734
- }
735
- #else
736
- # define _cffi_f_zero_stats _cffi_d_zero_stats
737
- #endif
738
-
739
- static const struct _cffi_global_s _cffi_globals[] = {
740
- { "dump_stats", (void *)_cffi_f_dump_stats, _CFFI_OP(_CFFI_OP_CPYTHON_BLTN_N, 3), (void *)_cffi_d_dump_stats },
741
- { "dump_stats_at", (void *)_cffi_f_dump_stats_at, _CFFI_OP(_CFFI_OP_CPYTHON_BLTN_O, 0), (void *)_cffi_d_dump_stats_at },
742
- { "start_instrumentation", (void *)_cffi_f_start_instrumentation, _CFFI_OP(_CFFI_OP_CPYTHON_BLTN_N, 3), (void *)_cffi_d_start_instrumentation },
743
- { "stop_instrumentation", (void *)_cffi_f_stop_instrumentation, _CFFI_OP(_CFFI_OP_CPYTHON_BLTN_N, 3), (void *)_cffi_d_stop_instrumentation },
744
- { "toggle_collect", (void *)_cffi_f_toggle_collect, _CFFI_OP(_CFFI_OP_CPYTHON_BLTN_N, 3), (void *)_cffi_d_toggle_collect },
745
- { "zero_stats", (void *)_cffi_f_zero_stats, _CFFI_OP(_CFFI_OP_CPYTHON_BLTN_N, 3), (void *)_cffi_d_zero_stats },
746
- };
747
-
748
- static const struct _cffi_type_context_s _cffi_type_context = {
749
- _cffi_types,
750
- _cffi_globals,
751
- NULL, /* no fields */
752
- NULL, /* no struct_unions */
753
- NULL, /* no enums */
754
- NULL, /* no typenames */
755
- 6, /* num_globals */
756
- 0, /* num_struct_unions */
757
- 0, /* num_enums */
758
- 0, /* num_typenames */
759
- NULL, /* no includes */
760
- 7, /* num_types */
761
- 0, /* flags */
762
- };
763
-
764
- #ifdef __GNUC__
765
- # pragma GCC visibility push(default) /* for -fvisibility= */
766
- #endif
767
-
768
- #ifdef PYPY_VERSION
769
- PyMODINIT_FUNC
770
- _cffi_pypyinit_dist_callgrind_wrapper(const void *p[])
771
- {
772
- p[0] = (const void *)0x2601;
773
- p[1] = &_cffi_type_context;
774
- #if PY_MAJOR_VERSION >= 3
775
- return NULL;
776
- #endif
777
- }
778
- # ifdef _MSC_VER
779
- PyMODINIT_FUNC
780
- # if PY_MAJOR_VERSION >= 3
781
- PyInit_dist_callgrind_wrapper(void) { return NULL; }
782
- # else
783
- initdist_callgrind_wrapper(void) { }
784
- # endif
785
- # endif
786
- #elif PY_MAJOR_VERSION >= 3
787
- PyMODINIT_FUNC
788
- PyInit_dist_callgrind_wrapper(void)
789
- {
790
- return _cffi_init("dist_callgrind_wrapper", 0x2601, &_cffi_type_context);
791
- }
792
- #else
793
- PyMODINIT_FUNC
794
- initdist_callgrind_wrapper(void)
795
- {
796
- _cffi_init("dist_callgrind_wrapper", 0x2601, &_cffi_type_context);
797
- }
798
- #endif
799
-
800
- #ifdef __GNUC__
801
- # pragma GCC visibility pop
802
- #endif
File without changes