-
Notifications
You must be signed in to change notification settings - Fork 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
Python/C inconsistency: Cannot store raw Persistent
objects in cache
#133
Comments
Thank you for the excellent overview of the current problem. I have no idea what the cause of the problem is, nor how to fix it. But I do know one thing. Often just discussing a problem with others helps. Maybe you could you be so kind as to explain how you think how this works, and what you have checked so far. By explaining your mental model of the system, one of the erudite developers on this mailing list may be able to point out what you are missing. Chris |
IIRC classes with |
Right. Except, it turns out, on PyPy. That's why the test passes there. >>>> class Foo(object):
.... __slots__ = ()
....
>>>> import weakref
>>>> weakref.ref(Foo())
<weakref at 0x000000010ff79500; to 'Foo'>
I think so, yes, at the cost of (1) increased size for all instances and (2) introducing a different incompatibility: CPersistent objects cannot be weakly referenced. In practice that's probably not very important, and since the main production use of the pure-Python implementation should be on PyPy (CPython+pure-Python is best for debugging and testing) where they can already be weakly referenced one could argue that it's even slightly more consistent, if one squints at it just right. At any rate, I haven't thought of any other solution yet either. |
How come CPersistent objects do not get the "TypeError: cannot create weak reference to ..." error then, if they don't support weakrefs? |
Because the C cache doesn’t use weakrefs. At least, not at the Python level. Internally it cheats the ref counting rules, and arranges for the C Persistent class to directly notify it when an instance is deallocated. |
…nt objects. Fixes #133. But there's a bug right now, this currently crashes on PyPy on my machine with malloc use-after-free errors (or segfaults, depending on if GC is run explicitly). So lifetime management is not yet correct.
…nt objects. Except on PyPy, where we can already weakref them automatically. Fixes #133.
…nt objects. Except on PyPy, where we can already weakref them automatically. Fixes #133.
The C implementation lets you store basic
Persistent
instances in the cache:But the pure-Python implementation does not:
This creates a test failure in ZODB:
(Why don't we see this failure running ZODB with PyPy? I'm not sure, but I'd guess that we don't even try to run this test; for some reason, PyPy runs only 814 ZODB unit tests while CPython runs 1185. In total, PyPy runs 1313 tests while CPython runs 1684 tests.)
The text was updated successfully, but these errors were encountered: