|
273 | 273 | // the transition from the legacy behavior to the non-permissive |
274 | 274 | // behavior. |
275 | 275 |
|
276 | | -#if PY_MAJOR_VERSION >= 3 /// Compatibility macros for various Python versions |
277 | | -# define PYBIND11_INSTANCE_METHOD_NEW(ptr, class_) PyInstanceMethod_New(ptr) |
278 | | -# define PYBIND11_INSTANCE_METHOD_CHECK PyInstanceMethod_Check |
279 | | -# define PYBIND11_INSTANCE_METHOD_GET_FUNCTION PyInstanceMethod_GET_FUNCTION |
280 | | -# define PYBIND11_BYTES_CHECK PyBytes_Check |
281 | | -# define PYBIND11_BYTES_FROM_STRING PyBytes_FromString |
282 | | -# define PYBIND11_BYTES_FROM_STRING_AND_SIZE PyBytes_FromStringAndSize |
283 | | -# define PYBIND11_BYTES_AS_STRING_AND_SIZE PyBytes_AsStringAndSize |
284 | | -# define PYBIND11_BYTES_AS_STRING PyBytes_AsString |
285 | | -# define PYBIND11_BYTES_SIZE PyBytes_Size |
286 | | -# define PYBIND11_LONG_CHECK(o) PyLong_Check(o) |
287 | | -# define PYBIND11_LONG_AS_LONGLONG(o) PyLong_AsLongLong(o) |
288 | | -# define PYBIND11_LONG_FROM_SIGNED(o) PyLong_FromSsize_t((ssize_t) (o)) |
289 | | -# define PYBIND11_LONG_FROM_UNSIGNED(o) PyLong_FromSize_t((size_t) (o)) |
290 | | -# define PYBIND11_BYTES_NAME "bytes" |
291 | | -# define PYBIND11_STRING_NAME "str" |
292 | | -# define PYBIND11_SLICE_OBJECT PyObject |
293 | | -# define PYBIND11_FROM_STRING PyUnicode_FromString |
294 | | -# define PYBIND11_STR_TYPE ::pybind11::str |
295 | | -# define PYBIND11_BOOL_ATTR "__bool__" |
296 | | -# define PYBIND11_NB_BOOL(ptr) ((ptr)->nb_bool) |
297 | | -# define PYBIND11_BUILTINS_MODULE "builtins" |
| 276 | +/// Compatibility macros for Python 2 / Python 3 versions TODO: remove |
| 277 | +#define PYBIND11_INSTANCE_METHOD_NEW(ptr, class_) PyInstanceMethod_New(ptr) |
| 278 | +#define PYBIND11_INSTANCE_METHOD_CHECK PyInstanceMethod_Check |
| 279 | +#define PYBIND11_INSTANCE_METHOD_GET_FUNCTION PyInstanceMethod_GET_FUNCTION |
| 280 | +#define PYBIND11_BYTES_CHECK PyBytes_Check |
| 281 | +#define PYBIND11_BYTES_FROM_STRING PyBytes_FromString |
| 282 | +#define PYBIND11_BYTES_FROM_STRING_AND_SIZE PyBytes_FromStringAndSize |
| 283 | +#define PYBIND11_BYTES_AS_STRING_AND_SIZE PyBytes_AsStringAndSize |
| 284 | +#define PYBIND11_BYTES_AS_STRING PyBytes_AsString |
| 285 | +#define PYBIND11_BYTES_SIZE PyBytes_Size |
| 286 | +#define PYBIND11_LONG_CHECK(o) PyLong_Check(o) |
| 287 | +#define PYBIND11_LONG_AS_LONGLONG(o) PyLong_AsLongLong(o) |
| 288 | +#define PYBIND11_LONG_FROM_SIGNED(o) PyLong_FromSsize_t((ssize_t) (o)) |
| 289 | +#define PYBIND11_LONG_FROM_UNSIGNED(o) PyLong_FromSize_t((size_t) (o)) |
| 290 | +#define PYBIND11_BYTES_NAME "bytes" |
| 291 | +#define PYBIND11_STRING_NAME "str" |
| 292 | +#define PYBIND11_SLICE_OBJECT PyObject |
| 293 | +#define PYBIND11_FROM_STRING PyUnicode_FromString |
| 294 | +#define PYBIND11_STR_TYPE ::pybind11::str |
| 295 | +#define PYBIND11_BOOL_ATTR "__bool__" |
| 296 | +#define PYBIND11_NB_BOOL(ptr) ((ptr)->nb_bool) |
| 297 | +#define PYBIND11_BUILTINS_MODULE "builtins" |
298 | 298 | // Providing a separate declaration to make Clang's -Wmissing-prototypes happy. |
299 | 299 | // See comment for PYBIND11_MODULE below for why this is marked "maybe unused". |
300 | | -# define PYBIND11_PLUGIN_IMPL(name) \ |
301 | | - extern "C" PYBIND11_MAYBE_UNUSED PYBIND11_EXPORT PyObject *PyInit_##name(); \ |
302 | | - extern "C" PYBIND11_EXPORT PyObject *PyInit_##name() |
303 | | - |
304 | | -#else |
305 | | -# define PYBIND11_INSTANCE_METHOD_NEW(ptr, class_) PyMethod_New(ptr, nullptr, class_) |
306 | | -# define PYBIND11_INSTANCE_METHOD_CHECK PyMethod_Check |
307 | | -# define PYBIND11_INSTANCE_METHOD_GET_FUNCTION PyMethod_GET_FUNCTION |
308 | | -# define PYBIND11_BYTES_CHECK PyString_Check |
309 | | -# define PYBIND11_BYTES_FROM_STRING PyString_FromString |
310 | | -# define PYBIND11_BYTES_FROM_STRING_AND_SIZE PyString_FromStringAndSize |
311 | | -# define PYBIND11_BYTES_AS_STRING_AND_SIZE PyString_AsStringAndSize |
312 | | -# define PYBIND11_BYTES_AS_STRING PyString_AsString |
313 | | -# define PYBIND11_BYTES_SIZE PyString_Size |
314 | | -# define PYBIND11_LONG_CHECK(o) (PyInt_Check(o) || PyLong_Check(o)) |
315 | | -# define PYBIND11_LONG_AS_LONGLONG(o) \ |
316 | | - (PyInt_Check(o) ? (long long) PyLong_AsLong(o) : PyLong_AsLongLong(o)) |
317 | | -# define PYBIND11_LONG_FROM_SIGNED(o) PyInt_FromSsize_t((ssize_t) o) // Returns long if needed. |
318 | | -# define PYBIND11_LONG_FROM_UNSIGNED(o) PyInt_FromSize_t((size_t) o) // Returns long if needed. |
319 | | -# define PYBIND11_BYTES_NAME "str" |
320 | | -# define PYBIND11_STRING_NAME "unicode" |
321 | | -# define PYBIND11_SLICE_OBJECT PySliceObject |
322 | | -# define PYBIND11_FROM_STRING PyString_FromString |
323 | | -# define PYBIND11_STR_TYPE ::pybind11::bytes |
324 | | -# define PYBIND11_BOOL_ATTR "__nonzero__" |
325 | | -# define PYBIND11_NB_BOOL(ptr) ((ptr)->nb_nonzero) |
326 | | -# define PYBIND11_BUILTINS_MODULE "__builtin__" |
327 | | -// Providing a separate PyInit decl to make Clang's -Wmissing-prototypes happy. |
328 | | -// See comment for PYBIND11_MODULE below for why this is marked "maybe unused". |
329 | | -# define PYBIND11_PLUGIN_IMPL(name) \ |
330 | | - static PyObject *pybind11_init_wrapper(); \ |
331 | | - extern "C" PYBIND11_MAYBE_UNUSED PYBIND11_EXPORT void init##name(); \ |
332 | | - extern "C" PYBIND11_EXPORT void init##name() { (void) pybind11_init_wrapper(); } \ |
333 | | - PyObject *pybind11_init_wrapper() |
334 | | -#endif |
| 300 | +#define PYBIND11_PLUGIN_IMPL(name) \ |
| 301 | + extern "C" PYBIND11_MAYBE_UNUSED PYBIND11_EXPORT PyObject *PyInit_##name(); \ |
| 302 | + extern "C" PYBIND11_EXPORT PyObject *PyInit_##name() |
335 | 303 |
|
336 | 304 | #if PY_VERSION_HEX >= 0x03050000 && PY_VERSION_HEX < 0x03050200 |
337 | 305 | extern "C" { |
@@ -365,31 +333,15 @@ PyAPI_DATA(_Py_atomic_address) _PyThreadState_Current; |
365 | 333 | } \ |
366 | 334 | } |
367 | 335 |
|
368 | | -#if PY_VERSION_HEX >= 0x03030000 |
369 | | - |
370 | | -# define PYBIND11_CATCH_INIT_EXCEPTIONS \ |
371 | | - catch (pybind11::error_already_set & e) { \ |
372 | | - pybind11::raise_from(e, PyExc_ImportError, "initialization failed"); \ |
373 | | - return nullptr; \ |
374 | | - } \ |
375 | | - catch (const std::exception &e) { \ |
376 | | - PyErr_SetString(PyExc_ImportError, e.what()); \ |
377 | | - return nullptr; \ |
378 | | - } |
379 | | - |
380 | | -#else |
381 | | - |
382 | | -# define PYBIND11_CATCH_INIT_EXCEPTIONS \ |
383 | | - catch (pybind11::error_already_set & e) { \ |
384 | | - PyErr_SetString(PyExc_ImportError, e.what()); \ |
385 | | - return nullptr; \ |
386 | | - } \ |
387 | | - catch (const std::exception &e) { \ |
388 | | - PyErr_SetString(PyExc_ImportError, e.what()); \ |
389 | | - return nullptr; \ |
390 | | - } |
391 | | - |
392 | | -#endif |
| 336 | +#define PYBIND11_CATCH_INIT_EXCEPTIONS \ |
| 337 | + catch (pybind11::error_already_set & e) { \ |
| 338 | + pybind11::raise_from(e, PyExc_ImportError, "initialization failed"); \ |
| 339 | + return nullptr; \ |
| 340 | + } \ |
| 341 | + catch (const std::exception &e) { \ |
| 342 | + PyErr_SetString(PyExc_ImportError, e.what()); \ |
| 343 | + return nullptr; \ |
| 344 | + } |
393 | 345 |
|
394 | 346 | /** \rst |
395 | 347 | ***Deprecated in favor of PYBIND11_MODULE*** |
|
0 commit comments