Skip to content

Separate type/constant declarations from functions in C headers#15760

Merged
Cryoris merged 5 commits into
Qiskit:mainfrom
jakelishman:c/separate-types
Mar 17, 2026
Merged

Separate type/constant declarations from functions in C headers#15760
Cryoris merged 5 commits into
Qiskit:mainfrom
jakelishman:c/separate-types

Conversation

@jakelishman

Copy link
Copy Markdown
Member

When importing the C header files in Python extension-module mode, we will need to generate the function definitions in a completely different manner to regular function prototypes resolved at link time. This separates off the definitions of types and constants (which are shared) from functions (which are not), so that a later patch can add the alternate form.


Depends on:

@jakelishman jakelishman added this to the 2.4.0 milestone Mar 5, 2026
@jakelishman jakelishman requested a review from a team as a code owner March 5, 2026 11:18
@jakelishman jakelishman added on hold Can not fix yet Changelog: Added Add an "Added" entry in the GitHub Release changelog. C API Related to the C API labels Mar 5, 2026
@github-project-automation github-project-automation Bot moved this to Ready in Qiskit 2.4 Mar 5, 2026
@qiskit-bot

Copy link
Copy Markdown
Collaborator

One or more of the following people are relevant to this code:

@mrossinek mrossinek left a comment

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.

(Reviewing only dd22bbe since the other commit is a roll-up of another base PR)

This looks nice! Just some comments/clarifications from my side 👍

Comment thread crates/bindgen/include/qiskit/funcs_py.h
Comment thread crates/bindgen/include/qiskit.h Outdated
Comment thread crates/bindgen/include/qiskit.h
Comment thread crates/bindgen/src/lib.rs
When importing the C header files in Python extension-module mode, we
will need to generate the function definitions in a completely different
manner to regular function prototypes resolved at link time.  This
separates off the definitions of types and constants (which are shared)
from functions (which are not), so that a later patch can add the
alternate form.
@jakelishman jakelishman removed the on hold Can not fix yet label Mar 11, 2026

@raynelfss raynelfss left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Quick question + typo

Comment thread crates/bindgen/src/lib.rs Outdated
Comment thread crates/bindgen/src/lib.rs

@Cryoris Cryoris left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This looks good and I'm happy to merge with the open questions addressed 🙂

Comment thread crates/bindgen/include/qiskit.h Outdated
Comment thread crates/bindgen/src/lib.rs
Comment thread crates/bindgen-c/src/main.rs
jakelishman and others added 3 commits March 16, 2026 18:36
Co-authored-by: Max Rossmannek <rmax@ethz.ch>
Co-authored-by: Julien Gacon <gaconju@gmail.com>
Co-authored-by: Raynel Sanchez <87539502+raynelfss@users.noreply.github.com>
mrossinek
mrossinek previously approved these changes Mar 17, 2026

@mrossinek mrossinek left a comment

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.

This looks good to me!

The only open thread is around updating the comments/documentation around funcs_py.h which I'm willing to accept as is, too. Being only a comment, it can also always be updated later on.

@Cryoris Cryoris left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM, thanks!

@Cryoris Cryoris enabled auto-merge March 17, 2026 10:28
// The top-level `qiskit.h` defines all the C API functions in a different manner if
// `QISKIT_PYTHON_EXTENSION` is defined. In Python-aware builds/distributions of the C API, this
// file is replaced by one that is safe to use in those situations. We leave this file in place
// with an explicit stub to provide a better explanations to users who have a version of the C API

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.

Suggested change
// with an explicit stub to provide a better explanations to users who have a version of the C API
// with an explicit stub to provide a better explanation to users who have a version of the C API

Either this or remove the a

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Ah good catch -- maybe Jake can just add this to one of the follow up PRs.

@Cryoris Cryoris added this pull request to the merge queue Mar 17, 2026
Merged via the queue into Qiskit:main with commit 95c6eea Mar 17, 2026
25 checks passed
@github-project-automation github-project-automation Bot moved this from Ready to Done in Qiskit 2.4 Mar 17, 2026
@jakelishman jakelishman deleted the c/separate-types branch March 17, 2026 11:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

C API Related to the C API Changelog: Added Add an "Added" entry in the GitHub Release changelog.

Projects

No open projects
Status: Done

Development

Successfully merging this pull request may close these issues.

5 participants