Skip to content
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
2 changes: 1 addition & 1 deletion .readthedocs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ build:
pre_create_environment:
- |
PREFIX=$(pwd)/.local
ZZ_VERSION=0.8.0a3
ZZ_VERSION=0.8.0b0
ZZ_DIR=zz-${ZZ_VERSION}
GITHUB_URL=https://github.com/diofant/zz/releases/download/
ZZ_URL=${GITHUB_URL}v${ZZ_VERSION}/${ZZ_DIR}.tar.gz
Expand Down
37 changes: 11 additions & 26 deletions gmp.c
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ MPZ_to_str(MPZ_Object *u, int base, int options)
assert(saved_char);
}

zz_err ret = zz_get_str(&u->z, base, p, &len);
zz_err ret = zz_get_str(&u->z, base, p);

if (saved_char) {
*p = saved_char;
Expand All @@ -120,11 +120,11 @@ MPZ_to_str(MPZ_Object *u, int base, int options)
return PyErr_NoMemory();
/* LCOV_EXCL_STOP */
}
p += len;
p += strlen(p);
if (options & OPT_TAG) {
*(p++) = ')';
*p = '\0';
}
*(p++) = '\0';

PyObject *res = PyUnicode_FromString(buf);

Expand All @@ -135,8 +135,7 @@ MPZ_to_str(MPZ_Object *u, int base, int options)
static MPZ_Object *
MPZ_from_str(PyObject *obj, int base)
{
Py_ssize_t len;
const char *str = PyUnicode_AsUTF8AndSize(obj, &len);
const char *str = PyUnicode_AsUTF8(obj);

if (!str) {
return NULL; /* LCOV_EXCL_LINE */
Expand All @@ -150,20 +149,17 @@ MPZ_from_str(PyObject *obj, int base)
if (!res) {
return (MPZ_Object *)PyErr_NoMemory(); /* LCOV_EXCL_LINE */
}
while (len && isspace(*str)) {
while (isspace(*str)) {
str++;
len--;
}

bool cast_negative = (str[0] == '-');

str += cast_negative;
len -= cast_negative;
if (len && str[0] == '+') {
if (str[0] == '+') {
str++;
len--;
}
if (str[0] == '0' && len >= 2) {
if (str[0] == '0') {
if (base == 0) {
if (tolower(str[1]) == 'b') {
base = 2;
Expand All @@ -174,7 +170,7 @@ MPZ_from_str(PyObject *obj, int base)
else if (tolower(str[1]) == 'x') {
base = 16;
}
else {
else if (!isspace(str[1]) && str[1] != '\0') {
goto err;
}
}
Expand All @@ -183,10 +179,8 @@ MPZ_from_str(PyObject *obj, int base)
|| (tolower(str[1]) == 'x' && base == 16))
{
str += 2;
len -= 2;
if (len && str[0] == '_') {
if (str[0] == '_') {
str++;
len--;
}
}
else {
Expand All @@ -196,21 +190,13 @@ MPZ_from_str(PyObject *obj, int base)
else {
skip_negation:
str -= cast_negative;
len += cast_negative;
cast_negative = false;
}
if (base == 0) {
base = 10;
}

const char *end = str + len - 1;

while (len > 0 && isspace(*end)) {
end--;
len--;
}

zz_err ret = zz_set_str(str, (size_t)len, base, &res->z);
zz_err ret = zz_set_str(str, base, &res->z);

if (ret == ZZ_MEM) {
/* LCOV_EXCL_START */
Expand Down Expand Up @@ -327,13 +313,12 @@ MPZ_to_int(MPZ_Object *u)

char *buf = malloc(len + 1);

if (zz_get_str(&u->z, 16, buf, &len)) {
if (zz_get_str(&u->z, 16, buf)) {
/* LCOV_EXCL_START */
free(buf);
return NULL;
/* LCOV_EXCL_STOP */
}
buf[len] = '\0';

PyObject *res = PyLong_FromString(buf, NULL, 16);

Expand Down
2 changes: 1 addition & 1 deletion scripts/cibw_before_all.sh
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ make --silent all install

cd ..

ZZ_VERSION=0.8.0a3
ZZ_VERSION=0.8.0b0
ZZ_DIR=zz-${ZZ_VERSION}
ZZ_URL=https://github.com/diofant/zz/releases/download/v${ZZ_VERSION}/${ZZ_DIR}.tar.gz

Expand Down
2 changes: 1 addition & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ def pytest_configure(config):
from hypothesis import settings

default = settings.get_profile("default")
settings.register_profile("default", settings(default, deadline=700))
settings.register_profile("default", settings(default, deadline=1600))
ci = settings.get_profile("ci")
if platform.python_implementation() != "GraalVM":
ci = settings(ci, max_examples=10000)
Expand Down