Skip to content

Commit

Permalink
[python-package] remove unnecessary allocations in ctypes code (#6111)
Browse files Browse the repository at this point in the history
  • Loading branch information
jameslamb authored Sep 25, 2023
1 parent 7c9a985 commit 60a4a13
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions python-package/lightgbm/basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand All @@ -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),
Expand Down Expand Up @@ -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),
Expand All @@ -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),
Expand Down Expand Up @@ -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),
Expand All @@ -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),
Expand Down Expand Up @@ -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),
Expand All @@ -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),
Expand Down

0 comments on commit 60a4a13

Please sign in to comment.