]> git.wh0rd.org Git - ICEs.git/blob - 137054/ice.ii.1
updates
[ICEs.git] / 137054 / ice.ii.1
1  extern "C++" { namespace std {   class exception   {   public:     exception() throw() { }     virtual ~exception() throw();     virtual const char* what() const throw();   };   class bad_exception : public exception   {   public:     bad_exception() throw() { }     virtual ~bad_exception() throw();   };   typedef void (*terminate_handler) ();   typedef void (*unexpected_handler) ();   terminate_handler set_terminate(terminate_handler) throw();   void terminate() __attribute__ ((__noreturn__));   unexpected_handler set_unexpected(unexpected_handler) throw();   void unexpected() __attribute__ ((__noreturn__));   bool uncaught_exception() throw(); } namespace __gnu_cxx {   void __verbose_terminate_handler (); } }
2  typedef int ptrdiff_t;
3  typedef unsigned int size_t;
4  extern "C" {      extern void *memcpy (void *__restrict __dest,        __const void *__restrict __src, size_t __n)      throw () __attribute__ ((__nonnull__ (1, 2)));   extern void *memmove (void *__dest, __const void *__src, size_t __n)      throw () __attribute__ ((__nonnull__ (1, 2)));       extern void *memccpy (void *__restrict __dest, __const void *__restrict __src,         int __c, size_t __n)      throw () __attribute__ ((__nonnull__ (1, 2)));      extern void *memset (void *__s, int __c, size_t __n) throw () __attribute__ ((__nonnull__ (1)));   extern int memcmp (__const void *__s1, __const void *__s2, size_t __n)      throw () __attribute__ ((__pure__)) __attribute__ ((__nonnull__ (1, 2)));   extern void *memchr (__const void *__s, int __c, size_t __n)       throw () __attribute__ ((__pure__)) __attribute__ ((__nonnull__ (1)));      extern void *rawmemchr (__const void *__s, int __c)      throw () __attribute__ ((__pure__)) __attribute__ ((__nonnull__ (1)));   extern void *memrchr (__const void *__s, int __c, size_t __n)       throw () __attribute__ ((__pure__)) __attribute__ ((__nonnull__ (1)));      extern char *strcpy (char *__restrict __dest, __const char *__restrict __src)      throw () __attribute__ ((__nonnull__ (1, 2)));  extern char *strncpy (char *__restrict __dest,         __const char *__restrict __src, size_t __n)      throw () __attribute__ ((__nonnull__ (1, 2)));   extern char *strcat (char *__restrict __dest, __const char *__restrict __src)      throw () __attribute__ ((__nonnull__ (1, 2)));  extern char *strncat (char *__restrict __dest, __const char *__restrict __src,         size_t __n) throw () __attribute__ ((__nonnull__ (1, 2)));   extern int strcmp (__const char *__s1, __const char *__s2)      throw () __attribute__ ((__pure__)) __attribute__ ((__nonnull__ (1, 2)));  extern int strncmp (__const char *__s1, __const char *__s2, size_t __n)      throw () __attribute__ ((__pure__)) __attribute__ ((__nonnull__ (1, 2)));   extern int strcoll (__const char *__s1, __const char *__s2)      throw () __attribute__ ((__pure__)) __attribute__ ((__nonnull__ (1, 2)));  extern size_t strxfrm (char *__restrict __dest,          __const char *__restrict __src, size_t __n)      throw () __attribute__ ((__nonnull__ (2))); typedef struct __locale_struct {   struct locale_data *__locales[13];   const unsigned short int *__ctype_b;   const int *__ctype_tolower;   const int *__ctype_toupper;   const char *__names[13]; } *__locale_t;  extern int strcoll_l (__const char *__s1, __const char *__s2, __locale_t __l)      throw () __attribute__ ((__pure__)) __attribute__ ((__nonnull__ (1, 2, 3)));  extern size_t strxfrm_l (char *__dest, __const char *__src, size_t __n,     __locale_t __l) throw () __attribute__ ((__nonnull__ (2, 4)));     extern char *strdup (__const char *__s)      throw () __attribute__ ((__malloc__)) __attribute__ ((__nonnull__ (1)));       extern char *strndup (__const char *__string, size_t __n)      throw () __attribute__ ((__malloc__)) __attribute__ ((__nonnull__ (1))); extern char *strchr (__const char *__s, int __c)      throw () __attribute__ ((__pure__)) __attribute__ ((__nonnull__ (1))); extern char *strrchr (__const char *__s, int __c)      throw () __attribute__ ((__pure__)) __attribute__ ((__nonnull__ (1))); extern char *strchrnul (__const char *__s, int __c)      throw () __attribute__ ((__pure__)) __attribute__ ((__nonnull__ (1))); extern size_t strcspn (__const char *__s, __const char *__reject)      throw () __attribute__ ((__pure__)) __attribute__ ((__nonnull__ (1, 2))); extern size_t strspn (__const char *__s, __const char *__accept)      throw () __attribute__ ((__pure__)) __attribute__ ((__nonnull__ (1, 2))); extern char *strpbrk (__const char *__s, __const char *__accept)      throw () __attribute__ ((__pure__)) __attribute__ ((__nonnull__ (1, 2))); extern char *strstr (__const char *__haystack, __const char *__needle)      throw () __attribute__ ((__pure__)) __attribute__ ((__nonnull__ (1, 2))); extern char *strtok (char *__restrict __s, __const char *__restrict __delim)      throw () __attribute__ ((__nonnull__ (2))); extern char *__strtok_r (char *__restrict __s,     __const char *__restrict __delim,     char **__restrict __save_ptr)      throw () __attribute__ ((__nonnull__ (2, 3))); extern char *strtok_r (char *__restrict __s, __const char *__restrict __delim,          char **__restrict __save_ptr)      throw () __attribute__ ((__nonnull__ (2, 3))); extern char *strcasestr (__const char *__haystack, __const char *__needle)      throw () __attribute__ ((__pure__)) __attribute__ ((__nonnull__ (1, 2))); extern void *memmem (__const void *__haystack, size_t __haystacklen,        __const void *__needle, size_t __needlelen)      throw () __attribute__ ((__pure__)) __attribute__ ((__nonnull__ (1, 3))); extern void *__mempcpy (void *__restrict __dest,    __const void *__restrict __src, size_t __n)      throw () __attribute__ ((__nonnull__ (1, 2))); extern void *mempcpy (void *__restrict __dest,         __const void *__restrict __src, size_t __n)      throw () __attribute__ ((__nonnull__ (1, 2))); extern size_t strlen (__const char *__s)      throw () __attribute__ ((__pure__)) __attribute__ ((__nonnull__ (1))); extern size_t strnlen (__const char *__string, size_t __maxlen)      throw () __attribute__ ((__pure__)) __attribute__ ((__nonnull__ (1))); extern char *strerror (int __errnum) throw (); extern char *strerror_r (int __errnum, char *__buf, size_t __buflen)      throw () __attribute__ ((__nonnull__ (2))); extern void __bzero (void *__s, size_t __n) throw () __attribute__ ((__nonnull__ (1))); extern void bcopy (__const void *__src, void *__dest, size_t __n)      throw () __attribute__ ((__nonnull__ (1, 2))); extern void bzero (void *__s, size_t __n) throw () __attribute__ ((__nonnull__ (1))); extern int bcmp (__const void *__s1, __const void *__s2, size_t __n)      throw () __attribute__ ((__pure__)) __attribute__ ((__nonnull__ (1, 2))); extern char *index (__const char *__s, int __c)      throw () __attribute__ ((__pure__)) __attribute__ ((__nonnull__ (1))); extern char *rindex (__const char *__s, int __c)      throw () __attribute__ ((__pure__)) __attribute__ ((__nonnull__ (1))); extern int ffs (int __i) throw () __attribute__ ((__const__)); extern int ffsl (long int __l) throw () __attribute__ ((__const__)); __extension__ extern int ffsll (long long int __ll)      throw () __attribute__ ((__const__)); extern int strcasecmp (__const char *__s1, __const char *__s2)      throw () __attribute__ ((__pure__)) __attribute__ ((__nonnull__ (1, 2))); extern int strncasecmp (__const char *__s1, __const char *__s2, size_t __n)      throw () __attribute__ ((__pure__)) __attribute__ ((__nonnull__ (1, 2))); extern int strcasecmp_l (__const char *__s1, __const char *__s2,     __locale_t __loc)      throw () __attribute__ ((__pure__)) __attribute__ ((__nonnull__ (1, 2, 3))); extern int strncasecmp_l (__const char *__s1, __const char *__s2,      size_t __n, __locale_t __loc)      throw () __attribute__ ((__pure__)) __attribute__ ((__nonnull__ (1, 2, 4))); extern char *strsep (char **__restrict __stringp,        __const char *__restrict __delim)      throw () __attribute__ ((__nonnull__ (1, 2))); extern int strverscmp (__const char *__s1, __const char *__s2)      throw () __attribute__ ((__pure__)) __attribute__ ((__nonnull__ (1, 2))); extern char *strsignal (int __sig) throw (); extern char *__stpcpy (char *__restrict __dest, __const char *__restrict __src)      throw () __attribute__ ((__nonnull__ (1, 2))); extern char *stpcpy (char *__restrict __dest, __const char *__restrict __src)      throw () __attribute__ ((__nonnull__ (1, 2))); extern char *__stpncpy (char *__restrict __dest,    __const char *__restrict __src, size_t __n)      throw () __attribute__ ((__nonnull__ (1, 2))); extern char *stpncpy (char *__restrict __dest,         __const char *__restrict __src, size_t __n)      throw () __attribute__ ((__nonnull__ (1, 2))); extern char *strfry (char *__string) throw () __attribute__ ((__nonnull__ (1))); extern void *memfrob (void *__s, size_t __n) throw () __attribute__ ((__nonnull__ (1))); extern char *basename (__const char *__filename) throw () __attribute__ ((__nonnull__ (1))); }
5   typedef long SLONG;
6   typedef unsigned long ULONG;
7  typedef char SCHAR;
8  typedef unsigned char UCHAR;
9  typedef short SSHORT;
10  typedef unsigned short USHORT;
11  typedef long ISC_STATUS;
12  typedef ISC_STATUS ISC_STATUS_ARRAY[20];
13  typedef int ISC_DATE;
14  typedef unsigned int ISC_TIME;
15  typedef struct {  ISC_DATE timestamp_date;  ISC_TIME timestamp_time; }
16  ISC_TIMESTAMP;
17  typedef struct GDS_QUAD_t ISC_QUAD;
18  typedef unsigned char BOOLEAN;
19  typedef char TEXT;
20  typedef void (*FPTR_VOID_PTR) (void*);
21  typedef void (*FPTR_PRINT_CALLBACK) (void*, SSHORT, const char*);
22  namespace Firebird { class StringsBuffer { public:  virtual char* alloc(const char* string, size_t length) = 0;  virtual ~StringsBuffer() {} }; template <size_t BUFFER_SIZE> class CircularStringsBuffer : public StringsBuffer { public:  CircularStringsBuffer() throw() {   memset(buffer, 0, BUFFER_SIZE);   buffer_ptr = buffer;  }  virtual char* alloc(const char* string, size_t length) {   if (buffer_ptr + length + 1 > buffer + BUFFER_SIZE)    buffer_ptr = buffer;   char* new_string = buffer_ptr;   memcpy(new_string, string, length);   new_string[length] = 0;   buffer_ptr += length + 1;   return new_string;  } private:  char buffer[BUFFER_SIZE];  char *buffer_ptr; }; class status_exception : public std::exception { public:  status_exception(const ISC_STATUS *status_vector, bool permanent) throw();  virtual ~status_exception() throw();  virtual const char* what() const throw() { return "Firebird::status_exception"; }  const ISC_STATUS* value() const throw() { return m_status_vector; }  bool strings_permanent() const throw() { return m_strings_permanent; }  bool status_known() const throw() { return m_status_known; }  static void raise(const ISC_STATUS *status_vector);  static void raise();  static void raise(ISC_STATUS status, ...); protected:  status_exception() throw();  void set_status(const ISC_STATUS *new_vector, bool permanent) throw(); private:  ISC_STATUS_ARRAY m_status_vector;  bool m_strings_permanent;  bool m_status_known;  void release_vector() throw(); }; class system_call_failed : public status_exception { private:  int errorCode; public:  system_call_failed(const char* v_syscall, int v_error_code);  static void raise(const char* syscall, int error_code);  static void raise(const char* syscall);  int getErrorCode() const  {   return errorCode;  } }; class fatal_exception : public status_exception { public:  explicit fatal_exception(const char* message);  static void raiseFmt(const char* format, ...);  const char* what() const throw()  {   return reinterpret_cast<const char*>(value()[3]);  }  static void raise(const char* message); }; ISC_STATUS stuff_exception(ISC_STATUS *status_vector, const std::exception& ex, StringsBuffer* sb = __null) throw(); const char* status_string(const char* string); const char* status_nstring(const char* string, size_t length); }
23  extern "C" { typedef unsigned char __u_char; typedef unsigned short int __u_short; typedef unsigned int __u_int; typedef unsigned long int __u_long; typedef signed char __int8_t; typedef unsigned char __uint8_t; typedef signed short int __int16_t; typedef unsigned short int __uint16_t; typedef signed int __int32_t; typedef unsigned int __uint32_t; __extension__ typedef signed long long int __int64_t; __extension__ typedef unsigned long long int __uint64_t; __extension__ typedef long long int __quad_t; __extension__ typedef unsigned long long int __u_quad_t; __extension__ typedef __u_quad_t __dev_t; __extension__ typedef unsigned int __uid_t; __extension__ typedef unsigned int __gid_t; __extension__ typedef unsigned long int __ino_t; __extension__ typedef __u_quad_t __ino64_t; __extension__ typedef unsigned int __mode_t; __extension__ typedef unsigned int __nlink_t; __extension__ typedef long int __off_t; __extension__ typedef __quad_t __off64_t; __extension__ typedef int __pid_t; __extension__ typedef struct { int __val[2]; } __fsid_t; __extension__ typedef long int __clock_t; __extension__ typedef unsigned long int __rlim_t; __extension__ typedef __u_quad_t __rlim64_t; __extension__ typedef unsigned int __id_t; __extension__ typedef long int __time_t; __extension__ typedef unsigned int __useconds_t; __extension__ typedef long int __suseconds_t; __extension__ typedef int __daddr_t; __extension__ typedef long int __swblk_t; __extension__ typedef int __key_t; __extension__ typedef int __clockid_t; __extension__ typedef int __timer_t; __extension__ typedef long int __blksize_t; __extension__ typedef long int __blkcnt_t; __extension__ typedef __quad_t __blkcnt64_t; __extension__ typedef unsigned long int __fsblkcnt_t; __extension__ typedef __u_quad_t __fsblkcnt64_t; __extension__ typedef unsigned long int __fsfilcnt_t; __extension__ typedef __u_quad_t __fsfilcnt64_t; __extension__ typedef int __ssize_t; typedef __off64_t __loff_t; typedef __quad_t *__qaddr_t; typedef char *__caddr_t; __extension__ typedef int __intptr_t; __extension__ typedef unsigned int __socklen_t; typedef struct _IO_FILE FILE; typedef struct _IO_FILE __FILE; typedef unsigned int wint_t; typedef struct {   int __count;   union   {     wint_t __wch;     char __wchb[4];   } __value; } __mbstate_t; typedef struct {   __off_t __pos;   __mbstate_t __state; } _G_fpos_t; typedef struct {   __off64_t __pos;   __mbstate_t __state; } _G_fpos64_t; enum {   __GCONV_OK = 0,   __GCONV_NOCONV,   __GCONV_NODB,   __GCONV_NOMEM,   __GCONV_EMPTY_INPUT,   __GCONV_FULL_OUTPUT,   __GCONV_ILLEGAL_INPUT,   __GCONV_INCOMPLETE_INPUT,   __GCONV_ILLEGAL_DESCRIPTOR,   __GCONV_INTERNAL_ERROR }; enum {   __GCONV_IS_LAST = 0x0001,   __GCONV_IGNORE_ERRORS = 0x0002 }; struct __gconv_step; struct __gconv_step_data; struct __gconv_loaded_object; struct __gconv_trans_data; typedef int (*__gconv_fct) (struct __gconv_step *, struct __gconv_step_data *,        __const unsigned char **, __const unsigned char *,        unsigned char **, size_t *, int, int); typedef wint_t (*__gconv_btowc_fct) (struct __gconv_step *, unsigned char); typedef int (*__gconv_init_fct) (struct __gconv_step *); typedef void (*__gconv_end_fct) (struct __gconv_step *); typedef int (*__gconv_trans_fct) (struct __gconv_step *,       struct __gconv_step_data *, void *,       __const unsigned char *,       __const unsigned char **,       __const unsigned char *, unsigned char **,       size_t *); typedef int (*__gconv_trans_context_fct) (void *, __const unsigned char *,        __const unsigned char *,        unsigned char *, unsigned char *); typedef int (*__gconv_trans_query_fct) (__const char *, __const char ***,      size_t *); typedef int (*__gconv_trans_init_fct) (void **, const char *); typedef void (*__gconv_trans_end_fct) (void *); struct __gconv_trans_data {   __gconv_trans_fct __trans_fct;   __gconv_trans_context_fct __trans_context_fct;   __gconv_trans_end_fct __trans_end_fct;   void *__data;   struct __gconv_trans_data *__next; }; struct __gconv_step {   struct __gconv_loaded_object *__shlib_handle;   __const char *__modname;   int __counter;   char *__from_name;   char *__to_name;   __gconv_fct __fct;   __gconv_btowc_fct __btowc_fct;   __gconv_init_fct __init_fct;   __gconv_end_fct __end_fct;   int __min_needed_from;   int __max_needed_from;   int __min_needed_to;   int __max_needed_to;   int __stateful;   void *__data; }; struct __gconv_step_data {   unsigned char *__outbuf;   unsigned char *__outbufend;   int __flags;   int __invocation_counter;   int __internal_use;   __mbstate_t *__statep;   __mbstate_t __state;   struct __gconv_trans_data *__trans; }; typedef struct __gconv_info {   size_t __nsteps;   struct __gconv_step *__steps;   __extension__ struct __gconv_step_data __data []; } *__gconv_t; typedef union {   struct __gconv_info __cd;   struct   {     struct __gconv_info __cd;     struct __gconv_step_data __data;   } __combined; } _G_iconv_t; typedef int _G_int16_t __attribute__ ((__mode__ (__HI__))); typedef int _G_int32_t __attribute__ ((__mode__ (__SI__))); typedef unsigned int _G_uint16_t __attribute__ ((__mode__ (__HI__))); typedef unsigned int _G_uint32_t __attribute__ ((__mode__ (__SI__))); typedef __builtin_va_list __gnuc_va_list; struct _IO_jump_t; struct _IO_FILE; typedef void _IO_lock_t; struct _IO_marker {   struct _IO_marker *_next;   struct _IO_FILE *_sbuf;   int _pos; }; enum __codecvt_result {   __codecvt_ok,   __codecvt_partial,   __codecvt_error,   __codecvt_noconv }; struct _IO_FILE {   int _flags;   char* _IO_read_ptr;   char* _IO_read_end;   char* _IO_read_base;   char* _IO_write_base;   char* _IO_write_ptr;   char* _IO_write_end;   char* _IO_buf_base;   char* _IO_buf_end;   char *_IO_save_base;   char *_IO_backup_base;   char *_IO_save_end;   struct _IO_marker *_markers;   struct _IO_FILE *_chain;   int _fileno;   int _flags2;   __off_t _old_offset;   unsigned short _cur_column;   signed char _vtable_offset;   char _shortbuf[1];   _IO_lock_t *_lock;   __off64_t _offset;   void *__pad1;   void *__pad2;   int _mode;   char _unused2[15 * sizeof (int) - 2 * sizeof (void *)]; }; struct _IO_FILE_plus; extern struct _IO_FILE_plus _IO_2_1_stdin_; extern struct _IO_FILE_plus _IO_2_1_stdout_; extern struct _IO_FILE_plus _IO_2_1_stderr_; typedef __ssize_t __io_read_fn (void *__cookie, char *__buf, size_t __nbytes); typedef __ssize_t __io_write_fn (void *__cookie, __const char *__buf,      size_t __n); typedef int __io_seek_fn (void *__cookie, __off64_t *__pos, int __w); typedef int __io_close_fn (void *__cookie); typedef __io_read_fn cookie_read_function_t; typedef __io_write_fn cookie_write_function_t; typedef __io_seek_fn cookie_seek_function_t; typedef __io_close_fn cookie_close_function_t; typedef struct {   __io_read_fn *read;   __io_write_fn *write;   __io_seek_fn *seek;   __io_close_fn *close; } _IO_cookie_io_functions_t; typedef _IO_cookie_io_functions_t cookie_io_functions_t; struct _IO_cookie_file; extern void _IO_cookie_init (struct _IO_cookie_file *__cfile, int __read_write,         void *__cookie, _IO_cookie_io_functions_t __fns); extern "C" { extern int __underflow (_IO_FILE *) throw (); extern int __uflow (_IO_FILE *) throw (); extern int __overflow (_IO_FILE *, int) throw (); extern wint_t __wunderflow (_IO_FILE *) throw (); extern wint_t __wuflow (_IO_FILE *) throw (); extern wint_t __woverflow (_IO_FILE *, wint_t) throw (); extern int _IO_getc (_IO_FILE *__fp) throw (); extern int _IO_putc (int __c, _IO_FILE *__fp) throw (); extern int _IO_feof (_IO_FILE *__fp) throw (); extern int _IO_ferror (_IO_FILE *__fp) throw (); extern int _IO_peekc_locked (_IO_FILE *__fp) throw (); extern void _IO_flockfile (_IO_FILE *) throw (); extern void _IO_funlockfile (_IO_FILE *) throw (); extern int _IO_ftrylockfile (_IO_FILE *) throw (); extern int _IO_vfscanf (_IO_FILE * __restrict, const char * __restrict,    __gnuc_va_list, int *__restrict) throw (); extern int _IO_vfprintf (_IO_FILE *__restrict, const char *__restrict,     __gnuc_va_list) throw (); extern __ssize_t _IO_padn (_IO_FILE *, int, __ssize_t) throw (); extern size_t _IO_sgetn (_IO_FILE *, void *, size_t) throw (); extern __off64_t _IO_seekoff (_IO_FILE *, __off64_t, int, int) throw (); extern __off64_t _IO_seekpos (_IO_FILE *, __off64_t, int) throw (); extern void _IO_free_backup_area (_IO_FILE *) throw (); } typedef __gnuc_va_list va_list; typedef _G_fpos64_t fpos_t; typedef _G_fpos64_t fpos64_t; extern struct _IO_FILE *stdin; extern struct _IO_FILE *stdout; extern struct _IO_FILE *stderr; extern int remove (__const char *__filename) throw (); extern int rename (__const char *__old, __const char *__new) throw (); extern FILE *tmpfile (void) __asm__ ("" "tmpfile64"); extern FILE *tmpfile64 (void); extern char *tmpnam (char *__s) throw (); extern char *tmpnam_r (char *__s) throw (); extern char *tempnam (__const char *__dir, __const char *__pfx)      throw () __attribute__ ((__malloc__)); extern int fclose (FILE *__stream); extern int fflush (FILE *__stream); extern int fflush_unlocked (FILE *__stream); extern int fcloseall (void); extern FILE *fopen (__const char *__restrict __filename, __const char *__restrict __modes) __asm__ ("" "fopen64"); extern FILE *freopen (__const char *__restrict __filename, __const char *__restrict __modes, FILE *__restrict __stream) __asm__ ("" "freopen64"); extern FILE *fopen64 (__const char *__restrict __filename,         __const char *__restrict __modes); extern FILE *freopen64 (__const char *__restrict __filename,    __const char *__restrict __modes,    FILE *__restrict __stream); extern FILE *fdopen (int __fd, __const char *__modes) throw (); extern FILE *fopencookie (void *__restrict __magic_cookie,      __const char *__restrict __modes,      _IO_cookie_io_functions_t __io_funcs) throw (); extern FILE *fmemopen (void *__s, size_t __len, __const char *__modes) throw (); extern FILE *open_memstream (char **__restrict __bufloc,         size_t *__restrict __sizeloc) throw (); extern void setbuf (FILE *__restrict __stream, char *__restrict __buf) throw (); extern int setvbuf (FILE *__restrict __stream, char *__restrict __buf,       int __modes, size_t __n) throw (); extern void setbuffer (FILE *__restrict __stream, char *__restrict __buf,          size_t __size) throw (); extern void setlinebuf (FILE *__stream) throw (); extern int fprintf (FILE *__restrict __stream,       __const char *__restrict __format, ...); extern int printf (__const char *__restrict __format, ...); extern int sprintf (char *__restrict __s,       __const char *__restrict __format, ...) throw (); extern int vfprintf (FILE *__restrict __s, __const char *__restrict __format,        __gnuc_va_list __arg); extern int vprintf (__const char *__restrict __format, __gnuc_va_list __arg); extern int vsprintf (char *__restrict __s, __const char *__restrict __format,        __gnuc_va_list __arg) throw (); extern int snprintf (char *__restrict __s, size_t __maxlen,        __const char *__restrict __format, ...)      throw () __attribute__ ((__format__ (__printf__, 3, 4))); extern int vsnprintf (char *__restrict __s, size_t __maxlen,         __const char *__restrict __format, __gnuc_va_list __arg)      throw () __attribute__ ((__format__ (__printf__, 3, 0))); extern int vasprintf (char **__restrict __ptr, __const char *__restrict __f,         __gnuc_va_list __arg)      throw () __attribute__ ((__format__ (__printf__, 2, 0))); extern int __asprintf (char **__restrict __ptr,          __const char *__restrict __fmt, ...)      throw () __attribute__ ((__format__ (__printf__, 2, 3))); extern int asprintf (char **__restrict __ptr,        __const char *__restrict __fmt, ...)      throw () __attribute__ ((__format__ (__printf__, 2, 3))); extern int vdprintf (int __fd, __const char *__restrict __fmt,        __gnuc_va_list __arg)      __attribute__ ((__format__ (__printf__, 2, 0))); extern int dprintf (int __fd, __const char *__restrict __fmt, ...)      __attribute__ ((__format__ (__printf__, 2, 3))); extern int fscanf (FILE *__restrict __stream,      __const char *__restrict __format, ...); extern int scanf (__const char *__restrict __format, ...); extern int sscanf (__const char *__restrict __s,      __const char *__restrict __format, ...) throw (); extern int vfscanf (FILE *__restrict __s, __const char *__restrict __format,       __gnuc_va_list __arg)      __attribute__ ((__format__ (__scanf__, 2, 0))); extern int vscanf (__const char *__restrict __format, __gnuc_va_list __arg)      __attribute__ ((__format__ (__scanf__, 1, 0))); extern int vsscanf (__const char *__restrict __s,       __const char *__restrict __format, __gnuc_va_list __arg)      throw () __attribute__ ((__format__ (__scanf__, 2, 0))); extern int fgetc (FILE *__stream); extern int getc (FILE *__stream); extern int getchar (void); extern int getc_unlocked (FILE *__stream); extern int getchar_unlocked (void); extern int fgetc_unlocked (FILE *__stream); extern int fputc (int __c, FILE *__stream); extern int putc (int __c, FILE *__stream); extern int putchar (int __c); extern int fputc_unlocked (int __c, FILE *__stream); extern int putc_unlocked (int __c, FILE *__stream); extern int putchar_unlocked (int __c); extern int getw (FILE *__stream); extern int putw (int __w, FILE *__stream); extern char *fgets (char *__restrict __s, int __n, FILE *__restrict __stream); extern char *gets (char *__s); extern char *fgets_unlocked (char *__restrict __s, int __n,         FILE *__restrict __stream); extern __ssize_t __getdelim (char **__restrict __lineptr,           size_t *__restrict __n, int __delimiter,           FILE *__restrict __stream); extern __ssize_t getdelim (char **__restrict __lineptr,         size_t *__restrict __n, int __delimiter,         FILE *__restrict __stream); extern __ssize_t getline (char **__restrict __lineptr,        size_t *__restrict __n,        FILE *__restrict __stream); extern int fputs (__const char *__restrict __s, FILE *__restrict __stream); extern int puts (__const char *__s); extern int ungetc (int __c, FILE *__stream); extern size_t fread (void *__restrict __ptr, size_t __size,        size_t __n, FILE *__restrict __stream); extern size_t fwrite (__const void *__restrict __ptr, size_t __size,         size_t __n, FILE *__restrict __s); extern int fputs_unlocked (__const char *__restrict __s,       FILE *__restrict __stream); extern size_t fread_unlocked (void *__restrict __ptr, size_t __size,          size_t __n, FILE *__restrict __stream); extern size_t fwrite_unlocked (__const void *__restrict __ptr, size_t __size,           size_t __n, FILE *__restrict __stream); extern int fseek (FILE *__stream, long int __off, int __whence); extern long int ftell (FILE *__stream); extern void rewind (FILE *__stream); extern int fseeko (FILE *__stream, __off64_t __off, int __whence) __asm__ ("" "fseeko64"); extern __off64_t ftello (FILE *__stream) __asm__ ("" "ftello64"); extern int fgetpos (FILE *__restrict __stream, fpos_t *__restrict __pos) __asm__ ("" "fgetpos64"); extern int fsetpos (FILE *__stream, __const fpos_t *__pos) __asm__ ("" "fsetpos64"); extern int fseeko64 (FILE *__stream, __off64_t __off, int __whence); extern __off64_t ftello64 (FILE *__stream); extern int fgetpos64 (FILE *__restrict __stream, fpos64_t *__restrict __pos); extern int fsetpos64 (FILE *__stream, __const fpos64_t *__pos); extern void clearerr (FILE *__stream) throw (); extern int feof (FILE *__stream) throw (); extern int ferror (FILE *__stream) throw (); extern void clearerr_unlocked (FILE *__stream) throw (); extern int feof_unlocked (FILE *__stream) throw (); extern int ferror_unlocked (FILE *__stream) throw (); extern void perror (__const char *__s); extern int sys_nerr; extern __const char *__const sys_errlist[]; extern int _sys_nerr; extern __const char *__const _sys_errlist[]; extern int fileno (FILE *__stream) throw (); extern int fileno_unlocked (FILE *__stream) throw (); extern FILE *popen (__const char *__command, __const char *__modes); extern int pclose (FILE *__stream); extern char *ctermid (char *__s) throw ();  extern char *cuserid (char *__s);     struct obstack;   extern int obstack_printf (struct obstack *__restrict __obstack,       __const char *__restrict __format, ...)      throw () __attribute__ ((__format__ (__printf__, 2, 3))); extern int obstack_vprintf (struct obstack *__restrict __obstack,        __const char *__restrict __format,        __gnuc_va_list __args)      throw () __attribute__ ((__format__ (__printf__, 2, 0)));        extern void flockfile (FILE *__stream) throw ();    extern int ftrylockfile (FILE *__stream) throw ();   extern void funlockfile (FILE *__stream) throw (); }
24  extern "C" { union wait   {     int w_status;     struct       {  unsigned int __w_termsig:7;  unsigned int __w_coredump:1;  unsigned int __w_retcode:8;  unsigned int:16;       } __wait_terminated;     struct       {  unsigned int __w_stopval:8;  unsigned int __w_stopsig:8;  unsigned int:16;       } __wait_stopped;   }; typedef struct   {     int quot;     int rem;   } div_t; typedef struct   {     long int quot;     long int rem;   } ldiv_t; __extension__ typedef struct   {     long long int quot;     long long int rem;   } lldiv_t; extern size_t __ctype_get_mb_cur_max (void) throw (); extern double atof (__const char *__nptr)      throw () __attribute__ ((__pure__)) __attribute__ ((__nonnull__ (1))); extern int atoi (__const char *__nptr)      throw () __attribute__ ((__pure__)) __attribute__ ((__nonnull__ (1))); extern long int atol (__const char *__nptr)      throw () __attribute__ ((__pure__)) __attribute__ ((__nonnull__ (1))); __extension__ extern long long int atoll (__const char *__nptr)      throw () __attribute__ ((__pure__)) __attribute__ ((__nonnull__ (1))); extern double strtod (__const char *__restrict __nptr,         char **__restrict __endptr) throw () __attribute__ ((__nonnull__ (1))); extern float strtof (__const char *__restrict __nptr,        char **__restrict __endptr) throw () __attribute__ ((__nonnull__ (1))); extern long double strtold (__const char *__restrict __nptr,        char **__restrict __endptr)      throw () __attribute__ ((__nonnull__ (1))); extern long int strtol (__const char *__restrict __nptr,    char **__restrict __endptr, int __base)      throw () __attribute__ ((__nonnull__ (1))); extern unsigned long int strtoul (__const char *__restrict __nptr,       char **__restrict __endptr, int __base)      throw () __attribute__ ((__nonnull__ (1))); __extension__ extern long long int strtoq (__const char *__restrict __nptr,         char **__restrict __endptr, int __base)      throw () __attribute__ ((__nonnull__ (1))); __extension__ extern unsigned long long int strtouq (__const char *__restrict __nptr,            char **__restrict __endptr, int __base)      throw () __attribute__ ((__nonnull__ (1))); __extension__ extern long long int strtoll (__const char *__restrict __nptr,          char **__restrict __endptr, int __base)      throw () __attribute__ ((__nonnull__ (1))); __extension__ extern unsigned long long int strtoull (__const char *__restrict __nptr,      char **__restrict __endptr, int __base)      throw () __attribute__ ((__nonnull__ (1))); extern long int strtol_l (__const char *__restrict __nptr,      char **__restrict __endptr, int __base,      __locale_t __loc) throw () __attribute__ ((__nonnull__ (1, 4))); extern unsigned long int strtoul_l (__const char *__restrict __nptr,         char **__restrict __endptr,         int __base, __locale_t __loc)      throw () __attribute__ ((__nonnull__ (1, 4))); __extension__ extern long long int strtoll_l (__const char *__restrict __nptr,     char **__restrict __endptr, int __base,     __locale_t __loc)      throw () __attribute__ ((__nonnull__ (1, 4))); __extension__ extern unsigned long long int strtoull_l (__const char *__restrict __nptr,        char **__restrict __endptr,        int __base, __locale_t __loc)      throw () __attribute__ ((__nonnull__ (1, 4))); extern double strtod_l (__const char *__restrict __nptr,    char **__restrict __endptr, __locale_t __loc)      throw () __attribute__ ((__nonnull__ (1, 3))); extern float strtof_l (__const char *__restrict __nptr,          char **__restrict __endptr, __locale_t __loc)      throw () __attribute__ ((__nonnull__ (1, 3))); extern long double strtold_l (__const char *__restrict __nptr,          char **__restrict __endptr,          __locale_t __loc) throw () __attribute__ ((__nonnull__ (1, 3))); extern double __strtod_internal (__const char *__restrict __nptr,      char **__restrict __endptr, int __group)      throw () __attribute__ ((__nonnull__ (1))); extern float __strtof_internal (__const char *__restrict __nptr,     char **__restrict __endptr, int __group)      throw () __attribute__ ((__nonnull__ (1))); extern long double __strtold_internal (__const char *__restrict __nptr,            char **__restrict __endptr,            int __group) throw () __attribute__ ((__nonnull__ (1))); extern long int __strtol_internal (__const char *__restrict __nptr,        char **__restrict __endptr,        int __base, int __group)      throw () __attribute__ ((__nonnull__ (1))); extern unsigned long int __strtoul_internal (__const char *__restrict __nptr,           char **__restrict __endptr,           int __base, int __group)      throw () __attribute__ ((__nonnull__ (1))); __extension__ extern long long int __strtoll_internal (__const char *__restrict __nptr,       char **__restrict __endptr,       int __base, int __group)      throw () __attribute__ ((__nonnull__ (1))); __extension__ extern unsigned long long int __strtoull_internal (__const char *          __restrict __nptr,          char **__restrict __endptr,          int __base, int __group)      throw () __attribute__ ((__nonnull__ (1))); extern char *l64a (long int __n) throw (); extern long int a64l (__const char *__s)      throw () __attribute__ ((__pure__)) __attribute__ ((__nonnull__ (1))); extern "C" { typedef __u_char u_char; typedef __u_short u_short; typedef __u_int u_int; typedef __u_long u_long; typedef __quad_t quad_t; typedef __u_quad_t u_quad_t; typedef __fsid_t fsid_t; typedef __loff_t loff_t; typedef __ino64_t ino_t; typedef __ino64_t ino64_t; typedef __dev_t dev_t; typedef __gid_t gid_t; typedef __mode_t mode_t; typedef __nlink_t nlink_t; typedef __uid_t uid_t; typedef __off64_t off_t; typedef __off64_t off64_t; typedef __pid_t pid_t; typedef __id_t id_t; typedef __ssize_t ssize_t; typedef __daddr_t daddr_t; typedef __caddr_t caddr_t; typedef __key_t key_t; typedef __clock_t clock_t; typedef __time_t time_t; typedef __clockid_t clockid_t; typedef __timer_t timer_t; typedef __useconds_t useconds_t; typedef __suseconds_t suseconds_t; typedef unsigned long int ulong; typedef unsigned short int ushort; typedef unsigned int uint; typedef int int8_t __attribute__ ((__mode__ (__QI__))); typedef int int16_t __attribute__ ((__mode__ (__HI__))); typedef int int32_t __attribute__ ((__mode__ (__SI__))); typedef int int64_t __attribute__ ((__mode__ (__DI__))); typedef unsigned int u_int8_t __attribute__ ((__mode__ (__QI__))); typedef unsigned int u_int16_t __attribute__ ((__mode__ (__HI__))); typedef unsigned int u_int32_t __attribute__ ((__mode__ (__SI__))); typedef unsigned int u_int64_t __attribute__ ((__mode__ (__DI__))); typedef int register_t __attribute__ ((__mode__ (__word__))); typedef int __sig_atomic_t; typedef struct   {     unsigned long int __val[(1024 / (8 * sizeof (unsigned long int)))];   } __sigset_t; typedef __sigset_t sigset_t; struct timespec   {     __time_t tv_sec;     long int tv_nsec;   }; struct timeval   {     __time_t tv_sec;     __suseconds_t tv_usec;   }; typedef long int __fd_mask; typedef struct   {     __fd_mask fds_bits[1024 / (8 * sizeof (__fd_mask))];   } fd_set; typedef __fd_mask fd_mask; extern "C" { extern int select (int __nfds, fd_set *__restrict __readfds,      fd_set *__restrict __writefds,      fd_set *__restrict __exceptfds,      struct timeval *__restrict __timeout); extern int pselect (int __nfds, fd_set *__restrict __readfds,       fd_set *__restrict __writefds,       fd_set *__restrict __exceptfds,       const struct timespec *__restrict __timeout,       const __sigset_t *__restrict __sigmask); } __extension__ extern __inline unsigned int gnu_dev_major (unsigned long long int __dev)      throw (); __extension__ extern __inline unsigned int gnu_dev_minor (unsigned long long int __dev)      throw (); __extension__ extern __inline unsigned long long int gnu_dev_makedev (unsigned int __major,        unsigned int __minor)      throw (); __extension__ extern __inline unsigned int gnu_dev_major (unsigned long long int __dev) throw () {   return ((__dev >> 8) & 0xfff) | ((unsigned int) (__dev >> 32) & ~0xfff); } __extension__ extern __inline unsigned int gnu_dev_minor (unsigned long long int __dev) throw () {   return (__dev & 0xff) | ((unsigned int) (__dev >> 12) & ~0xff); } __extension__ extern __inline unsigned long long int gnu_dev_makedev (unsigned int __major, unsigned int __minor) throw () {   return ((__minor & 0xff) | ((__major & 0xfff) << 8)    | (((unsigned long long int) (__minor & ~0xff)) << 12)    | (((unsigned long long int) (__major & ~0xfff)) << 32)); } typedef __blksize_t blksize_t; typedef __blkcnt64_t blkcnt_t; typedef __fsblkcnt64_t fsblkcnt_t; typedef __fsfilcnt64_t fsfilcnt_t; typedef __blkcnt64_t blkcnt64_t; typedef __fsblkcnt64_t fsblkcnt64_t; typedef __fsfilcnt64_t fsfilcnt64_t; struct __sched_param   {     int __sched_priority;   }; struct _pthread_fastlock {   long int __status;   int __spinlock; }; typedef struct _pthread_descr_struct *_pthread_descr; typedef struct __pthread_attr_s {   int __detachstate;   int __schedpolicy;   struct __sched_param __schedparam;   int __inheritsched;   int __scope;   size_t __guardsize;   int __stackaddr_set;   void *__stackaddr;   size_t __stacksize; } pthread_attr_t; __extension__ typedef long long __pthread_cond_align_t; typedef struct {   struct _pthread_fastlock __c_lock;   _pthread_descr __c_waiting;   char __padding[48 - sizeof (struct _pthread_fastlock)    - sizeof (_pthread_descr) - sizeof (__pthread_cond_align_t)];   __pthread_cond_align_t __align; } pthread_cond_t; typedef struct {   int __dummy; } pthread_condattr_t; typedef unsigned int pthread_key_t; typedef struct {   int __m_reserved;   int __m_count;   _pthread_descr __m_owner;   int __m_kind;   struct _pthread_fastlock __m_lock; } pthread_mutex_t; typedef struct {   int __mutexkind; } pthread_mutexattr_t; typedef int pthread_once_t; typedef struct _pthread_rwlock_t {   struct _pthread_fastlock __rw_lock;   int __rw_readers;   _pthread_descr __rw_writer;   _pthread_descr __rw_read_waiting;   _pthread_descr __rw_write_waiting;   int __rw_kind;   int __rw_pshared; } pthread_rwlock_t; typedef struct {   int __lockkind;   int __pshared; } pthread_rwlockattr_t; typedef volatile int pthread_spinlock_t; typedef struct {   struct _pthread_fastlock __ba_lock;   int __ba_required;   int __ba_present;   _pthread_descr __ba_waiting; } pthread_barrier_t; typedef struct {   int __pshared; } pthread_barrierattr_t; typedef unsigned long int pthread_t; } extern long int random (void) throw (); extern void srandom (unsigned int __seed) throw (); extern char *initstate (unsigned int __seed, char *__statebuf,    size_t __statelen) throw () __attribute__ ((__nonnull__ (2))); extern char *setstate (char *__statebuf) throw () __attribute__ ((__nonnull__ (1))); struct random_data   {     int32_t *fptr;     int32_t *rptr;     int32_t *state;     int rand_type;     int rand_deg;     int rand_sep;     int32_t *end_ptr;   }; extern int random_r (struct random_data *__restrict __buf,        int32_t *__restrict __result) throw () __attribute__ ((__nonnull__ (1, 2))); extern int srandom_r (unsigned int __seed, struct random_data *__buf)      throw () __attribute__ ((__nonnull__ (2))); extern int initstate_r (unsigned int __seed, char *__restrict __statebuf,    size_t __statelen,    struct random_data *__restrict __buf)      throw () __attribute__ ((__nonnull__ (2, 4))); extern int setstate_r (char *__restrict __statebuf,          struct random_data *__restrict __buf)      throw () __attribute__ ((__nonnull__ (1, 2))); extern int rand (void) throw (); extern void srand (unsigned int __seed) throw (); extern int rand_r (unsigned int *__seed) throw (); extern double drand48 (void) throw (); extern double erand48 (unsigned short int __xsubi[3]) throw () __attribute__ ((__nonnull__ (1))); extern long int lrand48 (void) throw (); extern long int nrand48 (unsigned short int __xsubi[3])      throw () __attribute__ ((__nonnull__ (1))); extern long int mrand48 (void) throw (); extern long int jrand48 (unsigned short int __xsubi[3])      throw () __attribute__ ((__nonnull__ (1))); extern void srand48 (long int __seedval) throw (); extern unsigned short int *seed48 (unsigned short int __seed16v[3])      throw () __attribute__ ((__nonnull__ (1))); extern void lcong48 (unsigned short int __param[7]) throw () __attribute__ ((__nonnull__ (1))); struct drand48_data   {     unsigned short int __x[3];     unsigned short int __old_x[3];     unsigned short int __c;     unsigned short int __init;     unsigned long long int __a;   }; extern int drand48_r (struct drand48_data *__restrict __buffer,         double *__restrict __result) throw () __attribute__ ((__nonnull__ (1, 2))); extern int erand48_r (unsigned short int __xsubi[3],         struct drand48_data *__restrict __buffer,         double *__restrict __result) throw () __attribute__ ((__nonnull__ (1, 2))); extern int lrand48_r (struct drand48_data *__restrict __buffer,         long int *__restrict __result)      throw () __attribute__ ((__nonnull__ (1, 2))); extern int nrand48_r (unsigned short int __xsubi[3],         struct drand48_data *__restrict __buffer,         long int *__restrict __result)      throw () __attribute__ ((__nonnull__ (1, 2))); extern int mrand48_r (struct drand48_data *__restrict __buffer,         long int *__restrict __result)      throw () __attribute__ ((__nonnull__ (1, 2))); extern int jrand48_r (unsigned short int __xsubi[3],         struct drand48_data *__restrict __buffer,         long int *__restrict __result)      throw () __attribute__ ((__nonnull__ (1, 2))); extern int srand48_r (long int __seedval, struct drand48_data *__buffer)      throw () __attribute__ ((__nonnull__ (2))); extern int seed48_r (unsigned short int __seed16v[3],        struct drand48_data *__buffer) throw () __attribute__ ((__nonnull__ (1, 2))); extern int lcong48_r (unsigned short int __param[7],         struct drand48_data *__buffer)      throw () __attribute__ ((__nonnull__ (1, 2))); extern void *malloc (size_t __size) throw () __attribute__ ((__malloc__)); extern void *calloc (size_t __nmemb, size_t __size)      throw () __attribute__ ((__malloc__)); extern void *realloc (void *__ptr, size_t __size) throw () __attribute__ ((__malloc__)); extern void free (void *__ptr) throw (); extern void cfree (void *__ptr) throw (); extern "C" { extern void *alloca (size_t __size) throw (); } extern void *valloc (size_t __size) throw () __attribute__ ((__malloc__)); extern int posix_memalign (void **__memptr, size_t __alignment, size_t __size)      throw () __attribute__ ((__malloc__)) __attribute__ ((__nonnull__ (1))); extern void abort (void) throw () __attribute__ ((__noreturn__)); extern int atexit (void (*__func) (void)) throw () __attribute__ ((__nonnull__ (1))); extern int on_exit (void (*__func) (int __status, void *__arg), void *__arg)      throw () __attribute__ ((__nonnull__ (1))); extern void exit (int __status) throw () __attribute__ ((__noreturn__)); extern void _Exit (int __status) throw () __attribute__ ((__noreturn__)); extern char *getenv (__const char *__name) throw () __attribute__ ((__nonnull__ (1))); extern char *__secure_getenv (__const char *__name) throw () __attribute__ ((__nonnull__ (1))); extern int putenv (char *__string) throw () __attribute__ ((__nonnull__ (1))); extern int setenv (__const char *__name, __const char *__value, int __replace)      throw () __attribute__ ((__nonnull__ (2))); extern int unsetenv (__const char *__name) throw (); extern int clearenv (void) throw (); extern char *mktemp (char *__template) throw () __attribute__ ((__nonnull__ (1))); extern int mkstemp (char *__template) __asm__ ("" "mkstemp64") __attribute__ ((__nonnull__ (1))); extern int mkstemp64 (char *__template) __attribute__ ((__nonnull__ (1))); extern char *mkdtemp (char *__template) throw () __attribute__ ((__nonnull__ (1))); extern int system (__const char *__command); extern char *canonicalize_file_name (__const char *__name)      throw () __attribute__ ((__nonnull__ (1))); extern char *realpath (__const char *__restrict __name,          char *__restrict __resolved) throw (); typedef int (*__compar_fn_t) (__const void *, __const void *); typedef __compar_fn_t comparison_fn_t; extern void *bsearch (__const void *__key, __const void *__base,         size_t __nmemb, size_t __size, __compar_fn_t __compar)      __attribute__ ((__nonnull__ (1, 2, 5))); extern void qsort (void *__base, size_t __nmemb, size_t __size,      __compar_fn_t __compar) __attribute__ ((__nonnull__ (1, 4))); extern int abs (int __x) throw () __attribute__ ((__const__)); extern long int labs (long int __x) throw () __attribute__ ((__const__)); __extension__ extern long long int llabs (long long int __x)      throw () __attribute__ ((__const__)); extern div_t div (int __numer, int __denom)      throw () __attribute__ ((__const__)); extern ldiv_t ldiv (long int __numer, long int __denom)      throw () __attribute__ ((__const__)); __extension__ extern lldiv_t lldiv (long long int __numer,         long long int __denom)      throw () __attribute__ ((__const__)); extern char *ecvt (double __value, int __ndigit, int *__restrict __decpt,      int *__restrict __sign) throw () __attribute__ ((__nonnull__ (3, 4))); extern char *fcvt (double __value, int __ndigit, int *__restrict __decpt,      int *__restrict __sign) throw () __attribute__ ((__nonnull__ (3, 4))); extern char *gcvt (double __value, int __ndigit, char *__buf)      throw () __attribute__ ((__nonnull__ (3))); extern char *qecvt (long double __value, int __ndigit,       int *__restrict __decpt, int *__restrict __sign)      throw () __attribute__ ((__nonnull__ (3, 4))); extern char *qfcvt (long double __value, int __ndigit,       int *__restrict __decpt, int *__restrict __sign)      throw () __attribute__ ((__nonnull__ (3, 4))); extern char *qgcvt (long double __value, int __ndigit, char *__buf)      throw () __attribute__ ((__nonnull__ (3))); extern int ecvt_r (double __value, int __ndigit, int *__restrict __decpt,      int *__restrict __sign, char *__restrict __buf,      size_t __len) throw () __attribute__ ((__nonnull__ (3, 4, 5))); extern int fcvt_r (double __value, int __ndigit, int *__restrict __decpt,      int *__restrict __sign, char *__restrict __buf,      size_t __len) throw () __attribute__ ((__nonnull__ (3, 4, 5))); extern int qecvt_r (long double __value, int __ndigit,       int *__restrict __decpt, int *__restrict __sign,       char *__restrict __buf, size_t __len)      throw () __attribute__ ((__nonnull__ (3, 4, 5))); extern int qfcvt_r (long double __value, int __ndigit,       int *__restrict __decpt, int *__restrict __sign,       char *__restrict __buf, size_t __len)      throw () __attribute__ ((__nonnull__ (3, 4, 5))); extern int mblen (__const char *__s, size_t __n) throw (); extern int mbtowc (wchar_t *__restrict __pwc,      __const char *__restrict __s, size_t __n) throw (); extern int wctomb (char *__s, wchar_t __wchar) throw (); extern size_t mbstowcs (wchar_t *__restrict __pwcs,    __const char *__restrict __s, size_t __n) throw (); extern size_t wcstombs (char *__restrict __s,    __const wchar_t *__restrict __pwcs, size_t __n)      throw (); extern int rpmatch (__const char *__response) throw () __attribute__ ((__nonnull__ (1))); extern int getsubopt (char **__restrict __optionp,         char *__const *__restrict __tokens,         char **__restrict __valuep)      throw () __attribute__ ((__nonnull__ (1, 2, 3))); extern void setkey (__const char *__key) throw () __attribute__ ((__nonnull__ (1))); extern int posix_openpt (int __oflag); extern int grantpt (int __fd) throw (); extern int unlockpt (int __fd) throw (); extern char *ptsname (int __fd) throw (); extern int ptsname_r (int __fd, char *__buf, size_t __buflen)      throw () __attribute__ ((__nonnull__ (2))); extern int getpt (void); extern int getloadavg (double __loadavg[], int __nelem)      throw () __attribute__ ((__nonnull__ (1))); }
25  typedef long long int SINT64;
26  class AtomicCounter { public:  typedef int counter_type;  AtomicCounter(counter_type value = 0) : counter(value) {}  ~AtomicCounter() {}  counter_type exchangeAdd(counter_type value) {   register counter_type result;   __asm __volatile (    "lock; xaddl %0, %1"     : "=r" (result), "=m" (counter)     : "0" (value), "m" (counter));   return result;  }  counter_type operator +=(counter_type value) {   return exchangeAdd(value) + value;  }  counter_type operator -=(counter_type value) {   return exchangeAdd(-value) - value;  }  counter_type operator ++() {   return exchangeAdd(1) + 1;  }  counter_type operator --() {   return exchangeAdd(-1) - 1;  }  counter_type value() const { return counter; } private:  volatile counter_type counter; };
27  extern "C" { void* gds__alloc_debug(SLONG, const TEXT*, ULONG); void gds_alloc_flag_unfreed(void*); void gds_alloc_report(ULONG, const char*, int); void* gds__alloc(SLONG); ISC_STATUS gds__decode(ISC_STATUS, USHORT*, USHORT*); void isc_decode_date(const ISC_QUAD*, void*); void isc_decode_sql_date(const ISC_DATE*, void*); void isc_decode_sql_time(const ISC_TIME*, void*); void isc_decode_timestamp(const ISC_TIMESTAMP*, void*); ISC_STATUS gds__encode(ISC_STATUS, USHORT); void isc_encode_date(const void*, ISC_QUAD*); void isc_encode_sql_date(const void*, ISC_DATE*); void isc_encode_sql_time(const void*, ISC_TIME*); void isc_encode_timestamp(const void*, ISC_TIMESTAMP*); ULONG gds__free(void*); SLONG fb_interpret(char*, unsigned int, const ISC_STATUS**); SLONG gds__interprete(char*, ISC_STATUS**); void gds__interprete_a(SCHAR*, SSHORT*, ISC_STATUS*, SSHORT*); void gds__log(const TEXT*, ...); void gds__trace(const char*); void gds__trace_raw(const char*, unsigned int = 0); void gds__log_status(const TEXT*, const ISC_STATUS*); int gds__msg_close(void*); SSHORT gds__msg_format(void* handle,          USHORT facility,          USHORT msgNumber,          USHORT bufsize,          TEXT* buffer,          const TEXT* arg1,          const TEXT* arg2,          const TEXT* arg3,          const TEXT* arg4,          const TEXT* arg5); SSHORT gds__msg_lookup(void*, USHORT, USHORT, USHORT,            TEXT*, USHORT*); int gds__msg_open(void**, const TEXT*); void gds__msg_put(void*, USHORT, USHORT, const TEXT*,        const TEXT*, const TEXT*, const TEXT*, const TEXT*); void gds__prefix(TEXT*, const TEXT*); void gds__prefix_lock(TEXT*, const TEXT*); void gds__prefix_msg(TEXT*, const TEXT*); SLONG gds__get_prefix(SSHORT, const TEXT*); ISC_STATUS gds__print_status(const ISC_STATUS*); USHORT gds__parse_bpb(USHORT, const UCHAR*, USHORT*, USHORT*); USHORT gds__parse_bpb2(USHORT, const UCHAR*, SSHORT*, SSHORT*,            USHORT*, USHORT*); SLONG gds__ftof(const SCHAR*, const USHORT length1, SCHAR*,           const USHORT length2); int gds__print_blr(const UCHAR*,        FPTR_PRINT_CALLBACK,        void*, SSHORT); void gds__put_error(const TEXT*); void gds__qtoq(const void*, void*); void gds__register_cleanup(FPTR_VOID_PTR, void*); SLONG gds__sqlcode(const ISC_STATUS*); void gds__sqlcode_s(const ISC_STATUS*, ULONG*); void gds__temp_dir(TEXT*); void* gds__temp_file(BOOLEAN, const TEXT*, TEXT*, TEXT* = __null,  BOOLEAN = 0); void gds__unregister_cleanup(FPTR_VOID_PTR, void*); BOOLEAN gds__validate_lib_path(const TEXT*, const TEXT*, TEXT*,              SLONG); SLONG gds__vax_integer(const UCHAR*, SSHORT); void gds__vtof(const SCHAR*, SCHAR*, USHORT); void gds__vtov(const SCHAR*, char*, SSHORT); void isc_print_sqlerror(SSHORT, const ISC_STATUS*); void isc_sql_interprete(SSHORT, TEXT*, SSHORT); SINT64 isc_portable_integer(const UCHAR*, SSHORT); void gds__cleanup(void); void gds__ulstr(char* buffer, ULONG value, const int minlen, const char filler); void gds__default_printer(void*, SSHORT, const TEXT*); void gds__trace_printer(void*, SSHORT, const TEXT*); void gds__print_pool(class JrdMemoryPool*, const TEXT*, ...); }
28  namespace Firebird { template <typename T, size_t Capacity> class Vector { public:  Vector() : count(0) {}  T& operator[](size_t index) {     {if (!(index < count)) {fprintf (stderr, "GDS Assertion failure: %s %""d""\n", "../src/include/../common/classes/vector.h", 46); abort();}};     return data[index];  }  const T& operator[](size_t index) const {     {if (!(index < count)) {fprintf (stderr, "GDS Assertion failure: %s %""d""\n", "../src/include/../common/classes/vector.h", 50); abort();}};     return data[index];  }  T* begin() { return data; }  T* end() { return data + count; }  const T* begin() const { return data; }  const T* end() const { return data + count; }  size_t getCount() const { return count; }  size_t getCapacity() const { return Capacity; }  void clear() { count = 0; }  void insert(size_t index, const T& item) {    {if (!(index <= count)) {fprintf (stderr, "GDS Assertion failure: %s %""d""\n", "../src/include/../common/classes/vector.h", 62); abort();}};    {if (!(count < Capacity)) {fprintf (stderr, "GDS Assertion failure: %s %""d""\n", "../src/include/../common/classes/vector.h", 63); abort();}};    memmove(data + index + 1, data + index, sizeof(T) * (count++ - index));    data[index] = item;  }  size_t add(const T& item) {   {if (!(count < Capacity)) {fprintf (stderr, "GDS Assertion failure: %s %""d""\n", "../src/include/../common/classes/vector.h", 68); abort();}};   data[count++] = item;     return count;  }  void remove(size_t index) {     {if (!(index < count)) {fprintf (stderr, "GDS Assertion failure: %s %""d""\n", "../src/include/../common/classes/vector.h", 73); abort();}};     memmove(data + index, data + index + 1, sizeof(T) * (--count - index));  }  void shrink(size_t newCount) {   {if (!(newCount <= count)) {fprintf (stderr, "GDS Assertion failure: %s %""d""\n", "../src/include/../common/classes/vector.h", 77); abort();}};   count = newCount;  }  void join(const Vector<T, Capacity>& L) {   {if (!(count + L.count <= Capacity)) {fprintf (stderr, "GDS Assertion failure: %s %""d""\n", "../src/include/../common/classes/vector.h", 81); abort();}};   memcpy(data + count, L.data, sizeof(T) * L.count);   count += L.count;  }  T* getBuffer(size_t capacityL) {   {if (!(capacityL <= Capacity)) {fprintf (stderr, "GDS Assertion failure: %s %""d""\n", "../src/include/../common/classes/vector.h", 88); abort();}};   count = capacityL;   return data;  } protected:  size_t count;  T data[Capacity]; }; template <typename T> class DefaultComparator { public:  static bool greaterThan(const T& i1, const T& i2) {      return i1 > i2;  } }; template <typename T> class DefaultKeyValue { public:  static const T& generate(const void* sender, const T& Item) { return Item; } }; template <typename Value, size_t Capacity, typename Key = Value,  typename KeyOfValue = DefaultKeyValue<Value>,  typename Cmp = DefaultComparator<Key> > class SortedVector : public Vector<Value, Capacity> { public:  SortedVector() : Vector<Value, Capacity>() {}  bool find(const Key& item, size_t& pos) const {   size_t highBound = this->count, lowBound = 0;   while (highBound > lowBound) {    const size_t temp = (highBound + lowBound) >> 1;    if (Cmp::greaterThan(item, KeyOfValue::generate(this, this->data[temp])))     lowBound = temp + 1;    else     highBound = temp;   }   pos = lowBound;   return highBound != this->count &&    !Cmp::greaterThan(KeyOfValue::generate(this, this->data[lowBound]), item);  }  size_t add(const Value& item) {      size_t pos;        find(KeyOfValue::generate(this, item), pos);   insert(pos, item);   return pos;  } }; }
29  namespace Firebird { static inline bool NEED_MERGE(int current_count, int page_count) {  return current_count * 4 / 3 <= page_count; } const int LEAF_PAGE_SIZE = 400; const int NODE_PAGE_SIZE = 3000; const int MAX_TREE_LEVEL = 30; class MallocAllocator { public:  void *allocate(size_t size) {   return malloc(size);  }  void deallocate(void *p) {   free(p);  } }; enum LocType { locEqual, locLess, locGreat, locGreatEqual, locLessEqual }; template <typename Value, typename Key = Value, typename Allocator = MallocAllocator,  typename KeyOfValue = DefaultKeyValue<Value>,  typename Cmp = DefaultComparator<Key>,  int LeafCount = LEAF_PAGE_SIZE / sizeof(Value),  int NodeCount = NODE_PAGE_SIZE / sizeof(void*)> class BePlusTree { public:  BePlusTree(Allocator *_pool) : pool(_pool), level(0), root(__null), defaultAccessor(this) { }  void clear() {   if (!root) return;   void *temp = root;   for (int i = level; i > 0; i--)    temp = (*(NodeList *)temp)[0];   ItemList *items = (ItemList *)temp;   NodeList *lists = items->parent;   while ( items ) {    ItemList *t = items->next;    items->~ItemList();    pool->deallocate(items);    items = t;   }   while (lists) {    NodeList *list = lists;    lists = lists->parent;    while ( list ) {     NodeList *t = list->next;     list->~NodeList();     pool->deallocate(list);     list = t;    }   }   root = __null;   level = 0;  }     ~BePlusTree() {   clear();  }  bool isEmpty() const {   return    root == __null ||    (level == 0 && ((ItemList*)root)->getCount() == 0);  }  bool add(const Value& item);     bool fastRemove() { return defaultAccessor.fastRemove(); }  bool locate(const Key& key) { return defaultAccessor.locate(locEqual, key); }  bool locate(LocType lt, const Key& key) { return defaultAccessor.locate(lt, key); }  bool getFirst() { return defaultAccessor.getFirst(); }  bool getLast() { return defaultAccessor.getLast(); }  bool getNext() { return defaultAccessor.getNext(); }  bool getPrev() { return defaultAccessor.getPrev(); }     Value& current() const { return defaultAccessor.current(); }  bool seemsBiggerThan(const BePlusTree &other) const {   if (level != other.level)    return level > other.level;   if (level == 0) {    if (root == __null)     return other.root == __null;    if (other.root == __null)     return true;    return ((ItemList*) root)->getCount() > ((ItemList*) other.root)->getCount();   }   return ((NodeList*) root)->getCount() > ((NodeList*) other.root)->getCount();  }  size_t approxCount() const {   if (!root) return 0;   if (level == 0) return ((ItemList*)root)->getCount();   size_t items_per_node = LeafCount * 3 / 5;   for (int i = 1; i < level; i++)    items_per_node *= NodeCount * 3 / 5;   {if (!(items_per_node)) {fprintf (stderr, "GDS Assertion failure: %s %""d""\n", "../src/include/../common/classes/tree.h", 209); abort();}};   return ((NodeList*)root)->getCount() * items_per_node;  }  size_t approxSize() const {   if (!root) return 0;   if (level == 0)    return sizeof(ItemList);   size_t bytes_per_node = sizeof(ItemList);   for (int i = 1; i < level; i++)    bytes_per_node *= NodeCount * 3 / 5;   {if (!(bytes_per_node)) {fprintf (stderr, "GDS Assertion failure: %s %""d""\n", "../src/include/../common/classes/tree.h", 227); abort();}};   return ((NodeList*)root)->getCount() * bytes_per_node;  } private:  BePlusTree(Allocator *_pool, void *rootPage) : pool(_pool), level(0),   root(new(rootPage) ItemList()), defaultAccessor(this) {}  class NodeList;     class ItemList : public SortedVector<Value, LeafCount, Key, KeyOfValue, Cmp> {  public:   NodeList *parent;   ItemList *next, *prev;   ItemList(ItemList *items) : parent(__null) {    if ( (next = items->next) )     next->prev = this;    prev = items;    items->next = this;   }   ItemList() : parent(__null), next(__null), prev(__null) {}   friend class BePlusTree;   friend class BePlusTree::NodeList;   friend class BePlusTree::Accessor;  };     class NodeList : public SortedVector<void*, NodeCount, Key, NodeList, Cmp> {  public:   NodeList(NodeList *items) : parent(__null) {    if ( (next = items->next) )     next->prev = this;    prev = items;    items->next = this;   }   NodeList() : parent(__null), next(__null), prev(__null) {}   int level;   NodeList *parent;   NodeList *next, *prev;   static const Key& generate(const void *sender, void *item) {    for (int lev = ((NodeList *)sender)->level; lev > 0; lev--)     item = *((NodeList *)item)->begin();    return KeyOfValue::generate(item, *((ItemList *)item)->begin());   }   static void setNodeParentAndLevel(void *node, int level, NodeList *parent) {    if (level) {     ((NodeList *)node)->parent = parent;     ((NodeList *)node)->level = level - 1;    }    else     ((ItemList *)node)->parent = parent;   }   static void setNodeParent(void *node, int level, NodeList *parent) {    if (level)     ((NodeList *)node)->parent = parent;    else     ((ItemList *)node)->parent = parent;   }  }; public:  class Accessor {  public:   Accessor(BePlusTree* _tree) : tree(_tree), curr(__null), curPos(0) {}   bool fastRemove() {    if ( !tree->level ) {     curr->remove(curPos);     return curPos < curr->getCount();    }    if ( curr->getCount() == 1 ) {     {if (!(curPos == 0)) {fprintf (stderr, "GDS Assertion failure: %s %""d""\n", "../src/include/../common/classes/tree.h", 318); abort();}};     ItemList *temp;     if ( (temp = curr->prev) && NEED_MERGE(temp->getCount(), LeafCount) ) {      temp = curr->next;      tree->_removePage(0, curr);      curr = temp;      return curr;     }     if ( (temp = curr->next) && NEED_MERGE(temp->getCount(), LeafCount) ) {      tree->_removePage(0, curr);      curr = temp;      return true;     }     if ( (temp = curr->prev) ) {      (*curr)[0] = (*temp)[temp->getCount() - 1];      temp->shrink(temp->getCount() - 1);      curr = curr->next;      return curr;     }     if ( (temp = curr->next) ) {      (*curr)[0] = (*temp)[0];      temp->remove(0);      return true;     }     {if (!(false)) {fprintf (stderr, "GDS Assertion failure: %s %""d""\n", "../src/include/../common/classes/tree.h", 343); abort();}};     return false;    }    curr->remove(curPos);    ItemList *temp;    if ( (temp = curr->prev) && NEED_MERGE(temp->getCount() + curr->getCount(), LeafCount) ) {     curPos += temp->getCount();     temp->join(*curr);     tree->_removePage(0, curr);     curr = temp;    }    else {     if ( (temp = curr->next) && NEED_MERGE(temp->getCount() + curr->getCount(), LeafCount) ) {      curr->join(*temp);      tree->_removePage(0, temp);      return true;     }    }    if (curPos >= curr->getCount()) {     {if (!(curPos == curr->getCount())) {fprintf (stderr, "GDS Assertion failure: %s %""d""\n", "../src/include/../common/classes/tree.h", 365); abort();}};     curPos = 0;     curr = curr->next;     return curr;    }    return true;   }   bool locate(const Key& key) {    return locate(locEqual, key);   }   bool locate(LocType lt, const Key& key) {    void *list = tree->root;    if (!list) return false;    for (int lev = tree->level; lev; lev--) {     size_t pos;     if (!((NodeList *)list)->find(key, pos))      if ( pos > 0 ) pos--;     list = (*(NodeList *)list)[pos];    }    curr = (ItemList *)list;    const bool found = curr->find(key, curPos);    switch (lt) {    case locEqual: return found;    case locGreatEqual:     if (curPos == curr->getCount()) {      curr = curr->next;      curPos = 0;     }     return found || curr;    case locLessEqual:     if (found) return true;    case locLess:     if (curPos == 0) {      curr = curr->prev;      if (!curr) return false;      curPos = curr->getCount() - 1;     }     else       curPos--;     return true;    case locGreat:     if (found) curPos++;     if (curPos == curr->getCount()) {      curr = curr->next;      curPos = 0;     }     return curr != 0;    }    return false;   }   bool getFirst() {    void *items = tree->root;    if (!items) return false;    for (int i = tree->level; i > 0; i--)     items = (*(NodeList *)items)[0];    curr = (ItemList *)items;    curPos = 0;    return ((ItemList *)items)->getCount();   }   bool getLast() {    void *items = tree->root;    if (!items) return false;    for (int i = tree->level; i > 0; i--)     items = (*(NodeList *)items)[((NodeList *)items)->getCount() - 1];    curr = (ItemList *)items;    if (((ItemList *)items)->getCount()) {     curPos = ((ItemList *)items)->getCount() - 1;     return true;    }    return false;   }   bool getNext() {    curPos++;    if (curPos >= curr->getCount()) {     if (curr->next) {      curr = curr->next;      curPos = 0;     }     else {      curPos--;      return false;     }    }    return true;   }   bool getPrev() {    if (curPos == 0) {     if (curr->prev) {      curr = curr->prev;      curPos = curr->getCount() - 1;     }     else {      curPos = 0;      return false;     }    }    else     curPos--;    return true;   }      Value& current() const { return (*curr)[curPos]; }  private:   BePlusTree* tree;   ItemList *curr;     size_t curPos;  }; private:  Allocator *pool;  int level;     void *root;  Accessor defaultAccessor;  void _removePage(int level, void *node);  friend class MemoryPool;  friend class NodeList;  friend class Accessor; }; template <typename Value, typename Key, typename Allocator, typename KeyOfValue, typename Cmp, int LeafCount, int NodeCount> bool BePlusTree<Value, Key, Allocator, KeyOfValue, Cmp, LeafCount, NodeCount>::add(const Value& item) {  if (!root) root = new (pool->allocate(sizeof(ItemList))) ItemList();  void *vList = this->root;  const Key& key = KeyOfValue::generate(__null, item);  for (int lev = this->level; lev > 0 ; lev--) {   size_t pos;   if (!((NodeList *)vList)->find(key, pos))    if ( pos > 0 ) pos--;   vList = (*(NodeList *)vList)[pos];  }  ItemList *leaf = (ItemList *)vList;  size_t pos;  if (leaf->find(key, pos)) return false;  if (leaf->getCount() < LeafCount) {   leaf->insert(pos, item);   return true;  }  ItemList *temp;  if ((temp = leaf->next) && temp->getCount() < LeafCount) {   if (pos == LeafCount) {    temp->insert(0, item);   }   else {    temp->insert(0, (*leaf)[LeafCount - 1]);    leaf->shrink(LeafCount - 1);    leaf->insert(pos, item);   }   return true;  }  if ((temp = leaf->prev) && temp->getCount() < LeafCount) {   if (pos == 0) {    temp->insert(temp->getCount(), item);   }   else {    temp->insert(temp->getCount(), (*leaf)[0]);    leaf->remove(0);    leaf->insert(pos - 1, item);   }   return true;  }  ItemList *newLeaf = new(this->pool->allocate(sizeof(ItemList))) ItemList(leaf);  int recovery_map[MAX_TREE_LEVEL];  if (pos == LeafCount) {   newLeaf->insert(0, item);   recovery_map[0] = -1;  }  else {   newLeaf->insert(0, (*leaf)[LeafCount - 1]);   leaf->shrink(leaf->getCount() - 1);   leaf->insert(pos, item);   recovery_map[0] = pos;  }  void *newNode = newLeaf;  NodeList *nodeList = leaf->parent;  int curLevel = 0;  try {   while (nodeList) {    if (nodeList->getCount() < NodeCount) {     NodeList::setNodeParentAndLevel(newNode, curLevel, nodeList);     nodeList->add(newNode);     return true;    }    nodeList->find(NodeList::generate(nodeList, newNode), pos);    NodeList *list;    if ((list = nodeList->next) && list->getCount() < NodeCount) {     if (pos == NodeCount) {      NodeList::setNodeParentAndLevel(newNode, curLevel, list);      list->insert(0, newNode);     }     else {      void *t = (*nodeList)[NodeCount - 1];      NodeList::setNodeParent(t, curLevel, list);      list->insert(0, t);      nodeList->shrink(NodeCount - 1);      NodeList::setNodeParentAndLevel(newNode, curLevel, nodeList);      nodeList->insert(pos, newNode);     }     return true;    }    if ((list = nodeList->prev) && list->getCount() < NodeCount) {     if (pos == 0) {      NodeList::setNodeParentAndLevel(newNode, curLevel, list);      list->insert(list->getCount(), newNode);     }     else {      void *t = (*nodeList)[0];      NodeList::setNodeParent(t, curLevel, list);      list->insert(list->getCount(), t);      nodeList->remove(0);      NodeList::setNodeParentAndLevel(newNode, curLevel, nodeList);      nodeList->insert(pos - 1, newNode);     }     return true;    }    NodeList *newList = new(this->pool->allocate(sizeof(NodeList))) NodeList(nodeList);    if (pos == NodeCount) {     NodeList::setNodeParentAndLevel(newNode, curLevel, newList);     newList->insert(0, newNode);     recovery_map[curLevel + 1] = -1;    }    else {     void *t = (*nodeList)[NodeCount - 1];     NodeList::setNodeParent(t, curLevel, newList);     newList->insert(0, t);     nodeList->shrink(NodeCount - 1);     NodeList::setNodeParentAndLevel(newNode, curLevel, nodeList);     nodeList->insert(pos, newNode);     recovery_map[curLevel + 1] = pos;    }    newNode = newList;    nodeList = nodeList->parent;    curLevel++;   }   nodeList = new(this->pool->allocate(sizeof(NodeList))) NodeList();   nodeList->level = this->level;   nodeList->insert(0, this->root);   NodeList::setNodeParentAndLevel(newNode, this->level, nodeList);   NodeList::setNodeParent(this->root, this->level, nodeList);   nodeList->add(newNode);   this->root = nodeList;   this->level++;  } catch(const std::exception&) {   while (curLevel) {    NodeList *itemL = reinterpret_cast<NodeList*>(newNode);    void *lower;       if (recovery_map[curLevel] < 0) {     lower = (*itemL)[0];    }    else {     lower = (*itemL->prev)[recovery_map[curLevel]];     itemL->prev->remove(recovery_map[curLevel]);     itemL->prev->insert(itemL->prev->getCount(), (*itemL)[0]);     NodeList::setNodeParent((*itemL)[0], curLevel - 1, itemL->prev);    }    itemL->~NodeList();    this->pool->deallocate(newNode);    newNode = lower;    curLevel--;   }   ItemList *itemL2 = reinterpret_cast<ItemList*>(newNode);   if (recovery_map[0] >= 0) {    itemL2->prev->remove(recovery_map[0]);    itemL2->prev->insert(itemL2->prev->getCount(), (*itemL2)[0]);   }   itemL2->~ItemList();   this->pool->deallocate(newNode);   throw;  }  return true; } template <typename Value, typename Key, typename Allocator, typename KeyOfValue, typename Cmp, int LeafCount, int NodeCount> void BePlusTree<Value, Key, Allocator, KeyOfValue, Cmp, LeafCount, NodeCount>::_removePage(int nodeLevel, void *node) {  NodeList *list;  if (nodeLevel) {   NodeList *temp = (NodeList *)node;   if (temp->prev)    temp->prev->next = temp->next;   if (temp->next)    temp->next->prev = temp->prev;   list = temp->parent;  }  else {   ItemList *temp = (ItemList *)node;   if (temp->prev)    temp->prev->next = temp->next;   if (temp->next)    temp->next->prev = temp->prev;   list = temp->parent;  }  if ( list->getCount() == 1 ) {   NodeList *temp;   if ( (temp = list->prev) && NEED_MERGE(temp->getCount(), NodeCount) ) {    _removePage(nodeLevel + 1, list);   }   else   if ( (temp = list->next) && NEED_MERGE(temp->getCount(), NodeCount) ) {    _removePage(nodeLevel + 1, list);   }   else   if ( (temp = list->prev) ) {    NodeList::setNodeParent(     ((*list)[0] = (*temp)[temp->getCount() - 1]), nodeLevel, list);    temp->shrink(temp->getCount() - 1);   }   else   if ( (temp = list->next) ) {    NodeList::setNodeParent(     ((*list)[0] = (*temp)[0]), nodeLevel, list);    temp->remove(0);   }   else   {    {if (!(false)) {fprintf (stderr, "GDS Assertion failure: %s %""d""\n", "../src/include/../common/classes/tree.h", 757); abort();}};   }  }  else  {   size_t pos;   const bool found = list->find(NodeList::generate(list, node), pos);   {if (!(found)) {fprintf (stderr, "GDS Assertion failure: %s %""d""\n", "../src/include/../common/classes/tree.h", 767); abort();}};   list->remove(pos);   if (list == root && list->getCount() == 1) {    root = (*list)[0];    level--;    NodeList::setNodeParent(root, level, __null);    list->~NodeList();    pool->deallocate(list);   }   else {    NodeList *temp;    if ( (temp = list->prev) &&      NEED_MERGE(temp->getCount() + list->getCount(), NodeCount) )    {     temp->join(*list);     for (size_t i = 0; i < list->getCount(); i++)      NodeList::setNodeParent((*list)[i], nodeLevel, temp);     _removePage(nodeLevel + 1, list);    }    else    if ( (temp = list->next) &&      NEED_MERGE(temp->getCount() + list->getCount(), NodeCount) )    {     list->join(*temp);     for (size_t i = 0; i < temp->getCount(); i++)      NodeList::setNodeParent((*temp)[i], nodeLevel, list);     _removePage(nodeLevel + 1, temp);    }   }  }  if (nodeLevel)   ((NodeList *)node)->~NodeList();  else   ((ItemList *)node)->~ItemList();  pool->deallocate(node); } }
30  namespace Firebird { class Mutex { public:  Mutex() {  }  ~Mutex() {  }  void enter() {  }  void leave() {  } }; class MutexLockGuard { public:  explicit MutexLockGuard(Mutex &alock)   : lock(&alock) { lock->enter(); }  ~MutexLockGuard() { lock->leave(); } private:  MutexLockGuard(const MutexLockGuard& source);  Mutex *lock; }; }
31  namespace Firebird { const int MAX_TREE_DEPTH = 4; const size_t ALLOC_ALIGNMENT = 4; static inline size_t MEM_ALIGN(size_t value) {  return ((value + ALLOC_ALIGNMENT - 1) & ~(ALLOC_ALIGNMENT - 1)); } const USHORT MBK_LARGE = 1; const USHORT MBK_PARENT = 2; const USHORT MBK_USED = 4; const USHORT MBK_LAST = 8; const USHORT MBK_DELAYED = 16; struct FreeMemoryBlock {  FreeMemoryBlock* fbk_next_fragment; }; struct MemoryBlock {  USHORT mbk_flags;  SSHORT mbk_type;  union {   struct {     USHORT mbk_length;     USHORT mbk_prev_length;   } small;   ULONG mbk_large_length;  };  union {   class MemoryPool* mbk_pool;   FreeMemoryBlock* mbk_prev_fragment;  };  const char mbk_valgrind_redzone[8]; }; struct MemoryRedirectList {  MemoryBlock* mrl_prev;  MemoryBlock* mrl_next; }; const SSHORT TYPE_POOL = -1; const SSHORT TYPE_EXTENT = -2; const SSHORT TYPE_LEAFPAGE = -3; const SSHORT TYPE_TREEPAGE = -4; struct BlockInfo {  size_t bli_length;  FreeMemoryBlock* bli_fragments;  inline static const size_t& generate(const void* sender, const BlockInfo& i) {   return i.bli_length;  } }; struct MemoryExtent {  MemoryExtent *mxt_next;  MemoryExtent *mxt_prev; }; struct PendingFreeBlock {  PendingFreeBlock *next; }; class MemoryStats { public:  MemoryStats() : mst_usage(0), mst_mapped(0), mst_max_usage(0), mst_max_mapped(0) {}  ~MemoryStats() {}  size_t get_current_usage() const { return mst_usage.value(); }  size_t get_maximum_usage() const { return mst_max_usage; }  size_t get_current_mapping() const { return mst_mapped.value(); }  size_t get_maximum_mapping() const { return mst_max_mapped; } private:  MemoryStats(const MemoryStats& object) {}  AtomicCounter mst_usage;  AtomicCounter mst_mapped;  size_t mst_max_usage;  size_t mst_max_mapped;  friend class MemoryPool; }; class MemoryPool { private:  class InternalAllocator {  public:   void* allocate(size_t size) {    return ((MemoryPool*)this)->tree_alloc(size);   }   void deallocate(void* block) {    ((MemoryPool*)this)->tree_free(block);   }  };  typedef BePlusTree<BlockInfo, size_t, InternalAllocator, BlockInfo> FreeBlocksTree;  bool parent_redirect;  FreeBlocksTree freeBlocks;  MemoryExtent *extents;  Vector<void*, 2> spareLeafs;  Vector<void*, MAX_TREE_DEPTH + 1> spareNodes;  bool needSpare;  PendingFreeBlock *pendingFree;  Mutex lock;  AtomicCounter used_memory;  size_t mapped_memory;  MemoryPool *parent;  MemoryBlock *parent_redirected, *os_redirected;  size_t redirect_amount;  MemoryStats *stats;  void* delayedFree[1024];  int delayedFreeHandles[1024];  size_t delayedFreeCount;  size_t delayedFreePos;  static void* external_alloc(size_t &size);  static void external_free(void* blk, size_t &size, bool pool_destroying);  void* tree_alloc(size_t size);  void tree_free(void* block);  void updateSpare();  inline void addFreeBlock(MemoryBlock* blk);  void removeFreeBlock(MemoryBlock* blk);  void free_blk_extent(MemoryBlock* blk);  void* internal_alloc(size_t size, SSHORT type = 0  );  void internal_deallocate(void* block);  MemoryPool(const MemoryPool& pool) : freeBlocks((InternalAllocator*)this) { }  inline void increment_usage(size_t size);  inline void decrement_usage(size_t size);  inline void increment_mapping(size_t size);  inline void decrement_mapping(size_t size); protected:  MemoryPool(MemoryPool* _parent, MemoryStats &_stats, void* first_extent, void* root_page);  ~MemoryPool() {  }  static MemoryPool* internal_create(size_t instance_size,   MemoryPool* parent = __null, MemoryStats &stats = default_stats_group); public:  static MemoryStats default_stats_group;  static MemoryPool* processMemoryPool;  static MemoryPool* createPool(MemoryPool* parent = __null, MemoryStats &stats = default_stats_group) {   return internal_create(sizeof(MemoryPool), parent, stats);  }  static MemoryPool* setContextPool(MemoryPool *newPool);  static MemoryPool* getContextPool();  void setStatsGroup(MemoryStats &stats);  static void deletePool(MemoryPool* pool);  void* allocate(size_t size, SSHORT type = 0  );  void* allocate_nothrow(size_t size, SSHORT type = 0  );  void deallocate(void* block);  bool verify_pool(bool fast_checks_only = false);  void print_contents(FILE*, bool = false, const char* filter_path = 0);  void print_contents(const char* filename, bool = false,   const char* filter_path = 0);  static void globalFree(void* block) {      if (block)     ((MemoryBlock*)((char*)block - MEM_ALIGN(sizeof(MemoryBlock))))->mbk_pool->deallocate(block);  }  void* calloc(size_t size, SSHORT type = 0  ) {   void* result = allocate(size, type   );   memset(result, 0, size);   return result;  }  static SSHORT blk_type(const void* mem) {   return ((MemoryBlock*)((char *)mem - MEM_ALIGN(sizeof(MemoryBlock))))->mbk_type;  }  friend class InternalAllocator; }; class ContextPoolHolder { public:  ContextPoolHolder(MemoryPool* newPool) {   savedPool = MemoryPool::setContextPool(newPool);  }  ~ContextPoolHolder() {   MemoryPool::setContextPool(savedPool);  } private:  MemoryPool* savedPool; }; template <typename SubsystemThreadData, typename SubsystemPool> class SubsystemContextPoolHolder : public ContextPoolHolder { public:  SubsystemContextPoolHolder <SubsystemThreadData, SubsystemPool>  (   SubsystemThreadData* subThreadData,   SubsystemPool* newPool  )   : ContextPoolHolder(newPool),   savedThreadData(subThreadData),   savedPool(savedThreadData->getDefaultPool())  {   savedThreadData->setDefaultPool(newPool);  }  ~SubsystemContextPoolHolder() {   savedThreadData->setDefaultPool(savedPool);  } private:  SubsystemThreadData* savedThreadData;  SubsystemPool* savedPool; }; }
32  using Firebird::MemoryPool;
33  inline static MemoryPool* getDefaultMemoryPool() { return Firebird::MemoryPool::processMemoryPool; }
34  inline void* operator new[](size_t s, Firebird::MemoryPool& pool) {  return pool.allocate(s); }
35  namespace Firebird {  template <class T>  class allocator  {   public:   typedef size_t size_type;   typedef ptrdiff_t difference_type;   typedef T* pointer;   typedef const T* const_pointer;   typedef T& reference;   typedef const T& const_reference;   typedef T value_type;   allocator(MemoryPool& p, SSHORT t = 0) : pool(&p), type(t) {}   allocator(MemoryPool* p = getDefaultMemoryPool(), SSHORT t = 0) : pool(p), type(t) {}   template <class DST>   allocator(const allocator<DST> &alloc)    : pool(alloc.getPool()), type(alloc.getType()) { }   pointer allocate(size_type s, const void* = 0)    { return (pointer) pool->allocate(sizeof(T) * s, 0); }   char* _Charalloc(size_type n)    { return (char*) pool->allocate(n, 0); }   void deallocate(pointer p, size_type s) { pool->deallocate(p); }   void deallocate(void* p, size_type s) { pool->deallocate(p); }   void construct(pointer p, const T& v) { new(p) T(v); }   void destroy(pointer p) { p->~T(); }   size_type max_size() const { return (size_type) - 1 / sizeof(T); }   pointer address(reference X) const { return &X; }   const_pointer address(const_reference X) const { return &X; }   template <class _Tp1> struct rebind {    typedef Firebird::allocator<_Tp1> other;   };   bool operator==(const allocator<T>& rhs) const   {    return pool == rhs.pool && type == rhs.type;   }   MemoryPool* getPool() const { return pool; }   SSHORT getType() const { return type; }  private:   MemoryPool* pool;   SSHORT type;  };  class PermanentStorage {  private:   MemoryPool& pool;  protected:   explicit PermanentStorage(MemoryPool& p) : pool(p) { }   MemoryPool& getPool() const { return pool; }  };  class AutoStorage : public PermanentStorage {  private:   void ProbeStack() const;  public:   static MemoryPool& getAutoMemoryPool();  protected:   AutoStorage() : PermanentStorage(getAutoMemoryPool()) {    ProbeStack();   }   explicit AutoStorage(MemoryPool& p) : PermanentStorage(p) { }  }; }
36  namespace Firebird {  class AbstractString : private AutoStorage {  public:   typedef char char_type;   typedef size_t size_type;   typedef ptrdiff_t difference_type;   typedef char* pointer;   typedef const char* const_pointer;   typedef char& reference;   typedef const char& const_reference;   typedef char value_type;   typedef pointer iterator;   typedef const_pointer const_iterator;   static const size_type npos;   enum {INLINE_BUFFER_SIZE = 32, INIT_RESERVE = 16 };  protected:   typedef USHORT internal_size_type;   char_type inlineBuffer[INLINE_BUFFER_SIZE];   char_type* stringBuffer;   internal_size_type stringLength, bufferSize;  private:   inline void checkPos(size_type pos) const {    if (pos >= length()) {     fatal_exception::raise("Firebird::string - pos out of range");    }   }   static inline void checkLength(size_type len) {    if (len > max_length()) {     fatal_exception::raise("Firebird::string - length exceeds predefined limit");    }   }   void reserveBuffer(size_type newLen) {    size_type newSize = newLen + 1;    if (newSize > bufferSize) {     checkLength(newLen);     if (newSize / 2 < bufferSize)      newSize = bufferSize * 2;     if (newSize > max_length() + 1)      newSize = max_length() + 1;     char_type *newBuffer = new(getPool()) char_type[newSize];     memcpy(newBuffer, stringBuffer, sizeof(char_type) * (stringLength + 1));     if (stringBuffer != inlineBuffer)      delete[] stringBuffer;     stringBuffer = newBuffer;     bufferSize = static_cast<internal_size_type>(newSize);    }   }   void initialize(size_type len) {    if (len < INLINE_BUFFER_SIZE) {     stringBuffer = inlineBuffer;     bufferSize = INLINE_BUFFER_SIZE;    }    else {     stringBuffer = __null;     checkLength(len);     size_type newSize = len + 1 + INIT_RESERVE;     if (newSize > max_length() + 1)      newSize = max_length() + 1;     stringBuffer = new(getPool()) char_type[newSize];     bufferSize = static_cast<internal_size_type>(newSize);    }    stringLength = static_cast<internal_size_type>(len);    stringBuffer[stringLength] = 0;   }   void shrinkBuffer() {   }  protected:   AbstractString(size_type sizeL, const_pointer datap);   AbstractString(const_pointer p1, size_type n1,       const_pointer p2, size_type n2);   AbstractString(const AbstractString& v);   inline AbstractString() :    stringBuffer(inlineBuffer), stringLength(0), bufferSize(INLINE_BUFFER_SIZE)   {    stringBuffer[0] = 0;   }   AbstractString(size_type sizeL, char_type c);   inline explicit AbstractString(MemoryPool& p) : AutoStorage(p),    stringBuffer(inlineBuffer), stringLength(0), bufferSize(INLINE_BUFFER_SIZE)   {    stringBuffer[0] = 0;   }   inline AbstractString(MemoryPool& p, const AbstractString& v)    : AutoStorage(p)   {    initialize(v.length());    memcpy(stringBuffer, v.c_str(), stringLength);   }   inline AbstractString(MemoryPool& p, const char_type* s, size_type l)    : AutoStorage(p)   {    initialize(l);    memcpy(stringBuffer, s, l);   }   pointer Modify(void) {    return stringBuffer;   }   static void AdjustRange(size_type length, size_type& pos, size_type& n);   pointer baseAssign(size_type n);   pointer baseAppend(size_type n);   pointer baseInsert(size_type p0, size_type n);   void baseErase(size_type p0, size_type n);   enum TrimType {TrimLeft, TrimRight, TrimBoth};   void baseTrim(TrimType WhereTrim, const_pointer ToTrim);  public:   inline const_pointer c_str() const {    return stringBuffer;   }   inline size_type length() const {    return stringLength;   }   inline const_pointer nullStr() const {    return stringLength ? stringBuffer : 0;   }   inline size_type recalculate_length()   {       stringLength = strlen(stringBuffer);       return stringLength;   }   void reserve(size_type n = 0);   void resize(size_type n, char_type c = ' ');   inline size_type copy_from(pointer s, size_type n, size_type pos = 0) const   {    AdjustRange(length(), pos, n);    memcpy(s, c_str() + pos, n);    return n;   }   inline size_type find(const AbstractString& str, size_type pos = 0) const {    return find(str.c_str(), pos);   }   inline size_type find(const_pointer s, size_type pos = 0) const {    const_pointer p = strstr(c_str() + pos, s);    return p ? p - c_str() : npos;   }   inline size_type find(char_type c, size_type pos = 0) const {    const_pointer p = strchr(c_str() + pos, c);    return p ? p - c_str() : npos;   }   inline size_type rfind(const AbstractString& str, size_type pos = npos) const {    return rfind(str.c_str(), pos);   }   size_type rfind(const_pointer s, size_type pos = npos) const;   size_type rfind(char_type c, size_type pos = npos) const;   inline size_type find_first_of(const AbstractString& str, size_type pos = 0) const {    return find_first_of(str.c_str(), pos, str.length());   }   size_type find_first_of(const_pointer s, size_type pos, size_type n) const;   inline size_type find_first_of(const_pointer s, size_type pos = 0) const {    return find_first_of(s, pos, strlen(s));   }   inline size_type find_first_of(char_type c, size_type pos = 0) const {    return find(c, pos);   }   inline size_type find_last_of(const AbstractString& str, size_type pos = npos) const {    return find_last_of(str.c_str(), pos, str.length());   }   size_type find_last_of(const_pointer s, size_type pos, size_type n = npos) const;   inline size_type find_last_of(const_pointer s, size_type pos = npos) const {    return find_last_of(s, pos, strlen(s));   }   inline size_type find_last_of(char_type c, size_type pos = npos) const {    return rfind(c, pos);   }   inline size_type find_first_not_of(const AbstractString& str, size_type pos = 0) const {    return find_first_not_of(str.c_str(), pos, str.length());   }   size_type find_first_not_of(const_pointer s, size_type pos, size_type n) const;   inline size_type find_first_not_of(const_pointer s, size_type pos = 0) const {    return find_first_not_of(s, pos, strlen(s));   }   inline size_type find_first_not_of(char_type c, size_type pos = 0) const {    const char s[2] = {c, 0};    return find_first_not_of(s, pos, 1);   }   inline size_type find_last_not_of(const AbstractString& str, size_type pos = npos) const {    return find_last_not_of(str.c_str(), pos, str.length());   }   size_type find_last_not_of(const_pointer s, size_type pos, size_type n = npos) const;   inline size_type find_last_not_of(const_pointer s, size_type pos = npos) const {    return find_last_not_of(s, pos, strlen(s));   }   inline size_type find_last_not_of(char_type c, size_type pos = npos) const {    const char s[2] = {c, 0};    return find_last_not_of(s, pos, 1);   }   inline iterator begin() {    return Modify();   }   inline const_iterator begin() const {    return c_str();   }   inline iterator end() {    return Modify() + length();   }   inline const_iterator end() const {    return c_str() + length();   }   inline const_reference at(size_type pos) const {    checkPos(pos);    return c_str()[pos];   }   inline reference at(size_type pos) {    checkPos(pos);    return Modify()[pos];   }   inline const_reference operator[](size_type pos) const {    return at(pos);   }   inline reference operator[](size_type pos) {    return at(pos);   }   inline const_pointer data() const {    return c_str();   }   inline size_type size() const {    return length();   }   static inline size_type max_length() {    return 0xfffe;   }   inline size_type capacity() const {    return bufferSize - 1;   }   inline bool empty() const {    return length() == 0;   }   inline bool hasData() const {    return !empty();   }   inline bool isEmpty() const {    return empty();   }   void upper();   void lower();   inline void ltrim(const_pointer ToTrim = " ") {    baseTrim(TrimLeft, ToTrim);   }   inline void rtrim(const_pointer ToTrim = " ") {    baseTrim(TrimRight, ToTrim);   }   inline void trim(const_pointer ToTrim = " ") {    baseTrim(TrimBoth, ToTrim);   }   inline void alltrim(const_pointer ToTrim = " ") {    baseTrim(TrimBoth, ToTrim);   }   bool LoadFromFile(FILE *file);   void vprintf(const char* Format, va_list params);   void printf(const char* Format, ...);   inline int copyTo(pointer to, size_type toSize) const   {    {if (!(to)) {fprintf (stderr, "GDS Assertion failure: %s %""d""\n", "../src/include/../common/classes/fb_string.h", 363); abort();}};    {if (!(toSize)) {fprintf (stderr, "GDS Assertion failure: %s %""d""\n", "../src/include/../common/classes/fb_string.h", 364); abort();}};    if (--toSize > length())    {     toSize = length();    }    memcpy(to, c_str(), toSize);    to[toSize] = 0;    return toSize;   }   inline ~AbstractString() {    if (stringBuffer != inlineBuffer)     delete[] stringBuffer;   }  };  class StringComparator {  public:   static inline int compare(AbstractString::const_pointer s1, AbstractString::const_pointer s2, AbstractString::size_type n) {    return memcmp(s1, s2, n);   }  };  class PathNameComparator {  public:   static int compare(AbstractString::const_pointer s1, AbstractString::const_pointer s2, AbstractString::size_type n);  };  template<typename Comparator>  class StringBase : public AbstractString {   typedef StringBase<Comparator> StringType;  protected:   inline StringBase<Comparator>(const_pointer p1, size_type n1,         const_pointer p2, size_type n2) :       AbstractString(p1, n1, p2, n2) {}  private:   inline StringType add(const_pointer s, size_type n) const {    return StringBase<Comparator>(c_str(), length(), s, n);   }  public:   inline StringBase<Comparator>() : AbstractString() {}   inline StringBase<Comparator>(const StringType& v) : AbstractString(v) {}   inline StringBase<Comparator>(const_pointer s, size_type n) : AbstractString(n, s) {}   inline StringBase<Comparator>(const_pointer s) : AbstractString(strlen(s), s) {}   inline StringBase<Comparator>(const unsigned char* s) : AbstractString(strlen((char*)s), (char*)s) {}   inline StringBase<Comparator>(size_type n, char_type c) : AbstractString(n, c) {}   inline StringBase<Comparator>(char_type c) : AbstractString(1, c) {}   inline StringBase<Comparator>(const_iterator first, const_iterator last) : AbstractString(last - first, first) {}   inline explicit StringBase<Comparator>(MemoryPool& p) : AbstractString(p) {}   inline StringBase<Comparator>(MemoryPool& p, const AbstractString& v) : AbstractString(p, v) {}   inline StringBase<Comparator>(MemoryPool& p, const char_type* s, size_type l) : AbstractString(p, s, l) {}   inline StringType& append(const StringType& str) {    {if (!(&str != this)) {fprintf (stderr, "GDS Assertion failure: %s %""d""\n", "../src/include/../common/classes/fb_string.h", 416); abort();}};    return append(str.c_str(), str.length());   }   inline StringType& append(const StringType& str, size_type pos, size_type n) {    {if (!(&str != this)) {fprintf (stderr, "GDS Assertion failure: %s %""d""\n", "../src/include/../common/classes/fb_string.h", 420); abort();}};    AdjustRange(str.length(), pos, n);    return append(str.c_str() + pos, n);   }   inline StringType& append(const_pointer s, size_type n) {    memcpy(baseAppend(n), s, n);    return *this;   }   inline StringType& append(const_pointer s) {    return append(s, strlen(s));   }   inline StringType& append(size_type n, char_type c) {    memset(baseAppend(n), c, n);    return *this;   }   inline StringType& append(const_iterator first, const_iterator last) {    return append(first, last - first);   }   inline StringType& assign(const StringType& str) {    {if (!(&str != this)) {fprintf (stderr, "GDS Assertion failure: %s %""d""\n", "../src/include/../common/classes/fb_string.h", 440); abort();}};    return assign(str.c_str(), str.length());   }   inline StringType& assign(const StringType& str, size_type pos, size_type n) {    {if (!(&str != this)) {fprintf (stderr, "GDS Assertion failure: %s %""d""\n", "../src/include/../common/classes/fb_string.h", 444); abort();}};    AdjustRange(str.length(), pos, n);    return assign(&str.c_str()[pos], n);   }   inline StringType& assign(const_pointer s, size_type n) {    memcpy(baseAssign(n), s, n);    return *this;   }   inline StringType& assign(const_pointer s) {    return assign(s, strlen(s));   }   inline StringType& assign(size_type n, char_type c) {    memset(baseAssign(n), c, n);    return *this;   }   inline StringType& assign(const_iterator first, const_iterator last) {    return assign(first, last - first);   }   inline StringType& operator=(const StringType& v) {    {if (!(&v != this)) {fprintf (stderr, "GDS Assertion failure: %s %""d""\n", "../src/include/../common/classes/fb_string.h", 464); abort();}};    return assign(v);   }   inline StringType& operator=(const_pointer s) {    return assign(s, strlen(s));   }   inline StringType& operator=(char_type c) {    return assign(&c, 1);   }   inline StringType& operator+=(const StringType& v) {    {if (!(&v != this)) {fprintf (stderr, "GDS Assertion failure: %s %""d""\n", "../src/include/../common/classes/fb_string.h", 474); abort();}};    return append(v);   }   inline StringType& operator+=(const_pointer s) {    return append(s);   }   inline StringType& operator+=(char_type c) {    return append(1, c);   }   inline StringType operator+(const StringType& v) const {    {if (!(&v != this)) {fprintf (stderr, "GDS Assertion failure: %s %""d""\n", "../src/include/../common/classes/fb_string.h", 484); abort();}};    return add(v.c_str(), v.length());   }   inline StringType operator+(const_pointer s) const {    return add(s, strlen(s));   }   inline StringType operator+(char_type c) const {    return add(&c, 1);   }   inline StringBase<StringComparator> ToString() const {    return StringBase<StringComparator>(c_str());   }   inline StringBase<PathNameComparator> ToPathName() const {    return StringBase<PathNameComparator>(c_str());   }   inline StringType& insert(size_type p0, const StringType& str) {    {if (!(&str != this)) {fprintf (stderr, "GDS Assertion failure: %s %""d""\n", "../src/include/../common/classes/fb_string.h", 502); abort();}};    return insert(p0, str.c_str(), str.length());   }   inline StringType& insert(size_type p0, const StringType& str, size_type pos, size_type n) {    {if (!(&str != this)) {fprintf (stderr, "GDS Assertion failure: %s %""d""\n", "../src/include/../common/classes/fb_string.h", 506); abort();}};    AdjustRange(str.length(), pos, n);    return insert(p0, &str.c_str()[pos], n);   }   inline StringType& insert(size_type p0, const_pointer s, size_type n) {    if (p0 >= length()) {     return append(s, n);    }    memcpy(baseInsert(p0, n), s, n);    return *this;   }   inline StringType& insert(size_type p0, const_pointer s) {    return insert(p0, s, strlen(s));   }   inline StringType& insert(size_type p0, size_type n, char_type c) {    if (p0 >= length()) {     return append(n, c);    }    memset(baseInsert(p0, n), c, n);    return *this;   }   inline void insert(iterator it, size_type n, char_type c) {    insert(it - c_str(), n, c);   }   inline void insert(iterator it, const_iterator first, const_iterator last) {    insert(it - c_str(), first, last - first);   }   inline StringType& erase(size_type p0 = 0, size_type n = npos) {    baseErase(p0, n);    return *this;   }   inline iterator erase(iterator it) {    erase(it - c_str(), 1);    return it;   }   inline iterator erase(iterator first, iterator last) {    erase(first - c_str(), last - first);    return first;   }   inline StringType& replace(size_type p0, size_type n0, const StringType& str) {    {if (!(&str != this)) {fprintf (stderr, "GDS Assertion failure: %s %""d""\n", "../src/include/../common/classes/fb_string.h", 549); abort();}};    return replace(p0, n0, str.c_str(), str.length());   }   inline StringType& replace(size_type p0, size_type n0, const StringType& str, size_type pos, size_type n) {    {if (!(&str != this)) {fprintf (stderr, "GDS Assertion failure: %s %""d""\n", "../src/include/../common/classes/fb_string.h", 553); abort();}};    AdjustRange(str.length(), pos, n);    return replace(p0, n0, &str.c_str()[pos], n);   }   inline StringType& replace(size_type p0, size_type n0, const_pointer s, size_type n) {    erase(p0, n0);    return insert(p0, s, n);   }   inline StringType& replace(size_type p0, size_type n0, const_pointer s) {    return replace(p0, n0, s, strlen(s));   }   inline StringType& replace(size_type p0, size_type n0, size_type n, char_type c) {    erase(p0, n0);    return insert(p0, n, c);   }   inline StringType& replace(iterator first0, iterator last0, const StringType& str) {    {if (!(&str != this)) {fprintf (stderr, "GDS Assertion failure: %s %""d""\n", "../src/include/../common/classes/fb_string.h", 569); abort();}};    return replace(first0 - c_str(), last0 - first0, str);   }   inline StringType& replace(iterator first0, iterator last0, const_pointer s, size_type n) {    return replace(first0 - c_str(), last0 - first0, s, n);   }   inline StringType& replace(iterator first0, iterator last0, const_pointer s) {    return replace(first0 - c_str(), last0 - first0, s);   }   inline StringType& replace(iterator first0, iterator last0, size_type n, char_type c) {    return replace(first0 - c_str(), last0 - first0, n, c);   }   inline StringType& replace(iterator first0, iterator last0, const_iterator first, const_iterator last) {    return replace(first0 - c_str(), last0 - first0, first, last - first);   }   inline StringType substr(size_type pos = 0, size_type n = npos) const {    AdjustRange(length(), pos, n);    return StringType(&c_str()[pos], n);   }   inline int compare(const StringType& str) const {    return compare(str.c_str(), str.length());   }   inline int compare(size_type p0, size_type n0, const StringType& str) {    return compare(p0, n0, str.c_str(), str.length());   }   inline int compare(size_type p0, size_type n0, const StringType& str, size_type pos, size_type n) {    AdjustRange(str.length(), pos, n);    return compare(p0, n0, &str.c_str()[pos], n);   }   inline int compare(const_pointer s) const {    return compare(s, strlen(s));   }   int compare(size_type p0, size_type n0, const_pointer s, size_type n) const {    AdjustRange(length(), p0, n0);    const size_type ml = n0 < n ? n0 : n;    const int rc = Comparator::compare(&c_str()[p0], s, ml);    return rc ? rc : n0 - n;   }   int compare(const_pointer s, size_type n) const {    const size_type ml = length() < n ? length() : n;    const int rc = Comparator::compare(c_str(), s, ml);    return rc ? rc : length() - n;   }   inline bool operator< (const StringType& str) const {return compare(str) < 0;}   inline bool operator<=(const StringType& str) const {return compare(str) <= 0;}   inline bool operator==(const StringType& str) const {return compare(str) == 0;}   inline bool operator>=(const StringType& str) const {return compare(str) >= 0;}   inline bool operator> (const StringType& str) const {return compare(str) > 0;}   inline bool operator!=(const StringType& str) const {return compare(str) != 0;}   inline bool operator< (const char_type* str) const {return compare(str) < 0;}   inline bool operator<=(const char_type* str) const {return compare(str) <= 0;}   inline bool operator==(const char_type* str) const {return compare(str) == 0;}   inline bool operator>=(const char_type* str) const {return compare(str) >= 0;}   inline bool operator> (const char_type* str) const {return compare(str) > 0;}   inline bool operator!=(const char_type* str) const {return compare(str) != 0;}     };  typedef StringBase<StringComparator> string;  inline string operator+(string::const_pointer s, const string& str) {   string rc(s);   rc += str;   return rc;  }  inline string operator+(string::char_type c, const string& str) {   string rc(c);   rc += str;   return rc;  }  typedef StringBase<PathNameComparator> PathName;  inline PathName operator+(PathName::const_pointer s, const PathName& str) {   PathName rc(s);   rc += str;   return rc;  }  inline PathName operator+(PathName::char_type c, const PathName& str) {   PathName rc(c);   rc += str;   return rc;  } }
37  namespace Firebird { class ClumpletReader : protected AutoStorage { public:  enum Kind {Tagged, UnTagged, SpbAttach, SpbStart, Tpb };  ClumpletReader(Kind k, const UCHAR* buffer, size_t buffLen);  virtual ~ClumpletReader() { }  bool isEof() const { return cur_offset >= getBufferLength(); }  void moveNext();  void rewind();  bool find(UCHAR tag);  UCHAR getClumpTag() const;  size_t getClumpLength() const;  SLONG getInt() const;  bool getBoolean() const;  SINT64 getBigInt() const;  string& getString(string& str) const;  PathName& getPath(PathName& str) const;  const UCHAR* getBytes() const;  UCHAR getBufferTag() const;  size_t getBufferLength() const  {   size_t rc = getBufferEnd() - getBuffer();   if (rc == 1 && kind != UnTagged && kind != SpbStart)   {    rc = 0;   }   return rc;  }  size_t getCurOffset() const { return cur_offset; }  void setCurOffset(size_t newOffset) { cur_offset = newOffset; }  void dump() const; protected:  enum ClumpletType {TraditionalDpb, SingleTpb, StringSpb, IntSpb, ByteSpb};  ClumpletType getClumpletType(UCHAR tag) const;  size_t getClumpletSize(bool wTag, bool wLength, bool wData) const;  void adjustSpbState();  size_t cur_offset;  const Kind kind;  UCHAR spbState;  virtual const UCHAR* getBuffer() const { return static_buffer; }  virtual const UCHAR* getBufferEnd() const { return static_buffer_end; }  virtual void usage_mistake(const char* what) const;  virtual void invalid_structure(const char* what) const; private:  ClumpletReader(const ClumpletReader& from);  ClumpletReader& operator=(const ClumpletReader& from);  const UCHAR* static_buffer;  const UCHAR* static_buffer_end; }; }
38  extern "C" { enum {   _ISupper = ((0) < 8 ? ((1 << (0)) << 8) : ((1 << (0)) >> 8)),   _ISlower = ((1) < 8 ? ((1 << (1)) << 8) : ((1 << (1)) >> 8)),   _ISalpha = ((2) < 8 ? ((1 << (2)) << 8) : ((1 << (2)) >> 8)),   _ISdigit = ((3) < 8 ? ((1 << (3)) << 8) : ((1 << (3)) >> 8)),   _ISxdigit = ((4) < 8 ? ((1 << (4)) << 8) : ((1 << (4)) >> 8)),   _ISspace = ((5) < 8 ? ((1 << (5)) << 8) : ((1 << (5)) >> 8)),   _ISprint = ((6) < 8 ? ((1 << (6)) << 8) : ((1 << (6)) >> 8)),   _ISgraph = ((7) < 8 ? ((1 << (7)) << 8) : ((1 << (7)) >> 8)),   _ISblank = ((8) < 8 ? ((1 << (8)) << 8) : ((1 << (8)) >> 8)),   _IScntrl = ((9) < 8 ? ((1 << (9)) << 8) : ((1 << (9)) >> 8)),   _ISpunct = ((10) < 8 ? ((1 << (10)) << 8) : ((1 << (10)) >> 8)),   _ISalnum = ((11) < 8 ? ((1 << (11)) << 8) : ((1 << (11)) >> 8)) }; extern __const unsigned short int **__ctype_b_loc (void)      __attribute__ ((__const)); extern __const __int32_t **__ctype_tolower_loc (void)      __attribute__ ((__const)); extern __const __int32_t **__ctype_toupper_loc (void)      __attribute__ ((__const)); extern int isalnum (int) throw (); extern int isalpha (int) throw (); extern int iscntrl (int) throw (); extern int isdigit (int) throw (); extern int islower (int) throw (); extern int isgraph (int) throw (); extern int isprint (int) throw (); extern int ispunct (int) throw (); extern int isspace (int) throw (); extern int isupper (int) throw (); extern int isxdigit (int) throw (); extern int tolower (int __c) throw (); extern int toupper (int __c) throw (); extern int isblank (int) throw (); extern int isctype (int __c, int __mask) throw (); extern int isascii (int __c) throw (); extern int toascii (int __c) throw (); extern int _toupper (int) throw (); extern int _tolower (int) throw (); extern int isalnum_l (int, __locale_t) throw (); extern int isalpha_l (int, __locale_t) throw (); extern int iscntrl_l (int, __locale_t) throw (); extern int isdigit_l (int, __locale_t) throw (); extern int islower_l (int, __locale_t) throw (); extern int isgraph_l (int, __locale_t) throw (); extern int isprint_l (int, __locale_t) throw (); extern int ispunct_l (int, __locale_t) throw (); extern int isspace_l (int, __locale_t) throw (); extern int isupper_l (int, __locale_t) throw (); extern int isxdigit_l (int, __locale_t) throw (); extern int isblank_l (int, __locale_t) throw (); extern int __tolower_l (int __c, __locale_t __l) throw (); extern int tolower_l (int __c, __locale_t __l) throw (); extern int __toupper_l (int __c, __locale_t __l) throw (); extern int toupper_l (int __c, __locale_t __l) throw (); }
39  namespace Firebird { void ClumpletReader::dump() const {  static int dmp = 0;  gds__log("*** DUMP ***");  if (dmp) {   gds__log("recursion");   return;  }  dmp++;  class ClumpletDump : public ClumpletReader  {  public:   ClumpletDump(Kind k, const UCHAR* buffer, size_t buffLen)    : ClumpletReader(k, buffer, buffLen) { }   static string hexString(const UCHAR* b, size_t len)   {    string t1, t2;    for (; len > 0; --len, ++b) {     if (isprint(*b))      t2 += *b;     else {      t1.printf("<%02x>", *b);      t2 += t1;     }    }    return t2;   }  protected:   virtual void usage_mistake(const char* what) const   {    fatal_exception::raiseFmt(            "Internal error when using clumplet API: %s", what);   }   virtual void invalid_structure(const char* what) const   {    fatal_exception::raiseFmt(      "Invalid clumplet buffer structure: %s", what);   }  };  try {   ClumpletDump d(kind, getBuffer(), getBufferLength());   int t = (kind == SpbStart || kind == UnTagged) ? -1 : d.getBufferTag();   gds__log("Tag=%d Offset=%d Length=%d Eof=%d\n", t, getCurOffset(), getBufferLength(), isEof());   for (d.rewind(); !(d.isEof()); d.moveNext())   {    gds__log("Clump %d at offset %d: %s", d.getClumpTag(), d.getCurOffset(),     ClumpletDump::hexString(d.getBytes(), d.getClumpLength()).c_str());   }  }  catch(const fatal_exception& x) {   gds__log("Fatal exception during clumplet dump: %s", x.what());   size_t l = getBufferLength() - getCurOffset();   const UCHAR *p = getBuffer() + getCurOffset();   gds__log("Plain dump starting with offset %d: %s", getCurOffset(),    ClumpletDump::hexString(p, l).c_str());  }  dmp--; } }