changeset 361:39f5d932941a

misc: fix some warnings
author David Demelier <markand@malikania.fr>
date Fri, 22 Oct 2021 14:26:41 +0200
parents 51c439068b59
children 12367bfc2df6
files CMakeLists.txt doc/mkdocs.yml extern/libduktape/duktape.h src/libmlk-core-js/core/js-animation.c src/libmlk-core-js/core/js-clock.c src/libmlk-core-js/core/js-font.c src/libmlk-core-js/core/js-game.c src/libmlk-core-js/core/js-music.c src/libmlk-core-js/core/js-sound.c src/libmlk-core-js/core/js-sprite.c src/libmlk-core-js/core/js-state.c src/libmlk-core-js/core/js-texture.c src/libmlk-core-js/core/js-window.c
diffstat 13 files changed, 72 insertions(+), 59 deletions(-) [+]
line wrap: on
line diff
--- a/CMakeLists.txt	Fri Oct 22 13:57:24 2021 +0200
+++ b/CMakeLists.txt	Fri Oct 22 14:26:41 2021 +0200
@@ -28,6 +28,10 @@
 
 if (CMAKE_C_COMPILER_ID MATCHES "GNU|Clang")
 	set(CMAKE_C_FLAGS "-Wall -Wextra -pedantic -D_POSIX_C_SOURCE=200809L ${CMAKE_C_FLAGS}")
+
+	if (CMAKE_C_COMPILER_ID MATCHES "GNU")
+		set(CMAKE_C_FLAGS "-Wno-format-truncation ${CMAKE_C_FLAGS}")
+	endif ()
 elseif (CMAKE_C_COMPILER_ID MATCHES "MSVC")
 	set(CMAKE_C_FLAGS "/wd4090 /wd5105 /wd6031 /wd6001 /wd26451 ${CMAKE_C_FLAGS}")
 endif ()
--- a/doc/mkdocs.yml	Fri Oct 22 13:57:24 2021 +0200
+++ b/doc/mkdocs.yml	Fri Oct 22 14:26:41 2021 +0200
@@ -42,7 +42,7 @@
       - FAQ: dev/faq.md
     - Howto:
       - dev/howto/01-init.md
-    - API Reference:
+    - C API Reference:
       - libmlk-core:
         - action: dev/api/core/action.md
         - alloc: dev/api/core/alloc.md
@@ -75,3 +75,6 @@
         - util: dev/api/core/util.md
         - window: dev/api/core/window.md
         - zfile: dev/api/core/zfile.md
+    - Javascript API Reference:
+      - Core:
+        - animation: dev/jsapi/core/animation.md
--- a/extern/libduktape/duktape.h	Fri Oct 22 13:57:24 2021 +0200
+++ b/extern/libduktape/duktape.h	Fri Oct 22 14:26:41 2021 +0200
@@ -18,21 +18,21 @@
  *  ===============
  *  Duktape license
  *  ===============
