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 — gh-106307: Fix PyMapping_GetOptionalItemString() by serhiy-storchaka · Pull Request #108797 · python/cpython

Conversation

@serhiy-storchaka

@serhiy-storchaka serhiy-storchaka commented Sep 2, 2023

Copy link
Copy Markdown
Member

The resulting pointer was not set to NULL if the creation of a temporary string object was failed.

The tests were also missed due to oversight.

Sorry, something went wrong.

Uh oh!

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

All reactions
@serhiy-storchaka
pythongh-106307: Fix PyMapping_GetOptionalItemString()
0d54c80
The resulting pointer was not set to NULL if the creation of a temporary
string object was failed.

The tests were also missed due to oversight.
@serhiy-storchaka serhiy-storchaka added skip issue skip news topic-C-API labels Sep 2, 2023
@serhiy-storchaka
serhiy-storchaka requested a review from vstinner September 2, 2023 04:26
@bedevere-bot bedevere-bot added the awaiting core review label Sep 2, 2023
vstinner
vstinner approved these changes Sep 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. I just propose adding a comment on the new macro.

Does Valgrind or similar tool detect the usage of uninitialized memory?

Sorry, something went wrong.

Uh oh!

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

All reactions
Comment thread Modules/_testcapi/util.h Resolved

Uh oh!

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

@serhiy-storchaka serhiy-storchaka mentioned this pull request Sep 6, 2023
C API tests: use special markers to test that output parameters were set #109014
Merged
@serhiy-storchaka
Merge branch 'main' into PyMapping_GetOptionalItemString-errors
382afb9
@serhiy-storchaka
serhiy-storchaka enabled auto-merge (squash) September 6, 2023 19:39
@serhiy-storchaka
serhiy-storchaka merged commit 3a08db8 into python:main Sep 6, 2023
@bedevere-bot bedevere-bot removed the awaiting core review label Sep 6, 2023
vstinner
vstinner approved these changes Sep 6, 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.

The _testcapi now intializes the variable used in the test:

static PyObject *
mapping_getoptionalitemstring(PyObject *self, PyObject *args)
{
    PyObject *obj, *value = UNINITIALIZED_PTR;

Sorry, something went wrong.

Uh oh!

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

All reactions
@vstinner

vstinner commented Sep 6, 2023

Copy link
Copy Markdown
Member

@erlend-aasland: Idea for the devguide: We should suggest to always initialized the &value parameter to NULL in case of errors. I just avoid any risk of using an uninitialized variable by misusing the C API. What do you think?

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

@erlend-aasland: Idea for the devguide: We should suggest to always initialized the &value parameter to NULL in case of errors. I just avoid any risk of using an uninitialized variable by misusing the C API. What do you think?

I have a PR for this, and you already approved it twice 😃 python/devguide#1128

vstinner reacted with laugh emoji
All reactions
  • 😄 1 reaction

Sorry, something went wrong.

Uh oh!

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

@erlend-aasland erlend-aasland mentioned this pull request Sep 6, 2023
Add guidelines for C API with output parameters python/devguide#1128
Closed
@serhiy-storchaka

serhiy-storchaka commented Sep 7, 2023

Copy link
Copy Markdown
Member Author

There are exceptions, like _PyEval_SliceIndex(), where the output parameter should not be set in some cases.

All reactions

Sorry, something went wrong.

Uh oh!

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

@serhiy-storchaka
serhiy-storchaka deleted the PyMapping_GetOptionalItemString-errors branch September 7, 2023 09:07
@erlend-aasland

erlend-aasland commented Sep 7, 2023

Copy link
Copy Markdown
Contributor

Exceptions are fine; guidelines are for the general case, not the special case.

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 have a PR for this, and you already approved it twice 😃 python/devguide#1128

Alright, I should approve it 3 or 4 times 👍👍👍👍

erlend-aasland reacted with laugh emoji AlexWaygood reacted with rocket emoji
All reactions
  • 😄 1 reaction
  • 🚀 1 reaction

Sorry, something went wrong.

Uh oh!

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

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

Uh oh!

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

Assignees

No one assigned

Labels

skip issue skip news topic-C-API

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

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

4 participants

@serhiy-storchaka @vstinner @erlend-aasland @bedevere-bot
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.