From 719efe72b0707ed9b0e75a2bbf00e41ecc9ab451 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8D=9C=E9=83=A8=E6=98=8C=E5=B9=B3?= Date: Wed, 4 Dec 2019 12:30:06 +0900 Subject: internal/process.h rework Eliminated the macro to convert into an inline function. --- internal/process.h | 55 +++++++++++++++++++++++++++++++++++++----------------- 1 file changed, 38 insertions(+), 17 deletions(-) (limited to 'internal') diff --git a/internal/process.h b/internal/process.h index 8258f97f1b..c62b95bf80 100644 --- a/internal/process.h +++ b/internal/process.h @@ -9,8 +9,20 @@ * modify this file, provided that the conditions mentioned in the * file COPYING are met. Consult the file for details. */ +#include "ruby/config.h" /* for rb_pid_t */ +#include /* for size_t */ + +#ifdef HAVE_SYS_TYPES_H +# include /* for mode_t */ +#endif + +#ifdef _WIN32 +# include "ruby/win32.h" /* for mode_t */ +#endif + +#include "ruby/ruby.h" /* for VALUE */ +#include "internal/imemo.h" /* for RB_IMEMO_TMPBUF_PTR */ -/* process.c */ #define RB_MAX_GROUPS (65536) struct waitpid_state; @@ -60,24 +72,11 @@ struct rb_execarg { VALUE chdir_dir; }; -/* argv_str contains extra two elements. - * The beginning one is for /bin/sh used by exec_with_sh. - * The last one for terminating NULL used by execve. - * See rb_exec_fillarg() in process.c. */ -#define ARGVSTR2ARGV(argv_str) ((char **)RB_IMEMO_TMPBUF_PTR(argv_str) + 1) - -static inline size_t -ARGVSTR2ARGC(VALUE argv_str) -{ - size_t i = 0; - char *const *p = ARGVSTR2ARGV(argv_str); - while (p[i++]) - ; - return i - 1; -} - +/* process.c */ rb_pid_t rb_fork_ruby(int *status); void rb_last_status_clear(void); +static inline char **ARGVSTR2ARGV(VALUE argv_str); +static inline size_t ARGVSTR2ARGC(VALUE argv_str); RUBY_SYMBOL_EXPORT_BEGIN /* process.c (export) */ @@ -92,4 +91,26 @@ int rb_execarg_run_options(const struct rb_execarg *e, struct rb_execarg *s, cha VALUE rb_execarg_extract_options(VALUE execarg_obj, VALUE opthash); void rb_execarg_setenv(VALUE execarg_obj, VALUE env); RUBY_SYMBOL_EXPORT_END + +/* argv_str contains extra two elements. + * The beginning one is for /bin/sh used by exec_with_sh. + * The last one for terminating NULL used by execve. + * See rb_exec_fillarg() in process.c. */ +static inline char ** +ARGVSTR2ARGV(VALUE argv_str) +{ + char **buf = RB_IMEMO_TMPBUF_PTR(argv_str); + return &buf[1]; +} + +static inline size_t +ARGVSTR2ARGC(VALUE argv_str) +{ + size_t i = 0; + char *const *p = ARGVSTR2ARGV(argv_str); + while (p[i++]) + ; + return i - 1; +} + #endif /* INTERNAL_PROCESS_H */ -- cgit v1.2.3