Loading...
Searching...
No Matches
py3Compat.h
Go to the documentation of this file.
1
//
2
// Copyright 2020 Pixar
3
//
4
// Licensed under the terms set forth in the LICENSE.txt file available at
5
// https://openusd.org/license.
6
//
7
#ifndef PXR_BASE_TF_PY_3_COMPAT_H
8
#define PXR_BASE_TF_PY_3_COMPAT_H
9
12
13
#include "
pxr/pxr.h
"
14
15
#include "
pxr/base/tf/pySafePython.h
"
16
17
PXR_NAMESPACE_OPEN_SCOPE
18
19
// Python 3 migrating helpers:
20
#if PY_MAJOR_VERSION >= 3
21
22
// These flags are needed in python 2 only, stub them out in python 3.
23
// In python 3 this behavior is the default. See PEP-3118
24
#define TfPy_TPFLAGS_HAVE_NEWBUFFER 0
25
#define TfPy_TPFLAGS_HAVE_GETCHARBUFFER 0
26
27
#define TfPyBytes_Check PyBytes_Check
28
#define TfPyString_Check(a) (PyBytes_Check(a) || PyUnicode_Check(a))
29
#define TfPyString_AsString PyUnicode_AsUTF8
30
31
// PyInt -> PyLong remapping
32
#define TfPyInt_Check PyLong_Check
33
// Note: Slightly different semantics, the macro does not do any error checking
34
#define TfPyInt_AS_LONG PyLong_AsLong
35
36
// Method and module names that are changed in python 3
37
#define TfPyIteratorNextMethodName "__next__"
38
#define TfPyClassMethodFuncName "__func__"
39
#define TfPyBoolBuiltinFuncName "__bool__"
40
#define TfPyBuiltinModuleName "builtins"
41
42
#else
// Python 2
43
44
#define TfPy_TPFLAGS_HAVE_NEWBUFFER Py_TPFLAGS_HAVE_NEWBUFFER
45
#define TfPy_TPFLAGS_HAVE_GETCHARBUFFER Py_TPFLAGS_HAVE_GETCHARBUFFER
46
47
#define TfPyBytes_Check PyString_Check
48
#define TfPyString_Check PyString_Check
49
#define TfPyString_AsString PyString_AsString
50
51
#define TfPyInt_Check PyInt_Check
52
#define TfPyInt_AS_LONG PyInt_AS_LONG
53
54
#define TfPyIteratorNextMethodName "next"
55
#define TfPyClassMethodFuncName "im_func"
56
#define TfPyBoolBuiltinFuncName "__nonzero__"
57
#define TfPyBuiltinModuleName "__builtin__"
58
59
#endif
60
61
PXR_NAMESPACE_CLOSE_SCOPE
62
63
#endif
// PXR_BASE_TF_PY_3_COMPAT_H
pxr.h
pySafePython.h
Intended to replace a direct include of Python.h, which causes several build problems with certain co...
pxr
base
tf
py3Compat.h
© Copyright 2025, Pixar Animation Studios. |
Terms of Use
| Generated on Thu Oct 23 2025 15:48:42 by
1.9.6