[Bf-blender-cvs] [15f3cf7f8f9] master: Cleanup: replace C-style casts with functional casts for numeric types

Campbell Barton noreply at git.blender.org
Mon Sep 26 01:56:47 CEST 2022


Commit: 15f3cf7f8f956a6372b6a99788b622946ba3d1e5
Author: Campbell Barton
Date:   Mon Sep 26 09:53:49 2022 +1000
Branches: master
https://developer.blender.org/rB15f3cf7f8f956a6372b6a99788b622946ba3d1e5

Cleanup: replace C-style casts with functional casts for numeric types

Some changes missed from f68cfd6bb078482c4a779a6e26a56e2734edb5b8.

===================================================================

M	intern/cycles/blender/python.cpp
M	intern/ghost/intern/GHOST_SystemWin32.cpp
M	intern/ghost/intern/GHOST_SystemX11.cpp
M	intern/ghost/intern/GHOST_WindowWin32.cpp
M	intern/guardedalloc/tests/guardedalloc_alignment_test.cc
M	source/blender/blenkernel/intern/icons.cc
M	source/blender/blenkernel/intern/scene.cc
M	source/blender/blenlib/tests/BLI_polyfill_2d_test.cc
M	source/blender/blenlib/tests/BLI_stack_cxx_test.cc
M	source/blender/blenlib/tests/BLI_vector_test.cc
M	source/blender/bmesh/tests/bmesh_core_test.cc
M	source/blender/draw/engines/overlay/overlay_armature.cc

===================================================================

diff --git a/intern/cycles/blender/python.cpp b/intern/cycles/blender/python.cpp
index 1e33b0b7207..077875aecb2 100644
--- a/intern/cycles/blender/python.cpp
+++ b/intern/cycles/blender/python.cpp
@@ -534,7 +534,7 @@ static PyObject *osl_update_node_func(PyObject * /*self*/, PyObject *args)
           socket_type = "NodeSocketBool";
           data_type = BL::NodeSocket::type_BOOLEAN;
           if (param->validdefault) {
-            default_boolean = (bool)param->idefault[0];
+            default_boolean = bool(param->idefault[0]);
           }
         }
         else {
diff --git a/intern/ghost/intern/GHOST_SystemWin32.cpp b/intern/ghost/intern/GHOST_SystemWin32.cpp
index 5c58f9a856c..5a840d869b3 100644
--- a/intern/ghost/intern/GHOST_SystemWin32.cpp
+++ b/intern/ghost/intern/GHOST_SystemWin32.cpp
@@ -562,7 +562,7 @@ GHOST_TKey GHOST_SystemWin32::processSpecialKey(short vKey, short scanCode) cons
     return key;
   }
 
