Cycles: Cleanup, silence strict compiler warning
authorSergey Sharybin <sergey.vfx@gmail.com>
Mon, 11 Jun 2018 10:54:17 +0000 (12:54 +0200)
committerSergey Sharybin <sergey.vfx@gmail.com>
Mon, 11 Jun 2018 11:02:10 +0000 (13:02 +0200)
There is one legit place in the code where memcpy was used as an
optimization trick. Was needed for older version of GCC, but now
it should be re-evaluated and checked if it still helps to have
that trick.

In other places it's somewhat lazy programming to zero out all
object members. That is absolutely unsafe, at the moment when
less trivial class is used as a member in that object things
will break.

Other cases were using memcpy into an object which comes from
an external library. We don't control that object, and we can
not guarantee it will always be safe for such memory tricks
and debugging bugs caused by such low level access is far fun.

Ideally we need to use more proper C++, but needs to be done with
big care, including benchmarks of each change, For now do
annoying but simple cast to void*.

intern/cycles/blender/blender_camera.cpp
intern/cycles/blender/blender_util.h
intern/cycles/bvh/bvh_params.h
intern/cycles/kernel/closure/alloc.h
intern/cycles/kernel/osl/osl_services.cpp
intern/cycles/kernel/osl/osl_shader.cpp
intern/cycles/render/camera.cpp
intern/cycles/render/scene.cpp
intern/cycles/render/svm.cpp
intern/cycles/util/util_vector.h

