Skip to content

Commit f36416b

Browse files
alexmalyshevfacebook-github-bot
authored andcommitted
Add cinderx/python.h, handle atomic symbol collisions
Summary: Adding a new header to wrap Python.h and to force the right order between atomic and stdatomic.h. This is only really an issue with 3.12 and later. 3.10.cinder seems fine, in fact it gets upset if we include atomic headers before internal/pycore_runtime.h so we have to avoid that. All usage of Python.h should be replaced with cinderx/python.h now. There's an exception carved out for cinderx/PythonBin to keep it simple. Reviewed By: DinoV, mpage Differential Revision: D78585773 fbshipit-source-id: 1d10410c43e1437413cee8c8692d9c410c34f5f6
1 parent f9b9d99 commit f36416b

137 files changed

Lines changed: 178 additions & 261 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.clang-format

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,13 @@ DisableFormat: false
4646
ForEachMacros: [ FOR_EACH, FOR_EACH_ENUMERATE, FOR_EACH_KV, FOR_EACH_R, FOR_EACH_RANGE, ]
4747
IncludeBlocks: Regroup
4848
IncludeCategories:
49-
# Want to make sure that Python.h is included before any internal/ headers.
50-
# Plus it is helpful to have it high up to make PY_VERSION_HEX available early.
49+
# Want to make sure that Python.h and cinderx/python.h are included before
50+
# any internal/ headers. We want it high up to make PY_VERSION_HEX
51+
# available early.
5152
- Regex: '^<Python.h>$'
5253
Priority: 1
54+
- Regex: '^"cinderx/python.h"$'
55+
Priority: 1
5356

5457
# Next come the other CPython headers. This assumes that anything that looks
5558
# like "foo.h" is a CPython top-level header. cinder/ headers are only found

CachedProperties/cached_properties.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22

33
#include "cinderx/CachedProperties/cached_properties.h"
44

5-
#include "structmember.h" // PyMemberDef
6-
75
#include "cinderx/Common/py-portability.h"
86
#include "cinderx/Common/string.h"
97
#include "cinderx/UpstreamBorrow/borrowed.h"

CachedProperties/cached_properties.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
#ifndef Py_CACHED_PROPERTIES_H
44
#define Py_CACHED_PROPERTIES_H
55

6-
#include <Python.h>
6+
#include "cinderx/python.h"
77

88
/* fb t46346203 */
99
typedef struct {

Common/audit.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
#pragma once
44

5-
#include <Python.h>
5+
#include "cinderx/python.h"
66

77
#include <stdbool.h>
88

Common/code.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
#pragma once
44

5-
#include <Python.h>
5+
#include "cinderx/python.h"
66

77
#if PY_VERSION_HEX >= 0x030D0000
88
#include "internal/pycore_code.h"

Common/dict.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
#pragma once
44

5-
#include <Python.h>
5+
#include "cinderx/python.h"
66

77
#include <stdbool.h>
88

Common/extra-py-flags.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
#pragma once
88

9-
#include <Python.h>
9+
#include "cinderx/python.h"
1010

1111
// Additional PyCodeObject flags (see Include/code.h)
1212
#define CI_CO_STATICALLY_COMPILED 0x4000000

Common/func.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@
22

33
#pragma once
44

5-
#include <Python.h>
6-
7-
#include "structmember.h"
5+
#include "cinderx/python.h"
86

97
#include <assert.h>
108

Common/import.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/* Copyright (c) Meta Platforms, Inc. and affiliates. */
22
#pragma once
33

4-
#include <Python.h>
4+
#include "cinderx/python.h"
55

66
#ifdef __cplusplus
77
extern "C" {

Common/log.cpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,6 @@
44

55
#include "cinderx/Jit/threaded_compile.h"
66

7-
#if PY_VERSION_HEX < 0x030C0000
8-
#include "internal/pycore_pystate.h"
9-
#endif
10-
117
namespace jit {
128

139
int g_debug = 0;
@@ -26,7 +22,7 @@ FILE* g_log_file = stderr;
2622

2723
void printPythonException() {
2824
#if PY_VERSION_HEX < 0x030C0000
29-
PyThreadState* tstate = _PyThreadState_GET();
25+
PyThreadState* tstate = PyThreadState_Get();
3026
if (tstate != nullptr && tstate->curexc_type != nullptr) {
3127
PyErr_Display(
3228
tstate->curexc_type, tstate->curexc_value, tstate->curexc_traceback);

0 commit comments

Comments
 (0)