GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Add guidelines for C API with output parameters by erlend-aasland · Pull Request #1128 · python/devguide

Conversation

@erlend-aasland

@erlend-aasland erlend-aasland commented Jun 26, 2023 •
edited by github-actions Bot
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

📚 Documentation preview 📚: https://cpython-devguide--1128.org.readthedocs.build/

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@erlend-aasland
Add guidelines for C API with output parameters
f4b9c29
@erlend-aasland
erlend-aasland requested review from encukou, markshannon and vstinner June 26, 2023 09:30
vstinner
vstinner reviewed Jun 26, 2023
View reviewed changes
Comment thread developer-workflow/c-api.rst Resolved

Uh oh!

There was an error while loading. Please reload this page.

vstinner
vstinner reviewed Jun 26, 2023
View reviewed changes
Comment thread developer-workflow/c-api.rst Resolved

Uh oh!

There was an error while loading. Please reload this page.

@erlend-aasland
Address review: fix example
50a9805
@erlend-aasland erlend-aasland linked an issue Jun 26, 2023 that may be closed by this pull request
C API: Add guidelines for C APIs with output params #1125
Closed
vstinner
vstinner reviewed Jun 26, 2023
View reviewed changes
Comment thread developer-workflow/c-api.rst Resolved

Uh oh!

There was an error while loading. Please reload this page.

erlend-aasland added 3 commits June 26, 2023 12:55
@erlend-aasland
Address review: make example more explicit by adding explanatory comm…
cf5eeb3
…ents
@erlend-aasland
Fix sphinx formatting
8e90a69
@erlend-aasland
Address review: reword
f026d7a
vstinner
vstinner approved these changes Jun 26, 2023
View reviewed changes

@vstinner vstinner left a comment

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

LGTM, I just left some comments

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread developer-workflow/c-api.rst Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread developer-workflow/c-api.rst
PyFoo_Bar(PyObject **out)
{
PyObject *value;
int rc = foo_bar(&value);

@vstinner vstinner Jun 26, 2023 •
edited by terryjreedy
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Maybe you could mimic a legacy API call which returns NULL if not found and on error, and call PyErr_Occurred(). So the difference with the two APIs is even more obvious?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@erlend-aasland
Address review: american spelling
8792d61
vstinner
vstinner approved these changes Jul 2, 2023
View reviewed changes

@vstinner vstinner left a comment

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

LGTM.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@erlend-aasland erlend-aasland mentioned this pull request Jul 11, 2023
gh-106307: Add PyMapping_GetOptionalItem() python/cpython#106308
Merged
@erlend-aasland
erlend-aasland requested a review from serhiy-storchaka July 12, 2023 21:40
@erlend-aasland erlend-aasland mentioned this pull request Sep 6, 2023
gh-106307: Fix PyMapping_GetOptionalItemString() python/cpython#108797
Merged
@erlend-aasland

erlend-aasland commented Sep 6, 2023

Copy link
Copy Markdown
Contributor Author

See also python/cpython#108797.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@vstinner

vstinner commented Sep 6, 2023

Copy link
Copy Markdown
Member

Do you need a different review? Or are you waiting for something?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@erlend-aasland

erlend-aasland commented Sep 6, 2023

Copy link
Copy Markdown
Contributor Author

Do you need a different review? Or are you waiting for something?

I think @encukou wants to wait until the sprint before any C API guidelines are updated in any kind of way. Correct me if I'm wrong, Petr.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@vstinner

vstinner commented Sep 6, 2023

Copy link
Copy Markdown
Member

I think @encukou wants to wait until the sprint before any C API guidelines are updated in any kind of way. Correct me if I'm wrong, Petr.

Oh, I wasn't aware of that.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@serhiy-storchaka

serhiy-storchaka commented Sep 7, 2023

Copy link
Copy Markdown
Member

Some converters, like _PyEval_SliceIndex(), are designed so that they do not set the output parameter if the argument is None. It allows to set the default value to what you want: 0, -1, PY_SSIZE_T_MAX or Py_SIZE(self). It is the only way, because the signature of such converters is fixed, and they cannot take other arguments.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@erlend-aasland

erlend-aasland commented Sep 7, 2023

Copy link
Copy Markdown
Contributor Author

Some converters, like _PyEval_SliceIndex(), are designed so that they do not set the output parameter if the argument is None. It allows to set the default value to what you want: 0, -1, PY_SSIZE_T_MAX or Py_SIZE(self). It is the only way, because the signature of such converters is fixed, and they cannot take other arguments.

As I commented on python/cpython#108797, I think the guideline should care only about the general case, not the special case. There will be deviant APIs once in a while; that's ok.

BTW, _PyEval_SliceIndex is exposed through Python.h, but I guess it is considered an internal and/or private API since it is not documented and it is prefixed with an underscore. The guidelines are for public API.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@vstinner

vstinner commented Sep 7, 2023

Copy link
Copy Markdown
Member

I think the guideline should care only about the general case, not the special case.

I concur with @erlend-aasland on that.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@vstinner

vstinner commented Sep 7, 2023

Copy link
Copy Markdown
Member

FYI there is one public converter :-) PyUnicode_FSConverter().

I tried to move other private ones to the internal C API, but it's quite complicated: python/cpython#106320 (comment) I decided to give up in Python 3.13. I prefer to wait to see what's going on with the limited C API.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@willingc willingc added the DO-NOT-MERGE Do not merge this PR label Oct 10, 2023
@erlend-aasland

erlend-aasland commented Oct 11, 2023

Copy link
Copy Markdown
Contributor Author

I'll leave this to the C API workgroup.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@erlend-aasland erlend-aasland closed this Oct 11, 2023
@erlend-aasland
erlend-aasland deleted the c-api/guidelines-output-params branch October 11, 2023 21:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@vstinner vstinner vstinner approved these changes
@markshannon markshannon Awaiting requested review from markshannon
@encukou encukou Awaiting requested review from encukou
@serhiy-storchaka serhiy-storchaka Awaiting requested review from serhiy-storchaka

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

DO-NOT-MERGE Do not merge this PR

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

C API: Add guidelines for C APIs with output params

Uh oh!

There was an error while loading. Please reload this page.

4 participants

@erlend-aasland @vstinner @serhiy-storchaka @willingc
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.