Files
typthon/Modules/_testlimitedcapi/complex.c
copilot-swe-agent[bot] 42e2356c88 Fix incorrect replacements in Py_ to Ty_ renaming
Fixed several macros and constants that should not have been renamed:
- _Py_CAST, _Py_NULL, _Py_RVALUE (internal utility macros)
- Py_UNUSED (unused parameter macro)
- Py_EQ, Py_NE, Py_LT, Py_LE, Py_GT, Py_GE (comparison constants)
- Py_RETURN_* macros (NONE, TRUE, FALSE, NOTIMPLEMENTED, RICHCOMPARE)
- Py_READONLY, Py_ULL, Py_CONTEXT_SWITCHED
- TyGC_Head in generated clinic files

Build is still in progress with some remaining issues to resolve.

Co-authored-by: johndoe6345789 <224850594+johndoe6345789@users.noreply.github.com>
2025-12-29 17:44:05 +00:00

80 lines
1.6 KiB
C

#include "parts.h"
#include "util.h"
static TyObject *
complex_check(TyObject *Py_UNUSED(module), TyObject *obj)
{
NULLABLE(obj);
return TyLong_FromLong(TyComplex_Check(obj));
}
static TyObject *
complex_checkexact(TyObject *Py_UNUSED(module), TyObject *obj)
{
NULLABLE(obj);
return TyLong_FromLong(TyComplex_CheckExact(obj));
}
static TyObject *
complex_fromdoubles(TyObject *Py_UNUSED(module), TyObject *args)
{
double real, imag;
if (!TyArg_ParseTuple(args, "dd", &real, &imag)) {
return NULL;
}
return TyComplex_FromDoubles(real, imag);
}
static TyObject *
complex_realasdouble(TyObject *Py_UNUSED(module), TyObject *obj)
{
double real;
NULLABLE(obj);
real = TyComplex_RealAsDouble(obj);
if (real == -1. && TyErr_Occurred()) {
return NULL;
}
return TyFloat_FromDouble(real);
}
static TyObject *
complex_imagasdouble(TyObject *Py_UNUSED(module), TyObject *obj)
{
double imag;
NULLABLE(obj);
imag = TyComplex_ImagAsDouble(obj);
if (imag == -1. && TyErr_Occurred()) {
return NULL;
}
return TyFloat_FromDouble(imag);
}
static TyMethodDef test_methods[] = {
{"complex_check", complex_check, METH_O},
{"complex_checkexact", complex_checkexact, METH_O},
{"complex_fromdoubles", complex_fromdoubles, METH_VARARGS},
{"complex_realasdouble", complex_realasdouble, METH_O},
{"complex_imagasdouble", complex_imagasdouble, METH_O},
{NULL},
};
int
_PyTestLimitedCAPI_Init_Complex(TyObject *mod)
{
if (TyModule_AddFunctions(mod, test_methods) < 0) {
return -1;
}
return 0;
}