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

281 Коммитов

Автор SHA1 Сообщение Дата
Nobuyoshi Nakada 49fcd33e13 Introduce a specialize instruction for Array#pack
Instructions for this code:

```ruby
  # frozen_string_literal: true

[a].pack("C")
```

Before this commit:

```
== disasm: #<ISeq:<main>@test.rb:1 (1,0)-(3,13)>
0000 putself                                                          (   3)[Li]
0001 opt_send_without_block                 <calldata!mid:a, argc:0, FCALL|VCALL|ARGS_SIMPLE>
0003 newarray                               1
0005 putobject                              "C"
0007 opt_send_without_block                 <calldata!mid:pack, argc:1, ARGS_SIMPLE>
0009 leave
```

After this commit:

```
== disasm: #<ISeq:<main>@test.rb:1 (1,0)-(3,13)>
0000 putself                                                          (   3)[Li]
0001 opt_send_without_block                 <calldata!mid:a, argc:0, FCALL|VCALL|ARGS_SIMPLE>
0003 putobject                              "C"
0005 opt_newarray_send                      2, :pack
0008 leave
```

Co-authored-by: Maxime Chevalier-Boisvert <maxime.chevalierboisvert@shopify.com>
Co-authored-by: Aaron Patterson <tenderlove@ruby-lang.org>
2024-05-23 12:11:50 -07:00
Nobuyoshi Nakada 232e401b0f Reuse `natstr` if it equals `endstr` 2023-10-06 16:33:44 +09:00
Nobuyoshi Nakada f36178006b
Fix a typo in BUG message [ci skip] 2023-01-20 00:20:27 +09:00
Peter Zhu 29a5fcd60b Add RBIMPL_ATTR_NORETURN to unknown_directive
Fixes a compiler warning about the function unknown_directive:

