@@ -2077,16 +2077,12 @@ static PyStructSequence_Desc waitid_result_desc = {
2077
2077
#endif
2078
2078
2079
2079
static PyObject *
2080
- statresult_new (PyTypeObject * type , PyObject * args , PyObject * kwargs )
2080
+ statresult_new (PyTypeObject * type , PyObject * args )
2081
2081
{
2082
2082
PyObject * sequence , * kwds ;
2083
2083
PyStructSequence * result ;
2084
2084
int i ;
2085
2085
2086
- if (!_PyArg_NoKeywords ("StatResult" , kwargs )) {
2087
- return NULL ;
2088
- }
2089
-
2090
2086
/* Remove the cls object from the argument list */
2091
2087
sequence = PyTuple_GetSlice (args , 1 , PyTuple_Size (args ));
2092
2088
if (!sequence ) {
@@ -6253,20 +6249,24 @@ PyDoc_STRVAR(os_sched_param__doc__,
6253
6249
" A scheduling parameter." );
6254
6250
6255
6251
static PyObject *
6256
- os_sched_param (PyObject * module , PyObject * args , PyObject * kwargs )
6252
+ os_sched_param (PyTypeObject * type , PyObject * args , PyObject * kwargs )
6257
6253
{
6258
6254
static char * _keywords [] = {"sched_priority" , NULL };
6259
6255
static const char * _format = "O:sched_param" ;
6260
- PyObject * sched_priority , * res ;
6256
+ PyObject * sequence , * sched_priority , * res ;
6261
6257
6258
+ /* Remove the cls object from the argument list */
6259
+ sequence = PyTuple_GetSlice (args , 1 , PyTuple_Size (args ));
6260
+ if (!sequence ) {
6261
+ return NULL ;
6262
+ }
6262
6263
int result = PyArg_ParseTupleAndKeywords (args , kwargs , _format , _keywords ,
6263
6264
& sched_priority );
6265
+ Py_DECREF (sequence );
6264
6266
if (!result ) {
6265
6267
return NULL ;
6266
6268
}
6267
- res = PyStructSequence_New (
6268
- (PyTypeObject * )_posixstate (module )-> SchedParamType
6269
- );
6269
+ res = PyStructSequence_New ((PyTypeObject * )type );
6270
6270
if (!res ) {
6271
6271
return NULL ;
6272
6272
}
@@ -6275,22 +6275,6 @@ os_sched_param(PyObject *module, PyObject *args, PyObject *kwargs)
6275
6275
return res ;
6276
6276
}
6277
6277
6278
- static PyObject *
6279
- sched_param_new (PyTypeObject * type , PyObject * args , PyObject * kwargs ) {
6280
- PyObject * module = PyState_FindModule (& posixmodule );
6281
- if (!module ) {
6282
- return NULL ;
6283
- }
6284
- /* Remove the cls object from the argument list */
6285
- PyObject * sequence = PyTuple_GetSlice (args , 1 , PyTuple_Size (args ));
6286
- if (!sequence ) {
6287
- return NULL ;
6288
- }
6289
- PyObject * result = os_sched_param (module , args , kwargs );
6290
- Py_DECREF (sequence );
6291
- return result ;
6292
- }
6293
-
6294
6278
static PyStructSequence_Field sched_param_fields [] = {
6295
6279
{"sched_priority" , "the scheduling priority" },
6296
6280
{0 }
@@ -13593,6 +13577,16 @@ os__remove_dll_directory_impl(PyObject *module, PyObject *cookie)
13593
13577
13594
13578
#endif
13595
13579
13580
+ #if defined(HAVE_SCHED_SETPARAM ) || defined(HAVE_SCHED_SETSCHEDULER ) || defined(POSIX_SPAWN_SETSCHEDULER ) || defined(POSIX_SPAWN_SETSCHEDPARAM )
13581
+ static PyMethodDef SchedParamType_dunder_new = {
13582
+ "__new__" , (PyCFunction )os_sched_param , METH_VARARGS | METH_KEYWORDS
13583
+ };
13584
+ #endif
13585
+
13586
+ static PyMethodDef StatResultType_dunder_new = {
13587
+ "__new__" , (PyCFunction )statresult_new , METH_VARARGS
13588
+ };
13589
+
13596
13590
static PyMethodDef posix_methods [] = {
13597
13591
13598
13592
OS_STAT_METHODDEF
@@ -14446,7 +14440,7 @@ static const char * const have_functions[] = {
14446
14440
PyMODINIT_FUNC
14447
14441
INITFUNC (void )
14448
14442
{
14449
- PyObject * m , * v ;
14443
+ PyObject * m , * v , * dunder_new ;
14450
14444
PyObject * list ;
14451
14445
const char * const * trace ;
14452
14446
@@ -14504,10 +14498,14 @@ INITFUNC(void)
14504
14498
Py_INCREF (StatResultType );
14505
14499
PyModule_AddObject (m , "stat_result" , StatResultType );
14506
14500
_posixstate (m )-> StatResultType = StatResultType ;
14507
-
14508
14501
/* Add a custom __new__ to the structsequence */
14509
- _posixstate (m )-> structseq_new = ((PyTypeObject * )StatResultType )-> tp_new ;
14510
- ((PyTypeObject * )StatResultType )-> tp_new = statresult_new ;
14502
+ _posixstate (m )-> structseq_new = (newfunc )PyType_GetSlot ((PyTypeObject * )StatResultType , Py_tp_new );
14503
+ dunder_new = PyDescr_NewClassMethod ((PyTypeObject * )StatResultType , & StatResultType_dunder_new );
14504
+ if (dunder_new == NULL ) {
14505
+ return NULL ;
14506
+ }
14507
+ PyObject_SetAttrString (StatResultType , "__new__" , dunder_new );
14508
+ Py_DECREF (dunder_new );
14511
14509
14512
14510
statvfs_result_desc .name = "os.statvfs_result" ; /* see issue #19209 */
14513
14511
PyObject * StatVFSResultType = (PyObject * )PyStructSequence_NewType (& statvfs_result_desc );
@@ -14537,7 +14535,12 @@ INITFUNC(void)
14537
14535
PyModule_AddObject (m , "sched_param" , SchedParamType );
14538
14536
_posixstate (m )-> SchedParamType = SchedParamType ;
14539
14537
/* Add a custom __new__ to the structsequence */
14540
- ((PyTypeObject * )SchedParamType )-> tp_new = sched_param_new ;
14538
+ dunder_new = PyDescr_NewClassMethod ((PyTypeObject * )SchedParamType , & SchedParamType_dunder_new );
14539
+ if (dunder_new == NULL ) {
14540
+ return NULL ;
14541
+ }
14542
+ PyObject_SetAttrString ((PyObject * )SchedParamType , "__new__" , dunder_new );
14543
+ Py_DECREF (dunder_new );
14541
14544
#endif
14542
14545
14543
14546
/* initialize TerminalSize_info */
0 commit comments