Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
60902dd
Establish global state
erlend-aasland Mar 12, 2023
fa06750
Adapt PyDecContextManager_Type to heap type and add it to state
erlend-aasland Mar 12, 2023
f19c14c
fixup! Adapt PyDecContextManager_Type to heap type and add it to state
erlend-aasland Mar 12, 2023
cde5da9
Adapt PyDecContext_Type to heap type and add it to state
erlend-aasland Mar 12, 2023
90955ab
Adapt PyDecSignalDictMixin_Type to heap type and add it to state
erlend-aasland Mar 12, 2023
ae2ac48
fixup! Adapt PyDecSignalDictMixin_Type to heap type and add it to state
erlend-aasland Mar 12, 2023
eee3ef7
Adapt and add PyDec_Type & PyDecSignalDict_Type
erlend-aasland Mar 14, 2023
f9c3573
Add DecimalTuple to state
erlend-aasland Mar 14, 2023
57316db
fixup! Add DecimalTuple to state
erlend-aasland Mar 14, 2023
30e4128
Add DecimalException to state
erlend-aasland Mar 14, 2023
f92e385
fixup! Add DecimalException to state
erlend-aasland Mar 14, 2023
8b6c0c7
Add `basic_context_template` to state
CharlieZhao95 Mar 30, 2023
2ea6d98
Add `extended_context_template` to state
CharlieZhao95 Mar 30, 2023
7bf48be
Add `default_context_template` to state
CharlieZhao95 Mar 30, 2023
cd41d2c
Add context var to state
CharlieZhao95 Mar 31, 2023
44b0843
fixup! Add default_context_template to state
CharlieZhao95 Mar 31, 2023
db7b988
Add round_map to state
CharlieZhao95 Mar 31, 2023
86170a2
Add `Rational` and `SignalTuple` to state
CharlieZhao95 Mar 31, 2023
bc8df8f
Add external C-API functions to state
CharlieZhao95 Apr 3, 2023
4ff1074
port _decimal module to multi-initialization
CharlieZhao95 Apr 3, 2023
8fba9e8
Move global state to module state
CharlieZhao95 Apr 3, 2023
be7fa2a
Add `signal_map` to state to fix error in `decimal.Context`.
CharlieZhao95 Apr 8, 2023
b130f56
solve warnings and remove redundant code
CharlieZhao95 Apr 11, 2023
39fe618
Merge branch 'main' into isolate-decimal
erlend-aasland Apr 14, 2023
a81da37
remove NDEBUG and static-local variables
CharlieZhao95 Apr 20, 2023
6638ca7
Add a NEWS entry.
CharlieZhao95 Apr 21, 2023
7b05a94
Merge remote-tracking branch 'upstream/main' into isolate-decimal
CharlieZhao95 May 25, 2023
68473a0
Add Py_MOD_PER_INTERPRETER_GIL_SUPPORTED
CharlieZhao95 May 25, 2023
e00dc55
Merge branch 'main' into isolate-decimal
kumaraditya303 May 28, 2023
58f0049
Update Modules/_decimal/_decimal.c
CharlieZhao95 May 28, 2023
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
Prev Previous commit
Next Next commit
Add round_map to state
  • Loading branch information
CharlieZhao95 committed Mar 31, 2023
commit db7b9885093df325b1ad096b56593e3d4456dc5a
27 changes: 15 additions & 12 deletions Modules/_decimal/_decimal.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,12 @@

#include "docstrings.h"

#ifdef EXTRA_FUNCTIONALITY
#define _PY_DEC_ROUND_GUARD MPD_ROUND_GUARD
#else
#define _PY_DEC_ROUND_GUARD (MPD_ROUND_GUARD-1)
#endif

typedef struct {
PyTypeObject *PyDecContextManager_Type;
PyTypeObject *PyDecContext_Type;
Expand Down Expand Up @@ -65,6 +71,8 @@ typedef struct {
/* Basic and extended context templates */
PyObject *basic_context_template;
PyObject *extended_context_template;

PyObject *round_map[_PY_DEC_ROUND_GUARD];
} decimal_state;

static decimal_state global_state;
Expand Down Expand Up @@ -216,13 +224,6 @@ static const char *dec_signal_string[MPD_NUM_FLAGS] = {
"Underflow",
};

#ifdef EXTRA_FUNCTIONALITY
#define _PY_DEC_ROUND_GUARD MPD_ROUND_GUARD
#else
#define _PY_DEC_ROUND_GUARD (MPD_ROUND_GUARD-1)
#endif
static PyObject *round_map[_PY_DEC_ROUND_GUARD];

static const char *invalid_rounding_err =
"valid values for rounding are:\n\
[ROUND_CEILING, ROUND_FLOOR, ROUND_UP, ROUND_DOWN,\n\
Expand Down Expand Up @@ -520,15 +521,16 @@ static int
getround(PyObject *v)
{
int i;
decimal_state *state = GLOBAL_STATE();

if (PyUnicode_Check(v)) {
for (i = 0; i < _PY_DEC_ROUND_GUARD; i++) {
if (v == round_map[i]) {
if (v == state->round_map[i]) {
return i;
}
}
for (i = 0; i < _PY_DEC_ROUND_GUARD; i++) {
if (PyUnicode_Compare(v, round_map[i]) == 0) {
if (PyUnicode_Compare(v, state->round_map[i]) == 0) {
return i;
}
}
Expand Down Expand Up @@ -753,8 +755,9 @@ static PyObject *
context_getround(PyObject *self, void *closure UNUSED)
{
int i = mpd_getround(CTX(self));
decimal_state *state = GLOBAL_STATE();

return Py_NewRef(round_map[i]);
return Py_NewRef(state->round_map[i]);
}

static PyObject *
Expand Down Expand Up @@ -6058,8 +6061,8 @@ PyInit__decimal(void)

/* Init string constants */
for (i = 0; i < _PY_DEC_ROUND_GUARD; i++) {
ASSIGN_PTR(round_map[i], PyUnicode_InternFromString(mpd_round_string[i]));
CHECK_INT(PyModule_AddObject(m, mpd_round_string[i], Py_NewRef(round_map[i])));
ASSIGN_PTR(state->round_map[i], PyUnicode_InternFromString(mpd_round_string[i]));
CHECK_INT(PyModule_AddObject(m, mpd_round_string[i], Py_NewRef(state->round_map[i])));
}

/* Add specification version number */
Expand Down
1 change: 0 additions & 1 deletion Tools/c-analyzer/cpython/globals-to-fix.tsv
Original file line number Diff line number Diff line change
Expand Up @@ -443,7 +443,6 @@ Modules/_datetimemodule.c - us_per_hour -
Modules/_datetimemodule.c - us_per_day -
Modules/_datetimemodule.c - us_per_week -
Modules/_datetimemodule.c - seconds_per_day -
Modules/_decimal/_decimal.c - round_map -
Modules/_decimal/_decimal.c - Rational -
Modules/_decimal/_decimal.c - SignalTuple -
Modules/arraymodule.c array_array___reduce_ex___impl array_reconstructor -
Expand Down