Ruby: util.c File Reference

Ruby 3.0.5p211 (2022-11-24 revision ba5cf0f7c52d4d35cc6a173c89eda98ceffa2dcf)

Data Structures | Macros | Typedefs | Functions | Variables
util.c File Reference
`#include "ruby/internal/config.h"`
`#include <ctype.h>`
`#include <errno.h>`
`#include <float.h>`
`#include <math.h>`
`#include <stdio.h>`
`#include "internal.h"`
`#include "internal/sanitizers.h"`
`#include "internal/util.h"`
`#include "ruby/util.h"`
`#include "ruby_atomic.h"`
`#include <sys/types.h>`
`#include <sys/stat.h>`
`#include "missing/dtoa.c"`

Go to the source code of this file.

## Data Structures
struct | stack_node

## Macros
#define | hexdigit ruby_hexdigits
#define | S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
#define | mmtype long
#define | mmcount (16 / SIZEOF_LONG)
#define | A ((mmtype*)a)
#define | B ((mmtype*)b)
#define | C ((mmtype*)c)
#define | D ((mmtype*)d)
#define | mmstep (sizeof(mmtype) * mmcount)
#define | mmprepare(base, size)
#define | mmarg mmkind, size, high, low
#define | mmargdecl int mmkind, size_t size, size_t high, size_t low
#define | mmswap(a, b) mmswap_((a),(b),mmarg)
#define | mmrot3(a, b, c) mmrot3_((a),(b),(c),mmarg)
#define | PUSH(ll, rr) do { top->LL = (ll); top->RR = (rr); ++top; } while (0) /* Push L,l,R,r */
#define | POP(ll, rr) do { --top; (ll) = top->LL; (rr) = top->RR; } while (0) /* Pop L,l,R,r */
#define | med3(a, b, c)
#define | PATH_MAX 8192
#define | strtod ruby_strtod
#define | dtoa ruby_dtoa
#define | hdtoa ruby_hdtoa

## Typedefs
typedef int() | cmpfunc_t(const void *, const void *, void *)

## Functions
unsigned long | ruby_scan_oct (const char *start, size_t len, size_t *retlen)
unsigned long | ruby_scan_hex (const char *start, size_t len, size_t *retlen)
| NO_SANITIZE ("unsigned-integer-overflow", extern unsigned long ruby_scan_digits(const char *str, ssize_t len, int base, size_t *retlen, int *overflow))
unsigned long | ruby_scan_digits (const char *str, ssize_t len, int base, size_t *retlen, int *overflow)
unsigned long | ruby_strtoul (const char *str, char **endptr, int base)
void | ruby_qsort (void *base, const size_t nel, const size_t size, cmpfunc_t *cmp, void *d)
char * | ruby_strdup (const char *str)
char * | ruby_getcwd (void)
void | ruby_each_words (const char *str, void(*func)(const char *, int, void *), void *arg)

## Variables
const char | ruby_hexdigits [] = "0123456789abcdef0123456789ABCDEF"
const signed char | ruby_digit36_to_number_table []

## Macro Definition Documentation

## ◆ A

#define A ((mmtype*)a)

Definition at line 267 of file util.c.

## ◆ B

#define B ((mmtype*)b)

Definition at line 268 of file util.c.

## ◆ C

#define C ((mmtype*)c)

Definition at line 269 of file util.c.

## ◆ D

#define D ((mmtype*)d)

Definition at line 270 of file util.c.

## ◆ dtoa

#define dtoa ruby_dtoa

Definition at line 608 of file util.c.

## ◆ hdtoa

#define hdtoa ruby_hdtoa

Definition at line 610 of file util.c.

## ◆ hexdigit

#define hexdigit ruby_hexdigits

Definition at line 35 of file util.c.

## ◆ med3

#define med3 | ( |  | a,
|  |  | b,
|  |  | c
| ) |  |

Value:
((*cmp)((a),(b),d)<0 ? \
((*cmp)((b),(c),d)<0 ? (b) : ((*cmp)((a),(c),d)<0 ? (c) : (a))) : \
((*cmp)((b),(c),d)>0 ? (b) : ((*cmp)((a),(c),d)<0 ? (a) : (c))))

Definition at line 374 of file util.c.

## ◆ mmarg

#define mmarg mmkind, size, high, low

Definition at line 282 of file util.c.

## ◆ mmargdecl

#define mmargdecl int mmkind, size_t size, size_t high, size_t low

Definition at line 283 of file util.c.

## ◆ mmcount

#define mmcount (16 / SIZEOF_LONG)

Definition at line 266 of file util.c.

## ◆ mmprepare

#define mmprepare | ( |  | base,
|  |  | size
| ) |  |

Value:
do {\
if (((VALUE)(base) % sizeof(mmtype)) == 0 && ((size) % sizeof(mmtype)) == 0) \
if ((size) >= mmstep) mmkind = 1;\
else mmkind = 0;\
else mmkind = -1;\
high = ((size) / mmstep) * mmstep;\
low = ((size) % mmstep);\
} while (0)\
size
voidpf void uLong size
Definition: ioapi.h:138
mmstep
#define mmstep
Definition: util.c:272
mmtype
#define mmtype
Definition: util.c:265
VALUE
unsigned long VALUE
Definition: value.h:38

Definition at line 273 of file util.c.

