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

85 Коммитов

Автор SHA1 Сообщение Дата
Chris Seaton 3015a7aae7 [ruby/fiddle] Improve documentation on how to correctly free memory and free memory in tests (#33)
https://github.com/ruby/fiddle/commit/e59cfd708a
2020-05-23 14:34:07 +09:00
sinisterchipmunk 77cc13943c [ruby/fiddle] Fix assignment to array within struct (#26)
* Allow access to a struct's underlying memory with `struct[offset, length]`.

https://github.com/ruby/fiddle/commit/24083690a6
2020-05-23 14:29:16 +09:00
sinisterchipmunk 4a835621ce [ruby/fiddle] Make array access override compatible with base class (#25)
* Allow access to a struct's underlying memory with `struct[offset, length]`.

* Make accessing a struct's underlying memory more convenient.

* refactor memory access unit tests for improved clarity


https://github.com/ruby/fiddle/commit/c082c81bb5
2020-05-23 14:29:16 +09:00
Nobuyoshi Nakada 5a81562dfe
`Dir.glob` always returns an array
It is not needed to test itself, but the element should be tested
instead.
2020-04-01 12:48:56 +09:00
Paul Jordan 3e386d76c2 Fix helper to not assume glibc 2020-04-01 15:49:02 +13:00
Nobuyoshi Nakada 502d9bcd36
Fixed never-defined symbol name 2020-03-04 21:00:17 +09:00
卜部昌平 3b9f36d6c6 pass appropriate libc path
The same as https://github.com/ruby/ruby/pull/2686, but for musl libc.
Musl is not named as libc.so.6 so the `ldd` hack implemented some lines
below does not work.
2020-01-24 10:49:35 +09:00
Jun Aruga c0d118f41a Fix "cannot find the function: strcpy()" error on arm32 on Travis CI. (#2686)
This issue happened when `libc.so` and `libm.so` path were not found
and `ldd ruby` command also failed to print the shared dependencies
in `test/fiddle/helper.rb`.

See https://travis-ci.org/ruby/ruby/jobs/611483288#L3018
/home/travis/build/ruby/ruby/build/.ext/common/fiddle/import.rb:299:in `import_function': cannot find the function: strcpy() (Fiddle::DLError)

* Set libc6:armhf as a installing dependency explicitly.
* Remove arm32 from allow_failures.
2019-12-05 14:17:16 +09:00
Jeremy Evans ab42e5a486 More fixes for $SAFE/taint post merging 2019-11-18 01:00:25 +02: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
Hiroshi SHIBATA dc44ab2913 Revert "[ruby/fiddle] Fix a failing test (#13)"
This reverts commit 5ebb0d50f6.
2019-10-24 20:58:32 +09:00
Hiroshi SHIBATA de5ee47c3d Revert "[ruby/fiddle] test: use env Hash"
This reverts commit 4d844cbaed.
2019-10-24 20:58:32 +09:00
Jeremy Evans b809784817 [ruby/fiddle] Remove taint support (#21)
Ruby 2.7 deprecates taint and it no longer has an effect.
The lack of taint support should not cause a problem in
previous Ruby versions.
https://github.com/ruby/fiddle/commit/18d6fb6915
2019-10-24 19:34:49 +09:00
Nobuyoshi Nakada 30d46966a9 [ruby/fiddle] Use RbConfig::SIZEOF (#19)
https://github.com/ruby/fiddle/commit/ea06b28db8
2019-10-24 19:34:36 +09:00
Sutou Kouhei 4d844cbaed [ruby/fiddle] test: use env Hash
https://github.com/ruby/fiddle/commit/a01a962342
2019-10-24 19:34:29 +09:00
Kenta Murata 5ebb0d50f6 [ruby/fiddle] Fix a failing test (#13)
* Fix a failing test

This commit fixes the following failure:

```
  1) Failure:
Fiddle::TestImport#test_no_message_with_debug [/Users/mrkn/src/github.com/ruby/fiddle/test/fiddle/test_import.rb:152]:

1. [2/2] Assertion for "stderr"
   | <[]> expected but was
   | <["Exception `NameError' at /Users/mrkn/.rbenv/versions/2.5.1/lib/ruby/2.5.0/fiddle/import.rb:157 - uninitialized constant Fiddle::Function::STDCALL"]>.
```

* Stop using Bundler.with_clean_env

* Clear existing Ruby environment variables on test_no_message_with_debug

https://github.com/ruby/fiddle/commit/13133ddec8
2019-10-24 19:34:22 +09:00
Yusuke Endoh cce6cfbe48 Make test-all and test-spec runnable on Android
Calling some syscall functions such as Dir.chroot causes SIGSYS instead
of EPERM on Android.
This change skips all tests that stops the test-suite run.
2019-09-09 20:24:03 +09:00
k0kubun 9e71ce687f test/fiddle/test_function.rb: loosen timeout
We're hitting `Expected |200 - 351| (151) to be <= 150.` in several places:
https://rubyci.org/logs/rubyci.s3.amazonaws.com/osx1012/ruby-trunk/log/20181215T094505Z.fail.html.gz
https://travis-ci.org/ruby/ruby/jobs/471483171

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66503 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-12-23 01:40:33 +00:00
k0kubun 5ad8e42bef test_function.rb: loosen delta boundary
On osx build https://travis-ci.org/ruby/ruby/jobs/454309945,

```
1) Failure:
Fiddle::TestFunction#test_nogvl_poll [/Users/travis/build/ruby/ruby/test/fiddle/test_function.rb:95]:
slept amount of time.
Expected |200 - 322| (122) to be <= 100.
```

but it succeeds on my macOS machine as is. So it seems that the boundary is
just too strict and prone to random failure by overload.

To make osx Travis build usable, let me loosen the delta requirement.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65705 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-11-13 06:17:57 +00:00
k0kubun 29aa73fcec test_function.rb: try running test_nogvl_poll again
According to some runs in mjit-test (make test-all RUN_OPTS="--jit-wait"),
this test might not be the cause of its failure.

So, let me try running this again.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64426 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-08-18 02:15:41 +00:00
k0kubun 7815d7d713 test_function.rb: skip running test
that times out with test-all w/ --jit-wait.

I'm running the following command on Wecker CI everyday:
```
make test-all TESTOPTS="--color=never --job-status=normal" RUN_OPTS="--disable-gems --jit-wait --jit-warnings" RUBY_FORCE_TEST_JIT=1
```

By running yesterday's all commits, r64354 ran successfully but r64355
didn't. So the test should be fixed to run with --jit-wait at first.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64374 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-08-15 04:51:10 +00:00
normal 1e769ce6ed test/fiddle/test_function.rb (test_nogvl_poll): stop timer hack
EINTR seems unavoidable in real programs (or MJIT), so maybe
it's not worth dealing with.  r64353 relies on POSIX timers
to signal.

Switching pipes and sockets to non-blocking by default would let
us get rid of POSIX timers, timer pthread and this hack:
https://bugs.ruby-lang.org/issues/14968

[ruby-core:88360] [Misc #14937]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64355 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-08-14 00:31:31 +00:00
nobu 440f4421ee test_function.rb: fix messages
* test/fiddle/test_function.rb (test_nogvl_poll): fix messages as
  failed conditions, with errno description.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64091 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-07-28 13:06:43 +00:00
nobu 1c904182d2 removed unusecd constants
* ruby-runner.c (ruby_libm_func): removed as the following test
  actually doesn't need the path of libm.

* test/fiddle/test_pointer.rb (Fiddle::TestPointer#test_free=):
  removed never used constants and instance variables.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63957 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-07-12 02:29:57 +00:00
nobu 5a5c9a706c fiddle/test_import.rb: fix warnings by rubygems
[Bug #14686]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63206 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-04-19 23:46:55 +00:00
nobu eb02a846a4 fiddle/import.rb: suppress warning
* ext/fiddle/lib/fiddle/import.rb: suppress exception report when
  $DEBUG is enabled.  [ruby-core:86536] [Bug #14686]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63205 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-04-19 23:35:39 +00:00
shyouhei 1aaeeb326e long long is a C99ism
so SIZEOF_LONG_LONG is not always available.
We have to check its defined?-ness before using.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62450 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-02-17 09:51:23 +00:00
ko1 c39bdb798d `$SAFE` as a process global state. [Feature #14250]
* vm_core.h (rb_vm_t): move `rb_execution_context_t::safe_level` to
  `rb_vm_t::safe_level_` because `$SAFE` is a process (VM) global state.

* vm_core.h (rb_proc_t): remove `rb_proc_t::safe_level` because `Proc`
  objects don't need to keep `$SAFE` at the creation.
  Also make `is_from_method` and `is_lambda` as 1 bit fields.

* cont.c (cont_restore_thread): no need to keep `$SAFE` for Continuation.

* eval.c (ruby_cleanup): use `rb_set_safe_level_force()` instead of access
  `vm->safe_level_` directly.

* eval_jump.c: End procs `END{}` doesn't keep `$SAFE`.

* proc.c (proc_dup): removed and introduce `rb_proc_dup` in vm.c.

* safe.c (rb_set_safe_level): don't check `$SAFE` 1 -> 0 changes.

* safe.c (safe_setter): use `rb_set_safe_level()`.

* thread.c (rb_thread_safe_level): `Thread#safe_level` returns `$SAFE`.
  It should be obsolete.

* transcode.c (load_transcoder_entry): `rb_safe_level()` only returns
  0 or 1 so that this check is not needed.

* vm.c (vm_proc_create_from_captured): don't need to keep `$SAFE` for Proc.

* vm.c (rb_proc_create): renamed to `proc_create`.

* vm.c (rb_proc_dup): moved from proc.c.

* vm.c (vm_invoke_proc): do not need to set and restore `$SAFE`
  for `Proc#call`.

* vm_eval.c (rb_eval_cmd): rename a local variable to represent clearer
  meaning.

* lib/drb/drb.rb: restore `$SAFE`.

* lib/erb.rb: restore `$SAFE`, too.

* test/lib/leakchecker.rb: check `$SAFE == 0` at the end of tests.

* test/rubygems/test_gem.rb: do not set `$SAFE = 1`.

* bootstraptest/test_proc.rb: catch up this change.

* spec/ruby/optional/capi/string_spec.rb: ditto.

* test/bigdecimal/test_bigdecimal.rb: ditto.

* test/fiddle/test_func.rb: ditto.

* test/fiddle/test_handle.rb: ditto.

* test/net/imap/test_imap_response_parser.rb: ditto.

* test/pathname/test_pathname.rb: ditto.

* test/readline/test_readline.rb: ditto.

* test/ruby/test_file.rb: ditto.

* test/ruby/test_optimization.rb: ditto.

* test/ruby/test_proc.rb: ditto.

* test/ruby/test_require.rb: ditto.

* test/ruby/test_thread.rb: ditto.

* test/rubygems/test_gem_specification.rb: ditto.

* test/test_tempfile.rb: ditto.

* test/test_tmpdir.rb: ditto.

* test/win32ole/test_win32ole.rb: ditto.

* test/win32ole/test_win32ole_event.rb: ditto.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61510 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-12-28 20:09:24 +00:00
eregon 15689ed778 Fix test-all tests to avoid creating report_on_exception warnings
* The warnings are shown by Thread.report_on_exception defaulting to
  true. [Feature #14143] [ruby-core:83979]
* Improves tests by narrowing down the scope where an exception
  is expected.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61188 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-12-12 18:44:49 +00:00
ko1 3fe69a0da4 Use mutable strings for mutation tests.
* test/fiddle/test_func.rb (test_string): this test break String buffer
  by `strcpy` ("000" -> "123"). However, the string literal "000" with
  `frozen_string_literal: true` returns a string object from frozen
  string pool. So that after this test "000" from fstring pool becomes
  "123" (modified string). 'test/date/' uses "000" (as fstring) and tests
  are fails (we could check with `make test-all TESTS='fiddle date'`).

* test/fiddle/test_function.rb: ditto.

* test/fiddle/test_import.rb: ditto.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59861 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-09-12 23:15:34 +00:00
hsbt 7f24b0aabd Merge fiddle-1.0.0.beta2 from upstream.
* ext/fiddle/closure.c: use directly declaration for standalone gem
    without internal.h.
  * Specify frozen string literal is true.
  * Update gemspec configuration for release version.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59854 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-09-12 11:52:23 +00:00
hsbt 24873d1a05 Use Test::Unit::TestCase instead of MiniTest::Unit::TestCase. Because
tests of fiddle already used customized assertions of ruby core.

  * test/fiddle/helper.rb: Use Test::Unit::TestCase for base class of
    testcase.
  * test/fiddle/test_*.rb: Use assert_raise instead of assert_raises.
    Remove needless includes for Test::Unit::Assertions.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59321 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-07-13 09:46:16 +00:00
normal 5c244d73d7 test/fiddle/helper: remove special case for x86_64-linux
RUBY_PLATFORM is "x86_64-linux" on a 32-bit (x86) Ruby built and
running on a 64-bit Linux kernel.  I also have a /lib64
directory nowadays because I just installed multi-arch support
in userspace.  So, fall back to loading based in the size of a
packed "unsigned long" type instead of special-casing.

Tested with both x86 and x86_64 userspace on 64-bit Linux kernel,
as well as x86 with a 32-bit Linux kernel.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57309 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-01-11 23:46:05 +00:00
usa 836794f206 Removed the obstacle to running test-all with VC14.
* test/fiddle/test_import.rb (LIBC.fprintf): VC14's `fprintf` is very distinct
  name, then, just ignore this test.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57081 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-12-14 17:53:20 +00:00
ngoto 053c1e08e3 * test/fiddle/test_pointer.rb (test_to_str, test_to_s, test_aref_aset):
Attempt to use independent strings for destructive tests that
  directly modify values on memory by using Fiddle::Pointer.
  [Bug #12537] [ruby-dev:49700]


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@55554 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-07-01 10:43:07 +00:00
nobu 9a9d375f73 * test_handle.rb: refine test_fallback_to_ansi
* test/fiddle/test_handle.rb (test_fallback_to_ansi): ensure that
  the fallback result equals to ANSI version.
  [ruby-core:75494] [Bug #12377]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@55016 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-05-16 06:26:56 +00:00
nobu c7d11ee1ba configure.in: revert macro names
* configure.in (FUNC_STDCALL, FUNC_CDECL, FUNC_FASTCALL): set
  macro names explicitly to the old names, which are accidentally
  changed at r54985, for backward compatibilities.
  fiddle also depends on these names to fallback to ANSI names.
  [ruby-core:75494] [Bug #12377]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@55015 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-05-16 04:29:01 +00:00
nagachika 79c7a51893 * ext/fiddle/handle.c: check tainted string arguments.
Patch provided by tenderlove and nobu.

* test/fiddle/test_handle.rb (class TestHandle): add test for above.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@53153 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-12-16 12:08:49 +00:00
naruse 3e92b635fb Add frozen_string_literal: false for all files
When you change this to true, you may need to add more tests.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@53141 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-12-16 05:07:31 +00:00
normal 15476c695d fiddle: release GVL for ffi_call
Some external functions I wish to call may take a long time
and unnecessarily block other threads.  This may lead to performance
regressions for fast functions as releasing/acquiring the GVL is not
cheap, but can improve performance for long-running functions
in multi-threaded applications.

This also means we must reacquire the GVL when calling Ruby-defined
callbacks for Fiddle::Closure, meaning we must detect whether the
current thread has the GVL by exporting ruby_thread_has_gvl_p
in internal.h

* ext/fiddle/function.c (struct nogvl_ffi_call_args):
  new struct for GVL release
  (nogvl_ffi_call): new function
  (function_call): adjust for GVL release
  [ruby-core:71642] [Feature #11607]
* ext/fiddle/closure.c (struct callback_args):
  new struct for GVL acquire
  (with_gvl_callback): adjusted original callback function
  (callback): wrapper for conditional GVL acquire
* ext/fiddle/depend: add dependencies
* ext/fiddle/extconf.rb: include top_srcdir for internal.h
* internal.h (ruby_thread_has_gvl_p): expose for fiddle
* vm_core.h (ruby_thread_has_gvl_p): moved to internal.h
* test/fiddle/test_function.rb (test_nogvl_poll): new test

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52723 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-11-23 21:20:56 +00:00
naruse 8fdebec088 fix r52690
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52696 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-11-21 06:36:05 +00:00
naruse a77fb26da8 Visual C++ 14 (2015) uses ucrtbase.dll as c runtime
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52690 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-11-21 00:20:53 +00:00
nobu 0445b5f6c6 test/fiddle: revert r52384 partially
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52388 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-10-30 07:17:08 +00:00
nobu 068f312a7c use assert_raise
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52384 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-10-30 04:37:13 +00:00
hsbt 5d6ca9e950 * include/ruby/ruby.h: $SAFE=2 is now obsolete.
* dir.c, ext/fiddle/handle.c, ext/socket/basicsocket.c, file.c
  gc.c, io.c, process.c, safe.c, signal.c, win32/file.c:
  removed code for $SAFE=2
* test/erb/test_erb.rb, test/fiddle/test_handle.rb
  test/ruby/test_env.rb: removed tests for $SAFE=2.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@50958 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-06-18 14:21:03 +00:00
ko1 37360f82aa * test/fiddle/test_handle.rb: fix syntax.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@49159 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-01-05 18:11:32 +00:00
nobu 64e2406427 test_handle.rb: use -test-/dln/empty
* test/fiddle/test_handle.rb (test_NEXT): use -test-/dln/empty
  which is always a shared object and is not used by others.
  [ruby-dev:48629] [Bug #10384]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@49157 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-01-05 15:16:13 +00:00
nobu fb79364092 test_handle.rb: separate blocks
* test/fiddle/test_handle.rb (test_static_sym, test_NEXT):
  separate each rescue blocks.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@49156 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-01-05 15:15:48 +00:00
nobu 3e8687a2ad test_handle.rb: remove skips
* test/fiddle/test_handle.rb (test_static_sym, test_DEFAULT):
  remove useless skips.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@49155 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-01-05 15:15:41 +00:00
hsbt 1ba6e8868c * ext/fiddle/lib/fiddle/cparser.rb: r49110 brake Fiddle::Import with
type_alias
* test/fiddle/test_cparser.rb: added type_alias test for parse_ctype
  and parse_struct_signature.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@49119 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-01-03 09:23:43 +00:00