Skip to content

Commit

Permalink
Moved FFI under Rubinius.
Browse files Browse the repository at this point in the history
  • Loading branch information
brixen committed Dec 17, 2012
1 parent e850ba2 commit 53a0a09
Show file tree
Hide file tree
Showing 35 changed files with 90 additions and 30 deletions.
2 changes: 2 additions & 0 deletions kernel/common/complex.rb
Expand Up @@ -9,6 +9,8 @@
#

class Complex < Numeric
FFI = Rubinius::FFI

undef_method :%
undef_method :<
undef_method :<=
Expand Down
2 changes: 2 additions & 0 deletions kernel/common/dir.rb
Expand Up @@ -3,6 +3,8 @@
class Dir
include Enumerable

FFI = Rubinius::FFI

def self.[](*patterns)
if patterns.size == 1
patterns = Rubinius::Type.coerce_to_path(patterns[0]).split("\0")
Expand Down
1 change: 1 addition & 0 deletions kernel/common/errno.rb
Expand Up @@ -4,6 +4,7 @@
# Interface to the C errno integer.

module Errno
FFI = Rubinius::FFI

##
# Raises the appropriate SystemCallError exception with +additional+ as the
Expand Down
6 changes: 6 additions & 0 deletions kernel/common/file.rb
@@ -1,5 +1,6 @@
# -*- encoding: us-ascii -*-

module Rubinius
module FFI::Platform::POSIX
#--
# Internal class for accessing timevals
Expand All @@ -8,6 +9,7 @@ class TimeVal < FFI::Struct
config 'rbx.platform.timeval', :tv_sec, :tv_usec
end
end
end

class File < IO
include Enumerable
Expand Down Expand Up @@ -59,6 +61,8 @@ module Constants
FNM_CASEFOLD = 0x08
end

FFI = Rubinius::FFI

SEPARATOR = FFI::Platform::File::SEPARATOR
Separator = FFI::Platform::File::SEPARATOR
ALT_SEPARATOR = FFI::Platform::File::ALT_SEPARATOR
Expand Down Expand Up @@ -1065,6 +1069,8 @@ class IO
end

class File::Stat
FFI = Rubinius::FFI

class Struct < FFI::Struct
config "rbx.platform.stat", :st_dev, :st_ino, :st_mode, :st_nlink,
:st_uid, :st_gid, :st_rdev, :st_size, :st_blksize, :st_blocks,
Expand Down
2 changes: 2 additions & 0 deletions kernel/common/float.rb
Expand Up @@ -4,6 +4,8 @@ class Float < Numeric

include Precision

FFI = Rubinius::FFI

def self.induced_from(obj)
case obj
when Float, Bignum, Fixnum
Expand Down
1 change: 1 addition & 0 deletions kernel/common/io.rb
@@ -1,6 +1,7 @@
# -*- encoding: us-ascii -*-

class IO
FFI = Rubinius::FFI

include Enumerable

Expand Down
2 changes: 2 additions & 0 deletions kernel/common/math.rb
@@ -1,6 +1,8 @@
# -*- encoding: us-ascii -*-

module Math
FFI = Rubinius::FFI

# Constants
PI = 3.14159_26535_89793_23846
E = 2.71828_18284_59045_23536
Expand Down
2 changes: 2 additions & 0 deletions kernel/common/process.rb
Expand Up @@ -30,6 +30,8 @@ module Constants
end
include Constants

FFI = Rubinius::FFI

class Rlimit < FFI::Struct
config "rbx.platform.rlimit", :rlim_cur, :rlim_max
end
Expand Down
2 changes: 2 additions & 0 deletions kernel/delta/ffi.rb
@@ -1,5 +1,6 @@
# -*- encoding: us-ascii -*-

module Rubinius
module FFI

module Library
Expand All @@ -18,3 +19,4 @@ class InlineArray
end

end
end
2 changes: 2 additions & 0 deletions kernel/platform/enum.rb
@@ -1,5 +1,6 @@
# -*- encoding: us-ascii -*-

module Rubinius
module FFI

# Represents a C enum.
Expand Down Expand Up @@ -59,3 +60,4 @@ def symbol(value)

end
end
end
2 changes: 2 additions & 0 deletions kernel/platform/ffi.rb
Expand Up @@ -3,6 +3,7 @@
##
# A Foreign Function Interface used to bind C libraries to ruby.

