Issue2780

classification
Title: Update ctypes/jffi to Python 2.7 and test
Type: behaviour Severity: normal
Components: Library Versions:
Milestone:
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: jeff.allen, stefan.richthofer
Priority: normal Keywords:

Created on 2019-06-21.21:57:59 by jeff.allen, last changed 2019-06-26.07:13:34 by jeff.allen.

Messages
msg12562 (view) Author: Jeff Allen (jeff.allen) Date: 2019-06-21.21:57:59
Our implementation of ctypes sits on top of jffi. We upgrade the JARs occasionally, but unfortunately, the code on our side is 10 years old. Except in a few of the source files, I have not found a shred of documentation.

ctypes doesn't get exercised in the regression tests, because test_ctypes does not find a module _ctypes. If I dig out ctypes.tests.runtests specially from lib-python, it fails in a way that suggests ctypes moved on from Python 2.5 and ours didn't. So I think the fix is to enable test_ctypes for Jython, then work off the failures.

I bring this up because of https://github.com/jythontools/jython/issues/147, which we should fix at the same time. If it had been tested, I would have noticed the bug when futzing around in my Chinese persona.

As this is a late arrival, and we've managed so far, I'm inclined to leave it to 2.7.3.
msg12564 (view) Author: Stefan Richthofer (stefan.richthofer) Date: 2019-06-22.07:22:14
Also see https://bugs.jython.org/issue2148.
Current JyNI can use a fair amount of CPython's ctypes. E.g. sufficient for some PyOpenGL (on Linux). However, JyNI is still experimental and introduces a larger overhead than jffi (I guess).
That said, did you ever look at ctypes codebase? It's large and complicated, 10k lines of code the main c file alone. I remember debugging JyNI in context of ctypes was a nightmare. OTOH I never looked into jffi, so no idea how straight forward a port would be. Though, I suspect it would be *plenty* of work. I'm not confident it would be realistic to tackle this in foreseeable future with the few active developers that are currently around.

From that point of view I would recommend to simply advice users to try using current jffi-based version and if it's not sufficient use original ctypes through JyNI.

You're right that's an issue for 2.7.3 (if there will be a 2.7.3). I would rather recommend to scope it for Jython 3.
msg12566 (view) Author: Jeff Allen (jeff.allen) Date: 2019-06-26.07:13:34
Interesting link, thanks. There is quite a lot of code in our jffi module, some of which I suspect is copied from JRuby.

Nothing indicates it is incomplete. The first test failure is about a missing type, but I attributed that to a 2.7 difference from 2.5, so it looked like an exercise in updating. I'll happily take Jim's word that it was never finished, however.

There may be a lot of lines in _ctypes, but at least some are comment. One interface is well commented in our jffi module. After that, practically nothing. To understand, explain and complete this would be an interesting project, but possibly challenging, whether in 2.7.x or 3.
History
Date User Action Args
2019-06-26 07:13:34jeff.allensetmessages: + msg12566
2019-06-22 07:22:15stefan.richthofersetnosy: + stefan.richthofer
messages: + msg12564
2019-06-21 21:57:59jeff.allencreate