From: john at keeping.me.uk (John Keeping)
Subject: [PATCH 8/8] filter: don't use dlsym unnecessarily
Date: Thu, 13 Aug 2015 12:14:20 +0100 [thread overview]
Message-ID: <9ffa0d517e7ee81ac262d9a657e77e0d19e99c68.1439464215.git.john@keeping.me.uk> (raw)
In-Reply-To: <cover.1439464215.git.john@keeping.me.uk>
We only need to hook write() if Lua filter's are in use. If support has
been disabled, remove the dependency on dlsym().
Signed-off-by: John Keeping <john at keeping.me.uk>
---
filter.c | 78 ++++++++++++++++++++++++++++++++++------------------------------
1 file changed, 42 insertions(+), 36 deletions(-)
diff --git a/filter.c b/filter.c
index c7037a3..949c931 100644
--- a/filter.c
+++ b/filter.c
@@ -8,17 +8,13 @@
#include "cgit.h"
#include "html.h"
-#include <dlfcn.h>
#ifndef NO_LUA
+#include <dlfcn.h>
#include <lua.h>
#include <lualib.h>
#include <lauxlib.h>
#endif
-static ssize_t (*libc_write)(int fd, const void *buf, size_t count);
-static ssize_t (*filter_write)(struct cgit_filter *base, const void *buf, size_t count) = NULL;
-static struct cgit_filter *current_write_filter = NULL;
-
static inline void reap_filter(struct cgit_filter *filter)
{
if (filter && filter->cleanup)
@@ -43,37 +39,6 @@ void cgit_cleanup_filters(void)
}
}
-void cgit_init_filters(void)
-{
- libc_write = dlsym(RTLD_NEXT, "write");
- if (!libc_write)
- die("Could not locate libc's write function");
-}
-
-ssize_t write(int fd, const void *buf, size_t count)
-{
- if (fd != STDOUT_FILENO || !filter_write)
- return libc_write(fd, buf, count);
- return filter_write(current_write_filter, buf, count);
-}
-
-static inline void hook_write(struct cgit_filter *filter, ssize_t (*new_write)(struct cgit_filter *base, const void *buf, size_t count))
-{
- /* We want to avoid buggy nested patterns. */
- assert(filter_write == NULL);
- assert(current_write_filter == NULL);
- current_write_filter = filter;
- filter_write = new_write;
-}
-
-static inline void unhook_write(void)
-{
- assert(filter_write != NULL);
- assert(current_write_filter != NULL);
- filter_write = NULL;
- current_write_filter = NULL;
-}
-
static int open_exec_filter(struct cgit_filter *base, va_list ap)
{
struct cgit_exec_filter *filter = (struct cgit_exec_filter *)base;
@@ -170,7 +135,48 @@ void cgit_exec_filter_init(struct cgit_exec_filter *filter, char *cmd, char **ar
filter->base.argument_count = 0;
}
+#ifdef NO_LUA
+void cgit_init_filters(void)
+{
+}
+#endif
+
#ifndef NO_LUA
+static ssize_t (*libc_write)(int fd, const void *buf, size_t count);
+static ssize_t (*filter_write)(struct cgit_filter *base, const void *buf, size_t count) = NULL;
+static struct cgit_filter *current_write_filter = NULL;
+
+void cgit_init_filters(void)
+{
+ libc_write = dlsym(RTLD_NEXT, "write");
+ if (!libc_write)
+ die("Could not locate libc's write function");
+}
+
+ssize_t write(int fd, const void *buf, size_t count)
+{
+ if (fd != STDOUT_FILENO || !filter_write)
+ return libc_write(fd, buf, count);
+ return filter_write(current_write_filter, buf, count);
+}
+
+static inline void hook_write(struct cgit_filter *filter, ssize_t (*new_write)(struct cgit_filter *base, const void *buf, size_t count))
+{
+ /* We want to avoid buggy nested patterns. */
+ assert(filter_write == NULL);
+ assert(current_write_filter == NULL);
+ current_write_filter = filter;
+ filter_write = new_write;
+}
+
+static inline void unhook_write(void)
+{
+ assert(filter_write != NULL);
+ assert(current_write_filter != NULL);
+ filter_write = NULL;
+ current_write_filter = NULL;
+}
+
struct lua_filter {
struct cgit_filter base;
char *script_file;
--
2.5.0.466.g9af26fa
next prev parent reply other threads:[~2015-08-13 11:14 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-08-13 11:14 [PATCH 0/8] Portability fixes john
2015-08-13 11:14 ` [PATCH 1/8] tests: allow shell to be overridden john
2015-08-13 11:14 ` [PATCH 2/8] Makefile: include Git's config.mak.uname john
2015-08-13 11:14 ` [PATCH 3/8] Remove redundant includes john
2015-08-13 13:36 ` Jason
2015-08-13 13:49 ` john
2015-08-20 13:51 ` mathstuf
2015-08-13 11:14 ` [PATCH 4/8] configfile.c: don't include system headers directly john
2015-08-13 11:14 ` [PATCH 5/8] cache.c: fix header order john
2015-08-13 11:14 ` [PATCH 6/8] cgit.h: move stdbool.h from ui-shared.h john
2015-08-13 11:14 ` [PATCH 7/8] ui-tree: use "sane" isgraph() john
2015-08-13 11:14 ` john [this message]
2015-08-13 13:38 ` [PATCH 0/8] Portability fixes Jason
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=9ffa0d517e7ee81ac262d9a657e77e0d19e99c68.1439464215.git.john@keeping.me.uk \
--to=cgit@lists.zx2c4.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).