~herrhotzenplotz/gcli-devel

gcli: Makefile.in: define NDEBUG in release mode v1 APPLIED

Nico Sonack: 2
 Makefile.in: define NDEBUG in release mode
 jsongen: sprinkle some assertions sanity checking scopes

 2 files changed, 21 insertions(+), 10 deletions(-)
build pending: alpine.yml
Export patchset (mbox)
How do I use this?

Copy & paste the following snippet into your terminal to import this patchset into git:

curl -s https://lists.sr.ht/~herrhotzenplotz/gcli-devel/patches/56655/mbox | git am -3
Learn more about email & git

[PATCH gcli 1/2] Makefile.in: define NDEBUG in release mode Export this patch

This will disable assertions on most libc's.

Signed-off-by: Nico Sonack <nsonack@herrhotzenplotz.de>
---
 Makefile.in | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/Makefile.in b/Makefile.in
index 77e17fff..140133bf 100644
--- a/Makefile.in
+++ b/Makefile.in
@@ -24,13 +24,13 @@ SHELL               = @SHELL@

############## Optimiser / Warning flags #####
COPTFLAGS_gcc_debug=		-O0 -g3 -Wall -Wextra -Werror
COPTFLAGS_gcc_release=		-O2
COPTFLAGS_gcc_release=		-O2 -DNDEBUG
COPTFLAGS_clang_debug=		-O0 -g3 -Wall -Wextra -Wno-gnu-zero-variadic-macro-arguments -Werror
COPTFLAGS_clang_release=	-O2
COPTFLAGS_clang_release=	-O2 -DNDEBUG
COPTFLAGS_xlc_debug=		-qpic -qcheck=all -qfulldebug -qnoopt -g -qhalt=w
COPTFLAGS_xlc_release=		-qpic -qoptimize=4
COPTFLAGS_xlc_release=		-qpic -qoptimize=4 -DNDEBUG
COPTFLAGS_sunstudio_debug=	-xO0 -g -xvector=%none
COPTFLAGS_sunstudio_release=	-xO5
COPTFLAGS_sunstudio_release=	-xO5 -DNDEBUG
COPTFLAGS=			$(COPTFLAGS_$(CCOM)_$(OPTIMISE))
COPTFLAGS_FOR_BUILD=		$(COPTFLAGS_$(CCOM_FOR_BUILD)_$(OPTIMISE))

-- 
2.46.2

[PATCH gcli 2/2] jsongen: sprinkle some assertions sanity checking scopes Export this patch

This adds assertions in various places where we wish to check that
JSON scoping is correct.

These are only in effect if not in release mode (NDEBUG is not
defined).

Reference:     3147ffa4 (Fix uninitialised jsongen structs, 2024-12-24)
Signed-off-by: Nico Sonack <nsonack@herrhotzenplotz.de>
---
 src/json_gen.c | 23 +++++++++++++++++------
 1 file changed, 17 insertions(+), 6 deletions(-)

diff --git a/src/json_gen.c b/src/json_gen.c
index 51ee1ae2..051a34b6 100644
--- a/src/json_gen.c
+++ b/src/json_gen.c
@@ -1,5 +1,5 @@
/*
 * Copyright 2023 Nico Sonack <nsonack@herrhotzenplotz.de>
 * Copyright 2023-2024 Nico Sonack <nsonack@herrhotzenplotz.de>
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
@@ -33,6 +33,7 @@

#include <config.h>

#include <assert.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
@@ -145,8 +146,10 @@ int
gcli_jsongen_begin_object(struct gcli_jsongen *gen)
{
	/* Cannot put a json object into a json object key */
	if (is_object_scope(gen) && !gen->await_object_value)
	if (is_object_scope(gen) && !gen->await_object_value) {
		assert(0 && "attempt to use json object as object key");
		return -1;
	}

	put_comma_if_needed(gen);

@@ -163,8 +166,10 @@ gcli_jsongen_begin_object(struct gcli_jsongen *gen)
int
gcli_jsongen_end_object(struct gcli_jsongen *gen)
{
	if (pop_scope(gen) != GCLI_JSONGEN_OBJECT)
	if (pop_scope(gen) != GCLI_JSONGEN_OBJECT) {
		assert(0 && "unbalanced json scopes");
		return -1;
	}

	append_str(gen, "}");

@@ -178,8 +183,10 @@ int
gcli_jsongen_begin_array(struct gcli_jsongen *gen)
{
	/* Cannot put a json array into a json object key */
	if (is_object_scope(gen) && !gen->await_object_value)
	if (is_object_scope(gen) && !gen->await_object_value) {
		assert(0 && "attempt to use array as object key");
		return -1;
	}

	put_comma_if_needed(gen);

@@ -196,8 +203,10 @@ gcli_jsongen_begin_array(struct gcli_jsongen *gen)
int
gcli_jsongen_end_array(struct gcli_jsongen *gen)
{
	if (pop_scope(gen) != GCLI_JSONGEN_ARRAY)
	if (pop_scope(gen) != GCLI_JSONGEN_ARRAY) {
		assert(0 && "unbalanced json scopes");
		return -1;
	}

	append_str(gen, "]");

@@ -235,8 +244,10 @@ append_strf(struct gcli_jsongen *gen, char const *const fmt, ...)
int
gcli_jsongen_objmember(struct gcli_jsongen *gen, char const *const key)
{
	if (!is_object_scope(gen))
	if (!is_object_scope(gen)) {
		assert(0 && "gcli_jsongen_objmember called outside object scope");
		return -1;
	}

	put_comma_if_needed(gen);
	char *const e_key = gcli_json_escape_cstr(key);
-- 
2.46.2