cfbolz changed the topic of #pypy to: #pypy PyPy, the flexible snake https://pypy.org | IRC logs: https://quodlibet.duckdns.org/irc/pypy/latest.log.html#irc-end and https://libera.irclog.whitequark.org/pypy | the pypy angle is to shrug and copy the implementation of CPython as closely as possible, and staying out of design decisions
joshszep_work has quit [Ping timeout: 245 seconds]
derpydoo has joined #pypy
derpydoo has quit [Ping timeout: 264 seconds]
jcea has quit [Ping timeout: 240 seconds]
otisolsen70 has joined #pypy
otisolsen70 has quit [Remote host closed the connection]
otisolsen70 has joined #pypy
lehmrob has joined #pypy
lehmrob has quit [Ping timeout: 265 seconds]
lehmrob has joined #pypy
Techcable has quit [Ping timeout: 250 seconds]
Techcable has joined #pypy
Techcable has quit [Read error: Connection reset by peer]
Techcable has joined #pypy
Blob has joined #pypy
<Blob> Hey all. I'm trying to understand an issue raised at my work by a previously employed dev. I'm pretty entry-level with python, so I would really appreciate if someone can help put me on the right path with the issue.
<Blob> We have a tool that uses CFFI to generate modules w/ the necessary bindings to run C code within our Python application (with a little help from pycparser for pre-processing). The stack context of that module is entered by the standard python interpreter the module runs, and then returns whatever we asked it to.
<Blob> The error the previous dev describes is that 'python exception objects are stored in the thread state, then checked for in the interpreter loop' and that 'if the path of execution for that exception returns to the C module, the module continues to execute until it returns to the Python handler'. So those exceptions lead to undefined behaviour. It
<Blob> also mentions div/0, segfault and tight loops aren't handled correctly, though I think that's a totally separate problem.
<Blob> So my questions - how can I access the exception handler used by CFFI so I can ensure it re-raises python exceptions rather than continuing execution? Am I right in thinking pycparser would be a good way to insert checks into the C code to handle the problems I've mentioned? Would PyPy as an interpreter handle any of the issues I've raised by
<Blob> design?
Techcable has quit [Ping timeout: 240 seconds]
Techcable has joined #pypy
<arigato> Blob: so you mean, you have a Python function that calls a C function (with CFFI) that itself calls back a Python function? and what occurs if the inner Python function raises an exception?
<Blob> arigato : yep, that's what I'm trying to resolve. This is at least an issue raised by a previous developer but I currently am trying to insert some python exceptions using pycparser so that I can actually see what happens
<arigato> I'm not sure I understand what you mean by using pycparser
<arigato> pycparser is just a parser for C, it has nothing to do with any runtime behavior of cffi or python
<arigato> based on what I understand so far, you're looking for https://cffi.readthedocs.io/en/latest/using.html#extern-python-reference, specifying "onerror=" in ffi.def_extern() or ffi.callback()
<Blob> Thanks, you're right to be confused, I'm out of my depth, in honesty. :P My personal guess was to traverse CFFI's generated code using pycparser, then include some wrapper behaviour for any of CFFI's python calls to re-raise their exceptions.
<Blob> And thank you very much! I think the listed callback method is what I'm after. I'll have to test it by writing some python exceptions into a C file and see what happens
lehmrob has quit [Ping timeout: 265 seconds]
jcea has joined #pypy
Blob has quit [Quit: Client closed]
Blob has joined #pypy
<arigato> np, and ah, i see. makes sense
Techcable has quit [Ping timeout: 240 seconds]
Techcable has joined #pypy
joshszep_work has joined #pypy
joshszep_work has quit [Ping timeout: 245 seconds]
Blob has quit [Ping timeout: 245 seconds]
joshszep_work has joined #pypy
otisolsen70 has quit [Quit: Leaving]
pbsds has quit [Ping timeout: 240 seconds]
pbsds has joined #pypy
joshszep_work has quit [Quit: Client closed]
joshszep_work has joined #pypy