1
0
forked from 0ad/0ad

Silence warnings about unused result.

Introduce a DISCARD macro to ignore the warn_unused_result attribute
used by Spidermonkey, and reuse it elsewhere.

Differential Revision: https://code.wildfiregames.com/D3147
This was SVN commit r24261.
This commit is contained in:
wraitii 2020-11-26 13:58:59 +00:00
parent 22d1742311
commit eb7940b418
14 changed files with 55 additions and 49 deletions

View File

@ -255,5 +255,5 @@ void CHeightMipmap::DumpToDisk(const VfsPath& filename) const
DynArray da;
WARN_IF_ERR(t.encode(filename.Extension(), &da));
g_VFS->CreateFile(filename, DummySharedPtr(da.base), da.pos);
(void)da_free(&da);
DISCARD da_free(&da);
}

View File

@ -266,7 +266,7 @@ void CTerrainTextureEntry::LoadAlphaMaps(VfsPath &amtype)
// get its size and make sure they are all equal.
// (the packing algo assumes this)
size_t this_width = 0, this_height = 0, this_bpp = 0; // fail-safe
(void)ogl_tex_get_size(textures[i], &this_width, &this_height, &this_bpp);
DISCARD ogl_tex_get_size(textures[i], &this_width, &this_height, &this_bpp);
if(this_width != this_height)
DEBUG_DISPLAY_ERROR(L"Alpha maps are not square");
// .. first iteration: establish size
@ -293,7 +293,7 @@ void CTerrainTextureEntry::LoadAlphaMaps(VfsPath &amtype)
{
// get src of copy
u8* src = 0;
(void)ogl_tex_get_data(textures[i], &src);
DISCARD ogl_tex_get_data(textures[i], &src);
size_t srcstep = bpp/8;
@ -329,11 +329,11 @@ void CTerrainTextureEntry::LoadAlphaMaps(VfsPath &amtype)
}
for (size_t i = 0; i < NUM_ALPHA_MAPS; i++)
(void)ogl_tex_free(textures[i]);
DISCARD ogl_tex_free(textures[i]);
// upload the composite texture
Tex t;
(void)t.wrap(total_w, total_h, 8, TEX_GREY, data, 0);
DISCARD t.wrap(total_w, total_h, 8, TEX_GREY, data, 0);
// uncomment the following to save a png of the generated texture
// in the public/ directory, for debugging
@ -353,11 +353,11 @@ void CTerrainTextureEntry::LoadAlphaMaps(VfsPath &amtype)
// ret = (Status)bytes_written;
}
(void)da_free(&da);*/
DISCARD da_free(&da);*/
Handle hCompositeAlphaMap = ogl_tex_wrap(&t, g_VFS, key);
(void)ogl_tex_set_filter(hCompositeAlphaMap, GL_LINEAR);
(void)ogl_tex_set_wrap (hCompositeAlphaMap, GL_CLAMP_TO_EDGE, GL_CLAMP_TO_EDGE);
DISCARD ogl_tex_set_filter(hCompositeAlphaMap, GL_LINEAR);
DISCARD ogl_tex_set_wrap (hCompositeAlphaMap, GL_CLAMP_TO_EDGE, GL_CLAMP_TO_EDGE);
ogl_tex_upload(hCompositeAlphaMap, GL_ALPHA, 0, 0);
result.m_hCompositeAlphaMap = hCompositeAlphaMap;

View File

