Title: [C API] Add PyBytesWriter API · Issue #121710 · python/cpython · GitHub
Open Graph Title: [C API] Add PyBytesWriter API · Issue #121710 · python/cpython
X Title: [C API] Add PyBytesWriter API · Issue #121710 · python/cpython
Description: Feature or enhancement I propose adding a new PyBytesWriter API to create a Python bytes object. API: typedef struct PyBytesWriter PyBytesWriter; // Create a bytes writer instance. // On success, set *str and return a new writer. // On e...
Open Graph Description: Feature or enhancement I propose adding a new PyBytesWriter API to create a Python bytes object. API: typedef struct PyBytesWriter PyBytesWriter; // Create a bytes writer instance. // On success, s...
X Description: Feature or enhancement I propose adding a new PyBytesWriter API to create a Python bytes object. API: typedef struct PyBytesWriter PyBytesWriter; // Create a bytes writer instance. // On success, s...
Opengraph URL: https://github.com/python/cpython/issues/121710
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"[C API] Add PyBytesWriter API","articleBody":"# Feature or enhancement\n\nI propose adding a new `PyBytesWriter` API to create a Python bytes object.\n\nAPI:\n\n```c\ntypedef struct PyBytesWriter PyBytesWriter;\n\n// Create a bytes writer instance.\n// On success, set *str and return a new writer.\n// On error, set an exception and return NULLL.\nPyAPI_FUNC(PyBytesWriter*) PyBytesWriter_Create(\n Py_ssize_t size,\n char **str);\n\n// Return the final Python bytes object and destroy the writer instance.\n// On success, return a bytes object.\n// On error, set an exception and return NULL.\nPyAPI_FUNC(PyObject *) PyBytesWriter_Finish(\n PyBytesWriter *writer,\n char *str);\n\n// Disard a writer: deallocate its memory.\nPyAPI_FUNC(void) PyBytesWriter_Discard(PyBytesWriter *writer);\n\n// Allocate 'size' bytes to prepare writing into writer.\n// On success, return 0.\n// On error, set an exception and return -1.\nPyAPI_FUNC(int) PyBytesWriter_Prepare(\n PyBytesWriter *writer,\n char **str,\n Py_ssize_t size);\n\n// Write a bytes string into writer.\n// On success, return 0.\n// On error, set an exception and return -1.\nPyAPI_FUNC(int) PyBytesWriter_WriteBytes(\n PyBytesWriter *writer,\n char **str,\n const void *bytes,\n Py_ssize_t size);\n```\n\nThe `PyBytesWriter` *writer* is responsible to manage memor and uses overallocation to be more efficient, *str* is a cursor to write into the bytes string.\n\nThe implementation is based on the existing private `_PyBytesWriter` API which exists for many years and is used by many functions such as ASCII and Latin1 encoders, `binascii` module, `_pickle` module, `_struct` module, bytes methods, etc.\n\n\u003c!-- gh-linked-prs -->\n### Linked PRs\n* gh-121726\n\u003c!-- /gh-linked-prs -->\n","author":{"url":"https://github.com/vstinner","@type":"Person","name":"vstinner"},"datePublished":"2024-07-13T14:30:33Z","url":"https://github.com/python/cpython/issues/121710"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| 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:609a4dc2-1463-9d1a-12e1-a0b086735ce1 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | C640:313081:16C1F0A:1E08507:6B01FE9C |
| html-safe-nonce | 7b7fc1a70f96b96e4ae733ec8dfc19edd625d54c6c3a05450f4a1bc6c06dc897 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDNjQwOjMxMzA4MToxNkMxRjBBOjFFMDg1MDc6NkIwMUZFOUMiLCJ2aXNpdG9yX2lkIjoiMTg3ODczMzYzNDY4NTUwMTA4NCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 35563ac9dfcede8e5ce0ed1f75952f96800be238adf0413ac7a301e274c7d227 |
| hovercard-subject-tag | issue:2406957836 |
| 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/121710/issue_layout |
| twitter:image | https://opengraph.githubassets.com/3491c16de135846f5e2aaf88911932269379af8b80187d435ab79a88cf41d610/python/cpython/issues/121710 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/3491c16de135846f5e2aaf88911932269379af8b80187d435ab79a88cf41d610/python/cpython/issues/121710 |
| og:image:alt | Feature or enhancement I propose adding a new PyBytesWriter API to create a Python bytes object. API: typedef struct PyBytesWriter PyBytesWriter; // Create a bytes writer instance. // On success, s... |
| 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 | 87e774ee7c6b3bee0490394e4d3e57ec9dbc956f74b87ea685dc8996c1676456 |
| 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 | 423dbb54c5e7bfecc838eb387c1435eb3d0e760d |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width