bug (15/26)

Brian Grossman briang@gomer.fc.hp.com
Tue Sep 8 21:44:00 GMT 1998


  static void *operator new(size_t size) { return (void*) sql_alloc(size); }
  static void operator delete(void *ptr,size_t size  )  
    { sql_element_free(ptr); }
  ~String() { free(); }

  inline uint length() const { return str_length;}
  inline uint alloced_length() const { return Alloced_length;}
  inline char& operator [] (uint i) const { return Ptr[i]; }
  inline void length(uint len) { str_length=len ; }
  inline bool is_empty() { return (str_length == 0); }
  inline const char *ptr() const { return Ptr; }
  inline char *c_ptr()
  {
    if (!Ptr || Ptr[str_length])		 
      (void) realloc(str_length);
    return Ptr;
  }
  inline char *c_ptr_quick()
  {
    if (Ptr && str_length < Alloced_length)
      Ptr[str_length]=0;
    return Ptr;
  }

  void set(String &str,uint offset,uint length)
  {
    free();
    Ptr=(char*) str.ptr()+offset; str_length=length; alloced=0;
    if (str.Alloced_length)
      Alloced_length=str.Alloced_length-offset;
    else
      Alloced_length=0;
  }
  inline void set(char *str,uint length)
  {
    free();
    Ptr=(char*) str; str_length=length; Alloced_length=length ; alloced=0;
  }
  inline void set(const char *str,uint length)
  {
    free();
    Ptr=(char*) str; str_length=length; Alloced_length=0 ; alloced=0;
  }
  inline void set_quick(char *str,uint length)
  {
    if (!alloced)
    {
      Ptr=(char*) str; str_length=length; Alloced_length=length;
    }
  }
  void set(longlong num);
   
  void set(double num,uint decimals=2);
  inline void free()
    {
      if (alloced)
      {
	alloced=0;
	my_no_flags_free( Ptr ) ;
	Ptr=0;
      }
    }

  inline bool alloc(uint length)
  {
    if (length < Alloced_length)
      return 0;
    return real_alloc(length);
  }
  bool real_alloc(uint length);			 
  bool realloc(uint length);
  inline void shrink(uint length)		 
  {
    if (length < Alloced_length)
    {
      char *new_ptr;
      if (!(new_ptr=my_realloc(Ptr,length,(myf) ( 0 ) )))
      {
	(void) my_no_flags_free( Ptr ) ;
	real_alloc(length);
      }
      else
      {
	Ptr=new_ptr;
	Alloced_length=length;
      }
    }
  }
  bool is_alloced() { return alloced; }
  inline String& operator = (const String &s)
  {
    if (&s != this)
    {
      free();
      Ptr=s.Ptr ; str_length=s.str_length ; Alloced_length=s.Alloced_length;
      alloced=0;
    }
    return *this;
  }

  void copy();					 
  void copy(const String &s);			 
  void copy(const char *s,uint length);		 
  void append(const String &s);
  void append(const char *s,uint length=0);
  int strstr(const String &search,uint offset=0);  
  int strrstr(const String &search,uint offset=0);  
  void replace(uint offset,uint length,const String &to);
  inline bool append(char chr)
  {
    if (str_length < Alloced_length)
    {
      Ptr[str_length++]=chr;
    }
    else
    {
      if (realloc(str_length+1))
	return 1;
      Ptr[str_length++]=chr;
    }
    return 0;
  }
  void fill(uint max_length,char fill);
  void strip_sp();
  inline void caseup() { ::caseup(Ptr,str_length); }
  inline void casedn() { ::casedn(Ptr,str_length); }
  friend int sortcmp(const String *a,const String *b);
  friend int stringcmp(const String *a,const String *b);
  friend String *copy_if_not_alloced(String *a,String *b,uint length);
  friend int wild_case_compare(String &match,String &wild);
};
# 125 "mysql_priv.h" 2

# 1 "sql_list.h" 1
 













 


#pragma interface			



class Sql_alloc
{
public:
  static void *operator new(size_t size) {return (void*) sql_alloc(size); }
  static void operator delete(void *ptr  ,
			      size_t size  ) {}  
  inline Sql_alloc() {};
  inline ~Sql_alloc() {};
};

 




