Commit graph

317 commits

Author SHA1 Message Date
Hiroshi SHIBATA
32f134bb85
Added pre-release suffix for development version of default gems
https://github.com/ruby/stringio/issues/81
2024-08-31 14:22:17 +09:00
Hiroshi SHIBATA
c48e5959de
[ruby/fiddle] Removed libffi patchs for old Ruby
(https://github.com/ruby/fiddle/pull/143)

Pick
92865d8760
from `ruby/ruby` repo.

---------

aad5a3bc79

Co-authored-by: Nobuyoshi Nakada <nobu@ruby-lang.org>
2024-08-23 11:44:38 +09:00
Nobuyoshi Nakada
92865d8760 Remove files to build libffi in mswin
These files were to build libffi from the bundled source, but are no
longer used since we stopped bundling the libffi sources in commit
e4f5296f06.

The gemspec file is unchanged because fiddle gem itself still supports
ruby 2.5.
2024-07-31 11:19:52 +09:00
Aaron Patterson
0e1182f93c [ruby/fiddle] Remove Vim commands
(https://github.com/ruby/fiddle/pull/140)

Some of these commands just don't work (for example `sws` is not a Vim
setting). I think we should just remove these.

c3dbf7ba9a
2024-06-20 15:16:57 +09:00
卜部昌平
c844968b72 ruby tool/update-deps --fix 2024-04-27 21:55:28 +09:00
Masato Nakamura
e1834cdfe0
[ruby/fiddle] Set changelog_uri gem metadata
(https://github.com/ruby/fiddle/pull/138)

See https://guides.rubygems.org/specification-reference/#metadata for changelog_uri metadata.

0bd8e96adc
2024-02-08 14:43:56 +09:00
Sutou Kouhei
b4cb7ead30 [ruby/fiddle] Bump version
fd4bb4ea8a
2023-12-25 21:12:49 +09:00
Sutou Kouhei
9c2e0d49fe [ruby/fiddle] Remove garbage
bbcb66e16e
2023-11-08 09:25:45 +09:00
Sutou Kouhei
c19ea1066a [ruby/fiddle] Include stdbool.h explicitly for old Ruby
74a05fb358
2023-11-08 09:25:45 +09:00
Sutou Kouhei
2a6d6d3d65 [ruby/fiddle] Use Ruby's true/false for C bool
GitHub: fix https://github.com/ruby/fiddle/pull/130

Reported by Benoit Daloze. Thanks!!!

2640e0148e
2023-11-08 09:25:44 +09:00
Nobuyoshi Nakada
5c94f3fe9d [ruby/fiddle] Suppress -Wundef warnings on arm64 macOS and Windows
(https://github.com/ruby/fiddle/pull/134)

```
In file included from ../../../../ext/fiddle/fiddle.h:46:
/opt/local/include/ffi.h:477:5: warning: 'FFI_GO_CLOSURES' is not defined, evaluates to 0 [-Wundef]
    ^
```

c.f. https://github.com/libffi/libffi/pull/796

d4feb57098
2023-09-17 22:42:50 +09:00
卜部昌平
12ec1fb2b1 use configure-detected sanity of _Alignof
This is actually already checked in (Ruby's) configure.
2023-08-25 17:27:53 +09:00
Sutou Kouhei
fe25527781 [ruby/fiddle] Include stdbool.h explicitly
c313a74632
2023-08-02 18:17:20 +09:00
Sutou Kouhei
673f4493b0 [ruby/fiddle] Include stdbool.h explicitly
69ff680bf6
2023-08-02 18:17:19 +09:00
Sutou Kouhei
15e8cf7ad9 [ruby/fiddle] Add support for bool
GitHub: fix https://github.com/ruby/fiddle/pull/130

Reported by Benoit Daloze. Thanks!!!

bc6c66bbb9
2023-08-02 18:17:18 +09:00
Sutou Kouhei
10588fa121 [ruby/fiddle] Use ifdef
6cdf53726d
2023-08-02 18:17:16 +09:00
Jean byroot Boussier
f1313caec1 [ruby/fiddle] Mark Closure, Function and Handle as write barrier
protected
(https://github.com/ruby/fiddle/pull/129)

They don't have a mark function, so they don't need any change.

9bbc732aef

Co-authored-by: Jean Boussier <jean.boussier@gmail.com>
2023-06-28 16:36:53 +09:00
Jean byroot Boussier
135d5fa36c [ruby/fiddle] Implement write barriers for Fiddle::Pointer
(https://github.com/ruby/fiddle/pull/127)

Save from having to mark them on every minor.

153c09c99f

Co-authored-by: Jean Boussier <jean.boussier@gmail.com>
2023-06-28 16:36:52 +09:00
Sutou Kouhei
572b432e50 [ruby/fiddle] Fix a typo
4c0c5da1a5
2023-06-28 16:36:52 +09:00
Sutou Kouhei
02661f5e9b [ruby/fiddle] Add support for converting "C" (one character string) to char
GitHub: fix https://github.com/ruby/fiddle/pull/96

I wanted to add a test for this but I couldn't find a function that
has a "char" argument in libc...

Reported by kojix2. Thanks!!!

2c863ef8ba
2023-06-28 16:36:51 +09:00
Sutou Kouhei
731d27729b [ruby/fiddle] Add support for more "short" variants
2b22bb9d74
2023-06-28 16:36:50 +09:00
Sutou Kouhei
ebf14d01ba [ruby/fiddle] Add support for "long" variants
GitHub: fix https://github.com/ruby/fiddle/pull/100

Reported by David M. Lary. Thanks!!!

516333dd78
2023-06-28 16:36:50 +09:00
Aaron Patterson
85937f3a0a [ruby/fiddle] Add a helper method for reading/writing memory
(https://github.com/ruby/fiddle/pull/123)

This commit adds two new methods, `Fiddle::Pointer.read` and
`Fiddle::Pointer.write`. Both methods take an address, and will read or
write bytes at that address respectively.

For example we can read from an address without making a Pointer object:

```ruby
Fiddle::Pointer.read(address, 5) # read 5 bytes
```

We can also write to an address without allocating a Pointer object:

```ruby
Fiddle::Pointer.write(address, "bytes") # write 5 bytes
```

This allows us to read / write memory at arbitrary addresses without
instantiating a new `Fiddle::Pointer` object.

Examples where this API would be useful
[1](f03481d28b/lib/tenderjit/fiddle_hacks.rb (L26-L28))
[2](77c8daa2d4/lib/ruby_vm/rjit/c_pointer.rb (L193))
[3](77c8daa2d4/lib/ruby_vm/rjit/c_pointer.rb (L284))

I also added a writer method for the same reasons as the reader.

---------

04238cefed

Co-authored-by: Sutou Kouhei <kou@clear-code.com>
2023-06-28 16:36:49 +09:00
Matt Valentine-House
5e4b80177e Update the depend files 2023-02-28 09:09:00 -08:00
Matt Valentine-House
f38c6552f9 Remove intern/gc.h from Make deps 2023-02-27 10:11:56 -08:00
Hiroshi SHIBATA
db0a4c8923 Prefer to use File.foreach instead of IO.foreach 2023-02-27 18:49:18 +09:00
Hiroshi SHIBATA
d063ed12af Prefer to use File.binwrite instead of IO.binwrite 2023-02-27 18:49:18 +09:00
Hiroshi SHIBATA
6dfdc7b28e Prefer to use File.binread instead of IO.binread 2023-02-27 18:49:18 +09:00
Nobuyoshi Nakada
899ea35035
Extract include/ruby/internal/attr/packed_struct.h
Split `PACKED_STRUCT` and `PACKED_STRUCT_UNALIGNED` macros into the
macros bellow:
* `RBIMPL_ATTR_PACKED_STRUCT_BEGIN`
* `RBIMPL_ATTR_PACKED_STRUCT_END`
* `RBIMPL_ATTR_PACKED_STRUCT_UNALIGNED_BEGIN`
* `RBIMPL_ATTR_PACKED_STRUCT_UNALIGNED_END`
2023-02-08 12:34:13 +09:00
Khem Raj
f49bb1505b
[ruby/fiddle] fiddle: Use C11 _Alignof to define ALIGN_OF when
possible
(https://github.com/ruby/fiddle/pull/120)

WG14 N2350 made very clear that it is an UB having type definitions
within "offsetof" [1]. This patch enhances the implementation of macro
ALIGN_OF to use builtin "_Alignof" to avoid undefined behavior when
using std=c11 or newer

clang 16+ has started to flag this [2]

Fixes build when using -std >= gnu11 and using clang16+

Older compilers gcc < 4.9 or clang < 8 has buggy _Alignof even though it
may support C11, exclude those compiler versions

[1] https://www.open-std.org/jtc1/sc22/wg14/www/docs/n2350.htm
[2] https://reviews.llvm.org/D133574

Signed-off-by: Khem Raj <raj.khem@gmail.com>

ad6c9aa826
2023-01-27 11:30:13 +09:00
Aaron Patterson
f4609b6bc4
[ruby/fiddle] Fix comment formatting
36b2432575
2023-01-27 11:30:13 +09:00
Aaron Patterson
1df7f359d1
[ruby/fiddle] Update documentation
(https://github.com/ruby/fiddle/pull/119)

The documentation for `Fiddle.dlwrap` and `Fiddle.dlunwrap` were not
very accurate and pretty confusing. This commit updates the
documentation so it's easier to understand what the methods do.
2023-01-27 11:30:13 +09:00
Mau Magnaguagno
8df574a492 [ruby/fiddle] Prefer String#unpack1 in Fiddle::ValueUtil
(https://github.com/ruby/fiddle/pull/118)

String#unpack1 is available since Ruby 2.4, and support for older than
Ruby 2.5 was dropped by #85.
Also simplified a common return statement.
2022-12-26 15:09:21 +09:00
Sutou Kouhei
1dc8c18b72 [ruby/fiddle] Bump version
3033266902
2022-12-26 15:09:21 +09:00
Hiroshi SHIBATA
286812bcf3 Merge fiddle-1.1.1 2022-12-09 16:36:22 +09:00
Aaron Patterson
dffca50bb6 [ruby/fiddle] Free closures immediately
(https://github.com/ruby/fiddle/pull/109)

These structs don't need to be freed as part of finalization, so lets
free them immediately.

8a10ec1152
2022-10-18 17:21:45 +09:00
Sutou Kouhei
e84ea4af69 [ruby/fiddle] Add support for linker script on Linux
GitHub: fix https://github.com/ruby/fiddle/pull/107

Reported by nicholas a. evans. Thanks!!!

49ea1490df
2022-10-18 17:21:45 +09:00
Sutou Kouhei
08ec656282 [ruby/fiddle] Bump version 2022-10-18 17:21:45 +09:00
Nobuyoshi Nakada
091e3522d7 fiddle: use the old rb_ary_tmp_new() alias
Fiddle is a gem and has the external upstream which supports older
versions of Ruby.
2022-10-18 17:21:45 +09:00
Hiroshi SHIBATA
4f78560cf1
Add --with-libffi-source-dir feature and removed --enable-bundled-libffi option. (#113)
https://bugs.ruby-lang.org/issues/18571

Co-authored-by: Nobuyoshi Nakada <nobu@ruby-lang.org>
Co-authored-by: Sutou Kouhei <kou@clear-code.com>
2022-10-07 15:20:11 +09:00
Sutou Kouhei
ada9f8a9f7 [ruby/fiddle] closure: follow variable name change
GitHub: GH-102

2530496602
2022-10-07 15:18:54 +09:00
Sutou Kouhei
a4ad6bd9aa [ruby/fiddle] closure: free resources when an exception is raised in Closure.new
GitHub: GH-102

81a8a56239
2022-10-07 15:18:53 +09:00
Sutou Kouhei
255e617bc3 [ruby/fiddle] Add Fiddle::Closure.create and Fiddle::Closure.free
GitHub: fix GH-102

It's for freeing a closure explicitly.

We can't use Fiddle::Closure before we fork the process. If we do it,
the process may be crashed with SELinux.

See https://github.com/ruby/fiddle/issues/102#issuecomment-1241763091
for details.

Reported by Vít Ondruch. Thanks!!!

a0ccc6bb1b
2022-10-07 15:18:51 +09:00
Aaron Patterson
0097c7f388 [ruby/fiddle] Add sym_defined? methods to test if a symbol is defined (https://github.com/ruby/fiddle/pull/108)
I would like to check if a symbol is defined before trying to access it.
Some symbols aren't available on all platforms, so instead of raising an
exception, I want to check if it's defined first.

Today we have to do:

```ruby
begin
  addr = Fiddle::Handle.sym("something")
  # do something
rescue Fiddle::DLError
end
```

I want to write this:

```ruby
if Fiddle::Handle.sym_defined?("something")
  addr = Fiddle::Handle.sym("something")
  # do something
end
```

9d3371de13

Co-authored-by: Sutou Kouhei <kou@clear-code.com>
2022-10-07 15:18:51 +09:00
Aaron Patterson
755d99e878 [ruby/fiddle] Move "type" constants to Fiddle::Types (https://github.com/ruby/fiddle/pull/112)
This helps to reduce repetition in code. Instead of doing "TYPE_*"
everywhere, you can do `include Fiddle::Types`, and write the type name
directly.

This PR is to help reduce repetition when writing Fiddle code. Right now
we have to type `TYPE_` everywhere, and you also have to include all of
`Fiddle` to access `TYPE_*` constants. With this change, you can just
include `Fiddle::Types` and it will shorten your code and also you only
have to include those constants.

Here is an example before:

```ruby
require "fiddle"

module MMAP
  # All Fiddle constants included
  include Fiddle

  def self.make_function name, args, ret
    ptr = Handle::DEFAULT[name]
    func = Function.new ptr, args, ret, name: name
    define_singleton_method name, &func.to_proc
  end

  make_function "munmap", [TYPE_VOIDP, # addr
                           TYPE_SIZE_T], # len
                           TYPE_INT

  make_function "mmap", [TYPE_VOIDP,
                         TYPE_SIZE_T,
                         TYPE_INT,
                         TYPE_INT,
                         TYPE_INT,
                         TYPE_INT], TYPE_VOIDP

  make_function "mprotect", [TYPE_VOIDP, TYPE_SIZE_T, TYPE_INT], TYPE_INT
end
```

After:

```ruby
require "fiddle"

module MMAP
  # Only type names included
  include Fiddle::Types

  def self.make_function name, args, ret
    ptr = Fiddle::Handle::DEFAULT[name]
    func = Fiddle::Function.new ptr, args, ret, name: name
    define_singleton_method name, &func.to_proc
  end

  make_function "munmap", [VOIDP, # addr
                           SIZE_T], # len
                           INT

  make_function "mmap", [VOIDP, SIZE_T, INT, INT, INT, INT], VOIDP

  make_function "mprotect", [VOIDP, SIZE_T, INT], INT
end
```

We only need to import the type names, and you don't have to type
`TYPE_` over and over. I think this makes Fiddle code easier to read.

49fa7233e5

Co-authored-by: Sutou Kouhei <kou@clear-code.com>
2022-10-07 15:18:50 +09:00
Aaron Patterson
48a6498406 [ruby/fiddle] Add constants for unsigned values (https://github.com/ruby/fiddle/pull/111)
This commit adds constants for unsigned values. Currently we can use `-`
to mean "unsigned", but I think having a specific name makes Fiddle more
user friendly. This commit continues to support `-`, but introduces
negative constants with "unsigned" names

I think this will help to eliminate [this
code](3a56bf0bcc/lib/mjit/c_type.rb (L31-L38))

2bef0f1082

Co-authored-by: Sutou Kouhei <kou@clear-code.com>
2022-10-07 15:18:49 +09:00
Takashi Kokubun
106744107b
[ruby/fiddle] Fix PACK_MAP for unsigned types (https://github.com/ruby/fiddle/pull/110)
4a71246645
2022-09-11 15:30:49 +09:00
Nobuyoshi Nakada
e4f5296f06
No longer bundle external library sources 2022-09-09 01:33:53 +09:00
Peter Zhu
efb91ff19b Rename rb_ary_tmp_new to rb_ary_hidden_new
rb_ary_tmp_new suggests that the array is temporary in some way, but
that's not true, it just creates an array that's hidden and not on the
transient heap. This commit renames it to rb_ary_hidden_new.
2022-07-26 09:12:09 -04:00
Peter Zhu
2d5ecd60a5 [Feature #18249] Update dependencies 2022-02-22 09:55:21 -05:00