module Rubinius
module FFI

# Specialised error classes
Expand Down Expand Up @@ -258,3 +259,4 @@ def self.unix?
! windows?
end
end
end
3 changes: 2 additions & 1 deletion kernel/platform/file.rb
Expand Up @@ -3,9 +3,10 @@
##
# Platform specific behavior for the File class.

module Rubinius
module FFI::Platform::File
SEPARATOR = '/'
ALT_SEPARATOR = nil
PATH_SEPARATOR = ':'
end

end
3 changes: 2 additions & 1 deletion kernel/platform/library.rb
Expand Up @@ -5,6 +5,7 @@ class Rubinius::NativeFunction
attr_accessor :argument_types
end

module Rubinius
module FFI
def self.generate_function(ptr, name, args, ret)
Rubinius.primitive :nativefunction_generate
Expand Down Expand Up @@ -405,4 +406,4 @@ def last_error
CURRENT_PROCESS = DynamicLibrary.new(nil)
end
end

end
3 changes: 2 additions & 1 deletion kernel/platform/math.rb
Expand Up @@ -3,6 +3,7 @@
##
# Platform specific behavior for Math.

module Rubinius
module FFI::Platform::Math
extend FFI::Library

Expand Down Expand Up @@ -42,4 +43,4 @@ def self.log2(x)
log10(x) / log10(2.0)
end
end

end
2 changes: 2 additions & 0 deletions kernel/platform/math19.rb
Expand Up @@ -3,8 +3,10 @@
##
# Platform specific behavior for Math in 1.9.

module Rubinius
module FFI::Platform::Math
attach_function :cbrt, [:double], :double
attach_function :tgamma, [:double], :double
attach_function :lgamma_r, [:double, :pointer], :double
end
end
3 changes: 2 additions & 1 deletion kernel/platform/pointer.rb
@@ -1,5 +1,6 @@
# -*- encoding: us-ascii -*-

module Rubinius
module FFI

##
Expand Down Expand Up @@ -443,4 +444,4 @@ def attach(mod, name)
end
end
end

end
2 changes: 2 additions & 0 deletions kernel/platform/pointer_accessors.rb
Expand Up @@ -4,6 +4,7 @@
# modified manually. Due to the vast amount of very similar
# methods in this module, it is automatically generated.

module Rubinius
module FFI
##
# This module provides accessors for various different types. It
Expand Down Expand Up @@ -836,3 +837,4 @@ def put_array_of_pointer(offset, ary)

end
end
end
3 changes: 2 additions & 1 deletion kernel/platform/posix.rb
Expand Up @@ -3,6 +3,7 @@
##
# Namespace for various POSIX functions.

module Rubinius
module FFI::Platform::POSIX
extend FFI::Library

Expand Down Expand Up @@ -116,4 +117,4 @@ module FFI::Platform::POSIX
attach_function :fstat, 'ffi_fstat', [:int, :pointer], :int
attach_function :lstat, 'ffi_lstat', [:string, :pointer], :int
end

end
3 changes: 2 additions & 1 deletion kernel/platform/struct.rb
@@ -1,5 +1,6 @@
# -*- encoding: us-ascii -*-

module Rubinius
module FFI
##
# Represents a C struct as ruby class.
Expand Down Expand Up @@ -305,4 +306,4 @@ def null?

end
end

end
3 changes: 2 additions & 1 deletion kernel/platform/union.rb
@@ -1,10 +1,11 @@
# -*- encoding: us-ascii -*-

module Rubinius
module FFI
##
# Represents a C union as ruby class.

class Union < Struct
end
end

end
4 changes: 4 additions & 0 deletions lib/19/socket.rb
Expand Up @@ -8,6 +8,7 @@ class SocketError < StandardError
# @todo UDPSocket#recvfrom

class BasicSocket < IO
FFI = Rubinius::FFI

class << self
def from_descriptor(fixnum)
Expand Down Expand Up @@ -245,6 +246,7 @@ def constant(prefix, suffix)
end

class Socket < BasicSocket
FFI = Rubinius::FFI

# @todo Is omitting empty-value constants reasonable? --rue
module Constants
Expand Down Expand Up @@ -1017,6 +1019,7 @@ def recvfrom_nonblock(maxlen, flags = 0)
end

