New submission from Serhiy Storchaka:

When C code needs to compare Python object with int 0 or add int 1 it either 
use local reference to PyLong_FromLong(0) and PyLong_FromLong(1) which should 
be decrefed just after use or module level global variable initialized and 
cleared during initializing and finalizing the module.

Proposed patch adds global variables _PyLong_Zero and _PyLong_One for 
references to integer objects 0 and 1. This simplifies the code since no need 
to initialize local variables, check for error the result of PyLong_FromLong() 
and decref it after use. The patch decreases the total code size by 244 lines.

That variables are only for internal use. User code should use 
PyLong_FromLong(0) and PyLong_FromLong(1).

----------
components: Interpreter Core
files: long-constants.diff
keywords: patch
messages: 289974
nosy: haypo, mark.dickinson, serhiy.storchaka
priority: normal
severity: normal
stage: patch review
status: open
title: Add global instances of int 0 and 1
type: enhancement
versions: Python 3.7
Added file: http://bugs.python.org/file46751/long-constants.diff

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

Reply via email to