diff options
author | Stefan Krah <skrah@bytereef.org> | 2012-03-25 16:59:21 (GMT) |
---|---|---|
committer | Stefan Krah <skrah@bytereef.org> | 2012-03-25 16:59:21 (GMT) |
commit | fe17b2bc77851be1724f9ce2ea07112a06f413ab (patch) | |
tree | b9d680161ce00c04d494062d66410f321d3f83cb /Modules | |
parent | 1d5617958fa4e3e1039c62cbe15565e642a9e428 (diff) | |
download | cpython-fe17b2bc77851be1724f9ce2ea07112a06f413ab.zip cpython-fe17b2bc77851be1724f9ce2ea07112a06f413ab.tar.gz cpython-fe17b2bc77851be1724f9ce2ea07112a06f413ab.tar.bz2 |
Raise MemoryError instead of InvalidOperation/MallocError for compatibility
with decimal.py. The standard specifies InsufficientStorage (MallocError) as
a sub-condition of InvalidOperation. This allows a calculation to continue
with NaN results when allocation fails.
Diffstat (limited to 'Modules')
-rw-r--r-- | Modules/_decimal/_decimal.c | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/Modules/_decimal/_decimal.c b/Modules/_decimal/_decimal.c index aa39de1..bb2df44 100644 --- a/Modules/_decimal/_decimal.c +++ b/Modules/_decimal/_decimal.c @@ -168,7 +168,9 @@ static DecCondMap cond_map[] = { {"DivisionImpossible", "decimal.DivisionImpossible", MPD_Division_impossible, NULL}, {"DivisionUndefined", "decimal.DivisionUndefined", MPD_Division_undefined, NULL}, {"InvalidContext", "decimal.InvalidContext", MPD_Invalid_context, NULL}, +#ifdef EXTRA_FUNCTIONALITY {"MallocError", "decimal.MallocError", MPD_Malloc_error, NULL}, +#endif {NULL} }; @@ -466,9 +468,14 @@ dec_addstatus(PyObject *context, uint32_t status) mpd_context_t *ctx = CTX(context); ctx->status |= status; - if (ctx->traps&status) { + if (status & (ctx->traps|MPD_Malloc_error)) { PyObject *ex, *siglist; + if (status & MPD_Malloc_error) { + PyErr_NoMemory(); + return 1; + } + ex = flags_as_exception(ctx->traps&status); if (ex == NULL) { return 1; /* GCOV_NOT_REACHED */ |