if (!PyArg_ParseTuple(arg, "O:range", &m)) return (0);
if (grand_check(me)) return (0);
if (PyInt_Check(m)) {
- long mm = PyInt_AS_LONG(m);
- if (mm <= 0)
- goto notpos;
- if (mm <= 0xffffffff)
+ long mm = PyInt_AsLong(m);
+ if (mm == -1 && PyErr_Occurred()) PyErr_Clear();
+ else if (mm <= 0) goto notpos;
+ else if (mm <= 0xffffffff)
return (PyInt_FromLong(grand_range(GRAND_R(me), mm)));
}
- if ((x = getmp(m)) == 0)
- goto end;
- if (!MP_POSP(x))
- goto notpos;
+ if ((x = getmp(m)) == 0) goto end;
+ if (!MP_POSP(x)) goto notpos;
y = mprand_range(MP_NEW, x, GRAND_R(me), 0);
MP_DROP(x);
return (mp_pywrap(y));
if (!PyArg_ParseTuple(arg, "O&:block", convulong, &n)) goto end;
if (grand_check(me)) return (0);
rc = bytestring_pywrap(0, n);
- grand_fill(GRAND_R(me), PyString_AS_STRING(rc), n);
+ grand_fill(GRAND_R(me), BIN_PTR(rc), n);
end:
return (rc);
}
if (!PyArg_ParseTuple(arg, "O&:mask", convbin, &in)) return (0);
if (grand_check(me)) return (0);
rc = bytestring_pywrap(0, in.sz);
- q = (octet *)PyString_AS_STRING(rc);
+ q = (octet *)BIN_PTR(rc);
GR_FILL(r, q, in.sz);
p = in.p; n = in.sz; while (n--) *q++ ^= *p++;
return (rc);
}
static PyObject *grget_name(PyObject *me, void *hunoz)
- { return (grand_check(me) ? 0 : PyString_FromString(GRAND_R(me)->ops->name)); }
+ { return (grand_check(me) ? 0 : TEXT_FROMSTR(GRAND_R(me)->ops->name)); }
static PyObject *grget_cryptop(PyObject *me, void *hunoz)
{ return (grand_check(me) ? 0 : getbool(GRAND_R(me)->ops->f & GRAND_CRYPTO)); }
}
static PyObject *gccrget_name(PyObject *me, void *hunoz)
- { return (PyString_FromString(GCCRAND_INFO(me)->name)); }
+ { return (TEXT_FROMSTR(GCCRAND_INFO(me)->name)); }
static PyObject *gccrget_keysz(PyObject *me, void *hunoz)
{ return (keysz_pywrap(GCCRAND_INFO(me)->keysz)); }
grand *r = GRAND_R(me);
int n = r->ops->misc(r, DSARAND_SEEDSZ);
PyObject *rc = bytestring_pywrap(0, n);
- r->ops->misc(r, DSARAND_GETSEED, PyString_AS_STRING(rc));
+ r->ops->misc(r, DSARAND_GETSEED, BIN_PTR(rc));
return (rc);
}