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 — bpo-42064: Pass module state to `sqlite3` UDF callbacks by erlend-aasland · Pull Request #27456 · python/cpython

Conversation

@erlend-aasland

@erlend-aasland erlend-aasland commented Jul 29, 2021 •
edited by miss-islington
Loading

Uh oh!

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

Copy link
Copy Markdown
Contributor
  • Establish common callback context struct
  • Convert UDF callbacks to fetch module state from callback context

https://bugs.python.org/issue42064

Automerge-Triggered-By: GH:encukou

Sorry, something went wrong.

Uh oh!

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

All reactions
Erlend E. Aasland added 2 commits July 29, 2021 21:01
Erlend E. Aasland
Add stubs for managing callback context
bebc47a
Erlend E. Aasland
Adapt create_*() functions
48a954d
@erlend-aasland
erlend-aasland requested a review from berkerpeksag as a code owner July 29, 2021 19:03
@bedevere-bot bedevere-bot added the awaiting review label Jul 29, 2021
@the-knights-who-say-ni the-knights-who-say-ni added the CLA signed label Jul 29, 2021
@erlend-aasland
erlend-aasland requested a review from encukou July 29, 2021 19:04
@erlend-aasland erlend-aasland added the skip news label Jul 29, 2021
@erlend-aasland

erlend-aasland commented Jul 29, 2021

Copy link
Copy Markdown
Contributor Author

A couple of questions, @encukou:

  • Do I need to ensure GIL is held in create_callback_context(), or can I get away with it like it is?
  • Ditto for free_callback_context()
All reactions

Sorry, something went wrong.

Uh oh!

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

@encukou

encukou commented Jul 30, 2021

Copy link
Copy Markdown
Member

Do I need to ensure GIL is held in create_callback_context(), or can I get away with it like it is?

There are very few funcitons in the C-API that you can call without the GIL held; usually they're the ones needed before a GIL is created. For PyMem_Malloc/PyMem_Free specifically, there's a a big red warning to answer your question ;)
PyMem_Malloc is configurable; the default allocator relies on the GIL for synchronization.

erlend-aasland reacted with thumbs up 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 commented Jul 30, 2021 •
edited
Loading

Uh oh!

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

Copy link
Copy Markdown
Contributor Author

There are very few funcitons in the C-API that you can call without the GIL held; usually they're the ones needed before a GIL is created. For PyMem_Malloc/PyMem_Free specifically, there's a a big red warning to answer your question ;)

Yes, I've seen it ;) But then why does this PR work as it is? (That is, without the GIL)

(FYI: I'll update the PR with GIL wrappers soon)

All reactions

Sorry, something went wrong.

Uh oh!

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

@encukou

encukou commented Jul 30, 2021

Copy link
Copy Markdown
Member

But then why does this PR work as it is?

I assume it's because you're not using multiple threads.
Even if you were, it might be rare to cause the memory allocator to run in two threads at once. But when it would, it'd crash quite spectacularly. (Or worse, if a malicious actor could cause it to happen.)

erlend-aasland reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

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

Erlend E. Aasland
Hold GIL when allocating/freeing context
c5da5ab
@erlend-aasland

erlend-aasland commented Jul 30, 2021

Copy link
Copy Markdown
Contributor Author

But then why does this PR work as it is?

I assume it's because you're not using multiple threads.
Even if you were, it might be rare to cause the memory allocator to run in two threads at once. But when it would, it'd crash quite spectacularly. (Or worse, if a malicious actor could cause it to happen.)

Ah, right. Thanks!

I've updated the PR. PTAL :)

All reactions

Sorry, something went wrong.

Uh oh!

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

@erlend-aasland

erlend-aasland commented Aug 6, 2021 •
edited
Loading

Uh oh!

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

Copy link
Copy Markdown
Contributor Author

On hold until #27613 has landed.

@encukou, this is now ready for review (again). PTAL.

All reactions

Sorry, something went wrong.

Uh oh!

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

@erlend-aasland
erlend-aasland marked this pull request as draft August 6, 2021 07:41
Erlend E. Aasland
Improve naming and remove some unneeded temporary variables
506390f
@erlend-aasland
erlend-aasland marked this pull request as ready for review August 6, 2021 19:16
encukou
encukou reviewed Aug 24, 2021
View reviewed changes
Comment thread Modules/_sqlite/connection.c Resolved

Uh oh!

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

Comment thread Modules/_sqlite/connection.c Resolved

Uh oh!

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

Erlend E. Aasland added 2 commits August 24, 2021 13:54
Erlend E. Aasland
Merge branch 'main' into sqlite-callback-state/part1
b5355d6
Erlend E. Aasland
Address review: protect incref with GIL
271b9b5
encukou
encukou approved these changes Aug 24, 2021
View reviewed changes

@encukou encukou 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.

I found some more questionable uses of the GIL in existing code (see the issue). But let's not block this PR; it is an improvement.

Sorry, something went wrong.

Uh oh!

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

erlend-aasland reacted with hooray emoji
All reactions
  • 🎉 1 reaction
@bedevere-bot bedevere-bot added awaiting merge and removed awaiting review labels Aug 24, 2021
@encukou encukou added the 🤖 automerge label Aug 24, 2021
@miss-islington
miss-islington merged commit 9ed5231 into python:main Aug 24, 2021
@bedevere-bot bedevere-bot removed the awaiting merge label Aug 24, 2021
@erlend-aasland
erlend-aasland deleted the sqlite-callback-state/part1 branch August 24, 2021 13:03
@erlend-aasland

erlend-aasland commented Aug 24, 2021

Copy link
Copy Markdown
Contributor Author

Thanks for reviewing!

All reactions

Sorry, something went wrong.

Uh oh!

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

@erlend-aasland erlend-aasland mentioned this pull request Aug 24, 2021
gh-79097: Add support for aggregate window functions in sqlite3 #20903
Merged
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@encukou encukou encukou approved these changes
@berkerpeksag berkerpeksag Awaiting requested review from berkerpeksag

Uh oh!

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

Assignees

No one assigned

Labels

skip news

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.

5 participants

@erlend-aasland @encukou @the-knights-who-say-ni @bedevere-bot @miss-islington
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.