1
0
forked from 0ad/0ad

Replace DISCARD macro with ignore_result template.

Fixes eb7940b418.
As reported by Vladislav, there is possibly confusion on what exactly is
being ignored when there are multiple statements after DISCARD. Explicit
wrapping avoids that.

Differential Revision: https://code.wildfiregames.com/D3206
This was SVN commit r24397.
This commit is contained in:
wraitii 2020-12-15 09:03:44 +00:00
parent 38c3827d3b
commit dd0b56c8aa
14 changed files with 52 additions and 51 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);
DISCARD da_free(&da);
ignore_result(da_free(&da));
}

View File

@ -267,7 +267,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
DISCARD ogl_tex_get_size(textures[i], &this_width, &this_height, &this_bpp);
ignore_result(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
@ -294,7 +294,7 @@ void CTerrainTextureEntry::LoadAlphaMaps(VfsPath &amtype)
{
// get src of copy
u8* src = 0;
DISCARD ogl_tex_get_data(textures[i], &src);
ignore_result(ogl_tex_get_data(textures[i], &src));
size_t srcstep = bpp/8;
@ -330,11 +330,11 @@ void CTerrainTextureEntry::LoadAlphaMaps(VfsPath &amtype)
}
for (size_t i = 0; i < NUM_ALPHA_MAPS; i++)
DISCARD ogl_tex_free(textures[i]);
ignore_result(ogl_tex_free(textures[i]));
// upload the composite texture
Tex t;
DISCARD t.wrap(total_w, total_h, 8, TEX_GREY, data, 0);
ignore_result(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
@ -354,11 +354,11 @@ void CTerrainTextureEntry::LoadAlphaMaps(VfsPath &amtype)
// ret = (Status)bytes_written;
}
DISCARD da_free(&da);*/
ignore_result(da_free(&da));*/
Handle hCompositeAlphaMap = ogl_tex_wrap(&t, g_VFS, key);
DISCARD ogl_tex_set_filter(hCompositeAlphaMap, GL_LINEAR);
DISCARD ogl_tex_set_wrap (hCompositeAlphaMap, GL_CLAMP_TO_EDGE, GL_CLAMP_TO_EDGE);
ignore_result(ogl_tex_set_filter(hCompositeAlphaMap, GL_LINEAR));
ignore_result(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;
DISCARD t.wrap(1, 1, 24, 0, data, 0);
ignore_result(t.wrap(1, 1, 24, 0, data, 0));
m_DefaultHandle = ogl_tex_wrap(&t, m_VFS, L"(default texture)");
DISCARD ogl_tex_set_filter(m_DefaultHandle, GL_LINEAR);
ignore_result(ogl_tex_set_filter(m_DefaultHandle, GL_LINEAR));
if (!m_DisableGL)
DISCARD ogl_tex_upload(m_DefaultHandle);
ignore_result(ogl_tex_upload(m_DefaultHandle));
}
// Error texture (magenta)
@ -112,12 +112,12 @@ public:
data.get()[1] = 0;
data.get()[2] = 255;
Tex t;
DISCARD t.wrap(1, 1, 24, 0, data, 0);
ignore_result(t.wrap(1, 1, 24, 0, data, 0));
m_ErrorHandle = ogl_tex_wrap(&t, m_VFS, L"(error texture)");
DISCARD ogl_tex_set_filter(m_ErrorHandle, GL_LINEAR);
ignore_result(ogl_tex_set_filter(m_ErrorHandle, GL_LINEAR));
if (!m_DisableGL)
DISCARD ogl_tex_upload(m_ErrorHandle);
ignore_result(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);
DISCARD ogl_tex_free(m_DefaultHandle);
DISCARD ogl_tex_free(m_ErrorHandle);
ignore_result(ogl_tex_free(m_DefaultHandle));
ignore_result(ogl_tex_free(m_ErrorHandle));
}
CTexturePtr GetErrorTexture()
@ -188,14 +188,14 @@ public:
// Get some flags for later use
size_t flags = 0;
DISCARD ogl_tex_get_format(h, &flags, NULL);
ignore_result(ogl_tex_get_format(h, &flags, NULL));
// Initialise base color from the texture
DISCARD ogl_tex_get_average_color(h, &texture->m_BaseColor);
ignore_result(ogl_tex_get_average_color(h, &texture->m_BaseColor));
// Set GL upload properties
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);
ignore_result(ogl_tex_set_wrap(h, texture->m_Properties.m_WrapS, texture->m_Properties.m_WrapT));
ignore_result(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;
}
}
DISCARD ogl_tex_set_filter(h, filter);
ignore_result(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;
DISCARD ogl_tex_get_size(m_Handle, &w, 0, 0);
ignore_result(ogl_tex_get_size(m_Handle, &w, 0, 0));
return w;
}
size_t CTexture::GetHeight() const
{
size_t h = 0;
DISCARD ogl_tex_get_size(m_Handle, 0, &h, 0);
ignore_result(ogl_tex_get_size(m_Handle, 0, &h, 0));
return h;
}
bool CTexture::HasAlpha() const
{
size_t flags = 0;
DISCARD ogl_tex_get_format(m_Handle, &flags, 0);
ignore_result(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;
DISCARD ogl_tex_get_uploaded_size(m_Handle, &size);
ignore_result(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::RootedValueVector paramData(rq.cx);
DISCARD paramData.append(argVal);
ignore_result(paramData.append(argVal));
JS::RootedValue result(rq.cx);

View File

@ -413,7 +413,7 @@ InReaction IGUIObject::SendMouseEvent(EGUIMessageType type, const CStr& eventNam
"y", mousePos.y,
"buttons", m_pGUI.GetMouseButtons());
JS::RootedValueVector paramData(rq.cx);
DISCARD paramData.append(mouse);
ignore_result(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::RootedValueVector paramData(rq.cx);
DISCARD paramData.append(coords);
DISCARD paramData.append(buttonJs);
ignore_result(paramData.append(coords));
ignore_result(paramData.append(buttonJs));
return ScriptEventWithReturn(EventNameWorldClick, paramData);
}

View File

@ -57,11 +57,12 @@
#endif
/**
* Mark a function return value as discardable to silence [[nodiscard]] warnings.
* Silence the 'unused result' warning.
* (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)!
template<typename T>
inline void ignore_result(const T&) {}
/**
* 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::RootedValueVector paramData(rq.cx);
DISCARD paramData.append(JS::NumberValue(percent));
ignore_result(paramData.append(JS::NumberValue(percent)));
JS::RootedValue valPendingTask(rq.cx);
scriptInterface.ToJSVal(rq, &valPendingTask, pending_task);
DISCARD paramData.append(valPendingTask);
ignore_result(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;
}
DISCARD da_free(&da);
ignore_result(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
DISCARD ogl_tex_get_size(textures[i], &this_width, &this_height, &this_bpp);
ignore_result(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;
DISCARD ogl_tex_get_data(textures[i], &src);
ignore_result(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++)
DISCARD ogl_tex_free(textures[i]);
ignore_result(ogl_tex_free(textures[i]));
// upload the composite texture
Tex t;
DISCARD t.wrap(total_w, total_h, 8, TEX_GREY, data, 0);
ignore_result(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;
}
DISCARD da_free(&da);*/
ignore_result(da_free(&da));*/
m_hCompositeAlphaMap = ogl_tex_wrap(&t, g_VFS, key);
DISCARD ogl_tex_set_filter(m_hCompositeAlphaMap, GL_LINEAR);
DISCARD ogl_tex_set_wrap (m_hCompositeAlphaMap, GL_CLAMP_TO_EDGE, GL_CLAMP_TO_EDGE);
ignore_result(ogl_tex_set_filter(m_hCompositeAlphaMap, GL_LINEAR));
ignore_result(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
DISCARD ogl_tex_bind(g_Renderer.m_hCompositeAlphaMap, 1);
ignore_result(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::RootedValueVector argv(rq.cx);
DISCARD argv.resize(sizeof...(Ts));
ignore_result(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::RootedValueVector argv(rq.cx);
DISCARD argv.resize(sizeof...(Ts));
ignore_result(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::RootedValueVector argv(rq.cx);
DISCARD argv.resize(sizeof...(Ts));
ignore_result(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::RootedValueVector argv(rq.cx);
DISCARD argv.resize(sizeof...(Ts));
ignore_result(argv.resize(sizeof...(Ts)));
AssignOrToJSValHelper<0>(rq, &argv, params...);
return CallFunction_(val, name, argv, &jsRet);
}

View File

@ -159,7 +159,7 @@ private:
}
JS::RootedValueVector argv(rq.cx);
DISCARD argv.append(settings.get());
ignore_result(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::RootedValueVector argv(rq.cx);
DISCARD argv.append(settings);
ignore_result(argv.append(settings));
m_ScriptInterface->CallConstructor(ctor, argv, &m_SharedAIObj);
if (m_SharedAIObj.get().isNull())

View File

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