Issue1328

classification
Title: ctypes for jython
Type: behaviour Severity: normal
Components: Versions: Jython 2.7
Milestone:
process
Status: closed Resolution: out of date
Dependencies: Superseder:
Assigned To: Nosy List: Arfrever, fijal, fwierzbicki, kfitch42, vito, zyasoft
Priority: low Keywords: patch

Created on 2009-04-26.02:15:18 by fijal, last changed 2015-05-04.15:55:53 by zyasoft.

Files
File name Uploaded Description Edit Remove
out.diff fijal, 2009-04-26.02:15:15
out2.diff fijal, 2009-04-26.02:15:32
Messages
msg4596 (view) Author: fijal (fijal) Date: 2009-04-26.02:15:14
This is a basic patch that adds enough of _rawffi to actually run some
simple ctypes code. It should be fairly obvious how to proceed now.

Issues:
* make ant create a test .so. I have more tests, but unittest has no way
  to skip. Bummer
* I have disabled java security. jna has to be fixed somehow for that.
* More care is needed about field sizes/alignment, I want ant do it
  for me, hardcoding sucks.
* It's unfinished

but the example:
import ctypes
ctypes.CDLL('libc.so.6').time(0)

works on my machine :-)

out2.diff is against CPythonLib
msg4597 (view) Author: fijal (fijal) Date: 2009-04-26.02:15:32
I HATE ROUNDUP
msg4602 (view) Author: Kevin Fitch (kfitch42) Date: 2009-04-28.02:02:41
I wanted to play around with this, so I applied both patches. Then ran
it, and typed in your example ... it failed because it couldn't import
ctypes. I look again and realized that you didn't include ctypes itself
... so I copied it out of my CPython install (Python v2.5.2 from Ubuntu
8.04.2 x64) The ctypes/__init__.py mentions something about being
v1.0.3. At this point I get:
Jython 2.5b3+ (trunk:6266M, Apr 27 2009, 21:48:35) 
[Java HotSpot(TM) 64-Bit Server VM (Sun Microsystems Inc.)] on java1.5.0_16
Type "help", "copyright", "credits" or "license" for more information.
>>> import ctypes
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/kfitch/projects/jython/dist/Lib/ctypes/__init__.py", line
155, in <module>
    _check_size(py_object, "P")
  File "/home/kfitch/projects/jython/dist/Lib/ctypes/__init__.py", line
143, in _check_size
    actual, required = sizeof(typ), calcsize(typecode)
struct.error: bad char in struct format
>>> 

I seems that the "P" char is not understood by the struct implementation
in Jython (it works in my CPython).
msg4603 (view) Author: fijal (fijal) Date: 2009-04-28.04:44:00
No, I included ctypes and out2.diff is a patch for that, but you need to
copy ctypes from CPythonLib on your own to dist (or link it or something).

I didn't yet figure out how to make jython pick up those :-)
msg4604 (view) Author: Kevin Fitch (kfitch42) Date: 2009-04-28.10:27:05
Ahh... I get it now. I am a little slow sometimes :) ... anyway if you
want ctypes copied into the dist you can include the line:

ctypes/**

in the CPythonLib.includes file in the root directory of the project. 
Now I can run your test, and it segfaults, but I suspect that is because
I am running a 64bit box w/ 64bit java.
msg4606 (view) Author: fijal (fijal) Date: 2009-04-28.16:30:17
On Tue, Apr 28, 2009 at 4:27 AM, Kevin Fitch <report@bugs.jython.org> wrote:
>
> Kevin Fitch <kfitch42@gmail.com> added the comment:
>
> Ahh... I get it now. I am a little slow sometimes :) ... anyway if you
> want ctypes copied into the dist you can include the line:
>
> ctypes/**
>
> in the CPythonLib.includes file in the root directory of the project.
> Now I can run your test, and it segfaults, but I suspect that is because
> I am running a 64bit box w/ 64bit java.
>

That is very likely true.
msg4616 (view) Author: fijal (fijal) Date: 2009-04-29.04:40:00
I created the branch called ctypes-via-rawffi, so those patches are no
longer valid. Please note that it is 32bit *only* for now.
msg6006 (view) Author: Jim Baker (zyasoft) Date: 2010-08-22.23:13:16
There's a partial implementation of ctypes in Jython now. Completion will presumably be in 2.6.
msg7850 (view) Author: Frank Wierzbicki (fwierzbicki) Date: 2013-02-27.18:25:33
Can this be closed now? The partial ctypes we have includes these patches right?
msg9002 (view) Author: Vito (vito) Date: 2014-09-14.06:40:08
It loads the ctypes lib but not the util lib
from ctypes.util import find_library
ImportError: No module named util
msg10012 (view) Author: Jim Baker (zyasoft) Date: 2015-05-04.15:55:53
Closing out in favor of #2148
History
Date User Action Args
2015-05-04 15:55:53zyasoftsetstatus: open -> closed
resolution: out of date
messages: + msg10012
2014-09-14 06:40:09vitosetnosy: + vito
messages: + msg9002
versions: + Jython 2.7
2013-02-27 18:25:33fwierzbickisetmessages: + msg7850
2012-07-02 01:11:23fwierzbickisetnosy: + fwierzbicki
2012-06-18 18:49:07Arfreversetnosy: + Arfrever
2010-08-22 23:13:16zyasoftsetpriority: low
nosy: + zyasoft
messages: + msg6006
2009-04-29 04:40:06fijalsetmessages: + msg4616
2009-04-28 16:30:17fijalsetmessages: + msg4606
2009-04-28 10:27:06kfitch42setmessages: + msg4604
2009-04-28 04:44:13fijalsetmessages: + msg4603
2009-04-28 02:02:42kfitch42setnosy: + kfitch42
messages: + msg4602
2009-04-26 02:15:32fijalsetfiles: + out2.diff
messages: + msg4597
2009-04-26 02:15:18fijalcreate