]> granicus.if.org Git - python/commitdiff
Raise MemoryError instead of InvalidOperation/MallocError for compatibility
authorStefan Krah <skrah@bytereef.org>
Sun, 25 Mar 2012 16:59:21 +0000 (18:59 +0200)
committerStefan Krah <skrah@bytereef.org>
Sun, 25 Mar 2012 16:59:21 +0000 (18:59 +0200)
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.

Lib/test/test_decimal.py
Modules/_decimal/_decimal.c

index 4a352e51073a9c771fd5a8f5662e02bb60ab5847..694b959e21870bebe330bc6200d6e4c27c08a29d 100644 (file)
@@ -3837,7 +3837,7 @@ class CheckAttributes(unittest.TestCase):
 
         x = dir(C)
         y = [s for s in dir(P) if '__' in s or not s.startswith('_')]
-        self.assertEqual(set(x) - set(y), {'MallocError'})
+        self.assertEqual(set(x) - set(y), set())
 
     def test_context_attributes(self):
 
index aa39de1ba814e329a42fc0f92bd256a5ca8aa059..bb2df4409eb366f612f6585b4b5e8d90f8b10e9a 100644 (file)
@@ -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 */