Skip to content

Commit

Permalink
fix missing to exit critical section
Browse files Browse the repository at this point in the history
  • Loading branch information
eendebakpt committed Jun 4, 2024
1 parent daeec46 commit d54baf2
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
4 changes: 4 additions & 0 deletions Include/internal/pycore_critical_section.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,9 @@ extern "C" {
_PyCriticalSection_End(&_cs); \
}

# define Py_EXIT_CRITICAL_SECTION() \
_PyCriticalSection_End(&_cs);

# define Py_BEGIN_CRITICAL_SECTION2(a, b) \
{ \
_PyCriticalSection2 _cs2; \
Expand Down Expand Up @@ -160,6 +163,7 @@ extern "C" {
# define Py_BEGIN_CRITICAL_SECTION_MUT(mut)
# define Py_BEGIN_CRITICAL_SECTION(op)
# define Py_END_CRITICAL_SECTION()
# define Py_EXIT_CRITICAL_SECTION()
# define Py_BEGIN_CRITICAL_SECTION2(a, b)
# define Py_END_CRITICAL_SECTION2()
# define Py_BEGIN_CRITICAL_SECTION_SEQUENCE_FAST(original)
Expand Down
4 changes: 3 additions & 1 deletion Lib/test/test_json/test_dump.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,13 @@ def test_dump(self):
def test_dumps(self):
self.assertEqual(self.dumps({}), '{}')

def test_dump_skipkeys(self):
def test_dump_skipkeys_invalid(self):
v = {b'invalid_key': False, 'valid_key': True}
with self.assertRaises(TypeError):
self.json.dumps(v)

def test_dump_skipkeys(self):
v = {b'invalid_key': False, 'valid_key': True}
s = self.json.dumps(v, skipkeys=True)
o = self.json.loads(s)
self.assertIn('valid_key', o)
Expand Down
4 changes: 3 additions & 1 deletion Modules/_json.c
Original file line number Diff line number Diff line change
Expand Up @@ -1620,8 +1620,10 @@ encoder_listencode_dict(PyEncoderObject *s, _PyUnicodeWriter *writer,
while (PyDict_Next(dct, &pos, &key, &value)) {
if (encoder_encode_key_value(s, writer, &first, key, value,
new_newline_indent,
current_item_separator) < 0)
current_item_separator) < 0) {
Py_EXIT_CRITICAL_SECTION();
goto bail;
}
}
Py_END_CRITICAL_SECTION();
}
Expand Down

0 comments on commit d54baf2

Please sign in to comment.