## ◆ mmrot3

#define mmrot3 | ( |  | a,
|  |  | b,
|  |  | c
| ) |  | mmrot3_((a),(b),(c),mmarg)

Definition at line 359 of file util.c.

## ◆ mmstep

#define mmstep (sizeof(mmtype) * mmcount)

Definition at line 272 of file util.c.

## ◆ mmswap

#define mmswap | ( |  | a,
|  |  | b
| ) |  | mmswap_((a),(b),mmarg)

Definition at line 321 of file util.c.

## ◆ mmtype

#define mmtype long

Definition at line 265 of file util.c.

## ◆ PATH_MAX

#define PATH_MAX 8192

## ◆ POP

#define POP | ( |  | ll,
|  |  | rr
| ) |  | do { --top; (ll) = top->LL; (rr) = top->RR; } while (0) /* Pop L,l,R,r */

Definition at line 372 of file util.c.

## ◆ PUSH

#define PUSH | ( |  | ll,
|  |  | rr
| ) |  | do { top->LL = (ll); top->RR = (rr); ++top; } while (0) /* Push L,l,R,r */

Definition at line 371 of file util.c.

## ◆ S_ISDIR

#define S_ISDIR | ( |  | m | ) | (((m) & S_IFMT) == S_IFDIR)

Definition at line 212 of file util.c.

## ◆ strtod

#define strtod ruby_strtod

Definition at line 606 of file util.c.

## Typedef Documentation

## ◆ cmpfunc_t

typedef int() cmpfunc_t(const void *, const void *, void *)

Definition at line 215 of file util.c.

## Function Documentation

## ◆ NO_SANITIZE()

NO_SANITIZE | ( | "unsigned-integer-overflow" | ,
|  | extern unsigned long | ruby_scan_digitsconst char *str, ssize_t len, int base, size_t *retlen, int *overflow
| ) |  |

## ◆ ruby_each_words()

void ruby_each_words | ( | const char * | str,
|  | void(*)(const char *, int, void *) | func,
|  | void * | arg
| ) |  |

Definition at line 589 of file util.c.

References int(), ISSPACE, len, and str.

Referenced by ruby_set_debug_option().

## ◆ ruby_getcwd()

char * ruby_getcwd | ( | void |  | ) |

Definition at line 543 of file util.c.

References DATA_PTR, Data_Wrap_Struct, free, getcwd, NULL, PATH_MAX, RB_GC_GUARD, rb_sys_fail(), rb_syserr_fail(), RUBY_DEFAULT_FREE, ruby_strdup(), xfree, xmalloc, and xrealloc.

Referenced by rb_dir_getwd_ospath(), and rb_file_expand_path_internal().

## ◆ ruby_qsort()

void ruby_qsort | ( | void * | base,
|  | const size_t | nel,
|  | const size_t | size,
|  | cmpfunc_t * | cmp,
|  | void * | d
| ) |  |

Definition at line 379 of file util.c.

References CHAR_BIT, fail, L, med3, mmprepare, mmrot3, mmswap, POP, PUSH, R, t, and top.

## ◆ ruby_scan_digits()

unsigned long ruby_scan_digits | ( | const char * | str,
|  | ssize_t | len,
|  | int | base,
|  | size_t * | retlen,
|  | int * | overflow
| ) |  |

Definition at line 101 of file util.c.

References len, long(), ruby_digit36_to_number_table, and str.

Referenced by date_zone_to_diff(), rb_int_parse_cstr(), and ruby_strtoul().

## ◆ ruby_scan_hex()

unsigned long ruby_scan_hex | ( | const char * | start,
|  | size_t | len,
|  | size_t * | retlen
| ) |  |

Definition at line 56 of file util.c.

References hexdigit, int(), len, and strchr().

## ◆ ruby_scan_oct()

unsigned long ruby_scan_oct | ( | const char * | start,
|  | size_t | len,
|  | size_t * | retlen
| ) |  |

Definition at line 38 of file util.c.

References int(), and len.

## ◆ ruby_strdup()

char * ruby_strdup | ( | const char * | str | ) |

Definition at line 531 of file util.c.

References len, memcpy, str, strlen(), and xmalloc.

Referenced by compat_init_setproctitle(), getifaddrs(), ruby_getcwd(), and ruby_setenv().

## ◆ ruby_strtoul()

unsigned long ruby_strtoul | ( | const char * | str,
|  | char ** | endptr,
|  | int | base
| ) |  |

Definition at line 134 of file util.c.

References ISSPACE, len, long(), ruby_scan_digits(), and str.

## Variable Documentation

## ◆ ruby_digit36_to_number_table

const signed char ruby_digit36_to_number_table[]

Initial value:
= {
-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
0, 1, 2, 3, 4, 5, 6, 7, 8, 9,-1,-1,-1,-1,-1,-1,
-1,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,
25,26,27,28,29,30,31,32,33,34,35,-1,-1,-1,-1,-1,
-1,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,
25,26,27,28,29,30,31,32,33,34,35,-1,-1,-1,-1,-1,
-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
}

Definition at line 79 of file util.c.

Referenced by ruby_scan_digits().

## ◆ ruby_hexdigits

const char ruby_hexdigits[] = "0123456789abcdef0123456789ABCDEF"

Definition at line 34 of file util.c.