3 ms·
"In order to avoid this unbounded recursion, I have to implement a parallel code-path for `dir` by creating a `safe_PyObject_Dir`" I thought this was intended
by Someone 12y ago
"In order to avoid this unbounded recursion, I have to implement a parallel code-path for `dir` by creating a `safe_PyObject_Dir`"
I thought this was intended to not be used. Why then, don't you do the (in)sane thing and set a global flag "I am calling `dir`; ignore calls to PyObject_GetAttr, please", and check that flag in your patch? (if you aren't sure whether a single global flag will do, use a thread-local one, but I think/guess that is overkill, given Python's GIL)
And, by the way, this is how extensions in Mac OS pre Mac OS X did their magic. It got really fun when multiple extensions tried to patch up the same OS call, or when the OS would unpatch your patches. For some OS calls, that would happen when the Finder launched, for others whenever an application launched.
- jamesdutc 12y agoSetting a flag is another approach. There's already an extension mechanism for storing arbitrary per-thread state in a dictionary object, accessible via `PyThreadState_GetDict`. https://hg.python.org/cpython/file/1d708436831a/Python/pystate.c#l361 https://hg.python.org/cpython/file/1d708436831a/Python/pysta... However, implementing the parallel code-path turned out to be easier (just a bit of cut & paste) and a bit saner to debug. `PyObject_Dir` tries to look up a few attributes on the object (`__dir__`, `__bases__`, &c.) which may not exist. There's a high likelihood of multiple AttributeErrors each time through. Any documentation on Mac OS patches? Would be very curious to learn more about how these worked out in practice!
- Someone 12y agoThat old MacOS stuff is hard to find on the Internet. One thing I did find that gets a bit close is http://www.mactech.com/articles/develop/issue_16/Radcliffe_final.html http://www.mactech.com/articles/develop/issue_16/Radcliffe_f.... Problem is that it likely is a bit hard to follow if you do not know about the stuff. Moreover, it doesn't really show patching itself. I am fairly sure there is some article about patching in those archives of Develop, but I couldn't find it. Wikipedia has little, too. http://en.m.wikipedia.org/wiki/INIT http://en.m.wikipedia.org/wiki/INIT may provide some starting points.