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

Fix a bug when passing data to GMT in Session.open_virtual_file() #490

Merged
merged 1 commit into from
Jun 24, 2020

Conversation

seisman
Copy link
Member

@seisman seisman commented Jun 24, 2020

Description of proposed changes

External programs like PyGMT can pass dataset/momory to GMT. By default,
GMT can read, modify and free the momery, which sometimes can cause
crashes.

Issue #406 reports an example in which PyGMT crashes. The issue was reported
to the upstream (see GenericMappingTools/gmt#3515
and GenericMappingTools/gmt#3528). It turns out
to be an API user error (i.e., a PyGMT bug).

As per the explanation of Paul, external programs like PyGMT should
always use GMT_IN|GMT_IS_REFERENCE to tell GMT that the data is
read-only, so that GMT won't try to change and free the memory.

This PR makes the change from GMT_IN to GMT_IN|GMT_IS_REFERENCE
in the Session.open_virtual_file() function, updates a few docstrings,
and also adds the script in #406 as a test.

Fixes #406.

GMT C API references: https://docs.generic-mapping-tools.org/latest/api.html#resource-registration

Reminders

  • Run make format and make check to make sure the code follows the style guide.
  • Add tests for new features or tests that would have caught the bug that you're fixing.
  • Add new public functions/methods/classes to doc/api/index.rst.
  • Write detailed docstrings for all functions/methods.
  • If adding new functionality, add an example to docstrings or tutorials.

External programs like PyGMT can pass dataset/momory to GMT. By default,
GMT can read, modify and free the momery, which sometimes can cause
crashes.

Issue #406 reports an example in which PyGMT crashes. The issue was reported
to the upstream (see GenericMappingTools/gmt#3515
and GenericMappingTools/gmt#3528). It turns out
to be a API user error (i.e., a PyGMT bug).

As per the explanation of Paul, external programs like PyGMT should
always use `GMT_IN|GMT_IS_REFERENCE` to tell GMT that the data is
read-only, so that GMT won't try to change and free the memory.

This PR makes the change from `GMT_IN` to `GMT_IN|GMT_IS_REFERENCE`
in the `Session.open_virtual_file()` function, updates a few docstrings,
and also adds the script in #406 as a test.
@seisman seisman requested review from weiji14 and leouieda June 24, 2020 03:43
@seisman seisman added bug Something isn't working maintenance Boring but important stuff for the core devs and removed maintenance Boring but important stuff for the core devs labels Jun 24, 2020
Copy link
Member

@weiji14 weiji14 left a comment

Choose a reason for hiding this comment

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

Cool, the test looks good. Can you edit the top post and add a link/reference to the GMT C API documentation section for GMT_ IN|GMT_IS_REFERENCE (I'm guessing it's https://docs.generic-mapping-tools.org/dev/api.html#resource-registration?) so others know about it in the future.

Anyways, should be good to merge 🎉

pygmt/clib/session.py Show resolved Hide resolved
pygmt/clib/session.py Show resolved Hide resolved
@seisman seisman merged commit 516e799 into master Jun 24, 2020
@seisman seisman deleted the fix-passing-read-only-data branch June 24, 2020 04:40
@weiji14 weiji14 modified the milestones: 0.2.x, 0.1.x Jun 24, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

plot crashes when plotting arrows
2 participants