mirror of
https://github.com/python/cpython.git
synced 2025-09-26 10:19:53 +00:00
gh-128813: hide mixed-mode functions for complex arithmetic from C-API (#131703)
This commit is contained in:
parent
5ffb89420c
commit
79f7c67bf6
11 changed files with 91 additions and 111 deletions
|
@ -175,7 +175,7 @@
|
|||
@MODULE_XXSUBTYPE_TRUE@xxsubtype xxsubtype.c
|
||||
@MODULE__XXTESTFUZZ_TRUE@_xxtestfuzz _xxtestfuzz/_xxtestfuzz.c _xxtestfuzz/fuzzer.c
|
||||
@MODULE__TESTBUFFER_TRUE@_testbuffer _testbuffer.c
|
||||
@MODULE__TESTINTERNALCAPI_TRUE@_testinternalcapi _testinternalcapi.c _testinternalcapi/test_lock.c _testinternalcapi/pytime.c _testinternalcapi/set.c _testinternalcapi/test_critical_sections.c
|
||||
@MODULE__TESTINTERNALCAPI_TRUE@_testinternalcapi _testinternalcapi.c _testinternalcapi/test_lock.c _testinternalcapi/pytime.c _testinternalcapi/set.c _testinternalcapi/test_critical_sections.c _testinternalcapi/complex.c
|
||||
@MODULE__TESTCAPI_TRUE@_testcapi _testcapimodule.c _testcapi/vectorcall.c _testcapi/heaptype.c _testcapi/abstract.c _testcapi/unicode.c _testcapi/dict.c _testcapi/set.c _testcapi/list.c _testcapi/tuple.c _testcapi/getargs.c _testcapi/datetime.c _testcapi/docstring.c _testcapi/mem.c _testcapi/watchers.c _testcapi/long.c _testcapi/float.c _testcapi/complex.c _testcapi/numbers.c _testcapi/structmember.c _testcapi/exceptions.c _testcapi/code.c _testcapi/buffer.c _testcapi/pyatomic.c _testcapi/run.c _testcapi/file.c _testcapi/codec.c _testcapi/immortal.c _testcapi/gc.c _testcapi/hash.c _testcapi/time.c _testcapi/bytes.c _testcapi/object.c _testcapi/monitoring.c _testcapi/config.c _testcapi/import.c _testcapi/frame.c _testcapi/type.c _testcapi/function.c
|
||||
@MODULE__TESTLIMITEDCAPI_TRUE@_testlimitedcapi _testlimitedcapi.c _testlimitedcapi/abstract.c _testlimitedcapi/bytearray.c _testlimitedcapi/bytes.c _testlimitedcapi/codec.c _testlimitedcapi/complex.c _testlimitedcapi/dict.c _testlimitedcapi/eval.c _testlimitedcapi/float.c _testlimitedcapi/heaptype_relative.c _testlimitedcapi/import.c _testlimitedcapi/list.c _testlimitedcapi/long.c _testlimitedcapi/object.c _testlimitedcapi/pyos.c _testlimitedcapi/set.c _testlimitedcapi/sys.c _testlimitedcapi/tuple.c _testlimitedcapi/unicode.c _testlimitedcapi/vectorcall_limited.c _testlimitedcapi/version.c _testlimitedcapi/file.c
|
||||
@MODULE__TESTCLINIC_TRUE@_testclinic _testclinic.c
|
||||
|
|
|
@ -57,48 +57,10 @@ _py_c_neg(PyObject *Py_UNUSED(module), PyObject *num)
|
|||
return Py_BuildValue("Di", &res, errno); \
|
||||
};
|
||||
|
||||
#define _PY_CR_FUNC2(suffix) \
|
||||
static PyObject * \
|
||||
_py_cr_##suffix(PyObject *Py_UNUSED(module), PyObject *args) \
|
||||
{ \
|
||||
Py_complex a, res; \
|
||||
double b; \
|
||||
\
|
||||
if (!PyArg_ParseTuple(args, "Dd", &a, &b)) { \
|
||||
return NULL; \
|
||||
} \
|
||||
\
|
||||
errno = 0; \
|
||||
res = _Py_cr_##suffix(a, b); \
|
||||
return Py_BuildValue("Di", &res, errno); \
|
||||
};
|
||||
|
||||
#define _PY_RC_FUNC2(suffix) \
|
||||
static PyObject * \
|
||||
_py_rc_##suffix(PyObject *Py_UNUSED(module), PyObject *args) \
|
||||
{ \
|
||||
Py_complex b, res; \
|
||||
double a; \
|
||||
\
|
||||
if (!PyArg_ParseTuple(args, "dD", &a, &b)) { \
|
||||
return NULL; \
|
||||
} \
|
||||
\
|
||||
errno = 0; \
|
||||
res = _Py_rc_##suffix(a, b); \
|
||||
return Py_BuildValue("Di", &res, errno); \
|
||||
};
|
||||
|
||||
_PY_C_FUNC2(sum)
|
||||
_PY_CR_FUNC2(sum)
|
||||
_PY_C_FUNC2(diff)
|
||||
_PY_CR_FUNC2(diff)
|
||||
_PY_RC_FUNC2(diff)
|
||||
_PY_C_FUNC2(prod)
|
||||
_PY_CR_FUNC2(prod)
|
||||
_PY_C_FUNC2(quot)
|
||||
_PY_CR_FUNC2(quot)
|
||||
_PY_RC_FUNC2(quot)
|
||||
_PY_C_FUNC2(pow)
|
||||
|
||||
static PyObject*
|
||||
|
@ -124,16 +86,10 @@ static PyMethodDef test_methods[] = {
|
|||
{"complex_fromccomplex", complex_fromccomplex, METH_O},
|
||||
{"complex_asccomplex", complex_asccomplex, METH_O},
|
||||
{"_py_c_sum", _py_c_sum, METH_VARARGS},
|
||||
{"_py_cr_sum", _py_cr_sum, METH_VARARGS},
|
||||
{"_py_c_diff", _py_c_diff, METH_VARARGS},
|
||||
{"_py_cr_diff", _py_cr_diff, METH_VARARGS},
|
||||
{"_py_rc_diff", _py_rc_diff, METH_VARARGS},
|
||||
{"_py_c_neg", _py_c_neg, METH_O},
|
||||
{"_py_c_prod", _py_c_prod, METH_VARARGS},
|
||||
{"_py_cr_prod", _py_cr_prod, METH_VARARGS},
|
||||
{"_py_c_quot", _py_c_quot, METH_VARARGS},
|
||||
{"_py_cr_quot", _py_cr_quot, METH_VARARGS},
|
||||
{"_py_rc_quot", _py_rc_quot, METH_VARARGS},
|
||||
{"_py_c_pow", _py_c_pow, METH_VARARGS},
|
||||
{"_py_c_abs", _py_c_abs, METH_O},
|
||||
{NULL},
|
||||
|
|
|
@ -2118,6 +2118,9 @@ module_exec(PyObject *module)
|
|||
if (_PyTestInternalCapi_Init_Set(module) < 0) {
|
||||
return 1;
|
||||
}
|
||||
if (_PyTestInternalCapi_Init_Complex(module) < 0) {
|
||||
return 1;
|
||||
}
|
||||
if (_PyTestInternalCapi_Init_CriticalSection(module) < 0) {
|
||||
return 1;
|
||||
}
|
||||
|
|
66
Modules/_testinternalcapi/complex.c
Normal file
66
Modules/_testinternalcapi/complex.c
Normal file
|
@ -0,0 +1,66 @@
|
|||
#include "parts.h"
|
||||
#include "../_testcapi/util.h"
|
||||
|
||||
#define Py_BUILD_CORE
|
||||
#include "pycore_complexobject.h"
|
||||
|
||||
|
||||
#define _PY_CR_FUNC2(suffix) \
|
||||
static PyObject * \
|
||||
_py_cr_##suffix(PyObject *Py_UNUSED(module), PyObject *args) \
|
||||
{ \
|
||||
Py_complex a, res; \
|
||||
double b; \
|
||||
\
|
||||
if (!PyArg_ParseTuple(args, "Dd", &a, &b)) { \
|
||||
return NULL; \
|
||||
} \
|
||||
\
|
||||
errno = 0; \
|
||||
res = _Py_cr_##suffix(a, b); \
|
||||
return Py_BuildValue("Di", &res, errno); \
|
||||
};
|
||||
|
||||
#define _PY_RC_FUNC2(suffix) \
|
||||
static PyObject * \
|
||||
_py_rc_##suffix(PyObject *Py_UNUSED(module), PyObject *args) \
|
||||
{ \
|
||||
Py_complex b, res; \
|
||||
double a; \
|
||||
\
|
||||
if (!PyArg_ParseTuple(args, "dD", &a, &b)) { \
|
||||
return NULL; \
|
||||
} \
|
||||
\
|
||||
errno = 0; \
|
||||
res = _Py_rc_##suffix(a, b); \
|
||||
return Py_BuildValue("Di", &res, errno); \
|
||||
};
|
||||
|
||||
_PY_CR_FUNC2(sum)
|
||||
_PY_CR_FUNC2(diff)
|
||||
_PY_RC_FUNC2(diff)
|
||||
_PY_CR_FUNC2(prod)
|
||||
_PY_CR_FUNC2(quot)
|
||||
_PY_RC_FUNC2(quot)
|
||||
|
||||
|
||||
static PyMethodDef test_methods[] = {
|
||||
{"_py_cr_sum", _py_cr_sum, METH_VARARGS},
|
||||
{"_py_cr_diff", _py_cr_diff, METH_VARARGS},
|
||||
{"_py_rc_diff", _py_rc_diff, METH_VARARGS},
|
||||
{"_py_cr_prod", _py_cr_prod, METH_VARARGS},
|
||||
{"_py_cr_quot", _py_cr_quot, METH_VARARGS},
|
||||
{"_py_rc_quot", _py_rc_quot, METH_VARARGS},
|
||||
{NULL},
|
||||
};
|
||||
|
||||
int
|
||||
_PyTestInternalCapi_Init_Complex(PyObject *mod)
|
||||
{
|
||||
if (PyModule_AddFunctions(mod, test_methods) < 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
|
@ -13,6 +13,7 @@
|
|||
int _PyTestInternalCapi_Init_Lock(PyObject *module);
|
||||
int _PyTestInternalCapi_Init_PyTime(PyObject *module);
|
||||
int _PyTestInternalCapi_Init_Set(PyObject *module);
|
||||
int _PyTestInternalCapi_Init_Complex(PyObject *module);
|
||||
int _PyTestInternalCapi_Init_CriticalSection(PyObject *module);
|
||||
|
||||
#endif // Py_TESTINTERNALCAPI_PARTS_H
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue