HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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 
10 /// \file tf/py3Compat.h
11 /// Compatibility code for supporting python 2 and 3
12 
13 #include "pxr/pxr.h"
14 
16 
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 
62 
63 #endif // PXR_BASE_TF_PY_3_COMPAT_H
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1425
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:74