class base_list :public Sql_alloc {
protected:
  class list_node :public Sql_alloc
  {
public:
    list_node *next;
    void *info;
    list_node(void *info_par,list_node *next_par) : next(next_par),info(info_par) {}
    friend class base_list;
    friend class base_list_iterator;
  };
  list_node *first,**last;

public:
  uint elements;

  inline void empty() { elements=0; first=0; last=&first;}
  inline base_list() { empty(); }
  inline base_list(const base_list &tmp) :Sql_alloc()
  {
    elements=tmp.elements;
    first=tmp.first;
    last=tmp.last;
  }
  inline bool push_back(void *info)
  {
    if (((*last)=new list_node(info,0)))
    {
      last= &(*last)->next;
      elements++;
      return 0;
    }
    return 1;
  }
  inline bool push_front(void *info)
  {
    list_node *node=new list_node(info,first);
    if (node)
    {
      if (!first)
	last= &node->next;
      first=node;
      elements++;
      return 0;
    }
    return 1;
  }
  void remove(list_node **prev)
  {
    list_node *node=(*prev)->next;
    delete *prev;
    *prev=node;
    if (!--elements)
      last= &first;
  }
  inline void *pop(void)
  {
    if (!first) return 0;
    list_node *tmp=first;
    first=first->next;
    if (!--elements)
      last= &first;
    return tmp->info;
  }
  inline void *head() { return first ? first->info : 0; }
  inline void **head_ref() { return first ? &first->info : 0; }
  friend class base_list_iterator;

protected:
  void after(void *info,list_node *node)
  {
    list_node *new_node=new list_node(info,node->next);
    node->next=new_node;
    elements++;
  }
};


class base_list_iterator
{
  base_list *list;
  base_list::list_node **el,**prev,*current;
public:
  base_list_iterator(base_list &list_par) :list(&list_par),el(&list_par.first),
    prev(0),current(0)
  {}
  inline void *next(void)
  {
    prev=el;
    if (!(current= *el))
      return 0;
    el= &current->next;
    return current->info;
  }
  inline void rewind(void)
  {
    el= &list->first;
  }
  void *replace(void *element)
  {						 
    void *tmp=current->info;
    current->info=element;
    return tmp;
  }
  void *replace(base_list &new_list)
  {
    void *ret_value=current->info;
    if (new_list.first)
    {
      *new_list.last=current->next;
      current->info=new_list.first->info;
      current->next=new_list.first->next;
      list->elements+=new_list.elements-1;
    }
    return ret_value;				 
  }
  inline void remove(void)			 
  {
    list->remove(prev);
    el=prev;
    current=0;					 
  }
  void after(void *element)			 
  {
    list->after(element,current);
    current=current->next;
    el= &current->next;
  }
  inline void **ref()				 
  {
    return &current->info;
  }
};


template <class T> class List :public base_list
{
public:
  inline List() :base_list() {}
  inline List(const List<T> &tmp) :base_list(tmp) {}
  inline bool push_back(T *a) { return base_list::push_back(a); }
  inline bool push_front(T *a) { return base_list::push_front(a); }
  inline T* head() {return (T*) base_list::head(); }
  inline T* pop()  {return (T*) base_list::pop(); }
  void delete_elements(void)
  {
    list_node *element,*next;
    for (element=first; element ; element=next)
    {
      next=element->next;
      delete (T*) element->info;
    }
    empty();
  }
};


template <class T> class List_iterator :public base_list_iterator
{
public:
  List_iterator(List<T> &a) : base_list_iterator(a) {}
  inline T* operator++(int) { return (T*) base_list_iterator::next(); }
  inline void rewind(void)  { base_list_iterator::rewind(); }
  inline T *replace(T *a)   { return (T*) base_list_iterator::replace(a); }
  inline T *replace(List<T> &a) { return (T*) base_list_iterator::replace(a); }
  inline void remove(void)  { base_list_iterator::remove(); }
  inline void after(T *a)   { base_list_iterator::after(a); }
  inline T** ref()	    { return (T**) base_list_iterator::ref(); }
};


 




