Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
sobolevn opened this issue Feb 7, 2023 · 4 comments
Labels
type-bug An unexpected behavior, bug, or error

Comments

@sobolevn
Copy link
Member

sobolevn commented Feb 7, 2023

Снимок экрана 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

@sobolevn sobolevn added the type-bug An unexpected behavior, bug, or error label Feb 7, 2023
@ambv
Copy link
Contributor

ambv commented Feb 7, 2023

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.

@sobolevn
Copy link
Member Author

sobolevn commented Feb 7, 2023

@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 🤔

@sobolevn
Copy link
Member Author

sobolevn commented Feb 7, 2023

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

@ambv
Copy link
Contributor

ambv commented Feb 7, 2023

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

sobolevn added a commit to sobolevn/cpython that referenced this issue Feb 7, 2023
sobolevn added a commit to sobolevn/cpython that referenced this issue Feb 8, 2023
…ng in `_testcapimodule` (pythonGH-101657).

(cherry picked from commit acc2f3b)

Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
ambv pushed a commit that referenced this issue Feb 8, 2023
@sobolevn sobolevn closed this as completed Feb 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

2 participants