~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/set_var.cc

  • Committer: Stewart Smith
  • Date: 2009-03-11 01:16:44 UTC
  • mto: (910.4.19 sparc) (937.2.1 sparc)
  • mto: This revision was merged to the branch mainline in revision 931.
  • Revision ID: stewart@flamingspork.com-20090311011644-sj4p2peox2405p7k
fix system variables for correct endian architectures.

- remove sys_var_long (replace with 32 or 64 bit)
- union { uint32_t, uint64_t } isn't endian portable for setting uint64 and reading from uint32
- start to have out of range variables throw error instead of truncating and setting

Show diffs side-by-side

added added

removed removed

Lines of Context:
109
109
static void fix_trans_mem_root(Session *session, enum_var_type type);
110
110
static void fix_server_id(Session *session, enum_var_type type);
111
111
static uint64_t fix_unsigned(Session *, uint64_t, const struct my_option *);
112
 
static bool get_unsigned(Session *session, set_var *var);
 
112
static bool get_unsigned32(Session *session, set_var *var);
 
113
static bool get_unsigned64(Session *session, set_var *var);
113
114
bool throw_bounds_warning(Session *session, bool fixed, bool unsignd,
114
115
                          const char *name, int64_t val);
115
116
static KEY_CACHE *create_key_cache(const char *name, uint32_t length);
183
184
                                         &opt_local_infile);
184
185
static sys_var_session_uint32_t sys_max_allowed_packet(&vars, "max_allowed_packet",
185
186
                                                       &SV::max_allowed_packet);
186
 
static sys_var_long_ptr sys_max_connect_errors(&vars, "max_connect_errors",
 
187
static sys_var_uint64_t_ptr     sys_max_connect_errors(&vars, "max_connect_errors",
187
188
                                               &max_connect_errors);
188
189
static sys_var_session_uint64_t sys_max_error_count(&vars, "max_error_count",
189
190
                                                  &SV::max_error_count);
204
205
                                                    &SV::max_sort_length);
205
206
static sys_var_session_uint64_t sys_max_tmp_tables(&vars, "max_tmp_tables",
206
207
                                                   &SV::max_tmp_tables);
207
 
