mirror of
https://github.com/python/cpython.git
synced 2025-08-31 05:58:33 +00:00
gh-104469 Convert _testcapi/float.c to use AC (gh-104470)
This commit is contained in:
parent
2cd1c87d2a
commit
48b3617de4
2 changed files with 123 additions and 19 deletions
88
Modules/_testcapi/clinic/float.c.h
generated
Normal file
88
Modules/_testcapi/clinic/float.c.h
generated
Normal file
|
@ -0,0 +1,88 @@
|
|||
/*[clinic input]
|
||||
preserve
|
||||
[clinic start generated code]*/
|
||||
|
||||
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
|
||||
# include "pycore_gc.h" // PyGC_Head
|
||||
# include "pycore_runtime.h" // _Py_ID()
|
||||
#endif
|
||||
|
||||
|
||||
PyDoc_STRVAR(_testcapi_float_pack__doc__,
|
||||
"float_pack($module, size, d, le, /)\n"
|
||||
"--\n"
|
||||
"\n"
|
||||
"Test PyFloat_Pack2(), PyFloat_Pack4() and PyFloat_Pack8()");
|
||||
|
||||
#define _TESTCAPI_FLOAT_PACK_METHODDEF \
|
||||
{"float_pack", _PyCFunction_CAST(_testcapi_float_pack), METH_FASTCALL, _testcapi_float_pack__doc__},
|
||||
|
||||
static PyObject *
|
||||
_testcapi_float_pack_impl(PyObject *module, int size, double d, int le);
|
||||
|
||||
static PyObject *
|
||||
_testcapi_float_pack(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
|
||||
{
|
||||
PyObject *return_value = NULL;
|
||||
int size;
|
||||
double d;
|
||||
int le;
|
||||
|
||||
if (!_PyArg_CheckPositional("float_pack", nargs, 3, 3)) {
|
||||
goto exit;
|
||||
}
|
||||
size = _PyLong_AsInt(args[0]);
|
||||
if (size == -1 && PyErr_Occurred()) {
|
||||
goto exit;
|
||||
}
|
||||
if (PyFloat_CheckExact(args[1])) {
|
||||
d = PyFloat_AS_DOUBLE(args[1]);
|
||||
}
|
||||
else
|
||||
{
|
||||
d = PyFloat_AsDouble(args[1]);
|
||||
if (d == -1.0 && PyErr_Occurred()) {
|
||||
goto exit;
|
||||
}
|
||||
}
|
||||
le = _PyLong_AsInt(args[2]);
|
||||
if (le == -1 && PyErr_Occurred()) {
|
||||
goto exit;
|
||||
}
|
||||
return_value = _testcapi_float_pack_impl(module, size, d, le);
|
||||
|
||||
exit:
|
||||
return return_value;
|
||||
}
|
||||
|
||||
PyDoc_STRVAR(_testcapi_float_unpack__doc__,
|
||||
"float_unpack($module, data, le, /)\n"
|
||||
"--\n"
|
||||
"\n"
|
||||
"Test PyFloat_Unpack2(), PyFloat_Unpack4() and PyFloat_Unpack8()");
|
||||
|
||||
#define _TESTCAPI_FLOAT_UNPACK_METHODDEF \
|
||||
{"float_unpack", _PyCFunction_CAST(_testcapi_float_unpack), METH_FASTCALL, _testcapi_float_unpack__doc__},
|
||||
|
||||
static PyObject *
|
||||
_testcapi_float_unpack_impl(PyObject *module, const char *data,
|
||||
Py_ssize_t data_length, int le);
|
||||
|
||||
static PyObject *
|
||||
_testcapi_float_unpack(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
|
||||
{
|
||||
PyObject *return_value = NULL;
|
||||
const char *data;
|
||||
Py_ssize_t data_length;
|
||||
int le;
|
||||
|
||||
if (!_PyArg_ParseStack(args, nargs, "y#i:float_unpack",
|
||||
&data, &data_length, &le)) {
|
||||
goto exit;
|
||||
}
|
||||
return_value = _testcapi_float_unpack_impl(module, data, data_length, le);
|
||||
|
||||
exit:
|
||||
return return_value;
|
||||
}
|
||||
/*[clinic end generated code: output=083e5df26cd5fbeb input=a9049054013a1b77]*/
|
|
@ -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:
|
||||
|
@ -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);
|
||||
|
@ -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},
|
||||
};
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue