Title: [C API] Add PyLong_FromInt64() and PyLong_ToInt64() · Issue #120389 · python/cpython · GitHub
Open Graph Title: [C API] Add PyLong_FromInt64() and PyLong_ToInt64() · Issue #120389 · python/cpython
X Title: [C API] Add PyLong_FromInt64() and PyLong_ToInt64() · Issue #120389 · python/cpython
Description: Feature or enhancement I propose to add functions to convert
Open Graph Description: Feature or enhancement I propose to add functions to convert
X Description: Feature or enhancement I propose to add functions to convert <stdint.h> integers to/from Python int objects: PyObject* PyLong_FromInt32(int32_t value); PyObject* PyLong_FromInt64(int64_t valu...
Opengraph URL: https://github.com/python/cpython/issues/120389
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"[C API] Add PyLong_FromInt64() and PyLong_ToInt64()","articleBody":"# Feature or enhancement\r\n\r\nI propose to add functions to convert \u003cstdint.h> integers to/from Python int objects:\r\n\r\n```c\r\nPyObject* PyLong_FromInt32(int32_t value);\r\nPyObject* PyLong_FromInt64(int64_t value);\r\nPyObject* PyLong_FromUInt32(uint32_t value);\r\nPyObject* PyLong_FromUInt64(uint64_t value);\r\n\r\nint PyLong_ToInt32(PyObject *obj, int32_t *value);\r\nint PyLong_ToInt64(PyObject *obj, int64_t *value);\r\nint PyLong_ToUInt32(PyObject *obj, uint32_t *value);\r\nint PyLong_ToUInt64(PyObject *obj, uint64_t *value);\r\n```\r\n\r\nNotes:\r\n\r\n* 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.)\r\n* I prefer `UInt` to `Uint` since there are two words: Unsigned INTeger.\r\n* `To` functions don't return the result, but a status: 0 on success, -1 on error (with an exception set). It's to solve the [C API Problem #1](https://github.com/capi-workgroup/problems/issues/1): \"Ambiguous return values\". PyLong_AsLong() returns -1 on success and on error (with an exception set).\r\n\r\nRelated discussion: [Avoid C-specific Types](https://github.com/capi-workgroup/api-evolution/issues/10).\r\n\r\n\u003c!-- gh-linked-prs -->\r\n### Linked PRs\r\n* gh-120390\r\n\u003c!-- /gh-linked-prs -->\r\n","author":{"url":"https://github.com/vstinner","@type":"Person","name":"vstinner"},"datePublished":"2024-06-12T07:55:06Z","url":"https://github.com/python/cpython/issues/120389"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react-reconciler,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@d5750093facf |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:4312f665-3d97-4d0c-e075-499aa8047553 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | D838:36534B:28E704:3931FE:6AECB65C |
| html-safe-nonce | 51367370ef3a9f6db505afbffb5f14fc662127abba410c9176b7f421a62faabe |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJEODM4OjM2NTM0QjoyOEU3MDQ6MzkzMUZFOjZBRUNCNjVDIiwidmlzaXRvcl9pZCI6IjYyMzEzODI1ODE5ODc1NTQ5MDgiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 9d47a97a999ce4699d8868e9f0dae239a8135ff24a8686ce7b2a1dda81ac2e5e |
| hovercard-subject-tag | issue:2348085250 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/python/cpython/120389/issue_layout |
| twitter:image | https://opengraph.githubassets.com/3ace12913b02ce70936ef81b97b2955d573c386755418638a43613e739b0e91b/python/cpython/issues/120389 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/3ace12913b02ce70936ef81b97b2955d573c386755418638a43613e739b0e91b/python/cpython/issues/120389 |
| og:image:alt | Feature or enhancement I propose to add functions to convert |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | vstinner |
| hostname | github.com |
| expected-hostname | github.com |
| None | 95ae5445dec4cded2bc4f9d97ede92b9116c0bf381a08a5c844b60b5bddcbc97 |
| turbo-cache-control | no-preview |
| go-import | github.com/python/cpython git https://github.com/python/cpython.git |
| octolytics-dimension-user_id | 1525981 |
| octolytics-dimension-user_login | python |
| octolytics-dimension-repository_id | 81598961 |
| octolytics-dimension-repository_nwo | python/cpython |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 81598961 |
| octolytics-dimension-repository_network_root_nwo | python/cpython |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | db4ef601a7f034ae2a68e17d6eeaeb7ee9470192 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width