-  char ch = (char)MapVirtualKeyA(vKey, MAPVK_VK_TO_CHAR);
+  char ch = char(MapVirtualKeyA(vKey, MAPVK_VK_TO_CHAR));
   switch (ch) {
     case u'\"':
     case u'\'':
@@ -1747,10 +1747,10 @@ LRESULT WINAPI GHOST_SystemWin32::s_wndProc(HWND hwnd, UINT msg, WPARAM wParam,
           break;
         }
         case WM_XBUTTONDOWN: {
-          if ((short)HIWORD(wParam) == XBUTTON1) {
+          if (short(HIWORD(wParam)) == XBUTTON1) {
             event = processButtonEvent(GHOST_kEventButtonDown, window, GHOST_kButtonMaskButton4);
           }
-          else if ((short)HIWORD(wParam) == XBUTTON2) {
+          else if (short(HIWORD(wParam)) == XBUTTON2) {
             event = processButtonEvent(GHOST_kEventButtonDown, window, GHOST_kButtonMaskButton5);
           }
           break;
@@ -1768,10 +1768,10 @@ LRESULT WINAPI GHOST_SystemWin32::s_wndProc(HWND hwnd, UINT msg, WPARAM wParam,
           break;
         }
         case WM_XBUTTONUP: {
-          if ((short)HIWORD(wParam) == XBUTTON1) {
+          if (short(HIWORD(wParam)) == XBUTTON1) {
             event = processButtonEvent(GHOST_kEventButtonUp, window, GHOST_kButtonMaskButton4);
           }
-          else if ((short)HIWORD(wParam) == XBUTTON2) {
+          else if (short(HIWORD(wParam)) == XBUTTON2) {
             event = processButtonEvent(GHOST_kEventButtonUp, window, GHOST_kButtonMaskButton5);
           }
           break;
diff --git a/intern/ghost/intern/GHOST_SystemX11.cpp b/intern/ghost/intern/GHOST_SystemX11.cpp
index 5c1ac157980..89b4b31468b 100644
--- a/intern/ghost/intern/GHOST_SystemX11.cpp
+++ b/intern/ghost/intern/GHOST_SystemX11.cpp
@@ -1152,7 +1152,7 @@ void GHOST_SystemX11::processEvent(XEvent *xe)
           }
 
           if (ELEM(status, XLookupChars, XLookupBoth)) {
-            if ((unsigned char)utf8_buf[0] >= 32) { /* not an ascii control character */
+            if (uchar(utf8_buf[0]) >= 32) { /* not an ascii control character */
               /* do nothing for now, this is valid utf8 */
             }
             else {
@@ -1165,7 +1165,7 @@ void GHOST_SystemX11::processEvent(XEvent *xe)
           }
           else {
             printf("Bad keycode lookup. Keysym 0x%x Status: %s\n",
-                   (unsigned int)key_sym,
+                   uint(key_sym),
                    (status == XLookupNone   ? "XLookupNone" :
                     status == XLookupKeySym ? "XLookupKeySym" :
                                               "Unknown status"));
diff --git a/intern/ghost/intern/GHOST_WindowWin32.cpp b/intern/ghost/intern/GHOST_WindowWin32.cpp
index 50ee9385e39..e2d143ee5e6 100644
--- a/intern/ghost/intern/GHOST_WindowWin32.cpp
+++ b/intern/ghost/intern/GHOST_WindowWin32.cpp
@@ -89,7 +89,7 @@ GHOST_WindowWin32::GHOST_WindowWin32(GHOST_SystemWin32 *system,
      */
   }
 
-  RECT win_rect = {left, top, (long)(left + width), (long)(top + height)};
+  RECT win_rect = {left, top, long(left + width), long(top + height)};
   adjustWindowRectForClosestMonitor(&win_rect, style, extended_style);
 
   wchar_t *title_16 = alloc_utf16_from_8((char *)title, 0);
diff --git a/intern/guardedalloc/tests/guardedalloc_alignment_test.cc b/intern/guardedalloc/tests/guardedalloc_alignment_test.cc
index ceda01c2fba..b1a2143c8dc 100644
--- a/intern/guardedalloc/tests/guardedalloc_alignment_test.cc
+++ b/intern/guardedalloc/tests/guardedalloc_alignment_test.cc
@@ -7,7 +7,7 @@
 #include "MEM_guardedalloc.h"
 #include "guardedalloc_test_base.h"
 
-#define CHECK_ALIGNMENT(ptr, align) EXPECT_EQ((size_t)ptr % align, 0)
+#define CHECK_ALIGNMENT(ptr, align) EXPECT_EQ(size_t(ptr) % align, 0)
 
 namespace {
 
diff --git a/source/blender/blenkernel/intern/icons.cc b/source/blender/blenkernel/intern/icons.cc
index 82023c23ca5..dc1d23de7e0 100644
--- a/source/blender/blenkernel/intern/icons.cc
+++ b/source/blender/blenkernel/intern/icons.cc
@@ -971,8 +971,8 @@ struct Icon_Geom *BKE_icon_geom_from_memory(uchar *data, size_t data_len)
   p += 4;
 
   struct Icon_Geom *geom = (struct Icon_Geom *)MEM_mallocN(sizeof(*geom), __func__);
-  geom->coords_range[0] = (int)*p++;
-  geom->coords_range[1] = (int)*p++;
+  geom->coords_range[0] = int(*p++);
+  geom->coords_range[1] = int(*p++);
   /* x, y ignored for now */
   p += 2;
 
diff --git a/source/blender/blenkernel/intern/scene.cc b/source/blender/blenkernel/intern/scene.cc
index 7959ab845e8..6d10d31e976 100644
--- a/source/blender/blenkernel/intern/scene.cc
+++ b/source/blender/blenkernel/intern/scene.cc
@@ -159,8 +159,8 @@ static void scene_init_data(ID *id)
   scene->unit.length_unit = uchar(BKE_unit_base_of_type_get(USER_UNIT_METRIC, B_UNIT_LENGTH));
   scene->unit.mass_unit = uchar(BKE_unit_base_of_type_get(USER_UNIT_METRIC, B_UNIT_MASS));
   scene->unit.time_unit = uchar(BKE_unit_base_of_type_get(USER_UNIT_METRIC, B_UNIT_TIME));
-  scene->unit.temperature_unit = (uchar)BKE_unit_base_of_type_get(USER_UNIT_METRIC,
-                                                                  B_UNIT_TEMPERATURE);
+  scene->unit.temperature_unit = uchar(
+      BKE_unit_base_of_type_get(USER_UNIT_METRIC, B_UNIT_TEMPERATURE));
 
   /* Anti-Aliasing threshold. */
   scene->grease_pencil_settings.smaa_threshold = 1.0f;
diff --git a/source/blender/blenlib/tests/BLI_polyfill_2d_test.cc b/source/blender/blenlib/tests/BLI_polyfill_2d_test.cc
index 95fd664217f..f3b66bedf88 100644
--- a/source/blender/blenlib/tests/BLI_polyfill_2d_test.cc
+++ b/source/blender/blenlib/tests/BLI_polyfill_2d_test.cc
@@ -108,13 +108,13 @@ static void test_polyfill_topology(const float /*poly*/[][2],
     const uint v2 = (i + 1) % poly_num;
     void **p = BLI_edgehash_lookup_p(edgehash, v1, v2);
     EXPECT_NE((void *)p, nullptr);
-    EXPECT_EQ((intptr_t)*p, 1);
+    EXPECT_EQ(intptr_t(*p), 1);
   }
 
   for (ehi = BLI_edgehashIterator_new(edgehash), i = 0; BLI_edgehashIterator_isDone(ehi) == false;
        BLI_edgehashIterator_step(ehi), i++) {
     void **p = BLI_edgehashIterator_getValue_p(ehi);
-    EXPECT_TRUE(ELEM((intptr_t)*p, 1, 2));
+    EXPECT_TRUE(ELEM(intptr_t(*p), 1, 2));
   }
 
   BLI_edgehashIterator_free(ehi);
diff --git a/source/blender/blenlib/tests/BLI_stack_cxx_test.cc b/source/blender/blenlib/tests/BLI_stack_cxx_test.cc
index 768d7199f68..13d417d4374 100644
--- a/source/blender/blenlib/tests/BLI_stack_cxx_test.cc
+++ b/source/blender/blenlib/tests/BLI_stack_cxx_test.cc
@@ -191,7 +191,7 @@ TEST(stack, OveralignedValues)
   Stack<AlignedBuffer<1, 512>, 2> stack;
   for (int i = 0; i < 100; i++) {
     stack.push({});
-    EXPECT_EQ((uintptr_t)&stack.peek() % 512, 0);
+    EXPECT_EQ(uintptr_t(&stack.peek()) % 512, 0);
   }
 }
 
diff --git a/source/blender/blenlib/tests/BLI_vector_test.cc b/source/blender/blenlib/tests/BLI_vector_test.cc
index 53e8cd1047b..2dd220f562b 100644
--- a/source/blender/blenlib/tests/BLI_vector_test.cc
+++ b/source/blender/blenlib/tests/BLI_vector_test.cc
@@ -644,7 +644,7 @@ TEST(vector, OveralignedValues)
   Vector<AlignedBuffer<1, 512>, 2> vec;
   for (int i = 0; i < 100; i++) {
     vec.append({});
-    EXPECT_EQ((uintptr_t)&vec.last() % 512, 0);
+    EXPECT_EQ(uintptr_t(&vec.last()) % 512, 0);
   }
 }
 
diff --git a/source/blender/bmesh/tests/bmesh_core_test.cc b/source/blender/bmesh/tests/bmesh_core_test.cc
index 000e4cf92a2..a0f6ea2706b 100644
--- a/source/blender/bmesh/tests/bmesh_core_test.cc
+++ b/source/blender/bmesh/tests/bmesh_core_test.cc
@@ -24,7 +24,7 @@ TEST(bmesh_core, BMVertCreate)
   EXPECT_EQ(bv1->co[1], 2.0f);
   EXPECT_EQ(bv1->co[2], 0.0f);
   EXPECT_TRUE(is_zero_v3(bv1->no));
-  EXPECT_EQ(bv1->head.htype, (char)BM_VERT);
+  EXPECT_EQ(bv1->head.htype, char(BM_VERT));
   EXPECT_EQ(bv1->head.hflag, 0);
   EXPECT_EQ(bv1->head.api_flag, 0);
   bv2 = BM_vert_create(bm, nullptr, nullptr, BM_CREATE_NOP);
diff --git a/source/blender/draw/engines/overlay/overlay_armature.cc b/source/blender/draw/engines/overlay/overlay_armature.cc
index 903bcbb911e..dfbf4560271 100644
--- a/source/blender/draw/engines/overlay/overlay_armature.cc
+++ b/source/blender/draw/engines/overlay/overlay_armature.cc
@@ -2241,7 +2241,7 @@ static void draw_armature_edit(ArmatureDrawContext *ctx)
        eBone = eBone->next, index += 0x10000) {
     if (eBone->layer & arm->layer) {
       if ((eBone->flag & BONE_HIDDEN_A) == 0) {
-        const int select_id = is_select ? index : (uint)-1;
+        const int select_id = is_select ? index : uint(-1);
         const short constflag = 0;
 
         /* catch exception for bone with hidden parent */
@@ -2378,7 +2378,7 @@ static void draw_armature_pose(ArmatureDrawContext *ctx)
                                (arm->flag & ARM_POSEMODE) && (bone->flag & BONE_SELECTED) &&
                                ((ob->base_flag & BASE_FROM_DUPLI) == 0) &&
                                (pchan->ikflag & (BONE_IK_XLIMIT | BONE_IK_ZLIMIT));
-        const int select_id = is_pose_select ? index : (uint)-1;
+        const int select_id = is_pose_select ? index : uint(-1);
         const short constflag = pchan->constflag;
 
         pchan_draw_data_init(pchan);



More information about the Bf-blender-cvs mailing list