mirror of
https://github.com/MariaDB/server.git
synced 2025-07-29 05:21:33 +03:00
simplify and unify my_safe_alloca usage
This commit is contained in:
@ -205,16 +205,17 @@ extern void my_large_free(uchar *ptr);
|
|||||||
#endif /* GNUC */
|
#endif /* GNUC */
|
||||||
#define my_alloca(SZ) alloca((size_t) (SZ))
|
#define my_alloca(SZ) alloca((size_t) (SZ))
|
||||||
#define my_afree(PTR) ((void)0)
|
#define my_afree(PTR) ((void)0)
|
||||||
#define my_safe_alloca(size, max_alloca_sz) ((size <= max_alloca_sz) ? \
|
#define MAX_ALLOCA_SZ 4096
|
||||||
my_alloca(size) : \
|
#define my_safe_alloca(size) (((size) <= MAX_ALLOCA_SZ) ? \
|
||||||
my_malloc(size, MYF(0)))
|
my_alloca(size) : \
|
||||||
#define my_safe_afree(ptr, size, max_alloca_sz) if (size > max_alloca_sz) \
|
my_malloc((size), MYF(MY_THREAD_SPECIFIC|MY_WME)))
|
||||||
my_free(ptr)
|
#define my_safe_afree(ptr, size) \
|
||||||
|
do { if ((size) > MAX_ALLOCA_SZ) my_free(ptr); } while(0)
|
||||||
#else
|
#else
|
||||||
#define my_alloca(SZ) my_malloc(SZ,MYF(MY_FAE))
|
#define my_alloca(SZ) my_malloc(SZ,MYF(MY_FAE))
|
||||||
#define my_afree(PTR) my_free(PTR)
|
#define my_afree(PTR) my_free(PTR)
|
||||||
#define my_safe_alloca(size, max_alloca_sz) my_alloca(size)
|
#define my_safe_alloca(size) my_alloca(size)
|
||||||
#define my_safe_afree(ptr, size, max_alloca_sz) my_afree(ptr)
|
#define my_safe_afree(ptr, size) my_afree(ptr)
|
||||||
#endif /* HAVE_ALLOCA */
|
#endif /* HAVE_ALLOCA */
|
||||||
|
|
||||||
#ifndef errno /* did we already get it? */
|
#ifndef errno /* did we already get it? */
|
||||||
|
@ -1670,8 +1670,7 @@ int write_record(THD *thd, TABLE *table,COPY_INFO *info)
|
|||||||
|
|
||||||
if (!key)
|
if (!key)
|
||||||
{
|
{
|
||||||
if (!(key=(char*) my_safe_alloca(table->s->max_unique_length,
|
if (!(key=(char*) my_safe_alloca(table->s->max_unique_length)))
|
||||||
MAX_KEY_LENGTH)))
|
|
||||||
{
|
{
|
||||||
error=ENOMEM;
|
error=ENOMEM;
|
||||||
goto err;
|
goto err;
|
||||||
@ -1897,7 +1896,7 @@ after_trg_n_copied_inc:
|
|||||||
|
|
||||||
ok_or_after_trg_err:
|
ok_or_after_trg_err:
|
||||||
if (key)
|
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())
|
if (!table->file->has_transactions())
|
||||||
thd->transaction.stmt.modified_non_trans_table= TRUE;
|
thd->transaction.stmt.modified_non_trans_table= TRUE;
|
||||||
DBUG_RETURN(trg_error);
|
DBUG_RETURN(trg_error);
|
||||||
@ -1909,7 +1908,7 @@ err:
|
|||||||
before_trg_err:
|
before_trg_err:
|
||||||
table->file->restore_auto_increment(prev_insert_id);
|
table->file->restore_auto_increment(prev_insert_id);
|
||||||
if (key)
|
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);
|
table->column_bitmaps_set(save_read_set, save_write_set);
|
||||||
DBUG_RETURN(1);
|
DBUG_RETURN(1);
|
||||||
}
|
}
|
||||||
|
@ -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
|
Don't allocate more than 16K on the stack to ensure we don't get
|
||||||
stack overflow.
|
stack overflow.
|
||||||
*/
|
*/
|
||||||
if (!(old_record= my_safe_alloca(info->s->base.reclength,
|
if (!(old_record= my_safe_alloca(info->s->base.reclength)))
|
||||||
MARIA_MAX_RECORD_ON_STACK)))
|
|
||||||
DBUG_RETURN(1);
|
DBUG_RETURN(1);
|
||||||
|
|
||||||
/* Don't let the compare destroy blobs that may be in use */
|
/* 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;
|
info->rec_buff_size= org_rec_buff_size;
|
||||||
}
|
}
|
||||||
DBUG_PRINT("exit", ("result: %d", error));
|
DBUG_PRINT("exit", ("result: %d", error));
|
||||||
my_safe_afree(old_record, info->s->base.reclength,
|
my_safe_afree(old_record, info->s->base.reclength);
|
||||||
MARIA_MAX_RECORD_ON_STACK);
|
|
||||||
DBUG_RETURN(error != 0);
|
DBUG_RETURN(error != 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -250,8 +250,7 @@ my_bool _ma_write_blob_record(MARIA_HA *info, const uchar *record)
|
|||||||
MARIA_DYN_DELETE_BLOCK_HEADER+1);
|
MARIA_DYN_DELETE_BLOCK_HEADER+1);
|
||||||
reclength= (info->s->base.pack_reclength +
|
reclength= (info->s->base.pack_reclength +
|
||||||
_ma_calc_total_blob_length(info,record)+ extra);
|
_ma_calc_total_blob_length(info,record)+ extra);
|
||||||
if (!(rec_buff=(uchar*) my_safe_alloca(reclength,
|
if (!(rec_buff=(uchar*) my_safe_alloca(reclength)))
|
||||||
MARIA_MAX_RECORD_ON_STACK)))
|
|
||||||
{
|
{
|
||||||
my_errno= HA_ERR_OUT_OF_MEM; /* purecov: inspected */
|
my_errno= HA_ERR_OUT_OF_MEM; /* purecov: inspected */
|
||||||
return(1);
|
return(1);
|
||||||
@ -265,7 +264,7 @@ my_bool _ma_write_blob_record(MARIA_HA *info, const uchar *record)
|
|||||||
error= write_dynamic_record(info,
|
error= write_dynamic_record(info,
|
||||||
rec_buff+ALIGN_SIZE(MARIA_MAX_DYN_BLOCK_HEADER),
|
rec_buff+ALIGN_SIZE(MARIA_MAX_DYN_BLOCK_HEADER),
|
||||||
reclength2);
|
reclength2);
|
||||||
my_safe_afree(rec_buff, reclength, MARIA_MAX_RECORD_ON_STACK);
|
my_safe_afree(rec_buff, reclength);
|
||||||
return(error != 0);
|
return(error != 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -289,8 +288,7 @@ my_bool _ma_update_blob_record(MARIA_HA *info, MARIA_RECORD_POS pos,
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
if (!(rec_buff=(uchar*) my_safe_alloca(reclength,
|
if (!(rec_buff=(uchar*) my_safe_alloca(reclength)))
|
||||||
MARIA_MAX_RECORD_ON_STACK)))
|
|
||||||
{
|
{
|
||||||
my_errno= HA_ERR_OUT_OF_MEM; /* purecov: inspected */
|
my_errno= HA_ERR_OUT_OF_MEM; /* purecov: inspected */
|
||||||
return(1);
|
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,
|
error=update_dynamic_record(info,pos,
|
||||||
rec_buff+ALIGN_SIZE(MARIA_MAX_DYN_BLOCK_HEADER),
|
rec_buff+ALIGN_SIZE(MARIA_MAX_DYN_BLOCK_HEADER),
|
||||||
reclength);
|
reclength);
|
||||||
my_safe_afree(rec_buff, reclength, MARIA_MAX_RECORD_ON_STACK);
|
my_safe_afree(rec_buff, reclength);
|
||||||
return(error != 0);
|
return(error != 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1555,8 +1553,7 @@ my_bool _ma_cmp_dynamic_unique(MARIA_HA *info, MARIA_UNIQUEDEF *def,
|
|||||||
my_bool error;
|
my_bool error;
|
||||||
DBUG_ENTER("_ma_cmp_dynamic_unique");
|
DBUG_ENTER("_ma_cmp_dynamic_unique");
|
||||||
|
|
||||||
if (!(old_record= my_safe_alloca(info->s->base.reclength,
|
if (!(old_record= my_safe_alloca(info->s->base.reclength)))
|
||||||
MARIA_MAX_RECORD_ON_STACK)))
|
|
||||||
DBUG_RETURN(1);
|
DBUG_RETURN(1);
|
||||||
|
|
||||||
/* Don't let the compare destroy blobs that may be in use */
|
/* 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= old_rec_buff;
|
||||||
info->rec_buff_size= old_rec_buff_size;
|
info->rec_buff_size= old_rec_buff_size;
|
||||||
}
|
}
|
||||||
my_safe_afree(old_record, info->s->base.reclength,
|
my_safe_afree(old_record, info->s->base.reclength);
|
||||||
MARIA_MAX_RECORD_ON_STACK);
|
|
||||||
DBUG_RETURN(error);
|
DBUG_RETURN(error);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1613,8 +1609,7 @@ my_bool _ma_cmp_dynamic_record(register MARIA_HA *info,
|
|||||||
{
|
{
|
||||||
buffer_length= (info->s->base.pack_reclength +
|
buffer_length= (info->s->base.pack_reclength +
|
||||||
_ma_calc_total_blob_length(info,record));
|
_ma_calc_total_blob_length(info,record));
|
||||||
if (!(buffer=(uchar*) my_safe_alloca(buffer_length,
|
if (!(buffer=(uchar*) my_safe_alloca(buffer_length)))
|
||||||
MARIA_MAX_RECORD_ON_STACK)))
|
|
||||||
DBUG_RETURN(1);
|
DBUG_RETURN(1);
|
||||||
}
|
}
|
||||||
reclength= _ma_rec_pack(info,buffer,record);
|
reclength= _ma_rec_pack(info,buffer,record);
|
||||||
@ -1666,7 +1661,7 @@ my_bool _ma_cmp_dynamic_record(register MARIA_HA *info,
|
|||||||
error= 0;
|
error= 0;
|
||||||
err:
|
err:
|
||||||
if (buffer != info->rec_buff)
|
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_PRINT("exit", ("result: %d", error));
|
||||||
DBUG_RETURN(error);
|
DBUG_RETURN(error);
|
||||||
}
|
}
|
||||||
|
@ -861,7 +861,7 @@ static int get_statistic(PACK_MRG_INFO *mrg,HUFF_COUNTS *huff_counts)
|
|||||||
|
|
||||||
reclength= mrg->file[0]->s->base.reclength;
|
reclength= mrg->file[0]->s->base.reclength;
|
||||||
null_bytes= mrg->file[0]->s->base.null_bytes;
|
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;
|
end_count=huff_counts+mrg->file[0]->s->base.fields;
|
||||||
record_count=0; glob_crc=0;
|
record_count=0; glob_crc=0;
|
||||||
max_blob_length=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->records=record_count;
|
||||||
mrg->max_blob_length=max_blob_length;
|
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);
|
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");
|
DBUG_ENTER("compress_maria_file");
|
||||||
|
|
||||||
/* Allocate a buffer for the records (excluding blobs). */
|
/* Allocate a buffer for the records (excluding blobs). */
|
||||||
if (!(record=(uchar*) my_safe_alloca(isam_file->s->base.reclength,
|
if (!(record=(uchar*) my_safe_alloca(isam_file->s->base.reclength)))
|
||||||
MARIA_MAX_RECORD_ON_STACK)))
|
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
end_count=huff_counts+isam_file->s->base.fields;
|
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)
|
if (verbose >= 2)
|
||||||
printf("wrote %s records.\n", llstr((longlong) record_count, llbuf));
|
printf("wrote %s records.\n", llstr((longlong) record_count, llbuf));
|
||||||
|
|
||||||
my_safe_afree(record, isam_file->s->base.reclength,
|
my_safe_afree(record, isam_file->s->base.reclength);
|
||||||
MARIA_MAX_RECORD_ON_STACK);
|
|
||||||
mrg->ref_length=max_pack_length;
|
mrg->ref_length=max_pack_length;
|
||||||
mrg->min_pack_length=max_record_length ? min_record_length : 0;
|
mrg->min_pack_length=max_record_length ? min_record_length : 0;
|
||||||
mrg->max_pack_length=max_record_length;
|
mrg->max_pack_length=max_record_length;
|
||||||
|
Reference in New Issue
Block a user