Tests for the presence of a --with-
config or --without-
config option. Returns true
if the with option is given, false
if the without option is given, and the default value otherwise.
This can be useful for adding custom definitions, such as debug information.
Example:
if with_config("debug") $defs.push("-DOSSL_DEBUG") unless $defs.include? "-DOSSL_DEBUG" end
Tests for the presence of an --enable-
config or --disable-
config option. Returns true
if the enable option is given, false
if the disable option is given, and the default value otherwise.
This can be useful for adding custom definitions, such as debug information.
Example:
if enable_config("debug") $defs.push("-DOSSL_DEBUG") unless $defs.include? "-DOSSL_DEBUG" end
Generates a header file consisting of the various macro definitions generated by other methods such as have_func
and have_header. These are then wrapped in a custom #ifndef
based on the header
file name, which defaults to “extconf.h”.
For example:
# extconf.rb require 'mkmf' have_func('realpath') have_header('sys/utime.h') create_header create_makefile('foo')
The above script would generate the following extconf.h file:
#ifndef EXTCONF_H #define EXTCONF_H #define HAVE_REALPATH 1 #define HAVE_SYS_UTIME_H 1 #endif
Given that the create_header
method generates a file based on definitions set earlier in your extconf.rb file, you will probably want to make this one of the last methods you call in your script.
Generates the Makefile for your extension, passing along any options and preprocessor constants that you may have generated through other methods.
The target
name should correspond the name of the global function name defined within your C extension, minus the Init_
. For example, if your C extension is defined as Init_foo
, then your target would simply be “foo”.
If any “/” characters are present in the target name, only the last name is interpreted as the target name, and the rest are considered toplevel directory names, and the generated Makefile will be altered accordingly to follow that directory structure.
For example, if you pass “test/foo” as a target name, your extension will be installed under the “test” directory. This means that in order to load the file within a Ruby program later, that directory structure will have to be followed, e.g. require 'test/foo'
.
The srcprefix
should be used when your source files are not in the same directory as your build script. This will not only eliminate the need for you to manually copy the source files into the same directory as your build script, but it also sets the proper target_prefix
in the generated Makefile.
Setting the target_prefix
will, in turn, install the generated binary in a directory under your RbConfig::CONFIG['sitearchdir']
that mimics your local filesystem when you run make install
.
For example, given the following file tree:
ext/ extconf.rb test/ foo.c
And given the following code:
create_makefile('test/foo', 'test')
That will set the target_prefix
in the generated Makefile to “test”. That, in turn, will create the following file tree when installed via the make install
command:
/path/to/ruby/sitearchdir/test/foo.so
It is recommended that you use this approach to generate your makefiles, instead of copying files around manually, because some third party libraries may depend on the target_prefix
being set properly.
The srcprefix
argument can be used to override the default source directory, i.e. the current directory. It is included as part of the VPATH
and added to the list of INCFLAGS
.
Registers the given klass
as the class to be instantiated when parsing a URI with the given scheme
:
URI.register_scheme('MS_SEARCH', URI::Generic) # => URI::Generic URI.scheme_list['MS_SEARCH'] # => URI::Generic
Note that after calling String#upcase
on scheme
, it must be a valid constant name.
Returns a hash of the defined schemes:
URI.scheme_list # => {"MAILTO"=>URI::MailTo, "LDAPS"=>URI::LDAPS, "WS"=>URI::WS, "HTTP"=>URI::HTTP, "HTTPS"=>URI::HTTPS, "LDAP"=>URI::LDAP, "FILE"=>URI::File, "FTP"=>URI::FTP}
Related: URI.register_scheme
.
Returns true if the source parses with errors.
Mirror the Prism.parse_file
API by using the serialization API. This uses native strings instead of Ruby strings because it allows us to use mmap when it is available.
Mirror the Prism.parse_lex
API by using the serialization API.
Mirror the Prism.parse_success?
API by using the serialization API.
SyntaxSuggest.valid_without?
[Private]
This will tell you if the ‘code_lines` would be valid if you removed the `without_lines`. In short it’s a way to detect if we’ve found the lines with syntax errors in our document yet.
code_lines = [ CodeLine.new(line: "def foo\n", index: 0) CodeLine.new(line: " def bar\n", index: 1) CodeLine.new(line: "end\n", index: 2) ] SyntaxSuggest.valid_without?( without_lines: code_lines[1], code_lines: code_lines ) # => true SyntaxSuggest.valid?(code_lines) # => false
Returns a Process::Status
object representing the most recently exited child process in the current thread, or nil
if none:
Process.spawn('ruby', '-e', 'exit 13') Process.wait Process.last_status # => #<Process::Status: pid 14396 exit 13> Process.spawn('ruby', '-e', 'exit 14') Process.wait Process.last_status # => #<Process::Status: pid 4692 exit 14> Process.spawn('ruby', '-e', 'exit 15') # 'exit 15' has not been reaped by #wait. Process.last_status # => #<Process::Status: pid 4692 exit 14> Process.wait Process.last_status # => #<Process::Status: pid 1380 exit 15>
Returns a clock time as determined by POSIX function clock_gettime():
Process.clock_gettime(:CLOCK_PROCESS_CPUTIME_ID) # => 198.650379677
Argument clock_id
should be a symbol or a constant that specifies the clock whose time is to be returned; see below.
Optional argument unit
should be a symbol that specifies the unit to be used in the returned clock time; see below.
Argument clock_id
Argument clock_id
specifies the clock whose time is to be returned; it may be a constant such as Process::CLOCK_REALTIME
, or a symbol shorthand such as :CLOCK_REALTIME
.
The supported clocks depend on the underlying operating system; this method supports the following clocks on the indicated platforms (raises Errno::EINVAL if called with an unsupported clock):
:CLOCK_BOOTTIME
: Linux 2.6.39.
:CLOCK_BOOTTIME_ALARM
: Linux 3.0.
:CLOCK_MONOTONIC
: SUSv3 to 4, Linux 2.5.63, FreeBSD 3.0, NetBSD 2.0, OpenBSD 3.4, macOS 10.12, Windows-2000.
:CLOCK_MONOTONIC_COARSE
: Linux 2.6.32.
:CLOCK_MONOTONIC_FAST
: FreeBSD 8.1.
:CLOCK_MONOTONIC_PRECISE
: FreeBSD 8.1.
:CLOCK_MONOTONIC_RAW
: Linux 2.6.28, macOS 10.12.
:CLOCK_MONOTONIC_RAW_APPROX
: macOS 10.12.
:CLOCK_PROCESS_CPUTIME_ID
: SUSv3 to 4, Linux 2.5.63, FreeBSD 9.3, OpenBSD 5.4, macOS 10.12.
:CLOCK_PROF
: FreeBSD 3.0, OpenBSD 2.1.
:CLOCK_REALTIME
: SUSv2 to 4, Linux 2.5.63, FreeBSD 3.0, NetBSD 2.0, OpenBSD 2.1, macOS 10.12, Windows-8/Server-2012. Time.now
is recommended over +:CLOCK_REALTIME:.
:CLOCK_REALTIME_ALARM
: Linux 3.0.
:CLOCK_REALTIME_COARSE
: Linux 2.6.32.
:CLOCK_REALTIME_FAST
: FreeBSD 8.1.
:CLOCK_REALTIME_PRECISE
: FreeBSD 8.1.
:CLOCK_SECOND
: FreeBSD 8.1.
:CLOCK_TAI
: Linux 3.10.
:CLOCK_THREAD_CPUTIME_ID
: SUSv3 to 4, Linux 2.5.63, FreeBSD 7.1, OpenBSD 5.4, macOS 10.12.
:CLOCK_UPTIME
: FreeBSD 7.0, OpenBSD 5.5.
:CLOCK_UPTIME_FAST
: FreeBSD 8.1.
:CLOCK_UPTIME_PRECISE
: FreeBSD 8.1.
:CLOCK_UPTIME_RAW
: macOS 10.12.
:CLOCK_UPTIME_RAW_APPROX
: macOS 10.12.
:CLOCK_VIRTUAL
: FreeBSD 3.0, OpenBSD 2.1.
Note that SUS stands for Single Unix Specification. SUS contains POSIX and clock_gettime
is defined in the POSIX part. SUS defines :CLOCK_REALTIME
as mandatory but :CLOCK_MONOTONIC
, :CLOCK_PROCESS_CPUTIME_ID
, and :CLOCK_THREAD_CPUTIME_ID
are optional.
Certain emulations are used when the given clock_id
is not supported directly:
Emulations for :CLOCK_REALTIME
:
:GETTIMEOFDAY_BASED_CLOCK_REALTIME
: Use gettimeofday() defined by SUS (deprecated in SUSv4). The resolution is 1 microsecond.
:TIME_BASED_CLOCK_REALTIME
: Use time() defined by ISO C. The resolution is 1 second.
Emulations for :CLOCK_MONOTONIC
:
:MACH_ABSOLUTE_TIME_BASED_CLOCK_MONOTONIC
: Use mach_absolute_time(), available on Darwin. The resolution is CPU dependent.
:TIMES_BASED_CLOCK_MONOTONIC
: Use the result value of times() defined by POSIX, thus:
Upon successful completion, times() shall return the elapsed real time, in clock ticks, since an arbitrary point in the past (for example, system start-up time).
For example, GNU/Linux returns a value based on jiffies and it is monotonic. However, 4.4BSD uses gettimeofday() and it is not monotonic. (FreeBSD uses :CLOCK_MONOTONIC
instead, though.)
The resolution is the clock tick. “getconf CLK_TCK” command shows the clock ticks per second. (The clock ticks-per-second is defined by HZ macro in older systems.) If it is 100 and clock_t is 32 bits integer type, the resolution is 10 millisecond and cannot represent over 497 days.
Emulations for :CLOCK_PROCESS_CPUTIME_ID
:
:GETRUSAGE_BASED_CLOCK_PROCESS_CPUTIME_ID
: Use getrusage() defined by SUS. getrusage() is used with RUSAGE_SELF to obtain the time only for the calling process (excluding the time for child processes). The result is addition of user time (ru_utime) and system time (ru_stime). The resolution is 1 microsecond.
:TIMES_BASED_CLOCK_PROCESS_CPUTIME_ID
: Use times() defined by POSIX. The result is addition of user time (tms_utime) and system time (tms_stime). tms_cutime and tms_cstime are ignored to exclude the time for child processes. The resolution is the clock tick. “getconf CLK_TCK” command shows the clock ticks per second. (The clock ticks per second is defined by HZ macro in older systems.) If it is 100, the resolution is 10 millisecond.
:CLOCK_BASED_CLOCK_PROCESS_CPUTIME_ID
: Use clock() defined by ISO C. The resolution is 1/CLOCKS_PER_SEC
. CLOCKS_PER_SEC
is the C-level macro defined by time.h. SUS defines CLOCKS_PER_SEC
as 1000000; other systems may define it differently. If CLOCKS_PER_SEC
is 1000000 (as in SUS), the resolution is 1 microsecond. If CLOCKS_PER_SEC
is 1000000 and clock_t is a 32-bit integer type, it cannot represent over 72 minutes.
Argument unit
Optional argument unit
(default :float_second
) specifies the unit for the returned value.
:float_microsecond
: Number of microseconds as a float.
:float_millisecond
: Number of milliseconds as a float.
:float_second
: Number of seconds as a float.
:microsecond
: Number of microseconds as an integer.
:millisecond
: Number of milliseconds as an integer.
:nanosecond
: Number of nanoseconds as an integer.
::second
: Number of seconds as an integer.
Examples:
Process.clock_gettime(:CLOCK_PROCESS_CPUTIME_ID, :float_microsecond) # => 203605054.825 Process.clock_gettime(:CLOCK_PROCESS_CPUTIME_ID, :float_millisecond) # => 203643.696848 Process.clock_gettime(:CLOCK_PROCESS_CPUTIME_ID, :float_second) # => 203.762181929 Process.clock_gettime(:CLOCK_PROCESS_CPUTIME_ID, :microsecond) # => 204123212 Process.clock_gettime(:CLOCK_PROCESS_CPUTIME_ID, :millisecond) # => 204298 Process.clock_gettime(:CLOCK_PROCESS_CPUTIME_ID, :nanosecond) # => 204602286036 Process.clock_gettime(:CLOCK_PROCESS_CPUTIME_ID, :second) # => 204
The underlying function, clock_gettime
(), returns a number of nanoseconds. Float
object (IEEE 754 double) is not enough to represent the return value for :CLOCK_REALTIME
. If the exact nanoseconds value is required, use :nanosecond
as the unit
.
The origin (time zero) of the returned value is system-dependent, and may be, for example, system start up time, process start up time, the Epoch, etc.
The origin in :CLOCK_REALTIME
is defined as the Epoch: 1970-01-01 00:00:00 UTC
; some systems count leap seconds and others don’t, so the result may vary across systems.
Parses the current JSON
text source and returns the complete data structure as a result. It raises JSON::ParserError
if fail to parse.
Creates a new DH
instance from scratch by generating random parameters and a key pair.
See also OpenSSL::PKey.generate_parameters
and OpenSSL::PKey.generate_key
.
size
The desired key size in bits.
generator
The generator.
Indicates whether this DH
instance has a private key associated with it or not. The private key may be retrieved with DH#priv_key.
Creates a new DSA
instance by generating a private/public key pair from scratch.
See also OpenSSL::PKey.generate_parameters
and OpenSSL::PKey.generate_key
.
size
The desired key size in bits.
Indicates whether this DSA
instance has a private key associated with it or not. The private key may be retrieved with DSA#private_key.
Creates a new EC
instance with a new random private and public key.
Returns whether this EC
instance has a private key. The private key (BN
) can be retrieved with EC#private_key
.
Generates an RSA keypair.
See also OpenSSL::PKey.generate_key
.
size
The desired key size in bits.
exponent
An odd Integer
, normally 3, 17, or 65537.