mirror of
				https://github.com/ruby/ruby.git
				synced 2022-11-09 12:17:21 -05:00 
			
		
		
		
	bugfix.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@2542 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
		
							parent
							
								
									5c1bdda10c
								
							
						
					
					
						commit
						ceade7b926
					
				
					 3 changed files with 19 additions and 1 deletions
				
			
		| 
						 | 
				
			
			@ -59,6 +59,18 @@ to wrap the given PtrData object which is, for example, created by DL::malloc().
 | 
			
		|||
DL::malloc() is a function to allocate a memory by using the C library function
 | 
			
		||||
malloc().
 | 
			
		||||
 | 
			
		||||
We can define a callback using the module function "callback" as follows:
 | 
			
		||||
 | 
			
		||||
  module Foo
 | 
			
		||||
    extend DL::Importable
 | 
			
		||||
    def my_comp(str1,str2)
 | 
			
		||||
      str1 <=> str2
 | 
			
		||||
    end
 | 
			
		||||
    COMPARE = callback "int my_comp(char*,char*)"
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
where Foo::COMPARE is a Symbol object which invokes the method "my_comp".
 | 
			
		||||
 | 
			
		||||
DL::Importable module is very useful. However, we sometimes encounter a case
 | 
			
		||||
that we must directly use low-level functions such as dlsym(). In such case,
 | 
			
		||||
we would use DL module functions. They are described in next section.
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -88,6 +88,7 @@ module DL
 | 
			
		|||
      ["long",   "L", nil, nil, nil, nil],
 | 
			
		||||
      ["float",  "F", nil, nil, nil, nil],
 | 
			
		||||
      ["double", "D", nil, nil, nil, nil],
 | 
			
		||||
      [/char\s*\*/,"S",nil, nil, nil, nil],
 | 
			
		||||
      [/.+\*/,   "P", nil, nil, nil, nil],
 | 
			
		||||
      [/.+\[\]/, "a", nil, nil, nil, nil],
 | 
			
		||||
      ["void",   "0", nil, nil, nil, nil],
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -35,6 +35,11 @@ module LIBC
 | 
			
		|||
    "int tz_minuteswest",
 | 
			
		||||
    "int tz_dsttime",
 | 
			
		||||
  ]
 | 
			
		||||
 | 
			
		||||
  def my_compare(ptr1, ptr2)
 | 
			
		||||
    ptr1.ptr.to_s <=> ptr2.ptr.to_s
 | 
			
		||||
  end
 | 
			
		||||
  COMPARE = callback "int my_compare(char**, char**)"
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -54,7 +59,7 @@ p LIBC.strcat("a", "b")
 | 
			
		|||
 | 
			
		||||
ary = ["a","c","b"]
 | 
			
		||||
ptr = ary.to_ptr
 | 
			
		||||
LIBC.qsort(ptr, ary.length, DL.sizeof('P'), $cb1)
 | 
			
		||||
LIBC.qsort(ptr, ary.length, DL.sizeof('P'), LIBC::COMPARE)
 | 
			
		||||
p ptr.to_a('S', ary.length)
 | 
			
		||||
 | 
			
		||||
tv = LIBC::Timeval.malloc
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue