@@ -12747,17 +12747,20 @@ DirEntry_dealloc(DirEntry *entry)
12747
12747
12748
12748
/* Forward reference */
12749
12749
static int
12750
- DirEntry_test_mode (DirEntry * self , int follow_symlinks , unsigned short mode_bits );
12750
+ DirEntry_test_mode (PyTypeObject * defining_class , DirEntry * self ,
12751
+ int follow_symlinks , unsigned short mode_bits );
12751
12752
12752
12753
/*[clinic input]
12753
12754
os.DirEntry.is_symlink -> bool
12755
+ defining_class: defining_class
12756
+ /
12754
12757
12755
12758
Return True if the entry is a symbolic link; cached per entry.
12756
12759
[clinic start generated code]*/
12757
12760
12758
12761
static int
12759
- os_DirEntry_is_symlink_impl (DirEntry * self )
12760
- /*[clinic end generated code: output=42244667d7bcfc25 input=1605a1b4b96976c3 ]*/
12762
+ os_DirEntry_is_symlink_impl (DirEntry * self , PyTypeObject * defining_class )
12763
+ /*[clinic end generated code: output=293096d589b6d47c input=e9acc5ee4d511113 ]*/
12761
12764
{
12762
12765
#ifdef MS_WINDOWS
12763
12766
return (self -> win32_lstat .st_mode & S_IFMT ) == S_IFLNK ;
@@ -12766,21 +12769,16 @@ os_DirEntry_is_symlink_impl(DirEntry *self)
12766
12769
if (self -> d_type != DT_UNKNOWN )
12767
12770
return self -> d_type == DT_LNK ;
12768
12771
else
12769
- return DirEntry_test_mode (self , 0 , S_IFLNK );
12772
+ return DirEntry_test_mode (defining_class , self , 0 , S_IFLNK );
12770
12773
#else
12771
12774
/* POSIX without d_type */
12772
- return DirEntry_test_mode (self , 0 , S_IFLNK );
12775
+ return DirEntry_test_mode (defining_class , self , 0 , S_IFLNK );
12773
12776
#endif
12774
12777
}
12775
12778
12776
- static inline PyObject *
12777
- DirEntry_get_module (DirEntry * self )
12778
- {
12779
- return PyType_GetModule (Py_TYPE (self ));
12780
- }
12781
-
12782
12779
static PyObject *
12783
- DirEntry_fetch_stat (DirEntry * self , int follow_symlinks )
12780
+ DirEntry_fetch_stat (PyTypeObject * defining_class , DirEntry * self ,
12781
+ int follow_symlinks )
12784
12782
{
12785
12783
int result ;
12786
12784
STRUCT_STAT st ;
@@ -12816,18 +12814,18 @@ DirEntry_fetch_stat(DirEntry *self, int follow_symlinks)
12816
12814
if (result != 0 )
12817
12815
return path_object_error (self -> path );
12818
12816
12819
- return _pystat_fromstructstat (DirEntry_get_module ( self ), & st );
12817
+ return _pystat_fromstructstat (PyType_GetModule ( defining_class ), & st );
12820
12818
}
12821
12819
12822
12820
static PyObject *
12823
- DirEntry_get_lstat (DirEntry * self )
12821
+ DirEntry_get_lstat (PyTypeObject * defining_class , DirEntry * self )
12824
12822
{
12825
12823
if (!self -> lstat ) {
12826
12824
#ifdef MS_WINDOWS
12827
- self -> lstat = _pystat_fromstructstat (DirEntry_get_module ( self ),
12825
+ self -> lstat = _pystat_fromstructstat (PyType_GetModule ( defining_class ),
12828
12826
& self -> win32_lstat );
12829
12827
#else /* POSIX */
12830
- self -> lstat = DirEntry_fetch_stat (self , 0 );
12828
+ self -> lstat = DirEntry_fetch_stat (defining_class , self , 0 );
12831
12829
#endif
12832
12830
}
12833
12831
Py_XINCREF (self -> lstat );
@@ -12836,27 +12834,34 @@ DirEntry_get_lstat(DirEntry *self)
12836
12834
12837
12835
/*[clinic input]
12838
12836
os.DirEntry.stat
12837
+ defining_class: defining_class
12838
+ /
12839
12839
*
12840
12840
follow_symlinks: bool = True
12841
12841
12842
12842
Return stat_result object for the entry; cached per entry.
12843
12843
[clinic start generated code]*/
12844
12844
12845
12845
static PyObject *
12846
- os_DirEntry_stat_impl (DirEntry * self , int follow_symlinks )
12847
- /*[clinic end generated code: output=008593b3a6d01305 input=280d14c1d6f1d00d]*/
12846
+ os_DirEntry_stat_impl (DirEntry * self , PyTypeObject * defining_class ,
12847
+ int follow_symlinks )
12848
+ /*[clinic end generated code: output=23f803e19c3e780e input=e816273c4e67ee98]*/
12848
12849
{
12849
- if (!follow_symlinks )
12850
- return DirEntry_get_lstat (self );
12850
+ if (!follow_symlinks ) {
12851
+ return DirEntry_get_lstat (defining_class , self );
12852
+ }
12851
12853
12852
12854
if (!self -> stat ) {
12853
- int result = os_DirEntry_is_symlink_impl (self );
12854
- if (result == -1 )
12855
+ int result = os_DirEntry_is_symlink_impl (self , defining_class );
12856
+ if (result == -1 ) {
12855
12857
return NULL ;
12856
- else if (result )
12857
- self -> stat = DirEntry_fetch_stat (self , 1 );
12858
- else
12859
- self -> stat = DirEntry_get_lstat (self );
12858
+ }
12859
+ if (result ) {
12860
+ self -> stat = DirEntry_fetch_stat (defining_class , self , 1 );
12861
+ }
12862
+ else {
12863
+ self -> stat = DirEntry_get_lstat (defining_class , self );
12864
+ }
12860
12865
}
12861
12866
12862
12867
Py_XINCREF (self -> stat );
@@ -12865,7 +12870,8 @@ os_DirEntry_stat_impl(DirEntry *self, int follow_symlinks)
12865
12870
12866
12871
/* Set exception and return -1 on error, 0 for False, 1 for True */
12867
12872
static int
12868
- DirEntry_test_mode (DirEntry * self , int follow_symlinks , unsigned short mode_bits )
12873
+ DirEntry_test_mode (PyTypeObject * defining_class , DirEntry * self ,
12874
+ int follow_symlinks , unsigned short mode_bits )
12869
12875
{
12870
12876
PyObject * stat = NULL ;
12871
12877
PyObject * st_mode = NULL ;
@@ -12890,7 +12896,7 @@ DirEntry_test_mode(DirEntry *self, int follow_symlinks, unsigned short mode_bits
12890
12896
#if defined(MS_WINDOWS ) || defined(HAVE_DIRENT_D_TYPE )
12891
12897
if (need_stat ) {
12892
12898
#endif
12893
- stat = os_DirEntry_stat_impl (self , follow_symlinks );
12899
+ stat = os_DirEntry_stat_impl (self , defining_class , follow_symlinks );
12894
12900
if (!stat ) {
12895
12901
if (PyErr_ExceptionMatches (PyExc_FileNotFoundError )) {
12896
12902
/* If file doesn't exist (anymore), then return False
@@ -12900,7 +12906,7 @@ DirEntry_test_mode(DirEntry *self, int follow_symlinks, unsigned short mode_bits
12900
12906
}
12901
12907
goto error ;
12902
12908
}
12903
- st_mode = PyObject_GetAttr (stat , get_posix_state (DirEntry_get_module ( self ))-> st_mode );
12909
+ st_mode = PyObject_GetAttr (stat , get_posix_state (PyType_GetModule ( defining_class ))-> st_mode );
12904
12910
if (!st_mode )
12905
12911
goto error ;
12906
12912
@@ -12943,32 +12949,38 @@ DirEntry_test_mode(DirEntry *self, int follow_symlinks, unsigned short mode_bits
12943
12949
12944
12950
/*[clinic input]
12945
12951
os.DirEntry.is_dir -> bool
12952
+ defining_class: defining_class
12953
+ /
12946
12954
*
12947
12955
follow_symlinks: bool = True
12948
12956
12949
12957
Return True if the entry is a directory; cached per entry.
12950
12958
[clinic start generated code]*/
12951
12959
12952
12960
static int
12953
- os_DirEntry_is_dir_impl (DirEntry * self , int follow_symlinks )
12954
- /*[clinic end generated code: output=ad2e8d54365da287 input=0135232766f53f58]*/
12961
+ os_DirEntry_is_dir_impl (DirEntry * self , PyTypeObject * defining_class ,
12962
+ int follow_symlinks )
12963
+ /*[clinic end generated code: output=0cd453b9c0987fdf input=1a4ffd6dec9920cb]*/
12955
12964
{
12956
- return DirEntry_test_mode (self , follow_symlinks , S_IFDIR );
12965
+ return DirEntry_test_mode (defining_class , self , follow_symlinks , S_IFDIR );
12957
12966
}
12958
12967
12959
12968
/*[clinic input]
12960
12969
os.DirEntry.is_file -> bool
12970
+ defining_class: defining_class
12971
+ /
12961
12972
*
12962
12973
follow_symlinks: bool = True
12963
12974
12964
12975
Return True if the entry is a file; cached per entry.
12965
12976
[clinic start generated code]*/
12966
12977
12967
12978
static int
12968
- os_DirEntry_is_file_impl (DirEntry * self , int follow_symlinks )
12969
- /*[clinic end generated code: output=8462ade481d8a476 input=0dc90be168b041ee]*/
12979
+ os_DirEntry_is_file_impl (DirEntry * self , PyTypeObject * defining_class ,
12980
+ int follow_symlinks )
12981
+ /*[clinic end generated code: output=f7c277ab5ba80908 input=0a64c5a12e802e3b]*/
12970
12982
{
12971
- return DirEntry_test_mode (self , follow_symlinks , S_IFREG );
12983
+ return DirEntry_test_mode (defining_class , self , follow_symlinks , S_IFREG );
12972
12984
}
12973
12985
12974
12986
/*[clinic input]
@@ -13496,6 +13508,8 @@ static PyType_Spec ScandirIteratorType_spec = {
13496
13508
MODNAME ".ScandirIterator" ,
13497
13509
sizeof (ScandirIterator ),
13498
13510
0 ,
13511
+ // bpo-40549: Py_TPFLAGS_BASETYPE should not be used, since
13512
+ // PyType_GetModule(Py_TYPE(self)) doesn't work on a subclass instance.
13499
13513
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_FINALIZE ,
13500
13514
ScandirIteratorType_slots
13501
13515
};
0 commit comments