All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/3] add real support for __BASE_FILE__
@ 2017-04-05  1:14 Luc Van Oostenryck
  2017-04-05  1:14 ` [PATCH 1/3] build: add missing #include "compat.h" Luc Van Oostenryck
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Luc Van Oostenryck @ 2017-04-05  1:14 UTC (permalink / raw)
  To: linux-sparse; +Cc: Christopher Li, Luc Van Oostenryck

These 3 patches add real support for __BASE_FILE__
as until now its expansion just returned the fixed
string: "base_file.c".

This series is available at:
	git://github.com/lucvoo/sparse.git base-file
based on commit:
	14964df5373292af78b29529d4fc7e1a26b67a97 (sparse-next @ 2017-03-31)
up to commit:
	f0988518f8792a203103af01f97ccb9b568bd37d


Luc Van Oostenryck (3):
  build: add missing #include "compat.h"
  add sparse_basename()
  add real support for __BASE_FILE__

 Makefile                                |  2 ++
 compat.h                                |  1 +
 compat/basename.c                       | 16 ++++++++++++++++
 compat/mmap-blob.c                      |  1 +
 compat/strtold.c                        |  1 +
 ident-list.h                            |  1 +
 lib.c                                   |  3 ---
 pre-process.c                           |  4 ++++
 validation/preprocessor/__BASE_FILE__.c | 11 +++++++++++
 9 files changed, 37 insertions(+), 3 deletions(-)
 create mode 100644 compat/basename.c
 create mode 100644 validation/preprocessor/__BASE_FILE__.c

-- Luc Van Oostenryck
-- 
2.12.0


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH 1/3] build: add missing #include "compat.h"
  2017-04-05  1:14 [PATCH 0/3] add real support for __BASE_FILE__ Luc Van Oostenryck
@ 2017-04-05  1:14 ` Luc Van Oostenryck
  2017-04-05  1:14 ` [PATCH 2/3] add sparse_basename() Luc Van Oostenryck
  2017-04-05  1:14 ` [PATCH 3/3] add real support for __BASE_FILE__ Luc Van Oostenryck
  2 siblings, 0 replies; 4+ messages in thread
From: Luc Van Oostenryck @ 2017-04-05  1:14 UTC (permalink / raw)
  To: linux-sparse; +Cc: Christopher Li, Luc Van Oostenryck

The files in compat/ didnt included "compat.h" which contains
the declarations of the functions defined there.

Fix this by adding the missing #include "compat.h".

Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
---
 Makefile           | 1 +
 compat/mmap-blob.c | 1 +
 compat/strtold.c   | 1 +
 3 files changed, 3 insertions(+)

diff --git a/Makefile b/Makefile
index 76902b75e..e8edd95f6 100644
--- a/Makefile
+++ b/Makefile
@@ -14,6 +14,7 @@ OS = linux
 CC = gcc
 CFLAGS = -O2 -finline-functions -fno-strict-aliasing -g
 CFLAGS += -Wall -Wwrite-strings
+CFLAGS += -I.
 LDFLAGS += -g
 LD = gcc
 AR = ar
diff --git a/compat/mmap-blob.c b/compat/mmap-blob.c
index 1cab4dead..79040c26e 100644
--- a/compat/mmap-blob.c
+++ b/compat/mmap-blob.c
@@ -1,3 +1,4 @@
+#include "compat.h"
 #include <sys/mman.h>
 #include <sys/types.h>
 
diff --git a/compat/strtold.c b/compat/strtold.c
index 1b6ad7d51..29e6eb73f 100644
--- a/compat/strtold.c
+++ b/compat/strtold.c
@@ -1,3 +1,4 @@
+#include "compat.h"
 #include <stdlib.h>
 
 long double string_to_ld(const char *nptr, char **endptr)
-- 
2.12.0


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH 2/3] add sparse_basename()
  2017-04-05  1:14 [PATCH 0/3] add real support for __BASE_FILE__ Luc Van Oostenryck
  2017-04-05  1:14 ` [PATCH 1/3] build: add missing #include "compat.h" Luc Van Oostenryck
@ 2017-04-05  1:14 ` Luc Van Oostenryck
  2017-04-05  1:14 ` [PATCH 3/3] add real support for __BASE_FILE__ Luc Van Oostenryck
  2 siblings, 0 replies; 4+ messages in thread
From: Luc Van Oostenryck @ 2017-04-05  1:14 UTC (permalink / raw)
  To: linux-sparse; +Cc: Christopher Li, Luc Van Oostenryck

Add sparse_basename() as a simplified version of basename()
working on Unix and non-unix environments.

Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
---
 Makefile          |  1 +
 compat.h          |  1 +
 compat/basename.c | 16 ++++++++++++++++
 3 files changed, 18 insertions(+)
 create mode 100644 compat/basename.c

diff --git a/Makefile b/Makefile
index e8edd95f6..b4826728c 100644
--- a/Makefile
+++ b/Makefile
@@ -107,6 +107,7 @@ LIB_OBJS= target.o parse.o tokenize.o pre-process.o symbol.o lib.o scope.o \
 	  expression.o show-parse.o evaluate.o expand.o inline.o linearize.o \
 	  char.o sort.o allocate.o compat-$(OS).o ptrlist.o \
 	  builtin.o \
+	  compat/basename.o \
 	  flow.o cse.o simplify.o memops.o liveness.o storage.o unssa.o dissect.o
 
 LIB_FILE= libsparse.a
diff --git a/compat.h b/compat.h
index 9814ae3e8..5b69548af 100644
--- a/compat.h
+++ b/compat.h
@@ -24,5 +24,6 @@ struct stat;
 void *blob_alloc(unsigned long size);
 void blob_free(void *addr, unsigned long size);
 long double string_to_ld(const char *nptr, char **endptr);
+const char *sparse_basename(const char *path);
 
 #endif
diff --git a/compat/basename.c b/compat/basename.c
new file mode 100644
index 000000000..c9770229c
--- /dev/null
+++ b/compat/basename.c
@@ -0,0 +1,16 @@
+#include "compat.h"
+#include <string.h>
+
+const char *sparse_basename(const char *path)
+{
+	const char *last;
+
+	last = strrchr(path, '/');
+	path = last ? last + 1 : path;
+#if defined(_WIN32) || defined(_WIN64)
+	last = strrchr(path, '\\');
+	path = last ? last + 1 : path;
+#endif
+
+	return path;
+}
-- 
2.12.0


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH 3/3] add real support for __BASE_FILE__
  2017-04-05  1:14 [PATCH 0/3] add real support for __BASE_FILE__ Luc Van Oostenryck
  2017-04-05  1:14 ` [PATCH 1/3] build: add missing #include "compat.h" Luc Van Oostenryck
  2017-04-05  1:14 ` [PATCH 2/3] add sparse_basename() Luc Van Oostenryck
@ 2017-04-05  1:14 ` Luc Van Oostenryck
  2 siblings, 0 replies; 4+ messages in thread