struct ilink {
  struct ilink **prev,*next;
  inline ilink()
  {
    prev=0; next=0;
  }
  inline void unlink()
  {
    if (prev) *prev= next;
    if (next) next->prev=prev;
    prev=0 ; next=0;
  }
  virtual ~ilink() { unlink(); }  
};

template <class T> class I_List_iterator;

class base_ilist {
  public:
  struct ilink *first;
  base_ilist() { first=0; }
  inline void append(ilink *a)
  {
    if (first)
      first->prev=&a->next;
    a->next=first; a->prev=&first; first=a;
  }
  inline struct ilink *get()
  {
    struct ilink *link=first;
    if (link)
      link->unlink();				 
    return link;
  }
  friend class base_list_iterator;
};


class base_ilist_iterator
{
  base_ilist *list;
  struct ilink *el,*current;
public:
  base_ilist_iterator(base_ilist &list_par) :list(&list_par),el(list_par.first),current(0) {}
  void *next(void)
  {
    current=el;
    if (!el) return 0;
    el=el->next;
    return current;
  }
};


template <class T>
class I_List :private base_ilist {
public:
  I_List() :base_ilist() {}
  void append(T* a) { base_ilist::append(a); }
  inline T* get()   { return (T*) base_ilist::get(); }

  friend class I_List_iterator<T>;

};


template <class T> class I_List_iterator :public base_ilist_iterator
{
public:
  I_List_iterator(I_List<T> &a) : base_ilist_iterator(a) {}
  inline T* operator++(int) { return (T*) base_ilist_iterator::next(); }
};
# 126 "mysql_priv.h" 2

# 1 "sql_map.h" 1
 













 


#pragma interface			


class mapped_files :public ilink {
  byte *map;
  ulong size;
  char *name;					 
  File file;					 
  int  error;					 
  uint use_count;

public:
  mapped_files(const my_string name,byte *magic,uint magic_length);
  ~mapped_files();

  friend class mapped_file;
  friend mapped_files *map_file(const my_string name,byte *magic,
				uint magic_length);
  friend void unmap_file(mapped_files *map);
};


class mapped_file
{
  mapped_files *file;
public:
  mapped_file(const my_string name,byte *magic,uint magic_length)
  {
    file=map_file(name,magic,magic_length);	 
  }
  ~mapped_file()
  {
    unmap_file(file);				 
  }
  byte *map()
  {
    return file->map;
  }
};
# 127 "mysql_priv.h" 2

# 1 "../include/my_base.h" 1
 


 
 




# 24 "../include/my_base.h"



	 





	 

enum ha_rkey_function {
  HA_READ_KEY_EXACT,			 
  HA_READ_KEY_OR_NEXT,			 
  HA_READ_KEY_OR_PREV,			 
  HA_READ_AFTER_KEY,			 
  HA_READ_BEFORE_KEY			 
};

	 

enum ha_extra_function {
  HA_EXTRA_NORMAL=0,			 
  HA_EXTRA_QUICK=1,			 
  HA_EXTRA_RESET=2,			 
  HA_EXTRA_CACHE=3,			 
  HA_EXTRA_NO_CACHE=4,			 
  HA_EXTRA_NO_READCHECK=5,		 
  HA_EXTRA_READCHECK=6,			 
  HA_EXTRA_KEYREAD=7,			 
  HA_EXTRA_NO_KEYREAD=8,		 
  HA_EXTRA_NO_USER_CHANGE=9,		 
  HA_EXTRA_KEY_CACHE=10,
  HA_EXTRA_NO_KEY_CACHE=11,
  HA_EXTRA_WAIT_LOCK=12,		 
  HA_EXTRA_NO_WAIT_LOCK=13,		 
  HA_EXTRA_WRITE_CACHE=14,		 
  HA_EXTRA_FLUSH_CACHE=15,		 
  HA_EXTRA_NO_KEYS=16,			 
  HA_EXTRA_KEYREAD_CHANGE_POS=17,	 
					 
  HA_EXTRA_REMEMBER_POS=18,		 
  HA_EXTRA_RESTORE_POS=19,
  HA_EXTRA_REINIT_CACHE=20,		 
  HA_EXTRA_FORCE_REOPEN=21		 
};

	 

