New submission from YoSTEALTH <rit...@stealthcentral.com>:
import os import ctypes # Stdlib # ------ def test_preadv_stdlib(path): fd = os.open(path, os.O_RDWR | os.O_CREAT) buffer = bytearray(10) buffers = [buffer] try: length = os.preadv(fd, buffers, 0, os.RWF_NOWAIT) # OSError: [Errno 95] Operation not supported print('length:', length) print('buffer:', buffer) finally: os.close(fd) # Cyptes Libc # ----------- class iovec(ctypes.Structure): _fields_ = [('iov_base', ctypes.c_char_p), ('iov_len', ctypes.c_size_t)] libc = ctypes.CDLL('libc.so.6') def test_preadv_libc(path): fd = os.open(path, os.O_RDWR | os.O_CREAT) buffer = bytes(10) buffers = (iovec*1)() buffers[0].iov_base = buffer buffers[0].iov_len = 10 try: length = libc.preadv2(fd, buffers, len(buffers), 0, os.RWF_NOWAIT) print('length:', length) # length: -1 print('buffer:', buffer) # buffer: b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' finally: os.close(fd) # Test Run # -------- def test(): path = '/dev/shm/test-preadv-in-ram-file' # Test-1 stdlib implementation try: test_preadv_stdlib(path) # OSError: [Errno 95] Operation not supported except OSError: print('OSError is raised. This should not raise OSError') # Test-2 custom ctype `libc` implementation test_preadv_libc(path) if __name__ == '__main__': test() This code is just to demonstrate working vs receiving an OSError in this specific usage. System: Linux 4.19.56-1-MANJARO Python: 3.8.0b2 When the file in question is stored in ram ('/dev/shm') stdlib implementation raises an OSError while libc version does not. ---------- messages: 347364 nosy: YoSTEALTH, pablogsal, vstinner priority: normal severity: normal status: open title: OSError preadv() type: behavior versions: Python 3.8 _______________________________________ Python tracker <rep...@bugs.python.org> <https://bugs.python.org/issue37509> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com