Skip to content

Need fixer for dl (removed) -> ctypes module #46722

Closed

Description

@nnorwitz
mannequin
BPO 2470
Nosy @loewis, @theller, @benjaminp, @florentx
Superseder
  • bpo-45544: Close 2to3 issues and list them here
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = None
    closed_at = <Date 2021-10-20.22:36:58.582>
    created_at = <Date 2008-03-24.06:24:34.126>
    labels = ['type-feature', 'expert-2to3']
    title = 'Need fixer for dl (removed) -> ctypes module'
    updated_at = <Date 2021-10-20.22:40:57.612>
    user = 'https://bugs.python.org/nnorwitz'

    bugs.python.org fields:

    activity = <Date 2021-10-20.22:40:57.612>
    actor = 'iritkatriel'
    assignee = 'collinwinter'
    closed = True
    closed_date = <Date 2021-10-20.22:36:58.582>
    closer = 'iritkatriel'
    components = ['2to3 (2.x to 3.x conversion tool)']
    creation = <Date 2008-03-24.06:24:34.126>
    creator = 'nnorwitz'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 2470
    keywords = []
    message_count = 12.0
    messages = ['64394', '64407', '64417', '64419', '64467', '64526', '70466', '70712', '70713', '70854', '146303', '158724']
    nosy_count = 7.0
    nosy_names = ['loewis', 'nnorwitz', 'theller', 'collinwinter', 'benjamin.peterson', 'nedds', 'flox']
    pr_nums = []
    priority = 'normal'
    resolution = 'wont fix'
    stage = 'resolved'
    status = 'closed'
    superseder = '45544'
    type = 'enhancement'
    url = 'https://bugs.python.org/issue2470'
    versions = []

    Activity

    1. nnorwitz commented on Mar 24, 2008

      nnorwitzmannequin
      MannequinAuthor

      r61837 removed the dl module. It needs a 2to3 fixer written to use ctypes.

    2. loewis commented on Mar 24, 2008

      loewismannequin
      Mannequin

      Is it possible to write one? I'm skeptical.

    3. collinwinter commented on Mar 24, 2008

      collinwintermannequin
      Mannequin

      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.

    4. loewis commented on Mar 24, 2008

      loewismannequin
      Mannequin

      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
    5. theller commented on Mar 25, 2008

      @theller

      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.

    6. theller commented on Mar 25, 2008

      @theller

      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)
    7. benjaminp commented on Jul 31, 2008

      @benjaminp
      Contributor

      What's the status of this?

    8. nedds commented on Aug 4, 2008

      neddsmannequin
      Mannequin

      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?

    9. collinwinter commented on Aug 4, 2008

      collinwintermannequin
      Mannequin

      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).

    10. theller commented on Aug 7, 2008

      @theller

      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.

    11. florentx commented on Oct 24, 2011

      florentxmannequin
      Mannequin

      for the RTLD_ constants, refer to issue bpo-13226.

    12. loewis commented on Apr 19, 2012

      loewismannequin
      Mannequin

      Being open for four years, this is hardly critical.

    13. transferred this issue fromon Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

    Metadata

    Metadata

    Assignees

    No one assigned

      Labels

      Projects

      No projects

        Milestone

        No milestone

        Relationships

        None yet

        Development

        No branches or pull requests

        Issue actions