Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
da0e917
Make the _json module thread safe
eendebakpt May 22, 2024
3797dfa
Update Modules/_json.c
eendebakpt May 22, 2024
366654c
handle goto and return statements
eendebakpt May 24, 2024
5b72cdf
Apply suggestions from code review
eendebakpt May 25, 2024
c4c24c3
Update Include/internal/pycore_critical_section.h
eendebakpt May 25, 2024
370191b
rename macro
eendebakpt May 31, 2024
93c4466
Merge branch 'main' into json_ft
eendebakpt May 31, 2024
eafd3c1
fix typo
eendebakpt May 31, 2024
daeec46
Merge branch 'json_ft' of github.com:eendebakpt/cpython into json_ft
eendebakpt May 31, 2024
d54baf2
fix missing to exit critical section
eendebakpt Jun 4, 2024
e5fa305
revert changes to tests
eendebakpt Jun 4, 2024
d4ddf5d
📜🤖 Added by blurb_it.
blurb-it[bot] Jun 4, 2024
67d942f
Merge branch 'main' into json_ft
eendebakpt Jun 4, 2024
4ffc1b2
Merge branch 'main' into json_ft
eendebakpt Aug 14, 2024
384ca59
sync with main
eendebakpt Aug 14, 2024
64e20aa
sync with main
eendebakpt Aug 14, 2024
e6ce9c9
update news entry
eendebakpt Aug 14, 2024
34885a0
fix normal build
eendebakpt Aug 14, 2024
2fe760b
Merge branch 'main' into json_ft
eendebakpt Aug 14, 2024
eebccac
add lock around result of PyMapping_Items
eendebakpt Aug 15, 2024
db8947c
add tests
eendebakpt Aug 15, 2024
c19ad14
fix argument of Py_END_CRITICAL_SECTION_SEQUENCE_FAST
eendebakpt Aug 15, 2024
8b12e0f
Merge branch 'main' into json_ft
eendebakpt Feb 10, 2025
78d3595
avoid Py_EXIT_CRITICAL_SECTION_SEQUENCE_FAST
eendebakpt Feb 10, 2025
6e8615f
use barriers in test
eendebakpt Feb 10, 2025
39ebc00
typo
eendebakpt Feb 10, 2025
7c5b185
whitespace
eendebakpt Feb 10, 2025
adf78c7
Merge branch 'main' into json_ft
eendebakpt Jun 24, 2025
acd0ad1
resolve merge conflicts
eendebakpt Jun 24, 2025
41e3dee
Update Misc/NEWS.d/next/Core_and_Builtins/2024-06-04-20-26-21.gh-issu…
eendebakpt Jun 24, 2025
75884cb
cleanup
eendebakpt Jun 24, 2025
0424c58
Merge branch 'json_ft' of github.com:eendebakpt/cpython into json_ft
eendebakpt Jun 24, 2025
9c964f9
Merge branch 'main' into json_ft
eendebakpt Jun 24, 2025
5acc999
Merge branch 'main' into json_ft
eendebakpt Jul 28, 2025
5173373
format
eendebakpt Jul 28, 2025
7d00562
only use items locally in encoder_listencode_dict
eendebakpt Aug 6, 2025
00f4d7f
Merge branch 'main' into json_ft
eendebakpt Aug 14, 2025
b95c07f
use strong references in iteration
eendebakpt Aug 24, 2025
cedc2c3
Merge branch 'main' into json_ft
eendebakpt Aug 24, 2025
0ca453d
replace Py_IncRef with Py_INCREF
eendebakpt Aug 26, 2025
45544f3
Update Modules/_json.c
eendebakpt Aug 27, 2025
dcb088e
Apply suggestion from @kumaraditya303
kumaraditya303 Aug 27, 2025
5f8ad07
add header
kumaraditya303 Aug 27, 2025
61bc8d1
Apply suggestions from code review
eendebakpt Aug 27, 2025
f85b695
review comments
eendebakpt Aug 28, 2025
2c0cd18
use _Py_CRITICAL_SECTION_ASSERT_OBJECT_LOCKED
eendebakpt Aug 28, 2025
c133b71
remove testing code
eendebakpt Aug 29, 2025
7609117
Merge branch 'main' into json_ft
eendebakpt Aug 29, 2025
7656a2a
add incref/decref to fast seq iteration
eendebakpt Aug 30, 2025
1920aed
Merge branch 'json_ft' of github.com:eendebakpt/cpython into json_ft
eendebakpt Aug 30, 2025
d5d65ab
fix
eendebakpt Aug 30, 2025
4a16e18
fix
eendebakpt Aug 30, 2025
00139f3
Update Modules/_json.c
kumaraditya303 Aug 30, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions Include/internal/pycore_critical_section.h
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,12 @@ extern "C" {
} \
}

