[Python-Dev] Lost sight
I have virtually completely lost the sight of my right eye (and the loss is quickly progresses) and the sight of my left eye is weak. That is why my activity as a core developer was decreased significantly at recent time. My apologies to those who are waiting for my review. I will do it slowly. ___ Python-Dev mailing list Python-Dev@python.org https://mail.python.org/mailman/listinfo/python-dev Unsubscribe: https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com
Re: [Python-Dev] ctypes: is it intentional that id() is the only way to get the address of an object?
On 1/18/19, Steven D'Aprano wrote: > On Thu, Jan 17, 2019 at 07:50:51AM -0600, eryk sun wrote: >> >> It's kind of dangerous to pass an object to C without an increment of >> its reference count. > > "Kind of dangerous?" How dangerous? I take that back. Dangerous is too strong of a word. It can be managed if we're careful to avoid expressions like c_function(id(f())). Using py_object simply avoids that problem. Bear with me while I make a few more comments about py_object, even though it's straying off topic. For a type "O" argument (i.e. py_object is in the function's `argtypes`), we might be able to borrow the reference from the argument tuple. As implemented, however, the argument actually keeps its own reference. For example, we can observe this by calling the from_param method: >>> b = bytearray(b'spam') >>> arg = ctypes.py_object.from_param(b) >>> print(arg) >>> print(arg._obj) bytearray(b'spam') This is due to the type "O" setfunc, which needs to keep a reference to the object when setting the value of a py_object instance. The reference is stored as the _objects attribute. (For non-simple pointer and aggregate types, _objects is instead a dict keyed by the index as a hexadecimal string.) (The getfunc and setfunc of a simple ctypes object are called to get and set the value, which also includes cases in which we don't have an actual py_object instance, such as function call arguments; pointer and array indexes; and struct and union fields. These functions are defined in Modules/_ctypes/cfield.c.) IMO, a downside of py_object is that it's a simple type, so the getfunc gets called automatically when getting fields or indexes. This is annoying for py_object since a NULL value raises ValueError. Returning None in this case isn't possible, in contrast to other simple pointer types. We can work around this by subclassing py_object. For example: >>> a1 = (ctypes.py_object * 1)() >>> a1[0] Traceback (most recent call last): File "", line 1, in ValueError: PyObject is NULL py_object = type('py_object', (ctypes.py_object,), {}) >>> a2 = (py_object * 1)() >>> a2[0] Then, like all ctypes pointers, a false boolean value means it's NULL: >>> bool(a2[0]) False >>> a2[0] = b'spam' >>> bool(a2[0]) True py_object doesn't help if a library holds onto the pointer and tries to use it later on. For example, with Python's C API there are functions that 'steal' a reference (with the assumption that it's a newly created object, in which case it's more like 'claiming'), such as PyTuple_SetItem. In this case, we need to increment the reference count via Py_IncRef. py_object can be returned from a callback without leaking a reference, assuming the library manages the new reference. In contrast, other types that need memory support have to leak a reference (e.g. c_wchar_p, i.e. type "Z", needs a capsule object for the wchar_t buffer). In case of a leak, we get warned with RuntimeWarning('memory leak in callback function.'). > If I am reading this correctly, I think you are saying that using id() > in this way is never(?) correct. Yes, it's incorrect, but I've been guilty of using id() like this, too, because it's convenient. Perhaps we could provide a function that's explicitly specified to return the address, if implemented. Maybe call it sys.getaddress()? In my first reply, I provided two alternatives that use ctypes to return the address instead of id(). So there's that as well. The fine print is that ctypes is optional in the standard library. Platforms and implementations don't have to support it. ___ Python-Dev mailing list Python-Dev@python.org https://mail.python.org/mailman/listinfo/python-dev Unsubscribe: https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com
Re: [Python-Dev] Lost sight
On 19/01/2019 11.12, Serhiy Storchaka wrote: > I have virtually completely lost the sight of my right eye (and the loss > is quickly progresses) and the sight of my left eye is weak. That is why > my activity as a core developer was decreased significantly at recent > time. My apologies to those who are waiting for my review. I will do it > slowly. Oh, I'm sorry to hear that and hope that you'll get better soon. Please take care of yourself! Christian ___ Python-Dev mailing list Python-Dev@python.org https://mail.python.org/mailman/listinfo/python-dev Unsubscribe: https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com
Re: [Python-Dev] ctypes: is it intentional that id() is the only way to get the address of an object?
On Sat, 19 Jan 2019 13:28:06 +1300 Greg Ewing wrote: > Tim Peters wrote: > > > The dict itself keeps the objects alive. > > Yes, but the idea of a cache is that you're free to flush > things out of it to make room for something else without > breaking anything. > > It sounds like MRAB is using ids as weak references, > without the assurance actual weak references give you > that they become invalidated when the refefenced object > goes away, Hmm... That sounds nonsensical to me. By construction, if you're able to get a reference to an object in pure Python, then the object is alive. (by pure Python I'm excluding ctypes hacks or the exploitation of bugs in the CPython object implementation) By the way, you can also have a WeakValueDictionary where keys are ids and values are the corresponding objects, if you need both identity lookup and weak references. Regards Antoine. ___ Python-Dev mailing list Python-Dev@python.org https://mail.python.org/mailman/listinfo/python-dev Unsubscribe: https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com
Re: [Python-Dev] Lost sight
That's sad to hear. Get well soon! On Sat, Jan 19, 2019 at 1:22 PM Christian Heimes wrote: > On 19/01/2019 11.12, Serhiy Storchaka wrote: > > I have virtually completely lost the sight of my right eye (and the loss > > is quickly progresses) and the sight of my left eye is weak. That is why > > my activity as a core developer was decreased significantly at recent > > time. My apologies to those who are waiting for my review. I will do it > > slowly. > > Oh, I'm sorry to hear that and hope that you'll get better soon. Please > take care of yourself! > > Christian > ___ > Python-Dev mailing list > Python-Dev@python.org > https://mail.python.org/mailman/listinfo/python-dev > Unsubscribe: > https://mail.python.org/mailman/options/python-dev/andrew.svetlov%40gmail.com > -- Thanks, Andrew Svetlov ___ Python-Dev mailing list Python-Dev@python.org https://mail.python.org/mailman/listinfo/python-dev Unsubscribe: https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com
Re: [Python-Dev] Lost sight
On Sat, 19 Jan 2019 at 10:15, Serhiy Storchaka wrote: > > I have virtually completely lost the sight of my right eye (and the loss > is quickly progresses) and the sight of my left eye is weak. That is why > my activity as a core developer was decreased significantly at recent > time. My apologies to those who are waiting for my review. I will do it > slowly. Sorry to hear about that! Take care of yourself, your health is the most important thing. Best wishes, Paul ___ Python-Dev mailing list Python-Dev@python.org https://mail.python.org/mailman/listinfo/python-dev Unsubscribe: https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com
Re: [Python-Dev] Lost sight
Sorry to hear this, Serhiy. Hope you'll get better soon. Yury On Sat, Jan 19, 2019 at 5:15 AM Serhiy Storchaka wrote: > > I have virtually completely lost the sight of my right eye (and the loss > is quickly progresses) and the sight of my left eye is weak. That is why > my activity as a core developer was decreased significantly at recent > time. My apologies to those who are waiting for my review. I will do it > slowly. > > ___ > Python-Dev mailing list > Python-Dev@python.org > https://mail.python.org/mailman/listinfo/python-dev > Unsubscribe: > https://mail.python.org/mailman/options/python-dev/yselivanov.ml%40gmail.com -- Yury ___ Python-Dev mailing list Python-Dev@python.org https://mail.python.org/mailman/listinfo/python-dev Unsubscribe: https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com
Re: [Python-Dev] Lost sight
Sorry to hear that. Please take care. On Sat, Jan 19, 2019, 4:15 AM Serhiy Storchaka I have virtually completely lost the sight of my right eye (and the loss > is quickly progresses) and the sight of my left eye is weak. That is why > my activity as a core developer was decreased significantly at recent > time. My apologies to those who are waiting for my review. I will do it > slowly. > > ___ > Python-Dev mailing list > Python-Dev@python.org > https://mail.python.org/mailman/listinfo/python-dev > Unsubscribe: > https://mail.python.org/mailman/options/python-dev/mariatta%40python.org > ___ Python-Dev mailing list Python-Dev@python.org https://mail.python.org/mailman/listinfo/python-dev Unsubscribe: https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com
Re: [Python-Dev] Lost sight
Hi Serhiy, That's terrible and sounds frightening. Were you able to get medical care to get a diagnosis and treatment if needed? We all hope your condition improves. --Chris On Sat, Jan 19, 2019 at 2:14 AM Serhiy Storchaka wrote: > > I have virtually completely lost the sight of my right eye (and the loss > is quickly progresses) and the sight of my left eye is weak. That is why > my activity as a core developer was decreased significantly at recent > time. My apologies to those who are waiting for my review. I will do it > slowly. > > ___ > Python-Dev mailing list > Python-Dev@python.org > https://mail.python.org/mailman/listinfo/python-dev > Unsubscribe: > https://mail.python.org/mailman/options/python-dev/chris.jerdonek%40gmail.com ___ Python-Dev mailing list Python-Dev@python.org https://mail.python.org/mailman/listinfo/python-dev Unsubscribe: https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com
Re: [Python-Dev] Lost sight
Really sorry Serhiy, hope the best for you, take care. Firstly the most important thing, is your health. Stéphane > Le 19 janv. 2019 à 23:25, Mariatta Wijaya a écrit : > > Sorry to hear that. Please take care. > >> On Sat, Jan 19, 2019, 4:15 AM Serhiy Storchaka > I have virtually completely lost the sight of my right eye (and the loss >> is quickly progresses) and the sight of my left eye is weak. That is why >> my activity as a core developer was decreased significantly at recent >> time. My apologies to those who are waiting for my review. I will do it >> slowly. >> >> ___ >> Python-Dev mailing list >> Python-Dev@python.org >> https://mail.python.org/mailman/listinfo/python-dev >> Unsubscribe: >> https://mail.python.org/mailman/options/python-dev/mariatta%40python.org > ___ > Python-Dev mailing list > Python-Dev@python.org > https://mail.python.org/mailman/listinfo/python-dev > Unsubscribe: > https://mail.python.org/mailman/options/python-dev/stephane%40wirtel.be ___ Python-Dev mailing list Python-Dev@python.org https://mail.python.org/mailman/listinfo/python-dev Unsubscribe: https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com