summaryrefslogtreecommitdiffstats
path: root/Modules/_json.c
Commit message (Collapse)AuthorAgeFilesLines
* Use static inline function Py_EnterRecursiveCall() (#91988)Victor Stinner2022-05-041-12/+13
| | | | | | | | | | | | | | | | Currently, calling Py_EnterRecursiveCall() and Py_LeaveRecursiveCall() may use a function call or a static inline function call, depending if the internal pycore_ceval.h header file is included or not. Use a different name for the static inline function to ensure that the static inline function is always used in Python internals for best performance. Similar approach than PyThreadState_GET() (function call) and _PyThreadState_GET() (static inline function). * Rename _Py_EnterRecursiveCall() to _Py_EnterRecursiveCallTstate() * Rename _Py_LeaveRecursiveCall() to _Py_LeaveRecursiveCallTstate() * pycore_ceval.h: Rename Py_EnterRecursiveCall() to _Py_EnterRecursiveCall() and Py_LeaveRecursiveCall() and _Py_LeaveRecursiveCall()
* bpo-46541: Replace core use of _Py_IDENTIFIER() with statically initialized ↵Eric Snow2022-02-081-0/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | global objects. (gh-30928) We're no longer using _Py_IDENTIFIER() (or _Py_static_string()) in any core CPython code. It is still used in a number of non-builtin stdlib modules. The replacement is: PyUnicodeObject (not pointer) fields under _PyRuntimeState, statically initialized as part of _PyRuntime. A new _Py_GET_GLOBAL_IDENTIFIER() macro facilitates lookup of the fields (along with _Py_GET_GLOBAL_STRING() for non-identifier strings). https://bugs.python.org/issue46541#msg411799 explains the rationale for this change. The core of the change is in: * (new) Include/internal/pycore_global_strings.h - the declarations for the global strings, along with the macros * Include/internal/pycore_runtime_init.h - added the static initializers for the global strings * Include/internal/pycore_global_objects.h - where the struct in pycore_global_strings.h is hooked into _PyRuntimeState * Tools/scripts/generate_global_objects.py - added generation of the global string declarations and static initializers I've also added a --check flag to generate_global_objects.py (along with make check-global-objects) to check for unused global strings. That check is added to the PR CI config. The remainder of this change updates the core code to use _Py_GET_GLOBAL_IDENTIFIER() instead of _Py_IDENTIFIER() and the related _Py*Id functions (likewise for _Py_GET_GLOBAL_STRING() instead of _Py_static_string()). This includes adding a few functions where there wasn't already an alternative to _Py*Id(), replacing the _Py_Identifier * parameter with PyObject *. The following are not changed (yet): * stop using _Py_IDENTIFIER() in the stdlib modules * (maybe) get rid of _Py_IDENTIFIER(), etc. entirely -- this may not be doable as at least one package on PyPI using this (private) API * (maybe) intern the strings during runtime init https://bugs.python.org/issue46541
* bpo-43974: Move Py_BUILD_CORE_MODULE into module code (GH-29157)Christian Heimes2021-10-221-2/+2
| | | | | | | | | | | | | | setup.py no longer defines Py_BUILD_CORE_MODULE. Instead every module defines the macro before #include "Python.h" unless Py_BUILD_CORE_BUILTIN is already defined. Py_BUILD_CORE_BUILTIN is defined for every module that is built by Modules/Setup. The PR also simplifies Modules/Setup. Makefile and makesetup already define Py_BUILD_CORE_BUILTIN and include Modules/internal for us. Signed-off-by: Christian Heimes <christian@python.org>
* bpo-44854: Remove trailing whitespaces (GH-27689)Serhiy Storchaka2021-08-091-1/+1
|
* bpo-42834: Fix _json internal caches for subinterpreters (GH-24121)Ken Jin2021-02-011-38/+39
| | | | Make internal caches of the _json extension module compatible with subinterpreters.
* bpo-40217: Ensure Py_VISIT(Py_TYPE(self)) is always called for ↵Pablo Galindo2020-05-271-0/+2
| | | | | | | | | PyType_FromSpec types (reverts GH-19414) (GH-20264) Heap types now always visit the type in tp_traverse. See added docs for details. This reverts commit 0169d3003be3d072751dd14a5c84748ab63a249f. Automerge-Triggered-By: @encukou
* bpo-40268: Remove unused structmember.h includes (GH-19530)Victor Stinner2020-04-151-1/+1
| | | | | | If only offsetof() is needed: include stddef.h instead. When structmember.h is used, add a comment explaining that PyMemberDef is used.
* bpo-39943: Add the const qualifier to pointers on non-mutable PyUnicode ↵Serhiy Storchaka2020-04-111-7/+7
| | | | data. (GH-19345)
* bpo-40077: Remove redundant cast in json module (GH-19438)Hai Shi2020-04-091-2/+2
|
* bpo-40077: Fix potential refleaks of _json: traverse memo (GH-19344)Hai Shi2020-04-041-0/+1
| | | | Fix possible refleaks in _json module, memo of PyScannerObject should be traversed.
* bpo-40077: Convert _json module to use PyType_FromSpec() (GH-19177)Dong-hee Na2020-03-271-157/+130
| | | | | | | Replace statically allocated types with heap allocated types: use PyType_FromSpec(). Add a module state to store the Scanner and Encoder types. Add traverse, clear and free functions to the module.
* bpo-39573: Clean up modules and headers to use Py_IS_TYPE() function (GH-18521)Dong-hee Na2020-02-171-2/+2
|
* bpo-39245: Switch to public API for Vectorcall (GH-18460)Petr Viktorin2020-02-111-6/+6
| | | | | | | | | | | | | | | | | | | | | | | | | | | | The bulk of this patch was generated automatically with: for name in \ PyObject_Vectorcall \ Py_TPFLAGS_HAVE_VECTORCALL \ PyObject_VectorcallMethod \ PyVectorcall_Function \ PyObject_CallOneArg \ PyObject_CallMethodNoArgs \ PyObject_CallMethodOneArg \ ; do echo $name git grep -lwz _$name | xargs -0 sed -i "s/\b_$name\b/$name/g" done old=_PyObject_FastCallDict new=PyObject_VectorcallDict git grep -lwz $old | xargs -0 sed -i "s/\b$old\b/$new/g" and then cleaned up: - Revert changes to in docs & news - Revert changes to backcompat defines in headers - Nudge misaligned comments
* bpo-39573: Use Py_TYPE() macro in Modules directory (GH-18393)Victor Stinner2020-02-071-1/+1
| | | Replace direct access to PyObject.ob_type with Py_TYPE().
* bpo-1635741: Port _json extension module to multiphase initialization (PEP ↵Hai Shi2020-01-151-23/+30
| | | | 489) (GH-17835)
* _json.c: use Py_UNUSED() macro (GH-17053)Victor Stinner2019-11-051-10/+4
| | | Remove UNUSED macro: use Py_UNUSED() macro instead.
* bpo-37587: json: Use _PyUnicodeWriter when scanning string. (GH-15591)Inada Naoki2019-10-171-57/+23
|
* bpo-37587: optimize json.loads (GH-15134)Inada Naoki2019-08-081-20/+19
| | | | | | | Use a tighter scope temporary variable to help register allocation. 1% speedup for large string. Use PyDict_SetItemDefault() for memoizing keys. At most 4% speedup when the cache hit ratio is low.
* bpo-37587: Make json.loads faster for long strings (GH-14752)Marco Paolini2019-07-301-1/+1
| | | | | | | | | | When scanning the string, most characters are valid, so checking for invalid characters first means never needing to check the value of strict on valid strings, and only needing to check it on invalid characters when doing non-strict parsing of invalid strings. This provides a measurable reduction in per-character processing time (~11% in the pre-merge patch testing).
* bpo-37483: add _PyObject_CallOneArg() function (#14558)Jeroen Demeyer2019-07-041-6/+6
|
* bpo-36974: tp_print -> tp_vectorcall_offset and tp_reserved -> tp_as_async ↵Jeroen Demeyer2019-05-311-4/+4
| | | | | | | | | (GH-13464) Automatically replace tp_print -> tp_vectorcall_offset tp_compare -> tp_as_async tp_reserved -> tp_as_async
* bpo-36793: Remove unneeded __str__ definitions. (GH-13081)Serhiy Storchaka2019-05-061-2/+2
| | | | Classes that define __str__ the same as __repr__ can just inherit it from object.
* bpo-36635: Change pyport.h for Py_BUILD_CORE_MODULE define (GH-12853)Victor Stinner2019-04-171-5/+8
| | | | | | | | | | | | | | | | | | | | Change PyAPI_FUNC(type), PyAPI_DATA(type) and PyMODINIT_FUNC macros of pyport.h when Py_BUILD_CORE_MODULE is defined. The Py_BUILD_CORE_MODULE define must be now be used to build a C extension as a dynamic library accessing Python internals: export the PyInit_xxx() function in DLL exports on Windows. Changes: * Py_BUILD_CORE_BUILTIN and Py_BUILD_CORE_MODULE now imply Py_BUILD_CORE directy in pyport.h. * ceval.c compilation now fails with an error if Py_BUILD_CORE is not defined, just to ensure that Python is build with the correct defines. * setup.py now compiles _pickle.c with Py_BUILD_CORE_MODULE define. * setup.py compiles _json.c with Py_BUILD_CORE_MODULE define, rather than Py_BUILD_CORE_BUILTIN define * PCbuild/pythoncore.vcxproj: Add Py_BUILD_CORE_BUILTIN define.
* bpo-35459: Use PyDict_GetItemWithError() instead of PyDict_GetItem(). (GH-11112)Serhiy Storchaka2019-02-251-1/+4
|
* bpo-35081: Move accu.h to Include/internal/pycore_accu.h (GH-10271)Victor Stinner2018-11-011-1/+1
| | | | | | | The accu.h header is no longer part of the Python C API: it has been moved to the "internal" headers which are restricted to Python itself. Replace #include "accu.h" with #include "pycore_accu.h".
* bpo-34649: Add missing NULL checks to _encoded_const() (GH-9225)Alexey Izbyshev2018-09-121-3/+3
| | | Reported by Svace static analyzer.
* bpo-24641: Improved error message for JSON unserializible keys. (#4364)Serhiy Storchaka2017-11-251-2/+3
| | | | | Also updated an example for default() in the module docstring. Removed quotes around type name in other error messages.
* bpo-31505: Fix an assertion failure in json, in case _json.make_encoder() ↵Oren Milman2017-09-241-3/+13
| | | | received a bad encoder() argument. (#3643)
* bpo-30860: Move windows.h include out of internal/*.h. (#3458)Eric Snow2017-09-121-1/+1
| | | PR #3397 introduced a large number of warnings to the Windows build. This patch fixes them.
* bpo-30860: Consolidate stateful runtime globals. (#3397)Eric Snow2017-09-081-0/+7
| | | | | | | * group the (stateful) runtime globals into various topical structs * consolidate the topical structs under a single top-level _PyRuntimeState struct * add a check-c-globals.py script that helps identify runtime globals Other globals are excluded (see globals.txt and check-c-globals.py).
* bpo-31095: fix potential crash during GC (GH-2974)INADA Naoki2017-08-241-2/+4
|
* bpo-30936: Fix a reference leak in json when fail to sort keys. (#2712)Serhiy Storchaka2017-07-161-1/+3
|
* bpo-30911: Fix a crash in json on platforms with unsigned char (#2684)Segev Finer2017-07-131-1/+1
| | | when pass bad strict argument.
* bpo-30248: Convert boolean arguments only once in _json. (#1423)Serhiy Storchaka2017-05-281-40/+24
| | | | | Rather than saving the Python object and calling PyObject_IsTrue() every time when the boolean argument is used, call it only once and save C boolean value.
* bpo-30243: Fixed the possibility of a crash in _json. (#1420)Serhiy Storchaka2017-05-051-66/+20
| | | | | | It was possible to get a core dump by using uninitialized _json objects. Now __new__ methods create initialized objects. __init__ methods are removed.
* bpo-29865: Use PyXXX_GET_SIZE macros rather than Py_SIZE for concrete types. ↵Serhiy Storchaka2017-03-211-1/+1
| | | | (#748)
* Issue #28999: Use Py_RETURN_NONE, Py_RETURN_TRUE and Py_RETURN_FALSE whereverSerhiy Storchaka2017-01-231-6/+3
| | | | possible but Coccinelle couldn't find opportunity.
* Py_SIZE() was misused for dict.Serhiy Storchaka2017-01-131-1/+1
|\
| * Py_SIZE() was misused for dict.Serhiy Storchaka2017-01-131-1/+1
| |\
| | * Py_SIZE() was misused for dict.Serhiy Storchaka2017-01-131-1/+1
| | |
* | | Fixed possible reference leaks in the _json module.Serhiy Storchaka2017-01-031-4/+9
|\ \ \ | |/ /
| * | Fixed possible reference leaks in the _json module.Serhiy Storchaka2017-01-031-4/+9
| |\ \ | | |/
| | * Fixed possible reference leaks in the _json module.Serhiy Storchaka2017-01-031-4/+9
| | |
* | | Don't parenthesis in _PyObject_CallMethodId() formatVictor Stinner2016-12-081-1/+1
| | | | | | | | | | | | | | | Issue #28915: Without parenthesis, _PyObject_CallMethodId() avoids the creation a temporary tuple, and so is more efficient.
* | | Backed out changeset b9c9691c72c5Victor Stinner2016-12-041-6/+6
| | | | | | | | | | | | | | | | | | Issue #28858: The change b9c9691c72c5 introduced a regression. It seems like _PyObject_CallArg1() uses more stack memory than PyObject_CallFunctionObjArgs().
* | | Replace PyObject_CallFunctionObjArgs() with fastcallVictor Stinner2016-12-011-6/+6
|/ / | | | | | | | | | | | | | | | | | | | | | | | | | | * PyObject_CallFunctionObjArgs(func, NULL) => _PyObject_CallNoArg(func) * PyObject_CallFunctionObjArgs(func, arg, NULL) => _PyObject_CallArg1(func, arg) PyObject_CallFunctionObjArgs() allocates 40 bytes on the C stack and requires extra work to "parse" C arguments to build a C array of PyObject*. _PyObject_CallNoArg() and _PyObject_CallArg1() are simpler and don't allocate memory on the C stack. This change is part of the fastcall project. The change on listsort() is related to the issue #23507.
* | Issue #26719: More efficient formatting of ints and floats in json.Serhiy Storchaka2016-04-101-52/+4
|\ \ | |/
| * Issue #26719: More efficient formatting of ints and floats in json.Serhiy Storchaka2016-04-101-52/+4
| |
* | Issue #25923: Added more const qualifiers to signatures of static and ↵Serhiy Storchaka2015-12-251-2/+2
|/ | | | private functions.
* Issue #24683: Fixed crashes in _json functions called with arguments ofSerhiy Storchaka2015-07-261-2/+10
|\ | | | | | | inappropriate type.