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

Can't set alert_mask to lt.alert.category_t.all_categories in Python bindings #5848

Closed
lucybythec opened this issue Jan 10, 2021 · 2 comments
Labels

Comments

@lucybythec
Copy link

In #5831, the following code was suggested:

settings = {'alert_mask': lt.alert.category_t.all_categories}
lt_session = lt.session(settings)

Contrary to expectations, this code does not work.

The problem is that lt.alert.category_t.all_categories does not fit into a signed 32-bit integer. As a result, an exception ("bad numeric conversion: positive overflow") is thrown in make_settings_pack when parsing the dict, but caught and silently discarded.

It works with this patch:

diff --git a/bindings/python/src/alert.cpp b/bindings/python/src/alert.cpp
index a004bda68..9652f78d3 100644
--- a/bindings/python/src/alert.cpp
+++ b/bindings/python/src/alert.cpp
@@ -346,7 +346,7 @@ void bind_alert()
         s.attr("piece_progress_notification") = alert::piece_progress_notification;
         s.attr("upload_notification") = alert::upload_notification;
         s.attr("block_progress_notification") = alert::block_progress_notification;
-        s.attr("all_categories") = alert::all_categories;
+        s.attr("all_categories") = alert::all_categories & INT_MAX;
     }
 
     {

Perhaps the C++ exception should be converted to a Python error?

Using libtorrent d5b27ee on Linux.

@arvidn
Copy link
Owner

arvidn commented Jan 10, 2021

I think this patch solves it for any value > INT_MAX and < UINT_MAX. #5849
It's against the 1.2 branch but should apply cleanly against master as well, I would think.

@stale
Copy link

stale bot commented Apr 10, 2021

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label Apr 10, 2021
@stale stale bot closed this as completed Apr 30, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants