From b49dbaca2bd3f544ef54b9a3d017eadef152de3b Mon Sep 17 00:00:00 2001 From: rdb Date: Thu, 25 Jan 2024 12:33:20 +0100 Subject: [PATCH 1/7] Report errors if calls to `close()` fail --- dtool/src/dtoolutil/filename.cxx | 28 ++++++++++++++++------ dtool/src/dtoolutil/pandaFileStreamBuf.cxx | 10 +++++++- panda/src/nativenet/socket_ip.h | 12 ++++++++-- pandatool/src/deploy-stub/deploy-stub.c | 4 +++- 4 files changed, 43 insertions(+), 11 deletions(-) diff --git a/dtool/src/dtoolutil/filename.cxx b/dtool/src/dtoolutil/filename.cxx index 7d3ce1693f..69556a5325 100644 --- a/dtool/src/dtoolutil/filename.cxx +++ b/dtool/src/dtoolutil/filename.cxx @@ -2287,7 +2287,9 @@ touch() const { perror(os_specific.c_str()); return false; } - close(fd); + if (close(fd) < 0) { + perror(os_specific.c_str()); + } return true; } perror(os_specific.c_str()); @@ -2736,7 +2738,9 @@ atomic_compare_and_exchange_contents(string &orig_contents, if (flock(fd, LOCK_EX) != 0) { #endif perror(os_specific.c_str()); - close(fd); + if (close(fd) < 0) { + perror(os_specific.c_str()); + } return false; } @@ -2748,7 +2752,9 @@ atomic_compare_and_exchange_contents(string &orig_contents, if (bytes_read < 0) { perror(os_specific.c_str()); - close(fd); + if (close(fd) < 0) { + perror(os_specific.c_str()); + } return false; } @@ -2759,7 +2765,9 @@ atomic_compare_and_exchange_contents(string &orig_contents, ssize_t bytes_written = write(fd, new_contents.data(), new_contents.size()); if (bytes_written < 0) { perror(os_specific.c_str()); - close(fd); + if (close(fd) < 0) { + perror(os_specific.c_str()); + } return false; } } @@ -2852,7 +2860,9 @@ atomic_read_contents(string &contents) const { if (flock(fd, LOCK_EX) != 0) { #endif perror(os_specific.c_str()); - close(fd); + if (close(fd) < 0) { + perror(os_specific.c_str()); + } return false; } @@ -2864,11 +2874,15 @@ atomic_read_contents(string &contents) const { if (bytes_read < 0) { perror(os_specific.c_str()); - close(fd); + if (close(fd) < 0) { + perror(os_specific.c_str()); + } return false; } - close(fd); + if (close(fd) < 0) { + perror(os_specific.c_str()); + } return true; #endif // WIN32_VC } diff --git a/dtool/src/dtoolutil/pandaFileStreamBuf.cxx b/dtool/src/dtoolutil/pandaFileStreamBuf.cxx index 1caecaf991..e5891c7158 100644 --- a/dtool/src/dtoolutil/pandaFileStreamBuf.cxx +++ b/dtool/src/dtoolutil/pandaFileStreamBuf.cxx @@ -267,7 +267,15 @@ close() { _handle = nullptr; #else if (_fd != -1) { - ::close(_fd); + if (::close(_fd) < 0) { +#ifdef NDEBUG + perror("close"); +#else + char *str = (char *)alloca(_filename.size() + 32); + sprintf(str, "close(%d \"%s\")", _fd, _filename.c_str()); + perror(str); +#endif + } } _fd = -1; #endif // _WIN32 diff --git a/panda/src/nativenet/socket_ip.h b/panda/src/nativenet/socket_ip.h index 3c03db2b3b..0589611be3 100644 --- a/panda/src/nativenet/socket_ip.h +++ b/panda/src/nativenet/socket_ip.h @@ -82,7 +82,11 @@ private: inline bool Socket_IP:: ErrorClose() { if (Active()) { - DO_CLOSE(_socket); + if (DO_CLOSE(_socket) != 0) { +#ifndef _WIN32 + perror("Socket_IP::ErrorClose"); +#endif + } } _socket = BAD_SOCKET; @@ -127,7 +131,11 @@ inline Socket_IP:: inline void Socket_IP:: Close() { if (Active()) { - DO_CLOSE(_socket); + if (DO_CLOSE(_socket) != 0) { +#ifndef _WIN32 + perror("Socket_IP::ErrorClose"); +#endif + } } _socket = BAD_SOCKET; diff --git a/pandatool/src/deploy-stub/deploy-stub.c b/pandatool/src/deploy-stub/deploy-stub.c index c9a9272b15..6fb5b1e310 100644 --- a/pandatool/src/deploy-stub/deploy-stub.c +++ b/pandatool/src/deploy-stub/deploy-stub.c @@ -359,7 +359,9 @@ static int setup_logging(const char *path, int append) { dup2(fd, 1); dup2(fd, 2); - close(fd); + if (close(fd) < 0) { + perror("setup_logging: close"); + } return 1; #endif } From 3303bac9026eca3fcb0468fdbc01a13401974528 Mon Sep 17 00:00:00 2001 From: rdb Date: Fri, 9 Feb 2024 15:06:27 +0100 Subject: [PATCH 2/7] x11: Fix error message when xf86dga extension is not found [skip ci] --- panda/src/x11display/x11GraphicsPipe.cxx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/panda/src/x11display/x11GraphicsPipe.cxx b/panda/src/x11display/x11GraphicsPipe.cxx index 974e67dd3c..42327d4582 100644 --- a/panda/src/x11display/x11GraphicsPipe.cxx +++ b/panda/src/x11display/x11GraphicsPipe.cxx @@ -117,7 +117,7 @@ x11GraphicsPipe(const std::string &display) : _XF86DGADirectVideo = nullptr; if (x11display_cat.is_debug()) { x11display_cat.debug() - << "cannot dlopen libXxf86dga.so.1; cursor changing will not work.\n"; + << "cannot dlopen libXxf86dga.so.1; relative mouse mode will not work.\n"; } } From 06b9e3af8b847804a61b59ce6dc60cbd79a3e273 Mon Sep 17 00:00:00 2001 From: rdb Date: Fri, 1 Mar 2024 17:50:48 +0100 Subject: [PATCH 3/7] makepanda: Remove net.py(d) file if present In anticipation of #1466 [skip ci] --- makepanda/makepanda.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/makepanda/makepanda.py b/makepanda/makepanda.py index d88a1cb153..83e56ec6f2 100755 --- a/makepanda/makepanda.py +++ b/makepanda/makepanda.py @@ -3152,7 +3152,9 @@ del_files = ['core.py', 'core.pyc', 'core.pyo', '_core.pyd', '_core.so', 'direct.py', 'direct.pyc', 'direct.pyo', '_direct.pyd', '_direct.so', - 'dtoolconfig.pyd', 'dtoolconfig.so'] + 'dtoolconfig.pyd', 'dtoolconfig.so', + 'net.pyd', 'net.so', + 'net.py', 'net.pyc', 'net.pyo'] for basename in del_files: path = os.path.join(GetOutputDir(), 'panda3d', basename) From 0ce7215ee902bb11410122d959b3b8020c884fcb Mon Sep 17 00:00:00 2001 From: rdb Date: Tue, 12 Mar 2024 15:10:14 +0100 Subject: [PATCH 4/7] interrogate: Fix typo in code Fixes #1627 [skip ci] --- dtool/src/interrogate/interfaceMakerPythonNative.cxx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dtool/src/interrogate/interfaceMakerPythonNative.cxx b/dtool/src/interrogate/interfaceMakerPythonNative.cxx index 163ece8030..0606965fa3 100644 --- a/dtool/src/interrogate/interfaceMakerPythonNative.cxx +++ b/dtool/src/interrogate/interfaceMakerPythonNative.cxx @@ -3814,7 +3814,7 @@ write_function_for_name(ostream &out, Object *obj, // None of the remaps take any keyword arguments, so let's check that // we take none. This saves some checks later on. indent(out, 4) << "if (kwds == nullptr || PyDict_GET_SIZE(kwds) == 0) {\n"; - if (min_args == 1 && min_args == 1) { + if (min_args == 1 && max_args == 1) { indent(out, 4) << " PyObject *arg = PyTuple_GET_ITEM(args, 0);\n"; always_returns = write_function_forset(out, mii->second, min_args, max_args, expected_params, 6, From bfe1c95d298b5a0f8adbf1e690ec5b7a335f94ba Mon Sep 17 00:00:00 2001 From: rdb Date: Tue, 12 Mar 2024 15:29:21 +0100 Subject: [PATCH 5/7] pgraph: Python wrappers for TransformState getters no longer return reference to temporary Fixes #1625 --- panda/src/pgraph/transformState.h | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/panda/src/pgraph/transformState.h b/panda/src/pgraph/transformState.h index 59a47daec7..d6342e9aa5 100644 --- a/panda/src/pgraph/transformState.h +++ b/panda/src/pgraph/transformState.h @@ -132,6 +132,17 @@ PUBLISHED: INLINE bool has_nonzero_shear() const; INLINE bool has_mat() const; +#ifdef CPPPARSER + // Force interrogate to make a copy as a temporary solution for #1625. + LPoint3 get_pos() const; + LVecBase3 get_hpr() const; + LQuaternion get_quat() const; + LQuaternion get_norm_quat() const; + LVecBase3 get_scale() const; + PN_stdfloat get_uniform_scale() const; + LVecBase3 get_shear() const; + LMatrix4 get_mat() const; +#else INLINE const LPoint3 &get_pos() const; INLINE const LVecBase3 &get_hpr() const; INLINE const LQuaternion &get_quat() const; @@ -140,6 +151,7 @@ PUBLISHED: INLINE PN_stdfloat get_uniform_scale() const; INLINE const LVecBase3 &get_shear() const; INLINE const LMatrix4 &get_mat() const; +#endif INLINE LVecBase2 get_pos2d() const; INLINE PN_stdfloat get_rotate2d() const; From c4adc17d55feacc03c00f5a66f0e8412ef8982a9 Mon Sep 17 00:00:00 2001 From: rdb Date: Tue, 12 Mar 2024 15:30:32 +0100 Subject: [PATCH 6/7] display: Fix assorted unreachable code warnings --- panda/metalibs/pandagl/pandagl.cxx | 15 +++++++------- panda/src/display/graphicsStateGuardian.cxx | 22 +++++++-------------- 2 files changed, 14 insertions(+), 23 deletions(-) diff --git a/panda/metalibs/pandagl/pandagl.cxx b/panda/metalibs/pandagl/pandagl.cxx index 1a317fbdca..95c147c75e 100644 --- a/panda/metalibs/pandagl/pandagl.cxx +++ b/panda/metalibs/pandagl/pandagl.cxx @@ -70,25 +70,24 @@ init_libpandagl() { */ int get_pipe_type_pandagl() { -#ifdef HAVE_WGL +#if defined(HAVE_WGL) return wglGraphicsPipe::get_class_type().get_index(); -#endif -#if defined(HAVE_COCOA) +#elif defined(HAVE_COCOA) return CocoaGraphicsPipe::get_class_type().get_index(); + #elif defined(HAVE_CARBON) return osxGraphicsPipe::get_class_type().get_index(); -#endif -#ifdef HAVE_GLX +#elif defined(HAVE_GLX) return glxGraphicsPipe::get_class_type().get_index(); -#endif -#ifdef HAVE_EGL +#elif defined(HAVE_EGL) return eglGraphicsPipe::get_class_type().get_index(); -#endif +#else return 0; +#endif } #if defined(HAVE_EGL) && !defined(USE_X11) diff --git a/panda/src/display/graphicsStateGuardian.cxx b/panda/src/display/graphicsStateGuardian.cxx index 7352afc85c..fb84f0cc96 100644 --- a/panda/src/display/graphicsStateGuardian.cxx +++ b/panda/src/display/graphicsStateGuardian.cxx @@ -1907,6 +1907,8 @@ fetch_specified_texture(Shader::ShaderTexSpec &spec, SamplerState &sampler, const LightAttrib *target_light; _target_rs->get_attrib_def(target_light); + PT(Texture) tex; + // We don't count ambient lights, which would be pretty silly to handle // via this mechanism. size_t num_lights = target_light->get_num_non_ambient_lights(); @@ -1916,28 +1918,21 @@ fetch_specified_texture(Shader::ShaderTexSpec &spec, SamplerState &sampler, Light *light_obj = light.node()->as_light(); nassertr(light_obj != nullptr, nullptr); - PT(Texture) tex; LightLensNode *lln = DCAST(LightLensNode, light.node()); if (lln != nullptr && lln->_shadow_caster) { tex = get_shadow_map(light); } else { tex = get_dummy_shadow_map((Texture::TextureType)spec._desired_type); } - - if (tex != nullptr) { - sampler = tex->get_default_sampler(); - } - return tex; } else { // There is no such light assigned. Bind a dummy shadow map. - PT(Texture) tex = get_dummy_shadow_map((Texture::TextureType)spec._desired_type); - if (tex != nullptr) { - sampler = tex->get_default_sampler(); - } - return tex; + tex = get_dummy_shadow_map((Texture::TextureType)spec._desired_type); } + if (tex != nullptr) { + sampler = tex->get_default_sampler(); + } + return tex; } - break; case Shader::STO_ff_stage_i: { @@ -2005,7 +2000,6 @@ fetch_specified_texture(Shader::ShaderTexSpec &spec, SamplerState &sampler, } return default_add_tex; } - break; case Shader::STO_stage_normal_i: { @@ -2035,7 +2029,6 @@ fetch_specified_texture(Shader::ShaderTexSpec &spec, SamplerState &sampler, } return default_normal_height_tex; } - break; case Shader::STO_stage_gloss_i: { @@ -2088,7 +2081,6 @@ fetch_specified_texture(Shader::ShaderTexSpec &spec, SamplerState &sampler, } return default_normal_height_tex; } - break; case Shader::STO_stage_selector_i: { From 4f7b153c3fe315bb2ff0833427f277f205f37d18 Mon Sep 17 00:00:00 2001 From: rdb Date: Tue, 12 Mar 2024 15:32:44 +0100 Subject: [PATCH 7/7] egg-qtess: Fix an unused variable warning --- pandatool/src/egg-qtess/isoPlacer.cxx | 2 ++ 1 file changed, 2 insertions(+) diff --git a/pandatool/src/egg-qtess/isoPlacer.cxx b/pandatool/src/egg-qtess/isoPlacer.cxx index fda96904e3..0c4cebeefa 100644 --- a/pandatool/src/egg-qtess/isoPlacer.cxx +++ b/pandatool/src/egg-qtess/isoPlacer.cxx @@ -108,12 +108,14 @@ void IsoPlacer:: place(int count, pvector &iso_points) { int i; + /* // Count up the average curvature. double avg_curve = 0.0; for (i = 0; i < _maxi; i++) { avg_curve += _cscore[i]; } avg_curve /= (double)_maxi; + */ // Find all the local maxima in the curvature table. These are bend points. typedef pvector BendPoints;