|
From: openocd-gerrit <ope...@us...> - 2026-07-25 10:47:20
|
This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "Main OpenOCD repository".
The branch, master has been updated
via c064a1999f55c66cf85df9f9e4e1e0744e052fe0 (commit)
via 2968660888fcd248932e2b6561951bf26f2e3916 (commit)
from 2285b2bca63f39a3db0a01fb2bbec66df2006aaa (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commit c064a1999f55c66cf85df9f9e4e1e0744e052fe0
Author: Antonio Borneo <bor...@gm...>
Date: Sun Jul 12 11:31:47 2026 +0200
helper: tcl-common: add tcl_escape_alloc()
OpenOCD commands can produce a Tcl output ready to be parsed in
Tcl scripts.
When a string has to be converted in a single Tcl element, the
OpenOCD command has to guarantee that he string does not contains
character that can confuse the Tcl parsing. A typical example is
the presence of whitespace that can split the element in two,
square brackets that can be expanded executing the content.
Rely on Jim Tcl API Jim_NewListObj() to handle all such corner
cases.
The string returned by tcl_escape_alloc() has to be free() by the
caller.
Change-Id: I898c314a02d455946e35223a43f7a65ed4c92833
Signed-off-by: Antonio Borneo <bor...@gm...>
Reviewed-on: https://review.openocd.org/c/openocd/+/9782
Reviewed-by: Tim Hutt <td...@gm...>
Tested-by: jenkins
diff --git a/src/helper/tcl-common.h b/src/helper/tcl-common.h
index 959c39972..4e0e81502 100644
--- a/src/helper/tcl-common.h
+++ b/src/helper/tcl-common.h
@@ -5,4 +5,13 @@
#include <jim.h>
+/**
+ * Convert a C string to a string that can be used for Tcl list.
+ * The returned string has to be deallocated through free().
+ * @param interp: the Tcl interpreter
+ * @param s: the C string to convert
+ * @returns converted string or NULL on error
+ */
+char *tcl_escape_alloc(Jim_Interp *interp, const char *s);
+
#endif /* OPENOCD_HELPER_TCL_COMMON_H */
diff --git a/src/helper/tcl-libjim.c b/src/helper/tcl-libjim.c
index bd19bc445..e36c6335f 100644
--- a/src/helper/tcl-libjim.c
+++ b/src/helper/tcl-libjim.c
@@ -17,4 +17,22 @@
#include "config.h"
#endif
+#include <assert.h>
+#include <string.h>
+
#include <helper/tcl-common.h>
+
+char *tcl_escape_alloc(Jim_Interp *interp, const char *s)
+{
+ assert(s);
+
+ Jim_Obj *o1 = Jim_NewStringObj(interp, s, -1);
+ Jim_Obj *o2 = Jim_NewListObj(interp, &o1, 1);
+ Jim_IncrRefCount(o2);
+
+ char *out = strdup(Jim_String(o2));
+
+ Jim_DecrRefCount(interp, o2);
+
+ return out;
+}
commit 2968660888fcd248932e2b6561951bf26f2e3916
Author: Antonio Borneo <bor...@gm...>
Date: Fri May 9 17:54:23 2025 +0200
helper: add tcl-common
Add a new helper file to start moving there the code specific to
Jim Tcl.
Coding with Jim Tcl require knowledge and dedicated review effort
to properly handle its garbage collection.
Having such specific helper will let us focus in a single place:
- the knowledge of Jim Tcl garbage collection;
- the use of Jim Tcl error codes JIM_OK and JIM_ERR;
- the use of CamelCase symbols of Jim Tcl.
Confining Jim Tcl code in a single file could also make easier the
switch to a different Tcl library, in the remote case we need to
address it.
Change-Id: Idd89adb57e5a782f141f02d9ccdd1911f3aa9bee
Signed-off-by: Antonio Borneo <bor...@gm...>
Reviewed-on: https://review.openocd.org/c/openocd/+/9781
Tested-by: jenkins
diff --git a/src/helper/Makefile.am b/src/helper/Makefile.am
index 1a61f7871..fab10c29e 100644
--- a/src/helper/Makefile.am
+++ b/src/helper/Makefile.am
@@ -18,6 +18,7 @@ noinst_LTLIBRARIES += %D%/libhelper.la
%D%/jep106.c \
%D%/jim-nvp.c \
%D%/nvp.c \
+ %D%/tcl-libjim.c \
%D%/align.h \
%D%/base64.h \
%D%/binarybuffer.h \
@@ -39,6 +40,7 @@ noinst_LTLIBRARIES += %D%/libhelper.la
%D%/jep106.inc \
%D%/jim-nvp.h \
%D%/nvp.h \
+ %D%/tcl-common.h \
%D%/compiler.h
STARTUP_TCL_SRCS += %D%/startup.tcl
diff --git a/src/helper/tcl-common.h b/src/helper/tcl-common.h
new file mode 100644
index 000000000..959c39972
--- /dev/null
+++ b/src/helper/tcl-common.h
@@ -0,0 +1,8 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+
+#ifndef OPENOCD_HELPER_TCL_COMMON_H
+#define OPENOCD_HELPER_TCL_COMMON_H
+
+#include <jim.h>
+
+#endif /* OPENOCD_HELPER_TCL_COMMON_H */
diff --git a/src/helper/tcl-libjim.c b/src/helper/tcl-libjim.c
new file mode 100644
index 000000000..bd19bc445
--- /dev/null
+++ b/src/helper/tcl-libjim.c
@@ -0,0 +1,20 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+
+/*
+ * This file collects all the functions to interact with Jim Tcl library.
+ *
+ * The purposes are:
+ * - to decouple the jimtcl error codes (JIM_OK, JIM_ERR, ...) from the error
+ * codes of OpenOCD;
+ * - to decouple the internal Jim_Obj and its garbage collection;
+ * - to concentrate the Jim Tcl CamelCase symbols, now spread in OpenOCD code.
+ *
+ * The Jim Tcl CamelCase symbols used in this file should be reported in the
+ * file 'tools/scripts/camelcase.txt' to prevent errors from checkpatch.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <helper/tcl-common.h>
-----------------------------------------------------------------------
Summary of changes:
src/helper/Makefile.am | 2 ++
src/helper/tcl-common.h | 17 +++++++++++++++++
src/helper/tcl-libjim.c | 38 ++++++++++++++++++++++++++++++++++++++
3 files changed, 57 insertions(+)
create mode 100644 src/helper/tcl-common.h
create mode 100644 src/helper/tcl-libjim.c
hooks/post-receive
--
Main OpenOCD repository
|