From efe34223945a5d27a7ae9445d0793d6330cd2411 Mon Sep 17 00:00:00 2001
From: xbe <xbe@machine>
Date: Sun, 16 Mar 2014 00:14:26 -0700
Subject: [PATCH] py: Clean up includes.

Remove unnecessary includes. Add includes that improve portability.
---
 py/asmthumb.c        | 1 -
 py/binary.c          | 1 -
 py/builtin.c         | 4 ----
 py/builtinevex.c     | 5 -----
 py/builtinimport.c   | 1 -
 py/builtinmath.c     | 1 -
 py/builtinmp.c       | 1 -
 py/compile.c         | 3 +--
 py/emitbc.c          | 3 +--
 py/emitcommon.c      | 2 --
 py/emitcpy.c         | 3 +--
 py/emitinlinethumb.c | 2 --
 py/emitnative.c      | 3 +--
 py/emitpass1.c       | 3 ---
 py/formatfloat.c     | 1 -
 py/gc.c              | 1 -
 py/lexer.c           | 2 +-
 py/lexerstr.c        | 2 --
 py/lexerunix.c       | 4 +++-
 py/malloc.c          | 1 +
 py/map.c             | 2 --
 py/obj.c             | 3 ---
 py/objarray.c        | 3 ---
 py/objbool.c         | 2 --
 py/objboundmeth.c    | 3 ---
 py/objcell.c         | 3 ---
 py/objclosure.c      | 3 ---
 py/objcomplex.c      | 2 --
 py/objdict.c         | 3 +--
 py/objenumerate.c    | 1 -
 py/objexcept.c       | 2 --
 py/objfilter.c       | 1 -
 py/objfloat.c        | 2 --
 py/objfun.c          | 2 +-
 py/objgenerator.c    | 2 --
 py/objgetitemiter.c  | 2 --
 py/objint.c          | 2 --
 py/objint_longlong.c | 2 --
 py/objint_mpz.c      | 2 --
 py/objlist.c         | 2 --
 py/objmap.c          | 1 -
 py/objmodule.c       | 2 --
 py/objnone.c         | 1 -
 py/objrange.c        | 2 --
 py/objset.c          | 3 +--
 py/objslice.c        | 2 --
 py/objstr.c          | 4 +---
 py/objtuple.c        | 2 --
 py/objtype.c         | 2 --
 py/parse.c           | 5 +----
 py/parsenum.c        | 1 +
 py/runtime.c         | 2 --
 py/scope.c           | 2 +-
 py/sequence.c        | 4 +---
 py/showbc.c          | 3 ---
 py/stream.c          | 2 +-
 py/vm.c              | 3 ---
 py/vstr.c            | 1 +
 58 files changed, 19 insertions(+), 111 deletions(-)

diff --git a/py/asmthumb.c b/py/asmthumb.c
index 1e6c23e2e..3fcd28a91 100644
--- a/py/asmthumb.c
+++ b/py/asmthumb.c
@@ -1,4 +1,3 @@
-#include <stdint.h>
 #include <stdio.h>
 #include <assert.h>
 #include <string.h>
diff --git a/py/binary.c b/py/binary.c
index 20b38b8b1..7a8ed4611 100644
--- a/py/binary.c
+++ b/py/binary.c
@@ -1,4 +1,3 @@
-#include <stdlib.h>
 #include <stdint.h>
 #include <assert.h>
 
diff --git a/py/builtin.c b/py/builtin.c
index df488e054..2e0627fa5 100644
--- a/py/builtin.c
+++ b/py/builtin.c
@@ -1,8 +1,4 @@
-#include <stdint.h>
-#include <stdlib.h>
 #include <stdio.h>
-#include <stdarg.h>
-#include <string.h>
 #include <assert.h>
 
 #include "nlr.h"
diff --git a/py/builtinevex.c b/py/builtinevex.c
index 6e920e85f..d658db0ad 100644
--- a/py/builtinevex.c
+++ b/py/builtinevex.c
@@ -1,9 +1,4 @@
 #include <stdint.h>
