Skip to content

Commit

Permalink
Fix error in comment, and in test_long_api and test_longlong_api remove
Browse files Browse the repository at this point in the history
the need for the F_ERROR macro.
  • Loading branch information
tim-one committed Jun 16, 2001
1 parent c605784 commit 83c9edc
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 26 deletions.
8 changes: 2 additions & 6 deletions Modules/_testcapimodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,6 @@ raise_test_long_error(const char* msg)
#define F_PY_TO_S PyLong_AsLong
#define F_U_TO_PY PyLong_FromUnsignedLong
#define F_PY_TO_U PyLong_AsUnsignedLong
#define F_ERROR raise_test_long_error

#include "testcapi_long.h"

Expand All @@ -212,7 +211,7 @@ test_long_api(PyObject* self, PyObject* args)
if (!PyArg_ParseTuple(args, ":test_long_api"))
return NULL;

return TESTNAME();
return TESTNAME(raise_test_long_error);
}

#undef TESTNAME
Expand All @@ -221,7 +220,6 @@ test_long_api(PyObject* self, PyObject* args)
#undef F_PY_TO_S
#undef F_U_TO_PY
#undef F_PY_TO_U
#undef F_ERROR

#ifdef HAVE_LONG_LONG

Expand All @@ -237,7 +235,6 @@ raise_test_longlong_error(const char* msg)
#define F_PY_TO_S PyLong_AsLongLong
#define F_U_TO_PY PyLong_FromUnsignedLongLong
#define F_PY_TO_U PyLong_AsUnsignedLongLong
#define F_ERROR raise_test_longlong_error

#include "testcapi_long.h"

Expand All @@ -247,7 +244,7 @@ test_longlong_api(PyObject* self, PyObject* args)
if (!PyArg_ParseTuple(args, ":test_longlong_api"))
return NULL;

return TESTNAME();
return TESTNAME(raise_test_longlong_error);
}

#undef TESTNAME
Expand All @@ -256,7 +253,6 @@ test_longlong_api(PyObject* self, PyObject* args)
#undef F_PY_TO_S
#undef F_U_TO_PY
#undef F_PY_TO_U
#undef F_ERROR

#endif /* ifdef HAVE_LONG_LONG */

Expand Down
39 changes: 19 additions & 20 deletions Modules/testcapi_long.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,11 @@
F_S_TO_PY convert signed to pylong; TYPENAME -> PyObject*
F_PY_TO_S convert pylong to signed; PyObject* -> TYPENAME
F_U_TO_PY convert unsigned to pylong; unsigned TYPENAME -> PyObject*
F_PY_TO_U convert pylong to unsigned; PyObject* -> TypeError
F_ERROR error-report function; char* -> PyObject* (returns NULL)
F_PY_TO_U convert pylong to unsigned; PyObject* -> unsigned TYPENAME
*/

static PyObject *
TESTNAME()
TESTNAME(PyObject *error(const char*))
{
const int NBITS = sizeof(TYPENAME) * 8;
unsigned TYPENAME base;
Expand Down Expand Up @@ -45,30 +44,30 @@ TESTNAME()

pyresult = F_U_TO_PY(uin);
if (pyresult == NULL)
return F_ERROR(
return error(
"unsigned unexpected null result");

uout = F_PY_TO_U(pyresult);
if (uout == (unsigned TYPENAME)-1 && PyErr_Occurred())
return F_ERROR(
return error(
"unsigned unexpected -1 result");
if (uout != uin)
return F_ERROR(
return error(
"unsigned output != input");
UNBIND(pyresult);

in = (TYPENAME)uin;
pyresult = F_S_TO_PY(in);
if (pyresult == NULL)
return F_ERROR(
return error(
"signed unexpected null result");

out = F_PY_TO_S(pyresult);
if (out == (TYPENAME)-1 && PyErr_Occurred())
return F_ERROR(
return error(
"signed unexpected -1 result");
if (out != in)
return F_ERROR(
return error(
"signed output != input");
UNBIND(pyresult);
}
Expand All @@ -85,37 +84,37 @@ TESTNAME()

one = PyLong_FromLong(1);
if (one == NULL)
return F_ERROR(
return error(
"unexpected NULL from PyLong_FromLong");

/* Unsigned complains about -1? */
x = PyNumber_Negative(one);
if (x == NULL)
return F_ERROR(
return error(
"unexpected NULL from PyNumber_Negative");

uout = F_PY_TO_U(x);
if (uout != (unsigned TYPENAME)-1 || !PyErr_Occurred())
return F_ERROR(
return error(
"PyLong_AsUnsignedXXX(-1) didn't complain");
PyErr_Clear();
UNBIND(x);

/* Unsigned complains about 2**NBITS? */
y = PyLong_FromLong((long)NBITS);
if (y == NULL)
return F_ERROR(
return error(
"unexpected NULL from PyLong_FromLong");

x = PyNumber_Lshift(one, y); /* 1L << NBITS, == 2**NBITS */
UNBIND(y);
if (x == NULL)
return F_ERROR(
return error(
"unexpected NULL from PyNumber_Lshift");

uout = F_PY_TO_U(x);
if (uout != (unsigned TYPENAME)-1 || !PyErr_Occurred())
return F_ERROR(
return error(
"PyLong_AsUnsignedXXX(2**NBITS) didn't "
"complain");
PyErr_Clear();
Expand All @@ -125,12 +124,12 @@ TESTNAME()
y = PyNumber_Rshift(x, one); /* 2**(NBITS-1) */
UNBIND(x);
if (y == NULL)
return F_ERROR(
return error(
"unexpected NULL from PyNumber_Rshift");

out = F_PY_TO_S(y);
if (out != (TYPENAME)-1 || !PyErr_Occurred())
return F_ERROR(
return error(
"PyLong_AsXXX(2**(NBITS-1)) didn't "
"complain");
PyErr_Clear();
Expand All @@ -140,18 +139,18 @@ TESTNAME()
x = PyNumber_Negative(y); /* -(2**(NBITS-1)) */
UNBIND(y);
if (x == NULL)
return F_ERROR(
return error(
"unexpected NULL from PyNumber_Negative");

y = PyNumber_Subtract(x, one); /* -(2**(NBITS-1))-1 */
UNBIND(x);
if (y == NULL)
return F_ERROR(
return error(
"unexpected NULL from PyNumber_Subtract");

out = F_PY_TO_S(y);
if (out != (TYPENAME)-1 || !PyErr_Occurred())
return F_ERROR(
return error(
"PyLong_AsXXX(-2**(NBITS-1)-1) didn't "
"complain");
PyErr_Clear();
Expand Down

0 comments on commit 83c9edc

Please sign in to comment.