]> andersk Git - libyaml.git/blobdiff - src/yaml_private.h
Fixed most compiler warnings -Wall -Wextra
[libyaml.git] / src / yaml_private.h
index 05123285d441a4624a48827e55d85e1fd8af1cc4..fe25141de2af6c6aaf7c1d5a6650c5d42c7eb905 100644 (file)
@@ -101,7 +101,7 @@ yaml_parser_fetch_more_tokens(yaml_parser_t *parser);
  */
 
 #define BUFFER_INIT(context,buffer,size)                                        \
-    (((buffer).start = yaml_malloc(size)) ?                                     \
+  (((buffer).start = (yaml_char_t *)yaml_malloc(size)) ?                        \
         ((buffer).last = (buffer).pointer = (buffer).start,                     \
          (buffer).end = (buffer).start+(size),                                  \
          1) :                                                                   \
@@ -141,7 +141,7 @@ yaml_string_join(
      (value).pointer = (string))
 
 #define STRING_INIT(context,string,size)                                        \
-    (((string).start = yaml_malloc(size)) ?                                     \
+    (((string).start = YAML_MALLOC(size)) ?                                     \
         ((string).pointer = (string).start,                                     \
          (string).end = (string).start+(size),                                  \
          memset((string).start, 0, (size)),                                     \
@@ -431,10 +431,10 @@ yaml_stack_extend(void **start, void **top, void **end);
 YAML_DECLARE(int)
 yaml_queue_extend(void **start, void **head, void **tail, void **end);
 
-#define STACK_INIT(context,stack,size)                                          \
-    (((stack).start = yaml_malloc((size)*sizeof(*(stack).start))) ?             \
+#define STACK_INIT(context,stack,type)                                     \
+  (((stack).start = (type)yaml_malloc(INITIAL_STACK_SIZE*sizeof(*(stack).start))) ? \
         ((stack).top = (stack).start,                                           \
-         (stack).end = (stack).start+(size),                                    \
+         (stack).end = (stack).start+INITIAL_STACK_SIZE,                        \
          1) :                                                                   \
         ((context)->error = YAML_MEMORY_ERROR,                                  \
          0))
@@ -464,8 +464,8 @@ yaml_queue_extend(void **start, void **head, void **tail, void **end);
 #define POP(context,stack)                                                      \
     (*(--(stack).top))
 
-#define QUEUE_INIT(context,queue,size)                                          \
-    (((queue).start = yaml_malloc((size)*sizeof(*(queue).start))) ?             \
+#define QUEUE_INIT(context,queue,size,type)                                     \
+  (((queue).start = (type)yaml_malloc((size)*sizeof(*(queue).start))) ?         \
         ((queue).head = (queue).tail = (queue).start,                           \
          (queue).end = (queue).start+(size),                                    \
          1) :                                                                   \
@@ -668,3 +668,28 @@ yaml_queue_extend(void **start, void **head, void **tail, void **end);
      (node).data.mapping.pairs.end = (node_pairs_end),                          \
      (node).data.mapping.pairs.top = (node_pairs_start),                        \
      (node).data.mapping.style = (node_style))
+
+/* Strict C compiler warning helpers */
+
+#if defined(__clang__) || defined(__GNUC__)
+#  define HASATTRIBUTE_UNUSED
+#endif
+#ifdef HASATTRIBUTE_UNUSED
+#  define __attribute__unused__             __attribute__((__unused__))
+#else
+#  define __attribute__unused__
+#endif
+
+/* Shim arguments are arguments that must be included in your function,
+ * but serve no purpose inside.  Silence compiler warnings. */
+#define SHIM(a) /*@unused@*/ a __attribute__unused__
+
+/* UNUSED_PARAM() marks a shim argument in the body to silence compiler warnings */
+#ifdef __clang__
+#  define UNUSED_PARAM(a) (void)(a);
+#else
+#  define UNUSED_PARAM(a) /*@-noeffect*/if (0) (void)(a)/*@=noeffect*/;
+#endif
+
+#define YAML_MALLOC_STATIC(type) (type*)yaml_malloc(sizeof(type))
+#define YAML_MALLOC(size)        (yaml_char_t *)yaml_malloc(size)
This page took 1.232991 seconds and 4 git commands to generate.