-#include <stdlib.h>
-#include <stdio.h>
-#include <stdarg.h>
-#include <string.h>
-#include <assert.h>
 
 #include "nlr.h"
 #include "misc.h"
diff --git a/py/builtinimport.c b/py/builtinimport.c
index 7cbb46012..2b9b3a30b 100644
--- a/py/builtinimport.c
+++ b/py/builtinimport.c
@@ -1,7 +1,6 @@
 #include <stdint.h>
 #include <stdlib.h>
 #include <stdio.h>
-#include <stdarg.h>
 #include <string.h>
 #include <assert.h>
 
diff --git a/py/builtinmath.c b/py/builtinmath.c
index 35c1e45ed..eeb715048 100644
--- a/py/builtinmath.c
+++ b/py/builtinmath.c
@@ -1,4 +1,3 @@
-#include <stdint.h>
 #include <math.h>
 
 #include "misc.h"
diff --git a/py/builtinmp.c b/py/builtinmp.c
index 22091f4ea..3b7351796 100644
--- a/py/builtinmp.c
+++ b/py/builtinmp.c
@@ -1,4 +1,3 @@
-#include <stdint.h>
 
 #include "misc.h"
 #include "mpconfig.h"
diff --git a/py/compile.c b/py/compile.c
index d1aec3095..bb688d5d8 100644
--- a/py/compile.c
+++ b/py/compile.c
@@ -1,5 +1,4 @@
-#include <unistd.h>
-#include <stdlib.h>
+#include <stdbool.h>
 #include <stdint.h>
 #include <stdio.h>
 #include <string.h>
diff --git a/py/emitbc.c b/py/emitbc.c
index b26da0e70..ef5da3a62 100644
--- a/py/emitbc.c
+++ b/py/emitbc.c
@@ -1,5 +1,4 @@
-#include <unistd.h>
-#include <stdlib.h>
+#include <stdbool.h>
 #include <stdint.h>
 #include <stdio.h>
 #include <string.h>
diff --git a/py/emitcommon.c b/py/emitcommon.c
index ff6457289..f7494668e 100644
--- a/py/emitcommon.c
+++ b/py/emitcommon.c
@@ -1,7 +1,5 @@
 #include <unistd.h>
-#include <stdio.h>
 #include <stdint.h>
-#include <string.h>
 #include <assert.h>
 
 #include "misc.h"
diff --git a/py/emitcpy.c b/py/emitcpy.c
index b31425f2e..afd5a5af9 100644
--- a/py/emitcpy.c
+++ b/py/emitcpy.c
@@ -1,5 +1,4 @@
-#include <unistd.h>
-#include <stdlib.h>
+#include <stdbool.h>
 #include <stdint.h>
 #include <stdio.h>
 #include <string.h>
diff --git a/py/emitinlinethumb.c b/py/emitinlinethumb.c
index 675ed1efc..55af97f83 100644
--- a/py/emitinlinethumb.c
+++ b/py/emitinlinethumb.c
@@ -1,5 +1,3 @@
-#include <unistd.h>
-#include <stdlib.h>
 #include <stdint.h>
 #include <stdio.h>
 #include <string.h>
diff --git a/py/emitnative.c b/py/emitnative.c
index df531af6b..3ed415b04 100644
--- a/py/emitnative.c
+++ b/py/emitnative.c
@@ -16,8 +16,7 @@
 
 // for x in l[0:8]: can be compiled into a native loop if l has pointer type
 
-#include <unistd.h>
-#include <stdlib.h>
+#include <stdbool.h>
 #include <stdint.h>
 #include <stdio.h>
 #include <string.h>
diff --git a/py/emitpass1.c b/py/emitpass1.c
index d49265239..e4dbf1412 100644
--- a/py/emitpass1.c
+++ b/py/emitpass1.c
@@ -1,8 +1,5 @@
-#include <unistd.h>
 #include <stdlib.h>
 #include <stdint.h>
-#include <stdio.h>
-#include <string.h>
 #include <assert.h>
 
 #include "misc.h"