- *  
+ *
  *  (http://opensource.org/licenses/MIT)
- *  
+ *
  *  Copyright (c) 2013-2019 by Duktape authors (see AUTHORS.rst)
- *  
+ *
  *  Permission is hereby granted, free of charge, to any person obtaining a copy
  *  of this software and associated documentation files (the "Software"), to deal
  *  in the Software without restriction, including without limitation the rights
  *  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  *  copies of the Software, and to permit persons to whom the Software is
  *  furnished to do so, subject to the following conditions:
- *  
+ *
  *  The above copyright notice and this permission notice shall be included in
  *  all copies or substantial portions of the Software.
- *  
+ *
  *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  *  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  *  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
@@ -47,24 +47,24 @@
  *  ===============
  *  Duktape authors
  *  ===============
- *  
+ *
  *  Copyright
  *  =========
- *  
+ *
  *  Duktape copyrights are held by its authors.  Each author has a copyright
  *  to their contribution, and agrees to irrevocably license the contribution
  *  under the Duktape ``LICENSE.txt``.
- *  
+ *
  *  Authors
  *  =======
- *  
+ *
  *  Please include an e-mail address, a link to your GitHub profile, or something
  *  similar to allow your contribution to be identified accurately.
- *  
+ *
  *  The following people have contributed code, website contents, or Wiki contents,
  *  and agreed to irrevocably license their contributions under the Duktape
  *  ``LICENSE.txt`` (in order of appearance):
- *  
+ *
  *  * Sami Vaarala <sami.vaarala@iki.fi>
  *  * Niki Dobrev
  *  * Andreas \u00d6man <andreas@lonelycoder.com>
@@ -110,13 +110,13 @@
  *  * Luis de Bethencourt (https://github.com/luisbg)
  *  * Ian Whyman (https://github.com/v00d00)
  *  * Rick Sayre (https://github.com/whorfin)
- *  
+ *
  *  Other contributions
  *  ===================
- *  
+ *
  *  The following people have contributed something other than code (e.g. reported
  *  bugs, provided ideas, etc; roughly in order of appearance):
- *  
+ *
  *  * Greg Burns
  *  * Anthony Rabine
  *  * Carlos Costa
@@ -152,7 +152,7 @@
  *  * Andrew Janke (https://github.com/apjanke)
  *  * Unamer (https://github.com/unamer)
  *  * Karl Dahlke (eklhad@gmail.com)
- *  
+ *
  *  If you are accidentally missing from this list, send me an e-mail
  *  (``sami.vaarala@iki.fi``) and I'll fix the omission.
  */
--- a/src/libmlk-core-js/core/js-animation.c	Fri Oct 22 13:57:24 2021 +0200
+++ b/src/libmlk-core-js/core/js-animation.c	Fri Oct 22 14:26:41 2021 +0200
@@ -38,7 +38,7 @@
 	duk_pop_2(ctx);
 
 	if (!anim)
-		duk_error(ctx, DUK_ERR_TYPE_ERROR, "not a Animation object");
+		return (void)duk_error(ctx, DUK_ERR_TYPE_ERROR, "not a Animation object"), NULL;
 
 	return anim;
 }
--- a/src/libmlk-core-js/core/js-clock.c	Fri Oct 22 13:57:24 2021 +0200
+++ b/src/libmlk-core-js/core/js-clock.c	Fri Oct 22 14:26:41 2021 +0200
@@ -25,7 +25,7 @@
 
 #define SIGNATURE DUK_HIDDEN_SYMBOL("Mlk.Clock")
 
-static struct clock *
+static inline struct clock *
 self(duk_context *ctx)
 {
 	struct clock *clk;
@@ -36,7 +36,7 @@
 	duk_pop_2(ctx);
 
 	if (!clk)
-		duk_error(ctx, DUK_ERR_TYPE_ERROR, "not a Clock object");
+		return (void)duk_error(ctx, DUK_ERR_TYPE_ERROR, "not a Clock object"), NULL;
 
 	return clk;
 }
--- a/src/libmlk-core-js/core/js-font.c	Fri Oct 22 13:57:24 2021 +0200
+++ b/src/libmlk-core-js/core/js-font.c	Fri Oct 22 14:26:41 2021 +0200
@@ -41,7 +41,7 @@
 	duk_pop_2(ctx);
 
 	if (!font)
-		duk_error(ctx, DUK_ERR_TYPE_ERROR, "not a Font object");
+		return (void)duk_error(ctx, DUK_ERR_TYPE_ERROR, "not a Font object"), NULL;
 
 	return font;
 }
@@ -60,7 +60,7 @@
 	const int style = duk_require_int(ctx, 0);
 
 	if (style < 0 || style >= FONT_STYLE_LAST)
-		duk_error(ctx, DUK_ERR_ERROR, "invalid style");
+		return duk_error(ctx, DUK_ERR_ERROR, "invalid style");
 
 	self(ctx)->style = style;
 
@@ -84,14 +84,15 @@
 	struct font *font;
 
 	if (vfs_open(js_core_global_vfs(ctx), &file, entry, "r") < 0)
-		duk_error(ctx, DUK_ERR_ERROR, "%s", error());
+		return duk_error(ctx, DUK_ERR_ERROR, "%s", error());
 
 	font = alloc_new0(sizeof (*font));
 
 	if (font_openvfs(font, &file, size) < 0) {
 		free(font);
 		vfs_file_finish(&file);
-		duk_error(ctx, DUK_ERR_ERROR, "%s", error());
+
+		return duk_error(ctx, DUK_ERR_ERROR, "%s", error());
 	}
 
 	vfs_file_finish(&file);
@@ -122,7 +123,7 @@
 
 	if (font_render(self(ctx), tex, text, color) < 0) {
 		free(tex);
-		duk_error(ctx, DUK_ERR_ERROR, "%s", error());
+		return duk_error(ctx, DUK_ERR_ERROR, "%s", error());
 	}
 
 	js_texture_push(ctx, tex);
@@ -137,7 +138,7 @@
 	unsigned int w, h;
 
 	if (font_query(self(ctx), text, &w, &h) < 0)
-		duk_error(ctx, DUK_ERR_ERROR, "%s", error());
+		return duk_error(ctx, DUK_ERR_ERROR, "%s", error());
 
 	duk_push_object(ctx);
 	duk_push_uint(ctx, w);
--- a/src/libmlk-core-js/core/js-game.c	Fri Oct 22 13:57:24 2021 +0200
+++ b/src/libmlk-core-js/core/js-game.c	Fri Oct 22 14:26:41 2021 +0200
@@ -35,7 +35,7 @@
 
 	if (game.state == &game.states[GAME_STATE_MAX]) {
 		state_finish(state);
-		duk_error(ctx, DUK_ERR_RANGE_ERROR, "too many states");
+		return duk_error(ctx, DUK_ERR_RANGE_ERROR, "too many states");
 	}
 
 	game_push(state);
@@ -46,6 +46,8 @@
 static duk_ret_t
 Game_pop(duk_context *ctx)
 {
+	(void)ctx;
+
 	if (game.state == &game.states[0])
 		return 0;
 
--- a/src/libmlk-core-js/core/js-music.c	Fri Oct 22 13:57:24 2021 +0200
+++ b/src/libmlk-core-js/core/js-music.c	Fri Oct 22 14:26:41 2021 +0200
@@ -39,7 +39,7 @@
 	duk_pop_2(ctx);
 
 	if (!mus)
-		duk_error(ctx, DUK_ERR_TYPE_ERROR, "not a Music object");
+		return (void)duk_error(ctx, DUK_ERR_TYPE_ERROR, "not a Music object"), NULL;
 
 	return mus;
 }
@@ -52,14 +52,15 @@
 	struct music *mus;
 
 	if (vfs_open(js_core_global_vfs(ctx), &file, entry, "r") < 0)
-		duk_error(ctx, DUK_ERR_ERROR, "%s", error());
+		return duk_error(ctx, DUK_ERR_ERROR, "%s", error());
 
 	mus = alloc_new0(sizeof (*mus));
 
 	if (music_openvfs(mus, &file) < 0) {
 		free(mus);
 		vfs_file_finish(&file);
-		duk_error(ctx, DUK_ERR_ERROR, "%s", error());
+
+		return duk_error(ctx, DUK_ERR_ERROR, "%s", error());
 	}
 
 	vfs_file_finish(&file);
@@ -79,7 +80,7 @@
 	const unsigned int fadein = duk_get_uint_default(ctx, 0, 0);
 
 	if (music_play(self(ctx), flags, fadein) < 0)
-		duk_error(ctx, DUK_ERR_ERROR, "%s", error());
+		return duk_error(ctx, DUK_ERR_ERROR, "%s", error());
 
 	return 0;
 }
--- a/src/libmlk-core-js/core/js-sound.c	Fri Oct 22 13:57:24 2021 +0200
+++ b/src/libmlk-core-js/core/js-sound.c	Fri Oct 22 14:26:41 2021 +0200
@@ -39,7 +39,7 @@
 	duk_pop_2(ctx);
 
 	if (!snd)
-		duk_error(ctx, DUK_ERR_TYPE_ERROR, "not a Sound object");
+		return (void)duk_error(ctx, DUK_ERR_TYPE_ERROR, "not a Sound object"), NULL;
 
 	return snd;
 }
@@ -52,14 +52,15 @@
 	struct sound *snd;
 
 	if (vfs_open(js_core_global_vfs(ctx), &file, entry, "r") < 0)
-		duk_error(ctx, DUK_ERR_ERROR, "%s", error());
+		return duk_error(ctx, DUK_ERR_ERROR, "%s", error());
 
 	snd = alloc_new0(sizeof (*snd));
 
 	if (sound_openvfs(snd, &file) < 0) {
 		free(snd);
 		vfs_file_finish(&file);
-		duk_error(ctx, DUK_ERR_ERROR, "%s", error());
+
+		return duk_error(ctx, DUK_ERR_ERROR, "%s", error());
 	}
 
 	vfs_file_finish(&file);
@@ -70,8 +71,8 @@
 	duk_pop(ctx);
 
 	return 0;
-	
-	
+
+
 }
 
 static duk_ret_t
@@ -97,8 +98,8 @@
 	const unsigned int fadein = duk_get_uint_default(ctx, 1, 0);
 
 	if (sound_play(self(ctx), channel, fadein) < 0)
-		duk_error(ctx, DUK_ERR_ERROR, "%s", error());
-	
+		return duk_error(ctx, DUK_ERR_ERROR, "%s", error());
+
 	return 0;
 }
 
