René's URL Explorer Experiment


Title: Add support for C99 complex type (_Complex) to the struct module · Issue #121249 · python/cpython · GitHub

Open Graph Title: Add support for C99 complex type (_Complex) to the struct module · Issue #121249 · python/cpython

X Title: Add support for C99 complex type (_Complex) to the struct module · Issue #121249 · python/cpython

Description: Feature or enhancement Proposal: The struct module has support for float and double types, so at least there should be also float _Complex and double _Complex. I'll work on a patch. Initial version diff --git a/Lib/ctypes/__init__.py b/L...

Open Graph Description: Feature or enhancement Proposal: The struct module has support for float and double types, so at least there should be also float _Complex and double _Complex. I'll work on a patch. Initial version...

X Description: Feature or enhancement Proposal: The struct module has support for float and double types, so at least there should be also float _Complex and double _Complex. I'll work on a patch. Initial ver...

Opengraph URL: https://github.com/python/cpython/issues/121249

X: @github

direct link

Domain: github.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Add support for C99 complex type (_Complex) to the struct module","articleBody":"# Feature or enhancement\n\n### Proposal:\n\nThe struct module has support for ``float`` and ``double`` types, so at least there should be also ``float _Complex`` and ``double _Complex``.  I'll work on a patch.\n\n\u003cdetails\u003e\n\n\u003csummary\u003eInitial version\u003c/summary\u003e\n\n```diff\ndiff --git a/Lib/ctypes/__init__.py b/Lib/ctypes/__init__.py\nindex d2e6a8bfc8..d941036719 100644\n--- a/Lib/ctypes/__init__.py\n+++ b/Lib/ctypes/__init__.py\n@@ -208,6 +208,7 @@ class c_longdouble(_SimpleCData):\n try:\n     class c_double_complex(_SimpleCData):\n         _type_ = \"C\"\n+    _check_size(c_double_complex)\n except AttributeError:\n     pass\n \ndiff --git a/Modules/_struct.c b/Modules/_struct.c\nindex 6a68478dd4..caf4975413 100644\n--- a/Modules/_struct.c\n+++ b/Modules/_struct.c\n@@ -12,6 +12,9 @@\n #include \"pycore_long.h\"          // _PyLong_AsByteArray()\n #include \"pycore_moduleobject.h\"  // _PyModule_GetState()\n \n+#ifdef Py_HAVE_C_COMPLEX\n+#  include \"_complex.h\"           // complex\n+#endif\n #include \u003cstddef.h\u003e               // offsetof()\n \n /*[clinic input]\n@@ -80,6 +83,9 @@ typedef struct { char c; int x; } st_int;\n typedef struct { char c; long x; } st_long;\n typedef struct { char c; float x; } st_float;\n typedef struct { char c; double x; } st_double;\n+#ifdef Py_HAVE_C_COMPLEX\n+typedef struct { char c; double complex x; } st_double_complex;\n+#endif\n typedef struct { char c; void *x; } st_void_p;\n typedef struct { char c; size_t x; } st_size_t;\n typedef struct { char c; _Bool x; } st_bool;\n@@ -89,6 +95,9 @@ typedef struct { char c; _Bool x; } st_bool;\n #define LONG_ALIGN (sizeof(st_long) - sizeof(long))\n #define FLOAT_ALIGN (sizeof(st_float) - sizeof(float))\n #define DOUBLE_ALIGN (sizeof(st_double) - sizeof(double))\n+#ifdef Py_HAVE_C_COMPLEX\n+#define DOUBLE_COMPLEX_ALIGN (sizeof(st_double_complex) - sizeof(double complex))\n+#endif\n #define VOID_P_ALIGN (sizeof(st_void_p) - sizeof(void *))\n #define SIZE_T_ALIGN (sizeof(st_size_t) - sizeof(size_t))\n #define BOOL_ALIGN (sizeof(st_bool) - sizeof(_Bool))\n@@ -518,6 +527,17 @@ nu_double(_structmodulestate *state, const char *p, const formatdef *f)\n     return PyFloat_FromDouble(x);\n }\n \n+#ifdef Py_HAVE_C_COMPLEX\n+static PyObject *\n+nu_double_complex(_structmodulestate *state, const char *p, const formatdef *f)\n+{\n+    double complex x;\n+\n+    memcpy(\u0026x, p, sizeof(x));\n+    return PyComplex_FromDoubles(creal(x), cimag(x));\n+}\n+#endif\n+\n static PyObject *\n nu_void_p(_structmodulestate *state, const char *p, const formatdef *f)\n {\n@@ -791,6 +811,24 @@ np_double(_structmodulestate *state, char *p, PyObject *v, const formatdef *f)\n     return 0;\n }\n \n+#ifdef Py_HAVE_C_COMPLEX\n+static int\n+np_double_complex(_structmodulestate *state, char *p, PyObject *v,\n+                  const formatdef *f)\n+{\n+    Py_complex c = PyComplex_AsCComplex(v);\n+    double complex x = CMPLX(c.real, c.imag);\n+\n+    if (c.real == -1 \u0026\u0026 PyErr_Occurred()) {\n+        PyErr_SetString(state-\u003eStructError,\n+                        \"required argument is not a complex\");\n+        return -1;\n+    }\n+    memcpy(p, (char *)\u0026x, sizeof(x));\n+    return 0;\n+}\n+#endif\n+\n static int\n np_void_p(_structmodulestate *state, char *p, PyObject *v, const formatdef *f)\n {\n@@ -829,6 +867,9 @@ static const formatdef native_table[] = {\n     {'e',       sizeof(short),  SHORT_ALIGN,    nu_halffloat,   np_halffloat},\n     {'f',       sizeof(float),  FLOAT_ALIGN,    nu_float,       np_float},\n     {'d',       sizeof(double), DOUBLE_ALIGN,   nu_double,      np_double},\n+#ifdef Py_HAVE_C_COMPLEX\n+    {'C',       sizeof(double complex), DOUBLE_COMPLEX_ALIGN, nu_double_complex, np_double_complex},\n+#endif\n     {'P',       sizeof(void *), VOID_P_ALIGN,   nu_void_p,      np_void_p},\n     {0}\n };\n```\n\n\u003c/details\u003e\n\n### Has this already been discussed elsewhere?\n\nThis is a minor feature, which does not need previous discussion elsewhere\n\n### Links to previous discussion of this feature:\n\n_No response_\n\n\u003c!-- gh-linked-prs --\u003e\n### Linked PRs\n* gh-121613\n* gh-131867\n* gh-132827\n* gh-132863\n* gh-132864\n* gh-133249\n* gh-149346\n* gh-152274\n* gh-152309\n\u003c!-- /gh-linked-prs --\u003e\n","author":{"url":"https://github.com/skirpichev","@type":"Person","name":"skirpichev"},"datePublished":"2024-07-02T03:36:14.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":23},"url":"https://github.com/121249/cpython/issues/121249"}

