@@ -1779,40 +1779,73 @@ static PyTypeObject kqueue_queue_Type;
1779
1779
#elif (SIZEOF_UINTPTR_T == SIZEOF_LONG_LONG )
1780
1780
# define T_UINTPTRT T_ULONGLONG
1781
1781
# define T_INTPTRT T_LONGLONG
1782
- # define PyLong_AsUintptr_t PyLong_AsUnsignedLongLong
1783
1782
# define UINTPTRT_FMT_UNIT "K"
1784
1783
# define INTPTRT_FMT_UNIT "L"
1785
1784
#elif (SIZEOF_UINTPTR_T == SIZEOF_LONG )
1786
1785
# define T_UINTPTRT T_ULONG
1787
1786
# define T_INTPTRT T_LONG
1788
- # define PyLong_AsUintptr_t PyLong_AsUnsignedLong
1789
1787
# define UINTPTRT_FMT_UNIT "k"
1790
1788
# define INTPTRT_FMT_UNIT "l"
1791
1789
#elif (SIZEOF_UINTPTR_T == SIZEOF_INT )
1792
1790
# define T_UINTPTRT T_UINT
1793
1791
# define T_INTPTRT T_INT
1794
- # define PyLong_AsUintptr_t PyLong_AsUnsignedLong
1795
1792
# define UINTPTRT_FMT_UNIT "I"
1796
1793
# define INTPTRT_FMT_UNIT "i"
1797
1794
#else
1798
1795
# error uintptr_t does not match int, long, or long long!
1799
1796
#endif
1800
1797
1798
+ #if SIZEOF_LONG_LONG == 8
1799
+ # define T_INT64 T_LONGLONG
1800
+ # define INT64_FMT_UNIT "L"
1801
+ #elif SIZEOF_LONG == 8
1802
+ # define T_INT64 T_LONG
1803
+ # define INT64_FMT_UNIT "l"
1804
+ #elif SIZEOF_INT == 8
1805
+ # define T_INT64 T_INT
1806
+ # define INT64_FMT_UNIT "i"
1807
+ #else
1808
+ # define INT64_FMT_UNIT "_"
1809
+ #endif
1810
+
1811
+ #if SIZEOF_LONG_LONG == 4
1812
+ # define T_UINT32 T_ULONGLONG
1813
+ # define UINT32_FMT_UNIT "K"
1814
+ #elif SIZEOF_LONG == 4
1815
+ # define T_UINT32 T_ULONG
1816
+ # define UINT32_FMT_UNIT "k"
1817
+ #elif SIZEOF_INT == 4
1818
+ # define T_UINT32 T_UINT
1819
+ # define UINT32_FMT_UNIT "I"
1820
+ #else
1821
+ # define UINT32_FMT_UNIT "_"
1822
+ #endif
1823
+
1801
1824
/*
1802
1825
* kevent is not standard and its members vary across BSDs.
1803
1826
*/
1804
- #if !defined(__OpenBSD__ )
1805
- # define IDENT_TYPE T_UINTPTRT
1806
- # define IDENT_CAST intptr_t
1807
- # define DATA_TYPE T_INTPTRT
1808
- # define DATA_FMT_UNIT INTPTRT_FMT_UNIT
1809
- # define IDENT_AsType PyLong_AsUintptr_t
1827
+ #ifdef __NetBSD__
1828
+ # define FILTER_TYPE T_UINT32
1829
+ # define FILTER_FMT_UNIT UINT32_FMT_UNIT
1830
+ # define FLAGS_TYPE T_UINT32
1831
+ # define FLAGS_FMT_UNIT UINT32_FMT_UNIT
1832
+ # define FFLAGS_TYPE T_UINT32
1833
+ # define FFLAGS_FMT_UNIT UINT32_FMT_UNIT
1810
1834
#else
1811
- # define IDENT_TYPE T_UINT
1812
- # define IDENT_CAST int
1813
- # define DATA_TYPE T_INT
1814
- # define DATA_FMT_UNIT "i"
1815
- # define IDENT_AsType PyLong_AsUnsignedLong
1835
+ # define FILTER_TYPE T_SHORT
1836
+ # define FILTER_FMT_UNIT "h"
1837
+ # define FLAGS_TYPE T_USHORT
1838
+ # define FLAGS_FMT_UNIT "H"
1839
+ # define FFLAGS_TYPE T_UINT
1840
+ # define FFLAGS_FMT_UNIT "I"
1841
+ #endif
1842
+
1843
+ #ifdef __FreeBSD__
1844
+ # define DATA_TYPE T_INTPTRT
1845
+ # define DATA_FMT_UNIT INTPTR_FMT_UNIT
1846
+ #else
1847
+ # define DATA_TYPE T_INT64
1848
+ # define DATA_FMT_UNIT INT64_FMT_UNIT
1816
1849
#endif
1817
1850
1818
1851
/* Unfortunately, we can't store python objects in udata, because
@@ -1822,9 +1855,9 @@ static PyTypeObject kqueue_queue_Type;
1822
1855
1823
1856
#define KQ_OFF (x ) offsetof(kqueue_event_Object, x)
1824
1857
static struct PyMemberDef kqueue_event_members [] = {
1825
- {"ident" , IDENT_TYPE , KQ_OFF (e .ident )},
1826
- {"filter" , T_SHORT , KQ_OFF (e .filter )},
1827
- {"flags" , T_USHORT , KQ_OFF (e .flags )},
1858
+ {"ident" , T_UINTPTRT , KQ_OFF (e .ident )},
1859
+ {"filter" , FILTER_TYPE , KQ_OFF (e .filter )},
1860
+ {"flags" , FLAGS_TYPE , KQ_OFF (e .flags )},
1828
1861
{"fflags" , T_UINT , KQ_OFF (e .fflags )},
1829
1862
{"data" , DATA_TYPE , KQ_OFF (e .data )},
1830
1863
{"udata" , T_UINTPTRT , KQ_OFF (e .udata )},
@@ -1840,9 +1873,9 @@ kqueue_event_repr(kqueue_event_Object *s)
1840
1873
PyOS_snprintf (
1841
1874
buf , sizeof (buf ),
1842
1875
"<select.kevent ident=%zu filter=%d flags=0x%x fflags=0x%x "
1843
- "data=0x%zd udata=%p>" ,
1844
- (size_t )(s -> e .ident ), s -> e .filter , s -> e .flags ,
1845
- s -> e .fflags , (Py_ssize_t )(s -> e .data ), s -> e .udata );
1876
+ "data=0x%llx udata=%p>" ,
1877
+ (size_t )(s -> e .ident ), ( int ) s -> e .filter , ( unsigned int ) s -> e .flags ,
1878
+ ( unsigned int ) s -> e .fflags , (long long )(s -> e .data ), ( void * ) s -> e .udata );
1846
1879
return PyUnicode_FromString (buf );
1847
1880
}
1848
1881
@@ -1852,7 +1885,9 @@ kqueue_event_init(kqueue_event_Object *self, PyObject *args, PyObject *kwds)
1852
1885
PyObject * pfd ;
1853
1886
static char * kwlist [] = {"ident" , "filter" , "flags" , "fflags" ,
1854
1887
"data" , "udata" , NULL };
1855
- static const char fmt [] = "O|hHI" DATA_FMT_UNIT UINTPTRT_FMT_UNIT ":kevent" ;
1888
+ static const char fmt [] = "O|"
1889
+ FILTER_FMT_UNIT FLAGS_FMT_UNIT FFLAGS_FMT_UNIT DATA_FMT_UNIT
1890
+ UINTPTRT_FMT_UNIT ":kevent" ;
1856
1891
1857
1892
EV_SET (& (self -> e ), 0 , EVFILT_READ , EV_ADD , 0 , 0 , 0 ); /* defaults */
1858
1893
@@ -1862,12 +1897,8 @@ kqueue_event_init(kqueue_event_Object *self, PyObject *args, PyObject *kwds)
1862
1897
return -1 ;
1863
1898
}
1864
1899
1865
- if (PyLong_Check (pfd )
1866
- #if IDENT_TYPE == T_UINT
1867
- && PyLong_AsUnsignedLong (pfd ) <= UINT_MAX
1868
- #endif
1869
- ) {
1870
- self -> e .ident = IDENT_AsType (pfd );
1900
+ if (PyLong_Check (pfd )) {
1901
+ self -> e .ident = PyLong_AsSize_t (pfd );
1871
1902
}
1872
1903
else {
1873
1904
self -> e .ident = PyObject_AsFileDescriptor (pfd );
@@ -1882,28 +1913,21 @@ static PyObject *
1882
1913
kqueue_event_richcompare (kqueue_event_Object * s , kqueue_event_Object * o ,
1883
1914
int op )
1884
1915
{
1885
- intptr_t result = 0 ;
1916
+ int result ;
1886
1917
1887
1918
if (!kqueue_event_Check (o )) {
1888
- if (op == Py_EQ || op == Py_NE ) {
1889
- PyObject * res = op == Py_EQ ? Py_False : Py_True ;
1890
- Py_INCREF (res );
1891
- return res ;
1892
- }
1893
- PyErr_Format (PyExc_TypeError ,
1894
- "can't compare %.200s to %.200s" ,
1895
- Py_TYPE (s )-> tp_name , Py_TYPE (o )-> tp_name );
1896
- return NULL ;
1897
- }
1898
- if (((result = (IDENT_CAST )(s -> e .ident - o -> e .ident )) == 0 ) &&
1899
- ((result = s -> e .filter - o -> e .filter ) == 0 ) &&
1900
- ((result = s -> e .flags - o -> e .flags ) == 0 ) &&
1901
- ((result = (int )(s -> e .fflags - o -> e .fflags )) == 0 ) &&
1902
- ((result = s -> e .data - o -> e .data ) == 0 ) &&
1903
- ((result = s -> e .udata - o -> e .udata ) == 0 )
1904
- ) {
1905
- result = 0 ;
1906
- }
1919
+ Py_RETURN_NOTIMPLEMENTED ;
1920
+ }
1921
+
1922
+ #define CMP (a , b ) ((a) != (b)) ? ((a) < (b) ? -1 : 1)
1923
+ result = CMP (s -> e .ident , o -> e .ident )
1924
+ : CMP (s -> e .filter , o -> e .filter )
1925
+ : CMP (s -> e .flags , o -> e .flags )
1926
+ : CMP (s -> e .fflags , o -> e .fflags )
1927
+ : CMP (s -> e .data , o -> e .data )
1928
+ : CMP ((intptr_t )s -> e .udata , (intptr_t )o -> e .udata )
1929
+ : 0 ;
1930
+ #undef CMP
1907
1931
1908
1932
switch (op ) {
1909
1933
case Py_EQ :
0 commit comments