Ruby
3.4.0dev (2024-11-05 revision 348a53415339076afc4a02fcd09f3ae36e9c4c61)
|
#include "ruby/internal/config.h"
#include "ruby/internal/attr/noalias.h"
#include "ruby/internal/attr/nodiscard.h"
#include "ruby/internal/attr/nonnull.h"
#include "ruby/internal/attr/restrict.h"
#include "ruby/internal/attr/returns_nonnull.h"
#include "ruby/internal/dllexport.h"
#include "ruby/defines.h"
Go to the source code of this file.
Macros | |
#define | DECIMAL_SIZE_OF_BITS(n) (((n) * 3010 + 9998) / 9999) |
an approximation of ceil(n * log10(2)), up to 1,048,576 (1<<20) without overflow within 32-bit calculation More... | |
#define | DECIMAL_SIZE_OF_BYTES(n) DECIMAL_SIZE_OF_BITS((n) * CHAR_BIT) |
an approximation of decimal representation size for n-bytes More... | |
#define | DECIMAL_SIZE_OF(expr) DECIMAL_SIZE_OF_BYTES(sizeof(expr)) |
An approximation of decimal representation size. More... | |
#define | scan_oct(s, l, e) ((int)ruby_scan_oct((s),(l),(e))) |
Old name of ruby_scan_oct. More... | |
#define | scan_hex(s, l, e) ((int)ruby_scan_hex((s),(l),(e))) |
Old name of ruby_scan_hex. More... | |
#define | strdup(s) ruby_strdup(s) |
Just another name of ruby_strdup. More... | |
#define | strtod(s, e) ruby_strtod((s),(e)) |
Just another name of ruby_strtod. More... | |
Functions | |
unsigned long | ruby_scan_digits (const char *str, ssize_t len, int base, size_t *retlen, int *overflow) |
Scans the passed string, assuming the string is a textual representation of an integer. More... | |
unsigned long | ruby_scan_oct (const char *str, size_t len, size_t *consumed) |
Interprets the passed string as an octal unsigned integer. More... | |
unsigned long | ruby_scan_hex (const char *str, size_t len, size_t *ret) |
Interprets the passed string a hexadecimal unsigned integer. More... | |
void | ruby_qsort (void *, const size_t, const size_t, int(*)(const void *, const void *, void *), void *) |
Reentrant implementation of quick sort. More... | |
void | ruby_setenv (const char *key, const char *val) |
Sets an environment variable. More... | |
void | ruby_unsetenv (const char *key) |
Deletes the passed environment variable, if any. More... | |
char * | ruby_strdup (const char *str) |
This is our own version of strdup(3) that uses ruby_xmalloc() instead of system malloc (benefits our GC). More... | |
char * | ruby_getcwd (void) |
This is our own version of getcwd(3) that uses ruby_xmalloc() instead of system malloc (benefits our GC). More... | |
double | ruby_strtod (const char *str, char **endptr) |
Our own locale-insensitive version of strtod(3) . More... | |
void | ruby_each_words (const char *str, void(*func)(const char *word, int len, void *argv), void *argv) |
Scans the passed string, with calling the callback function every time it encounters a "word". More... | |
Variables | |
const signed char | ruby_digit36_to_number_table [] |
Character to number mapping like ‘'a’-> 10, 'b'-> 11` etc. More... | |
const char | ruby_hexdigits [] |
Characters that Ruby accepts as hexadecimal digits. More... | |
Definition in file util.h.
#define DECIMAL_SIZE_OF | ( | expr | ) | DECIMAL_SIZE_OF_BYTES(sizeof(expr)) |
#define DECIMAL_SIZE_OF_BITS | ( | n | ) | (((n) * 3010 + 9998) / 9999) |
#define DECIMAL_SIZE_OF_BYTES | ( | n | ) | DECIMAL_SIZE_OF_BITS((n) * CHAR_BIT) |
#define strdup | ( | s | ) | ruby_strdup(s) |
Just another name of ruby_strdup.
#define strtod | ( | s, | |
e | |||
) | ruby_strtod((s),(e)) |
Just another name of ruby_strtod.
void ruby_each_words | ( | const char * | str, |
void(*)(const char *word, int len, void *argv) | func, | ||
void * | argv | ||
) |
Scans the passed string, with calling the callback function every time it encounters a "word".
A word here is a series of characters separated by either a space (of IEEE 1003.1 section 7.3.1.1), or a ‘’,'`.
[in] | str | Target string to split into each words. |
[in] | func | Callback function. |
[in,out] | argv | Passed as-is to func . |
char* ruby_getcwd | ( | void | ) |
This is our own version of getcwd(3)
that uses ruby_xmalloc() instead of system malloc (benefits our GC).
void ruby_qsort | ( | void * | , |
const | size_t, | ||
const | size_t, | ||
int(*)(const void *, const void *, void *) | , | ||
void * | |||
) |
Reentrant implementation of quick sort.
If your system provides something (like C11 qsort_s), this is a thin wrapper of that routine. Otherwise resorts to our own version.
Referenced by rb_ary_sort_bang().
unsigned long ruby_scan_digits | ( | const char * | str, |
ssize_t | len, | ||
int | base, | ||
size_t * | retlen, | ||
int * | overflow | ||
) |
Scans the passed string, assuming the string is a textual representation of an integer.
Stops when encountering something non-digit for the passed base.
0x
prefix. 0
to base
, unlike ruby_strtoul(). [in] | str | Target string of digits to interpret. |
[in] | len | Number of bytes of str , or -1 to detect NUL . |
[in] | base | Base, 2 to 36 inclusive. |
[out] | retlen | Return value buffer. |
[out] | overflow | Return value buffer. |
str
. retlen
is the number of bytes scanned so far. overflow
is set to true if the string represents something bigger than ULONG_MAX
. Something meaningful still returns; which is the designed belabour of C's unsigned arithmetic. Definition at line 103 of file util.c.
Referenced by ruby_strtoul().
unsigned long ruby_scan_hex | ( | const char * | str, |
size_t | len, | ||
size_t * | ret | ||
) |
Interprets the passed string a hexadecimal unsigned integer.
Stops when encounters something not understood.
[in] | str | C string to scan. |
[in] | len | Length of str . |
[out] | ret | Return value buffer. |
ret
is the number of characters read. unsigned long ruby_scan_oct | ( | const char * | str, |
size_t | len, | ||
size_t * | consumed | ||
) |
Interprets the passed string as an octal unsigned integer.
Stops when encounters something not understood.
[in] | str | C string to scan. |
[in] | len | Length of str . |
[out] | consumed | Return value buffer. |
ret
is the number of characters read. void ruby_setenv | ( | const char * | key, |
const char * | val | ||
) |
Sets an environment variable.
In case of POSIX this is a wrapper of setenv(3)
. But there are systems which lack one. We try hard emulating.
[in] | key | An environment variable. |
[in] | val | A value to be associated with key , or 0. |
rb_eSystemCallError | setenv(3) failed for some reason. |
key
is created if necessary. Its value is updated to be val
. Definition at line 5091 of file hash.c.
Referenced by rb_env_clear(), and ruby_unsetenv().
char* ruby_strdup | ( | const char * | str | ) |
This is our own version of strdup(3)
that uses ruby_xmalloc() instead of system malloc (benefits our GC).
[in] | str | Target C string to duplicate. |
Definition at line 536 of file util.c.
Referenced by ruby_setenv().
double ruby_strtod | ( | const char * | str, |
char ** | endptr | ||
) |
Our own locale-insensitive version of strtod(3)
.
The conversion is done as if the current locale is set to the "C" locale, no matter actual runtime locale settings.
[in] | str | Decimal or hexadecimal representation of a floating point number. |
[out] | endptr | NULL, or an arbitrary pointer (overwritten on return). |
endptr
is not NULL, it is updated to point the first such byte where conversion failed. errno
on failure.ERANGE
: Converted integer is out of range of double
. void ruby_unsetenv | ( | const char * | key | ) |
|
extern |
Character to number mapping like ‘'a’->
10,
'b'->
11` etc.
For punctuation etc., the value is -1. "36" terminology comes from the fact that this is the table behind str.to_i(36)
.
Definition at line 81 of file util.c.
Referenced by ruby_scan_digits(), and ruby_scan_hex().