Skip to content

Commit

Permalink
gh-104469 Convert _testcapi/float.c to use AC (gh-104470)
Browse files Browse the repository at this point in the history
  • Loading branch information
corona10 authored May 15, 2023
1 parent 2cd1c87 commit 48b3617
Show file tree
Hide file tree
Showing 2 changed files with 123 additions and 19 deletions.
88 changes: 88 additions & 0 deletions Modules/_testcapi/clinic/float.c.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

54 changes: 35 additions & 19 deletions Modules/_testcapi/float.c
Original file line number Diff line number Diff line change
@@ -1,18 +1,29 @@
#define PY_SSIZE_T_CLEAN

#include "parts.h"
#include "clinic/float.c.h"


// Test PyFloat_Pack2(), PyFloat_Pack4() and PyFloat_Pack8()
/*[clinic input]
module _testcapi
[clinic start generated code]*/
/*[clinic end generated code: output=da39a3ee5e6b4b0d input=6361033e795369fc]*/

/*[clinic input]
_testcapi.float_pack
size: int
d: double
le: int
/
Test PyFloat_Pack2(), PyFloat_Pack4() and PyFloat_Pack8()
[clinic start generated code]*/

static PyObject *
test_float_pack(PyObject *self, PyObject *args)
_testcapi_float_pack_impl(PyObject *module, int size, double d, int le)
/*[clinic end generated code: output=7899bd98f8b6cb04 input=52c9115121999c98]*/
{
int size;
double d;
int le;
if (!PyArg_ParseTuple(args, "idi", &size, &d, &le)) {
return NULL;
}
switch (size)
{
case 2:
Expand Down Expand Up @@ -47,19 +58,24 @@ test_float_pack(PyObject *self, PyObject *args)
}


// Test PyFloat_Unpack2(), PyFloat_Unpack4() and PyFloat_Unpack8()
/*[clinic input]
_testcapi.float_unpack
data: str(accept={robuffer}, zeroes=True)
le: int
/
Test PyFloat_Unpack2(), PyFloat_Unpack4() and PyFloat_Unpack8()
[clinic start generated code]*/

static PyObject *
test_float_unpack(PyObject *self, PyObject *args)
_testcapi_float_unpack_impl(PyObject *module, const char *data,
Py_ssize_t data_length, int le)
/*[clinic end generated code: output=617059f889ddbfe4 input=c095e4bb75a696cd]*/
{
assert(!PyErr_Occurred());
const char *data;
Py_ssize_t size;
int le;
if (!PyArg_ParseTuple(args, "y#i", &data, &size, &le)) {
return NULL;
}
double d;
switch (size)
switch (data_length)
{
case 2:
d = PyFloat_Unpack2(data, le);
Expand All @@ -82,8 +98,8 @@ test_float_unpack(PyObject *self, PyObject *args)
}

static PyMethodDef test_methods[] = {
{"float_pack", test_float_pack, METH_VARARGS, NULL},
{"float_unpack", test_float_unpack, METH_VARARGS, NULL},
_TESTCAPI_FLOAT_PACK_METHODDEF
_TESTCAPI_FLOAT_UNPACK_METHODDEF
{NULL},
};

Expand Down

0 comments on commit 48b3617

Please sign in to comment.