From: Luc Van Oostenryck @ 2017-04-05  1:14 UTC (permalink / raw)
  To: linux-sparse; +Cc: Christopher Li, Luc Van Oostenryck

There was some support of it but it was probably just
for sparse to not complain as it was a define that
expanded to the fixed name "base_file.c".

Fix this by letting it expand to the basename of the input
file.

Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
---
 ident-list.h                            |  1 +
 lib.c                                   |  3 ---
 pre-process.c                           |  4 ++++
 validation/preprocessor/__BASE_FILE__.c | 11 +++++++++++
 4 files changed, 16 insertions(+), 3 deletions(-)
 create mode 100644 validation/preprocessor/__BASE_FILE__.c

diff --git a/ident-list.h b/ident-list.h
index 8cc66a50c..21564bc5b 100644
--- a/ident-list.h
+++ b/ident-list.h
@@ -104,6 +104,7 @@ __IDENT(pragma_ident, "__pragma__", 0);
 __IDENT(__VA_ARGS___ident, "__VA_ARGS__", 0);
 __IDENT(__LINE___ident, "__LINE__", 0);
 __IDENT(__FILE___ident, "__FILE__", 0);
+__IDENT(__BASE_FILE___ident, "__BASE_FILE__", 0);
 __IDENT(__DATE___ident, "__DATE__", 0);
 __IDENT(__TIME___ident, "__TIME__", 0);
 __IDENT(__func___ident, "__func__", 0);
diff --git a/lib.c b/lib.c
index 272d2c88a..0b4564f5a 100644
--- a/lib.c
+++ b/lib.c
@@ -1038,9 +1038,6 @@ void create_builtin_stream(void)
 	add_pre_buffer("#define __builtin_ms_va_end(arg)\n");
 	add_pre_buffer("#define __builtin_va_arg_pack()\n");
 
-	/* FIXME! We need to do these as special magic macros at expansion time! */
-	add_pre_buffer("#define __BASE_FILE__ \"base_file.c\"\n");
-
 	if (optimize)
 		add_pre_buffer("#define __OPTIMIZE__ 1\n");
 	if (optimize_size)
diff --git a/pre-process.c b/pre-process.c
index 7c57ba1cd..dd698c5bc 100644
--- a/pre-process.c
+++ b/pre-process.c
@@ -172,6 +172,10 @@ static int expand_one_symbol(struct token **list)
 		replace_with_integer(token, token->pos.line);
 	} else if (token->ident == &__FILE___ident) {
 		replace_with_string(token, stream_name(token->pos.stream));
+	} else if (token->ident == &__BASE_FILE___ident) {
+		const char *base = stream_name(token->pos.stream);
+		base = sparse_basename(base);
+		replace_with_string(token, base);
 	} else if (token->ident == &__DATE___ident) {
 		if (!t)
 			time(&t);
diff --git a/validation/preprocessor/__BASE_FILE__.c b/validation/preprocessor/__BASE_FILE__.c
new file mode 100644
index 000000000..d1cce9633
--- /dev/null
+++ b/validation/preprocessor/__BASE_FILE__.c
@@ -0,0 +1,11 @@
+__BASE_FILE__
+
+/*
+ * check-name: __BASE_FILE__
+ * check-command: sparse -E $file
+ *
+ * check-output-start
+
+"__BASE_FILE__.c"
+ * check-output-end
+ */
-- 
2.12.0


^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2017-04-05  1:17 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-04-05  1:14 [PATCH 0/3] add real support for __BASE_FILE__ Luc Van Oostenryck
2017-04-05  1:14 ` [PATCH 1/3] build: add missing #include "compat.h" Luc Van Oostenryck
2017-04-05  1:14 ` [PATCH 2/3] add sparse_basename() Luc Van Oostenryck
2017-04-05  1:14 ` [PATCH 3/3] add real support for __BASE_FILE__ Luc Van Oostenryck

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.