Sha256: 492feb6cca00c043e435f1bd8352e7778d459cf6c93ea52e0a70cdef7ec257d8

Contents?: true

Size: 583 Bytes

Versions: 7013

Compression:

Stored size: 583 Bytes

Contents

require 'ffi'

module LibC
  extend FFI::Library
  ffi_lib FFI::Library::LIBC
  callback :qsort_cmp, [ :pointer, :pointer ], :int
  attach_function :qsort, [ :pointer, :ulong, :ulong, :qsort_cmp ], :int
end

p = FFI::MemoryPointer.new(:int, 2)
p.put_array_of_int32(0, [ 2, 1 ])
puts "ptr=#{p.inspect}"
puts "Before qsort #{p.get_array_of_int32(0, 2).join(', ')}"
LibC.qsort(p, 2, 4) do |p1, p2|
  i1 = p1.get_int32(0)
  i2 = p2.get_int32(0)
  puts "In block: comparing #{i1} and #{i2}"
  i1 < i2 ? -1 : i1 > i2 ? 1 : 0
end
puts "After qsort #{p.get_array_of_int32(0, 2).join(', ')}"

Version data entries

7,013 entries across 7,009 versions & 39 rubygems

Version Path
cybrid_api_bank_ruby-0.123.149 vendor/bundle/ruby/3.3.0/gems/ffi-1.17.1-x86_64-linux-gnu/samples/qsort.rb
cybrid_api_id_ruby-0.123.149 vendor/bundle/ruby/3.3.0/gems/ffi-1.17.1-x86_64-linux-gnu/samples/qsort.rb
cybrid_api_organization_ruby-0.123.149 vendor/bundle/ruby/3.3.0/gems/ffi-1.17.1-x86_64-linux-gnu/samples/qsort.rb
cybrid_api_bank_ruby-0.123.148 vendor/bundle/ruby/3.3.0/gems/ffi-1.17.1-x86_64-linux-gnu/samples/qsort.rb
cybrid_api_id_ruby-0.123.148 vendor/bundle/ruby/3.3.0/gems/ffi-1.17.1-x86_64-linux-gnu/samples/qsort.rb
cybrid_api_organization_ruby-0.123.148 vendor/bundle/ruby/3.3.0/gems/ffi-1.17.1-x86_64-linux-gnu/samples/qsort.rb
cybrid_api_bank_ruby-0.123.147 vendor/bundle/ruby/3.3.0/gems/ffi-1.17.1-x86_64-linux-gnu/samples/qsort.rb
cybrid_api_organization_ruby-0.123.147 vendor/bundle/ruby/3.3.0/gems/ffi-1.17.1-x86_64-linux-gnu/samples/qsort.rb
cybrid_api_id_ruby-0.123.147 vendor/bundle/ruby/3.3.0/gems/ffi-1.17.1-x86_64-linux-gnu/samples/qsort.rb
ory-client-1.16.2 vendor/bundle/ruby/3.1.0/gems/ffi-1.17.1/samples/qsort.rb
talon_one-7.0.0 .github/.example/vendor/bundle/ruby/3.3.0/gems/ffi-1.17.0-arm64-darwin/samples/qsort.rb
cybrid_api_bank_ruby-0.123.145 vendor/bundle/ruby/3.3.0/gems/ffi-1.17.1-x86_64-linux-gnu/samples/qsort.rb
cybrid_api_organization_ruby-0.123.145 vendor/bundle/ruby/3.3.0/gems/ffi-1.17.1-x86_64-linux-gnu/samples/qsort.rb
cybrid_api_id_ruby-0.123.145 vendor/bundle/ruby/3.3.0/gems/ffi-1.17.1-x86_64-linux-gnu/samples/qsort.rb
cybrid_api_bank_ruby-0.123.144 vendor/bundle/ruby/3.3.0/gems/ffi-1.17.1-x86_64-linux-gnu/samples/qsort.rb
cybrid_api_id_ruby-0.123.144 vendor/bundle/ruby/3.3.0/gems/ffi-1.17.1-x86_64-linux-gnu/samples/qsort.rb
cybrid_api_organization_ruby-0.123.144 vendor/bundle/ruby/3.3.0/gems/ffi-1.17.1-x86_64-linux-gnu/samples/qsort.rb
ory-client-1.16.1 vendor/bundle/ruby/3.1.0/gems/ffi-1.17.1/samples/qsort.rb
ory-client-1.16.0 vendor/bundle/ruby/3.1.0/gems/ffi-1.17.1/samples/qsort.rb
cybrid_api_bank_ruby-0.123.143 vendor/bundle/ruby/3.3.0/gems/ffi-1.17.1-x86_64-linux-gnu/samples/qsort.rb