diff --git a/py/formatfloat.c b/py/formatfloat.c
index e42266a71..83aee1ef7 100644
--- a/py/formatfloat.c
+++ b/py/formatfloat.c
@@ -13,7 +13,6 @@
 
 ***********************************************************************/
 
-#include <stdint.h>
 #include <stdlib.h>
 
 #include "mpconfig.h"
diff --git a/py/gc.c b/py/gc.c
index e0941af01..67f1e810e 100644
--- a/py/gc.c
+++ b/py/gc.c
@@ -1,6 +1,5 @@
 #include <stdio.h>
 #include <stdlib.h>
-#include <stdint.h>
 #include <string.h>
 
 #include "mpconfig.h"
diff --git a/py/lexer.c b/py/lexer.c
index 26fec121c..58d54b698 100644
--- a/py/lexer.c
+++ b/py/lexer.c
@@ -1,9 +1,9 @@
 /* lexer.c -- simple tokeniser for Python implementation
  */
 
+#include <stdbool.h>
 #include <stdint.h>
 #include <stdio.h>
-#include <string.h>
 #include <assert.h>
 
 #include "misc.h"
diff --git a/py/lexerstr.c b/py/lexerstr.c
index 634aa42ac..a2168c96c 100644
--- a/py/lexerstr.c
+++ b/py/lexerstr.c
@@ -1,5 +1,3 @@
-#include <stdint.h>
-#include <stdio.h>
 
 #include "misc.h"
 #include "mpconfig.h"
diff --git a/py/lexerunix.c b/py/lexerunix.c
index fb62d3d72..73d30f247 100644
--- a/py/lexerunix.c
+++ b/py/lexerunix.c
@@ -1,4 +1,3 @@
-#include <stdint.h>
 #include <stdio.h>
 #include <unistd.h>
 #include <fcntl.h>
@@ -11,6 +10,9 @@
 
 #if MICROPY_ENABLE_LEXER_UNIX
 
