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-30695: Add set_nomemory(start, stop) to _testcapi #2406

Merged
merged 3 commits into from
Jul 1, 2017
Merged

bpo-30695: Add set_nomemory(start, stop) to _testcapi #2406

merged 3 commits into from
Jul 1, 2017

Conversation

xdegaye
Copy link
Contributor

@xdegaye xdegaye commented Jun 26, 2017

No description provided.

@xdegaye xdegaye added the type-feature A feature request or enhancement label Jun 26, 2017
@mention-bot
Copy link

@xdegaye, thanks for your PR! By analyzing the history of the files in this pull request, we identified @larryhastings, @pitrou and @serhiy-storchaka to be potential reviewers.

typedef struct fm_filter_t {
void *data;
int (*has_memory) (struct fm_filter_t *);
} fm_filter_t;
Copy link
Member

Choose a reason for hiding this comment

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

This structure seems very generic, whereas the implementation is very specific.

Do we really need a configurable callback? Why not always call the same filter function and just store somewhere counters?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I must have misunderstood our discussion on issue 30695. I thought inclusion of pyfailmalloc in _testcapi (with its random start counter) was considered so that the test suite could be run forever until a problem with memory was detected. In that case a generic filter structure is useful. Otherwise I agree that the PR should be changed toward a simpler implementation.

typedef struct {
int count;
int start;
int stop;
Copy link
Member

Choose a reason for hiding this comment

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

I suggest to use Py_ssize_t here, to prevent integer overflows.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Will change the type of 'count' to Py_ssize_t.

Copy link
Member

@serhiy-storchaka serhiy-storchaka left a comment

Choose a reason for hiding this comment

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

Concur with Victor. This code looks overcomplicated.

fm_remove_filter(void)
{
if (FmFilter != NULL) {
if (FmFilter->data != NULL) {
Copy link
Member

Choose a reason for hiding this comment

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

You can call PyMem_RawFree() with NULL.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks. I will change that.

* to 0 (default) in which case allocation failures never stop. */
data->count = 0;
data->stop = 0;
if (! PyArg_ParseTuple(args, "i|i", &data->start, &data->stop)) {
Copy link
Member

Choose a reason for hiding this comment

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

Why use a space after !?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

For readability, a personal preference. But I see that the usage in Python code is overwhelmingly in favor of no space (5382 against 61 in the .c files), so I will change that.

@vstinner
Copy link
Member

This PR basically implements the same feature than pyfailmalloc. I don't see the need of including this PR and pyfailmalloc. So I suggest to focus on your PR!

@xdegaye
Copy link
Contributor Author

xdegaye commented Jun 29, 2017

Not sure if this PR is approved by the reviewers after the last changes.

@xdegaye xdegaye merged commit 85f6430 into python:master Jul 1, 2017
@xdegaye xdegaye deleted the bpo-30695 branch July 1, 2017 12:14
@miss-islington
Copy link
Contributor

Thanks @xdegaye for the PR 🌮🎉.. I'm working now to backport this PR to: 3.6.
🐍🍒⛏🤖

@bedevere-bot
Copy link

GH-4083 is a backport of this pull request to the 3.6 branch.

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Oct 23, 2017
xdegaye pushed a commit that referenced this pull request Oct 23, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type-feature A feature request or enhancement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants