[PATCH v8 1/2] Initial support for LuaJIT scripting

Dmitry V. Levin ldv at altlinux.org
Fri Jul 14 23:42:42 UTC 2017


On Sat, Jul 15, 2017 at 01:56:43AM +0300, Victor Krapivensky wrote:
> On Thu, Jul 13, 2017 at 09:24:03PM +0200, Eugene Syromiatnikov wrote:
> > On Tue, Jul 11, 2017 at 02:48:48PM +0300, Victor Krapivensky wrote:
[...]
> > > +#define EXPOSE_FUNC(rettype, ptr, name, ...)					\
> > > +	do {									\
> > > +		rettype (*fptr_)(__VA_ARGS__) = ptr;				\
> > > +		lua_pushvalue(L, -1); /* L: table cast cast */			\
> > > +		lua_pushstring(L, #rettype " (*)(" #__VA_ARGS__ ")");		\
> > > +		/* L: table cast cast str */					\
> > > +		lua_pushlightuserdata(L, * (void **) (&fptr_));			\
> > > +		/* L: table cast cast str ptr */				\
> > > +		assert_lua(lua_pcall(L, 2, 1, 0)); /* L: table cast value */	\
> > > +		lua_setfield(L, -3, name); /* L: table cast */			\
> > > +	} while (0)
> > > +
> > > +	EXPOSE_FUNC(bool, func_monitor, "monitor",
> > > +		unsigned int, unsigned int, bool, bool);
> > > +	EXPOSE_FUNC(struct tcb *, func_next_sc, "next_sc",
> > > +		void);
> > > +	EXPOSE_FUNC(bool, func_inject_signo, "inject_signo",
> > > +		int);
> > > +	EXPOSE_FUNC(bool, func_inject_retval, "inject_retval",
> > > +		int);
> > > +	EXPOSE_FUNC(int, func_umove, "umove",
> > > +		kernel_ulong_t, size_t, void *);
> > > +	EXPOSE_FUNC(int, func_umove_str, "umove_str",
> > > +		kernel_ulong_t, size_t, char *);
> > > +	EXPOSE_FUNC(bool, func_path_match_arr, "path_match_arr",
> > > +		const char **, size_t);
> > Taking into the account naming pattern, the duplication in ptr/name
> > values can be avoided.
> > 
> Could you please elaborate on this one?

#define EXPOSE_FUNC(rettype, name, ...)						\
	do {									\
		rettype (*fptr_)(__VA_ARGS__) = func_ ## name;			\
		lua_pushvalue(L, -1); /* L: table cast cast */			\
		lua_pushstring(L, #rettype " (*)(" #__VA_ARGS__ ")");		\
		/* L: table cast cast str */					\
		lua_pushlightuserdata(L, * (void **) (&fptr_));			\
		/* L: table cast cast str ptr */				\
		assert_lua(lua_pcall(L, 2, 1, 0)); /* L: table cast value */	\
		lua_setfield(L, -3, #name); /* L: table cast */			\
	} while (0)

	EXPOSE_FUNC(bool, monitor, unsigned int, unsigned int, bool, bool);
	EXPOSE_FUNC(struct tcb *, next_sc, void);
	EXPOSE_FUNC(bool, inject_signo, int);
	EXPOSE_FUNC(bool, inject_retval, int);
	EXPOSE_FUNC(int, umove, kernel_ulong_t, size_t, void *);
	EXPOSE_FUNC(int, umove_str, kernel_ulong_t, size_t, char *);
	EXPOSE_FUNC(bool, path_match_arr, const char **, size_t);

btw, have you considered use of typeof here?


-- 
ldv
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 801 bytes
Desc: not available
URL: <http://lists.strace.io/pipermail/strace-devel/attachments/20170715/d198d281/attachment.bin>


More information about the Strace-devel mailing list