Skip to content

Fix a segfault in iterator of a ConfigParser section #1682

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

Merged
merged 1 commit into from
Dec 10, 2024

Conversation

hroncok
Copy link
Contributor

@hroncok hroncok commented Dec 6, 2024

An iterator should return self on __iter__.

So that this works:

>>> it1 = iter(sectObj)
>>> it2 = iter(it1)
>>> it1 is it2
True

Previously, this iterator did not return self on __iter__, it was like this:

class PreserveOrderMapStringStringIterator(object):
...
def __iter__(self):
    return _common_types.PreserveOrderMapStringStringIterator___iter__(self)

And that returned a new Python object.

This fixes https://bugzilla.redhat.com/2330562 by avoiding a second iterator object.

My SWIG skills are close to zero,
perhaps this is not the best way to return self, but it seems to work.

@hroncok
Copy link
Contributor Author

hroncok commented Dec 8, 2024

FWIW I tried to research a better way to return self directly from the SWIG code, but I found nothing that actually works.

@@ -71,10 +71,6 @@ template<class T>
class Iterator {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Side note: I am not entirely sure why this class exists in this file as well.

An iterator should return self on __iter__.

So that this works:

    >>> it1 = iter(sectObj)
    >>> it2 = iter(it1)
    >>> it1 is it2
    True

Previously, this iterator did not return self on __iter__, it was like this:

    class PreserveOrderMapStringStringIterator(object):
        ...
        def __iter__(self):
            return _common_types.PreserveOrderMapStringStringIterator___iter__(self)

And that returned a new Python object.

This fixes https://bugzilla.redhat.com/2330562 by avoiding a second iterator object.

My SWIG skills are close to zero,
perhaps this is not the best way to return self, but it seems to work.
@hroncok
Copy link
Contributor Author

hroncok commented Dec 10, 2024

dnf5 has the entire Iterator written in Python which might be a possible solution as well: https://github.com/rpm-software-management/dnf5/blob/ff1ac05c43a4fbf022aedaeef9b6ba49a47a4e1f/bindings/libdnf5/common.i#L104C7-L104C15

Copy link
Member

@m-blaha m-blaha left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

@m-blaha m-blaha merged commit f3302a8 into rpm-software-management:dnf-4-master Dec 10, 2024
6 of 9 checks passed
@hroncok hroncok deleted the iter_self branch December 10, 2024 12:12
jan-kolarik added a commit to rpm-software-management/dnf that referenced this pull request Dec 10, 2024
jan-kolarik added a commit to rpm-software-management/dnf that referenced this pull request Dec 10, 2024
jan-kolarik added a commit to rpm-software-management/dnf that referenced this pull request Dec 10, 2024
jan-kolarik added a commit to rpm-software-management/dnf that referenced this pull request Dec 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants