Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[C API] Add PyLong_FromInt64() and PyLong_ToInt64() #120389

Closed
Labels
@vstinner

Description

@vstinner

Feature or enhancement

I propose to add functions to convert <stdint.h> integers to/from Python int objects:

PyObject*PyLong_FromInt32(int32_tvalue);PyObject*PyLong_FromInt64(int64_tvalue);PyObject*PyLong_FromUInt32(uint32_tvalue);PyObject*PyLong_FromUInt64(uint64_tvalue);intPyLong_ToInt32(PyObject*obj,int32_t*value);intPyLong_ToInt64(PyObject*obj,int64_t*value);intPyLong_ToUInt32(PyObject*obj,uint32_t*value);intPyLong_ToUInt64(PyObject*obj,uint64_t*value);

Notes:

  • I prefer to limit the API to 4 types for now: int32/64_t and uint32/64_t. Later, we can discuss add more types, but let's start with the most common ones. (UPDATE: I removed 8-bit and 16-bit types.)
  • I preferUInt toUint since there are two words: Unsigned INTeger.
  • To functions don't return the result, but a status: 0 on success, -1 on error (with an exception set). It's to solve theC API Problem #1: "Ambiguous return values". PyLong_AsLong() returns -1 on success and on error (with an exception set).

Related discussion:Avoid C-specific Types.

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp