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

gh-104469 Convert _testcapi/float.c to use AC #104470

Merged
merged 1 commit into from
May 15, 2023
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
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