Skip to content

Commit d0b03ff

Browse files
committed
+ convert functions
1 parent 257c4fa commit d0b03ff

File tree

7 files changed

+380
-60
lines changed

7 files changed

+380
-60
lines changed

Include/internal/pycore_global_objects_fini_generated.h

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Include/internal/pycore_global_strings.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ struct _Py_global_strings {
5757

5858
struct {
5959
STRUCT_FOR_ID(CANCELLED)
60+
STRUCT_FOR_ID(Emax)
61+
STRUCT_FOR_ID(Emin)
6062
STRUCT_FOR_ID(FINISHED)
6163
STRUCT_FOR_ID(False)
6264
STRUCT_FOR_ID(JSONDecodeError)
@@ -336,10 +338,12 @@ struct _Py_global_strings {
336338
STRUCT_FOR_ID(callback)
337339
STRUCT_FOR_ID(cancel)
338340
STRUCT_FOR_ID(capath)
341+
STRUCT_FOR_ID(capitals)
339342
STRUCT_FOR_ID(category)
340343
STRUCT_FOR_ID(cb_type)
341344
STRUCT_FOR_ID(certfile)
342345
STRUCT_FOR_ID(check_same_thread)
346+
STRUCT_FOR_ID(clamp)
343347
STRUCT_FOR_ID(clear)
344348
STRUCT_FOR_ID(close)
345349
STRUCT_FOR_ID(closed)
@@ -378,6 +382,7 @@ struct _Py_global_strings {
378382
STRUCT_FOR_ID(coro)
379383
STRUCT_FOR_ID(count)
380384
STRUCT_FOR_ID(covariant)
385+
STRUCT_FOR_ID(ctx)
381386
STRUCT_FOR_ID(cwd)
382387
STRUCT_FOR_ID(d_parameter_type)
383388
STRUCT_FOR_ID(data)
@@ -666,6 +671,7 @@ struct _Py_global_strings {
666671
STRUCT_FOR_ID(pos1)
667672
STRUCT_FOR_ID(pos2)
668673
STRUCT_FOR_ID(posix)
674+
STRUCT_FOR_ID(prec)
669675
STRUCT_FOR_ID(print_file_and_line)
670676
STRUCT_FOR_ID(priority)
671677
STRUCT_FOR_ID(progress)
@@ -782,6 +788,7 @@ struct _Py_global_strings {
782788
STRUCT_FOR_ID(traceback)
783789
STRUCT_FOR_ID(trailers)
784790
STRUCT_FOR_ID(translate)
791+
STRUCT_FOR_ID(traps)
785792
STRUCT_FOR_ID(true)
786793
STRUCT_FOR_ID(truncate)
787794
STRUCT_FOR_ID(twice)

Include/internal/pycore_runtime_init_generated.h

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Include/internal/pycore_unicodeobject_generated.h

Lines changed: 28 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Modules/_decimal/_decimal.c

Lines changed: 82 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1566,17 +1566,27 @@ init_extended_context(PyObject *v)
15661566
}
15671567

15681568
/* Factory function for creating IEEE interchange format contexts */
1569+
1570+
/*[clinic input]
1571+
_decimal.Decimal.IEEEContext
1572+
1573+
self as module: self
1574+
bits: Py_ssize_t
1575+
/
1576+
1577+
Return a context object initialized as one of the IEEE interchange formats.
1578+
1579+
The argument must be a multiple of 32 and less than
1580+
IEEE_CONTEXT_MAX_BITS.
1581+
[clinic start generated code]*/
1582+
15691583
static PyObject *
1570-
ieee_context(PyObject *module, PyObject *v)
1584+
_decimal_Decimal_IEEEContext_impl(PyObject *module, Py_ssize_t bits)
1585+
/*[clinic end generated code: output=042b8664fd2830f7 input=dc5578f331d0aaa9]*/
15711586
{
15721587
PyObject *context;
1573-
mpd_ssize_t bits;
15741588
mpd_context_t ctx;
15751589

1576-
bits = PyLong_AsSsize_t(v);
1577-
if (bits == -1 && PyErr_Occurred()) {
1578-
return NULL;
1579-
}
15801590
if (bits <= 0 || bits > INT_MAX) {
15811591
goto error;
15821592
}
@@ -1774,8 +1784,9 @@ current_context(decimal_state *modstate)
17741784
} while (0)
17751785

17761786
/* Return a new reference to the current context */
1787+
17771788
static PyObject *
1778-
PyDec_GetCurrentContext(PyObject *self, PyObject *Py_UNUSED(dummy))
1789+
PyDec_GetCurrentContext(PyObject *self)
17791790
{
17801791
PyObject *context;
17811792
decimal_state *state = get_module_state(self);
@@ -1871,7 +1882,7 @@ current_context(decimal_state *state)
18711882

18721883
/* Return a new reference to the current context */
18731884
static PyObject *
1874-
PyDec_GetCurrentContext(PyObject *self, PyObject *Py_UNUSED(dummy))
1885+
PyDec_GetCurrentContext(PyObject *self)
18751886
{
18761887
decimal_state *state = get_module_state(self);
18771888
return current_context(state);
@@ -1910,36 +1921,74 @@ PyDec_SetCurrentContext(PyObject *self, PyObject *v)
19101921
}
19111922
#endif
19121923

1924+
/*[clinic input]
1925+
_decimal.Decimal.getcontext
1926+
1927+
Get the current default context.
1928+
[clinic start generated code]*/
1929+
1930+
static PyObject *
1931+
_decimal_Decimal_getcontext_impl(PyObject *self)
1932+
/*[clinic end generated code: output=7efa232c0136dbba input=2d641118d62b25d4]*/
1933+
{
1934+
return PyDec_GetCurrentContext(self);
1935+
}
1936+
1937+
/*[clinic input]
1938+
_decimal.Decimal.setcontext
1939+
1940+
context: object
1941+
1942+
Set a new default context.
1943+
[clinic start generated code]*/
1944+
1945+
static PyObject *
1946+
_decimal_Decimal_setcontext_impl(PyObject *self, PyObject *context)
1947+
/*[clinic end generated code: output=28637d8482b37a71 input=d008c3c978217ccd]*/
1948+
{
1949+
return PyDec_SetCurrentContext(self, context);
1950+
}
1951+
19131952
/* Context manager object for the 'with' statement. The manager
19141953
* owns one reference to the global (outer) context and one
19151954
* to the local (inner) context. */
1955+
1956+
/*[clinic input]
1957+
@text_signature "($module, /, ctx=None, **kwargs)"
1958+
_decimal.Decimal.localcontext
1959+
1960+
self as m: self
1961+
ctx as local: object = None
1962+
*
1963+
prec: object = None
1964+
rounding: object = None
1965+
Emin: object = None
1966+
Emax: object = None
1967+
capitals: object = None
1968+
clamp: object = None
1969+
flags: object = None
1970+
traps: object = None
1971+
1972+
Return a context manager for a copy of the supplied context.
1973+
1974+
That will set the default context to a copy of ctx on entry to the
1975+
with-statement and restore the previous default context when exiting
1976+
the with-statement. If no context is specified, a copy of the current
1977+
default context is used.
1978+
[clinic start generated code]*/
1979+
19161980
static PyObject *
1917-
ctxmanager_new(PyObject *m, PyObject *args, PyObject *kwds)
1981+
_decimal_Decimal_localcontext_impl(PyObject *m, PyObject *local,
1982+
PyObject *prec, PyObject *rounding,
1983+
PyObject *Emin, PyObject *Emax,
1984+
PyObject *capitals, PyObject *clamp,
1985+
PyObject *flags, PyObject *traps)
1986+
/*[clinic end generated code: output=21cc25fbed642f2f input=77906e599937a9b5]*/
19181987
{
1919-
static char *kwlist[] = {
1920-
"ctx", "prec", "rounding",
1921-
"Emin", "Emax", "capitals",
1922-
"clamp", "flags", "traps",
1923-
NULL
1924-
};
1925-
PyObject *local = Py_None;
19261988
PyObject *global;
19271989

1928-
PyObject *prec = Py_None;
1929-
PyObject *rounding = Py_None;
1930-
PyObject *Emin = Py_None;
1931-
PyObject *Emax = Py_None;
1932-
PyObject *capitals = Py_None;
1933-
PyObject *clamp = Py_None;
1934-
PyObject *flags = Py_None;
1935-
PyObject *traps = Py_None;
1936-
19371990
decimal_state *state = get_module_state(m);
19381991
CURRENT_CONTEXT(state, global);
1939-
if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OOOOOOOOO", kwlist, &local,
1940-
&prec, &rounding, &Emin, &Emax, &capitals, &clamp, &flags, &traps)) {
1941-
return NULL;
1942-
}
19431992
if (local == Py_None) {
19441993
local = global;
19451994
}
@@ -6806,10 +6855,10 @@ static PyType_Spec context_spec = {
68066855

68076856
static PyMethodDef _decimal_methods [] =
68086857
{
6809-
{ "getcontext", PyDec_GetCurrentContext, METH_NOARGS, doc_getcontext},
6810-
{ "setcontext", PyDec_SetCurrentContext, METH_O, doc_setcontext},
6811-
{ "localcontext", _PyCFunction_CAST(ctxmanager_new), METH_VARARGS|METH_KEYWORDS, doc_localcontext},
6812-
{ "IEEEContext", ieee_context, METH_O, doc_ieee_context},
6858+
_DECIMAL_DECIMAL_GETCONTEXT_METHODDEF
6859+
_DECIMAL_DECIMAL_SETCONTEXT_METHODDEF
6860+
_DECIMAL_DECIMAL_LOCALCONTEXT_METHODDEF
6861+
_DECIMAL_DECIMAL_IEEECONTEXT_METHODDEF
68136862
{ NULL, NULL, 1, NULL }
68146863
};
68156864

0 commit comments

Comments
 (0)