8000 gh-103092: Isolate `_decimal` by CharlieZhao95 · Pull Request #103381 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

gh-103092: Isolate _decimal #103381

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 30 commits into from
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 8000
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 external C-API functions to state
  • Loading branch information
CharlieZhao95 committed Apr 3, 2023
commit bc8df8fd726a8aaacd90d41e476d78edb7c4c13b
44 changes: 22 additions & 22 deletions Modules/_decimal/_decimal.c
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,14 @@ typedef struct {
PyObject *Rational;

PyObject *SignalTuple;

/* External C-API functions */
binaryfunc _py_long_multiply;
binaryfunc _py_long_floor_divide;
ternaryfunc _py_long_power;
unaryfunc _py_float_abs;
PyCFunction _py_long_bit_length;
PyCFunction _py_float_as_integer_ratio;
} decimal_state;

static decimal_state global_state;
Expand Down Expand Up @@ -2313,14 +2321,6 @@ PyDecType_FromLongExact(PyTypeObject *type, PyObject *v,
return dec;
}

/* External C-API functions */
static binaryfunc _py_long_multiply;
static binaryfunc _py_long_floor_divide;
static ternaryfunc _py_long_power;
static unaryfunc _py_float_abs;
static PyCFunction _py_long_bit_length;
static PyCFunction _py_float_as_integer_ratio;

/* Return a PyDecObject or a subtype from a PyFloatObject.
Conversion is exact. */
static PyObject *
Expand Down Expand Up @@ -2374,21 +2374,21 @@ PyDecType_FromFloatExact(PyTypeObject *type, PyObject *v,
}

/* absolute value of the float */
tmp = _py_float_abs(v);
tmp = state->_py_float_abs(v);
if (tmp == NULL) {
return NULL;
}

/* float as integer ratio: numerator/denominator */
n_d = _py_float_as_integer_ratio(tmp, NULL);
n_d = state->_py_float_as_integer_ratio(tmp, NULL);
Py_DECREF(tmp);
if (n_d == NULL) {
return NULL;
}
n = PyTuple_GET_ITEM(n_d, 0);
d = PyTuple_GET_ITEM(n_d, 1);

tmp = _py_long_bit_length(d, NULL);
tmp = state->_py_long_bit_length(d, NULL);
if (tmp == NULL) {
Py_DECREF(n_d);
return NULL;
Expand Down Expand Up @@ -3694,14 +3694,14 @@ dec_as_integer_ratio(PyObject *self, PyObject *args UNUSED)
goto error;
}

Py_SETREF(exponent, _py_long_power(tmp, exponent, Py_None));
Py_SETREF(exponent, state->_py_long_power(tmp, exponent, Py_None));
Py_DECREF(tmp);
if (exponent == NULL) {
goto error;
}

if (exp >= 0) {
Py_SETREF(numerator, _py_long_multiply(numerator, exponent));
Py_SETREF(numerator, state->_py_long_multiply(numerator, exponent));
if (numerator == NULL) {
goto error;
}
Expand All @@ -3717,8 +3717,8 @@ dec_as_integer_ratio(PyObject *self, PyObject *args UNUSED)
if (tmp == NULL) {
goto error;
}
Py_SETREF(numerator, _py_long_floor_divide(numerator, tmp));
Py_SETREF(denominator, _py_long_floor_divide(denominator, tmp));
Py_SETREF(numerator, state->_py_long_floor_divide(numerator, tmp));
Py_SETREF(denominator, state->_py_long_floor_divide(denominator, tmp));
Py_DECREF(tmp);
if (numerator == NULL || denominator == NULL) {
goto error;
Expand Down Expand Up @@ -5865,13 +5865,13 @@ PyInit__decimal(void)
decimal_state *state = GLOBAL_STATE();

/* Init external C-API functions */
_py_long_multiply = PyLong_Type.tp_as_number->nb_multiply;
_py_long_floor_divide = PyLong_Type.tp_as_number->nb_floor_divide;
_py_long_power = PyLong_Type.tp_as_number->nb_power;
_py_float_abs = PyFloat_Type.tp_as_number->nb_absolute;
ASSIGN_PTR(_py_float_as_integer_ratio, cfunc_noargs(&PyFloat_Type,
"as_integer_ratio"));
ASSIGN_PTR(_py_long_bit_length, cfunc_noargs(&PyLong_Type, "bit_length"));
state->_py_long_multiply = PyLong_Type.tp_as_number->nb_multiply;
state->_py_long_floor_divide = PyLong_Type.tp_as_number->nb_floor_divide;
state->_py_long_power = PyLong_Type.tp_as_number->nb_power;
state->_py_float_abs = PyFloat_Type.tp_as_number->nb_absolute;
ASSIGN_PTR(state->_py_float_as_integer_ratio, cfunc_noargs(&PyFloat_Type,
"as_integer_ratio"));
ASSIGN_PTR(state->_py_long_bit_length, cfunc_noargs(&PyLong_Type, "bit_length"));


/* Init types */
Expand Down
6 changes: 0 additions & 6 deletions Tools/c-analyzer/cpython/globals-to-fix.tsv
Original file line number Diff line number Diff line change
Expand Up @@ -473,12 +473,6 @@ Modules/_cursesmodule.c - initialised -
Modules/_cursesmodule.c - initialised_setupterm -
Modules/_cursesmodule.c - initialisedcolors -
Modules/_cursesmodule.c - screen_encoding -
Modules/_decimal/_decimal.c - _py_long_multiply -
Modules/_decimal/_decimal.c - _py_long_floor_divide -
Modules/_decimal/_decimal.c - _py_long_power -
Modules/_decimal/_decimal.c - _py_float_abs -
Modules/_decimal/_decimal.c - _py_long_bit_length -
Modules/_decimal/_decimal.c - _py_float_as_integer_ratio -
Modules/_elementtree.c - expat_capi -
Modules/cjkcodecs/_codecs_hk.c - big5_encmap -
Modules/cjkcodecs/_codecs_hk.c - big5_decmap -
Expand Down
0