From 61d8cbe7bf1d8e0759f37542393a5d5725c38df9 Mon Sep 17 00:00:00 2001 From: Cloudwalk Date: Fri, 17 Sep 2021 12:02:00 -0400 Subject: [PATCH] com_list: Require type explicitly. Remove Q_typeof as typeof and decltype are unavailable in MSVC --- cmd.c | 4 +-- com_list.h | 78 +++++++++++++++++++++++++++--------------------------- lhnet.c | 12 ++++----- libcurl.c | 18 ++++++------- qdefs.h | 6 ----- world.c | 4 +-- zone.c | 8 +++--- 7 files changed, 62 insertions(+), 68 deletions(-) diff --git a/cmd.c b/cmd.c index abc512ee..e8f16889 100644 --- a/cmd.c +++ b/cmd.c @@ -86,7 +86,7 @@ static void Cmd_Defer_f (cmd_state_t *cmd) Con_Printf("No commands are pending.\n"); else { - List_For_Each_Entry(current, &cbuf->deferred, list) + List_For_Each_Entry(current, &cbuf->deferred, cmd_input_t, list) Con_Printf("-> In %9.2f: %s\n", current->delay, current->text); } } @@ -419,7 +419,7 @@ static void Cbuf_Execute_Deferred (cmd_buf_t *cbuf) return; cbuf->deferred_oldtime = host.realtime; - List_For_Each_Entry(current, &cbuf->deferred, list) + List_For_Each_Entry(current, &cbuf->deferred, cmd_input_t, list) { current->delay -= eat; if(current->delay <= 0) diff --git a/com_list.h b/com_list.h index 074b5504..4bbeb7d6 100644 --- a/com_list.h +++ b/com_list.h @@ -67,14 +67,14 @@ typedef struct llist_s /* * Get the next element in the list */ -#define List_Next_Entry(pos, member) \ - List_Entry((pos)->member.next, Q_typeof(*(pos)), member) +#define List_Next_Entry(pos, type, member) \ + List_Entry((pos)->member.next, type, member) /* * Get the prev element in the list */ -#define List_Prev_Entry(pos, member) \ - List_Entry((pos)->member.prev, Q_typeof(*(pos)), member) +#define List_Prev_Entry(pos, type, member) \ + List_Entry((pos)->member.prev, type, member) /* * Iterate over a list @@ -118,95 +118,95 @@ typedef struct llist_s /* * Iterate over a list of a given type */ -#define List_For_Each_Entry(pos, head, member) \ - for (pos = List_First_Entry(head, Q_typeof(*pos), member); \ +#define List_For_Each_Entry(pos, head, type, member) \ + for (pos = List_First_Entry(head, type, member); \ !List_Entry_Is_Head(pos, head, member); \ - pos = List_Next_Entry(pos, member)) + pos = List_Next_Entry(pos, type, member)) /* * Iterate over a list of a given type backwards */ -#define List_For_Each_Prev_Entry(pos, head, member) \ - for (pos = List_Last_Entry(head, Q_typeof(*pos), member); \ +#define List_For_Each_Prev_Entry(pos, head, type, member) \ + for (pos = List_Last_Entry(head, type, member); \ !List_Entry_Is_Head(pos, head, member); \ - pos = List_Prev_Entry(pos, member)) + pos = List_Prev_Entry(pos, type, member)) /* * Prepares a pos entry for use as a start point in List_For_Each_Entry_Continue() */ -#define List_Prepare_Entry(pos, head, member) \ - ((pos) ? : List_Entry(head, Q_typeof(*pos), member)) +#define List_Prepare_Entry(pos, head, type, member) \ + ((pos) ? : List_Entry(head, type, member)) /* * Continue iteration over a list of a given type, after the current position */ -#define List_For_Each_Entry_Continue(pos, head, member) \ - for (pos = List_Next_Entry(pos, member); \ +#define List_For_Each_Entry_Continue(pos, head, type, member) \ + for (pos = List_Next_Entry(pos, type, member); \ !List_Entry_Is_Head(pos, head, member); \ - pos = List_Next_Entry(pos, member)) + pos = List_Next_Entry(pos, type, member)) /* * Continue iteration over a list of a given type backwards, after the current position */ -#define List_For_Each_Prev_Entry_Continue(pos, head, member) \ - for (pos = List_Prev_Entry(pos, member); \ +#define List_For_Each_Prev_Entry_Continue(pos, head, type, member) \ + for (pos = List_Prev_Entry(pos, type, member); \ !List_Entry_Is_Head(pos, head, member); \ - pos = List_Prev_Entry(pos, member)) + pos = List_Prev_Entry(pos, type, member)) /* * Continue iteration over a list of a given type, from the current position */ -#define List_For_Each_Entry_From(pos, head, member) \ +#define List_For_Each_Entry_From(pos, head, type, member) \ for (; !List_Entry_Is_Head(pos, head, member); \ - pos = List_Next_Entry(pos, member)) + pos = List_Next_Entry(pos, type, member)) /* * Continue iteration over a list of a given type backwards, from the current position */ -#define List_For_Each_Prev_Entry_From(pos, head, member) \ +#define List_For_Each_Prev_Entry_From(pos, head, type, member) \ for (; !List_Entry_Is_Head(pos, head, member); \ - pos = List_Prev_Entry(pos, member)) + pos = List_Prev_Entry(pos, type, member)) /* * Iterate over a list of a given type, safe against removal of list entry */ -#define List_For_Each_Entry_Safe(pos, n, head, member) \ - for (pos = List_First_Entry(head, Q_typeof(*pos), member), \ - n = List_Next_Entry(pos, member); \ +#define List_For_Each_Entry_Safe(pos, n, head, type, member) \ + for (pos = List_First_Entry(head, type, member), \ + n = List_Next_Entry(pos, type, member); \ !List_Entry_Is_Head(pos, head, member); \ - pos = n, n = List_Next_Entry(n, member)) + pos = n, n = List_Next_Entry(n, type, member)) /* * Continue iteration over a list of a given type, after the current position, safe against removal of list entry */ -#define List_For_Each_Entry_Safe_Continue(pos, n, head, member) \ - for (pos = List_Next_Entry(pos, member), \ - n = List_Next_Entry(pos, member); \ +#define List_For_Each_Entry_Safe_Continue(pos, n, head, type, member) \ + for (pos = List_Next_Entry(pos, type, member), \ + n = List_Next_Entry(pos, type, member); \ !List_Entry_Is_Head(pos, head, member); \ - pos = n, n = List_Next_Entry(n, member)) + pos = n, n = List_Next_Entry(n, type, member)) /* * Continue iteration over a list of a given type, from the current position, safe against removal of list entry */ -#define List_For_Each_Entry_Safe_From(pos, n, head, member) \ - for (n = List_Next_Entry(pos, member); \ +#define List_For_Each_Entry_Safe_From(pos, n, head, type, member) \ + for (n = List_Next_Entry(pos, type, member); \ !List_Entry_Is_Head(pos, head, member); \ - pos = n, n = List_Next_Entry(n, member)) + pos = n, n = List_Next_Entry(n, type, member)) /* * Iterate over a list of a given type backwards, safe against removal of list entry */ -#define List_For_Each_Prev_Entry_Safe(pos, n, head, member) \ - for (pos = List_Last_Entry(head, Q_typeof(*pos), member), \ - n = List_Prev_Entry(pos, member); \ +#define List_For_Each_Prev_Entry_Safe(pos, n, head, type, member) \ + for (pos = List_Last_Entry(head, type, member), \ + n = List_Prev_Entry(pos, type, member); \ !List_Entry_Is_Head(pos, head, member); \ - pos = n, n = List_Prev_Entry(n, member)) + pos = n, n = List_Prev_Entry(n, type, member)) /* * Reset a stale List_For_Each_Entry_Safe loop */ -#define List_Safe_Reset_Next(pos, n, member) \ - n = List_Next_Entry(pos, member) +#define List_Safe_Reset_Next(pos, n, type, member) \ + n = List_Next_Entry(pos, type, member) static inline qbool List_Is_Empty(const llist_t *list) { diff --git a/lhnet.c b/lhnet.c index fff523dd..97dc9b06 100644 --- a/lhnet.c +++ b/lhnet.c @@ -764,9 +764,9 @@ void LHNET_Shutdown(void) lhnetpacket_t *p, *pnext; if (!lhnet_active) return; - List_For_Each_Entry_Safe(s, snext, &lhnet_socketlist.list, list) + List_For_Each_Entry_Safe(s, snext, &lhnet_socketlist.list, lhnetsocket_t, list) LHNET_CloseSocket(s); - List_For_Each_Entry_Safe(p, pnext, &lhnet_packetlist.list, list) + List_For_Each_Entry_Safe(p, pnext, &lhnet_packetlist.list, lhnetpacket_t, list) { List_Delete(&p->list); Z_Free(p); @@ -848,7 +848,7 @@ void LHNET_SleepUntilPacket_Microseconds(int microseconds) lhnetsocket_t *s; FD_ZERO(&fdreadset); lastfd = 0; - List_For_Each_Entry(s, &lhnet_socketlist.list, list) + List_For_Each_Entry(s, &lhnet_socketlist.list, lhnetsocket_t, list) { if (s->address.addresstype == LHNETADDRESSTYPE_INET4 || s->address.addresstype == LHNETADDRESSTYPE_INET6) { @@ -892,7 +892,7 @@ lhnetsocket_t *LHNET_OpenSocket_Connectionless(lhnetaddress_t *address) lhnetsocket->address.port = 1024; for (;;) { - List_For_Each_Entry(s, &lhnet_socketlist.list, list) + List_For_Each_Entry(s, &lhnet_socketlist.list, lhnetsocket_t, list) if (s->address.addresstype == lhnetsocket->address.addresstype && s->address.port == lhnetsocket->address.port) break; if (s == &lhnet_socketlist) @@ -901,7 +901,7 @@ lhnetsocket_t *LHNET_OpenSocket_Connectionless(lhnetaddress_t *address) } } // check if the port is available - List_For_Each_Entry(s, &lhnet_socketlist.list, list) + List_For_Each_Entry(s, &lhnet_socketlist.list, lhnetsocket_t, list) if (s->address.addresstype == lhnetsocket->address.addresstype && s->address.port == lhnetsocket->address.port) break; if (s == &lhnet_socketlist && lhnetsocket->address.port != 0) @@ -1084,7 +1084,7 @@ int LHNET_Read(lhnetsocket_t *lhnetsocket, void *content, int maxcontentlength, // scan for any old packets to timeout while searching for a packet // that is waiting to be delivered to this socket currenttime = time(NULL); - List_For_Each_Entry_Safe(p, pnext, &lhnet_packetlist.list, list) + List_For_Each_Entry_Safe(p, pnext, &lhnet_packetlist.list, lhnetpacket_t, list) { if (p->timeout < currenttime) { diff --git a/libcurl.c b/libcurl.c index fd3e7a61..26cb7a49 100644 --- a/libcurl.c +++ b/libcurl.c @@ -284,7 +284,7 @@ void Curl_Clear_forthismap(void) if(noclear) return; if (curl_mutex) Thread_LockMutex(curl_mutex); - List_For_Each_Entry(di, &downloads, list) + List_For_Each_Entry(di, &downloads, downloadinfo, list) di->forthismap = false; Curl_CommandWhenError(NULL); Curl_CommandWhenDone(NULL); @@ -682,7 +682,7 @@ static void CheckPendingDownloads(void) if(numdownloads < cl_curl_maxdownloads.integer) { downloadinfo *di; - List_For_Each_Entry(di, &downloads, list) + List_For_Each_Entry(di, &downloads, downloadinfo, list) { if(!di->started) { @@ -838,7 +838,7 @@ static downloadinfo *Curl_Find(const char *filename) downloadinfo *di; if(!curl_dll) return NULL; - List_For_Each_Entry(di, &downloads, list) + List_For_Each_Entry(di, &downloads, downloadinfo, list) if(!strcasecmp(di->filename, filename)) return di; return NULL; @@ -849,7 +849,7 @@ void Curl_Cancel_ToMemory(curl_callback_t callback, void *cbdata) downloadinfo *di, *ndi; if(!curl_dll) return; - List_For_Each_Entry_Safe(di, ndi, &downloads, list) + List_For_Each_Entry_Safe(di, ndi, &downloads, downloadinfo, list) { if(di->callback == callback && di->callback_data == cbdata) { @@ -1154,7 +1154,7 @@ void Curl_Frame(void) } while(mc == CURLM_CALL_MULTI_PERFORM); - List_For_Each_Entry(di, &downloads, list) + List_For_Each_Entry(di, &downloads, downloadinfo, list) { double b = 0; if(di->curle) @@ -1213,7 +1213,7 @@ void Curl_Frame(void) // use the slowest allowing download to derive the maxspeed... this CAN // be done better, but maybe later maxspeed = cl_curl_maxspeed.value; - List_For_Each_Entry(di, &downloads, list) + List_For_Each_Entry(di, &downloads, downloadinfo, list) if(di->maxspeed > 0) if(di->maxspeed < maxspeed || maxspeed <= 0) maxspeed = di->maxspeed; @@ -1333,7 +1333,7 @@ static void Curl_Info_f(cmd_state_t *cmd) { if (curl_mutex) Thread_LockMutex(curl_mutex); Con_Print("Currently running downloads:\n"); - List_For_Each_Entry(di, &downloads, list) + List_For_Each_Entry(di, &downloads, downloadinfo, list) { double speed, percent; Con_Printf(" %s -> %s ", CleanURL(di->url, urlbuf, sizeof(urlbuf)), di->filename); @@ -1574,12 +1574,12 @@ Curl_downloadinfo_t *Curl_GetDownloadInfo(int *nDownloads, const char **addition if (curl_mutex) Thread_LockMutex(curl_mutex); i = 0; - List_For_Each_Entry(di, &downloads, list) + List_For_Each_Entry(di, &downloads, downloadinfo, list) ++i; downinfo = (Curl_downloadinfo_t *) Z_Malloc(sizeof(*downinfo) * i); i = 0; - List_For_Each_Entry(di, &downloads, list) + List_For_Each_Entry(di, &downloads, downloadinfo, list) { // do not show infobars for background downloads if(developer.integer <= 0) diff --git a/qdefs.h b/qdefs.h index fa501464..9371f06e 100644 --- a/qdefs.h +++ b/qdefs.h @@ -21,12 +21,6 @@ # endif #endif -#ifdef DP_GCC_COMPATIBLE -#define Q_typeof(var) typeof(var) -#elif defined (_MSC_VER) -#define Q_typeof(var) decltype(var) -#endif - #define MAX_NUM_ARGVS 50 #ifdef DP_SMALLMEMORY diff --git a/world.c b/world.c index 9bdf1079..4f7cb48c 100644 --- a/world.c +++ b/world.c @@ -231,7 +231,7 @@ int World_EntitiesInBox(world_t *world, const vec3_t requestmins, const vec3_t r if (world->areagrid_outside.list.next) { grid = &world->areagrid_outside; - List_For_Each_Entry(l, &grid->list, list) + List_For_Each_Entry(l, &grid->list, link_t, list) { ent = PRVM_EDICT_NUM(l->entitynumber); if (ent->priv.server->areagridmarknumber != world->areagrid_marknumber) @@ -255,7 +255,7 @@ int World_EntitiesInBox(world_t *world, const vec3_t requestmins, const vec3_t r { if (grid->list.next) { - List_For_Each_Entry(l, &grid->list, list) + List_For_Each_Entry(l, &grid->list, link_t, list) { ent = PRVM_EDICT_NUM(l->entitynumber); if (ent->priv.server->areagridmarknumber != world->areagrid_marknumber) diff --git a/zone.c b/zone.c index 65964624..40708bd6 100644 --- a/zone.c +++ b/zone.c @@ -640,7 +640,7 @@ void _Mem_CheckSentinelsGlobal(const char *filename, int fileline) Sys_Error("Mem_CheckSentinelsGlobal: trashed pool sentinel 2 (allocpool at %s:%i, sentinel check at %s:%i)", pool->filename, pool->fileline, filename, fileline); } for (pool = poolchain;pool;pool = pool->next) - List_For_Each_Entry(mem, &pool->chain, list) + List_For_Each_Entry(mem, &pool->chain, memheader_t, list) _Mem_CheckSentinels((void *)((unsigned char *) mem + sizeof(memheader_t)), filename, fileline); #if MEMCLUMPING for (pool = poolchain;pool;pool = pool->next) @@ -658,7 +658,7 @@ qbool Mem_IsAllocated(mempool_t *pool, void *data) { // search only one pool target = (memheader_t *)((unsigned char *) data - sizeof(memheader_t)); - List_For_Each_Entry(header, &pool->chain, list) + List_For_Each_Entry(header, &pool->chain, memheader_t, list) if( header == target ) return true; } @@ -814,7 +814,7 @@ void Mem_PrintStats(void) if ((pool->flags & POOLFLAG_TEMP) && !List_Is_Empty(&pool->chain)) { Con_Printf("Memory pool %p has sprung a leak totalling %lu bytes (%.3fMB)! Listing contents...\n", (void *)pool, (unsigned long)pool->totalsize, pool->totalsize / 1048576.0); - List_For_Each_Entry(mem, &pool->chain, list) + List_For_Each_Entry(mem, &pool->chain, memheader_t, list) Con_Printf("%10lu bytes allocated at %s:%i\n", (unsigned long)mem->size, mem->filename, mem->fileline); } } @@ -831,7 +831,7 @@ void Mem_PrintList(size_t minallocationsize) { Con_Printf("%10luk (%10luk actual) %s (%+li byte change) %s\n", (unsigned long) ((pool->totalsize + 1023) / 1024), (unsigned long)((pool->realsize + 1023) / 1024), pool->name, (long)(pool->totalsize - pool->lastchecksize), (pool->flags & POOLFLAG_TEMP) ? "TEMP" : ""); pool->lastchecksize = pool->totalsize; - List_For_Each_Entry(mem, &pool->chain, list) + List_For_Each_Entry(mem, &pool->chain, memheader_t, list) if (mem->size >= minallocationsize) Con_Printf("%10lu bytes allocated at %s:%i\n", (unsigned long)mem->size, mem->filename, mem->fileline); } -- 2.39.2