Skip to content

Pass in NULL pointer to GMT_Get_Enum #224

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

Merged
merged 14 commits into from
Aug 17, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ env:
- DEPLOY_DOCS=false
- DEPLOY_PYPI=false
- CONDA_REQUIREMENTS="requirements.txt"
# Get GMT6 from the development channel
- CONDA_EXTRA_CHANNEL=conda-forge/label/dev

matrix:
# Build under the following configurations
Expand Down Expand Up @@ -55,8 +57,6 @@ before_install:
# Download and install miniconda and setup dependencies
# Need to source the script to set the PATH variable globaly
- source continuous-integration/travis/setup-miniconda.sh
# Install GMT from the dev channel to get development builds of GMT 6
- conda install --yes --quiet -c conda-forge/label/dev gmt=6.0.0a*
- if [ "$COVERAGE" == "true" ]; then
pip install codecov codacy-coverage codeclimate-test-reporter;
fi
Expand All @@ -70,7 +70,9 @@ install:

script:
# Check code for style and lint for code quality
# Black is Python 3.6 only so it can't be in the requirements file.
- if [ "$CHECK" == "true" ]; then
conda install --yes --quiet black python=$PYTHON;
make check;
fi
# Run the test suite. Make pytest report any captured output on stdout or stderr.
Expand Down
1 change: 0 additions & 1 deletion environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ name: gmt-python
channels:
- conda-forge
- conda-forge/label/dev
- defaults
dependencies:
- python=3.6
- pip
Expand Down
12 changes: 10 additions & 2 deletions gmt/clib/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,10 +214,17 @@ def __getitem__(self, name):

"""
c_get_enum = self.get_libgmt_func(
"GMT_Get_Enum", argtypes=[ctp.c_char_p], restype=ctp.c_int
"GMT_Get_Enum", argtypes=[ctp.c_void_p, ctp.c_char_p], restype=ctp.c_int
)

value = c_get_enum(name.encode())
# The C lib introduced the void API pointer to GMT_Get_Enum so that it's
# consistent with other functions. It doesn't use the pointer so we can pass in
# None (NULL pointer). We can't give it the actual pointer because we need to
# call GMT_Get_Enum when creating a new API session pointer (chicken-and-egg
# type of thing).
session = None

value = c_get_enum(session, name.encode())

if value is None or value == -99999:
raise GMTCLibError("Constant '{}' doesn't exits in libgmt.".format(name))
Expand Down Expand Up @@ -336,6 +343,7 @@ def print_func(file_pointer, message): # pylint: disable=unused-argument

padding = self["GMT_PAD_DEFAULT"]
session_type = self["GMT_SESSION_EXTERNAL"]

session = c_create_session(name.encode(), padding, session_type, print_func)

if session is None:
Expand Down
5 changes: 3 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# GMT isn't included because it needs to be downloaded from a separate channel
gmt=6.0.0*
numpy
pandas
xarray
Expand All @@ -11,7 +11,6 @@ pytest
pytest-cov
pytest-mpl
coverage
black
pylint
sphinx
sphinx_rtd_theme
Expand All @@ -20,3 +19,5 @@ numpydoc
twine
# The following are installed for checking possible conflicts
basemap
# Black is not included because it requires Python 3.6
#black