--- a/src/libmlk-core-js/core/js-sprite.c	Fri Oct 22 13:57:24 2021 +0200
+++ b/src/libmlk-core-js/core/js-sprite.c	Fri Oct 22 14:26:41 2021 +0200
@@ -39,7 +39,7 @@
 	duk_pop_2(ctx);
 
 	if (!sprite)
-		duk_error(ctx, DUK_ERR_TYPE_ERROR, "not a Sprite object");
+		return (void)duk_error(ctx, DUK_ERR_TYPE_ERROR, "not a Sprite object"), NULL;
 
 	return sprite;
 }
@@ -92,9 +92,9 @@
 	const int y = duk_require_int(ctx, 3);
 
 	if (r >= sprite->nrows)
-		duk_error(ctx, DUK_ERR_RANGE_ERROR, "row overflow: %u >= %u", r, sprite->nrows);
+		return duk_error(ctx, DUK_ERR_RANGE_ERROR, "row overflow: %u >= %u", r, sprite->nrows);
 	if (c >= sprite->ncols)
-		duk_error(ctx, DUK_ERR_RANGE_ERROR, "column overflow: %u >= %u", c, sprite->ncols);
+		return duk_error(ctx, DUK_ERR_RANGE_ERROR, "column overflow: %u >= %u", c, sprite->ncols);
 
 	sprite_draw(sprite, r, c, x, y);
 
