Skip to content

Latest commit

 

History

History
83 lines (67 loc) · 3.38 KB

defs.rst

File metadata and controls

83 lines (67 loc) · 3.38 KB

Definitions in py3c

This table summarizes the various macros py3c defines, or mentions in the Porting Guide.

Macro py2 py3
IS_PY3 → 0 → 1
PyStr* PyString* PyUnicode*
PyBytes* PyString*
PyUnicode*
PyString* error
PyStr_AsUTF8AndSize see below
PyInt* PyLong*
PyLong*
PyFloat_FromString see below
PyModuleDef see below
PyModuleDef_HEAD_INIT → 0
PyModule_Create see below
MODULE_INIT_FUNC see below see below
Rich comparisons
Py_RETURN_RICHCOMPARE = =
Py_RETURN_NOTIMPLEMENTED = =
Py_UNREACHABLE = =
PY3C_RICHCMP see below see below
Py_TYPE
Py_REFCNT
Py_SIZE
PyVarObject_HEAD_INIT
PyCapsule* see below
Py_TPFLAGS* see below
PyMem_Raw* = =
Py_UNUSED = =

Legend:

✔ – provided by Python
→ – defined in py3c as a simple alias for
= – provided by at least Python 3.7; py3c backports it to Python versions that don't define it

The following non-trivial macros are defined:

:cPyStr_AsUTF8AndSize

Python 2: defined in terms of PyString_Size and PyString_AsString. Differences from Python 3:

  • no encoding (string is assumed to be UTF-8-encoded)
  • size pointer must not be NULL
  • size may be stored even if an error occurs
:cPyFloat_FromSting
Python 2: Only takes one argument, as in Python 3.
:cPyModuleDef
Python 2: contains m_name, m_doc, m_size, m_methods fields from Python 3, and m_base to accomodate PyModuleDef_HEAD_INIT.
:cPyModule_Create
Python 2: calls Py_InitModule3; semantics same as in Python 3
:cMODULE_INIT_FUNC <MODULE_INIT_FUNC>(<mod>)
Python 3: declares PyInit<mod> and provides function header for it
Python 2: declares & defines init<mod>; declares a static PyInit<mod> and provides function header for it
:cPY3C_RICHCMP
Convenience macro for comparisons, same in both versions.
Deprecated; use :cPy_RETURN_RICHCOMPARE instead.
PyCapsule_* <capsulethunk>
Capsules are included in Python 2.7 and 3.1+.
For 2.6, see the chapter capsulethunk.
Py_TPFLAGS_* <tpflags>

Type flags that were removed in Python 3 are defined to 0 in <py3c/tpflags.h>. Read the documentation before including the file.