index f00ade320e780b6e8a1a1fff2568d13933d08955..435afabc2bbf16c77d945981f32e938b52cc0c95 100644 (file)
@@ -90,7 +90,7 @@ struct BlenderCamera {
 static void blender_camera_init(BlenderCamera *bcam,
                                 BL::RenderSettings& b_render)
 {
-       memset(bcam, 0, sizeof(BlenderCamera));
+       memset((void *)bcam, 0, sizeof(BlenderCamera));
 
        bcam->type = CAMERA_PERSPECTIVE;
        bcam->zoom = 1.0f;
index 85bff8f83231c7da7bfbc7cc283e0d54a4a58436..5176f9c3b5021cdef56d3514db8fad9c516732d4 100644 (file)
@@ -251,7 +251,7 @@ static inline Transform get_transform(const BL::Array<float, 16>& array)
 
        /* We assume both types to be just 16 floats, and transpose because blender
         * use column major matrix order while we use row major. */
-       memcpy(&projection, &array, sizeof(float)*16);
+       memcpy((void *)&projection, &array, sizeof(float)*16);
        projection = projection_transpose(projection);
 
        /* Drop last row, matrix is assumed to be affine transform. */
index 89a379cf3561a48fc690ff7046adf6cc722bb3d9..d8dd7df6ba1e7cf7cdf2f25ef18e95a8b03dc7a8 100644 (file)
@@ -182,7 +182,10 @@ public:
 
        BVHReference& operator=(const BVHReference &arg) {
                if(&arg != this) {
-                       memcpy(this, &arg, sizeof(BVHReference));
+                       /* TODO(sergey): Check if it is still faster to memcpy() with
+                        * modern compilers.
+                        */
+                       memcpy((void *)this, &arg, sizeof(BVHReference));
                }
                return *this;
        }
index b903aeb80735b46fe106baaec141e79caf5facd2..acccba9ecec0c51d71164c68e3a71d11d939f3dd 100644 (file)
@@ -75,7 +75,7 @@ ccl_device_inline ShaderClosure *bsdf_alloc_osl(ShaderData *sd, int size, float3
        if(!sc)
                return NULL;
 
-       memcpy(sc, data, size);
+       memcpy((void *)sc, data, size);
 
        float sample_weight = fabsf(average(weight));
        sc->weight = weight;
index 32d86b7192a01b758031f5fb6bb0ba4b98a597cf..5f4baf6fda3959d7fc639e4f81b28edd983c1b70 100644 (file)
@@ -65,13 +65,13 @@ CCL_NAMESPACE_BEGIN
 static void copy_matrix(OSL::Matrix44& m, const Transform& tfm)
 {
        ProjectionTransform t = projection_transpose(ProjectionTransform(tfm));
-       memcpy(&m, &t, sizeof(m));
+       memcpy((void *)&m, &t, sizeof(m));
 }
 
 static void copy_matrix(OSL::Matrix44& m, const ProjectionTransform& tfm)
 {
        ProjectionTransform t = projection_transpose(tfm);
-       memcpy(&m, &t, sizeof(m));
+       memcpy((void *)&m, &t, sizeof(m));
 }
 
 /* static ustrings */
index 6b3a996ca12a56254c051e61a1767d0a68ad325e..b7d1c629291973ffaf8a015ba8459010e7ea86ab 100644 (file)
@@ -53,7 +53,7 @@ void OSLShader::thread_init(KernelGlobals *kg, KernelGlobals *kernel_globals, OS
        OSL::ShadingSystem *ss = kg->osl->ss;
        OSLThreadData *tdata = new OSLThreadData();
 
-       memset(&tdata->globals, 0, sizeof(OSL::ShaderGlobals));
+       memset((void *)&tdata->globals, 0, sizeof(OSL::ShaderGlobals));
        tdata->globals.tracedata = &tdata->tracedata;
        tdata->globals.flipHandedness = false;
        tdata->osl_thread_info = ss->create_thread_info();
index 38936ffc094f35e72ea3be9eb0f672e54db2c080..734cdffd5c51fa211812cadc4b89f9f4760bf968 100644 (file)
@@ -176,7 +176,7 @@ Camera::Camera()
        need_flags_update = true;
        previous_need_motion = -1;
 
-       memset(&kernel_camera, 0, sizeof(kernel_camera));
+       memset((void *)&kernel_camera, 0, sizeof(kernel_camera));
 }
 
 Camera::~Camera()
index b35cdbd3db55415ea2b02025857413c09ad13816..c0f1ae0445e720ea6b40630cb5b1fd7f1645b1a1 100644 (file)
@@ -79,13 +79,13 @@ DeviceScene::DeviceScene(Device *device)
   sobol_directions(device, "__sobol_directions", MEM_TEXTURE),
   ies_lights(device, "__ies", MEM_TEXTURE)
 {
-       memset(&data, 0, sizeof(data));
+       memset((void*)&data, 0, sizeof(data));
 }
 
 Scene::Scene(const SceneParams& params_, Device *device)
 : device(device), dscene(device), params(params_)
 {
-       memset(&dscene.data, 0, sizeof(dscene.data));
+       memset((void *)&dscene.data, 0, sizeof(dscene.data));
 
        camera = new Camera();
        dicing_camera = new Camera();
index eb8a35a271fd3532d48ca1da01615760630876d2..626f160786f5d242a06a13243fb4d90299b73999 100644 (file)
@@ -735,7 +735,7 @@ void SVMCompiler::compile_type(Shader *shader, ShaderGraph *graph, ShaderType ty
        }
 
        /* clear all compiler state */
-       memset(&active_stack, 0, sizeof(active_stack));
+       memset((void *)&active_stack, 0, sizeof(active_stack));
        current_svm_nodes.clear();
 
        foreach(ShaderNode *node_iter, graph->nodes) {
index e98e4e3418141a287995a1a8f0e2cc018b19ab1d..8d91d3936a486f20c6dfb6f0b7ee04b9a538461f 100644 (file)
@@ -131,7 +131,7 @@ public:
        {
                if(this != &from) {
                        resize(from.size());
-                       memcpy(data_, from.data_, datasize_*sizeof(T));
+                       memcpy((void*)data_, from.data_, datasize_*sizeof(T));
                }
 
                return *this;
@@ -204,7 +204,9 @@ public:
                                        return NULL;
                                }
                                else if(data_ != NULL) {
-                                       memcpy(newdata, data_, ((datasize_ < newsize)? datasize_: newsize)*sizeof(T));
+                                       memcpy((void *)newdata,
+                                              data_,
+                                              ((datasize_ < newsize)? datasize_: newsize)*sizeof(T));
                                        mem_free(data_, capacity_);
                                }
                                data_ = newdata;