+#include <sys/stat.h>
+#include <sys/types.h>
+
 mp_lexer_t *mp_lexer_new_from_file(const char *filename) {
     int fd = open(filename, O_RDONLY);
     if (fd < 0) {
diff --git a/py/malloc.c b/py/malloc.c
index 27eaac108..504db4b1b 100644
--- a/py/malloc.c
+++ b/py/malloc.c
@@ -1,3 +1,4 @@
+#include <unistd.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
diff --git a/py/map.c b/py/map.c
index f41152703..d1c368c6a 100644
--- a/py/map.c
+++ b/py/map.c
@@ -1,6 +1,4 @@
-#include <stdint.h>
 #include <stdlib.h>
-#include <assert.h>
 
 #include "misc.h"
 #include "mpconfig.h"
diff --git a/py/obj.c b/py/obj.c
index 0f36ef569..e98dbae6c 100644
--- a/py/obj.c
+++ b/py/obj.c
@@ -1,8 +1,5 @@
-#include <stdint.h>
-#include <stdlib.h>
 #include <stdio.h>
 #include <stdarg.h>
-#include <string.h>
 #include <assert.h>
 
 #include "nlr.h"
diff --git a/py/objarray.c b/py/objarray.c
index d0b3e003b..ee43bde96 100644
--- a/py/objarray.c
+++ b/py/objarray.c
@@ -1,7 +1,4 @@
-#include <stdlib.h>
-#include <stdint.h>
 #include <string.h>
-#include <stdarg.h>
 #include <assert.h>
 
 #include "nlr.h"
diff --git a/py/objbool.c b/py/objbool.c
index 1dc5e5760..9b4af2a31 100644
--- a/py/objbool.c
+++ b/py/objbool.c
@@ -1,5 +1,3 @@
-#include <stdlib.h>
-#include <stdint.h>
 
 #include "nlr.h"
 #include "misc.h"
diff --git a/py/objboundmeth.c b/py/objboundmeth.c
index 0b5fc10a0..1b9ac61f2 100644
--- a/py/objboundmeth.c
+++ b/py/objboundmeth.c
@@ -1,7 +1,4 @@
-#include <stdlib.h>
-#include <stdlib.h>
 #include <string.h>
-#include <assert.h>
 
 #include "nlr.h"
 #include "misc.h"
diff --git a/py/objcell.c b/py/objcell.c
index 366661747..a6922b018 100644
--- a/py/objcell.c
+++ b/py/objcell.c
@@ -1,6 +1,3 @@
-#include <stdlib.h>
-#include <stdint.h>
-#include <assert.h>
 
 #include "nlr.h"
 #include "misc.h"
diff --git a/py/objclosure.c b/py/objclosure.c
index e2de0e045..cd8129e24 100644
--- a/py/objclosure.c
+++ b/py/objclosure.c
@@ -1,7 +1,4 @@
-#include <stdlib.h>
-#include <stdint.h>
 #include <string.h>
-#include <assert.h>
 
 #include "nlr.h"
 #include "misc.h"
diff --git a/py/objcomplex.c b/py/objcomplex.c
index bba89daf0..65957cbf6 100644
--- a/py/objcomplex.c
+++ b/py/objcomplex.c
@@ -1,6 +1,4 @@
 #include <stdlib.h>
-#include <stdint.h>
-#include <string.h>
 #include <assert.h>
 
 #include "nlr.h"
diff --git a/py/objdict.c b/py/objdict.c
index 31a80bd6c..17cc499c5 100644
--- a/py/objdict.c
+++ b/py/objdict.c
@@ -1,5 +1,4 @@
-#include <stdlib.h>
-#include <stdint.h>
+#include <stdbool.h>
 #include <string.h>
 #include <assert.h>
 
diff --git a/py/objenumerate.c b/py/objenumerate.c
index 1c858ff56..1862eb74e 100644
--- a/py/objenumerate.c
+++ b/py/objenumerate.c
@@ -1,4 +1,3 @@
-#include <stdlib.h>
 #include <assert.h>
 
 #include "misc.h"
diff --git a/py/objexcept.c b/py/objexcept.c
index 532ca4320..11177724d 100644
--- a/py/objexcept.c
+++ b/py/objexcept.c
@@ -1,5 +1,3 @@
-#include <stdlib.h>
-#include <stdint.h>
 #include <string.h>
 #include <stdarg.h>
 #include <assert.h>
diff --git a/py/objfilter.c b/py/objfilter.c
index dc400f1a2..ea76b9907 100644
--- a/py/objfilter.c
+++ b/py/objfilter.c
@@ -1,4 +1,3 @@
-#include <stdlib.h>
 #include <assert.h>
 
 #include "nlr.h"
diff --git a/py/objfloat.c b/py/objfloat.c
index 04d127801..401c1145e 100644
--- a/py/objfloat.c
+++ b/py/objfloat.c
@@ -1,6 +1,4 @@
 #include <stdlib.h>
-#include <stdint.h>
-#include <string.h>
 #include <assert.h>
 
 #include "nlr.h"
diff --git a/py/objfun.c b/py/objfun.c
index 361df1914..7d49f18da 100644
--- a/py/objfun.c
+++ b/py/objfun.c
@@ -1,5 +1,5 @@
+#include <stdbool.h>
 #include <stdlib.h>
-#include <stdint.h>
 #include <string.h>
 #include <assert.h>
 
diff --git a/py/objgenerator.c b/py/objgenerator.c
index 6a03af856..8c4bb595f 100644
--- a/py/objgenerator.c
+++ b/py/objgenerator.c
@@ -1,6 +1,4 @@
 #include <stdlib.h>
-#include <stdint.h>
-#include <string.h>
 #include <assert.h>
 
 #include "nlr.h"
diff --git a/py/objgetitemiter.c b/py/objgetitemiter.c
index bf466c05d..08ef66f29 100644
--- a/py/objgetitemiter.c
+++ b/py/objgetitemiter.c
@@ -1,5 +1,3 @@
-#include <stdlib.h>
-#include <stdint.h>
 
 #include "nlr.h"
 #include "misc.h"
diff --git a/py/objint.c b/py/objint.c
index 7a9b0366d..9cba1ce74 100644
--- a/py/objint.c
+++ b/py/objint.c
@@ -1,6 +1,4 @@
-#include <stdlib.h>
 #include <stdint.h>
-#include <string.h>
 #include <assert.h>
 
 #include "nlr.h"
diff --git a/py/objint_longlong.c b/py/objint_longlong.c
index eca2951be..58c2466fd 100644
--- a/py/objint_longlong.c
+++ b/py/objint_longlong.c
@@ -1,7 +1,5 @@
 #include <stdlib.h>
 #include <stdint.h>
-#include <string.h>
-#include <assert.h>
 
 #include "nlr.h"
 #include "misc.h"
diff --git a/py/objint_mpz.c b/py/objint_mpz.c
index e8e8b8547..8b7ed78a2 100644
--- a/py/objint_mpz.c
+++ b/py/objint_mpz.c
@@ -1,7 +1,5 @@
-#include <stdlib.h>
 #include <stdint.h>
 #include <string.h>
-#include <assert.h>
 
 #include "nlr.h"
 #include "misc.h"
diff --git a/py/objlist.c b/py/objlist.c
index aa082ea34..f43670d60 100644
--- a/py/objlist.c
+++ b/py/objlist.c
@@ -1,5 +1,3 @@
-#include <stdlib.h>
-#include <stdint.h>
 #include <string.h>
 #include <assert.h>
 
diff --git a/py/objmap.c b/py/objmap.c
index cbaef6fb9..2b356ec4e 100644
--- a/py/objmap.c
+++ b/py/objmap.c
@@ -1,4 +1,3 @@
-#include <stdlib.h>
 #include <assert.h>
 
 #include "nlr.h"
diff --git a/py/objmodule.c b/py/objmodule.c
index 791932dc7..e0778b4cf 100644
--- a/py/objmodule.c
+++ b/py/objmodule.c
@@ -1,6 +1,4 @@
 #include <stdlib.h>
-#include <stdint.h>
-#include <string.h>
 #include <assert.h>
 
 #include "nlr.h"
diff --git a/py/objnone.c b/py/objnone.c
index 489d34d13..a4370efeb 100644
--- a/py/objnone.c
+++ b/py/objnone.c
@@ -1,5 +1,4 @@
 #include <stdlib.h>
-#include <stdint.h>
 
 #include "nlr.h"
 #include "misc.h"
diff --git a/py/objrange.c b/py/objrange.c
index 80c592838..f80bc0860 100644
--- a/py/objrange.c
+++ b/py/objrange.c
@@ -1,5 +1,3 @@
-#include <stdlib.h>
-#include <stdint.h>
 
 #include "nlr.h"
 #include "misc.h"
diff --git a/py/objset.c b/py/objset.c
index aea107fc1..437bae9bf 100644
--- a/py/objset.c
+++ b/py/objset.c
@@ -1,5 +1,4 @@
-#include <stdlib.h>
-#include <stdint.h>
+#include <stdbool.h>
 #include <string.h>
 #include <assert.h>
 
diff --git a/py/objslice.c b/py/objslice.c
index 10df671fe..46cce264a 100644
--- a/py/objslice.c
+++ b/py/objslice.c
@@ -1,6 +1,4 @@
 #include <stdlib.h>
-#include <stdint.h>
-#include <string.h>
 #include <assert.h>
 
 #include "nlr.h"
diff --git a/py/objstr.c b/py/objstr.c
index 64ba6c5fa..9762b0efd 100644
--- a/py/objstr.c
+++ b/py/objstr.c
@@ -1,6 +1,4 @@
-#include <stdlib.h>
-#include <stdint.h>
-#include <stdarg.h>
+#include <stdbool.h>
 #include <string.h>
 #include <assert.h>
 
diff --git a/py/objtuple.c b/py/objtuple.c
index 827441f70..83d1f21ce 100644
--- a/py/objtuple.c
+++ b/py/objtuple.c
@@ -1,6 +1,4 @@
 #include <string.h>
-#include <stdlib.h>
-#include <stdint.h>
 #include <assert.h>
 
 #include "nlr.h"
diff --git a/py/objtype.c b/py/objtype.c
index 6480a99f6..4898c5ccb 100644
--- a/py/objtype.c
+++ b/py/objtype.c
@@ -1,5 +1,3 @@
-#include <stdlib.h>
-#include <stdint.h>
 #include <string.h>
 #include <assert.h>
 
diff --git a/py/parse.c b/py/parse.c
index a7b73a567..1381f1293 100644
--- a/py/parse.c
+++ b/py/parse.c
@@ -1,9 +1,6 @@
-#include <unistd.h>
-#include <stdlib.h>
+#include <stdbool.h>
 #include <stdint.h>
 #include <stdio.h>
-#include <ctype.h>
-#include <string.h>
 #include <assert.h>
 
 #include "misc.h"
diff --git a/py/parsenum.c b/py/parsenum.c
index 8e290da33..c9cef5fcd 100644
--- a/py/parsenum.c
+++ b/py/parsenum.c
@@ -1,3 +1,4 @@
+#include <stdbool.h>
 #include <stdlib.h>
 
 #include "misc.h"
diff --git a/py/runtime.c b/py/runtime.c
index bd6f2289d..9c8ba636c 100644
--- a/py/runtime.c
+++ b/py/runtime.c
@@ -2,8 +2,6 @@
 // mp_xxx functions are safer and can be called by anyone
 // note that rt_assign_xxx are called only from emit*, and maybe we can rename them to reflect this
 
-#include <stdint.h>
-#include <stdlib.h>
 #include <stdio.h>
 #include <string.h>
 #include <assert.h>
diff --git a/py/scope.c b/py/scope.c
index fc12fb5da..cc4be7c85 100644
--- a/py/scope.c
+++ b/py/scope.c
@@ -1,6 +1,6 @@
+#include <stdbool.h>
 #include <stdint.h>
 #include <stdio.h>
-#include <string.h>
 #include <assert.h>
 
 #include "misc.h"
diff --git a/py/sequence.c b/py/sequence.c
index 1723bb416..184c34e0b 100644
--- a/py/sequence.c
+++ b/py/sequence.c
@@ -1,7 +1,5 @@
-#include <stdlib.h>
-#include <stdint.h>
+#include <stdbool.h>
 #include <string.h>
-#include <assert.h>
 
 #include "nlr.h"
 #include "misc.h"
diff --git a/py/showbc.c b/py/showbc.c
index 609048e8f..bc81086c7 100644
--- a/py/showbc.c
+++ b/py/showbc.c
@@ -1,7 +1,4 @@
-#include <stdint.h>
-#include <stdlib.h>
 #include <stdio.h>
-#include <string.h>
 #include <assert.h>
 
 #include "misc.h"
diff --git a/py/stream.c b/py/stream.c
index 59877d724..7c97ee10c 100644
--- a/py/stream.c
+++ b/py/stream.c
@@ -1,4 +1,4 @@
-#include <string.h>
+#include <unistd.h>
 
 #include "nlr.h"
 #include "misc.h"
diff --git a/py/vm.c b/py/vm.c
index 77762a13a..7b78b5fef 100644
--- a/py/vm.c
+++ b/py/vm.c
@@ -1,7 +1,4 @@
-#include <stdint.h>
-#include <stdlib.h>
 #include <stdio.h>
-#include <string.h>
 #include <assert.h>
 
 #include "nlr.h"
diff --git a/py/vstr.c b/py/vstr.c
index c518fa704..032acc61b 100644
--- a/py/vstr.c
+++ b/py/vstr.c
@@ -1,3 +1,4 @@
+#include <stdbool.h>
 #include <stdio.h>
 #include <stdarg.h>
 #include <string.h>
-- 
GitLab