diff options
author | Stefan Krah <skrah@bytereef.org> | 2012-11-07 22:20:10 (GMT) |
---|---|---|
committer | Stefan Krah <skrah@bytereef.org> | 2012-11-07 22:20:10 (GMT) |
commit | fc55bb1cc53b62cc461827755edf2be6cb07d636 (patch) | |
tree | 68a70fc2cdfb4ba7f453a51826031b2c394a0ce2 /Modules | |
parent | 15c02e304852596f2468f5edc32cb57d496ce9ca (diff) | |
parent | f4abc7b8a016da5b1783f471f2f376d7e9c27d60 (diff) | |
download | cpython-fc55bb1cc53b62cc461827755edf2be6cb07d636.zip cpython-fc55bb1cc53b62cc461827755edf2be6cb07d636.tar.gz cpython-fc55bb1cc53b62cc461827755edf2be6cb07d636.tar.bz2 |
Merge 3.3.
Diffstat (limited to 'Modules')
-rw-r--r-- | Modules/_decimal/_decimal.c | 29 |
1 files changed, 27 insertions, 2 deletions
diff --git a/Modules/_decimal/_decimal.c b/Modules/_decimal/_decimal.c index 996f9da..0bc484f 100644 --- a/Modules/_decimal/_decimal.c +++ b/Modules/_decimal/_decimal.c @@ -2338,6 +2338,32 @@ PyDecType_FromFloat(PyTypeObject *type, PyObject *v, return dec; } +/* Return a new PyDecObject (subtype) from a Decimal. */ +static PyObject * +PyDecType_FromDecimalExact(PyTypeObject *type, PyObject *v, PyObject *context) +{ + PyObject *dec; + uint32_t status = 0; + + if (type == &PyDec_Type) { + Py_INCREF(v); + return v; + } + + dec = PyDecType_New(type); + if (dec == NULL) { + return NULL; + } + + mpd_qcopy(MPD(dec), MPD(v), &status); + if (dec_addstatus(context, status)) { + Py_DECREF(dec); + return NULL; + } + + return dec; +} + static PyObject * sequence_as_tuple(PyObject *v, PyObject *ex, const char *mesg) { @@ -2642,8 +2668,7 @@ PyDecType_FromObjectExact(PyTypeObject *type, PyObject *v, PyObject *context) return PyDecType_FromSsizeExact(type, 0, context); } else if (PyDec_Check(v)) { - Py_INCREF(v); - return v; + return PyDecType_FromDecimalExact(type, v, context); } else if (PyUnicode_Check(v)) { return PyDecType_FromUnicodeExactWS(type, v, context); |