class UDPSocket < IPSocket
FFI = Rubinius::FFI

def initialize(socktype = Socket::AF_INET)
@no_reverse_lookup = self.class.do_not_reverse_lookup
Expand Down Expand Up @@ -1091,6 +1094,7 @@ def inspect
end

class TCPSocket < IPSocket
FFI = Rubinius::FFI

def self.gethostbyname(hostname)
addrinfos = Socket.getaddrinfo(hostname, nil)
Expand Down
4 changes: 4 additions & 0 deletions lib/20/socket.rb
Expand Up @@ -8,6 +8,7 @@ class SocketError < StandardError
# @todo UDPSocket#recvfrom

class BasicSocket < IO
FFI = Rubinius::FFI

class << self
def from_descriptor(fixnum)
Expand Down Expand Up @@ -245,6 +246,7 @@ def constant(prefix, suffix)
end

class Socket < BasicSocket
FFI = Rubinius::FFI

# @todo Is omitting empty-value constants reasonable? --rue
module Constants
Expand Down Expand Up @@ -1017,6 +1019,7 @@ def recvfrom_nonblock(maxlen, flags = 0)
end

class UDPSocket < IPSocket
FFI = Rubinius::FFI

def initialize(socktype = Socket::AF_INET)
@no_reverse_lookup = self.class.do_not_reverse_lookup
Expand Down Expand Up @@ -1091,6 +1094,7 @@ def inspect
end

class TCPSocket < IPSocket
FFI = Rubinius::FFI

def self.gethostbyname(hostname)
addrinfos = Socket.getaddrinfo(hostname, nil)
Expand Down
7 changes: 5 additions & 2 deletions lib/etc.rb.ffi
@@ -1,4 +1,4 @@
class Struct::Passwd < FFI::Struct
class Struct::Passwd < Rubinius::FFI::Struct
@@@
struct do |s|
s.include "sys/types.h"
Expand All @@ -24,7 +24,7 @@ class Struct::Passwd < FFI::Struct
def shell; self[:pw_shell]; end
end

class Struct::Group < FFI::Struct
class Struct::Group < Rubinius::FFI::Struct
@@@
struct do |s|
s.include "sys/types.h"
Expand All @@ -38,6 +38,8 @@ class Struct::Group < FFI::Struct
end
@@@

FFI = Rubinius::FFI

def name; self[:gr_name]; end
def gid; self[:gr_gid]; end
def passwd; self[:gr_passwd]; end
Expand All @@ -58,6 +60,7 @@ class Struct::Group < FFI::Struct
end

module Etc
FFI = Rubinius::FFI

const_set(:Passwd, Struct::Passwd)
const_set(:Group, Struct::Group)
Expand Down
1 change: 1 addition & 0 deletions lib/ffi.rb
Expand Up @@ -3,3 +3,4 @@
# Rubinius, FFI is a part of the kernel code and thus
# already loaded.

FFI = Rubinius::FFI
2 changes: 2 additions & 0 deletions lib/ffi/file_processor.rb
@@ -1,5 +1,6 @@
require File.expand_path('../generators', __FILE__)

module Rubinius
module FFI

# Processes a file containing Ruby code with blocks of FFI definitions
Expand Down Expand Up @@ -85,3 +86,4 @@ def to_s
end
end
end
end
2 changes: 2 additions & 0 deletions lib/ffi/generator.rb
@@ -1,5 +1,6 @@
require File.expand_path('../file_processor', __FILE__)

module Rubinius
module FFI
class Generator
def initialize(ffi_name, rb_name)
Expand All @@ -10,3 +11,4 @@ def initialize(ffi_name, rb_name)
end
end
end
end
2 changes: 2 additions & 0 deletions lib/ffi/generators.rb
Expand Up @@ -6,6 +6,7 @@
require base + '/generators/constants'
require base + '/generators/types'

module Rubinius
module FFI
module Generators

Expand Down Expand Up @@ -126,3 +127,4 @@ def windows?
end
end
end
end
2 changes: 2 additions & 0 deletions lib/ffi/generators/constants.rb
@@ -1,3 +1,4 @@
module Rubinius
module FFI
module Generators
##
Expand Down Expand Up @@ -177,3 +178,4 @@ def include_dir(i)

ConstGenerator = Generators::Constants
end
end

0 comments on commit 53a0a09

Please sign in to comment.