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

Support object types as values. #8

Merged
merged 9 commits into from
May 21, 2014

Conversation

b4hand
Copy link
Contributor

@b4hand b4hand commented May 19, 2014

Fixes #7.

def __dealloc__(self):
cdef cpython.PyObject *o
if self._trie:
for k in self.iterkeys():
Copy link
Member

Choose a reason for hiding this comment

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

I suspect iterkeys() method is a Python attribute; it can be already deallocated when __dealloc__ is called. This may explain the segfaults on Travis (but maybe there is some other issue).

@kmike
Copy link
Member

kmike commented May 19, 2014

Getting all these INCREFs / DECREFs right is tricky; I don't have much experience with them and haven't checked your implementation in details yet. For example, according to Wiki, <object> o should increase the refcount, but you're also increasing it. I think it is better to inspect the generated C code (check the generated html file), and maybe even add some tests for garbage collection.

@b4hand
Copy link
Contributor Author

b4hand commented May 19, 2014

You're right about the extra Py_XINCREF because of the <object> o cast. I had read the docs that stated the cast implies an INCREF, but must have missed that invocation.

@b4hand
Copy link
Contributor Author

b4hand commented May 19, 2014

FWIW, I was able to test with Python 2.7 and Python 3.2 on my machine using virtualenv, and they both worked. I can't seem to get your tox setup to work locally, so I wasn't able to run it all combined.

@b4hand
Copy link
Contributor Author

b4hand commented May 20, 2014

Technically the change for 6475ecf is a bug in the original code. I bet if I insert a large enough integer value into the Trie and then try to get it back, the value will be truncated.

I can push that change as a separate PR with a single test if you'd prefer it.

@b4hand
Copy link
Contributor Author

b4hand commented May 21, 2014

I think I've addressed all your comments including the leak check test. (Writing that test actually caused me to discover a bug I introduced in the 8b96e7b commit.)

def test_get():
trie = hat_trie.IntTrie()

assert trie.get('foo') is -1
Copy link
Member

Choose a reason for hiding this comment

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

it is better to use == because the fact that -1 is always the same object is an interpreter implementation detail

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ooops, that a copy/paste error from it being None in Trie.

@kmike
Copy link
Member

kmike commented May 21, 2014

The PR looks very good, thanks!

kmike added a commit that referenced this pull request May 21, 2014
@kmike kmike merged commit d6b14d9 into pytries:master May 21, 2014
@b4hand b4hand deleted the support-object-values branch May 21, 2014 20:52
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.

Is there any particular reason you don't allow storing arbitrary Python objects as values?
2 participants