route-pattern/_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format)
route-controllervoltron_issues_fragments
route-actionissue_layout
fetch-noncev2:62f9e3f0-1a4d-a913-6fd3-4660d419bab1
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-id9D28:1F40D1:4AE670:679D0B:6A51213C
html-safe-nonce70778510df8463bad0eecf775a7cbea79486978fbf3d69fa71b3b7e89519d7ae
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5RDI4OjFGNDBEMTo0QUU2NzA6Njc5RDBCOjZBNTEyMTNDIiwidmlzaXRvcl9pZCI6IjM3NDExNDM1Mzk5ODEwMzM3ODgiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ==
visitor-hmac54a0e049f7e2af601b22675e17774b00009d1899731253396c1c5c1081fd5107
hovercard-subject-tagissue:2385121145
github-keyboard-shortcutsrepository,issues,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///voltron/issues_fragments/issue_layout
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/python/cpython/121249/issue_layout
twitter:imagehttps://opengraph.githubassets.com/fe23f6e76c6e61ca5275588aa7422fe4aa173dbced85bce6373ac50e14b7a54d/python/cpython/issues/121249
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/fe23f6e76c6e61ca5275588aa7422fe4aa173dbced85bce6373ac50e14b7a54d/python/cpython/issues/121249
og:image:altFeature or enhancement Proposal: The struct module has support for float and double types, so at least there should be also float _Complex and double _Complex. I'll work on a patch. Initial version...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernameskirpichev
hostnamegithub.com
expected-hostnamegithub.com
None689b683944b0d7f015d0e776452c970832fa81b82dc15284469b556ecced715b
turbo-cache-controlno-preview
go-importgithub.com/python/cpython git https://github.com/python/cpython.git
octolytics-dimension-user_id1525981
octolytics-dimension-user_loginpython
octolytics-dimension-repository_id81598961
octolytics-dimension-repository_nwopython/cpython
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id81598961
octolytics-dimension-repository_network_root_nwopython/cpython
turbo-body-classeslogged-out env-production page-responsive
disable-turbofalse
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
release942b51ed3bd5feee3d5e2719f890a5fe286edbbb
ui-targetfull
theme-color#1e2327
color-schemelight dark