# define Py_RETURN_CRITICAL_SECTION_SEQUENCE_FAST(value) \
if (_should_lock_cs) { \
_PyCriticalSection_End(&_cs); \
} \
return value;

// Asserts that the mutex is locked. The mutex must be held by the
// top-most critical section otherwise there's the possibility
// that the mutex would be swalled out in some code paths.
Expand Down Expand Up @@ -159,6 +165,7 @@ extern "C" {
# define Py_END_CRITICAL_SECTION2()
# define Py_BEGIN_CRITICAL_SECTION_SEQUENCE_FAST(original)
# define Py_END_CRITICAL_SECTION_SEQUENCE_FAST()
# define Py_RETURN_CRITICAL_SECTION_SEQUENCE_FAST(value)
# define _Py_CRITICAL_SECTION_ASSERT_MUTEX_LOCKED(mutex)
# define _Py_CRITICAL_SECTION_ASSERT_OBJECT_LOCKED(op)
#endif /* !Py_GIL_DISABLED */
Expand Down
14 changes: 8 additions & 6 deletions Modules/_json.c
Original file line number Diff line number Diff line change
Expand Up @@ -1664,13 +1664,15 @@ encoder_listencode_list(PyEncoderObject *s, _PyUnicodeWriter *writer,

ident = NULL;
s_fast = PySequence_Fast(seq, "_iterencode_list needs a sequence");
Py_BEGIN_CRITICAL_SECTION_SEQUENCE_FAST(seq);

if (s_fast == NULL)
return -1;

Py_BEGIN_CRITICAL_SECTION_SEQUENCE_FAST(seq);

if (PySequence_Fast_GET_SIZE(s_fast) == 0) {
Py_DECREF(s_fast);
return _PyUnicodeWriter_WriteASCIIString(writer, "[]", 2);
int r = _PyUnicodeWriter_WriteASCIIString(writer, "[]", 2);
Py_RETURN_CRITICAL_SECTION_SEQUENCE_FAST(r);
}

if (s->markers != Py_None) {
Expand Down Expand Up @@ -1718,13 +1720,11 @@ encoder_listencode_list(PyEncoderObject *s, _PyUnicodeWriter *writer,
if (encoder_listencode_obj(s, writer, obj, new_newline_indent))
goto bail;
}
Py_END_CRITICAL_SECTION_SEQUENCE_FAST();
if (ident != NULL) {
if (PyDict_DelItem(s->markers, ident))
goto bail;
Py_CLEAR(ident);
}

if (s->indent != Py_None) {
Py_CLEAR(new_newline_indent);
Py_CLEAR(separator_indent);
Expand All @@ -1736,14 +1736,16 @@ encoder_listencode_list(PyEncoderObject *s, _PyUnicodeWriter *writer,
if (_PyUnicodeWriter_WriteChar(writer, ']'))
goto bail;
Py_DECREF(s_fast);
return 0;
Py_RETURN_CRITICAL_SECTION_SEQUENCE_FAST(0);

bail:
Py_END_CRITICAL_SECTION_SEQUENCE_FAST();
Py_XDECREF(ident);
Py_DECREF(s_fast);
Py_XDECREF(separator_indent);
Py_XDECREF(new_newline_indent);
return -1;

}

static void
Expand Down