Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bpo-42064: Move sqlite3 types to global state #26537

Merged
merged 8 commits into from
Jun 15, 2021

Conversation

erlend-aasland
Copy link
Contributor

@erlend-aasland erlend-aasland commented Jun 4, 2021

@erlend-aasland
Copy link
Contributor Author

Internal change only; skipping news.

@erlend-aasland erlend-aasland removed the request for review from pablogsal June 4, 2021 22:13
@erlend-aasland
Copy link
Contributor Author

@vstinner or @encukou: could one of you take a look at this? It's mostly search-and-replace (ish), except for the one case I've pointed out. Let me know if I should break this up in multiple PR's.

@encukou
Copy link
Member

encukou commented Jun 8, 2021

Hmm, I'm not too familiar with the plan for the sqlite module. The calls to pysqlite_get_state(NULL) will be replaced with non-NULL in the future, right?

It seems that so far, the only module that uses dynamic types with Argument Clinic's subclass_of is _ssl, and AFAICS, it does things by walking the MRO twice. It might be worth it to add better support for this need. For example, I could imagine checking if any superclass was defined using a given PyType_Spec.

@erlend-aasland
Copy link
Contributor Author

erlend-aasland commented Jun 8, 2021

Hmm, I'm not too familiar with the plan for the sqlite module.

Well... my plan is multi-phase init (which implies module state). Heap type conversion is done, and Argument Clinic is mostly in place; establishing a global state is a natural next step.

The calls to pysqlite_get_state(NULL) will be replaced with non-NULL in the future, right?

Correct. I could add a comment about that above pysqlite_get_state; those lines may look weird if that piece of information is missing.

EDIT: now I remember: grepping for pysqlite_get_state.NULL makes it easy to identify state lookups that need special care when we move from global to module state.

It seems that so far, the only module that uses dynamic types with Argument Clinic's subclass_of is _ssl, and AFAICS, it does things by walking the MRO twice. It might be worth it to add better support for this need. For example, I could imagine checking if any superclass was defined using a given PyType_Spec.

You're talking about a new API to optimise this, right?

EDIT: Yes, I see the twin clinic_state calls in the clinic files. That's unfortunate. _ssl solves this by adding a pointer to the state in the object state.

@encukou
Copy link
Member

encukou commented Jun 9, 2021

OK, then this PR looks like a good step!

You're talking about a new API to optimise this, right?

Yes. I noted it and will try to make some time for it.

@erlend-aasland
Copy link
Contributor Author

erlend-aasland commented Jun 9, 2021

OK, then this PR looks like a good step!

Yes, I believe it is. I think it's best to keep the "establish global state" PR's as simple as possible, for the reviewers convenience. Optimisations, for example passing state as a parameter to a function, or storing state members in the object context (as functools does), are easier add afterwards, IMO.

You're talking about a new API to optimise this, right?

Yes. I noted it and will try to make some time for it.

Fantastic. I'd be interested in following that process, for the sake of learning.

@erlend-aasland
Copy link
Contributor Author

LGTY, @encukou?

@encukou
Copy link
Member

encukou commented Jun 15, 2021

Looks good; thanks for the clarification!

@encukou encukou merged commit 10a5c80 into python:main Jun 15, 2021
@erlend-aasland erlend-aasland deleted the sqlite-move-types-to-global-state branch June 15, 2021 14:33
@erlend-aasland
Copy link
Contributor Author

Thanks for reviewing, @encukou !

jdevries3133 pushed a commit to jdevries3133/cpython that referenced this pull request Jun 19, 2021
* Move connection type to global state
* Move cursor type to global state
* Move prepare protocol type to global state
* Move row type to global state
* Move statement type to global state
* ADD_TYPE takes a pointer
* pysqlite_get_state is now static inline
@encukou
Copy link
Member

encukou commented Oct 12, 2021

Fantastic. I'd be interested in following that process, for the sake of learning.

I don't yet have time to get into this, but I put down some notes: encukou/abi3#19

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants