Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
M
mariadb
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
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
mariadb
Commits
4569a895
Commit
4569a895
authored
Aug 11, 2015
by
Sergei Golubchik
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
simplify and unify my_safe_alloca usage
parent
b6776b3c
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
25 additions
and
34 deletions
+25
-34
include/my_sys.h
include/my_sys.h
+8
-7
sql/sql_insert.cc
sql/sql_insert.cc
+3
-4
storage/maria/ma_blockrec.c
storage/maria/ma_blockrec.c
+2
-4
storage/maria/ma_dynrec.c
storage/maria/ma_dynrec.c
+8
-13
storage/maria/maria_pack.c
storage/maria/maria_pack.c
+4
-6
No files found.
include/my_sys.h
View file @
4569a895
...
...
@@ -205,16 +205,17 @@ extern void my_large_free(uchar *ptr);
#endif
/* GNUC */
#define my_alloca(SZ) alloca((size_t) (SZ))
#define my_afree(PTR) ((void)0)
#define my_safe_alloca(size, max_alloca_sz) ((size <= max_alloca_sz) ? \
my_alloca(size) : \
my_malloc(size, MYF(0)))
#define my_safe_afree(ptr, size, max_alloca_sz) if (size > max_alloca_sz) \
my_free(ptr)
#define MAX_ALLOCA_SZ 4096
#define my_safe_alloca(size) (((size) <= MAX_ALLOCA_SZ) ? \
my_alloca(size) : \
my_malloc((size), MYF(MY_THREAD_SPECIFIC|MY_WME)))
#define my_safe_afree(ptr, size) \
do { if ((size) > MAX_ALLOCA_SZ) my_free(ptr); } while(0)
#else
#define my_alloca(SZ) my_malloc(SZ,MYF(MY_FAE))
#define my_afree(PTR) my_free(PTR)
#define my_safe_alloca(size
, max_alloca_sz
) my_alloca(size)
#define my_safe_afree(ptr, size
, max_alloca_sz
) my_afree(ptr)
#define my_safe_alloca(size) my_alloca(size)
#define my_safe_afree(ptr, size) my_afree(ptr)
#endif
/* HAVE_ALLOCA */
#ifndef errno
/* did we already get it? */
...
...
sql/sql_insert.cc
View file @
4569a895
...
...
@@ -1670,8 +1670,7 @@ int write_record(THD *thd, TABLE *table,COPY_INFO *info)
if
(
!
key
)
{
if
(
!
(
key
=
(
char
*
)
my_safe_alloca
(
table
->
s
->
max_unique_length
,
MAX_KEY_LENGTH
)))
if
(
!
(
key
=
(
char
*
)
my_safe_alloca
(
table
->
s
->
max_unique_length
)))
{
error
=
ENOMEM
;
goto
err
;
...
...
@@ -1897,7 +1896,7 @@ after_trg_n_copied_inc:
ok_or_after_trg_err:
if
(
key
)
my_safe_afree
(
key
,
table
->
s
->
max_unique_length
,
MAX_KEY_LENGTH
);
my_safe_afree
(
key
,
table
->
s
->
max_unique_length
);
if
(
!
table
->
file
->
has_transactions
())
thd
->
transaction
.
stmt
.
modified_non_trans_table
=
TRUE
;
DBUG_RETURN
(
trg_error
);
...
...
@@ -1909,7 +1908,7 @@ err:
before_trg_err:
table
->
file
->
restore_auto_increment
(
prev_insert_id
);
if
(
key
)
my_safe_afree
(
key
,
table
->
s
->
max_unique_length
,
MAX_KEY_LENGTH
);
my_safe_afree
(
key
,
table
->
s
->
max_unique_length
);
table
->
column_bitmaps_set
(
save_read_set
,
save_write_set
);
DBUG_RETURN
(
1
);
}
...
...
storage/maria/ma_blockrec.c
View file @
4569a895
...
...
@@ -5187,8 +5187,7 @@ my_bool _ma_cmp_block_unique(MARIA_HA *info, MARIA_UNIQUEDEF *def,
Don't allocate more than 16K on the stack to ensure we don't get
stack overflow.
*/
if
(
!
(
old_record
=
my_safe_alloca
(
info
->
s
->
base
.
reclength
,
MARIA_MAX_RECORD_ON_STACK
)))
if
(
!
(
old_record
=
my_safe_alloca
(
info
->
s
->
base
.
reclength
)))
DBUG_RETURN
(
1
);
/* Don't let the compare destroy blobs that may be in use */
...
...
@@ -5210,8 +5209,7 @@ my_bool _ma_cmp_block_unique(MARIA_HA *info, MARIA_UNIQUEDEF *def,
info
->
rec_buff_size
=
org_rec_buff_size
;
}
DBUG_PRINT
(
"exit"
,
(
"result: %d"
,
error
));
my_safe_afree
(
old_record
,
info
->
s
->
base
.
reclength
,
MARIA_MAX_RECORD_ON_STACK
);
my_safe_afree
(
old_record
,
info
->
s
->
base
.
reclength
);
DBUG_RETURN
(
error
!=
0
);
}
...
...
storage/maria/ma_dynrec.c
View file @
4569a895
...
...
@@ -250,8 +250,7 @@ my_bool _ma_write_blob_record(MARIA_HA *info, const uchar *record)
MARIA_DYN_DELETE_BLOCK_HEADER
+
1
);
reclength
=
(
info
->
s
->
base
.
pack_reclength
+
_ma_calc_total_blob_length
(
info
,
record
)
+
extra
);
if
(
!
(
rec_buff
=
(
uchar
*
)
my_safe_alloca
(
reclength
,
MARIA_MAX_RECORD_ON_STACK
)))
if
(
!
(
rec_buff
=
(
uchar
*
)
my_safe_alloca
(
reclength
)))
{
my_errno
=
HA_ERR_OUT_OF_MEM
;
/* purecov: inspected */
return
(
1
);
...
...
@@ -265,7 +264,7 @@ my_bool _ma_write_blob_record(MARIA_HA *info, const uchar *record)
error
=
write_dynamic_record
(
info
,
rec_buff
+
ALIGN_SIZE
(
MARIA_MAX_DYN_BLOCK_HEADER
),
reclength2
);
my_safe_afree
(
rec_buff
,
reclength
,
MARIA_MAX_RECORD_ON_STACK
);
my_safe_afree
(
rec_buff
,
reclength
);
return
(
error
!=
0
);
}
...
...
@@ -289,8 +288,7 @@ my_bool _ma_update_blob_record(MARIA_HA *info, MARIA_RECORD_POS pos,
return
1
;
}
#endif
if
(
!
(
rec_buff
=
(
uchar
*
)
my_safe_alloca
(
reclength
,
MARIA_MAX_RECORD_ON_STACK
)))
if
(
!
(
rec_buff
=
(
uchar
*
)
my_safe_alloca
(
reclength
)))
{
my_errno
=
HA_ERR_OUT_OF_MEM
;
/* purecov: inspected */
return
(
1
);
...
...
@@ -300,7 +298,7 @@ my_bool _ma_update_blob_record(MARIA_HA *info, MARIA_RECORD_POS pos,
error
=
update_dynamic_record
(
info
,
pos
,
rec_buff
+
ALIGN_SIZE
(
MARIA_MAX_DYN_BLOCK_HEADER
),
reclength
);
my_safe_afree
(
rec_buff
,
reclength
,
MARIA_MAX_RECORD_ON_STACK
);
my_safe_afree
(
rec_buff
,
reclength
);
return
(
error
!=
0
);
}
...
...
@@ -1555,8 +1553,7 @@ my_bool _ma_cmp_dynamic_unique(MARIA_HA *info, MARIA_UNIQUEDEF *def,
my_bool
error
;
DBUG_ENTER
(
"_ma_cmp_dynamic_unique"
);
if
(
!
(
old_record
=
my_safe_alloca
(
info
->
s
->
base
.
reclength
,
MARIA_MAX_RECORD_ON_STACK
)))
if
(
!
(
old_record
=
my_safe_alloca
(
info
->
s
->
base
.
reclength
)))
DBUG_RETURN
(
1
);
/* Don't let the compare destroy blobs that may be in use */
...
...
@@ -1577,8 +1574,7 @@ my_bool _ma_cmp_dynamic_unique(MARIA_HA *info, MARIA_UNIQUEDEF *def,
info
->
rec_buff
=
old_rec_buff
;
info
->
rec_buff_size
=
old_rec_buff_size
;
}
my_safe_afree
(
old_record
,
info
->
s
->
base
.
reclength
,
MARIA_MAX_RECORD_ON_STACK
);
my_safe_afree
(
old_record
,
info
->
s
->
base
.
reclength
);
DBUG_RETURN
(
error
);
}
...
...
@@ -1613,8 +1609,7 @@ my_bool _ma_cmp_dynamic_record(register MARIA_HA *info,
{
buffer_length
=
(
info
->
s
->
base
.
pack_reclength
+
_ma_calc_total_blob_length
(
info
,
record
));
if
(
!
(
buffer
=
(
uchar
*
)
my_safe_alloca
(
buffer_length
,
MARIA_MAX_RECORD_ON_STACK
)))
if
(
!
(
buffer
=
(
uchar
*
)
my_safe_alloca
(
buffer_length
)))
DBUG_RETURN
(
1
);
}
reclength
=
_ma_rec_pack
(
info
,
buffer
,
record
);
...
...
@@ -1666,7 +1661,7 @@ my_bool _ma_cmp_dynamic_record(register MARIA_HA *info,
error
=
0
;
err:
if
(
buffer
!=
info
->
rec_buff
)
my_safe_afree
(
buffer
,
buffer_length
,
MARIA_MAX_RECORD_ON_STACK
);
my_safe_afree
(
buffer
,
buffer_length
);
DBUG_PRINT
(
"exit"
,
(
"result: %d"
,
error
));
DBUG_RETURN
(
error
);
}
...
...
storage/maria/maria_pack.c
View file @
4569a895
...
...
@@ -861,7 +861,7 @@ static int get_statistic(PACK_MRG_INFO *mrg,HUFF_COUNTS *huff_counts)
reclength
=
mrg
->
file
[
0
]
->
s
->
base
.
reclength
;
null_bytes
=
mrg
->
file
[
0
]
->
s
->
base
.
null_bytes
;
record
=
(
uchar
*
)
my_safe_alloca
(
reclength
,
MARIA_MAX_RECORD_ON_STACK
);
record
=
(
uchar
*
)
my_safe_alloca
(
reclength
);
end_count
=
huff_counts
+
mrg
->
file
[
0
]
->
s
->
base
.
fields
;
record_count
=
0
;
glob_crc
=
0
;
max_blob_length
=
0
;
...
...
@@ -1145,7 +1145,7 @@ static int get_statistic(PACK_MRG_INFO *mrg,HUFF_COUNTS *huff_counts)
mrg
->
records
=
record_count
;
mrg
->
max_blob_length
=
max_blob_length
;
my_safe_afree
(
record
,
reclength
,
MARIA_MAX_RECORD_ON_STACK
);
my_safe_afree
(
record
,
reclength
);
DBUG_RETURN
(
error
!=
HA_ERR_END_OF_FILE
);
}
...
...
@@ -2415,8 +2415,7 @@ static int compress_maria_file(PACK_MRG_INFO *mrg, HUFF_COUNTS *huff_counts)
DBUG_ENTER
(
"compress_maria_file"
);
/* Allocate a buffer for the records (excluding blobs). */
if
(
!
(
record
=
(
uchar
*
)
my_safe_alloca
(
isam_file
->
s
->
base
.
reclength
,
MARIA_MAX_RECORD_ON_STACK
)))
if
(
!
(
record
=
(
uchar
*
)
my_safe_alloca
(
isam_file
->
s
->
base
.
reclength
)))
return
-
1
;
end_count
=
huff_counts
+
isam_file
->
s
->
base
.
fields
;
...
...
@@ -2779,8 +2778,7 @@ static int compress_maria_file(PACK_MRG_INFO *mrg, HUFF_COUNTS *huff_counts)
if
(
verbose
>=
2
)
printf
(
"wrote %s records.
\n
"
,
llstr
((
longlong
)
record_count
,
llbuf
));
my_safe_afree
(
record
,
isam_file
->
s
->
base
.
reclength
,
MARIA_MAX_RECORD_ON_STACK
);
my_safe_afree
(
record
,
isam_file
->
s
->
base
.
reclength
);
mrg
->
ref_length
=
max_pack_length
;
mrg
->
min_pack_length
=
max_record_length
?
min_record_length
:
0
;
mrg
->
max_pack_length
=
max_record_length
;
...
...
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