diff options
| author | Nobuyoshi Nakada <nobu@ruby-lang.org> | 2025-12-08 13:09:30 +0900 |
|---|---|---|
| committer | Nobuyoshi Nakada <nobu@ruby-lang.org> | 2026-04-12 16:51:29 +0900 |
| commit | b66b5008161bb9836d40729d0f070197c54fd5a3 (patch) | |
| tree | 6a4e2b96afeef80288ba5ec9bc3c027d952641c7 | |
| parent | 4affbf79ba624fe6861f955593dd0fe54b0a62a9 (diff) | |
Remove postponed job APIs deprecated for 2 years
| -rw-r--r-- | ext/-test-/postponed_job/postponed_job.c | 80 | ||||
| -rw-r--r-- | include/ruby/debug.h | 53 | ||||
| -rw-r--r-- | test/-ext-/postponed_job/test_postponed_job.rb | 35 | ||||
| -rw-r--r-- | vm_trace.c | 27 |
4 files changed, 0 insertions, 195 deletions
diff --git a/ext/-test-/postponed_job/postponed_job.c b/ext/-test-/postponed_job/postponed_job.c index 9ac866ae77..4426fc3104 100644 --- a/ext/-test-/postponed_job/postponed_job.c +++ b/ext/-test-/postponed_job/postponed_job.c @@ -36,38 +36,6 @@ pjob_callback(void *data) } static VALUE -pjob_register(VALUE self, VALUE obj) -{ - counter = 0; - rb_postponed_job_register(0, pjob_callback, (void *)obj); - rb_gc_start(); - counter++; - rb_gc_start(); - counter++; - rb_gc_start(); - counter++; - return self; -} - -static void -pjob_one_callback(void *data) -{ - VALUE ary = (VALUE)data; - Check_Type(ary, T_ARRAY); - - rb_ary_push(ary, INT2FIX(1)); -} - -static VALUE -pjob_register_one(VALUE self, VALUE obj) -{ - rb_postponed_job_register_one(0, pjob_one_callback, (void *)obj); - rb_postponed_job_register_one(0, pjob_one_callback, (void *)obj); - rb_postponed_job_register_one(0, pjob_one_callback, (void *)obj); - return self; -} - -static VALUE pjob_call_direct(VALUE self, VALUE obj) { counter = 0; @@ -83,48 +51,6 @@ pjob_call_direct(VALUE self, VALUE obj) static void pjob_noop_callback(void *data) { } -static VALUE -pjob_register_one_same(VALUE self) -{ - rb_gc_start(); - int r1 = rb_postponed_job_register_one(0, pjob_noop_callback, NULL); - int r2 = rb_postponed_job_register_one(0, pjob_noop_callback, NULL); - int r3 = rb_postponed_job_register_one(0, pjob_noop_callback, NULL); - VALUE ary = rb_ary_new(); - rb_ary_push(ary, INT2FIX(r1)); - rb_ary_push(ary, INT2FIX(r2)); - rb_ary_push(ary, INT2FIX(r3)); - return ary; -} - -#ifdef HAVE_PTHREAD_H -#include <pthread.h> - -static void * -pjob_register_in_c_thread_i(void *obj) -{ - rb_postponed_job_register_one(0, pjob_one_callback, (void *)obj); - rb_postponed_job_register_one(0, pjob_one_callback, (void *)obj); - rb_postponed_job_register_one(0, pjob_one_callback, (void *)obj); - return NULL; -} - -static VALUE -pjob_register_in_c_thread(VALUE self, VALUE obj) -{ - pthread_t thread; - if (pthread_create(&thread, NULL, pjob_register_in_c_thread_i, (void *)obj)) { - return Qfalse; - } - - if (pthread_join(thread, NULL)) { - return Qfalse; - } - - return Qtrue; -} -#endif - static void pjob_preregistered_callback(void *data) { @@ -216,13 +142,7 @@ void Init_postponed_job(VALUE self) { VALUE mBug = rb_define_module("Bug"); - rb_define_module_function(mBug, "postponed_job_register", pjob_register, 1); - rb_define_module_function(mBug, "postponed_job_register_one", pjob_register_one, 1); rb_define_module_function(mBug, "postponed_job_call_direct", pjob_call_direct, 1); - rb_define_module_function(mBug, "postponed_job_register_one_same", pjob_register_one_same, 0); -#ifdef HAVE_PTHREAD_H - rb_define_module_function(mBug, "postponed_job_register_in_c_thread", pjob_register_in_c_thread, 1); -#endif rb_define_module_function(mBug, "postponed_job_preregister_and_call_with_sleep", pjob_preregister_and_call_with_sleep, 1); rb_define_module_function(mBug, "postponed_job_preregister_and_call_without_sleep", pjob_preregister_and_call_without_sleep, 1); rb_define_module_function(mBug, "postponed_job_preregister_multiple_times", pjob_preregister_multiple_times, 0); diff --git a/include/ruby/debug.h b/include/ruby/debug.h index 547d5d94c4..27a7a5f2c1 100644 --- a/include/ruby/debug.h +++ b/include/ruby/debug.h @@ -754,59 +754,6 @@ rb_postponed_job_handle_t rb_postponed_job_preregister(unsigned int flags, rb_po */ void rb_postponed_job_trigger(rb_postponed_job_handle_t h); -/** - * Schedules the given `func` to be called with `data` when Ruby next checks for - * interrupts. If this function is called multiple times in between Ruby checking - * for interrupts, then `func` will be called only once with the `data` value from - * the first call to this function. - * - * Like `rb_postponed_job_trigger`, the context in which the job is called - * holds the GVL and can allocate Ruby objects. - * - * This method essentially has the same semantics as: - * - * ``` - * rb_postponed_job_trigger(rb_postponed_job_preregister(func, data)); - * ``` - * - * @note Previous versions of Ruby promised that the (`func`, `data`) pairs would - * be executed as many times as they were registered with this function; in - * reality this was always subject to race conditions and this function no - * longer provides this guarantee. Instead, multiple calls to this function - * can be coalesced into a single execution of the passed `func`, with the - * most recent `data` registered at that time passed in. - * - * @deprecated This interface implies that arbitrarily many `func`'s can be enqueued - * over the lifetime of the program, whilst in reality the registration - * slots for postponed jobs are a finite resource. This is made clearer - * by the `rb_postponed_job_preregister` and `rb_postponed_job_trigger` - * functions, and a future version of Ruby might delete this function. - * - * @param[in] flags Unused and ignored. - * @param[in] func Job body. - * @param[in,out] data Passed as-is to `func`. - * @retval 0 Postponed job registration table is full. Failed. - * @retval 1 Registration succeeded. - * @post The passed job will run on the next interrupt check. - */ - RBIMPL_ATTR_DEPRECATED(("use rb_postponed_job_preregister and rb_postponed_job_trigger")) -int rb_postponed_job_register(unsigned int flags, rb_postponed_job_func_t func, void *data); - -/** - * Identical to `rb_postponed_job_register` - * - * @deprecated This is deprecated for the same reason as `rb_postponed_job_register` - * - * @param[in] flags Unused and ignored. - * @param[in] func Job body. - * @param[in,out] data Passed as-is to `func`. - * @retval 0 Postponed job registration table is full. Failed. - * @retval 1 Registration succeeded. - * @post The passed job will run on the next interrupt check. - */ - RBIMPL_ATTR_DEPRECATED(("use rb_postponed_job_preregister and rb_postponed_job_trigger")) -int rb_postponed_job_register_one(unsigned int flags, rb_postponed_job_func_t func, void *data); - /** @} */ /** diff --git a/test/-ext-/postponed_job/test_postponed_job.rb b/test/-ext-/postponed_job/test_postponed_job.rb index 8c2b3e95d1..01d6015de1 100644 --- a/test/-ext-/postponed_job/test_postponed_job.rb +++ b/test/-ext-/postponed_job/test_postponed_job.rb @@ -33,39 +33,4 @@ class TestPostponed_job < Test::Unit::TestCase assert_equal [3, 4], values RUBY end - - def test_legacy_register - assert_separately([], __FILE__, __LINE__, <<-'RUBY') - require '-test-/postponed_job' - direct, registered = [], [] - - Bug.postponed_job_call_direct(direct) - Bug.postponed_job_register(registered) - - assert_equal([0], direct) - assert_equal([3], registered) - - Bug.postponed_job_register_one(ary = []) - assert_equal [1], ary - RUBY - end - - def test_legacy_register_one_same - assert_separately([], __FILE__, __LINE__, <<-'RUBY') - require '-test-/postponed_job' - # Registering the same job three times should result in three of the same handle - handles = Bug.postponed_job_register_one_same - assert_equal [handles[0]], handles.uniq - RUBY - end - - if Bug.respond_to?(:postponed_job_register_in_c_thread) - def test_legacy_register_in_c_thread - assert_separately([], __FILE__, __LINE__, <<-'RUBY') - require '-test-/postponed_job' - assert Bug.postponed_job_register_in_c_thread(ary = []) - assert_equal [1], ary - RUBY - end - end end diff --git a/vm_trace.c b/vm_trace.c index 42b9991e71..1a907da880 100644 --- a/vm_trace.c +++ b/vm_trace.c @@ -1921,33 +1921,6 @@ rb_postponed_job_trigger(rb_postponed_job_handle_t h) RUBY_VM_SET_POSTPONED_JOB_INTERRUPT(get_valid_ec(GET_VM())); } - -static int -pjob_register_legacy_impl(unsigned int flags, rb_postponed_job_func_t func, void *data) -{ - /* We _know_ calling preregister from a signal handler like this is racy; what is - * and is not promised is very exhaustively documented in debug.h */ - rb_postponed_job_handle_t h = rb_postponed_job_preregister(0, func, data); - if (h == POSTPONED_JOB_HANDLE_INVALID) { - return 0; - } - rb_postponed_job_trigger(h); - return 1; -} - -int -rb_postponed_job_register(unsigned int flags, rb_postponed_job_func_t func, void *data) -{ - return pjob_register_legacy_impl(flags, func, data); -} - -int -rb_postponed_job_register_one(unsigned int flags, rb_postponed_job_func_t func, void *data) -{ - return pjob_register_legacy_impl(flags, func, data); -} - - void rb_postponed_job_flush(rb_vm_t *vm) { |
