Граф коммитов

148 Коммитов

Автор SHA1 Сообщение Дата
nobu f4166e2dd7 prefer rb_syserr_fail
* file.c, io.c, util.c: prefer rb_syserr_fail with saved errno
  over setting errno then call rb_sys_fail, not to be clobbered
  potentially and to reduce thread local errno accesses.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@53264 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-12-23 08:57:48 +00:00
nobu a8994b167e util.c: BSD qsort_r
* util.c (ruby_qsort): use BSD-style qsort_r if available.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51857 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-09-15 03:44:34 +00:00
nobu e521b916ec util.c: fix off-by-one error
* util.c (ruby_scan_digits): fix the return length off-by-one
  error when the length is given and the last char is a digit.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@50935 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-06-17 07:21:41 +00:00
nobu 238394e738 parse.y: check NTH_REF range
* compile.c (iseq_compile_each): out of range NTH_REF is always
  nil.
* parse.y (parse_numvar): check overflow of NTH_REF and range.
  [ruby-core:69393] [Bug #11192]
* util.c (ruby_scan_digits): make public and add length parameter.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@50671 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-05-29 05:39:03 +00:00
nobu b4974e71dc util.c: hexdigit
* util.c (hexdigit): extract identical constants.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@49583 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-02-13 07:07:39 +00:00
akr 7cd76ab0c5 * internal.h: Include ruby.h and ruby/encoding.h to be
includable without prior inclusion.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@48447 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-11-15 11:49:06 +00:00
nobu 17eb86eb12 util.c: let getcwd allocate buffer
* util.c (ruby_getcwd): POSIX.1-2001 extends getcwd(3) as it
  allocates the buffer if the argument is NULL.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@45598 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-04-16 08:46:29 +00:00
glass cd476cd86b * configure.in: check qsort_r(3) and whether it is GNU version.
BSD version has different prototype.

* util.h: use qsort_r() as ruby_qsort() if it is GNU version.

* util.c: define ruby_qsort() if needed.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@44889 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-02-08 12:50:28 +00:00
nobu fcd7887407 util.c: bump stack size in ruby_qsort()
* util.c (ruby_qsort): fix potential stack overflow on a large
  machine.  based on the patch by Conrad Irwin <conrad.irwin AT
  gmail.com> at [ruby-core:51816].  [Bug #7772]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@44195 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-12-14 02:45:07 +00:00
nobu cf0efb8327 util.c: more precision
* util.c (ruby_strtod): BigMath requires more precision.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43780 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-11-22 04:10:46 +00:00
nobu 5cb83d9dab util.c: ignore too long fraction part
* util.c (ruby_strtod): ignore too long fraction part, which does not
  affect the result.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43775 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-11-22 03:43:56 +00:00
akr b2be623240 * internal.h (ruby_digit36_to_number_table): Declared.
* util.c (ruby_digit36_to_number_table): Moved from scan_digits.

* bignum.c (conv_digit): Use ruby_digit36_to_number_table.

* pack.c (hex2num): Ditto.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@41757 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-07-03 13:32:14 +00:00
nobu 2fef15145c util.c: constify
* util.c (scan_digits): constify readonly table.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@41730 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-07-01 14:44:31 +00:00
naruse f544ca4e4e * util.c (ruby_hdtoa): revert r29729.
If you want ruby to behave as before on x86, specify to use SSE like
  -msse2 -mfpmath=sse for gcc.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40404 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-04-22 02:59:09 +00:00
yugui 76bc2d1ed7 Imports Ruby's port to NativeClient (a.k.a NaCl).
Patch by Google Inc. [ruby-core:45073].

* configure.in (RUBY_NACL): New M4 func to configure variables for
  NaCl.
  (RUBY_NACL_CHECK_PEPPER_TYPES): New M4 func to check the old names
  of Pepper interface types.
  (BTESTRUBY): New variable to specify which ruby should be run on
  "make btest". NaCl can run the built binary by sel_ldr, but it need
  rbconfig.rb. So this variable is distinguished from $MINIRUBY.
  
* thread_pthread.c: Disabled some features on NaCl.

* io.c: ditto.

* process.c: ditto.

* signal.c: ditto.

* file.c: ditto.

* missing/flock.c: ditto.

* nacl/pepper_main.c: An example implementation of Pepper application
  that embeds Ruby.

* nacl/example.html: An example of web page that uses the Pepper
  application.

* nacl/nacl-config.rb: Detects variants of NaCl SDK.

* nacl/GNUmakefile.in: Makefile template for NaCl specific build
  process.

* nacl/package.rb: script for packaging a NaCl-Ruby embedding
  application. 

* nacl/reate_nmf.rb: Wrapper script of create_nmf.py

* dln.c (dln_load): Added a hack to call on NaCl.

* util.c (ruby_getcwd): Path to the current directort is not available
  on NaCl.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@35672 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-05-17 02:48:59 +00:00
nobu a258d6f415 * util.c (ruby_strtod): no need to check same digit for hexdigit
twice.  [ruby-dev:45363][Bug #6146]


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@35035 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-03-15 06:04:56 +00:00
kazu 0212af1733 * ext/bigdecimal/bigdecimal.h: add satisfy cc-mode comment.
* util.c: ditto.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@34104 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2011-12-22 21:06:19 +00:00
nobu 72cbec3f6d * util.c (mmprepare): fix for fragmental size.
* util.c (mmswap_, mmrot3_): portability improvement.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@33489 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2011-10-20 02:42:26 +00:00
usa f9e9eee677 * util.c, include/ruby/util.h (ruby_add_suffix): remove the function.
[Bug #5153] [ruby-core:38736]

* io.c (argf_next_argv): remove the call of above function.

* ext/-test-/add_suffix, test/-ext-/test_add_suffix.rb: remove the test
  extension module because this is only for testsing ruby_add_suffix().

* LEGAL: remove the mention about a part of util.c, because now we
  removed the part.

* io.c (argf_next_argv): now the new filename is not guranteed to
  use, so should check the return value of rename(2).

* test/ruby/test_argf.rb (TestArgf#test_inplace_rename_impossible):
  now we expect same result with other platforms on no_safe_rename
  platforms (=Windows).


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@32826 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2011-08-03 07:10:56 +00:00
kosaki b9a13f4962 * thread_pthread.c (mutex_debug): use exit(EXIT_FAILURE) instad of
exit(1).
* thread_pthread.c (add_signal_thread_list): ditto.
* thread.c (rb_thread_call_with_gvl): ditto.
* util.c (Bug): ditto.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@32494 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2011-07-10 08:29:46 +00:00
akr afd7e4668f * internal.h: declare more internal functions.
* iseq.h (rb_method_get_iseq): declared.

* compile.c, eval.c, eval_error.c, iseq.c, parse.y, proc.c, range.c,
  ruby.c, time.c, util.c, vm.c: don't declare internal functions.

* eval.c, parse.y, thread_pthread.c: non-existing function declarations
  removed.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@32158 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2011-06-18 01:54:57 +00:00
akr ee0f448fea * util.c: parenthesize macro arguments.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@30504 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2011-01-10 02:24:04 +00:00
naruse c383fbf93f * util.c (ruby_strtod): this code uses FPU's rounding system.
But x86's FPU calculates double precision floating-point
  numbers in 80bit precision, so it fails to round the value.
  So ensure the value is assigned a variable. [ruby-dev:42551]
  see also [ruby-math:00802]
  http://www.shudo.net/java-grandprix99/strictfp/

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@29729 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2010-11-09 01:57:49 +00:00
nobu b188d19ee0 * util.c (ruby_strtod): suppress a warning.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@29727 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2010-11-08 22:28:17 +00:00
naruse e640e1c565 * util.c (ruby_hdtoa): fix type cast and bufsize.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@29720 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2010-11-08 09:28:42 +00:00
nobu 767fe5170d * util.c (ruby_strtod): get rid of overflow/underflow as possible.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@29645 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2010-10-30 08:23:40 +00:00
nobu bd7daa5ac5 * util.c (ruby_strtod): fix indent.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@29644 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2010-10-30 06:39:53 +00:00
naruse 05ba0b1dd5 * util.c (ruby_strtod): reject 0x1.p+0. [ruby-dev:42432] #3966
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@29539 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2010-10-20 01:48:24 +00:00
nobu 17c48bebf8 * compile.c (iseq_build_body), insns.def (getglobal, setglobal),
iseq.c (iseq_load, iseq_data_to_ary), util.c (valid_filename):
  use VALUE.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@29461 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2010-10-12 14:35:40 +00:00
naruse 2590d7447a * util.c (ruby_strtod): reject Float('0x0.').
[ruby-dev:42239] Bug #3820

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@29239 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2010-09-13 01:15:39 +00:00
naruse a69423beb8 * util.c (ruby_strtod): check there is at least 1 digit after
"0x" before ".". [ruby-dev:42183] #3790

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@29187 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2010-09-06 01:00:29 +00:00
naruse 0ed5aee000 * util.c (ruby_strtod): check integr overflow.
[ruby-dev:42180] #3789

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@29186 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2010-09-06 00:46:48 +00:00
naruse 815ab02971 * util.c (ruby_strtod): make sure to have digit-sequence after 'p'
for hexadecimal-floating-constant. [ruby-dev:42105]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@29073 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2010-08-23 03:19:58 +00:00
nobu a043fb8642 From b80689141673b93e8d12968c3196ec6a2331da45 Mon Sep 17 00:00:00 2001
From: Nobuyoshi Nakada <nobu@ruby-lang.org>
Date: Mon, 16 Aug 2010 18:55:11 +0900
Subject: [PATCH 2/2] 	* util.c (ruby_dtoa, ruby_hdtoa): use same representations for
 	  Infinity and NaN.  a part of a patch from Peter Weldon at
 	  [ruby-core:31725].

---
 util.c |   14 ++++++++------
 1 files changed, 8 insertions(+), 6 deletions(-)

diff --git a/util.c b/util.c
index 065b2f1..76ba457 100644
--- a/util.c
+++ b/util.c
@@ -3145,6 +3145,10 @@ freedtoa(char *s)
 }
 #endif

+static const char INFSTR[] = "Infinity";
+static const char NANSTR[] = "NaN";
+static const char ZEROSTR[] = "0";
+
 /* dtoa for IEEE arithmetic (dmg): convert double to ASCII string.
  *
  * Inspired by "How to Print Floating-Point Numbers Accurately" by
@@ -3263,9 +3267,9 @@ ruby_dtoa(double d_, int mode, int ndigits, int *decpt, int *sign, char **rve)
         *decpt = 9999;
 #ifdef IEEE_Arith
         if (!word1(d) && !(word0(d) & 0xfffff))
-            return rv_strdup("Infinity", rve);
+            return rv_strdup(INFSTR, rve);
 #endif
-        return rv_strdup("NaN", rve);
+        return rv_strdup(NANSTR, rve);
     }
 #endif
 #ifdef IBM
@@ -3273,7 +3277,7 @@ ruby_dtoa(double d_, int mode, int ndigits, int *decpt, int *sign, char **rve)
 #endif
     if (!dval(d)) {
         *decpt = 1;
-        return rv_strdup("0", rve);
+        return rv_strdup(ZEROSTR, rve);
     }

 #ifdef SET_INEXACT
@@ -3897,8 +3901,6 @@ ruby_each_words(const char *str, void (*func)(const char*, int, void*), void *ar

 #define	DBL_MANH_SIZE	20
 #define	DBL_MANL_SIZE	32
-#define	INFSTR	"Infinity"
-#define	NANSTR	"NaN"
 #define	DBL_ADJ	(DBL_MAX_EXP - 2)
 #define	SIGFIGS	((DBL_MANT_DIG + 3) / 4 + 1)
 #define dexp_get(u) ((int)(word0(u) >> Exp_shift) & ~Exp_msk1)
@@ -3959,7 +3961,7 @@ ruby_hdtoa(double d, const char *xdigs, int ndigits, int *decpt, int *sign,
 	}
 	else if (d == 0.0) { /* FP_ZERO */
 	    *decpt = 1;
-	    return rv_strdup("0", rve);
+	    return rv_strdup(ZEROSTR, rve);
 	}
 	else if (dexp_get(u)) { /* FP_NORMAL */
 	    *decpt = dexp_get(u) - DBL_ADJ;
--
1.7.0.4

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@29011 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2010-08-16 10:23:22 +00:00
nobu d17ff1a6a5 From 75db84d6ec7c9ef5fd05e5835ac1004df8ea7e2a Mon Sep 17 00:00:00 2001
From: Nobuyoshi Nakada <nobu@ruby-lang.org>
Date: Mon, 16 Aug 2010 18:50:06 +0900
Subject: [PATCH 1/2] 	* util.c (ruby_hdtoa): fixed buffer overrun.  based on a patch
 	  from Peter Weldon at [ruby-core:31725].

---
 util.c |    6 +++---
 1 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/util.c b/util.c
index 97b2d6c..065b2f1 100644
--- a/util.c
+++ b/util.c
@@ -3951,15 +3951,15 @@ ruby_hdtoa(double d, const char *xdigs, int ndigits, int *decpt, int *sign,

 	if (isinf(d)) { /* FP_INFINITE */
 	    *decpt = INT_MAX;
-	    return (nrv_alloc(INFSTR, rve, sizeof(INFSTR) - 1));
+	    return rv_strdup(INFSTR, rve);
 	}
 	else if (isnan(d)) { /* FP_NAN */
 	    *decpt = INT_MAX;
-	    return (nrv_alloc(NANSTR, rve, sizeof(NANSTR) - 1));
+	    return rv_strdup(NANSTR, rve);
 	}
 	else if (d == 0.0) { /* FP_ZERO */
 	    *decpt = 1;
-	    return (nrv_alloc("0", rve, 1));
+	    return rv_strdup("0", rve);
 	}
 	else if (dexp_get(u)) { /* FP_NORMAL */
 	    *decpt = dexp_get(u) - DBL_ADJ;
--
1.7.0.4

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@29010 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2010-08-16 10:22:36 +00:00
nobu 0794c1da93 * util.c (ruby_add_suffix): suppress a warning.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@28806 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2010-07-31 00:36:12 +00:00
nobu 7ae7ac4aba * util.c (ruby_add_suffix): fixed a bug returning uninitialized
value.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@28794 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2010-07-29 22:59:54 +00:00
nobu 9a89e864ea * util.c (ruby_hdtoa): renamed from BSD__hdtoa.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@28696 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2010-07-21 02:55:10 +00:00
nobu e4820b1cfa * util.c (ruby_add_suffix): fixed type warnings.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@28664 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2010-07-17 05:10:22 +00:00
usa 09ee12bb20 * io.c (argf_inplace_mode_set): prohibits an assignment of a tainted
value.

* file.c (ruby_find_basename, ruby_find_extname): split from
  rb_file_s_basename() and rb_file_s_extname().

* util.c (ruby_add_suffix): support arbitrary length of the suffix
  to get rid of the potential buffer overflow.
  reported by tarui.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@28525 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2010-07-02 14:31:26 +00:00
nobu 7271a56417 * util.c (BSD__hdtoa): suppress a warning.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@27165 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2010-04-01 21:59:57 +00:00
naruse 3a4c2bc034 * util.c (BSD__hdtoa): don't use C99 macros. (FP_NORMAL etc)
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@27142 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2010-04-01 05:09:10 +00:00
naruse 12b2e16e21 * sprintf.c (rb_str_format): support %a format. [ruby-dev:40650]
* missing/vsnprintf.c (BSD_vfprintf): ditto.

* missing/vsnprintf.c (cvt): ditto.

* util.c (BSD__hdtoa): added.  This is 2-clause BSDL licensed
  by David Schultz and from FreeBSD.

* LEGAL: add about hdtoa() in util.c.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@27141 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2010-04-01 04:32:57 +00:00
naruse 4d399f12d4 * object.c (rb_cstr_to_dbl): return 0.0 if hexadecimal and
baccheck is FALSE: Float("0x1p+0") works, but "0x1p+0".to_f
  doesn't. [ruby-dev:40650]

* util.c (ruby_strtod): allow hexdecimal integers.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@27140 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2010-04-01 04:32:43 +00:00
naruse 9eb68d7c44 * util.c (ruby_strtod): Add support for Hexadecimal
floating-point expression [ruby-dev:40650] #2969

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@26965 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2010-03-17 16:21:45 +00:00
nobu 4d786d21e3 * removed spaces just before tabs.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@25930 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2009-11-26 05:25:08 +00:00
akr 145f07fac2 * util.c (ruby_strtod): use dval() consistently.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@25712 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2009-11-10 23:23:15 +00:00
akr b9e0294eda fix typos.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@25635 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2009-11-03 17:46:28 +00:00
nobu 8e86bd59c0 * common.mk (bignum.o, numeric.o): depend on util.h.
* bignum.c, marshal.c: fixed types.

* numeric.c (infinite_value): use ruby_div0.

* include/ruby/util.h (ruby_div0): moved from marshal.c.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@23575 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2009-05-26 04:58:15 +00:00
nobu 22cde7b682 * dir.c, dln.c, parse.y, re.c, ruby.c, sprintf.c, strftime.c,
string.c, util.c, variable.c: use strlcpy, memcpy and snprintf
  instead of strcpy, strncpy and sprintf.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@22984 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2009-03-17 01:29:17 +00:00