Skip to content

New warning: conversion from 'Py_ssize_t' to 'int', possible loss of data in Modules/_testcapimodule.c #101656

Description

@sobolevn

Снимок экрана 2023-02-07 в 21 22 57

This happens because:

  • Py_ssize_t c_args_len = 0;
  • But, PyEval_EvalCodeEx expects int:
     PyObject *
     PyEval_EvalCodeEx(PyObject *_co, PyObject *globals, PyObject *locals,
                    PyObject *const *args, int argcount,
                    PyObject *const *kws, int kwcount,
                    PyObject *const *defs, int defcount,
                    PyObject *kwdefs, PyObject *closure)

Looks like this is a side effect of ae62bdd

Possible solution is to use an explicit (int) converter.
I don't think that we should really worry about an overflow in the test code.
I will send a PR to check if this is a proper fix.

CC @ambv as the original PR reviewer.

Linked PRs

Activity

  1. ambv commented on Feb 7, 2023

    @ambv
    Contributor

    I think the fix is to replace the Py_ssize_t variables in the test function to ints as this is indeed what PyEval_EvalCodeEx expects.

  2. sobolevn commented on Feb 7, 2023

    @sobolevn
    MemberAuthor

    @ambv can we do that? Because, for example, c_defaults_len uses this code:

    Py_ssize_t c_defaults_len = 0;
    if (defaults && PyTuple_Check(defaults)) {
    c_defaults = &PyTuple_GET_ITEM(defaults, 0);
    c_defaults_len = PyTuple_Size(defaults);
    }

    And PyTuple_Size returns Py_ssize_t 🤔

  3. sobolevn commented on Feb 7, 2023

    @sobolevn
    MemberAuthor

    Either way, we need to convert Py_ssize_t to int at some point. I propose to do it later on :)

  4. ambv commented on Feb 7, 2023

    @ambv
    Contributor

    OK, that makes sense to me, too. Let's go!

  5. added a commit that references this issue on Feb 7, 2023
  6. added a commit that references this issue on Feb 7, 2023
  7. added a commit that references this issue on Feb 8, 2023
  8. added a commit that references this issue on Feb 8, 2023
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

    type-bugAn unexpected behavior, bug, or error

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions