Skip to content

_elementtree.c warnings under 64-bit Windows #53992

Closed

Description

@pitrou
BPO 9783
Nosy @loewis, @pitrou, @florentx
Superseder
  • bpo-9566: Compilation warnings under x64 Windows
  • Files
  • issue9783.diff
  • 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 2012-07-21.13:00:19.025>
    created_at = <Date 2010-09-06.12:49:52.757>
    labels = ['extension-modules', 'build', 'OS-windows']
    title = '_elementtree.c warnings under 64-bit Windows'
    updated_at = <Date 2012-07-21.13:00:19.024>
    user = 'https://github.com/pitrou'

    bugs.python.org fields:

    activity = <Date 2012-07-21.13:00:19.024>
    actor = 'flox'
    assignee = 'none'
    closed = True
    closed_date = <Date 2012-07-21.13:00:19.025>
    closer = 'flox'
    components = ['Extension Modules', 'Windows']
    creation = <Date 2010-09-06.12:49:52.757>
    creator = 'pitrou'
    dependencies = []
    files = ['18988']
    hgrepos = []
    issue_num = 9783
    keywords = ['patch']
    message_count = 6.0
    messages = ['115700', '116175', '117255', '117324', '117362', '166019']
    nosy_count = 6.0
    nosy_names = ['loewis', 'effbot', 'pitrou', 'eli.bendersky', 'janglin', 'flox']
    pr_nums = []
    priority = 'normal'
    resolution = 'duplicate'
    stage = 'patch review'
    status = 'closed'
    superseder = '9566'
    type = 'compile error'
    url = 'https://bugs.python.org/issue9783'
    versions = ['Python 3.2']

    Activity

    1. pitrou commented on Sep 6, 2010

      @pitrou
      MemberAuthor

      Some of these warnings could be serious (e.g. the one where the 64-bit "self" is converted to a 32-bit "long"):

      13>..\Modules\_elementtree.c(696) : warning C4244: 'function' : conversion from 'Py_uintptr_t' to 'long', possible loss of data
      13>..\Modules\_elementtree.c(1239) : warning C4244: '=' : conversion from 'Py_ssize_t' to 'int', possible loss of data
      13>..\Modules\_elementtree.c(1372) : warning C4244: 'function' : conversion from 'Py_ssize_t' to 'int', possible loss of data
      13>..\Modules\_elementtree.c(1414) : warning C4244: '+=' : conversion from 'Py_ssize_t' to 'int', possible loss of data
      13>..\Modules\_elementtree.c(2076) : warning C4267: 'initializing' : conversion from 'size_t' to 'int', possible loss of data
      13>..\Modules\_elementtree.c(2663) : warning C4244: 'function' : conversion from 'Py_ssize_t' to 'int', possible loss of data

    2. loewis commented on Sep 12, 2010

      loewismannequin
      Mannequin

      Instead of

        PyLong_FromLong((Py_uintptr_t) self);

      use

         PyLong_FromVoidPtr(self);

      For the others, I suggest making length and allocated Py_ssize_t; this is likely a pervasive change. Of course, very few people will currently run into XML documents where some element has more than 2**31 children... You would need several TiB of main memory to represent it using ElementTree.

      Fredrik, please indicate whether it is ok to make this kind of change, or whether it would need your explicit approval.

    3. janglin commented on Sep 24, 2010

      janglinmannequin
      Mannequin

      bpo-9783.diff provides a patch that will compile clean on 32 and 64 bit Windows systems. I tried to avoid explicit casts where I could, but it was not always possible. I have ported a lot of my company's code to 64 bit (all Windows based). In my experience many warnings are because of programmers using the int type in places where a size_t may be more appropriate. Most of the warnings here are due to mixing int and Py_ssize_t types.

    4. loewis commented on Sep 24, 2010

      loewismannequin
      Mannequin

      bpo-9783.diff provides a patch that will compile clean on 32 and 64
      bit Windows systems. I tried to avoid explicit casts where I could,
      but it was not always possible. I have ported a lot of my company's
      code to 64 bit (all Windows based). In my experience many warnings
      are because of programmers using the int type in places where a
      size_t may be more appropriate. Most of the warnings here are due to
      mixing int and Py_ssize_t types.

      I think the patch is incorrect as it stands: the casts may cause
      truncation. As you say, int is still being used where size_t was
      more appropriate, so I think we should change it in that manner
      (e.g. make element_resize accept Py_ssize_t).

      In cases where we really can't propagate Py_ssize_t to (e.g.
      XML_Parse), we need to check for an int overflow, and raise
      an exception if it does overflow.

    5. janglin commented on Sep 25, 2010

      janglinmannequin
      Mannequin

      Martin is correct about this patch.

      In cases where we really can't propagate Py_ssize_t to (e.g.
      XML_Parse), we need to check for an int overflow, and raise
      an exception if it does overflow.

      Is this an appropriate approach?

      int
      PySize_AsInt(Py_ssize_t value)
      {
          if (value > (Py_ssize_t)INT_MAX || value < (Py_ssize_t)INT_MIN) {
              PyErr_SetString(PyExc_OverflowError, 
                              "Size value can not be represented as an integer");
          }
          return (int)value;
      }

      I would only define this when sizeof(Py_ssize_t) > sizeof(int) of course. In other cases it would be a macro that just evaluates to value.
      I would most likely need an unsigned version as well (although not for this particular issue).

      This code could be used in many C modules. Where in the Python code base should such functions be placed?

    6. florentx commented on Jul 21, 2012

      florentxmannequin
      Mannequin

      This warning is not specific to the _elementtree module.
      See related issue bpo-9566.

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