static sys_var_long_ptr sys_max_write_lock_count(&vars, "max_write_lock_count",
 
208
static sys_var_uint64_t_ptr     sys_max_write_lock_count(&vars, "max_write_lock_count",
208
209
                                                 &max_write_lock_count);
209
210
static sys_var_session_uint64_t sys_min_examined_row_limit(&vars, "min_examined_row_limit",
210
211
                                                           &SV::min_examined_row_limit);
274
275
static sys_var_uint32_t_ptr  sys_server_id(&vars, "server_id", &server_id,
275
276
                                           fix_server_id);
276
277
 
277
 
static sys_var_long_ptr sys_slow_launch_time(&vars, "slow_launch_time",
 
278
static sys_var_uint64_t_ptr     sys_slow_launch_time(&vars, "slow_launch_time",
278
279
                                             &slow_launch_time);
279
280
static sys_var_session_size_t   sys_sort_buffer(&vars, "sort_buffer_size",
280
281
                                                &SV::sortbuff_size);
291
292
                                       &SV::table_plugin);
292
293
static sys_var_const_str        sys_system_time_zone(&vars, "system_time_zone",
293
294
                                             system_time_zone);
294
 
static sys_var_long_ptr sys_table_def_size(&vars, "table_definition_cache",
 
295
static sys_var_uint64_t_ptr     sys_table_def_size(&vars, "table_definition_cache",
295
296
                                           &table_def_size);
296
 
static sys_var_long_ptr sys_table_cache_size(&vars, "table_open_cache",
 
297
static sys_var_uint64_t_ptr     sys_table_cache_size(&vars, "table_open_cache",
297
298
                                             &table_cache_size);
298
 
static sys_var_long_ptr sys_table_lock_wait_timeout(&vars, "table_lock_wait_timeout",
 
299
static sys_var_uint64_t_ptr     sys_table_lock_wait_timeout(&vars, "table_lock_wait_timeout",
299
300
                                                    &table_lock_wait_timeout);
300
301
static sys_var_session_enum     sys_tx_isolation(&vars, "tx_isolation",
301
302
                                             &SV::tx_isolation,
639
640
    else
640
641
      llstr(val, buf);
641
642
 
642
 
    push_warning_printf(session, DRIZZLE_ERROR::WARN_LEVEL_WARN,
 
643
    push_warning_printf(session, DRIZZLE_ERROR::WARN_LEVEL_ERROR,
643
644
                        ER_TRUNCATED_WRONG_VALUE,
644
645
                        ER(ER_TRUNCATED_WRONG_VALUE), name, buf);
645
646
  }
667
668
  return out;
668
669
}
669
670
 
670
 
static bool get_unsigned(Session *, set_var *var)
671
 
{
672
 
  if (var->value->unsigned_flag)
673
 
    var->save_result.uint64_t_value= (uint64_t) var->value->val_int();
674
 
  else
675
 
  {
676
 
    int64_t v= var->value->val_int();
677
 
    var->save_result.uint64_t_value= (uint64_t) ((v < 0) ? 0 : v);
 
671
static bool get_unsigned32(Session *, set_var *var)
 
672
{
 
673
  if (var->value->unsigned_flag)
 
674
    var->save_result.uint32_t_value= (uint32_t) var->value->val_int();
 
675
  else
 
676
  {
 
677
    int64_t v= var->value->val_int();
 
678
    var->save_result.uint32_t_value= (uint32_t) ((v < 0) ? 0 : v);
 
679
  }
 
680
  return 0;
 
681
}
 
682
 
 
683
static bool get_unsigned64(Session *, set_var *var)
 
684
{
 
685
  if (var->value->unsigned_flag)
 
686
      var->save_result.uint64_t_value=(uint64_t) var->value->val_int();
 
687
  else
 
688
  {
 
689
    int64_t v= var->value->val_int();
 
690
      var->save_result.uint64_t_value= (uint64_t) ((v < 0) ? 0 : v);
678
691
  }
679
692
  return 0;
680
693
}
691
704
  return 0;
692
705
}
693
706
 
694
 
 
695
 
sys_var_long_ptr::
696
 
sys_var_long_ptr(sys_var_chain *chain, const char *name_arg, uint64_t *value_ptr_arg,
697
 
                 sys_after_update_func after_update_arg)
698
 
  :sys_var_long_ptr_global(chain, name_arg, value_ptr_arg,
699
 
                           &LOCK_global_system_variables, after_update_arg)
700
 
{}
701
 
 
702
 
 
703
 
bool sys_var_long_ptr_global::check(Session *session, set_var *var)
704
 
{
705
 
  return get_unsigned(session, var);
706
 
}
707
 
 
708
 
bool sys_var_long_ptr_global::update(Session *session, set_var *var)
709
 
{
710
 
  uint64_t tmp= var->save_result.uint64_t_value;
711
 
  pthread_mutex_lock(guard);
712
 
  if (option_limits)
713
 
    *value= (uint64_t) fix_unsigned(session, tmp, option_limits);
714
 
  else
715
 
  {
716
 
    if (tmp > UINT32_MAX)
717
 
    {
718
 
      tmp= UINT32_MAX;
719
 
      throw_bounds_warning(session, true, true, name,
720
 
                           (int64_t) var->save_result.uint64_t_value);
721
 
    }
722
 
    *value= (uint64_t) tmp;
723
 
  }
724
 
 
725
 
  pthread_mutex_unlock(guard);
 
707
bool sys_var_uint32_t_ptr::check(Session *, set_var *var)
 
708
{
 
709
  var->save_result.uint32_t_value= var->value->val_int();
726
710
  return 0;
727
711
}
728
712
 
729
 
 
730
 
void sys_var_long_ptr_global::set_default(Session *, enum_var_type)
731
 
{
732
 
  bool not_used;
733
 
  pthread_mutex_lock(guard);
734
 
  *value= (uint64_t) getopt_ull_limit_value((uint64_t) option_limits->def_value,
735
 
                                         option_limits, &not_used);
736
 
  pthread_mutex_unlock(guard);
737
 
}
738
 
 
739
713
bool sys_var_uint32_t_ptr::update(Session *session, set_var *var)
740
714
{
741
715
  uint32_t tmp= var->save_result.uint32_t_value;
742
716
  pthread_mutex_lock(&LOCK_global_system_variables);
743
717
  if (option_limits)
744
 
    *value= (uint32_t) fix_unsigned(session, tmp, option_limits);
 
718
  {
 
719
    uint32_t newvalue= (uint32_t) fix_unsigned(session, tmp, option_limits);
 
720
    if(newvalue==tmp)
 
721
      *value= newvalue;
 
722
  }
745
723
  else
746
724
    *value= (uint32_t) tmp;
747
725
  pthread_mutex_unlock(&LOCK_global_system_variables);
764
742
  uint64_t tmp= var->save_result.uint64_t_value;
765
743
  pthread_mutex_lock(&LOCK_global_system_variables);
766
744
  if (option_limits)
767
 
    *value= (uint64_t) fix_unsigned(session, tmp, option_limits);
 
745
  {
 
746
    uint64_t newvalue= (uint64_t) fix_unsigned(session, tmp, option_limits);
 
747
    if(newvalue==tmp)
 
748
      *value= newvalue;
 
749
  }
768
750
  else
769
751
    *value= (uint64_t) tmp;
770
752
  pthread_mutex_unlock(&LOCK_global_system_variables);
841
823
*/
842
824
bool sys_var_session_uint32_t::check(Session *session, set_var *var)
843
825
{
844
 
  return (get_unsigned(session, var) ||
 
826
  return (get_unsigned32(session, var) ||
845
827
          (check_func && (*check_func)(session, var)));
846
828
}
847
829
 
848
830
bool sys_var_session_uint32_t::update(Session *session, set_var *var)
849
831
{
850
 
  uint64_t tmp= var->save_result.uint64_t_value;
 
832
  uint64_t tmp= (uint64_t) var->save_result.uint32_t_value;
851
833
 
852
834
  /* Don't use bigger value than given with --maximum-variable-name=.. */
853
835
  if ((uint32_t) tmp > max_system_variables.*offset)
949
931
 
950
932
bool sys_var_session_uint64_t::check(Session *session, set_var *var)
951
933
{
952
 
  return (get_unsigned(session, var) ||
 
934
  return (get_unsigned64(session, var) ||
953
935
          (check_func && (*check_func)(session, var)));
954
936
}
955
937