Issue 2470: Need fixer for dl (removed) -> ctypes module
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) * ![]() |
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) * ![]() |
Date: 2008-03-24 09:12 | |
Is it possible to write one? I'm skeptical. |
|||
| msg64417 - (view) | Author: Collin Winter (collinwinter) * ![]() |
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) * ![]() |
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) * ![]() |
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) * ![]() |
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) * ![]() |
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) * ![]() |
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) * ![]() |
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) * ![]() |
Date: 2011-10-24 13:23 | |
for the RTLD_ constants, refer to issue #13226. |
|||
| msg158724 - (view) | Author: Martin v. Löwis (loewis) * ![]() |
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:32 | admin | set | github: 46722 |
| 2021-10-20 22:40:57 | iritkatriel | set | resolution: duplicate -> wont fix |
| 2021-10-20 22:36:58 | iritkatriel | set | status: open -> closed resolution: duplicate superseder: Close 2to3 issues and list them here stage: needs patch -> resolved |
| 2012-04-19 12:41:20 | loewis | set | priority: critical -> normal messages: + msg158724 |
| 2011-10-24 13:23:41 | flox | set | nosy:
+ flox messages: + msg146303 |
| 2010-05-29 15:26:34 | meador.inge | set | type: enhancement stage: needs patch |
| 2008-08-07 19:29:13 | theller | set | messages: + msg70854 |
| 2008-08-04 18:40:07 | collinwinter | set | messages: + msg70713 |
| 2008-08-04 18:32:39 | nedds | set | nosy:
+ nedds messages: + msg70712 |
| 2008-07-31 02:02:38 | benjamin.peterson | set | nosy:
+ benjamin.peterson messages: + msg70466 |
| 2008-03-25 22:41:57 | theller | set | messages: + msg64526 |
| 2008-03-25 08:44:06 | theller | set | messages: + msg64467 |
| 2008-03-24 16:41:37 | loewis | set | nosy:
+ theller messages: + msg64419 |
| 2008-03-24 16:08:33 | collinwinter | set | messages: + msg64417 |
| 2008-03-24 09:12:48 | loewis | set | nosy:
+ loewis messages: + msg64407 |
| 2008-03-24 06:24:34 | nnorwitz | create | |
