New submission from STINNER Victor:

I recently added new functions to call functions in C, especially 
_PyObject_FastCallDict(). I started with the C int type for the number of 
positional arguments: "int nargs".

But slowly, when I started to patch code to use _PyObject_FastCallDict(), I 
used more and more Py_ssize_t variables for the number of arguments, variable 
downcasted to int to call _PyObject_FastCallDict().

It is similar to the old issue #18295.

I propose to avoid any risk of integer overflow by using Py_ssize_t everywhere. 
It *might* produce more efficient machine code, since "i++" may require extra 
code to handle overflow when the int rather is used. But I'm not sure that 
Py_ssize_t is better, especially when -fwrapv option of the GCC compiler is 
used.

Attached patch implements this idea.

The patch also uses Py_ssize_t for some BUILD_xxx opcodes like 
BUILD_LIST_UNPACK. The change is not directly related. I wrote it in the hope 
that machine code could be more efficient, and avoid having to ask myself if 
types could overflow or not.

----------
files: Py_ssize_t.patch
keywords: patch
messages: 273549
nosy: haypo, scoder, serhiy.storchaka
priority: normal
severity: normal
status: open
title: C function calls: use Py_ssize_t rather than C int for number of 
arguments
versions: Python 3.6
Added file: http://bugs.python.org/file44209/Py_ssize_t.patch

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue27848>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to