This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Need fixer for dl (removed) -> ctypes module
Type: enhancement Stage: resolved
Components: 2to3 (2.x to 3.x conversion tool) Versions:
process
Status: closed Resolution: wont fix
Dependencies: Superseder: Close 2to3 issues and list them here
View: 45544
Assigned To: collinwinter Nosy List: benjamin.peterson, collinwinter, flox, loewis, nedds, nnorwitz, theller
Priority: normal Keywords:

Created on 2008-03-24 06:24 by nnorwitz, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Messages (12)
msg64394 - (view) Author: Neal Norwitz (nnorwitz) * (Python committer) Date: 2008-03-24 06:24
r61837 removed the dl module.  It needs a 2to3 fixer written to use ctypes.
msg64407 - (view) Author: Martin v. Löwis (loewis) * (Python committer) Date: 2008-03-24 09:12
Is it possible to write one? I'm skeptical.
msg64417 - (view) Author: Collin Winter (collinwinter) * (Python committer) Date: 2008-03-24 16:08
Can you list the mapping you'd like to see? I've never used dl or
ctypes, so I'm not immediately sure how to port from one to the other.
msg64419 - (view) Author: Martin v. Löwis (loewis) * (Python committer) Date: 2008-03-24 16:41
In the simplest case, convert

import dl
libc = dl.open("libc.so.6")
iconv = libc.call("iconv_open", "ISO-8859-1", "ISO-8859-2")
print(iconv)

to

import ctypes
libc = ctypes.CDLL("libc.so.6")
iconv = libc.iconv_open("ISO-8859-1", "ISO-8859-2")
print(iconv)

Notice that <dlobject>.call has up to 11 arguments, the first one being
the function name.

Thomas, is it the case that all calls to dl.call can be converted to a
ctypes call without parameter conversion? dl supports these parameter
types:
- byte string, passed as char*
- integers, passed as int
- None, passed as NULL
msg64467 - (view) Author: Thomas Heller (theller) * (Python committer) Date: 2008-03-25 08:44
> In the simplest case, convert
> 
> import dl
> libc = dl.open("libc.so.6")
> iconv = libc.call("iconv_open", "ISO-8859-1", "ISO-8859-2")
> print(iconv)
> 
> to
> 
> import ctypes
> libc = ctypes.CDLL("libc.so.6")
> iconv = libc.iconv_open("ISO-8859-1", "ISO-8859-2")
> print(iconv)
> 
> Notice that <dlobject>.call has up to 11 arguments, the first one being
> the function name.
> 
> Thomas, is it the case that all calls to dl.call can be converted to a
> ctypes call without parameter conversion? dl supports these parameter
> types:
> - byte string, passed as char*
> - integers, passed as int
> - None, passed as NULL

Yes, this is correct.
msg64526 - (view) Author: Thomas Heller (theller) * (Python committer) Date: 2008-03-25 22:41
Thomas Heller schrieb:
> Thomas Heller <theller@ctypes.org> added the comment:
> 
>> In the simplest case, convert
>> 
>> import dl
>> libc = dl.open("libc.so.6")
>> iconv = libc.call("iconv_open", "ISO-8859-1", "ISO-8859-2")
>> print(iconv)
>> 
>> to
>> 
>> import ctypes
>> libc = ctypes.CDLL("libc.so.6")
>> iconv = libc.iconv_open("ISO-8859-1", "ISO-8859-2")
>> print(iconv)
>> 

Currently, in py3k, ctypes only passed bytes objects as char*; so
the strings should be translated to bytes literals:

import ctypes
libc = ctypes.CDLL("libc.so.6")
iconv = libc.iconv_open(b"ISO-8859-1", b"ISO-8859-2")
#                       ^              ^
print(iconv)
msg70466 - (view) Author: Benjamin Peterson (benjamin.peterson) * (Python committer) Date: 2008-07-31 02:02
What's the status of this?
msg70712 - (view) Author: Nick Edds (nedds) Date: 2008-08-04 18:32
If nobody else is interested in or currently in the process of making a
fixer for this, I can do it. I'm not sure if I completely understand the
changes I need to make though. Importing dl needs to be replaced by
importing ctypes, calls to dl.open() need to be replaced by calls to
ctypes.CDLL(), and calls to call() from an open dl object need to be
replaced to calls to funcname, where funcname is the first argument to
call(). Also, any strings in the other arguments should be preceded with
b to make them byte objects. Is this all that needs doing or am I
missing something else? Are there more complicated cases that I should
also take into account?
msg70713 - (view) Author: Collin Winter (collinwinter) * (Python committer) Date: 2008-08-04 18:40
I'd prefer it if someone better-versed in ctypes/dl wrote this fixer (or
at the very least, someone with access to Windows to test the translation).
msg70854 - (view) Author: Thomas Heller (theller) * (Python committer) Date: 2008-08-07 19:29
I can review and try out the fixer if someone provides a patch.  OTOH I
have never used the dl module.

Note that dl exposed a lot of RTLD_ constants that ctypes does not yet,
so there should be a patch for ctypes also.
msg146303 - (view) Author: Florent Xicluna (flox) * (Python committer) Date: 2011-10-24 13:23
for the RTLD_ constants, refer to issue #13226.
msg158724 - (view) Author: Martin v. Löwis (loewis) * (Python committer) Date: 2012-04-19 12:41
Being open for four years, this is hardly critical.
History
Date User Action Args
2022-04-11 14:56:32adminsetgithub: 46722
2021-10-20 22:40:57iritkatrielsetresolution: duplicate -> wont fix
2021-10-20 22:36:58iritkatrielsetstatus: open -> closed
resolution: duplicate
superseder: Close 2to3 issues and list them here
stage: needs patch -> resolved
2012-04-19 12:41:20loewissetpriority: critical -> normal

messages: + msg158724
2011-10-24 13:23:41floxsetnosy: + flox
messages: + msg146303
2010-05-29 15:26:34meador.ingesettype: enhancement
stage: needs patch
2008-08-07 19:29:13thellersetmessages: + msg70854
2008-08-04 18:40:07collinwintersetmessages: + msg70713
2008-08-04 18:32:39neddssetnosy: + nedds
messages: + msg70712
2008-07-31 02:02:38benjamin.petersonsetnosy: + benjamin.peterson
messages: + msg70466
2008-03-25 22:41:57thellersetmessages: + msg64526
2008-03-25 08:44:06thellersetmessages: + msg64467
2008-03-24 16:41:37loewissetnosy: + theller
messages: + msg64419
2008-03-24 16:08:33collinwintersetmessages: + msg64417
2008-03-24 09:12:48loewissetnosy: + loewis
messages: + msg64407
2008-03-24 06:24:34nnorwitzcreate