@@ -113,9 +113,9 @@
 	const unsigned int h = duk_require_uint(ctx, 5);
 
 	if (r >= sprite->nrows)
-		duk_error(ctx, DUK_ERR_RANGE_ERROR, "row overflow: %u >= %u", r, sprite->nrows);
+		return duk_error(ctx, DUK_ERR_RANGE_ERROR, "row overflow: %u >= %u", r, sprite->nrows);
 	if (c >= sprite->ncols)
-		duk_error(ctx, DUK_ERR_RANGE_ERROR, "column overflow: %u >= %u", c, sprite->ncols);
+		return duk_error(ctx, DUK_ERR_RANGE_ERROR, "column overflow: %u >= %u", c, sprite->ncols);
 
 	sprite_scale(sprite, r, c, x, y, w, h);
 
@@ -154,7 +154,7 @@
 	duk_pop(ctx);
 
 	if (!sprite)
-		duk_error(ctx, DUK_ERR_TYPE_ERROR, "not a Sprite object");
+		return (void)duk_error(ctx, DUK_ERR_TYPE_ERROR, "not a Sprite object"), NULL;
 
 	return sprite;
 }
--- a/src/libmlk-core-js/core/js-state.c	Fri Oct 22 13:57:24 2021 +0200
+++ b/src/libmlk-core-js/core/js-state.c	Fri Oct 22 14:26:41 2021 +0200
@@ -159,7 +159,7 @@
 	duk_pop_2(ctx);
 
 	if (!data)
-		duk_error(ctx, DUK_ERR_TYPE_ERROR, "not a State object");
+		return (void)duk_error(ctx, DUK_ERR_TYPE_ERROR, "not a State object"), NULL;
 
 	return data;
 }
@@ -231,9 +231,9 @@
 		self = duk_to_pointer(ctx, -1);
 		duk_pop(ctx);
 	}
-	
+
 	if (!self)
-		duk_error(ctx, DUK_ERR_TYPE_ERROR, "not a State object");
+		return (void)duk_error(ctx, DUK_ERR_TYPE_ERROR, "not a State object"), NULL;
 
 	self->refc++;
 
--- a/src/libmlk-core-js/core/js-texture.c	Fri Oct 22 13:57:24 2021 +0200
+++ b/src/libmlk-core-js/core/js-texture.c	Fri Oct 22 14:26:41 2021 +0200
@@ -41,7 +41,7 @@
 	duk_pop_2(ctx);
 
 	if (!tex)
-		duk_error(ctx, DUK_ERR_TYPE_ERROR, "not a Texture object");
+		return (void)duk_error(ctx, DUK_ERR_TYPE_ERROR, "not a Texture object"), NULL;
 
 	return tex;
 }
@@ -56,7 +56,7 @@
 	tex = alloc_new(sizeof (*tex));
 
 	if (texture_new(tex, w, h) < 0)
