Ruby  3.1.0dev(2021-09-10revisionb76ad15ed0da636161de0243c547ee1e6fc95681)
Data Structures | Macros | Typedefs | Functions | Variables
util.c File Reference

(b76ad15ed0da636161de0243c547ee1e6fc95681)

#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"
Include dependency graph for util.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 264 of file util.c.

◆ B

#define B   ((mmtype*)b)

Definition at line 265 of file util.c.

◆ C

#define C   ((mmtype*)c)

Definition at line 266 of file util.c.

◆ D

#define D   ((mmtype*)d)

Definition at line 267 of file util.c.

◆ dtoa

#define dtoa   ruby_dtoa

Definition at line 606 of file util.c.

◆ hdtoa

#define hdtoa   ruby_hdtoa

Definition at line 608 of file util.c.

◆ hexdigit

#define hexdigit   ruby_hexdigits

Definition at line 35 of file util.c.

◆ med3

#define med3 (   a,
  b,
 
)
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 371 of file util.c.

◆ mmarg

#define mmarg   mmkind, size, high, low

Definition at line 279 of file util.c.

◆ mmargdecl

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

Definition at line 280 of file util.c.

◆ mmcount

#define mmcount   (16 / SIZEOF_LONG)

Definition at line 263 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)\

Definition at line 270 of file util.c.

◆ mmrot3

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

Definition at line 356 of file util.c.

◆ mmstep

#define mmstep   (sizeof(mmtype) * mmcount)

Definition at line 269 of file util.c.

◆ mmswap

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

Definition at line 318 of file util.c.

◆ mmtype

#define mmtype   long

Definition at line 262 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 369 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 368 of file util.c.

◆ S_ISDIR

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

Definition at line 209 of file util.c.

◆ strtod

#define strtod   ruby_strtod

Definition at line 604 of file util.c.

Typedef Documentation

◆ cmpfunc_t

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

Definition at line 212 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 587 of file util.c.

References ISSPACE, len, and str.

Referenced by ruby_set_debug_option().

◆ ruby_getcwd()

char* ruby_getcwd ( void  )

◆ ruby_qsort()

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

Definition at line 376 of file util.c.

◆ ruby_scan_digits()

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

Definition at line 98 of file util.c.

References len, ret, ruby_digit36_to_number_table, and str.

Referenced by 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 len, and ruby_digit36_to_number_table.

◆ 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 len.

◆ ruby_strdup()

char* ruby_strdup ( const char *  str)

Definition at line 529 of file util.c.

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

Referenced by compat_init_setproctitle(), and ruby_getcwd().

◆ ruby_strtoul()

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

Definition at line 131 of file util.c.

References ISSPACE, len, ret, 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 76 of file util.c.

Referenced by ruby_scan_digits(), and ruby_scan_hex().

◆ ruby_hexdigits

const char ruby_hexdigits[] = "0123456789abcdef0123456789ABCDEF"

Definition at line 34 of file util.c.

mmstep
#define mmstep
Definition: util.c:269
mmtype
#define mmtype
Definition: util.c:262
VALUE
unsigned long VALUE
Definition: value.h:38
size
rb_atomic_t size
Definition: signal.c:509