@ -95,12 +95,12 @@ public:
data.get()[1] = 64;
data.get()[2] = 64;
Tex t;
(void)t.wrap(1, 1, 24, 0, data, 0);
DISCARD t.wrap(1, 1, 24, 0, data, 0);
m_DefaultHandle = ogl_tex_wrap(&t, m_VFS, L"(default texture)");
(void)ogl_tex_set_filter(m_DefaultHandle, GL_LINEAR);
DISCARD ogl_tex_set_filter(m_DefaultHandle, GL_LINEAR);
if (!m_DisableGL)
(void)ogl_tex_upload(m_DefaultHandle);
DISCARD ogl_tex_upload(m_DefaultHandle);
}
// Error texture (magenta)
@ -112,12 +112,12 @@ public:
data.get()[1] = 0;
data.get()[2] = 255;
Tex t;
(void)t.wrap(1, 1, 24, 0, data, 0);
DISCARD t.wrap(1, 1, 24, 0, data, 0);
m_ErrorHandle = ogl_tex_wrap(&t, m_VFS, L"(error texture)");
(void)ogl_tex_set_filter(m_ErrorHandle, GL_LINEAR);
DISCARD ogl_tex_set_filter(m_ErrorHandle, GL_LINEAR);
if (!m_DisableGL)
(void)ogl_tex_upload(m_ErrorHandle);
DISCARD ogl_tex_upload(m_ErrorHandle);
// Construct a CTexture to return to callers who want an error texture
CTextureProperties props(L"(error texture)");
@ -134,8 +134,8 @@ public:
{
UnregisterFileReloadFunc(ReloadChangedFileCB, this);
(void)ogl_tex_free(m_DefaultHandle);
(void)ogl_tex_free(m_ErrorHandle);
DISCARD ogl_tex_free(m_DefaultHandle);
DISCARD ogl_tex_free(m_ErrorHandle);
}
CTexturePtr GetErrorTexture()
@ -188,14 +188,14 @@ public:
// Get some flags for later use
size_t flags = 0;
(void)ogl_tex_get_format(h, &flags, NULL);
DISCARD ogl_tex_get_format(h, &flags, NULL);
// Initialise base color from the texture
(void)ogl_tex_get_average_color(h, &texture->m_BaseColor);
DISCARD ogl_tex_get_average_color(h, &texture->m_BaseColor);
// Set GL upload properties
(void)ogl_tex_set_wrap(h, texture->m_Properties.m_WrapS, texture->m_Properties.m_WrapT);
(void)ogl_tex_set_anisotropy(h, texture->m_Properties.m_Aniso);
DISCARD ogl_tex_set_wrap(h, texture->m_Properties.m_WrapS, texture->m_Properties.m_WrapT);
DISCARD ogl_tex_set_anisotropy(h, texture->m_Properties.m_Aniso);
// Prevent ogl_tex automatically generating mipmaps (which is slow and unwanted),
// by avoiding mipmapped filters unless the source texture already has mipmaps
@ -214,7 +214,7 @@ public:
break;
}
}
(void)ogl_tex_set_filter(h, filter);
DISCARD ogl_tex_set_filter(h, filter);
// Upload to GL
if (!m_DisableGL && ogl_tex_upload(h, texture->m_Properties.m_Format) < 0)
@ -604,21 +604,21 @@ void CTexture::SetHandle(Handle handle, bool takeOwnership)
size_t CTexture::GetWidth() const
{
size_t w = 0;
(void)ogl_tex_get_size(m_Handle, &w, 0, 0);
DISCARD ogl_tex_get_size(m_Handle, &w, 0, 0);
return w;
}
size_t CTexture::GetHeight() const
{
size_t h = 0;
(void)ogl_tex_get_size(m_Handle, 0, &h, 0);
DISCARD ogl_tex_get_size(m_Handle, 0, &h, 0);
return h;
}
bool CTexture::HasAlpha() const
{
size_t flags = 0;
(void)ogl_tex_get_format(m_Handle, &flags, 0);
DISCARD ogl_tex_get_format(m_Handle, &flags, 0);
return (flags & TEX_ALPHA) != 0;
}
@ -630,7 +630,7 @@ u32 CTexture::GetBaseColor() const
size_t CTexture::GetUploadedSize() const
{
size_t size = 0;
(void)ogl_tex_get_uploaded_size(m_Handle, &size);
DISCARD ogl_tex_get_uploaded_size(m_Handle, &size);
return size;
}

View File

@ -255,7 +255,7 @@ void CGUIManager::SGUIPage::PerformCallbackFunction(ScriptInterface::StructuredC
scriptInterface->ReadStructuredClone(args, &argVal);
JS::AutoValueVector paramData(rq.cx);
paramData.append(argVal);
DISCARD paramData.append(argVal);
JS::RootedValue result(rq.cx);

View File

@ -403,7 +403,7 @@ InReaction IGUIObject::SendMouseEvent(EGUIMessageType type, const CStr& eventNam
"y", mousePos.y,
"buttons", m_pGUI.GetMouseButtons());
JS::AutoValueVector paramData(rq.cx);
(void)paramData.append(mouse);
DISCARD paramData.append(mouse);
ScriptEvent(eventName, paramData);
return msg.skipped ? IN_PASS : IN_HANDLED;

View File

@ -251,8 +251,8 @@ bool CMiniMap::FireWorldClickEvent(int button, int UNUSED(clicks))
ScriptInterface::ToJSVal(rq, &buttonJs, button);
JS::AutoValueVector paramData(rq.cx);
paramData.append(coords);
paramData.append(buttonJs);
DISCARD paramData.append(coords);
DISCARD paramData.append(buttonJs);
return ScriptEventWithReturn(EventNameWorldClick, paramData);
}

View File

@ -56,6 +56,12 @@
# define UNUSED2(param) ((void)(param))
#endif
/**
* Mark a function return value as discardable to silence [[nodiscard]] warnings.
* (void) would be sufficient but Spidermonkey still uses warn_unused_result,
* and GCC is stricter about that. See https://bugzilla.mozilla.org/show_bug.cgi?id=1571631.
**/
#define DISCARD (void)!
/**
* indicate a function will not throw any synchronous exceptions,

View File

@ -188,11 +188,11 @@ void GUI_DisplayLoadProgress(int percent, const wchar_t* pending_task)
JS::AutoValueVector paramData(rq.cx);
paramData.append(JS::NumberValue(percent));
DISCARD paramData.append(JS::NumberValue(percent));
JS::RootedValue valPendingTask(rq.cx);
scriptInterface.ToJSVal(rq, &valPendingTask, pending_task);
paramData.append(valPendingTask);
DISCARD paramData.append(valPendingTask);
g_GUI->SendEventToAll(g_EventNameGameLoadProgress, paramData);
}

View File

@ -195,7 +195,7 @@ Status tex_write(Tex* t, const VfsPath& filename)
ret = (Status)bytes_written;
}
(void)da_free(&da);
DISCARD da_free(&da);
return ret;
}

View File

@ -1795,7 +1795,7 @@ int CRenderer::LoadAlphaMaps()
// get its size and make sure they are all equal.
// (the packing algo assumes this)
size_t this_width = 0, this_height = 0, this_bpp = 0; // fail-safe
(void)ogl_tex_get_size(textures[i], &this_width, &this_height, &this_bpp);
DISCARD ogl_tex_get_size(textures[i], &this_width, &this_height, &this_bpp);
if(this_width != this_height)
DEBUG_DISPLAY_ERROR(L"Alpha maps are not square");
// .. first iteration: establish size
@ -1822,7 +1822,7 @@ int CRenderer::LoadAlphaMaps()
{
// get src of copy
u8* src = 0;
(void)ogl_tex_get_data(textures[i], &src);
DISCARD ogl_tex_get_data(textures[i], &src);
size_t srcstep = bpp/8;
@ -1858,11 +1858,11 @@ int CRenderer::LoadAlphaMaps()
}
for (size_t i = 0; i < NumAlphaMaps; i++)
(void)ogl_tex_free(textures[i]);
DISCARD ogl_tex_free(textures[i]);
// upload the composite texture
Tex t;
(void)t.wrap(total_w, total_h, 8, TEX_GREY, data, 0);
DISCARD t.wrap(total_w, total_h, 8, TEX_GREY, data, 0);
/*VfsPath filename("blendtex.png");
@ -1880,11 +1880,11 @@ int CRenderer::LoadAlphaMaps()
// ret = (Status)bytes_written;
}
(void)da_free(&da);*/
DISCARD da_free(&da);*/
m_hCompositeAlphaMap = ogl_tex_wrap(&t, g_VFS, key);
(void)ogl_tex_set_filter(m_hCompositeAlphaMap, GL_LINEAR);
(void)ogl_tex_set_wrap (m_hCompositeAlphaMap, GL_CLAMP_TO_EDGE, GL_CLAMP_TO_EDGE);
DISCARD ogl_tex_set_filter(m_hCompositeAlphaMap, GL_LINEAR);
DISCARD ogl_tex_set_wrap (m_hCompositeAlphaMap, GL_CLAMP_TO_EDGE, GL_CLAMP_TO_EDGE);
int ret = ogl_tex_upload(m_hCompositeAlphaMap, GL_ALPHA, 0, 0);
return ret;