-		duk_error(ctx, DUK_ERR_ERROR, "%s", error());
+		return duk_error(ctx, DUK_ERR_ERROR, "%s", error());
 
 	duk_push_this(ctx);
 	duk_push_pointer(ctx, tex);
@@ -73,9 +73,9 @@
 	struct texture *tex = self(ctx);
 
 	if (blend < 0 || blend >= TEXTURE_BLEND_LAST)
-		duk_error(ctx, DUK_ERR_ERROR, "invalid blend");
+		return duk_error(ctx, DUK_ERR_ERROR, "invalid blend");
 	if (texture_set_blend_mode(tex, blend) < 0)
-		duk_error(ctx, DUK_ERR_ERROR, "%s", error());
+		return duk_error(ctx, DUK_ERR_ERROR, "%s", error());
 
 	return 0;
 }
@@ -87,7 +87,7 @@
 	struct texture *tex = self(ctx);
 
 	if (texture_set_alpha_mod(tex, alpha) < 0)
-		duk_error(ctx, DUK_ERR_ERROR, "%s", error());
+		return duk_error(ctx, DUK_ERR_ERROR, "%s", error());
 
 	return 0;
 }
@@ -99,7 +99,7 @@
 	struct texture *tex = self(ctx);
 
 	if (texture_set_color_mod(tex, color) < 0)
-		duk_error(ctx, DUK_ERR_ERROR, "%s", error());
+		return duk_error(ctx, DUK_ERR_ERROR, "%s", error());
 
 	return 0;
 }
@@ -112,7 +112,7 @@
 	struct texture *tex = self(ctx);
 
 	if (texture_draw(tex, x, y) < 0)
-		duk_error(ctx, DUK_ERR_ERROR, "%s", error());
+		return duk_error(ctx, DUK_ERR_ERROR, "%s", error());
 
 	return 0;
 }
@@ -132,7 +132,7 @@
 	struct texture *tex = self(ctx);
 
 	if (texture_scale(tex, srcx, srcy, srcw, srch, dstx, dsty, dstw, dsth, angle) < 0)
-		duk_error(ctx, DUK_ERR_ERROR, "%s", error());
+		return duk_error(ctx, DUK_ERR_ERROR, "%s", error());
 
 	return 0;
 }
@@ -161,14 +161,15 @@
 	struct vfs_file file;
 
 	if (vfs_open(js_core_global_vfs(ctx), &file, entry, "r") < 0)
-		duk_error(ctx, DUK_ERR_ERROR, "%s", error());
+		return duk_error(ctx, DUK_ERR_ERROR, "%s", error());
 
 	tex = alloc_new0(sizeof (*tex));
 
 	if (image_openvfs(tex, &file) < 0) {
 		free(tex);
 		vfs_file_finish(&file);
-		duk_error(ctx, DUK_ERR_ERROR, "%s", error());
+
+		return duk_error(ctx, DUK_ERR_ERROR, "%s", error());
 	}
 
 	vfs_file_finish(&file);
@@ -229,7 +230,7 @@
 	duk_pop(ctx);
 
 	if (!tex)
-		duk_error(ctx, DUK_ERR_TYPE_ERROR, "not a Texture object");
+		return (void)duk_error(ctx, DUK_ERR_TYPE_ERROR, "not a Texture object"), NULL;
 
 	return tex;
 }
--- a/src/libmlk-core-js/core/js-window.c	Fri Oct 22 13:57:24 2021 +0200
+++ b/src/libmlk-core-js/core/js-window.c	Fri Oct 22 14:26:41 2021 +0200
@@ -33,7 +33,7 @@
 	const unsigned int h = duk_require_uint(ctx, 2);
 
 	if (window_open(title, w, h) < 0)
-		duk_error(ctx, DUK_ERR_ERROR, "%s", error());
+		return duk_error(ctx, DUK_ERR_ERROR, "%s", error());
 
 	duk_push_this(ctx);
 	duk_push_boolean(ctx, 1);
@@ -49,7 +49,7 @@
 	const unsigned int cursor = duk_require_uint(ctx, 0);
 
 	if (cursor >= WINDOW_CURSOR_LAST)
-		duk_error(ctx, DUK_ERR_RANGE_ERROR, "invalid cursor");
+		return duk_error(ctx, DUK_ERR_RANGE_ERROR, "invalid cursor");
 
 	window_set_cursor(cursor);