logo

oasis

Own branch of Oasis Linux (upstream: <https://git.sr.ht/~mcf/oasis/>) git clone https://anongit.hacktivis.me/git/oasis.git

0001-Avoid-multiple-definitions-of-global-variables.patch (5732B)


  1. From 8d15541e85b391c1cd86907089d33f70d7ca0f65 Mon Sep 17 00:00:00 2001
  2. From: Michael Forney <mforney@mforney.org>
  3. Date: Mon, 4 Nov 2019 20:50:08 -0800
  4. Subject: [PATCH] Avoid multiple definitions of global variables
  5. ---
  6. exec.c | 9 ++++++++-
  7. exec.h | 12 ++++++------
  8. io.c | 1 +
  9. io.h | 2 +-
  10. lex.c | 3 +++
  11. rc.h | 30 +++++++++++++++---------------
  12. simple.c | 2 ++
  13. subr.c | 1 +
  14. var.c | 1 +
  15. 9 files changed, 38 insertions(+), 23 deletions(-)
  16. diff --git a/exec.c b/exec.c
  17. index 3ad8a0d..268f429 100644
  18. --- a/exec.c
  19. +++ b/exec.c
  20. @@ -3,10 +3,17 @@
  21. #include "exec.h"
  22. #include "io.h"
  23. #include "fns.h"
  24. +int mypid;
  25. +thread *runq;
  26. +code *codebuf;
  27. +int ntrap;
  28. +int trap[NSIG];
  29. +int eflagok;
  30. +
  31. /*
  32. * Start executing the given code at the given pc with the given redirection
  33. */
  34. -char *argv0="rc";
  35. +char *argv0 = "rc";
  36. void
  37. start(code *c, int pc, var *local)
  38. diff --git a/exec.h b/exec.h
  39. index 06d2991..ab0bfb4 100644
  40. --- a/exec.h
  41. +++ b/exec.h
  42. @@ -56,18 +56,18 @@ struct thread{
  43. tree *treenodes; /* tree nodes created by this process */
  44. thread *ret; /* who continues when this finishes */
  45. };
  46. -thread *runq;
  47. +extern thread *runq;
  48. code *codecopy(code*);
  49. -code *codebuf; /* compiler output */
  50. -int ntrap; /* number of outstanding traps */
  51. -int trap[NSIG]; /* number of outstanding traps per type */
  52. +extern code *codebuf; /* compiler output */
  53. +extern int ntrap; /* number of outstanding traps */
  54. +extern int trap[NSIG]; /* number of outstanding traps per type */
  55. struct builtin{
  56. char *name;
  57. void (*fnc)(void);
  58. };
  59. extern struct builtin Builtin[];
  60. -int eflagok; /* kludge flag so that -e doesn't exit in startup */
  61. -int havefork;
  62. +extern int eflagok; /* kludge flag so that -e doesn't exit in startup */
  63. +extern int havefork;
  64. void execcd(void), execwhatis(void), execeval(void), execexec(void);
  65. int execforkexec(void);
  66. diff --git a/io.c b/io.c
  67. index bb8af4a..228ec56 100644
  68. --- a/io.c
  69. +++ b/io.c
  70. @@ -3,6 +3,7 @@
  71. #include "exec.h"
  72. #include "io.h"
  73. #include "fns.h"
  74. +io *err;
  75. int pfmtnest = 0;
  76. void
  77. diff --git a/io.h b/io.h
  78. index 21cc6b8..68b9e89 100644
  79. --- a/io.h
  80. +++ b/io.h
  81. @@ -10,7 +10,7 @@ struct io{
  82. int fd;
  83. char *bufp, *ebuf, *strp, buf[NBUF];
  84. };
  85. -io *err;
  86. +extern io *err;
  87. io *openfd(int), *openstr(void), *opencore(char *, int);
  88. int emptybuf(io*);
  89. void pchr(io*, int);
  90. diff --git a/lex.c b/lex.c
  91. index d2bef32..943112a 100644
  92. --- a/lex.c
  93. +++ b/lex.c
  94. @@ -22,6 +22,7 @@ idchr(int c)
  95. return c>' ' && !strchr("!\"#$%&'()+,-./:;<=>?@[\\]^`{|}~", c);
  96. }
  97. int future = EOF;
  98. +char *promptstr;
  99. int doprompt = 1;
  100. int inquote;
  101. int incomm;
  102. @@ -36,6 +37,7 @@ nextc(void)
  103. future = getnext();
  104. return future;
  105. }
  106. +int lastc;
  107. /*
  108. * Consume the lookahead character.
  109. */
  110. @@ -131,6 +133,7 @@ nextis(int c)
  111. }
  112. return 0;
  113. }
  114. +char tok[NTOK];
  115. char*
  116. addtok(char *p, int val)
  117. diff --git a/rc.h b/rc.h
  118. index 8a6a5bb..cbec275 100644
  119. --- a/rc.h
  120. +++ b/rc.h
  121. @@ -53,7 +53,7 @@ tree *mung1(tree*, tree*), *mung2(tree*, tree*, tree*);
  122. tree *mung3(tree*, tree*, tree*, tree*), *epimung(tree*, tree*);
  123. tree *simplemung(tree*), *heredoc(tree*);
  124. void freetree(tree*);
  125. -tree *cmdtree;
  126. +extern tree *cmdtree;
  127. /*
  128. * The first word of any code vector is a reference count.
  129. * Always create a new reference to a code vector by calling codecopy(.).
  130. @@ -64,10 +64,10 @@ union code{
  131. int i;
  132. char *s;
  133. };
  134. -char *promptstr;
  135. -int doprompt;
  136. +extern char *promptstr;
  137. +extern int doprompt;
  138. #define NTOK 8192
  139. -char tok[NTOK];
  140. +extern char tok[NTOK];
  141. #define APPEND 1
  142. #define WRITE 2
  143. #define READ 3
  144. @@ -87,7 +87,7 @@ struct var{
  145. };
  146. var *vlook(char*), *gvlook(char*), *newvar(char*, var*);
  147. #define NVAR 521
  148. -var *gvar[NVAR]; /* hash for globals */
  149. +extern var *gvar[NVAR]; /* hash for globals */
  150. #define new(type) ((type *)emalloc(sizeof(type)))
  151. void *emalloc(long);
  152. void *Malloc(ulong);
  153. @@ -98,7 +98,7 @@ struct here{
  154. char *name;
  155. struct here *next;
  156. };
  157. -int mypid;
  158. +extern int mypid;
  159. /*
  160. * Glob character escape in strings:
  161. * In a string, GLOB must be followed by *?[ or GLOB.
  162. @@ -117,10 +117,10 @@ int mypid;
  163. #define threebyte(c) ((c&0xf0)==0xe0)
  164. #define fourbyte(c) ((c&0xf8)==0xf0)
  165. -char **argp;
  166. -char **args;
  167. -int nerror; /* number of errors encountered during compilation */
  168. -int doprompt; /* is it time for a prompt? */
  169. +extern char **argp;
  170. +extern char **args;
  171. +extern int nerror; /* number of errors encountered during compilation */
  172. +extern int doprompt; /* is it time for a prompt? */
  173. /*
  174. * Which fds are the reading/writing end of a pipe?
  175. * Unfortunately, this can vary from system to system.
  176. @@ -129,14 +129,14 @@ int doprompt; /* is it time for a prompt? */
  177. */
  178. #define PRD 0
  179. #define PWR 1
  180. -char *Rcmain, *Fdprefix;
  181. +extern char *Rcmain, *Fdprefix;
  182. #define register
  183. /*
  184. * How many dot commands have we executed?
  185. * Used to ensure that -v flag doesn't print rcmain.
  186. */
  187. -int ndot;
  188. +extern int ndot;
  189. char *getstatus(void);
  190. -int lastc;
  191. -int lastword;
  192. -int kidpid;
  193. +extern int lastc;
  194. +extern int lastword;
  195. +extern int kidpid;
  196. diff --git a/simple.c b/simple.c
  197. index d587227..7f1ee12 100644
  198. --- a/simple.c
  199. +++ b/simple.c
  200. @@ -6,6 +6,8 @@
  201. #include "exec.h"
  202. #include "io.h"
  203. #include "fns.h"
  204. +int ndot;
  205. +
  206. /*
  207. * Search through the following code to see if we're just going to exit.
  208. */
  209. diff --git a/subr.c b/subr.c
  210. index a2d8a18..f031be5 100644
  211. --- a/subr.c
  212. +++ b/subr.c
  213. @@ -23,6 +23,7 @@ efree(void *p)
  214. else pfmt(err, "free 0\n");
  215. }
  216. extern int lastword, lastdol;
  217. +int nerror;
  218. void
  219. yyerror(char *m)
  220. diff --git a/var.c b/var.c
  221. index 2564ba2..b4a3ef5 100644
  222. --- a/var.c
  223. +++ b/var.c
  224. @@ -1,6 +1,7 @@
  225. #include "rc.h"
  226. #include "exec.h"
  227. #include "fns.h"
  228. +var *gvar[NVAR];
  229. int
  230. hash(char *s, int n)
  231. --
  232. 2.24.0