From 60a4a13e72f18f55a024d6912836fb9583aed67a Mon Sep 17 00:00:00 2001 From: James Lamb Date: Mon, 25 Sep 2023 10:50:35 -0500 Subject: [PATCH] [python-package] remove unnecessary allocations in ctypes code (#6111) --- python-package/lightgbm/basic.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/python-package/lightgbm/basic.py b/python-package/lightgbm/basic.py index c2964fcedd8d..3dfa583a62bb 100644 --- a/python-package/lightgbm/basic.py +++ b/python-package/lightgbm/basic.py @@ -479,7 +479,7 @@ def _get_all_param_aliases() -> Dict[str, List[str]]: buffer_len = 1 << 20 tmp_out_len = ctypes.c_int64(0) string_buffer = ctypes.create_string_buffer(buffer_len) - ptr_string_buffer = ctypes.c_char_p(*[ctypes.addressof(string_buffer)]) + ptr_string_buffer = ctypes.c_char_p(ctypes.addressof(string_buffer)) _safe_call(_LIB.LGBM_DumpParamAliases( ctypes.c_int64(buffer_len), ctypes.byref(tmp_out_len), @@ -488,7 +488,7 @@ def _get_all_param_aliases() -> Dict[str, List[str]]: # if buffer length is not long enough, re-allocate a buffer if actual_len > buffer_len: string_buffer = ctypes.create_string_buffer(actual_len) - ptr_string_buffer = ctypes.c_char_p(*[ctypes.addressof(string_buffer)]) + ptr_string_buffer = ctypes.c_char_p(ctypes.addressof(string_buffer)) _safe_call(_LIB.LGBM_DumpParamAliases( ctypes.c_int64(actual_len), ctypes.byref(tmp_out_len), @@ -3315,7 +3315,7 @@ def _get_loaded_param(self) -> Dict[str, Any]: buffer_len = 1 << 20 tmp_out_len = ctypes.c_int64(0) string_buffer = ctypes.create_string_buffer(buffer_len) - ptr_string_buffer = ctypes.c_char_p(*[ctypes.addressof(string_buffer)]) + ptr_string_buffer = ctypes.c_char_p(ctypes.addressof(string_buffer)) _safe_call(_LIB.LGBM_BoosterGetLoadedParam( self._handle, ctypes.c_int64(buffer_len), @@ -3325,7 +3325,7 @@ def _get_loaded_param(self) -> Dict[str, Any]: # if buffer length is not long enough, re-allocate a buffer if actual_len > buffer_len: string_buffer = ctypes.create_string_buffer(actual_len) - ptr_string_buffer = ctypes.c_char_p(*[ctypes.addressof(string_buffer)]) + ptr_string_buffer = ctypes.c_char_p(ctypes.addressof(string_buffer)) _safe_call(_LIB.LGBM_BoosterGetLoadedParam( self._handle, ctypes.c_int64(actual_len), @@ -4078,7 +4078,7 @@ def model_to_string( buffer_len = 1 << 20 tmp_out_len = ctypes.c_int64(0) string_buffer = ctypes.create_string_buffer(buffer_len) - ptr_string_buffer = ctypes.c_char_p(*[ctypes.addressof(string_buffer)]) + ptr_string_buffer = ctypes.c_char_p(ctypes.addressof(string_buffer)) _safe_call(_LIB.LGBM_BoosterSaveModelToString( self._handle, ctypes.c_int(start_iteration), @@ -4091,7 +4091,7 @@ def model_to_string( # if buffer length is not long enough, re-allocate a buffer if actual_len > buffer_len: string_buffer = ctypes.create_string_buffer(actual_len) - ptr_string_buffer = ctypes.c_char_p(*[ctypes.addressof(string_buffer)]) + ptr_string_buffer = ctypes.c_char_p(ctypes.addressof(string_buffer)) _safe_call(_LIB.LGBM_BoosterSaveModelToString( self._handle, ctypes.c_int(start_iteration), @@ -4146,7 +4146,7 @@ def dump_model( buffer_len = 1 << 20 tmp_out_len = ctypes.c_int64(0) string_buffer = ctypes.create_string_buffer(buffer_len) - ptr_string_buffer = ctypes.c_char_p(*[ctypes.addressof(string_buffer)]) + ptr_string_buffer = ctypes.c_char_p(ctypes.addressof(string_buffer)) _safe_call(_LIB.LGBM_BoosterDumpModel( self._handle, ctypes.c_int(start_iteration), @@ -4159,7 +4159,7 @@ def dump_model( # if buffer length is not long enough, reallocate a buffer if actual_len > buffer_len: string_buffer = ctypes.create_string_buffer(actual_len) - ptr_string_buffer = ctypes.c_char_p(*[ctypes.addressof(string_buffer)]) + ptr_string_buffer = ctypes.c_char_p(ctypes.addressof(string_buffer)) _safe_call(_LIB.LGBM_BoosterDumpModel( self._handle, ctypes.c_int(start_iteration),