SDL_asyncio_liburing.c: replace size_t casts on pointers with intptr_t

This commit is contained in:
Ozkan Sezer 2024-12-04 07:01:40 +03:00 committed by Ryan C. Gordon
parent 2ad5836d02
commit 4ac78706bf
1 changed files with 6 additions and 5 deletions

View File

@ -169,7 +169,7 @@ static bool liburing_SetError(const char *what, int err)
static Sint64 liburing_asyncio_size(void *userdata) static Sint64 liburing_asyncio_size(void *userdata)
{ {
const int fd = (int) (size_t) userdata; const int fd = (int) (intptr_t) userdata;
struct stat statbuf; struct stat statbuf;
if (fstat(fd, &statbuf) < 0) { if (fstat(fd, &statbuf) < 0) {
SDL_SetError("fstat failed: %s", strerror(errno)); SDL_SetError("fstat failed: %s", strerror(errno));
@ -265,6 +265,7 @@ static SDL_AsyncIOTask *liburing_asyncioqueue_get_results(void *userdata)
SDL_UnlockMutex(queuedata->cqe_lock); SDL_UnlockMutex(queuedata->cqe_lock);
return NULL; return NULL;
} }
struct io_uring_cqe cqe_copy; struct io_uring_cqe cqe_copy;
SDL_copyp(&cqe_copy, cqe); // this is only a few bytes. SDL_copyp(&cqe_copy, cqe); // this is only a few bytes.
liburing.io_uring_cqe_seen(&queuedata->ring, cqe); // let io_uring use this slot again. liburing.io_uring_cqe_seen(&queuedata->ring, cqe); // let io_uring use this slot again.
@ -371,7 +372,7 @@ static bool SDL_SYS_CreateAsyncIOQueue_liburing(SDL_AsyncIOQueue *queue)
static bool liburing_asyncio_read(void *userdata, SDL_AsyncIOTask *task) static bool liburing_asyncio_read(void *userdata, SDL_AsyncIOTask *task)
{ {
LibUringAsyncIOQueueData *queuedata = (LibUringAsyncIOQueueData *) task->queue->userdata; LibUringAsyncIOQueueData *queuedata = (LibUringAsyncIOQueueData *) task->queue->userdata;
const int fd = (int) (size_t) userdata; const int fd = (int) (intptr_t) userdata;
// !!! FIXME: `unsigned` is likely smaller than requested_size's Uint64. If we overflow it, we could try submitting multiple SQEs // !!! FIXME: `unsigned` is likely smaller than requested_size's Uint64. If we overflow it, we could try submitting multiple SQEs
// !!! FIXME: and make a note in the task that there are several in sequence. // !!! FIXME: and make a note in the task that there are several in sequence.
@ -397,7 +398,7 @@ static bool liburing_asyncio_read(void *userdata, SDL_AsyncIOTask *task)
static bool liburing_asyncio_write(void *userdata, SDL_AsyncIOTask *task) static bool liburing_asyncio_write(void *userdata, SDL_AsyncIOTask *task)
{ {
LibUringAsyncIOQueueData *queuedata = (LibUringAsyncIOQueueData *) task->queue->userdata; LibUringAsyncIOQueueData *queuedata = (LibUringAsyncIOQueueData *) task->queue->userdata;
const int fd = (int) (size_t) userdata; const int fd = (int) (intptr_t) userdata;
// !!! FIXME: `unsigned` is likely smaller than requested_size's Uint64. If we overflow it, we could try submitting multiple SQEs // !!! FIXME: `unsigned` is likely smaller than requested_size's Uint64. If we overflow it, we could try submitting multiple SQEs
// !!! FIXME: and make a note in the task that there are several in sequence. // !!! FIXME: and make a note in the task that there are several in sequence.
@ -423,7 +424,7 @@ static bool liburing_asyncio_write(void *userdata, SDL_AsyncIOTask *task)
static bool liburing_asyncio_close(void *userdata, SDL_AsyncIOTask *task) static bool liburing_asyncio_close(void *userdata, SDL_AsyncIOTask *task)
{ {
LibUringAsyncIOQueueData *queuedata = (LibUringAsyncIOQueueData *) task->queue->userdata; LibUringAsyncIOQueueData *queuedata = (LibUringAsyncIOQueueData *) task->queue->userdata;
const int fd = (int) (size_t) userdata; const int fd = (int) (intptr_t) userdata;
// have to hold a lock because otherwise two threads could get_sqe and submit while one request isn't fully set up. // have to hold a lock because otherwise two threads could get_sqe and submit while one request isn't fully set up.
SDL_LockMutex(queuedata->sqe_lock); SDL_LockMutex(queuedata->sqe_lock);
@ -497,7 +498,7 @@ static bool SDL_SYS_AsyncIOFromFile_liburing(const char *file, const char *mode,
}; };
SDL_copyp(&asyncio->iface, &SDL_AsyncIOFile_liburing); SDL_copyp(&asyncio->iface, &SDL_AsyncIOFile_liburing);
asyncio->userdata = (void *) (size_t) fd; asyncio->userdata = (void *) (intptr_t) fd;
return true; return true;
} }