[前][次][番号順一覧][スレッド一覧]

ruby-changes:64667

From: Kenta <ko1@a...>
Date: Wed, 30 Dec 2020 00:46:16 +0900 (JST)
Subject: [ruby-changes:64667] 086f3f1872 (master): [ruby/bigdecimal] Remove needless pointer checks

https://git.ruby-lang.org/ruby.git/commit/?id=086f3f1872

From 086f3f187224fa59e294947ed4e840bc277aadc5 Mon Sep 17 00:00:00 2001
From: Kenta Murata <mrkn@m...>
Date: Tue, 29 Dec 2020 22:36:51 +0900
Subject: [ruby/bigdecimal] Remove needless pointer checks

xmalloc and xrealloc return non-NULL pointers or raise memory error.

https://github.com/ruby/bigdecimal/commit/507f0a6a64

diff --git a/ext/bigdecimal/bigdecimal.c b/ext/bigdecimal/bigdecimal.c
index 89653f4..65f412e 100644
--- a/ext/bigdecimal/bigdecimal.c
+++ b/ext/bigdecimal/bigdecimal.c
@@ -3779,9 +3779,6 @@ VP_EXPORT void * https://github.com/ruby/ruby/blob/trunk/ext/bigdecimal/bigdecimal.c#L3779
 VpMemAlloc(size_t mb)
 {
     void *p = xmalloc(mb);
-    if (!p) {
-	VpException(VP_EXCEPTION_MEMORY, "failed to allocate memory", 1);
-    }
     memset(p, 0, mb);
 #ifdef BIGDECIMAL_DEBUG
     gnAlloc++; /* Count allocation call */
@@ -3792,11 +3789,7 @@ VpMemAlloc(size_t mb) https://github.com/ruby/ruby/blob/trunk/ext/bigdecimal/bigdecimal.c#L3789
 VP_EXPORT void *
 VpMemRealloc(void *ptr, size_t mb)
 {
-    void *p = xrealloc(ptr, mb);
-    if (!p) {
-	VpException(VP_EXCEPTION_MEMORY, "failed to allocate memory", 1);
-    }
-    return p;
+    return xrealloc(ptr, mb);
 }
 
 VP_EXPORT void
@@ -4348,7 +4341,6 @@ VpAlloc(size_t mx, const char *szVal, int strict_p, int exc) https://github.com/ruby/ruby/blob/trunk/ext/bigdecimal/bigdecimal.c#L4341
         /* at least mx digits. */
         /* szVal==NULL ==> allocate zero value. */
         vp = VpAllocReal(mx);
-        /* xmalloc() always returns(or throw interruption) */
         vp->MaxPrec = mx;    /* set max precision */
         VpSetZero(vp, 1);    /* initialize vp to zero. */
         return vp;
@@ -4524,7 +4516,6 @@ VpAlloc(size_t mx, const char *szVal, int strict_p, int exc) https://github.com/ruby/ruby/blob/trunk/ext/bigdecimal/bigdecimal.c#L4516
     nalloc = Max(nalloc, mx);
     mx = nalloc;
     vp = VpAllocReal(mx);
-    /* xmalloc() always returns(or throw interruption) */
     vp->MaxPrec = mx;        /* set max precision */
     VpSetZero(vp, sign);
     VpCtoV(vp, psz, ni, psz + ipf, nf, psz + ipe, ne);
-- 
cgit v0.10.2


--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]