View File

@ -243,7 +243,7 @@ void TerrainRenderer::RenderTerrainFixed(int cullGroup)
// render blends
// switch on the composite alpha map texture
(void)ogl_tex_bind(g_Renderer.m_hCompositeAlphaMap, 1);
DISCARD ogl_tex_bind(g_Renderer.m_hCompositeAlphaMap, 1);
// switch on second uv set
pglClientActiveTextureARB(GL_TEXTURE1);

View File

@ -180,7 +180,7 @@ bool ScriptInterface::CallFunction(JS::HandleValue val, const char* name, R& ret
ScriptRequest rq(this);
JS::RootedValue jsRet(rq.cx);
JS::AutoValueVector argv(rq.cx);
(void)argv.resize(sizeof...(Ts));
DISCARD argv.resize(sizeof...(Ts));
AssignOrToJSValHelper<0>(rq, argv, params...);
if (!CallFunction_(val, name, argv, &jsRet))
return false;
@ -193,7 +193,7 @@ bool ScriptInterface::CallFunction(JS::HandleValue val, const char* name, JS::Ro
ScriptRequest rq(this);
JS::MutableHandle<R> jsRet(ret);
JS::AutoValueVector argv(rq.cx);
(void)argv.resize(sizeof...(Ts));
DISCARD argv.resize(sizeof...(Ts));
AssignOrToJSValHelper<0>(rq, argv, params...);
return CallFunction_(val, name, argv, jsRet);
}
@ -203,7 +203,7 @@ bool ScriptInterface::CallFunction(JS::HandleValue val, const char* name, JS::Mu
{
ScriptRequest rq(this);
JS::AutoValueVector argv(rq.cx);
(void)argv.resize(sizeof...(Ts));
DISCARD argv.resize(sizeof...(Ts));
AssignOrToJSValHelper<0>(rq, argv, params...);
return CallFunction_(val, name, argv, ret);
}
@ -215,7 +215,7 @@ bool ScriptInterface::CallFunctionVoid(JS::HandleValue val, const char* name, co
ScriptRequest rq(this);
JS::RootedValue jsRet(rq.cx);
JS::AutoValueVector argv(rq.cx);
(void)argv.resize(sizeof...(Ts));
DISCARD argv.resize(sizeof...(Ts));
AssignOrToJSValHelper<0>(rq, argv, params...);
return CallFunction_(val, name, argv, &jsRet);
}

View File

@ -159,7 +159,7 @@ private:
}
JS::AutoValueVector argv(rq.cx);
argv.append(settings.get());
DISCARD argv.append(settings.get());
m_ScriptInterface->CallConstructor(ctor, argv, &m_Obj);
if (m_Obj.get().isNull())
@ -458,7 +458,7 @@ public:
"templates", m_EntityTemplates);
JS::AutoValueVector argv(rq.cx);
argv.append(settings);
DISCARD argv.append(settings);
m_ScriptInterface->CallConstructor(ctor, argv, &m_SharedAIObj);
if (m_SharedAIObj.get().isNull())

View File

@ -91,15 +91,15 @@ void CReplayTurnManager::NotifyFinishedUpdate(u32 turn)
JS::AutoValueVector paramData(rq.cx);
paramData.append(JS::NumberValue(turn));
DISCARD paramData.append(JS::NumberValue(turn));
JS::RootedValue hashVal(rq.cx);
scriptInterface.ToJSVal(rq, &hashVal, hash);
paramData.append(hashVal);
DISCARD paramData.append(hashVal);
JS::RootedValue expectedHashVal(rq.cx);
scriptInterface.ToJSVal(rq, &expectedHashVal, expectedHash);
paramData.append(expectedHashVal);
DISCARD paramData.append(expectedHashVal);
g_GUI->SendEventToAll(EventNameReplayOutOfSync, paramData);
}