enum ha_panic_function {
  HA_PANIC_CLOSE,			 
  HA_PANIC_WRITE,			 
  HA_PANIC_READ				 
};

	 

enum ha_base_keytype {
  HA_KEYTYPE_END=0,
  HA_KEYTYPE_TEXT=1,			 
  HA_KEYTYPE_BINARY=2,			 
  HA_KEYTYPE_SHORT_INT=3,
  HA_KEYTYPE_LONG_INT=4,
  HA_KEYTYPE_FLOAT=5,
  HA_KEYTYPE_DOUBLE=6,
  HA_KEYTYPE_NUM=7,			 
  HA_KEYTYPE_USHORT_INT=8,
  HA_KEYTYPE_ULONG_INT=9,

  HA_KEYTYPE_LONGLONG=10,
  HA_KEYTYPE_ULONGLONG=11,

  HA_KEYTYPE_INT24=12,
  HA_KEYTYPE_UINT24=13,
  HA_KEYTYPE_INT8=14
};



	 




	 




	 


 	 


	 






	 



	 

















	 



	 

	 







	 






	 











enum en_fieldtype {
  FIELD_LAST=-1,FIELD_NORMAL,FIELD_SKIPP_ENDSPACE,FIELD_SKIPP_PRESPACE,
  FIELD_SKIPP_ZERO,FIELD_BLOB,FIELD_CONSTANT,FIELD_INTERVALL,FIELD_ZERO
};

 


typedef ulong	ha_rows;	 


# 128 "mysql_priv.h" 2

# 1 "table.h" 1
 













 

typedef ulong table_map;		 
typedef ulong key_map;			 

class Item;				 

 

typedef struct st_order {
  struct st_order *next;
  Item	 **item;			 
  bool	 asc;				 
  bool	 free_me;			 

  Field  *field;			 
  char   *buff;				 
} ORDER;


 

typedef struct st_table {
  byte* file;				 
  File dfile;				 
  Field **field;			 
  byte *record[3];			 
  uint fields;				 
  uint reclength;			 
  uint rec_buff_length;
  uint keys,key_parts,max_key_length;
  uint null_fields;			 
  uint blob_fields;			 
  KEY  *key_info;			 
  TYPELIB keynames;			 
  KEYFILE_INFO keyfile_info;
  ulong max_records;			 
  ulong reloc;				 
  TYPELIB fieldnames;			 
  TYPELIB *intervals;			 
  enum db_type db_type;			 
  uint db_capabilities;
  uint db_create_options;		 
  uint db_record_offset;		 
  uint db_stat;				 
  uint status;				 
  uint system;				 
  uint time_stamp;			 
  uint next_number_index;
  int locked;				 
  my_bool copy_blobs;			 
  my_bool null_row;			 
  my_bool maybe_null,outer_join;	 
  my_bool distinct,tmp_table,const_table;
  Field *next_number_field,		 
	*found_next_number_field,	 
	*timestamp_field;
  my_string info;			 
  REGINFO reginfo;			 
  MEM_ROOT mem_root;

  char		*table_cache_key;
  char		*table_name,*real_name;
  uint		key_length;		 
  uint		tablenr,used_fields;
  table_map	map;
  ulong		version;
  uchar		*null_flags;
  IO_CACHE	*io_cache;			 
  byte		*record_pointers;		 
  ulong		found_records;			 
  ORDER		*group;

  THD		*in_use;			 
  struct st_table *next,*prev;
} TABLE;


typedef struct st_table_list {
  struct	st_table_list *next;
  char		*db,*name,*real_name;
  uint		flags;
  TABLE		*table;
  Item		*on_expr;			 
  struct st_table_list *natural_join;		 
} TABLE_LIST;
# 129 "mysql_priv.h" 2

# 1 "field.h" 1
 












 





#pragma interface			


class Send_field;
struct st_cache_field;