pack.c:160:1: warning: function 'unknown_directive' could be declared with attribute 'noreturn' [-Wmissing-noreturn]
2023-01-05 14:55:14 -05:00
Benoit Daloze 03dd37775a Raise an ArgumentError for unknown pack/unpack directive
* [Bug #19150]
2023-01-05 19:05:03 +01:00
Yusuke Endoh ee7a338d2b Unconditionally warn "unknown pack/unpack directive"
[Bug #19150]
2022-12-16 12:15:50 +01:00
Nobuyoshi Nakada 9869bd1d61 [Bug #19108] Check for the encoding of pack/unpack format 2022-12-01 17:38:33 +09:00
Jeremy Evans 1340195e79 Reduce duplication in pack by sharing code for some cases
s/S, i/I, l/L, and q/Q had the same code in both cases, so
combine the cases.

Alternatively, we could actually the size of the unsigned type,
but I doubt there are any platforms where the unsigned type is
a different size than the signed type.
2022-11-24 14:27:19 -08:00
Nobuyoshi Nakada 20b9d7b9fd
Use `enum` over `int` 2022-11-22 14:20:45 +09:00
Jemma Issroff 199b59f065 Fix bug in array pack with shared strings
If string literals are long and they become shared, we need to make them
independent before we can write to them. [Bug #19116]
2022-11-10 09:26:37 -05:00
Takashi Kokubun 5b21e94beb Expand tabs [ci skip]
[Misc #18891]
2022-07-21 09:42:04 -07:00
Jean Boussier e5319dc985 pack.c: add an offset argument to unpack and unpack1
[Feature #18254]

This is useful to avoid repeteadly copying strings when parsing binary formats
2021-10-26 22:27:30 +02:00
Nobuyoshi Nakada b69c38e62e Refactor associated pointer 2021-10-24 17:50:35 +09:00
Nobuyoshi Nakada 4446942f1a
Extract UNPACK_FETCH 2021-10-22 12:47:34 +09:00
Nobuyoshi Nakada c38c2d8ee2 Moved exported symbols in internal/util.h to ruby/util.h
[Feature #18051]
2021-08-24 10:37:41 +09:00
Nobuyoshi Nakada eec45a93ef
Escape unprintable chars only, without surrounding quotes 2021-07-24 14:31:41 +09:00
卜部昌平 ff30358d13 RARRAY_AREF: convert into an inline function
RARRAY_AREF has been a macro for reasons.  We might not be able to
change that for public APIs, but why not relax the situation internally
to make it an inline function.
2020-08-15 12:09:26 +09:00
卜部昌平 9e41a75255 sed -i 's|ruby/impl|ruby/internal|'
To fix build failures.
2020-05-11 09:24:08 +09:00
卜部昌平 d7f4d732c1 sed -i s|ruby/3|ruby/impl|g
This shall fix compile errors.
2020-05-11 09:24:08 +09:00
卜部昌平 9e6e39c351
Merge pull request #2991 from shyouhei/ruby.h
Split ruby.h
2020-04-08 13:28:13 +09:00
Nobuyoshi Nakada d7bef803ac Separate builtin initialization calls 2019-12-29 12:34:55 +09:00
卜部昌平 5e22f873ed decouple internal.h headers
Saves comitters' daily life by avoid #include-ing everything from
internal.h to make each file do so instead.  This would significantly
speed up incremental builds.

We take the following inclusion order in this changeset:

1.  "ruby/config.h", where _GNU_SOURCE is defined (must be the very
    first thing among everything).
2.  RUBY_EXTCONF_H if any.
3.  Standard C headers, sorted alphabetically.
4.  Other system headers, maybe guarded by #ifdef
5.  Everything else, sorted alphabetically.

Exceptions are those win32-related headers, which tend not be self-
containing (headers have inclusion order dependencies).
2019-12-26 20:45:12 +09:00
Jeremy Evans ffd0820ab3 Deprecate taint/trust and related methods, and make the methods no-ops
This removes the related tests, and puts the related specs behind
version guards.  This affects all code in lib, including some
libraries that may want to support older versions of Ruby.
2019-11-18 01:00:25 +02:00
Koichi Sasada 3a408aff57 try to remove vm_core.h 2019-11-14 01:48:08 +09:00
Kazuhiro NISHIYAMA 00d56bdf66
Try to fix error on solaris
Add vm_core.h before builtin.h to pack.c for VM_CORE_H_EC_DEFINED.

https://rubyci.org/logs/rubyci.s3.amazonaws.com/solaris11s-sunc/ruby-master/log/20191112T102505Z.fail.html.gz
```
compiling dmyenc.c
linking miniruby
Undefined			first referenced
 symbol  			    in file
rb_vm_lvar_exposed                  pack.o
ld: fatal: symbol referencing errors
gmake: *** [miniruby] Error 2
```
2019-11-13 09:58:20 +09:00
Yusuke Endoh a3141e3c76 Rubified the APIs of pack.c 2019-11-08 23:51:51 +09:00
iain barnett 789776be08
Added some examples to the documentation for String#unpack1 because
there are currently no examples and to contrast with String#unpack.
2019-08-09 17:06:07 -07:00
Jeremy Evans 2f6cc00338 Fix documentation for Array#pack m directive count specifier [ci skip]
Fixes [Bug #10025]
2019-07-22 12:06:41 -07:00
nobu de0ef1a9df [DOC] fix markups [ci skip]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67354 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-03-28 03:33:35 +00:00
shyouhei ffd9a7ea27 pack.c: cast from double to float can be undefined
Generally speaking, a value of double is not always representable
when demoted to a float. ISO C defines what to do when such
conversion loses precision, but leaves it undefined when the
value is completely out of range. (cf: ISO/IEC 9899:1990 section
6.2.1.4).

Because ruby do not have half-precision floating-point types this
is not a frequent headache but for pack / unpack, there are
specifiers that has something to do with C float types.  We have
to explicitly care these situations.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65768 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-11-16 09:04:34 +00:00
nobu 027cf467a4 pack.c: refine warning
* pack.c (unknown_directive): refine warning message at unknown
  directive in unpack too, and quote unprintable characters.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65748 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-11-16 00:25:54 +00:00
nobu 6a6d03791b pack.c: adjust indent [ci skip]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65747 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-11-16 00:25:53 +00:00
svn db514e054b * expand tabs.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-10-17 15:03:11 +00:00
nagachika 4989bad438 infect taint flag on Array#pack and String#unpack
with the directives "B", "b", "H" and "h".

	* pack.c (pack_pack, pack_unpack_internal): infect taint flag.

	* test/ruby/test_pack.rb: add test for above.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65125 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-10-17 15:03:10 +00:00
nobu 97e05dad7f UNREACHABLE_RETURN
* include/ruby/ruby.h (UNREACHABLE_RETURN): UNREACHABLE at the end
  of non-void functions.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64025 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-07-24 05:38:07 +00:00
naruse 3a5d1e4b77 pack/unpack M only handles LF line breaks [Feature #14352]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63191 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-04-19 07:28:40 +00:00
nobu d02b7bd864 pack.c: fix underflow
* pack.c (pack_unpack_internal): get rid of underflow.
  https://hackerone.com/reports/298246

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62992 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-03-28 10:12:17 +00:00
nobu e9cb552ec9 internal.h: remove dependecy on ruby/encoding.h
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61713 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-01-09 06:24:11 +00:00
ngoto 504842d81f Workaround for optimization bug of Oracle Developer Studio 12.4-12.6
* pack.c (pack_unpack, AVOID_CC_BUG): Very ugly workaround for
  optimization bug of Oracle Developer Studio (Oracle Solaris Studio)
  12.4, 12.5, and 12.6 on Solaris 10 with -xO4 optimization option.
  [Bug #11684] [ruby-core:84351]


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61344 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-12-19 16:55:08 +00:00
nobu d35b5a4726 pack.c: unpack "M" may be ASCII only
* pack.c (pack_unpack_internal): set ASCII only properly on "M",
  may be ASCII only.  [ruby-core:83055] [Bug #13949]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60059 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-09-29 08:00:47 +00:00
ngoto f687a147eb Workaround for optimization bug of Oracle Solaris Studio 12.4 and 12.5
* pack.c (pack_unpack, AVOID_CC_BUG): Very ugly workaround for
  optimization bug of Oracle Solaris Studio 12.4 and 12.5
  (Oracle Developer Studio 12.5) on Solaris with -xO4 optimization
  option. [Bug #11684] [ruby-core:80690]


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58358 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-04-14 19:12:51 +00:00
nobu 556a1352e4 backward.h: 2.2 deprecated features
* include/ruby/backward.h (DECLARE_DEPRECATED_FEATURE): move
  features deprecated at 2.2.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57671 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-02-21 05:17:41 +00:00
nobu 6877de73de DEPRECATED_INTERNAL_FEATURE
* error.c (ruby_deprecated_internal_feature): renamed, to
  explicitly represent deprecation.

* internal.h (DEPRECATED_INTERNAL_FEATURE): ditto.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57643 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-02-17 05:45:44 +00:00
rhe b65b41861f pack.c: avoid returning uninitialized String
Fix unpacking with 'b', 'B', 'h' and 'H' format. Do not return an
uninitialized String to Ruby before filling the content bytes.
Fixes r11175 ("pack.c (pack_unpack): execute block if given with
unpacked value instead of creating an array", 2006-10-15).
[ruby-core:78841] [Bug #13075]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57187 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-12-26 06:32:00 +00:00
naruse 7e1b5d8d4f Remove unused variable
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56960 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-12-01 17:43:41 +00:00
naruse 306f43acfe String#unpack1 [Feature #12752]
Returns the first value of String#unpack.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56959 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-12-01 14:18:32 +00:00
usa b6e137e93c Remove `offset:` from `Array#pack`
* pack.c (pack_pack): can use `@` instead of `offset:`.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56958 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-12-01 13:20:47 +00:00
usa 0dd9c302d9 Supports `buffer` and `offset` in `Array#pack`
* pack.c (pack_pack): Supports `buffer` and `offset` in `Array#pack`.
  [Feature #12754] [ruby-dev:49798]


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56957 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-12-01 13:08:20 +00:00
nobu 0913d67f5d pack.c: simplify
* pack.c (str_associate): remove unnecessary branch.
  the argument must be a plain vanilla string object.

* pack.c (str_associated): use rb_ivar_lookup to give the
  undefined value.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56740 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-11-12 06:12:13 +00:00
akr 58206933b4 [DOC] table format refined.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56488 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-10-25 03:48:23 +00:00