Skip to content

Support for with-statement (context manager) for the reader object #28

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

Closed
wants to merge 3 commits into from
Closed

Conversation

Tethik
Copy link

@Tethik Tethik commented Mar 9, 2017

I made an attempt at implementing #21. Let me know what you think.

@Tethik
Copy link
Author

Tethik commented Mar 9, 2017

Not sure why travis fails. It looks like it ignores my additions? I tested locally with both python2.7 and python3.

@oschwald
Copy link
Member

This is a good start for the pure Python reader. Travis is failing because the C extension has not been updated.

@Tethik
Copy link
Author

Tethik commented Mar 10, 2017

Ah, that makes sense. I'll see if I can update the C extension too. Brb

Joakim Uddholm added 2 commits March 10, 2017 16:49
…open to __init__. Changed so that trying to reopen a closed reader throws an exception, similar to get.
@Tethik
Copy link
Author

Tethik commented Mar 10, 2017

Tests pass now on Travis. Is it failing because of the lint now? As far as I can see the lint errors are from before my changes.

Please review the C changes as it's my first time coding in a C extension for python

return NULL;
}

Py_INCREF(self);
Copy link
Member

Choose a reason for hiding this comment

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

If you are incrementing the reference count here, I think you would need to decrement it in Reader__exit__.

Was this incrementing necessary to prevent errors? Without checking, I am not sure whether the Python interpreter increments the reference count for us or whether this is necessary.

Copy link
Member

Choose a reason for hiding this comment

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

After some testing, I think the reference counting is correct as you have it.

Copy link
Author

Choose a reason for hiding this comment

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

I wasn't sure either. I got a segfault when not using Py_INCREF though.

Looking at other peoples code (pysqlite) it looks like they do the same thing:
https://github.com/ghaering/pysqlite/blob/e728ffbcaeb7bfae1d6b7165369bd0ae16cabf95/src/connection.c#1554

@oschwald
Copy link
Member

Thanks! This looks good. I had one comment and question about the reference counting.

@oschwald
Copy link
Member

Thanks! Merged from the command line and released as 1.3.0.

@oschwald oschwald closed this Mar 13, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants