Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
M
mruby
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Libraries
mruby
Commits
5622c977
Commit
5622c977
authored
Apr 20, 2012
by
Yukihiro Matsumoto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
remove dependency to SIZEOF_VOIDP
parent
673b3350
Changes
6
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
11 additions
and
319 deletions
+11
-319
include/mrbconf.h
include/mrbconf.h
+0
-1
src/Makefile
src/Makefile
+1
-1
src/numeric.c
src/numeric.c
+2
-93
src/re.c
src/re.c
+0
-49
src/st.h
src/st.h
+0
-6
src/string.c
src/string.c
+8
-169
No files found.
include/mrbconf.h
View file @
5622c977
...
...
@@ -27,7 +27,6 @@ typedef intptr_t mrb_sym;
#define SIZEOF_LONG 4
#define SIZEOF_LONG_LONG 8
#define SIZEOF___INT64 0
#define SIZEOF_VOIDP 4
#define SIZEOF_FLOAT 4
#define SIZEOF_DOUBLE 8
...
...
src/Makefile
View file @
5622c977
...
...
@@ -40,7 +40,7 @@ YACC = bison
DEBUG_MODE
=
1
ifeq
($(DEBUG_MODE),1)
CFLAGS
=
-g
CFLAGS
=
-g
-O3
else
CFLAGS
=
-O3
endif
...
...
src/numeric.c
View file @
5622c977
...
...
@@ -97,25 +97,9 @@
# define SIZEOF_LONG_LONG SIZEOF___INT64
#endif
#if defined HAVE_UINTPTR_T && 0
typedef
uintptr_t
VALUE
;
typedef
uintptr_t
ID
;
# define SIGNED_VALUE intptr_t
# define SIZEOF_VALUE SIZEOF_UINTPTR_T
#elif SIZEOF_LONG == SIZEOF_VOIDP
//typedef unsigned long VALUE;
//typedef unsigned long ID;
# define SIGNED_VALUE long long
# define SIZEOF_VALUE SIZEOF_LONG
#elif SIZEOF_LONG_LONG == SIZEOF_VOIDP
typedef
unsigned
LONG_LONG
VALUE
;
typedef
unsigned
LONG_LONG
ID
;
# define SIGNED_VALUE LONG_LONG
# define LONG_LONG_VALUE 1
# define SIZEOF_VALUE SIZEOF_LONG_LONG
#else
# error ---->> ruby requires sizeof(void*) == sizeof(long) to be compiled. <<----
#endif
#define SIGNED_VALUE intptr_t
#ifdef HAVE_INFINITY
#elif BYTE_ORDER == LITTLE_ENDIAN
...
...
@@ -980,80 +964,6 @@ mrb_num2ulong(mrb_state *mrb, mrb_value val)
}
}
#if SIZEOF_INT < SIZEOF_VALUE
void
mrb_out_of_int
(
mrb_state
*
mrb
,
SIGNED_VALUE
num
)
{
mrb_raise
(
mrb
,
E_RANGE_ERROR
,
"integer %"
PRIdVALUE
" too %s to convert to `int'"
,
num
,
num
<
0
?
"small"
:
"big"
);
}
static
void
check_int
(
SIGNED_VALUE
num
)
{
if
((
SIGNED_VALUE
)(
int
)
num
!=
num
)
{
mrb_out_of_int
(
num
);
}
}
static
void
check_uint
(
mrb_state
*
mrb
,
mrb_value
num
,
mrb_value
sign
)
{
static
const
mrb_value
mask
=
~
(
mrb_value
)
UINT_MAX
;
if
(
RTEST
(
sign
))
{
/* minus */
if
((
num
&
mask
)
!=
mask
||
(
num
&
~
mask
)
<=
INT_MAX
+
1UL
)
mrb_raise
(
mrb
,
E_RANGE_ERROR
,
"integer %"
PRIdVALUE
" too small to convert to `unsigned int'"
,
num
);
}
else
{
/* plus */
if
((
num
&
mask
)
!=
0
)
mrb_raise
(
mrb
,
E_RANGE_ERROR
,
"integer %"
PRIuVALUE
" too big to convert to `unsigned int'"
,
num
);
}
}
long
mrb_num2int
(
mrb_value
val
)
{
long
num
=
mrb_num2long
(
mrb
,
val
);
check_int
(
num
);
return
num
;
}
long
mrb_fix2int
(
mrb_state
*
mrb
,
mrb_value
val
)
{
long
num
=
FIXNUM_P
(
val
)
?
mrb_fixnum
(
val
)
:
mrb_num2long
(
mrb
,
val
);
check_int
(
num
);
return
num
;
}
unsigned
long
mrb_num2uint
(
mrb_value
val
)
{
unsigned
long
num
=
mrb_num2ulong
(
val
);
check_uint
(
num
,
mrb_funcall
(
mrb
,
val
,
"<"
,
1
,
mrb_fixnum_value
(
0
)));
return
num
;
}
unsigned
long
mrb_fix2uint
(
mrb_state
*
mrb
,
mrb_value
val
)
{
unsigned
long
num
;
if
(
!
FIXNUM_P
(
val
))
{
return
mrb_num2uint
(
mrb
,
val
);
}
num
=
FIX2ULONG
(
val
);
check_uint
(
num
,
mrb_funcall
(
mrb
,
val
,
"<"
,
1
,
mrb_fixnum_value
(
0
)));
return
num
;
}
#else
long
mrb_num2int
(
mrb_state
*
mrb
,
mrb_value
val
)
{
...
...
@@ -1065,7 +975,6 @@ mrb_fix2int(mrb_value val)
{
return
mrb_fixnum
(
val
);
}
#endif
mrb_value
mrb_num2fix
(
mrb_state
*
mrb
,
mrb_value
val
)
...
...
@@ -1204,7 +1113,7 @@ mrb_value
rb_fix2str
(
mrb_state
*
mrb
,
mrb_value
x
,
int
base
)
{
extern
const
char
ruby_digitmap
[];
char
buf
[
SIZEOF_VALUE
*
CHAR_BIT
+
2
],
*
b
=
buf
+
sizeof
buf
;
char
buf
[
sizeof
(
mrb_int
)
*
CHAR_BIT
+
2
],
*
b
=
buf
+
sizeof
buf
;
long
val
=
mrb_fixnum
(
x
);
int
neg
=
0
;
...
...
src/re.c
View file @
5622c977
...
...
@@ -1773,11 +1773,7 @@ static int
pair_byte_cmp
(
const
void
*
pair1
,
const
void
*
pair2
)
{
long
diff
=
((
pair_t
*
)
pair1
)
->
byte_pos
-
((
pair_t
*
)
pair2
)
->
byte_pos
;
#if SIZEOF_LONG > SIZEOF_INT
return
diff
?
diff
>
0
?
1
:
-
1
:
0
;
#else
return
(
int
)
diff
;
#endif
}
static
void
...
...
@@ -2958,48 +2954,6 @@ mrb_backref_set(mrb_state *mrb, mrb_value val)
#endif //INCLUDE_REGEXP
#ifdef INCLUDE_ENCODING
static
inline
long
mrb_memsearch_ss
(
const
unsigned
char
*
xs
,
long
m
,
const
unsigned
char
*
ys
,
long
n
)
{
const
unsigned
char
*
x
=
xs
,
*
xe
=
xs
+
m
;
const
unsigned
char
*
y
=
ys
,
*
ye
=
ys
+
n
;
#define SIZEOF_VOIDP 4
#define SIZEOF_LONG 4
#ifndef VALUE_MAX
# if SIZEOF_VALUE == 8
# define VALUE_MAX 0xFFFFFFFFFFFFFFFFULL
# elif SIZEOF_VALUE == 4
# define VALUE_MAX 0xFFFFFFFFUL
# elif SIZEOF_LONG == SIZEOF_VOIDP
# define SIZEOF_VALUE 4
# define VALUE_MAX 0xFFFFFFFFUL
# endif
#endif
int
hx
,
hy
,
mask
=
VALUE_MAX
>>
((
SIZEOF_VALUE
-
m
)
*
CHAR_BIT
);
if
(
m
>
SIZEOF_VALUE
)
mrb_bug
(
"!!too long pattern string!!"
);
/* Prepare hash value */
for
(
hx
=
*
x
++
,
hy
=
*
y
++
;
x
<
xe
;
++
x
,
++
y
)
{
hx
<<=
CHAR_BIT
;
hy
<<=
CHAR_BIT
;
hx
|=
*
x
;
hy
|=
*
y
;
}
/* Searching */
while
(
hx
!=
hy
)
{
if
(
y
==
ye
)
return
-
1
;
hy
<<=
CHAR_BIT
;
hy
|=
*
y
;
hy
&=
mask
;
y
++
;
}
return
y
-
ys
-
m
;
}
static
inline
long
mrb_memsearch_qs
(
const
unsigned
char
*
xs
,
long
m
,
const
unsigned
char
*
ys
,
long
n
)
{
...
...
@@ -3094,9 +3048,6 @@ mrb_memsearch(mrb_state *mrb, const void *x0, int m, const void *y0, int n, mrb_
}
return
-
1
;
}
else
if
(
m
<=
SIZEOF_VALUE
)
{
return
mrb_memsearch_ss
(
x0
,
m
,
y0
,
n
);
}
else
if
(
enc
==
mrb_utf8_encoding
(
mrb
))
{
return
mrb_memsearch_qs_utf8
(
x0
,
m
,
y0
,
n
);
}
...
...
src/st.h
View file @
5622c977
...
...
@@ -64,12 +64,6 @@ struct st_table_entry {
st_table_entry
*
fore
,
*
back
;
};
#ifndef SIZEOF_VOIDP
#define SIZEOF_VOIDP 4
#endif
#define SIZEOF_ST_INDEX_T SIZEOF_VOIDP
struct
st_hash_type
{
int
(
*
compare
)(
ANYARGS
/*st_data_t, st_data_t*/
);
/* st_compare_func* */
st_index_t
(
*
hash
)(
ANYARGS
/*st_data_t*/
);
/* st_hash_func* */
...
...
src/string.c
View file @
5622c977
...
...
@@ -211,32 +211,6 @@ single_byte_optimizable(mrb_state *mrb, mrb_value str)
static
inline
const
char
*
search_nonascii
(
const
char
*
p
,
const
char
*
e
)
{
#if SIZEOF_VALUE == 8
# define NONASCII_MASK 0x8080808080808080ULL
#elif SIZEOF_VALUE == 4
# define NONASCII_MASK 0x80808080UL
#endif
#ifdef NONASCII_MASK
if
((
int
)
sizeof
(
intptr_t
)
*
2
<
e
-
p
)
{
const
intptr_t
*
s
,
*
t
;
const
intptr_t
lowbits
=
sizeof
(
intptr_t
)
-
1
;
s
=
(
const
intptr_t
*
)(
~
lowbits
&
((
intptr_t
)
p
+
lowbits
));
while
(
p
<
(
const
char
*
)
s
)
{
if
(
!
ISASCII
(
*
p
))
return
p
;
p
++
;
}
t
=
(
const
intptr_t
*
)(
~
lowbits
&
(
intptr_t
)
e
);
while
(
s
<
t
)
{
if
(
*
s
&
(
intptr_t
)
NONASCII_MASK
)
{
t
=
s
;
break
;
}
s
++
;
}
p
=
(
const
char
*
)
t
;
}
#endif
while
(
p
<
e
)
{
if
(
!
ISASCII
(
*
p
))
return
p
;
...
...
@@ -1167,63 +1141,6 @@ mrb_str_match(mrb_state *mrb, mrb_value self/* x */)
}
}
/* ---------------------------------- */
#ifdef INCLUDE_ENCODING
#ifdef NONASCII_MASK
#define is_utf8_lead_byte(c) (((c)&0xC0) != 0x80)
static
inline
int
count_utf8_lead_bytes_with_word
(
const
intptr_t
*
s
)
{
int
d
=
*
s
;
d
|=
~
(
d
>>
1
);
d
>>=
6
;
d
&=
NONASCII_MASK
>>
7
;
d
+=
(
d
>>
8
);
d
+=
(
d
>>
16
);
#if SIZEOF_VALUE == 8
d
+=
(
d
>>
32
);
#endif
return
(
d
&
0xF
);
}
#endif
#ifdef NONASCII_MASK
static
char
*
str_utf8_nth
(
const
char
*
p
,
const
char
*
e
,
long
nth
)
{
if
((
int
)
SIZEOF_VALUE
<
e
-
p
&&
(
int
)
SIZEOF_VALUE
*
2
<
nth
)
{
const
intptr_t
*
s
,
*
t
;
const
intptr_t
lowbits
=
sizeof
(
int
)
-
1
;
s
=
(
const
intptr_t
*
)(
~
lowbits
&
((
intptr_t
)
p
+
lowbits
));
t
=
(
const
intptr_t
*
)(
~
lowbits
&
(
intptr_t
)
e
);
while
(
p
<
(
const
char
*
)
s
)
{
if
(
is_utf8_lead_byte
(
*
p
))
nth
--
;
p
++
;
}
do
{
nth
-=
count_utf8_lead_bytes_with_word
(
s
);
s
++
;
}
while
(
s
<
t
&&
(
int
)
sizeof
(
intptr_t
)
<=
nth
);
p
=
(
char
*
)
s
;
}
while
(
p
<
e
)
{
if
(
is_utf8_lead_byte
(
*
p
))
{
if
(
nth
==
0
)
break
;
nth
--
;
}
p
++
;
}
return
(
char
*
)
p
;
}
static
long
str_utf8_offset
(
const
char
*
p
,
const
char
*
e
,
long
nth
)
{
const
char
*
pp
=
str_utf8_nth
(
p
,
e
,
nth
);
return
pp
-
p
;
}
#endif
#endif //INCLUDE_ENCODING
mrb_value
mrb_str_substr
(
mrb_state
*
mrb
,
mrb_value
str
,
mrb_int
beg
,
int
len
)
{
...
...
@@ -1283,13 +1200,6 @@ mrb_str_substr(mrb_state *mrb, mrb_value str, mrb_int beg, int len)
if
(
len
==
0
)
{
p
=
0
;
}
#ifdef NONASCII_MASK
else
if
(
ENC_CODERANGE
(
str
)
==
ENC_CODERANGE_VALID
&&
enc
==
mrb_utf8_encoding
(
mrb
))
{
p
=
str_utf8_nth
(
s
,
e
,
beg
);
len
=
str_utf8_offset
(
p
,
e
,
len
);
}
#endif
else
if
(
mrb_enc_mbmaxlen
(
enc
)
==
mrb_enc_mbminlen
(
enc
))
{
int
char_sz
=
mrb_enc_mbmaxlen
(
enc
);
...
...
@@ -1405,46 +1315,6 @@ mrb_enc_strlen_cr(mrb_state *mrb, const char *p, const char *e, mrb_encoding *en
/* --- 1-8-7parse.c --< */
#ifndef INCLUDE_ENCODING
static
inline
long
mrb_memsearch_ss
(
const
unsigned
char
*
xs
,
long
m
,
const
unsigned
char
*
ys
,
long
n
)
{
const
unsigned
char
*
x
=
xs
,
*
xe
=
xs
+
m
;
const
unsigned
char
*
y
=
ys
,
*
ye
=
ys
+
n
;
//2011/06/30 #define SIZEOF_VALUE 4
#ifndef VALUE_MAX
# if SIZEOF_VALUE == 8
# define VALUE_MAX 0xFFFFFFFFFFFFFFFFULL
# elif SIZEOF_VALUE == 4
# define VALUE_MAX 0xFFFFFFFFUL
# elif SIZEOF_LONG == SIZEOF_VOIDP
# define SIZEOF_VALUE 4
# define VALUE_MAX 0xFFFFFFFFUL
# endif
#endif
int
hx
,
hy
,
mask
=
VALUE_MAX
>>
((
SIZEOF_VALUE
-
m
)
*
CHAR_BIT
);
if
(
m
>
SIZEOF_VALUE
)
mrb_bug
(
"!!too long pattern string!!"
);
/* Prepare hash value */
for
(
hx
=
*
x
++
,
hy
=
*
y
++
;
x
<
xe
;
++
x
,
++
y
)
{
hx
<<=
CHAR_BIT
;
hy
<<=
CHAR_BIT
;
hx
|=
*
x
;
hy
|=
*
y
;
}
/* Searching */
while
(
hx
!=
hy
)
{
if
(
y
==
ye
)
return
-
1
;
hy
<<=
CHAR_BIT
;
hy
|=
*
y
;
hy
&=
mask
;
y
++
;
}
return
y
-
ys
-
m
;
}
static
inline
long
mrb_memsearch_qs
(
const
unsigned
char
*
xs
,
long
m
,
const
unsigned
char
*
ys
,
long
n
)
{
...
...
@@ -1464,6 +1334,7 @@ mrb_memsearch_qs(const unsigned char *xs, long m, const unsigned char *ys, long
}
return
-
1
;
}
int
mrb_memsearch
(
const
void
*
x0
,
int
m
,
const
void
*
y0
,
int
n
)
{
...
...
@@ -1484,12 +1355,7 @@ mrb_memsearch(const void *x0, int m, const void *y0, int n)
}
return
-
1
;
}
else
if
(
m
<=
SIZEOF_VALUE
)
{
return
mrb_memsearch_ss
(
x0
,
m
,
y0
,
n
);
}
else
{
return
mrb_memsearch_qs
(
x0
,
m
,
y0
,
n
);
}
}
#endif //INCLUDE_ENCODING
...
...
@@ -1507,33 +1373,6 @@ str_strlen(mrb_state *mrb, mrb_value str, mrb_encoding *enc)
p
=
RSTRING_PTR
(
str
);
e
=
RSTRING_END
(
str
);
cr
=
ENC_CODERANGE
(
str
);
#ifdef NONASCII_MASK
if
(
ENC_CODERANGE
(
str
)
==
ENC_CODERANGE_VALID
&&
enc
==
mrb_utf8_encoding
(
mrb
))
{
int
len
=
0
;
if
((
int
)
sizeof
(
intptr_t
)
*
2
<
e
-
p
)
{
const
intptr_t
*
s
,
*
t
;
const
intptr_t
lowbits
=
sizeof
(
int
)
-
1
;
s
=
(
const
intptr_t
*
)(
~
lowbits
&
((
intptr_t
)
p
+
lowbits
));
t
=
(
const
intptr_t
*
)(
~
lowbits
&
(
intptr_t
)
e
);
while
(
p
<
(
const
char
*
)
s
)
{
if
(
is_utf8_lead_byte
(
*
p
))
len
++
;
p
++
;
}
while
(
s
<
t
)
{
len
+=
count_utf8_lead_bytes_with_word
(
s
);
s
++
;
}
p
=
(
const
char
*
)
s
;
}
while
(
p
<
e
)
{
if
(
is_utf8_lead_byte
(
*
p
))
len
++
;
p
++
;
}
return
(
long
)
len
;
}
#endif
n
=
mrb_enc_strlen_cr
(
mrb
,
p
,
e
,
enc
,
&
cr
);
if
(
cr
)
{
ENC_CODERANGE_SET
(
str
,
cr
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment