Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[python-package] remove unnecessary allocations in ctypes code #6111

Merged
merged 1 commit into from
Sep 25, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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