Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/usr.bin/make make(1): export FStr and MFStr



details:   https://anonhg.NetBSD.org/src/rev/622ee9eec4f3
branches:  trunk
changeset: 979237:622ee9eec4f3
user:      rillig <rillig%NetBSD.org@localhost>
date:      Sun Dec 20 12:53:34 2020 +0000

description:
make(1): export FStr and MFStr

These types are a replacement for the pattern "var + var_freeIt" that
enforces these two variables to be updated together.

diffstat:

 usr.bin/make/nonints.h |  55 +++++++++++++++++++++++++++++++++++++++++++++++++-
 usr.bin/make/var.c     |  29 +------------------------
 2 files changed, 56 insertions(+), 28 deletions(-)

diffs (125 lines):

diff -r b365a3a9cd59 -r 622ee9eec4f3 usr.bin/make/nonints.h
--- a/usr.bin/make/nonints.h    Sun Dec 20 12:46:49 2020 +0000
+++ b/usr.bin/make/nonints.h    Sun Dec 20 12:53:34 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: nonints.h,v 1.175 2020/12/19 20:47:24 rillig Exp $     */
+/*     $NetBSD: nonints.h,v 1.176 2020/12/20 12:53:34 rillig Exp $     */
 
 /*-
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -164,12 +164,65 @@
 int Parse_GetFatals(void);
 
 /* str.c */
+
+/* A read-only string that may need to be freed after use. */
+typedef struct FStr {
+       const char *str;
+       void *freeIt;
+} FStr;
+
+/* A modifiable string that may need to be freed after use. */
+typedef struct MFStr {
+       char *str;
+       void *freeIt;
+} MFStr;
+
 typedef struct Words {
        char **words;
        size_t len;
        void *freeIt;
 } Words;
 
+/* Return a string that is the sole owner of str. */
+MAKE_INLINE FStr
+FStr_InitOwn(char *str)
+{
+       return (FStr){ str, str };
+}
+
+/* Return a string that refers to the shared str. */
+MAKE_INLINE FStr
+FStr_InitRefer(const char *str)
+{
+       return (FStr){ str, NULL };
+}
+
+MAKE_INLINE void
+FStr_Done(FStr *fstr)
+{
+       free(fstr->freeIt);
+}
+
+/* Return a string that is the sole owner of str. */
+MAKE_INLINE MFStr
+MFStr_InitOwn(char *str)
+{
+       return (MFStr){ str, str };
+}
+
+/* Return a string that refers to the shared str. */
+MAKE_INLINE MFStr
+MFStr_InitRefer(char *str)
+{
+       return (MFStr){ str, NULL };
+}
+
+MAKE_INLINE void
+MFStr_Done(MFStr *mfstr)
+{
+       free(mfstr->freeIt);
+}
+
 Words Str_Words(const char *, Boolean);
 MAKE_INLINE void
 Words_Free(Words w)
diff -r b365a3a9cd59 -r 622ee9eec4f3 usr.bin/make/var.c
--- a/usr.bin/make/var.c        Sun Dec 20 12:46:49 2020 +0000
+++ b/usr.bin/make/var.c        Sun Dec 20 12:53:34 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: var.c,v 1.741 2020/12/20 11:38:51 rillig Exp $ */
+/*     $NetBSD: var.c,v 1.742 2020/12/20 12:53:34 rillig Exp $ */
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -131,13 +131,7 @@
 #include "metachar.h"
 
 /*     "@(#)var.c      8.3 (Berkeley) 3/19/94" */
-MAKE_RCSID("$NetBSD: var.c,v 1.741 2020/12/20 11:38:51 rillig Exp $");
-
-/* A string that may need to be freed after use. */
-typedef struct FStr {
-       const char *str;
-       void *freeIt;
-} FStr;
+MAKE_RCSID("$NetBSD: var.c,v 1.742 2020/12/20 12:53:34 rillig Exp $");
 
 typedef enum VarFlags {
        VAR_NONE        = 0,
@@ -305,25 +299,6 @@
 
 static VarExportedMode var_exportedVars = VAR_EXPORTED_NONE;
 
-/* Return an FStr that is the sole owner of str. */
-static FStr
-FStr_InitOwn(char *str)
-{
-       return (FStr){ str, str };
-}
-
-/* Return an FStr that refers to the shared str. */
-static FStr
-FStr_InitRefer(const char *str)
-{
-       return (FStr){ str, NULL };
-}
-
-static void
-FStr_Done(FStr *fstr)
-{
-       free(fstr->freeIt);
-}
 
 static Var *
 VarNew(const char *name, void *name_freeIt, const char *value, VarFlags flags)



Home | Main Index | Thread Index | Old Index