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-1635741 port _testbuffer to multi-phase init by koubaa · Pull Request #22003 · python/cpython

Conversation

@koubaa

@koubaa koubaa commented Aug 29, 2020 •
edited by bedevere-bot
Loading

Uh oh!

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

Copy link
Copy Markdown
Contributor

@vstinner @shihai1991 please review

This is the other half of #21986

https://bugs.python.org/issue1635741

Sorry, something went wrong.

Uh oh!

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

All reactions
@the-knights-who-say-ni the-knights-who-say-ni added the CLA signed label Aug 29, 2020
@bedevere-bot bedevere-bot added the awaiting review label Aug 29, 2020
shihai1991
shihai1991 reviewed Aug 30, 2020
View reviewed changes
Comment thread Modules/_testbuffer.c Outdated

@shihai1991 shihai1991 Aug 30, 2020

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 can use PyModule_AddType in here too?

Sorry, something went wrong.

Uh oh!

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

All reactions

@koubaa koubaa Aug 30, 2020

Copy link
Copy Markdown
Contributor Author

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.

@shihai1991 yes and I guess I should convert these to heap types too

Sorry, something went wrong.

Uh oh!

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

All reactions

@koubaa koubaa Aug 30, 2020

Copy link
Copy Markdown
Contributor Author

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.

@shihai1991 @vstinner I am trying to convert the NDArray_Type to a heap type but it has binary functions in its as_mapping that need access to the module state, e.g.:

nd = (NDArrayObject *)ndarray_new(&NDArray_Type, NULL, NULL);

The signature of this method is:

static PyObject *
ndarray_subscript(NDArrayObject *self, PyObject *key)

There doesn't seem to be a way to get the module in this case - so I believe converting to heap types might block until a future PEP. Please correct me if I am wrong but I will proceed with using PyModule_AddType without heap types.

Sorry, something went wrong.

Uh oh!

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

All reactions

@shihai1991 shihai1991 Aug 31, 2020

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 can take a look of victor's PR: 1c2fa78

Sorry, something went wrong.

Uh oh!

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

All reactions

@koubaa koubaa Aug 31, 2020

Copy link
Copy Markdown
Contributor Author

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.

@shihai1991 That PR does not have any types with an as_mapping method defined

Sorry, something went wrong.

Uh oh!

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

All reactions

@vstinner vstinner Sep 3, 2020

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.

If it is not possible to subclass the type, you can use PyType_GetModule().

Sorry, something went wrong.

Uh oh!

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

All reactions

@koubaa koubaa Sep 4, 2020

Copy link
Copy Markdown
Contributor Author

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.

@vstinner I think I'm missing some information. How can I use PyType_GetModule() on a method signature like:

static PyObject *
ndarray_subscript(NDArrayObject *self, PyObject *key)

There is no type here for me to access.

Sorry, something went wrong.

Uh oh!

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

All reactions

@vstinner vstinner Sep 4, 2020

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.

Py_TYPE(self) gives you a type.

Sorry, something went wrong.

Uh oh!

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

All reactions

@koubaa koubaa Sep 5, 2020

Copy link
Copy Markdown
Contributor Author

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.

@vstinner oh, right. Every object struct starts with PyObject_HEAD which has the type. I totally forgot about that.

Sorry, something went wrong.

Uh oh!

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

All reactions
Comment thread Modules/_testbuffer.c Resolved

Uh oh!

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

vstinner
vstinner reviewed Sep 1, 2020
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.

I may be simpler to have one PR for _testbuffer, and another for overlapped. These changes are really complex, so it's hard to review hard. It's simpler when a PR is on a single extension module. But you can also keep the PR as it is. It's up to you.

cc @corona10 @shihai1991

Sorry, something went wrong.

Uh oh!

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

All reactions
Comment thread Modules/_testbuffer.c Resolved

Uh oh!

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

Comment thread Modules/_testbuffer.c Outdated

@vstinner vstinner Sep 1, 2020

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.

Hum, would it be possible to move these static variables to be able to clear them when the extension module is unloaded? It would require to pass the module to NDArray_Type creation, so be able to get the module state from a ndarray instance.

static const char *simple_fmt = "B";
static PyObject *simple_format = NULL;

Sorry, something went wrong.

Uh oh!

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

All reactions

@koubaa koubaa Sep 1, 2020

Copy link
Copy Markdown
Contributor Author

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.

