summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorYukihiro "Matz" Matsumoto <[email protected]>2013-03-04 15:49:08 -0800
committerYukihiro "Matz" Matsumoto <[email protected]>2013-03-04 15:49:08 -0800
commit5a153851c3bc4aa96840438441d5a4c96906b299 (patch)
tree51feb5fa5d3dcdb675bfdc70847db99d10976309
parentf074951adab882fd128f0a763d9dd9eabd00ea24 (diff)
parent0e662e3bcd7d2676eadde28018a8306d66bb9775 (diff)
downloadmruby-5a153851c3bc4aa96840438441d5a4c96906b299.tar.gz
mruby-5a153851c3bc4aa96840438441d5a4c96906b299.zip
Merge pull request #947 from monaka/pr-cleanup-stdio-calls-20130304
Cleanup stdio related.
-rw-r--r--include/mrbconf.h4
-rw-r--r--src/class.c1
-rw-r--r--src/error.c7
-rw-r--r--src/numeric.c1
-rw-r--r--src/object.c1
-rw-r--r--src/parse.y1
-rw-r--r--src/print.c33
-rw-r--r--src/string.c1
-rw-r--r--src/vm.c1
9 files changed, 21 insertions, 29 deletions
diff --git a/include/mrbconf.h b/include/mrbconf.h
index 8a46e48ba..52490ceba 100644
--- a/include/mrbconf.h
+++ b/include/mrbconf.h
@@ -110,4 +110,8 @@ typedef short mrb_sym;
# include <inttypes.h>
#endif
+#ifdef ENABLE_STDIO
+# include <stdio.h>
+#endif
+
#endif /* MRUBYCONF_H */
diff --git a/src/class.c b/src/class.c
index 8ea323945..a3defc2ae 100644
--- a/src/class.c
+++ b/src/class.c
@@ -6,7 +6,6 @@
#include "mruby.h"
#include <stdarg.h>
-#include <stdio.h>
#include <ctype.h>
#include "mruby/class.h"
#include "mruby/proc.h"
diff --git a/src/error.c b/src/error.c
index 7599bd0a9..ed30173bc 100644
--- a/src/error.c
+++ b/src/error.c
@@ -6,7 +6,6 @@
#include "mruby.h"
#include <stdarg.h>
-#include <stdio.h>
#include <setjmp.h>
#include <string.h>
#include "error.h"
@@ -209,9 +208,7 @@ mrb_exc_raise(mrb_state *mrb, mrb_value exc)
mrb->exc = (struct RObject*)mrb_object(exc);
exc_debug_info(mrb, mrb->exc);
if (!mrb->jmp) {
-#ifdef ENABLE_STDIO
mrb_p(mrb, exc);
-#endif
abort();
}
longjmp(*(jmp_buf*)mrb->jmp, 1);
@@ -280,23 +277,27 @@ mrb_sprintf(mrb_state *mrb, const char *fmt, ...)
void
mrb_warn(const char *fmt, ...)
{
+#ifdef ENABLE_STDIO
va_list args;
va_start(args, fmt);
printf("warning: ");
vprintf(fmt, args);
va_end(args);
+#endif
}
void
mrb_bug(const char *fmt, ...)
{
+#ifdef ENABLE_STDIO
va_list args;
va_start(args, fmt);
printf("bug: ");
vprintf(fmt, args);
va_end(args);
+#endif
exit(EXIT_FAILURE);
}
diff --git a/src/numeric.c b/src/numeric.c
index 5aa577828..61b9a2f73 100644
--- a/src/numeric.c
+++ b/src/numeric.c
@@ -10,7 +10,6 @@
#include "mruby/array.h"
#include <math.h>
-#include <stdio.h>
#include <assert.h>
#if defined(__FreeBSD__) && __FreeBSD__ < 4
diff --git a/src/object.c b/src/object.c
index 6707fc6e4..0d1cc85b9 100644
--- a/src/object.c
+++ b/src/object.c
@@ -7,7 +7,6 @@
#include "mruby.h"
#include <string.h>
#include "mruby/string.h"
-#include <stdio.h>
#include "mruby/class.h"
#include "mruby/numeric.h"
#include "error.h"
diff --git a/src/parse.y b/src/parse.y
index 2b09c3e56..c6b377419 100644
--- a/src/parse.y
+++ b/src/parse.y
@@ -22,7 +22,6 @@
#include "mruby/proc.h"
#include "node.h"
-#include <stdio.h>
#include <errno.h>
#include <ctype.h>
#include <string.h>
diff --git a/src/print.c b/src/print.c
index 58297ea83..9d8a751f7 100644
--- a/src/print.c
+++ b/src/print.c
@@ -5,13 +5,12 @@
*/
#include "mruby.h"
-#ifdef ENABLE_STDIO
#include "mruby/string.h"
-#include <stdio.h>
static void
printstr(mrb_state *mrb, mrb_value obj)
{
+#ifdef ENABLE_STDIO
struct RString *str;
char *s;
int len;
@@ -22,14 +21,17 @@ printstr(mrb_state *mrb, mrb_value obj)
len = str->len;
fwrite(s, len, 1, stdout);
}
+#endif
}
void
mrb_p(mrb_state *mrb, mrb_value obj)
{
+#ifdef ENABLE_STDIO
obj = mrb_funcall(mrb, obj, "inspect", 0);
printstr(mrb, obj);
putc('\n', stdout);
+#endif
}
/* 15.3.1.2.9 */
@@ -55,31 +57,22 @@ mrb_init_print(mrb_state *mrb)
mrb_define_method(mrb, krn, "__printstr__", mrb_printstr, ARGS_REQ(1));
}
-
void
mrb_show_version(mrb_state *mrb)
{
- printf("mruby - Embeddable Ruby Copyright (c) 2010-2013 mruby developers\n");
-}
+ static const char version_msg[] = "mruby - Embeddable Ruby Copyright (c) 2010-2013 mruby developers\n";
+ mrb_value msg;
-void
-mrb_show_copyright(mrb_state *mrb)
-{
- printf("mruby - Copyright (c) 2010-2013 mruby developers\n");
-}
-#else
-void
-mrb_p(mrb_state *mrb, mrb_value obj)
-{
-}
-
-void
-mrb_show_version(mrb_state *mrb)
-{
+ msg = mrb_str_new(mrb, version_msg, sizeof(version_msg) - 1);
+ printstr(mrb, msg);
}
void
mrb_show_copyright(mrb_state *mrb)
{
+ static const char copyright_msg[] = "mruby - Copyright (c) 2010-2013 mruby developers\n";
+ mrb_value msg;
+
+ msg = mrb_str_new(mrb, copyright_msg, sizeof(copyright_msg) - 1);
+ printstr(mrb, msg);
}
-#endif
diff --git a/src/string.c b/src/string.c
index 23da3baa6..53e8fcab6 100644
--- a/src/string.c
+++ b/src/string.c
@@ -15,7 +15,6 @@
#include "mruby/array.h"
#include "mruby/class.h"
#include "mruby/numeric.h"
-#include <stdio.h>
#include "re.h"
const char mrb_digitmap[] = "0123456789abcdefghijklmnopqrstuvwxyz";
diff --git a/src/vm.c b/src/vm.c
index 2e92852bf..2255ebde8 100644
--- a/src/vm.c
+++ b/src/vm.c
@@ -17,7 +17,6 @@
#include "mruby/numeric.h"
#include "error.h"
-#include <stdio.h>
#include <string.h>
#include <setjmp.h>
#include <stddef.h>