class Field :public Sql_alloc {
  Field(const Item &);				 
  void operator=(Field &);
public:
  enum utype { NONE,DATE,SHIELD,NOEMPTY,CASEUP,PNR,BGNR,PGNR,YES,NO,REL,
	       CHECK,EMPTY,UNKNOWN,CASEDN,NEXT_NUMBER,INTERVAL_FIELD,BIT_FIELD,
	       TIMESTAMP_FIELD,CAPITALIZE,BLOB_FIELD};
  char	*ptr;				 
protected:

  uchar		*null_ptr;		 
  uint8		null_bit;		 

public:
  struct st_table *table;		 
  uint	field_length;			 
  ulong query_id;			 
  ulong key_parts;			 
  char	*table_name,*field_name;
  utype unireg_check;
  uint	flags;

  Field(char *ptr_arg,uint length_arg,uchar *null_ptr_arg,uint null_bit_arg,
	utype unireg_check_arg,char *field_name_arg,
	struct st_table *table_arg);
  virtual ~Field() {}
  virtual void store(const char *to,uint length)=0;
  virtual void store(double nr)=0;
  virtual void store(longlong nr)=0;
  virtual double val_real(void)=0;
  virtual longlong val_int(void)=0;
  virtual void val_str(String*)=0;
  virtual Item_result result_type () const=0;
  virtual Item_result cmp_type () const { return result_type(); }
  virtual bool eq(Field *field) { return ptr == field->ptr; }
  virtual uint pack_length() const { return field_length; }
  virtual void reset(void) { memset(( ptr ),0,( pack_length() )) ; }
  virtual bool binary() const { return 1; }
  virtual bool zero_pack() const { return 1; }
  virtual enum ha_base_keytype key_type() const { return HA_KEYTYPE_BINARY; }
  virtual enum_field_types type() const =0;
  virtual enum_field_types real_type() const { return type(); }
  inline int cmp(const char *str) { return cmp(ptr,str); }
  virtual int cmp(const char *,const char *)=0;
  virtual void sql_type(String &str) const =0;
  virtual uint size_of() const =0;			 
  inline bool is_null(uint offset=0)
    { return null_ptr ? (null_ptr[offset] & null_bit ? 1 : table->null_row) : table->null_row; }
  inline void set_null(int offset=0)
    { if (null_ptr) null_ptr[offset]|= null_bit; }
  inline void set_notnull(int offset=0)
    { if (null_ptr) null_ptr[offset]&= ~null_bit; }
  inline bool maybe_null(void) { return null_ptr != 0 || table->maybe_null; }
  virtual void make_field(Send_field *)=0;
  virtual void sort_string(char *buff,uint length)=0;
  virtual bool optimize_range() { return 1; }
  virtual bool store_for_compare() { return 0; }
  inline Field *new_field(struct st_table *new_table)
    {
      Field *tmp= (Field*) sql_memdup((char*) this,size_of());
      tmp->table=new_table;
      return tmp;
    }
  inline void move_field(char *ptr_arg,uchar *null_ptr_arg,uint null_bit_arg)
    {
      ptr=ptr_arg; null_ptr=null_ptr_arg; null_bit=null_bit_arg;
    }
  inline void move_field(char *ptr_arg) { ptr=ptr_arg; }
  inline void get_image(char *buff,uint length)
    { memcpy(buff,ptr,length); }
  inline void set_image(char *buff,uint length)
    { memcpy(ptr,buff,length); }
  inline int cmp_image(char *buff,uint length)
    {
      if (binary())
	return memcmp(ptr,buff,length);
      else
	return my_casecmp(ptr,buff,length);
    }
  inline longlong val_int_offset(uint offset)
    {
      ptr+=offset;
      longlong tmp=val_int();
      ptr-=offset;
      return tmp;
    }
  bool send(String *packet);
  uint offset();				 
  void copy_from_tmp(int offset);
  uint fill_cache_field(struct st_cache_field *copy);
  friend bool reopen_table(THD *,struct st_table *,bool);
  friend class Copy_field;
  friend class Item_avg_field;
  friend class Item_std_field;
  friend class Item_sum_num;
  friend class Item_sum_sum;
  friend class Item_sum_str;
  friend class Item_sum_count;
  friend class Item_sum_avg;
  friend class Item_sum_std;
  friend class Item_sum_min;
  friend class Item_sum_max;
};


