Skip to content

gh-143050: add helper _PyLong_InitTag()#147956

Open
skirpichev wants to merge 3 commits intopython:mainfrom
skirpichev:add-_PyLong_Init
Open

gh-143050: add helper _PyLong_InitTag()#147956
skirpichev wants to merge 3 commits intopython:mainfrom
skirpichev:add-_PyLong_Init

Conversation

@skirpichev
Copy link
Copy Markdown
Member

@skirpichev skirpichev commented Apr 1, 2026

With this we can assume, that _PyLong_Set*() operate on non-immortal integers.

With this we can assume, that _PyLong_Set*() operate on
non-immortal integers.
{
assert(PyLong_Check(op));
op->long_value.lv_tag = 1; /* non-immortal zero */
op->long_value.ob_digit[0] = 0;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would prefer to only initialize the tag and so rename the function to _PyLong_InitTag().

op->long_value.ob_digit[0] = 0; is only used (needed) by long_alloc(). All other functions using _PyLong_Init() will rewrite ob_digit[0] immediately and so it's inefficient.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this may trigger a compiler warning. I did renaming, lets do another change in a second commit.

@skirpichev skirpichev changed the title gh-143050: add helper _PyLong_Init() gh-143050: add helper _PyLong_InitTag() Apr 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants