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

Trail Access #187

Merged
merged 23 commits into from
Jan 13, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
another try to make the travesty happy
  • Loading branch information
rkaminsk committed Jan 11, 2020
commit e629473ef71fe47feb4ef929103f30260af352c2
1 change: 0 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ matrix:
include:
- os: linux
compiler: gcc
python: 3.5
addons:
apt:
sources:
Expand Down
42 changes: 40 additions & 2 deletions libpyclingo/pyclingo.cc
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,46 @@
#else
#define OBBASE(x) x
#define Py_hash_t long
#define PySlice_Unpack _PySlice_Unpack
#define PySlice_AdjustIndices _PySlice_AdjustIndices

int PySlice_Unpack(PyObject *slice, Py_ssize_t *start, Py_ssize_t *stop, Py_ssize_t *step) {
Py_ssize_t length;
return PySlice_GetIndicesEx(reinterpret_cast<PySliceObject*>(slice), PY_SSIZE_T_MAX, start, stop, step, &length);
}

Py_ssize_t PySlice_AdjustIndices(Py_ssize_t length, Py_ssize_t *start, Py_ssize_t *stop, Py_ssize_t step) {
assert(step != 0);
assert(step >= -PY_SSIZE_T_MAX);
if (*start < 0) {
*start += length;
if (*start < 0) {
*start = (step < 0) ? -1 : 0;
}
}
else if (*start >= length) {
*start = (step < 0) ? length - 1 : length;
}
if (*stop < 0) {
*stop += length;
if (*stop < 0) {
*stop = (step < 0) ? -1 : 0;
}
}
else if (*stop >= length) {
*stop = (step < 0) ? length - 1 : length;
}
if (step < 0) {
if (*stop < *start) {
return (*start - *stop - 1) / (-step) + 1;
}
}
else {
if (*start < *stop) {
return (*stop - *start - 1) / step + 1;
}
}
return 0;
}

#endif

#ifndef PyVarObject_HEAD_INIT
Expand Down