class Field_num :public Field {
public:
  const uint8 decimals;
  bool zerofill,unsigned_flag;		 
  Field_num(char *ptr_arg,uint len_arg, uchar *null_ptr_arg, uint null_bit_arg,
	    utype unireg_check_arg, char *field_name_arg,
	    struct st_table *table_arg,
	    uint dec_arg,bool zero_arg,bool unsigned_arg)
    :Field(ptr_arg, len_arg, null_ptr_arg, null_bit_arg,
	   unireg_check_arg, field_name_arg, table_arg),
     decimals(dec_arg),zerofill(zero_arg),unsigned_flag(unsigned_arg)
    {
      if (zerofill)
	flags|= 64 ;
      if (unsigned_flag)
	flags|= 32 ;
    }
  Item_result result_type () const { return REAL_RESULT; }
  void prepend_zeros(String *value);
  void add_zerofill_and_unsigned(String &res) const;
  friend class create_field;
  void make_field(Send_field *);
  uint size_of() const { return sizeof(*this); }
};


class Field_str :public Field {
public:
  Field_str(char *ptr_arg,uint len_arg, uchar *null_ptr_arg, uint null_bit_arg,
	    utype unireg_check_arg, char *field_name_arg,
	    struct st_table *table_arg)
    :Field(ptr_arg, len_arg, null_ptr_arg, null_bit_arg,
	   unireg_check_arg, field_name_arg, table_arg)
    {}
  Item_result result_type () const { return STRING_RESULT; }
  friend class create_field;
  void make_field(Send_field *);
  uint size_of() const { return sizeof(*this); }
};


class Field_decimal :public Field_num {
public:
  Field_decimal(char *ptr_arg, uint len_arg, uchar *null_ptr_arg,
		uint null_bit_arg,
		enum utype unireg_check_arg, char *field_name_arg,
		struct st_table *table_arg,
		uint dec_arg,bool zero_arg,bool unsigned_arg)
    :Field_num(ptr_arg, len_arg, null_ptr_arg, null_bit_arg,
	       unireg_check_arg, field_name_arg, table_arg,
	       dec_arg, zero_arg,unsigned_arg)
    {}
  enum_field_types type() const { return FIELD_TYPE_DECIMAL;}
  enum ha_base_keytype key_type() const
    { return zerofill ? HA_KEYTYPE_BINARY : HA_KEYTYPE_NUM; }
  void reset(void);
  void store(const char *to,uint length);
  void store(double nr);
  void store(longlong nr);
  double val_real(void);
  longlong val_int(void);
  void val_str(String*);
  int cmp(const char *,const char*);
  void sort_string(char *buff,uint length);
  void overflow(bool negative);
  bool zero_pack() const { return 0; }
  void sql_type(String &str) const;
};


class Field_tiny :public Field_num {
public:
  Field_tiny(char *ptr_arg, uint len_arg, uchar *null_ptr_arg,
	     uint null_bit_arg,
	     enum utype unireg_check_arg, char *field_name_arg,
	     struct st_table *table_arg,
	     bool zero_arg, bool unsigned_arg)
    :Field_num(ptr_arg, len_arg, null_ptr_arg, null_bit_arg,
	       unireg_check_arg, field_name_arg, table_arg,
	       0, zero_arg,unsigned_arg)
    {}
  enum Item_result result_type () const { return INT_RESULT; }
  enum_field_types type() const { return FIELD_TYPE_TINY;}
  enum ha_base_keytype key_type() const
    { return unsigned_flag ? HA_KEYTYPE_BINARY : HA_KEYTYPE_INT8; }
  void store(const char *to,uint length);
  void store(double nr);
  void store(longlong nr);
  double val_real(void);
  longlong val_int(void);
  void val_str(String*);
  int cmp(const char *,const char*);
  void sort_string(char *buff,uint length);
  uint pack_length() const { return 1; }
  void sql_type(String &str) const;
};


class Field_short :public Field_num {
public:
  Field_short(char *ptr_arg, uint len_arg, uchar *null_ptr_arg,
	      uint null_bit_arg,
	      enum utype unireg_check_arg, char *field_name_arg,
	      struct st_table *table_arg,




More information about the Gcc-bugs mailing list