This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author YoSTEALTH
Recipients YoSTEALTH, pablogsal, vstinner
Date 2019-07-05.17:50:39
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1562349039.72.0.211859672318.issue37509@roundup.psfhosted.org>
In-reply-to
Content
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.
History
Date User Action Args
2019-07-05 17:50:39YoSTEALTHsetrecipients: + YoSTEALTH, vstinner, pablogsal
2019-07-05 17:50:39YoSTEALTHsetmessageid: <1562349039.72.0.211859672318.issue37509@roundup.psfhosted.org>
2019-07-05 17:50:39YoSTEALTHlinkissue37509 messages
2019-07-05 17:50:39YoSTEALTHcreate