Links:

Skip to contenthttps://github.com/python/cpython/issues/121249#start-of-content
https://github.com/
Sign in https://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpython%2Fcpython%2Fissues%2F121249
GitHub CopilotWrite better code with AIhttps://github.com/features/copilot
GitHub Copilot appDirect agents from issue to mergehttps://github.com/features/ai/github-app
MCP RegistryNewIntegrate external toolshttps://github.com/mcp
ActionsAutomate any workflowhttps://github.com/features/actions
CodespacesInstant dev environmentshttps://github.com/features/codespaces
IssuesPlan and track workhttps://github.com/features/issues
Code ReviewManage code changeshttps://github.com/features/code-review
GitHub Advanced SecurityFind and fix vulnerabilitieshttps://github.com/security/advanced-security
Code securitySecure your code as you buildhttps://github.com/security/advanced-security/code-security
Secret protectionStop leaks before they starthttps://github.com/security/advanced-security/secret-protection
Why GitHubhttps://github.com/why-github
Documentationhttps://docs.github.com
Bloghttps://github.blog
Changeloghttps://github.blog/changelog
Marketplacehttps://github.com/marketplace
View all featureshttps://github.com/features
Enterpriseshttps://github.com/enterprise
Small and medium teamshttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
App Modernizationhttps://github.com/solutions/use-case/app-modernization
DevSecOpshttps://github.com/solutions/use-case/devsecops
DevOpshttps://github.com/solutions/use-case/devops
CI/CDhttps://github.com/solutions/use-case/ci-cd
View all use caseshttps://github.com/solutions/use-case
Healthcarehttps://github.com/solutions/industry/healthcare
Financial serviceshttps://github.com/solutions/industry/financial-services
Manufacturinghttps://github.com/solutions/industry/manufacturing
Governmenthttps://github.com/solutions/industry/government
View all industrieshttps://github.com/solutions/industry
View all solutionshttps://github.com/solutions
AIhttps://github.com/resources/articles?topic=ai
Software Developmenthttps://github.com/resources/articles?topic=software-development
DevOpshttps://github.com/resources/articles?topic=devops
Securityhttps://github.com/resources/articles?topic=security
View all topicshttps://github.com/resources/articles
Customer storieshttps://github.com/customer-stories
Events & webinarshttps://github.com/resources/events
Ebooks & reportshttps://github.com/resources/whitepapers
Business insightshttps://github.com/solutions/executive-insights
GitHub Skillshttps://skills.github.com
Documentationhttps://docs.github.com
Customer supporthttps://support.github.com
Community forumhttps://github.com/orgs/community/discussions
Trust centerhttps://github.com/trust-center
Partnershttps://github.com/partners
View all resourceshttps://github.com/resources
GitHub SponsorsFund open source developershttps://github.com/open-source/sponsors
Security Labhttps://securitylab.github.com
Maintainer Communityhttps://maintainers.github.com
Acceleratorhttps://github.com/open-source/accelerator
GitHub Starshttps://stars.github.com
Archive Programhttps://archiveprogram.github.com
Topicshttps://github.com/topics
Trendinghttps://github.com/trending
Collectionshttps://github.com/collections
Enterprise platformAI-powered developer platformhttps://github.com/enterprise
GitHub Advanced SecurityEnterprise-grade security featureshttps://github.com/security/advanced-security
Copilot for BusinessEnterprise-grade AI featureshttps://github.com/features/copilot/copilot-business
Premium SupportEnterprise-grade 24/7 supporthttps://github.com/enterprise/premium-support
Pricinghttps://github.com/pricing
Search syntax tipshttps://docs.github.com/search-github/github-code-search/understanding-github-code-search-syntax
documentationhttps://docs.github.com/search-github/github-code-search/understanding-github-code-search-syntax
Sign in https://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpython%2Fcpython%2Fissues%2F121249
Sign up https://github.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E%2Fvoltron%2Fissues_fragments%2Fissue_layout&source=header-repo&source_repo=python%2Fcpython
Reloadhttps://github.com/python/cpython/issues/121249
Reloadhttps://github.com/python/cpython/issues/121249
Reloadhttps://github.com/python/cpython/issues/121249
Please reload this pagehttps://github.com/python/cpython/issues/121249
python https://github.com/python
cpythonhttps://github.com/python/cpython
Please reload this pagehttps://github.com/python/cpython/issues/121249
Notifications https://github.com/login?return_to=%2Fpython%2Fcpython
Fork 35k https://github.com/login?return_to=%2Fpython%2Fcpython
Star 73.7k https://github.com/login?return_to=%2Fpython%2Fcpython
Code https://github.com/python/cpython
Issues 5k+ https://github.com/python/cpython/issues
Pull requests 2.3k https://github.com/python/cpython/pulls
Actions https://github.com/python/cpython/actions
Projects https://github.com/python/cpython/projects
Security and quality 0 https://github.com/python/cpython/security
Insights https://github.com/python/cpython/pulse
Code https://github.com/python/cpython
Issues https://github.com/python/cpython/issues
Pull requests https://github.com/python/cpython/pulls
Actions https://github.com/python/cpython/actions
Projects https://github.com/python/cpython/projects
Security and quality https://github.com/python/cpython/security
Insights https://github.com/python/cpython/pulse
Add support for C99 complex type (_Complex) to the struct modulehttps://github.com/python/cpython/issues/121249#top
extension-modulesC modules in the Modules dirhttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22extension-modules%22
type-featureA feature request or enhancementhttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22type-feature%22
https://github.com/skirpichev
skirpichevhttps://github.com/skirpichev
on Jul 2, 2024https://github.com/python/cpython/issues/121249#issue-2385121145
gh-121249: Support _Complex types in the struct module #121613https://github.com/python/cpython/pull/121613
gh-121249: Note struct module changes in What's New #131867https://github.com/python/cpython/pull/131867
gh-121249: adjust formatting codes for complex types in struct/ctypes modules #132827https://github.com/python/cpython/pull/132827
gh-121249: fix naming of struct tagPyCArgObject members #132863https://github.com/python/cpython/pull/132863
gh-121249: unconditionally support complex types in struct #132864https://github.com/python/cpython/pull/132864
gh-121249: fix complex formatting codes in the struct docs (note 10) #133249https://github.com/python/cpython/pull/133249
gh-121249: remove F/D type codes from table in the struct module #149346https://github.com/python/cpython/pull/149346
[3.15] gh-121249: Soft deprecate F and D struct format types (#149346) #152274https://github.com/python/cpython/pull/152274
gh-121249: Deprecate using F/D type codes in the struct module #152309https://github.com/python/cpython/pull/152309
extension-modulesC modules in the Modules dirhttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22extension-modules%22
type-featureA feature request or enhancementhttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22type-feature%22
https://github.com
Termshttps://docs.github.com/site-policy/github-terms/github-terms-of-service
Privacyhttps://docs.github.com/site-policy/privacy-policies/github-privacy-statement
Securityhttps://github.com/security
Statushttps://www.githubstatus.com/
Communityhttps://github.community/
Docshttps://docs.github.com/
Contacthttps://support.github.com?tags=dotcom-footer

Viewport: width=device-width


URLs of crawlers that visited me.