@vstinner This seems tricky. How do you recommend passing the module to a static type like NDArray_Type. I can't put the module instance on the type or it will be overridden each time we do _testbuffer_exec. Is there a way to do this in tp_new?

Sorry, something went wrong.

Uh oh!

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

All reactions

@koubaa koubaa Sep 1, 2020

Copy link
Copy Markdown
Contributor Author

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.

@vstinner What if I just call PyUnicode_FromString every time it is used, since as you say this is just a test module. Struct and calcsize should be handled properly in any case.

Sorry, something went wrong.

Uh oh!

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

All reactions

@vstinner vstinner Sep 2, 2020

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.

Usually to convert an extension module to multiphase init, you must convert static types to heap types first.

Sorry, something went wrong.

Uh oh!

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

All reactions

@koubaa koubaa Sep 2, 2020

Copy link
Copy Markdown
Contributor Author

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.

@vstinner see my comment in response to @shihai1991 about this - I was not able to convert these to heap types

Sorry, something went wrong.

Uh oh!

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

All reactions
Comment thread Modules/_testbuffer.c Outdated

@vstinner vstinner Sep 1, 2020

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.

Converting _testbuffer to multiphase init allows to create two instances of the module, but the C implementation uses global variables which is incompatible with that:

static PyObject *Struct = NULL;
static PyObject *calcsize = NULL;

You must first avoid these global variables. I suggest you to attempt to pass the module to functions using Struct and calcsize, and then get Struct and calcsize from the module. Either use PyObject_GetAttrString() which can slow down the module (which is ok, the module is only used for testing purpose), or use a module state (see my other comment about that).

Sorry, something went wrong.

Uh oh!

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

All reactions

@koubaa koubaa Sep 1, 2020

Copy link
Copy Markdown
Contributor Author

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.

@vstinner I am more comfortable with module state, anyways eventually it will need it if we migrate to heap types.

Sorry, something went wrong.

Uh oh!

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

All reactions
Comment thread Modules/overlapped.c Resolved

Uh oh!

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

Comment thread Modules/overlapped.c Resolved

Uh oh!

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

Comment thread Modules/overlapped.c Resolved

Uh oh!

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

@corona10
corona10 self-requested a review September 1, 2020 12:58
koubaa added 2 commits September 1, 2020 17:17
@koubaa
port _testbuffer to multi-phase
ec3c86e
@koubaa
blurb
3542f6a
@koubaa
koubaa force-pushed the bpo-1635741-overlapped-testbuffer branch from 5ae8c40 to 3542f6a Compare September 1, 2020 22:25
@koubaa koubaa changed the title bpo-1635741 overlapped testbuffer bpo-1635741 port _testbuffer to multi-phase init Sep 1, 2020
koubaa added 2 commits September 1, 2020 20:42
@koubaa
test module state
64d4c62
@koubaa
heap types
a1db5b3
@koubaa

koubaa commented Sep 6, 2020

Copy link
Copy Markdown
Contributor Author

I converted to heap types but now tests are failing (seems to be due to the "mismatch between initializer element and format string" exception thrown by pack_single). I'm going to try to figure out what I did that causes this.

All reactions

Sorry, something went wrong.

Uh oh!

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

@koubaa
really switch to heap types
f269a43
@vstinner

vstinner commented Sep 7, 2020

Copy link
Copy Markdown
Member

I'm going to try to figure out what I did that causes this.

Good luck :-) Ping me when you consider that the PR is ready for a new review. You can write a first PR just to convert static types to heap types if you prefer, to ease debug, and to ease review.

All reactions

Sorry, something went wrong.

Uh oh!

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

@koubaa
fix issue
282a416
@koubaa koubaa mentioned this pull request Sep 7, 2020
bpo-1635741: testbuffer heap types #22131
Closed
@skrah

skrah commented Sep 8, 2020

Copy link
Copy Markdown
Contributor

Same here: It is a test module that does not require changes.

All reactions

Sorry, something went wrong.

Uh oh!

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

@kylotan kylotan mannequin mentioned this pull request Sep 19, 2022
Py_Finalize() doesn't clear all Python objects at exit #44470
Closed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@vstinner vstinner vstinner left review comments
@shihai1991 shihai1991 shihai1991 left review comments
@corona10 corona10 Awaiting requested review from corona10

Uh oh!

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

Assignees

No one assigned

Labels

awaiting review

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.

6 participants

@koubaa @vstinner @skrah @shihai1991 @the-knights-who-say-ni @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.