Commit 70aa7424 authored by unknown's avatar unknown

Big code cleanup/review before 4.0.2 release.

(All commit emails since 4.0.1 checked)
This had to be done now, before the 4.1 tree changes to much, to make it easy to propagate bug fixes to the 4.1 tree.


BUILD/SETUP.sh:
  Added -DPEDANTIC_SAFEMALLOC as standard debug option
Docs/manual.texi:
  Changes for new version.
client/mysql.cc:
  Fixed default value for rehash
  cleanup
client/mysqladmin.c:
  Cleanup
client/mysqlbinlog.cc:
  cleanup
client/mysqldump.c:
  Cleanup
client/mysqlmanager-pwgen.c:
  Cleanup
client/mysqlmanagerc.c:
  Cleanup
client/mysqltest.c:
  Cleanup
dbug/dbug.c:
  Cleanup
extra/resolve_stack_dump.c:
  Cleanup & Simple optimizations
include/ft_global.h:
  Cleanup
include/my_alloc.h:
  Cleanup
include/my_global.h:
  Cleanup
include/my_sys.h:
  Cleanup
include/myisam.h:
  Cleanup
libmysql/libmysql.c:
  Cleanup
libmysql/manager.c:
  Cleanup
myisam/ft_boolean_search.c:
  Cleanup
myisam/ft_dump.c:
  Change strcpy -> strmov
myisam/ft_eval.c:
  Cleanup
myisam/ft_nlq_search.c:
  Cleanup
myisam/ft_test1.c:
  strncpy -> strnmov
myisam/ft_update.c:
  Cleanup
myisam/mi_static.c:
  Cleanup
myisam/mi_test2.c:
  Cleanup
myisam/mi_write.c:
  Cleanup
mysys/mf_fn_ext.c:
  Cleanup
mysys/mf_iocache.c:
  Cleanup
mysys/mf_iocache2.c:
  Cleanup
mysys/my_getopt.c:
  Cleanup
mysys/my_read.c:
  Cleanup
mysys/my_thr_init.c:
  Cleanup
mysys/queues.c:
  Cleanup
mysys/safemalloc.c:
  Cleanup
sql/field.cc:
  Indentation cleanups
sql/ha_berkeley.cc:
  Indentation cleanups
sql/ha_myisam.cc:
  Cleanup
sql/item.h:
  Indentation cleanups
sql/item_cmpfunc.cc:
  Indentation cleanups
sql/item_create.cc:
  cleanup
sql/item_func.cc:
  Cleanup
sql/item_func.h:
  Indentation cleanups
sql/item_strfunc.cc:
  Indentation cleanups
sql/item_sum.cc:
  Indentation cleanups
sql/item_timefunc.cc:
  Indentation cleanups
sql/lock.cc:
  Indentation cleanups
sql/log.cc:
  Cleanup
  strnmov -> strmake
sql/log_event.cc:
  Cleanup + optimizations
  Fixed memory leak
  Added missing pthread_mutex_unlock()  (On error condition)
sql/log_event.h:
  Indentation and comment cleanup
  Merged #ifdef's into common blocks for better readability
sql/mini_client.cc:
  Indentation cleanup
sql/mysql_priv.h:
  Cleanup
  Changed int function to bool
sql/mysqld.cc:
  Indentation and comment cleanup
sql/net_pkg.cc:
  Indentation cleanup
sql/net_serv.cc:
  Changed int function -> bool
sql/nt_servc.cc:
  Cleanup
sql/opt_range.cc:
  Indentation cleanup
sql/repl_failsafe.cc:
  Cleanup + simple optimization
  strnmov -> strmake
sql/slave.cc:
  strnmov -> strmake
  Cleanups
sql/slave.h:
  Cleanup
sql/sql_acl.cc:
  Indentation and DBUG_PRINT cleanup
  Changed WITH MAX... to not use =
sql/sql_base.cc:
  Indentation cleanup
sql/sql_cache.cc:
  Indentation cleanup
sql/sql_class.cc:
  Indentation cleanup
sql/sql_class.h:
  Renamed some struct slots
sql/sql_delete.cc:
  Indentation cleanup
sql/sql_handler.cc:
  Indentation cleanup
sql/sql_insert.cc:
  Use new slot names.
sql/sql_lex.cc:
  Indentation cleanup
sql/sql_lex.h:
  Indentation cleanup
sql/sql_load.cc:
  Indentation cleanup
sql/sql_parse.cc:
  Indentation cleanup
  Removed not used check from LOCK TABLES
sql/sql_repl.cc:
  strnmov -> strmake
sql/sql_repl.h:
  Removed test if file is included (We want to know if it's included twice to avoid this)
sql/sql_select.cc:
  Indentation cleanup
sql/sql_show.cc:
  Indentation cleanup
sql/sql_string.cc:
  Indentation cleanup
sql/sql_table.cc:
  Indentation cleanup
sql/sql_union.cc:
  Use renamed struct slot
sql/sql_update.cc:
  Indentation cleanup
sql/sql_yacc.yy:
  Removed = after GRANT ... MAX_  to make the syntax uniform
sql/table.cc:
  Indentation cleanup
sql/table.h:
  Indentation cleanup
sql/time.cc:
  Indentation cleanup
sql/udf_example.cc:
  Indentation cleanup
sql/unireg.cc:
  strnmov -> strmake
tests/grant.pl:
  Added test for LOCK TABLES
tools/mysqlmanager.c:
  Cleanup
  fopen() -> my_fopen()
vio/viosocket.c:
  DBUG_PRINT cleanups
vio/viosslfactories.c:
  Indentation cleanup
  Checking of results from malloc()
  Fixed possible memory leak
BitKeeper/etc/ignore:
  Added scripts/mysql_secure_installation to the ignore list
BitKeeper/etc/logging_ok:
  Logging to logging@openlogging.org accepted
parent 30d5eb22
......@@ -471,3 +471,4 @@ vio/test-sslserver
vio/viotest-ssl
mysys/getopt.c
mysys/getopt1.c
scripts/mysql_secure_installation
......@@ -48,7 +48,7 @@ fast_cflags="-O3 -fno-omit-frame-pointer"
# this is one is for someone who thinks 1% speedup is worth not being
# able to backtrace
reckless_cflags="-O3 -fomit-frame-pointer "
debug_cflags="-DEXTRA_DEBUG -DFORCE_INIT_OF_VARS -DSAFEMALLOC -DSAFE_MUTEX -O1"
debug_cflags="-DEXTRA_DEBUG -DFORCE_INIT_OF_VARS -DSAFEMALLOC -DPEDANTIC_SAFEMALLOC -DSAFE_MUTEX -O1"
base_cxxflags="-felide-constructors -fno-exceptions -fno-rtti"
......
......@@ -65,3 +65,4 @@ worm@altair.is.lan
zak@balfor.local
zak@linux.local
tfr@indrek.tfr.cafe.ee
monty@mashka.mysql.fi
......@@ -8180,7 +8180,7 @@ you need to rebuild them with @code{ALTER TABLE table_name TYPE=MyISAM},
@strong{even} if they are of @code{MyISAM} type.
@item
@code{LOCATE()} and @code{INSTR()} are case-sensitive if one of the
arguments is a binary string.
arguments is a binary string. Otherwise they are case insensitive.
@item
@code{STRCMP()} now uses the current character set when doing comparisons,
which means that the default comparison behavior now is case-insensitive.
......@@ -16425,9 +16425,9 @@ GRANT priv_type [(column_list)] [, priv_type [(column_list)] ...]
[CIPHER cipher [AND]]
[ISSUER issuer [AND]]
[SUBJECT subject]]
[WITH [GRANT OPTION | MAX_QUERIES_PER_HOUR=# |
MAX_UPDATES_PER_HOUR=# |
MAX_CONNECTIONS_PER_HOUR=#]]
[WITH [GRANT OPTION | MAX_QUERIES_PER_HOUR # |
MAX_UPDATES_PER_HOUR # |
MAX_CONNECTIONS_PER_HOUR #]]
REVOKE priv_type [(column_list)] [, priv_type [(column_list)] ...]
ON @{tbl_name | * | *.* | db_name.*@}
......@@ -16590,8 +16590,8 @@ to other users any privileges the user has at the specified privilege level.
You should be careful to whom you give the @strong{grant} privilege, as two
users with different privileges may be able to join privileges!
@code{MAX_QUERIES_PER_HOUR=#}, @code{MAX_UPDATES_PER_HOUR=#} and
@code{MAX_CONNECTIONS_PER_HOUR=#} limit the number of
@code{MAX_QUERIES_PER_HOUR #}, @code{MAX_UPDATES_PER_HOUR #} and
@code{MAX_CONNECTIONS_PER_HOUR #} limit the number of
queries/updates and logins the user can do during one hour.
If @code{#} is 0 (default), then this means that there is no limitations
for the user. @xref{User resources}.
......@@ -17109,9 +17109,9 @@ unless the limits are granted to them. These limits can be granted
@strong{only} via global @code{GRANT (*.*)}, using this syntax:
@example
GRANT ... WITH MAX_QUERIES_PER_HOUR = N1
MAX_UPDATES_PER_HOUR = N2
MAX_CONNECTIONS_PER_HOUR = N3;
GRANT ... WITH MAX_QUERIES_PER_HOUR N1
MAX_UPDATES_PER_HOUR N2
MAX_CONNECTIONS_PER_HOUR N3;
@end example
One can specify any combination of the above resources.
......@@ -30959,7 +30959,7 @@ mysql> SELECT LOCATE('xbar', 'foobar');
@end example
This function is multi-byte safe. In MySQL 3.23 this function is case
insensitive, while in 4.0 it's only case-insensitive if either argument is
sensitive, while in 4.0 it's only case sensitive if either argument is
a binary string.
@findex LOCATE()
......@@ -30974,7 +30974,7 @@ mysql> SELECT LOCATE('bar', 'foobarbar',5);
@end example
This function is multi-byte safe. In MySQL 3.23 this function is case
insensitive, while in 4.0 it's only case-insensitive if either argument is
sensitive, while in 4.0 it's only case sensitive if either argument is
a binary string.
@findex INSTR()
......@@ -30991,7 +30991,7 @@ mysql> SELECT INSTR('xbar', 'foobar');
@end example
This function is multi-byte safe. In MySQL 3.23 this function is case
insensitive, while in 4.0 it's only case-insensitive if either argument is
sensitive, while in 4.0 it's only case sensitive if either argument is
a binary string.
@findex LPAD()
......@@ -49547,9 +49547,9 @@ Added @code{--no-beep} and @code{--prompt} options to @code{mysql} command-line
@item
New feature: management of user resources.
@example
GRANT ... WITH MAX_QUERIES_PER_HOUR = N1
MAX_UPDATES_PER_HOUR = N2
MAX_CONNECTIONS_PER_HOUR = N3;
GRANT ... WITH MAX_QUERIES_PER_HOUR N1
MAX_UPDATES_PER_HOUR N2
MAX_CONNECTIONS_PER_HOUR N3;
@end example
@xref{User resources}.
This diff is collapsed.
......@@ -24,7 +24,7 @@
#endif
#define ADMIN_VERSION "8.35"
#define MAX_MYSQL_VAR 64
#define MAX_MYSQL_VAR 128
#define SHUTDOWN_DEF_TIMEOUT 3600 /* Wait for shutdown */
#define MAX_TRUNC_LENGTH 3
......@@ -40,9 +40,12 @@ static uint tcp_port = 0, option_wait = 0, option_silent=0;
static ulong opt_connect_timeout, opt_shutdown_timeout;
static my_string unix_port=0;
/* When using extended-status relatively, ex_val_max_len is the estimated
maximum length for any relative value printed by extended-status. The
idea is to try to keep the length of output as short as possible. */
/*
When using extended-status relatively, ex_val_max_len is the estimated
maximum length for any relative value printed by extended-status. The
idea is to try to keep the length of output as short as possible.
*/
static uint ex_val_max_len[MAX_MYSQL_VAR];
static my_bool ex_status_printed = 0; /* First output is not relative. */
static uint ex_var_count, max_var_length, max_val_length;
......@@ -235,17 +238,12 @@ int main(int argc,char *argv[])
{
int error, ho_error;
MYSQL mysql;
char **commands;
char** save_argv;
char **commands, **save_argv;
MY_INIT(argv[0]);
mysql_init(&mysql);
load_defaults("my",load_default_groups,&argc,&argv);
save_argv = argv;
/* Sasha: with the change to handle_options() we now need to do this fix
with save_argv in all client utilities. The problem is that
handle_options may modify argv, and that wreaks havoc with
free_defaults()
*/
save_argv = argv; /* Save for free_defaults */
if ((ho_error=handle_options(&argc, &argv, my_long_options, get_one_option)))
exit(ho_error);
......@@ -444,8 +442,10 @@ static int execute_commands(MYSQL *mysql,int argc, char **argv)
{
char pidfile[FN_REFLEN];
my_bool got_pidfile=0;
/* Only wait for pidfile on local connections */
/* If pidfile doesn't exist, continue without pid file checking */
/*
Only wait for pidfile on local connections
If pidfile doesn't exist, continue without pid file checking
*/
if (mysql->unix_socket)
got_pidfile= !get_pidfile(mysql, pidfile);
if (mysql_shutdown(mysql))
......
......@@ -20,7 +20,9 @@
#include <time.h>
#include "log_event.h"
#define PROBE_HEADER_LEN (4+EVENT_LEN_OFFSET+4)
#define BIN_LOG_HEADER_SIZE 4
#define PROBE_HEADER_LEN (BIN_LOG_HEADER_SIZE+EVENT_LEN_OFFSET+4)
#define CLIENT_CAPABILITIES (CLIENT_LONG_PASSWORD | CLIENT_LONG_FLAG | CLIENT_LOCAL_FILES)
......@@ -178,8 +180,7 @@ static my_bool
get_one_option(int optid, const struct my_option *opt __attribute__((unused)),
char *argument)
{
switch(optid)
{
switch(optid) {
#ifndef DBUG_OFF
case '#':
DBUG_PUSH(argument ? argument : default_dbug_option);
......@@ -234,7 +235,7 @@ static MYSQL* safe_connect()
if(!local_mysql)
die("Failed on mysql_init");
if(!mysql_real_connect(local_mysql, host, user, pass, 0, port, 0, 0))
if (!mysql_real_connect(local_mysql, host, user, pass, 0, port, 0, 0))
die("failed on connect: %s", mysql_error(local_mysql));
return local_mysql;
......@@ -242,7 +243,7 @@ static MYSQL* safe_connect()
static void dump_log_entries(const char* logname)
{
if(use_remote)
if (use_remote)
dump_remote_log_entries(logname);
else
dump_local_log_entries(logname);
......@@ -254,7 +255,7 @@ static void dump_remote_table(NET* net, const char* db, const char* table)
char * p = buf;
uint table_len = (uint) strlen(table);
uint db_len = (uint) strlen(db);
if(table_len + db_len > sizeof(buf) - 2)
if (table_len + db_len > sizeof(buf) - 2)
die("Buffer overrun");
*p++ = db_len;
......@@ -263,14 +264,14 @@ static void dump_remote_table(NET* net, const char* db, const char* table)
*p++ = table_len;
memcpy(p, table, table_len);
if(simple_command(mysql, COM_TABLE_DUMP, buf, p - buf + table_len, 1))
if (simple_command(mysql, COM_TABLE_DUMP, buf, p - buf + table_len, 1))
die("Error sending the table dump command");
for(;;)
for (;;)
{
uint packet_len = my_net_read(net);
if(packet_len == 0) break; // end of file
if(packet_len == packet_error)
if (packet_len == 0) break; // end of file
if (packet_len == packet_error)
die("Error reading packet in table dump");
my_fwrite(result_file, (byte*)net->read_pos, packet_len, MYF(MY_WME));
fflush(result_file);
......@@ -284,8 +285,8 @@ static int check_master_version(MYSQL* mysql)
const char* version;
int old_format = 0;
if (mysql_query(mysql, "SELECT VERSION()")
|| !(res = mysql_store_result(mysql)))
if (mysql_query(mysql, "SELECT VERSION()") ||
!(res = mysql_store_result(mysql)))
{
mysql_close(mysql);
die("Error checking master version: %s",
......@@ -305,12 +306,12 @@ static int check_master_version(MYSQL* mysql)
die("Master reported NULL for the version");
}
switch (*version)
{
switch (*version) {
case '3':
old_format = 1;
break;
case '4':
case '5':
old_format = 0;
break;
default:
......@@ -324,6 +325,7 @@ static int check_master_version(MYSQL* mysql)
return old_format;
}
static void dump_remote_log_entries(const char* logname)
{
char buf[128];
......@@ -333,38 +335,38 @@ static void dump_remote_log_entries(const char* logname)
int old_format;
old_format = check_master_version(mysql);
if(!position) position = 4; // protect the innocent from spam
if (position < 4)
if (!position)
position = BIN_LOG_HEADER_SIZE; // protect the innocent from spam
if (position < BIN_LOG_HEADER_SIZE)
{
position = 4;
position = BIN_LOG_HEADER_SIZE;
// warn the guity
sql_print_error("Warning: The position in the binary log can't be less than 4.\nStarting from position 4\n");
sql_print_error("Warning: The position in the binary log can't be less than %d.\nStarting from position %d\n", BIN_LOG_HEADER_SIZE, BIN_LOG_HEADER_SIZE);
}
int4store(buf, position);
int2store(buf + 4, binlog_flags);
int2store(buf + BIN_LOG_HEADER_SIZE, binlog_flags);
len = (uint) strlen(logname);
int4store(buf + 6, 0);
memcpy(buf + 10, logname,len);
if (simple_command(mysql, COM_BINLOG_DUMP, buf, len + 10, 1))
die("Error sending the log dump command");
for(;;)
for (;;)
{
const char *error;
len = net_safe_read(mysql);
if (len == packet_error)
die("Error reading packet from server: %s", mysql_error(mysql));
if(len == 1 && net->read_pos[0] == 254)
if (len == 1 && net->read_pos[0] == 254)
break; // end of data
DBUG_PRINT("info",( "len= %u, net->read_pos[5] = %d\n",
len, net->read_pos[5]));
Log_event * ev = Log_event::read_log_event(
(const char*) net->read_pos + 1 ,
len - 1, &error, old_format);
Log_event *ev = Log_event::read_log_event((const char*) net->read_pos + 1 ,
len - 1, &error, old_format);
if (ev)
{
ev->print(result_file, short_form, last_db);
if(ev->get_type_code() == LOAD_EVENT)
if (ev->get_type_code() == LOAD_EVENT)
dump_remote_file(net, ((Load_log_event*)ev)->fname);
delete ev;
}
......@@ -373,10 +375,11 @@ static void dump_remote_log_entries(const char* logname)
}
}
static int check_header(IO_CACHE* file)
{
byte buf[PROBE_HEADER_LEN];
int old_format;
int old_format=0;
my_off_t pos = my_b_tell(file);
my_b_seek(file, (my_off_t)0);
......@@ -388,8 +391,6 @@ static int check_header(IO_CACHE* file)
event_len = uint4korr(buf + EVENT_LEN_OFFSET + 4);
old_format = (event_len < LOG_EVENT_HEADER_LEN + START_HEADER_LEN);
}
else
old_format = 0;
my_b_seek(file, pos);
return old_format;
}
......@@ -425,7 +426,7 @@ static void dump_local_log_entries(const char* logname)
for (length= (my_off_t) position ; length > 0 ; length-=tmp)
{
tmp=min(length,sizeof(buff));
if (my_b_read(file,buff, (uint) tmp))
if (my_b_read(file, buff, (uint) tmp))
exit(1);
}
}
......@@ -435,10 +436,10 @@ static void dump_local_log_entries(const char* logname)
if (!position)
{
char magic[4];
char magic[BIN_LOG_HEADER_SIZE];
if (my_b_read(file, (byte*) magic, sizeof(magic)))
die("I/O error reading binlog magic number");
if(memcmp(magic, BINLOG_MAGIC, 4))
if (memcmp(magic, BINLOG_MAGIC, 4))
die("Bad magic number; The file is probably not a MySQL binary log");
}
......@@ -498,7 +499,7 @@ Could not read entry at offset %s : Error in log format or read error",
rec_count++;
delete ev;
}
if(fd >= 0)
if (fd >= 0)
my_close(fd, MYF(MY_WME));
end_io_cache(file);
}
......@@ -509,34 +510,30 @@ int main(int argc, char** argv)
MY_INIT(argv[0]);
parse_args(&argc, (char***)&argv);
if(!argc && !table)
if (!argc && !table)
{
usage();
return -1;
}
if(use_remote)
{
if (use_remote)
mysql = safe_connect();
}
if (table)
{
if(!use_remote)
if (!use_remote)
die("You must specify connection parameter to get table dump");
char* db = (char*)table;
char* db = (char*) table;
char* tbl = (char*) strchr(table, '.');
if(!tbl)
if (!tbl)
die("You must use database.table syntax to specify the table");
*tbl++ = 0;
dump_remote_table(&mysql->net, db, tbl);
}
else
{
while(--argc >= 0)
{
while (--argc >= 0)
dump_log_entries(*(argv++));
}
}
if (result_file != stdout)
my_fclose(result_file, MYF(0));
......
......@@ -1348,9 +1348,6 @@ int main(int argc, char **argv)
MYSQL_RES *master;
MY_INIT(argv[0]);
/*
** Check out the args
*/
if (get_options(&argc, &argv))
{
my_end(0);
......@@ -1374,12 +1371,16 @@ int main(int argc, char **argv)
}
if (opt_alldbs)
dump_all_databases();
/* Only one database and selected table(s) */
else if (argc > 1 && !opt_databases)
{
/* Only one database and selected table(s) */
dump_selected_tables(*argv, (argv + 1), (argc - 1));
/* One or more databases, all tables */
}
else
{
/* One or more databases, all tables */
dump_databases(argv);
}
if (opt_first_slave)
{
......@@ -1387,14 +1388,13 @@ int main(int argc, char **argv)
{
if (mysql_query(sock, "SHOW MASTER STATUS") ||
!(master = mysql_store_result(sock)))
{
my_printf_error(0, "Error: Couldn't execute 'SHOW MASTER STATUS': %s",
MYF(0), mysql_error(sock));
}
else
{
row = mysql_fetch_row(master);
if(row[0] && row[1]) {
if (row[0] && row[1])
{
fprintf(md_result_file,
"\n--\n-- Position to start replication from\n--\n\n");
fprintf(md_result_file,
......@@ -1406,15 +1406,11 @@ int main(int argc, char **argv)
}
}
if (mysql_query(sock, "FLUSH MASTER"))
{
my_printf_error(0, "Error: Couldn't execute 'FLUSH MASTER': %s",
MYF(0), mysql_error(sock));
}
if (mysql_query(sock, "UNLOCK TABLES"))
{
my_printf_error(0, "Error: Couldn't execute 'UNLOCK TABLES': %s",
MYF(0), mysql_error(sock));
}
}
dbDisconnect(current_host);
fputs("\n", md_result_file);
......
......@@ -105,8 +105,10 @@ void get_pass(char* pw, int len)
{
FILE* fp;
char* pw_end=pw+len;
/* /dev/random is more secure than rand() because the seed is easy to
predict, so we resort to rand() only if /dev/random is not available */
/*
/dev/random is more secure than rand() because the seed is easy to
predict, so we resort to rand() only if /dev/random is not available
*/
if ((fp=fopen("/dev/random","r")))
{
fread(pw,len,1,fp);
......@@ -129,6 +131,7 @@ void get_pass(char* pw, int len)
*pw_end=0;
}
int main(int argc, char** argv)
{
FILE* fp;
......
......@@ -138,6 +138,8 @@ int parse_args(int argc, char **argv)
return 0;
}
int main(int argc, char** argv)
{
MY_INIT(argv[0]);
......@@ -147,7 +149,7 @@ int main(int argc, char** argv)
if (!(manager=mysql_manager_init(0)))
die("Failed in mysql_manager_init()");
if (!mysql_manager_connect(manager,host,user,pass,port))
die("Could not connect to MySQL manager: %s(%d)",manager->last_error,
die("Could not connect to MySQL manager: %s (%d)",manager->last_error,
manager->last_errno);
for (;!feof(fp);)
{
......@@ -157,11 +159,11 @@ int main(int argc, char** argv)
if (!quiet)
fprintf(fp_out,"<<%s",buf);
if (mysql_manager_command(manager,buf,strlen(buf)))
die("Error in command: %s(%d)",manager->last_error,manager->last_errno);
die("Error in command: %s (%d)",manager->last_error,manager->last_errno);
while (!manager->eof)
{
if (mysql_manager_fetch_line(manager,buf,sizeof(buf)))
die("Error fetching result line: %s(%d)", manager->last_error,
die("Error fetching result line: %s (%d)", manager->last_error,
manager->last_errno);
if (!quiet)
fprintf(fp_out,">>%s\n",buf);
......
......@@ -1425,7 +1425,7 @@ int do_connect(struct st_query* q)
con_port = var_port->int_val;
}
else
con_port=atoi(con_port_str);
con_port=atoi(con_port_str);
p = safe_get_param(p, &con_sock, "missing connection socket");
if (*con_sock == '$')
{
......@@ -1469,6 +1469,7 @@ int do_connect(struct st_query* q)
DBUG_RETURN(0);
}
int do_done(struct st_query* q)
{
q->type = Q_END_BLOCK;
......@@ -1480,8 +1481,8 @@ int do_done(struct st_query* q)
}
else
{
++parser.current_line;
--cur_block;
++parser.current_line;
--cur_block;
}
return 0;
}
......@@ -1492,14 +1493,14 @@ int do_while(struct st_query* q)
const char* expr_start, *expr_end;
VAR v;
if (cur_block == block_stack_end)
die("Nesting too deeply");
die("Nesting too deeply");
if (!*block_ok)
{
++false_block_depth;
*++block_ok = 0;
*cur_block++ = parser.current_line++;
return 0;
}
{
++false_block_depth;
*++block_ok = 0;
*cur_block++ = parser.current_line++;
return 0;
}
expr_start = strchr(p, '(');
if (!expr_start)
......@@ -1511,10 +1512,10 @@ int do_while(struct st_query* q)
eval_expr(&v, ++expr_start, &expr_end);
*cur_block++ = parser.current_line++;
if (!v.int_val)
{
*++block_ok = 0;
false_block_depth++;
}
{
*++block_ok = 0;
false_block_depth++;
}
else
*++block_ok = 1;
var_free(&v);
......@@ -1530,45 +1531,42 @@ int safe_copy_unescape(char* dest, char* src, int size)
size--; /* just to make life easier */
for(; p_dest - size < dest && p_src - size < src
&& (c = *p_src) != '\n' && c; ++p_src )
{
switch(state)
{
case ST_NORMAL:
if (c == '\\')
{
state = ST_ESCAPED;
}
else
*p_dest++ = c;
break;
case ST_ESCAPED:
if ((val = hex_val(c)) > 0)
{
*p_dest = val;
state = ST_HEX2;
}
else
{
state = ST_NORMAL;
*p_dest++ = c;
}
break;
case ST_HEX2:
if ((val = hex_val(c)) > 0)
{
*p_dest = (*p_dest << 4) + val;
p_dest++;
}
else
*p_dest++ = c;
for (; p_dest - size < dest && p_src - size < src &&
(c = *p_src) != '\n' && c; ++p_src)
{
switch(state) {
case ST_NORMAL:
if (c == '\\')
state = ST_ESCAPED;
else
*p_dest++ = c;
break;
case ST_ESCAPED:
if ((val = hex_val(c)) > 0)
{
*p_dest = val;
state = ST_HEX2;
}
else
{
state = ST_NORMAL;
*p_dest++ = c;
}
break;
case ST_HEX2:
if ((val = hex_val(c)) > 0)
{
*p_dest = (*p_dest << 4) + val;
p_dest++;
}
else
*p_dest++ = c;
state = ST_NORMAL;
break;
state = ST_NORMAL;
break;
}
}
}
*p_dest = 0;
return (p_dest - dest);
......
......@@ -706,10 +706,11 @@ char ***_sframep_ __attribute__((unused)))
if (!_no_db_)
{
int save_errno=errno;
/* Sasha: the test below is so we could call functions with DBUG_ENTER
before my_thread_init(). I needed this because I suspected corruption
of a block allocated by my_thread_init() itself, so I wanted to use
my_malloc()/my_free() in my_thread_init()/my_thread_end()
/*
Sasha: the test below is so we could call functions with DBUG_ENTER
before my_thread_init(). I needed this because I suspected corruption
of a block allocated by my_thread_init() itself, so I wanted to use
my_malloc()/my_free() in my_thread_init()/my_thread_end()
*/
if (!(state=code_state()))
return;
......
......@@ -77,7 +77,8 @@ static void usage()
printf("MySQL AB, by Sasha Pachev\n");
printf("This software comes with ABSOLUTELY NO WARRANTY\n\n");
printf("Resolve numeric stack strace dump into symbols.\n\n");
printf("Usage: %s [OPTIONS] symbols-file [numeric-dump-file]\n", my_progname);
printf("Usage: %s [OPTIONS] symbols-file [numeric-dump-file]\n",
my_progname);
my_print_help(my_long_options);
my_print_variables(my_long_options);
printf("\n\
......@@ -159,14 +160,14 @@ static void open_files()
fp_out = stdout;
fp_dump = stdin;
if(dump_fname && !(fp_dump = my_fopen(dump_fname, O_RDONLY, MYF(MY_WME))))
if (dump_fname && !(fp_dump = my_fopen(dump_fname, O_RDONLY, MYF(MY_WME))))
die("Could not open %s", dump_fname);
/* if name not given, assume stdin*/
if(!sym_fname)
if (!sym_fname)
die("Please run nm --numeric-sort on mysqld binary that produced stack \
trace dump and specify the path to it with -s or --symbols-file");
if(!(fp_sym = my_fopen(sym_fname, O_RDONLY, MYF(MY_WME))))
if (!(fp_sym = my_fopen(sym_fname, O_RDONLY, MYF(MY_WME))))
die("Could not open %s", sym_fname);
}
......@@ -174,10 +175,10 @@ trace dump and specify the path to it with -s or --symbols-file");
static uchar hex_val(char c)
{
uchar l;
if(isdigit(c))
if (isdigit(c))
return c - '0';
l = tolower(c);
if(l < 'a' || l > 'f')
if (l < 'a' || l > 'f')
return HEX_INVALID;
return (uchar)10 + ((uchar)c - (uchar)'a');
}
......@@ -200,25 +201,18 @@ static int init_sym_entry(SYM_ENTRY* se, char* buf)
char* p, *p_end;
se->addr = (uchar*)read_addr(&buf);
if(!se->addr)
if (!se->addr)
return -1;
while(isspace(*buf++))
/* empty */;
while (isspace(*buf++)) ;
while(isspace(*buf++))
/* empty - skip more space */;
while (isspace(*buf++)) ; /* skip more space */
--buf;
/* now we are on the symbol */
for(p = se->symbol, p_end = se->symbol + sizeof(se->symbol) - 1;
*buf != '\n' && *buf; ++buf,++p )
{
if(p < p_end)
*p = *buf;
else
break;
}
for (p = se->symbol, p_end = se->symbol + sizeof(se->symbol) - 1;
*buf != '\n' && *buf && p < p_end; ++buf,++p)
*p = *buf;
*p = 0;
if(!strcmp(se->symbol, "gcc2_compiled."))
if (!strcmp(se->symbol, "gcc2_compiled."))
return -1;
return 0;
}
......@@ -226,18 +220,18 @@ static int init_sym_entry(SYM_ENTRY* se, char* buf)
static void init_sym_table()
{
char buf[512];
if(my_init_dynamic_array(&sym_table, sizeof(SYM_ENTRY), INIT_SYM_TABLE,
INC_SYM_TABLE))
if (my_init_dynamic_array(&sym_table, sizeof(SYM_ENTRY), INIT_SYM_TABLE,
INC_SYM_TABLE))
die("Failed in my_init_dynamic_array() -- looks like out of memory problem");
while(fgets(buf, sizeof(buf), fp_sym))
{
SYM_ENTRY se;
if(init_sym_entry(&se, buf))
continue;
if(insert_dynamic(&sym_table, (gptr)&se))
die("insert_dynamic() failed - looks like we are out of memory");
}
while (fgets(buf, sizeof(buf), fp_sym))
{
SYM_ENTRY se;
if (init_sym_entry(&se, buf))
continue;
if (insert_dynamic(&sym_table, (gptr)&se))
die("insert_dynamic() failed - looks like we are out of memory");
}
verify_sort();
}
......@@ -252,66 +246,68 @@ static void verify_sort()
uint i;
uchar* last = 0;
for(i = 0; i < sym_table.elements; i++)
{
SYM_ENTRY se;
get_dynamic(&sym_table, (gptr)&se, i);
if(se.addr < last)
die("sym table does not appear to be sorted, did you forget \
for (i = 0; i < sym_table.elements; i++)
{
SYM_ENTRY se;
get_dynamic(&sym_table, (gptr)&se, i);
if (se.addr < last)
die("sym table does not appear to be sorted, did you forget \
--numeric-sort arg to nm? trouble addr = %p, last = %p", se.addr, last);
last = se.addr;
}
last = se.addr;
}
}
static SYM_ENTRY* resolve_addr(uchar* addr, SYM_ENTRY* se)
{
uint i;
get_dynamic(&sym_table, (gptr)se, 0);
if(addr < se->addr)
if (addr < se->addr)
return 0;
for(i = 1; i < sym_table.elements; i++)
for (i = 1; i < sym_table.elements; i++)
{
get_dynamic(&sym_table, (gptr)se, i);
if (addr < se->addr)
{
get_dynamic(&sym_table, (gptr)se, i);
if(addr < se->addr)
{
get_dynamic(&sym_table, (gptr)se, i - 1);
return se;
}
get_dynamic(&sym_table, (gptr)se, i - 1);
return se;
}
}
return se;
}
static void do_resolve()
{
char buf[1024], *p;
while(fgets(buf, sizeof(buf), fp_dump))
while (fgets(buf, sizeof(buf), fp_dump))
{
p = buf;
while(isspace(*p))
++p;
if (*p++ == '0' && *p++ == 'x')
{
p = buf;
while(isspace(*p))
++p;
/* skip space */;
if(*p++ == '0' && *p++ == 'x')
{
SYM_ENTRY se ;
uchar* addr = (uchar*)read_addr(&p);
if(resolve_addr(addr, &se))
fprintf(fp_out, "%p %s + %d\n", addr, se.symbol,
(int) (addr - se.addr));
else
fprintf(fp_out, "%p (?)\n", addr);
}
SYM_ENTRY se ;
uchar* addr = (uchar*)read_addr(&p);
if (resolve_addr(addr, &se))
fprintf(fp_out, "%p %s + %d\n", addr, se.symbol,
(int) (addr - se.addr));
else
{
fputs(buf, fp_out);
continue;
}
fprintf(fp_out, "%p (?)\n", addr);
}
else
{
fputs(buf, fp_out);
continue;
}
}
}
int main(int argc, char** argv)
{
MY_INIT(argv[0]);
......
......@@ -30,7 +30,8 @@ extern "C" {
#define HA_FT_MAXLEN 254
typedef struct st_ft_info FT_INFO;
struct _ft_vft {
struct _ft_vft
{
int (*read_next)(FT_INFO *, char *);
float (*find_relevance)(FT_INFO *, byte *, uint);
void (*close_search)(FT_INFO *);
......@@ -39,7 +40,8 @@ struct _ft_vft {
};
#ifndef FT_CORE
struct st_ft_info {
struct st_ft_info
{
struct _ft_vft *please; /* INTERCAL style :-) */
};
#endif
......
......@@ -18,18 +18,23 @@
Data structures for mysys/my_alloc.c (root memory allocator)
*/
#ifndef ST_USED_MEM_DEFINED
#define ST_USED_MEM_DEFINED
typedef struct st_used_mem { /* struct for once_alloc (block) */
#ifndef _my_alloc_h
#define _my_alloc_h
typedef struct st_used_mem
{ /* struct for once_alloc (block) */
struct st_used_mem *next; /* Next block in use */
unsigned int left; /* memory left in block */
unsigned int size; /* size of block */
} USED_MEM;
typedef struct st_mem_root {
typedef struct st_mem_root
{
USED_MEM *free; /* blocks with free memory in it */
USED_MEM *used; /* blocks almost without free memory */
USED_MEM *pre_alloc; /* preallocated block */
/* if block have less memory it will be put in 'used' list*/
/* if block have less memory it will be put in 'used' list */
unsigned int min_malloc;
unsigned int block_size; /* initial block size */
unsigned int block_num; /* allocated blocks counter */
......
......@@ -14,8 +14,7 @@
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
/* This is the main include file that should included 'first' in every
C file. */
/* This is the include file that should be included 'first' in every C file. */
#ifndef _global_h
#define _global_h
......@@ -51,16 +50,6 @@
#endif
#endif /* _WIN32... */
/* sometimes we want to make sure that the variable is not put into
a register in debugging mode so we can see its value in the core
*/
#ifndef DBUG_OFF
#define dbug_volatile volatile
#else
#define dbug_volatile
#endif
/*
The macros below are borrowed from include/linux/compiler.h in the
Linux kernel. Use them to indicate the likelyhood of the truthfulness
......@@ -106,7 +95,7 @@
#ifndef _POSIX_PTHREAD_SEMANTICS
#define _POSIX_PTHREAD_SEMANTICS /* We want posix threads */
#endif
/* was #if defined(HAVE_LINUXTHREADS) || defined(HAVE_DEC_THREADS) || defined(HPUX) */
#if !defined(SCO)
#define _REENTRANT 1 /* Some thread libraries require this */
#endif
......@@ -275,10 +264,6 @@
#define DONT_USE_MYSQL_PWD 1
#endif
/* #define USE_some_charset 1 was deprecated by changes to configure */
/* my_ctype my_to_upper, my_to_lower, my_sort_order gain theit right value */
/* automagically during configuration */
/* Does the system remember a signal handler after a signal ? */
#ifndef HAVE_BSD_SIGNALS
#define DONT_REMEMBER_SIGNAL
......@@ -348,9 +333,11 @@ typedef unsigned short ushort;
/* From old s-system.h */
/* Support macros for non ansi & other old compilers. Since such
things are no longer supported we do nothing. We keep then since
some of our code may still be needed to upgrade old customers. */
/*
Support macros for non ansi & other old compilers. Since such
things are no longer supported we do nothing. We keep then since
some of our code may still be needed to upgrade old customers.
*/
#define _VARARGS(X) X
#define _STATIC_VARARGS(X) X
#define _PC(X) X
......@@ -468,12 +455,16 @@ typedef SOCKET_SIZE_TYPE size_socket;
/* #define FN_NO_CASE_SENCE */
/* #define FN_UPPER_CASE TRUE */
/* Io buffer size; Must be a power of 2 and a multiple of 512. May be
smaller what the disk page size. This influences the speed of the
isam btree library. eg to big to slow. */
/*
Io buffer size; Must be a power of 2 and a multiple of 512. May be
smaller what the disk page size. This influences the speed of the
isam btree library. eg to big to slow.
*/
#define IO_SIZE 4096
/* How much overhead does malloc have. The code often allocates
something like 1024-MALLOC_OVERHEAD bytes */
/*
How much overhead does malloc have. The code often allocates
something like 1024-MALLOC_OVERHEAD bytes
*/
#ifdef SAFEMALLOC
#define MALLOC_OVERHEAD (8+24+4)
#else
......@@ -488,7 +479,6 @@ typedef SOCKET_SIZE_TYPE size_socket;
/* Some things that this system doesn't have */
#define ONLY_OWN_DATABASES /* We are using only databases by monty */
#define NO_HASH /* Not needed anymore */
#ifdef __WIN__
#define NO_DIR_LIBRARY /* Not standar dir-library */
......@@ -534,11 +524,6 @@ extern double my_atof(const char*);
#define strtok_r(A,B,C) strtok((A),(B))
#endif
#ifdef HAVE_LINUXTHREADS
/* #define pthread_sigmask(A,B,C) sigprocmask((A),(B),(C)) */
/* #define sigset(A,B) signal((A),(B)) */
#endif
/* Remove some things that mit_thread break or doesn't support */
#if defined(HAVE_mit_thread) && defined(THREAD)
#undef HAVE_PREAD
......@@ -589,8 +574,10 @@ extern double my_atof(const char*);
#define FLT_MAX ((float)3.40282346638528860e+38)
#endif
/* Max size that must be added to a so that we know Size to make
adressable obj. */
/*
Max size that must be added to a so that we know Size to make
adressable obj.
*/
typedef long my_ptrdiff_t;
#define MY_ALIGN(A,L) (((A) + (L) - 1) & ~((L) - 1))
#define ALIGN_SIZE(A) MY_ALIGN((A),sizeof(double))
......@@ -648,21 +635,23 @@ error "Neither int or long is of 4 bytes width"
#endif
#if !defined(HAVE_ULONG) && !defined(HAVE_LINUXTHREADS) && !defined(__USE_MISC)
typedef unsigned long ulong; /* Short for unsigned long */
typedef unsigned long ulong; /* Short for unsigned long */
#endif
#ifndef longlong_defined
#if defined(HAVE_LONG_LONG) && SIZEOF_LONG != 8
typedef unsigned long long int ulonglong; /* ulong or unsigned long long */
typedef long long int longlong;
#else
typedef unsigned long ulonglong; /* ulong or unsigned long long */
typedef unsigned long ulonglong; /* ulong or unsigned long long */
typedef long longlong;
#endif
#endif
#ifdef USE_RAID
/* The following is done with a if to not get problems with pre-processors
with late define evaluation */
/*
The following is done with a if to not get problems with pre-processors
with late define evaluation
*/
#if SIZEOF_OFF_T == 4
#define SYSTEM_SIZEOF_OFF_T 4
#else
......@@ -727,8 +716,10 @@ typedef char bool; /* Ordinary boolean values 0 1 */
#define INT32(v) (int32) (v)
#define MYF(v) (myf) (v)
/* Defines to make it possible to prioritize register assignments. No
longer needed with moder compilers */
/*
Defines to make it possible to prioritize register assignments. No
longer that important with modern compilers.
*/
#ifndef USING_X
#define reg1 register
#define reg2 register
......@@ -748,6 +739,17 @@ typedef char bool; /* Ordinary boolean values 0 1 */
#define reg16 register
#endif
/*
Sometimes we want to make sure that the variable is not put into
a register in debugging mode so we can see its value in the core
*/
#ifndef DBUG_OFF
#define dbug_volatile volatile
#else
#define dbug_volatile
#endif
/* Defines for time function */
#define SCALE_SEC 100
#define SCALE_USEC 10000
......@@ -769,8 +771,8 @@ typedef char bool; /* Ordinary boolean values 0 1 */
#endif
/*
** Define-funktions for reading and storing in machine independent format
** (low byte first)
Define-funktions for reading and storing in machine independent format
(low byte first)
*/
/* Optimized store functions for Intel x86 */
......@@ -943,9 +945,11 @@ typedef union {
#endif /* sint2korr */
/* Define-funktions for reading and storing in machine format from/to
short/long to/from some place in memory V should be a (not
register) variable, M is a pointer to byte */
/*
Define-funktions for reading and storing in machine format from/to
short/long to/from some place in memory V should be a (not
register) variable, M is a pointer to byte
*/
#ifdef WORDS_BIGENDIAN
......
......@@ -245,16 +245,20 @@ typedef struct wild_file_pack /* Struct to hold info when selecting files */
typedef struct st_typelib { /* Different types saved here */
uint count; /* How many types */
const char *name; /* Name of typelib */
const char *name; /* Name of typelib */
const char **type_names;
} TYPELIB;
enum cache_type {READ_CACHE,WRITE_CACHE,
SEQ_READ_APPEND /* sequential read or append */,
READ_FIFO,
READ_NET,WRITE_NET};
enum flush_type { FLUSH_KEEP, FLUSH_RELEASE, FLUSH_IGNORE_CHANGED,
FLUSH_FORCE_WRITE};
enum cache_type
{
READ_CACHE,WRITE_CACHE,
SEQ_READ_APPEND /* sequential read or append */,
READ_FIFO, READ_NET,WRITE_NET};
enum flush_type
{
FLUSH_KEEP, FLUSH_RELEASE, FLUSH_IGNORE_CHANGED, FLUSH_FORCE_WRITE
};
typedef struct st_record_cache /* Used when cacheing records */
{
......@@ -270,9 +274,11 @@ typedef struct st_record_cache /* Used when cacheing records */
enum cache_type type;
} RECORD_CACHE;
enum file_type { UNOPEN = 0, FILE_BY_OPEN, FILE_BY_CREATE,
STREAM_BY_FOPEN, STREAM_BY_FDOPEN, FILE_BY_MKSTEMP,
FILE_BY_DUP };
enum file_type
{
UNOPEN = 0, FILE_BY_OPEN, FILE_BY_CREATE, STREAM_BY_FOPEN, STREAM_BY_FDOPEN,
FILE_BY_MKSTEMP, FILE_BY_DUP
};
extern struct my_file_info
{
......@@ -284,14 +290,16 @@ extern struct my_file_info
} my_file_info[MY_NFILE];
typedef struct st_dynamic_array {
typedef struct st_dynamic_array
{
char *buffer;
uint elements,max_element;
uint alloc_increment;
uint size_of_element;
} DYNAMIC_ARRAY;
typedef struct st_dynamic_string {
typedef struct st_dynamic_string
{
char *str;
uint length,max_length,alloc_increment;
} DYNAMIC_STRING;
......@@ -453,8 +461,8 @@ my_off_t my_b_append_tell(IO_CACHE* info);
#define my_b_bytes_in_cache(info) (uint) (*(info)->current_end - \
*(info)->current_pos)
typedef struct st_changeable_var {
typedef struct st_changeable_var
{
const char *name; /* Name of variable */
long *varptr; /* Pointer to variable */
long def_value, /* Default value */
......
......@@ -170,9 +170,11 @@ typedef struct st_mi_decode_tree /* Decode huff-table */
struct st_mi_bit_buff;
/* Note that null markers should always be first in a row !
When creating a column, one should only specify:
type, length, null_bit and null_pos */
/*
Note that null markers should always be first in a row !
When creating a column, one should only specify:
type, length, null_bit and null_pos
*/
typedef struct st_columndef /* column information */
{
......@@ -253,14 +255,15 @@ extern uint mi_get_pointer_length(ulonglong file_length, uint def);
#define MYISAMCHK_VERIFY 2 /* run equivalent of myisamchk -c,
* if corruption is detected, do myisamchk -r*/
/* definitions needed for myisamchk.c -- by Sasha Pachev */
/*
Definitions needed for myisamchk.c
/* entries marked as "QQ to be removed" are NOT used to
* pass check/repair options to mi_check.c. They are used
* internally by myisamchk.c or/and ha_myisam.cc and should NOT
* be stored together with other flags. They should be removed
* from the following list to make adding of new flags possible.
* -- Sergei */
Entries marked as "QQ to be removed" are NOT used to
pass check/repair options to mi_check.c. They are used
internally by myisamchk.c or/and ha_myisam.cc and should NOT
be stored together with other flags. They should be removed
from the following list to make adding of new flags possible.
*/
#define T_VERBOSE 1
#define T_SILENT 2
......@@ -295,9 +298,10 @@ extern uint mi_get_pointer_length(ulonglong file_length, uint def);
#define T_QUICK (1L << 30)
#define T_RETRY_WITHOUT_QUICK (1L << 31)
/* flags used by myisamchk.c or/and ha_myisam.cc that are NOT passed
* to mi_check.c follows:
* */
/*
Flags used by myisamchk.c or/and ha_myisam.cc that are NOT passed
to mi_check.c follows:
*/
#define TT_USEFRM 1
......@@ -307,7 +311,8 @@ extern uint mi_get_pointer_length(ulonglong file_length, uint def);
/* these struct is used by my_check to tell it what to do */
typedef struct st_sort_key_blocks { /* Used when sorting */
typedef struct st_sort_key_blocks /* Used when sorting */
{
uchar *buff,*end_pos;
uchar lastkey[MI_MAX_POSSIBLE_KEY_BUFF];
uint last_length;
......@@ -316,7 +321,8 @@ typedef struct st_sort_key_blocks { /* Used when sorting */
struct st_mi_check_param;
typedef struct st_sort_info {
typedef struct st_sort_info
{
MI_INFO *info;
struct st_mi_check_param *param;
enum data_file_type new_data_file_type;
......@@ -364,7 +370,8 @@ typedef struct st_mi_check_param
} MI_CHECK;
typedef struct st_mi_sortinfo {
typedef struct st_mi_sortinfo
{
ha_rows max_records;
SORT_INFO *sort_info;
char *tmpdir;
......@@ -403,7 +410,7 @@ int filecopy(MI_CHECK *param, File to,File from,my_off_t start,
int movepoint(MI_INFO *info,byte *record,my_off_t oldpos,
my_off_t newpos, uint prot_key);
int sort_write_record(SORT_INFO *sort_info);
int write_data_suffix(MI_CHECK *param, MI_INFO *info);
int write_data_suffix(MI_CHECK *param, MI_INFO *info);
int _create_index_by_sort(MI_SORT_PARAM *info,my_bool no_messages,
ulong);
int test_if_almost_full(MI_INFO *info);
......
This diff is collapsed.
......@@ -54,9 +54,6 @@
#endif
#define RES_BUF_SHIFT 5
#ifndef __WIN__
#define SOCKET_ERROR -1
#endif
#define NET_BUF_SIZE 2048
MYSQL_MANAGER* STDCALL mysql_manager_init(MYSQL_MANAGER* con)
......@@ -101,7 +98,7 @@ MYSQL_MANAGER* STDCALL mysql_manager_connect(MYSQL_MANAGER* con,
if (!passwd)
passwd="";
if ((sock=(my_socket)socket(AF_INET,SOCK_STREAM,0)) == SOCKET_ERROR)
if ((sock=(my_socket)socket(AF_INET,SOCK_STREAM,0)) == INVALID_SOCKET)
{
con->last_errno=errno;
strmov(con->last_error,"Cannot create socket");
......@@ -185,6 +182,7 @@ MYSQL_MANAGER* STDCALL mysql_manager_connect(MYSQL_MANAGER* con,
strmov(con->user,user);
strmov(con->passwd,passwd);
return con;
err:
{
my_bool free_me=con->free_me;
......@@ -195,18 +193,20 @@ MYSQL_MANAGER* STDCALL mysql_manager_connect(MYSQL_MANAGER* con,
return 0;
}
void STDCALL mysql_manager_close(MYSQL_MANAGER* con)
void STDCALL mysql_manager_close(MYSQL_MANAGER* con)
{
my_free((gptr)con->host,MYF(MY_ALLOW_ZERO_PTR));
/* no need to free con->user and con->passwd, because they were
allocated in my_multimalloc() along with con->host, freeing
con->hosts frees the whole block
/*
No need to free con->user and con->passwd, because they were
allocated in my_multimalloc() along with con->host, freeing
con->hosts frees the whole block
*/
my_free((gptr)con->host,MYF(MY_ALLOW_ZERO_PTR));
net_end(&con->net);
if (con->free_me)
my_free((gptr)con,MYF(0));
}
int STDCALL mysql_manager_command(MYSQL_MANAGER* con,const char* cmd,
int cmd_len)
{
......@@ -222,8 +222,9 @@ int STDCALL mysql_manager_command(MYSQL_MANAGER* con,const char* cmd,
return 0;
}
int STDCALL mysql_manager_fetch_line(MYSQL_MANAGER* con, char* res_buf,
int res_buf_size)
int STDCALL mysql_manager_fetch_line(MYSQL_MANAGER* con, char* res_buf,
int res_buf_size)
{
char* res_buf_end=res_buf+res_buf_size;
char* net_buf=(char*) con->net.read_pos, *net_buf_end;
......@@ -252,7 +253,7 @@ int STDCALL mysql_manager_fetch_line(MYSQL_MANAGER* con, char* res_buf,
res_buf_end[-1]=0;
for (;net_buf<net_buf_end && res_buf < res_buf_end;res_buf++,net_buf++)
{
if((*res_buf=*net_buf) == '\r')
if ((*res_buf=*net_buf) == '\r')
{
*res_buf=0;
break;
......
......@@ -24,7 +24,8 @@
/* search with boolean queries */
static double _wghts[11]={
static double _wghts[11]=
{
0.131687242798354,
0.197530864197531,
0.296296296296296,
......@@ -38,7 +39,8 @@ static double _wghts[11]={
7.593750000000000};
static double *wghts=_wghts+5; /* wghts[i] = 1.5**i */
static double _nwghts[11]={
static double _nwghts[11]=
{
-0.065843621399177,
-0.098765432098766,
-0.148148148148148,
......@@ -57,7 +59,8 @@ static double *nwghts=_nwghts+5; /* nwghts[i] = -0.5*1.5**i */
#define FTB_FLAG_NO 4 /* should NEVER be set both */
typedef struct st_ftb_expr FTB_EXPR;
struct st_ftb_expr {
struct st_ftb_expr
{
FTB_EXPR *up;
byte *quot, *qend;
float weight;
......@@ -70,7 +73,8 @@ struct st_ftb_expr {
int yweaks; /* number of "yes" words for scan only */
};
typedef struct st_ftb_word {
typedef struct st_ftb_word
{
FTB_EXPR *up;
float weight;
uint flags;
......@@ -81,7 +85,8 @@ typedef struct st_ftb_word {
byte word[1];
} FTB_WORD;
typedef struct st_ft_info {
typedef struct st_ft_info
{
struct _ft_vft *please;
MI_INFO *info;
uint keynr;
......@@ -200,21 +205,23 @@ void _ftb_init_index_search(FT_INFO *ftb)
{
ftbw=(FTB_WORD *)(ftb->queue.root[i]);
if (ftbw->flags&FTB_FLAG_TRUNC)
/* special treatment for truncation operator :((
1. +trunc* and there're other (not +trunc*) words
if (ftbw->flags & FTB_FLAG_TRUNC)
{
/*
special treatment for truncation operator :((
1. +trunc* and there're other (not +trunc*) words
| no need to search in the index, it can never ADD new rows
| to the result, and to remove half-matched rows we do scan anyway
2. -trunc*
2. -trunc*
| same as 1.
3. trunc*
3. trunc*
| We have to index-search for this prefix.
| It may cause duplicates, as in the index (sorted by <word,docid>)
| <aaaa,row1>
| <aabb,row2>
| <aacc,row1>
| Searching for "aa*" will find row1 twice...
*/
*/
if ( test(ftbw->flags&FTB_FLAG_NO) || /* 2 */
(test(ftbw->flags&FTB_FLAG_YES) && /* 1 */
ftbw->up->ythresh - ftbw->up->yweaks >1)) /* 1 */
......@@ -231,7 +238,7 @@ void _ftb_init_index_search(FT_INFO *ftb)
_ftb_no_dupes_cmp,0,0,0);
}
}
}
r=_mi_search(info, keyinfo, (uchar*) ftbw->word, ftbw->len,
SEARCH_FIND | SEARCH_BIGGER, keyroot);
if (!r)
......@@ -246,8 +253,11 @@ void _ftb_init_index_search(FT_INFO *ftb)
if (r) /* not found */
{
if (ftbw->flags&FTB_FLAG_YES && ftbw->up->up==0)
{ /* this word MUST BE present in every document returned,
so we can abort the search right now */
{
/*
This word MUST BE present in every document returned,
so we can abort the search right now
*/
ftb->state=INDEX_DONE;
return;
}
......@@ -261,8 +271,10 @@ void _ftb_init_index_search(FT_INFO *ftb)
queue_fix(& ftb->queue);
}
FT_INFO * ft_init_boolean_search(MI_INFO *info, uint keynr, byte *query,
uint query_len, my_bool presort __attribute__((unused)))
uint query_len,
my_bool presort __attribute__((unused)))
{
FTB *ftb;
FTB_EXPR *ftbe;
......@@ -282,9 +294,10 @@ FT_INFO * ft_init_boolean_search(MI_INFO *info, uint keynr, byte *query,
init_alloc_root(&ftb->mem_root, 1024, 1024);
/* hack: instead of init_queue, we'll use reinit queue to be able
* to alloc queue with alloc_root()
*/
/*
Hack: instead of init_queue, we'll use reinit queue to be able
to alloc queue with alloc_root()
*/
res=ftb->queue.max_elements=1+query_len/(ft_min_word_len+1);
ftb->queue.root=(byte **)alloc_root(&ftb->mem_root, (res+1)*sizeof(void*));
reinit_queue(& ftb->queue, res, 0, 0,
......@@ -309,6 +322,7 @@ FT_INFO * ft_init_boolean_search(MI_INFO *info, uint keynr, byte *query,
return ftb;
}
/* returns 1 if str0 contain str1 */
int _ftb_strstr(const byte *s0, const byte *e0,
const byte *s1, const byte *e1,
......@@ -333,6 +347,7 @@ int _ftb_strstr(const byte *s0, const byte *e0,
return 0;
}
void _ftb_climb_the_tree(FTB *ftb, FTB_WORD *ftbw, FT_SEG_ITERATOR *ftsi_orig)
{
FT_SEG_ITERATOR ftsi;
......@@ -381,28 +396,31 @@ void _ftb_climb_the_tree(FTB *ftb, FTB_WORD *ftbw, FT_SEG_ITERATOR *ftsi_orig)
else
if (yn & FTB_FLAG_NO)
{
/* NOTE: special sort function of queue assures that all
* (yn & FTB_FLAG_NO) != 0
* events for every particular subexpression will
* "auto-magically" happen BEFORE all the
* (yn & FTB_FLAG_YES) != 0 events. So no
* already matched expression can become not-matched again.
/*
NOTE: special sort function of queue assures that all
(yn & FTB_FLAG_NO) != 0
events for every particular subexpression will
"auto-magically" happen BEFORE all the
(yn & FTB_FLAG_YES) != 0 events. So no
already matched expression can become not-matched again.
*/
++ftbe->nos;
break;
}
else
{
if (ftbe->ythresh) weight/=3;
if (ftbe->ythresh)
weight/=3;
ftbe->cur_weight += weight;
if (ftbe->yesses < ythresh)
break;
yn= (ftbe->yesses++ == ythresh) ? ftbe->flags : 0 ;
weight*=ftbe->weight;
weight*= ftbe->weight;
}
}
}
int ft_boolean_read_next(FT_INFO *ftb, char *record)
{
FTB_EXPR *ftbe;
......@@ -426,8 +444,9 @@ int ft_boolean_read_next(FT_INFO *ftb, char *record)
if (!ftb->queue.elements)
return my_errno=HA_ERR_END_OF_FILE;
while(ftb->state == INDEX_SEARCH &&
(curdoc=((FTB_WORD *)queue_top(& ftb->queue))->docid[0]) != HA_POS_ERROR)
while (ftb->state == INDEX_SEARCH &&
(curdoc=((FTB_WORD *)queue_top(& ftb->queue))->docid[0]) !=
HA_POS_ERROR)
{
while (curdoc==(ftbw=(FTB_WORD *)queue_top(& ftb->queue))->docid[0])
{
......@@ -449,8 +468,11 @@ int ft_boolean_read_next(FT_INFO *ftb, char *record)
{
ftbw->docid[0]=HA_POS_ERROR;
if (ftbw->flags&FTB_FLAG_YES && ftbw->up->up==0)
{ /* this word MUST BE present in every document returned,
so we can stop the search right now */
{
/*
This word MUST BE present in every document returned,
so we can stop the search right now
*/
ftb->state=INDEX_DONE;
}
}
......@@ -473,7 +495,7 @@ int ft_boolean_read_next(FT_INFO *ftb, char *record)
continue;
info->lastpos=curdoc;
info->update&= (HA_STATE_CHANGED | HA_STATE_ROW_CHANGED); /* why is this ? */
info->update&= (HA_STATE_CHANGED | HA_STATE_ROW_CHANGED);
if (!(*info->read_record)(info,curdoc,record))
{
......@@ -489,6 +511,7 @@ int ft_boolean_read_next(FT_INFO *ftb, char *record)
return my_errno=HA_ERR_END_OF_FILE;
}
float ft_boolean_find_relevance(FT_INFO *ftb, byte *record, uint length)
{
FT_WORD word;
......@@ -555,6 +578,7 @@ float ft_boolean_find_relevance(FT_INFO *ftb, byte *record, uint length)
}
}
void ft_boolean_close_search(FT_INFO *ftb)
{
if (is_tree_inited(& ftb->no_dupes))
......@@ -565,11 +589,13 @@ void ft_boolean_close_search(FT_INFO *ftb)
my_free((gptr)ftb,MYF(0));
}
float ft_boolean_get_relevance(FT_INFO *ftb)
{
return ftb->root->cur_weight;
}
void ft_boolean_reinit_search(FT_INFO *ftb)
{
_ftb_init_index_search(ftb);
......
......@@ -148,16 +148,16 @@ int main(int argc,char *argv[])
if (maxlen<keylen2)
{
maxlen=keylen2;
strcpy(buf_maxlen, buf2);
strmov(buf_maxlen, buf2);
}
if (max_doc_cnt < doc_cnt)
{
max_doc_cnt=doc_cnt;
strcpy(buf_min_gws, buf2);
strmov(buf_min_gws, buf2);
min_gws=gws;
}
}
strcpy(buf2, buf);
strmov(buf2, buf);
keylen2=keylen;
doc_cnt=0;
}
......
......@@ -79,7 +79,7 @@ int main(int argc, char *argv[])
my_errno=0;
i=0;
while(create_record(record,df))
while (create_record(record,df))
{
error=mi_write(file,record);
if (error)
......@@ -94,24 +94,28 @@ int main(int argc, char *argv[])
if (!(file=mi_open(filename,2,0))) goto err;
if (!silent)
printf("- Reading rows with key\n");
for(i=1;create_record(record,qf);i++) {
for (i=1;create_record(record,qf);i++)
{
FT_DOCLIST *result;
double w;
int t, err;
result=ft_nlq_init_search(file,0,blob_record,(uint) strlen(blob_record),1);
if(!result) {
if (!result)
{
printf("Query %d failed with errno %3d\n",i,my_errno);
goto err;
}
if (!silent)
printf("Query %d. Found: %d.\n",i,result->ndocs);
for(j=0;(err=ft_nlq_read_next(result, read_record))==0;j++) {
for (j=0;(err=ft_nlq_read_next(result, read_record))==0;j++)
{
t=uint2korr(read_record);
w=ft_nlq_get_relevance(result);
printf("%d %.*s %f\n",i,t,read_record+2,w);
}
if(err != HA_ERR_END_OF_FILE) {
}
if (err != HA_ERR_END_OF_FILE)
{
printf("ft_read_next %d failed with errno %3d\n",j,my_errno);
goto err;
}
......@@ -134,24 +138,28 @@ static my_bool
get_one_option(int optid, const struct my_option *opt __attribute__((unused)),
char *argument)
{
switch(optid) {
switch (optid) {
case 's':
if(stopwordlist && stopwordlist!=ft_precompiled_stopwords) break;
if (stopwordlist && stopwordlist != ft_precompiled_stopwords)
break;
{
FILE *f; char s[HA_FT_MAXLEN]; int i=0,n=SWL_INIT;
if(!(stopwordlist=(const char**) malloc(n*sizeof(char *))))
if (!(stopwordlist=(const char**) malloc(n*sizeof(char *))))
print_error(1,"malloc(%d)",n*sizeof(char *));
if(!(f=fopen(argument,"r")))
if (!(f=fopen(argument,"r")))
print_error(1,"fopen(%s)",argument);
while(!feof(f)) {
if(!(fgets(s,HA_FT_MAXLEN,f)))
while (!feof(f))
{
if (!(fgets(s,HA_FT_MAXLEN,f)))
print_error(1,"fgets(s,%d,%s)",HA_FT_MAXLEN,argument);
if(!(stopwordlist[i++]=strdup(s)))
if (!(stopwordlist[i++]=strdup(s)))
print_error(1,"strdup(%s)",s);
if(i>=n) {
if (i >= n)
{
n+=SWL_PLUS;
if(!(stopwordlist=(const char**) realloc((char*) stopwordlist,n*sizeof(char *))))
if (!(stopwordlist=(const char**) realloc((char*) stopwordlist,
n*sizeof(char *))))
print_error(1,"realloc(%d)",n*sizeof(char *));
}
}
......@@ -160,7 +168,7 @@ get_one_option(int optid, const struct my_option *opt __attribute__((unused)),
break;
}
case 'q': silent=1; break;
case 'S': if(stopwordlist==ft_precompiled_stopwords) stopwordlist=NULL; break;
case 'S': if (stopwordlist==ft_precompiled_stopwords) stopwordlist=NULL; break;
case '#':
DEBUGGER_ON;
DBUG_PUSH (argument);
......@@ -174,6 +182,7 @@ get_one_option(int optid, const struct my_option *opt __attribute__((unused)),
return 0;
}
static void get_options(int argc, char *argv[])
{
int ho_error;
......@@ -181,24 +190,29 @@ static void get_options(int argc, char *argv[])
if ((ho_error=handle_options(&argc, &argv, my_long_options, get_one_option)))
exit(ho_error);
if(!(d_file=argv[optind])) print_error(1,"No d_file");
if(!(df=fopen(d_file,"r")))
if (!(d_file=argv[optind])) print_error(1,"No d_file");
if (!(df=fopen(d_file,"r")))
print_error(1,"fopen(%s)",d_file);
if(!(q_file=argv[optind+1])) print_error(1,"No q_file");
if(!(qf=fopen(q_file,"r")))
if (!(q_file=argv[optind+1])) print_error(1,"No q_file");
if (!(qf=fopen(q_file,"r")))
print_error(1,"fopen(%s)",q_file);
return;
} /* get options */
static int create_record(char *pos, FILE *file)
{ uint tmp; char *ptr;
{
uint tmp; char *ptr;
bzero((char *)pos,MAX_REC_LENGTH);
/* column 1 - VARCHAR */
if(!(fgets(pos+2,MAX_REC_LENGTH-32,file)))
if (!(fgets(pos+2,MAX_REC_LENGTH-32,file)))
{
if(feof(file)) return 0; else print_error(1,"fgets(docid) - 1");
if (feof(file))
return 0;
else
print_error(1,"fgets(docid) - 1");
}
tmp=(uint) strlen(pos+2)-1;
int2store(pos,tmp);
......@@ -206,7 +220,7 @@ static int create_record(char *pos, FILE *file)
/* column 2 - BLOB */
if(!(fgets(blob_record,MAX_BLOB_LENGTH,file)))
if (!(fgets(blob_record,MAX_BLOB_LENGTH,file)))
print_error(1,"fgets(docid) - 2");
tmp=(uint) strlen(blob_record);
int4store(pos,tmp);
......
......@@ -21,12 +21,14 @@
/* search with natural language queries */
typedef struct ft_doc_rec {
typedef struct ft_doc_rec
{
my_off_t dpos;
double weight;
} FT_DOC;
struct st_ft_info {
struct st_ft_info
{
struct _ft_vft *please;
MI_INFO *info;
int ndocs;
......@@ -34,7 +36,8 @@ struct st_ft_info {
FT_DOC doc[1];
};
typedef struct st_all_in_one {
typedef struct st_all_in_one
{
MI_INFO *info;
uint keynr;
CHARSET_INFO *charset;
......@@ -44,7 +47,8 @@ typedef struct st_all_in_one {
TREE dtree;
} ALL_IN_ONE;
typedef struct st_ft_superdoc {
typedef struct st_ft_superdoc
{
FT_DOC doc;
FT_WORD *word_ptr;
double tmp_weight;
......@@ -92,7 +96,7 @@ static int walk_and_match(FT_WORD *word, uint32 count, ALL_IN_ONE *aio)
r=_mi_search(aio->info, aio->keyinfo, aio->keybuff, keylen,
SEARCH_FIND | SEARCH_PREFIX, aio->key_root);
while(!r)
while (!r)
{
if (_mi_compare_text(aio->charset,
aio->info->lastkey,keylen,
......@@ -116,11 +120,12 @@ static int walk_and_match(FT_WORD *word, uint32 count, ALL_IN_ONE *aio)
sdoc.doc.dpos=aio->info->lastpos;
/* saving document matched into dtree */
if(!(selem=tree_insert(&aio->dtree, &sdoc, 0))) return 1;
if (!(selem=tree_insert(&aio->dtree, &sdoc, 0)))
return 1;
sptr=(FT_SUPERDOC *)ELEMENT_KEY((&aio->dtree), selem);
if(selem->count==1) /* document's first match */
if (selem->count==1) /* document's first match */
sptr->doc.weight=0;
else
sptr->doc.weight+=sptr->tmp_weight*sptr->word_ptr->weight;
......@@ -144,31 +149,35 @@ static int walk_and_match(FT_WORD *word, uint32 count, ALL_IN_ONE *aio)
aio->info->lastkey_length, SEARCH_BIGGER,
aio->key_root);
}
if(doc_cnt) {
if (doc_cnt)
{
word->weight*=GWS_IN_USE;
if(word->weight < 0) word->weight=0;
if (word->weight < 0)
word->weight=0;
}
return 0;
}
static int walk_and_copy(FT_SUPERDOC *from,
uint32 count __attribute__((unused)), FT_DOC **to)
{
from->doc.weight+=from->tmp_weight*from->word_ptr->weight;
(*to)->dpos=from->doc.dpos;
(*to)->weight=from->doc.weight;
(*to)++;
return 0;
from->doc.weight+=from->tmp_weight*from->word_ptr->weight;
(*to)->dpos=from->doc.dpos;
(*to)->weight=from->doc.weight;
(*to)++;
return 0;
}
static int FT_DOC_cmp(FT_DOC *a, FT_DOC *b)
{
return sgn(b->weight - a->weight);
return sgn(b->weight - a->weight);
}
FT_INFO *ft_init_nlq_search(MI_INFO *info, uint keynr, byte *query,
uint query_len, my_bool presort)
uint query_len, my_bool presort)
{
TREE allocated_wtree, *wtree=&allocated_wtree;
ALL_IN_ONE aio;
......@@ -196,15 +205,16 @@ FT_INFO *ft_init_nlq_search(MI_INFO *info, uint keynr, byte *query,
NULL, NULL);
ft_parse_init(&allocated_wtree, aio.charset);
if(ft_parse(&allocated_wtree,query,query_len))
if (ft_parse(&allocated_wtree,query,query_len))
goto err;
if(tree_walk(wtree, (tree_walk_action)&walk_and_match, &aio,
left_root_right))
if (tree_walk(wtree, (tree_walk_action)&walk_and_match, &aio,
left_root_right))
goto err2;
dlist=(FT_INFO *)my_malloc(sizeof(FT_INFO)+
sizeof(FT_DOC)*(aio.dtree.elements_in_tree-1),MYF(0));
sizeof(FT_DOC)*(aio.dtree.elements_in_tree-1),
MYF(0));
if(!dlist)
goto err2;
......@@ -214,10 +224,10 @@ FT_INFO *ft_init_nlq_search(MI_INFO *info, uint keynr, byte *query,
dlist->info=aio.info;
dptr=dlist->doc;
tree_walk(&aio.dtree, (tree_walk_action)&walk_and_copy,
&dptr, left_root_right);
tree_walk(&aio.dtree, (tree_walk_action) &walk_and_copy,
&dptr, left_root_right);
if(presort)
if (presort)
qsort(dlist->doc, dlist->ndocs, sizeof(FT_DOC), (qsort_cmp)&FT_DOC_cmp);
err2:
......@@ -229,6 +239,7 @@ FT_INFO *ft_init_nlq_search(MI_INFO *info, uint keynr, byte *query,
return dlist;
}
int ft_nlq_read_next(FT_INFO *handler, char *record)
{
MI_INFO *info= (MI_INFO *) handler->info;
......@@ -250,6 +261,7 @@ int ft_nlq_read_next(FT_INFO *handler, char *record)
return my_errno;
}
float ft_nlq_find_relevance(FT_INFO *handler,
byte *record __attribute__((unused)),
uint length __attribute__((unused)))
......@@ -276,16 +288,19 @@ float ft_nlq_find_relevance(FT_INFO *handler,
return 0.0;
}
void ft_nlq_close_search(FT_INFO *handler)
{
my_free((gptr)handler,MYF(0));
}
float ft_nlq_get_relevance(FT_INFO *handler)
{
return (float) handler->doc[handler->curdoc].weight;
}
void ft_nlq_reinit_search(FT_INFO *handler)
{
handler->curdoc=-1;
......
......@@ -205,7 +205,7 @@ void create_record(char *pos, int n)
{
uint tmp;
char *ptr;
strncpy(blob_key,data[n].f0,keyinfo[0].seg[0].length);
strnmov(blob_key,data[n].f0,keyinfo[0].seg[0].length);
tmp=strlen(blob_key);
int4store(pos,tmp);
ptr=blob_key;
......@@ -215,21 +215,21 @@ void create_record(char *pos, int n)
else if (recinfo[0].type == FIELD_VARCHAR)
{
uint tmp;
strncpy(pos+2,data[n].f0,keyinfo[0].seg[0].length);
strnmov(pos+2,data[n].f0,keyinfo[0].seg[0].length);
tmp=strlen(pos+2);
int2store(pos,tmp);
pos+=recinfo[0].length;
}
else
{
strncpy(pos,data[n].f0,keyinfo[0].seg[0].length);
strnmov(pos,data[n].f0,keyinfo[0].seg[0].length);
pos+=recinfo[0].length;
}
if (recinfo[1].type == FIELD_BLOB)
{
uint tmp;
char *ptr;
strncpy(blob_key,data[n].f2,keyinfo[0].seg[0].length);
strnmov(blob_key,data[n].f2,keyinfo[0].seg[0].length);
tmp=strlen(blob_key);
int4store(pos,tmp);
ptr=blob_key;
......@@ -239,14 +239,14 @@ void create_record(char *pos, int n)
else if (recinfo[1].type == FIELD_VARCHAR)
{
uint tmp;
strncpy(pos+2,data[n].f2,keyinfo[0].seg[0].length);
strnmov(pos+2,data[n].f2,keyinfo[0].seg[0].length);
tmp=strlen(pos+2);
int2store(pos,tmp);
pos+=recinfo[1].length;
}
else
{
strncpy(pos,data[n].f2,keyinfo[0].seg[0].length);
strnmov(pos,data[n].f2,keyinfo[0].seg[0].length);
pos+=recinfo[1].length;
}
}
......
......@@ -29,7 +29,7 @@
/**************************************************************/
void _mi_ft_segiterator_init(MI_INFO *info, uint keynr, const byte *record,
FT_SEG_ITERATOR *ftsi)
FT_SEG_ITERATOR *ftsi)
{
ftsi->num=info->s->keyinfo[keynr].keysegs-FT_SEGS;
ftsi->seg=info->s->keyinfo[keynr].seg;
......@@ -37,7 +37,7 @@ void _mi_ft_segiterator_init(MI_INFO *info, uint keynr, const byte *record,
}
void _mi_ft_segiterator_dummy_init(const byte *record, uint len,
FT_SEG_ITERATOR *ftsi)
FT_SEG_ITERATOR *ftsi)
{
ftsi->num=1;
ftsi->seg=0;
......@@ -45,12 +45,13 @@ void _mi_ft_segiterator_dummy_init(const byte *record, uint len,
ftsi->len=len;
}
/* This function breaks convention "return 0 in success"
but it's easier to use like this
/*
This function breaks convention "return 0 in success"
but it's easier to use like this
while(_mi_ft_segiterator())
while(_mi_ft_segiterator())
so "1" means "OK", "0" means "EOF"
so "1" means "OK", "0" means "EOF"
*/
uint _mi_ft_segiterator(register FT_SEG_ITERATOR *ftsi)
......@@ -68,7 +69,7 @@ uint _mi_ft_segiterator(register FT_SEG_ITERATOR *ftsi)
if (ftsi->seg->flag & HA_VAR_LENGTH)
{
ftsi->len=uint2korr(ftsi->pos);
ftsi->pos+=2; /* Skip VARCHAR length */
ftsi->pos+=2; /* Skip VARCHAR length */
set_if_smaller(ftsi->len,ftsi->seg->length);
return 1;
}
......@@ -84,7 +85,9 @@ uint _mi_ft_segiterator(register FT_SEG_ITERATOR *ftsi)
return 1;
}
/* parses a document i.e. calls ft_parse for every keyseg */
uint _mi_ft_parse(TREE *parsed, MI_INFO *info, uint keynr, const byte *record)
{
FT_SEG_ITERATOR ftsi;
......@@ -92,10 +95,11 @@ uint _mi_ft_parse(TREE *parsed, MI_INFO *info, uint keynr, const byte *record)
ft_parse_init(parsed, info->s->keyinfo[keynr].seg->charset);
while (_mi_ft_segiterator(&ftsi))
{
if (ftsi.pos)
if (ft_parse(parsed, (byte *)ftsi.pos, ftsi.len))
return 1;
}
return 0;
}
......@@ -117,32 +121,33 @@ static int _mi_ft_store(MI_INFO *info, uint keynr, byte *keybuf,
{
uint key_length;
while(wlist->pos)
for (; wlist->pos; wlist++)
{
key_length=_ft_make_key(info,keynr,keybuf,wlist,filepos);
if (_mi_ck_write(info,keynr,(uchar*) keybuf,key_length))
return 1;
wlist++;
}
return 0;
}
static int _mi_ft_erase(MI_INFO *info, uint keynr, byte *keybuf, FT_WORD *wlist, my_off_t filepos)
static int _mi_ft_erase(MI_INFO *info, uint keynr, byte *keybuf,
FT_WORD *wlist, my_off_t filepos)
{
uint key_length, err=0;
while(wlist->pos)
for (; wlist->pos; wlist++)
{
key_length=_ft_make_key(info,keynr,keybuf,wlist,filepos);
if (_mi_ck_delete(info,keynr,(uchar*) keybuf,key_length))
err=1;
wlist++;
}
return err;
}
/* compares an appropriate parts of two WORD_KEY keys directly out of records */
/* returns 1 if they are different */
/*
Compares an appropriate parts of two WORD_KEY keys directly out of records
returns 1 if they are different
*/
#define THOSE_TWO_DAMN_KEYS_ARE_REALLY_DIFFERENT 1
#define GEE_THEY_ARE_ABSOLUTELY_IDENTICAL 0
......@@ -154,7 +159,7 @@ int _mi_ft_cmp(MI_INFO *info, uint keynr, const byte *rec1, const byte *rec2)
_mi_ft_segiterator_init(info, keynr, rec1, &ftsi1);
_mi_ft_segiterator_init(info, keynr, rec2, &ftsi2);
while(_mi_ft_segiterator(&ftsi1) && _mi_ft_segiterator(&ftsi2))
while (_mi_ft_segiterator(&ftsi1) && _mi_ft_segiterator(&ftsi2))
{
if ((ftsi1.pos != ftsi2.pos) &&
(!ftsi1.pos || !ftsi2.pos ||
......@@ -165,7 +170,9 @@ int _mi_ft_cmp(MI_INFO *info, uint keynr, const byte *rec1, const byte *rec2)
return GEE_THEY_ARE_ABSOLUTELY_IDENTICAL;
}
/* update a document entry */
int _mi_ft_update(MI_INFO *info, uint keynr, byte *keybuf,
const byte *oldrec, const byte *newrec, my_off_t pos)
{
......@@ -215,7 +222,9 @@ int _mi_ft_update(MI_INFO *info, uint keynr, byte *keybuf,
return error;
}
/* adds a document to the collection */
int _mi_ft_add(MI_INFO *info, uint keynr, byte *keybuf, const byte *record,
my_off_t pos)
{
......@@ -230,7 +239,9 @@ int _mi_ft_add(MI_INFO *info, uint keynr, byte *keybuf, const byte *record,
return error;
}
/* removes a document from the collection */
int _mi_ft_del(MI_INFO *info, uint keynr, byte *keybuf, const byte *record,
my_off_t pos)
{
......
......@@ -42,8 +42,10 @@ my_off_t myisam_max_extra_temp_length= MI_MAX_TEMP_LENGTH;
my_off_t myisam_max_temp_length= MAX_FILE_SIZE;
ulong myisam_bulk_insert_tree_size=8192*1024;
/* read_vec[] is used for converting between P_READ_KEY.. and SEARCH_ */
/* Position is , == , >= , <= , > , < */
/*
read_vec[] is used for converting between P_READ_KEY.. and SEARCH_
Position is , == , >= , <= , > , <
*/
uint NEAR myisam_read_vec[]=
{
......
......@@ -341,13 +341,19 @@ int main(int argc, char *argv[])
}
}
}
if (testflag==3) goto end;
if (testflag == 3)
goto end;
for (i=999, dupp_keys=j=0 ; i>0 ; i--)
{
if (key1[i] > dupp_keys) { dupp_keys=key1[i]; j=i; }
if (key1[i] > dupp_keys)
{
dupp_keys=key1[i]; j=i;
}
}
sprintf(key,"%6d",j);
start=keyinfo[0].seg[0].start;
length=keyinfo[0].seg[0].length;
if (dupp_keys)
{
if (!silent)
......@@ -355,8 +361,10 @@ int main(int argc, char *argv[])
DBUG_PRINT("progpos",("first - next -> last - prev -> first"));
if (verbose) printf(" Using key: \"%s\" Keys: %d\n",key,dupp_keys);
if (mi_rkey(file,read_record,0,key,0,HA_READ_KEY_EXACT)) goto err;
if (mi_rsame(file,read_record2,-1)) goto err;
if (mi_rkey(file,read_record,0,key,0,HA_READ_KEY_EXACT))
goto err;
if (mi_rsame(file,read_record2,-1))
goto err;
if (memcmp(read_record,read_record2,reclength) != 0)
{
printf("mi_rsame didn't find same record\n");
......@@ -381,7 +389,6 @@ int main(int argc, char *argv[])
}
}
ant=1;
start=keyinfo[0].seg[0].start; length=keyinfo[0].seg[0].length;
while (mi_rnext(file,read_record2,0) == 0 &&
memcmp(read_record2+start,key,length) == 0) ant++;
if (ant != dupp_keys)
......
......@@ -103,7 +103,7 @@ int mi_write(MI_INFO *info, byte *record)
{
bool local_lock_tree= (lock_tree &&
!(info->bulk_insert &&
is_tree_inited(& info->bulk_insert[i])));
is_tree_inited(&info->bulk_insert[i])));
if (local_lock_tree)
{
rw_wrlock(&share->key_root_lock[i]);
......@@ -168,9 +168,9 @@ int mi_write(MI_INFO *info, byte *record)
uint j;
for (j=0 ; j < share->base.keys ; j++)
{
if (is_tree_inited(& info->bulk_insert[j]))
if (is_tree_inited(&info->bulk_insert[j]))
{
reset_tree(& info->bulk_insert[j]);
reset_tree(&info->bulk_insert[j]);
}
}
}
......@@ -181,7 +181,7 @@ int mi_write(MI_INFO *info, byte *record)
{
bool local_lock_tree= (lock_tree &&
!(info->bulk_insert &&
is_tree_inited(& info->bulk_insert[i])));
is_tree_inited(&info->bulk_insert[i])));
if (local_lock_tree)
rw_wrlock(&share->key_root_lock[i]);
if (share->keyinfo[i].flag & HA_FULLTEXT)
......@@ -227,7 +227,7 @@ int _mi_ck_write(MI_INFO *info, uint keynr, uchar *key, uint key_length)
{
DBUG_ENTER("_mi_ck_write");
if (info->bulk_insert && is_tree_inited(& info->bulk_insert[keynr]))
if (info->bulk_insert && is_tree_inited(&info->bulk_insert[keynr]))
{
DBUG_RETURN(_mi_ck_write_tree(info, keynr, key, key_length));
}
......@@ -750,7 +750,7 @@ int _mi_ck_write_tree(register MI_INFO *info, uint keynr, uchar *key,
int error;
DBUG_ENTER("_mi_ck_write_tree");
error= tree_insert(& info->bulk_insert[keynr], key,
error= tree_insert(&info->bulk_insert[keynr], key,
key_length + info->s->rec_reflength) ? 0 : HA_ERR_OUT_OF_MEM ;
DBUG_RETURN(error);
......
......@@ -14,16 +14,16 @@
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
/* Returnerar en pekare till filnamnets extension. */
#include "mysys_priv.h"
#include <m_string.h>
/* Return a pointerto the extension of the filename
The pointer points at the extension character (normally '.'))
If there isn't any extension, the pointer points at the end
NULL of the filename
*/
/*
Return a pointerto the extension of the filename
The pointer points at the extension character (normally '.'))
If there isn't any extension, the pointer points at the end
ASCII(0) of the filename.
*/
my_string fn_ext(const char *name)
{
......
......@@ -73,11 +73,12 @@ init_functions(IO_CACHE* info, enum cache_type type)
{
switch (type) {
case READ_NET:
/* must be initialized by the caller. The problem is that
_my_b_net_read has to be defined in sql directory because of
the dependency on THD, and therefore cannot be visible to
programs that link against mysys but know nothing about THD, such
as myisamchk
/*
Must be initialized by the caller. The problem is that
_my_b_net_read has to be defined in sql directory because of
the dependency on THD, and therefore cannot be visible to
programs that link against mysys but know nothing about THD, such
as myisamchk
*/
break;
case SEQ_READ_APPEND:
......
......@@ -27,32 +27,36 @@
my_off_t my_b_append_tell(IO_CACHE* info)
{
/* prevent optimizer from putting res in a register when debugging
we need this to be able to see the value of res when the assert fails
/*
Prevent optimizer from putting res in a register when debugging
we need this to be able to see the value of res when the assert fails
*/
dbug_volatile my_off_t res;
/* we need to lock the append buffer mutex to keep flush_io_cache()
from messing with the variables that we need in order to provide the
answer to the question.
*/
/*
We need to lock the append buffer mutex to keep flush_io_cache()
from messing with the variables that we need in order to provide the
answer to the question.
*/
#ifdef THREAD
pthread_mutex_lock(&info->append_buffer_lock);
#endif
/* save the value of my_tell in res so we can see it when studying
coredump
*/
#ifndef DBUG_OFF
/* make sure EOF is where we think it is. Note that we cannot just use
my_tell() because we have a reader thread that could have left the
file offset in a non-EOF location
*/
/*
Make sure EOF is where we think it is. Note that we cannot just use
my_tell() because we have a reader thread that could have left the
file offset in a non-EOF location
*/
{
volatile my_off_t save_pos;
save_pos = my_tell(info->file,MYF(0));
my_seek(info->file,(my_off_t)0,MY_SEEK_END,MYF(0));
DBUG_ASSERT(info->end_of_file - (info->append_read_pos-info->write_buffer)
== (res=my_tell(info->file,MYF(0))));
my_seek(info->file,save_pos,MY_SEEK_SET,MYF(0));
volatile my_off_t save_pos;
save_pos = my_tell(info->file,MYF(0));
my_seek(info->file,(my_off_t)0,MY_SEEK_END,MYF(0));
/*
Save the value of my_tell in res so we can see it when studying coredump
*/
DBUG_ASSERT(info->end_of_file - (info->append_read_pos-info->write_buffer)
== (res=my_tell(info->file,MYF(0))));
my_seek(info->file,save_pos,MY_SEEK_SET,MYF(0));
}
#endif
res = info->end_of_file + (info->write_pos-info->append_read_pos);
......@@ -74,10 +78,9 @@ void my_b_seek(IO_CACHE *info,my_off_t pos)
DBUG_PRINT("enter",("pos: %lu", (ulong) pos));
/*
TODO: verify that it is OK to do seek in the non-append
area in SEQ_READ_APPEND cache
*/
/* TODO:
TODO:
Verify that it is OK to do seek in the non-append
area in SEQ_READ_APPEND cache
a) see if this always works
b) see if there is a better way to make it work
*/
......
......@@ -22,17 +22,17 @@
#include <my_sys.h>
#include <mysys_err.h>
static int findopt (char *optpat, uint length,
const struct my_option **opt_res,
char **ffname);
static my_bool compare_strings (register const char *s, register const char *t,
uint length);
static longlong getopt_ll (char *arg, const struct my_option *optp, int *err);
static ulonglong getopt_ull (char *arg, const struct my_option *optp,
int *err);
static int findopt(char *optpat, uint length,
const struct my_option **opt_res,
char **ffname);
static my_bool compare_strings(register const char *s, register const char *t,
uint length);
static longlong getopt_ll(char *arg, const struct my_option *optp, int *err);
static ulonglong getopt_ull(char *arg, const struct my_option *optp,
int *err);
static void init_variables(const struct my_option *options);
static int setval (const struct my_option *opts, char *argument,
my_bool set_maximum_value);
static int setval(const struct my_option *opts, char *argument,
my_bool set_maximum_value);
/*
The following three variables belong to same group and the number and
......@@ -42,8 +42,8 @@ static const char *special_opt_prefix[]=
{"skip", "disable", "enable", "maximum", "loose", 0};
static const uint special_opt_prefix_lengths[]=
{ 4, 7, 6, 7, 5, 0};
enum enum_special_opt { OPT_SKIP, OPT_DISABLE, OPT_ENABLE, OPT_MAXIMUM,
OPT_LOOSE};
enum enum_special_opt
{ OPT_SKIP, OPT_DISABLE, OPT_ENABLE, OPT_MAXIMUM, OPT_LOOSE};
char *disabled_my_option= (char*) "0";
......@@ -74,7 +74,7 @@ int handle_options(int *argc, char ***argv,
{
uint opt_found, argvpos= 0, length, i;
my_bool end_of_options= 0, must_be_var, set_maximum_value, special_used,
option_is_loose, option_used= 0;
option_is_loose;
char *progname= *(*argv), **pos, *optend, *prev_found;
const struct my_option *optp;
int error;
......@@ -90,7 +90,6 @@ int handle_options(int *argc, char ***argv,
if (cur_arg[0] == '-' && cur_arg[1] && !end_of_options) /* must be opt */
{
char *argument= 0;
option_used= 1;
must_be_var= 0;
set_maximum_value= 0;
special_used= 0;
......@@ -406,12 +405,13 @@ int handle_options(int *argc, char ***argv,
else /* non-option found */
(*argv)[argvpos++]= cur_arg;
}
/* Destroy the first, already handled option, so that programs that look
for arguments in 'argv', without checking 'argc', know when to stop.
Items in argv, before the destroyed one, are all non-option -arguments
to the program, yet to be (possibly) handled. */
if (option_used)
(*argv)[argvpos]= 0;
/*
Destroy the first, already handled option, so that programs that look
for arguments in 'argv', without checking 'argc', know when to stop.
Items in argv, before the destroyed one, are all non-option -arguments
to the program, yet to be (possibly) handled.
*/
(*argv)[argvpos]= 0;
return 0;
}
......@@ -429,8 +429,8 @@ static int setval (const struct my_option *opts, char *argument,
if (opts->value && argument)
{
gptr *result_pos= (set_maximum_value) ?
opts->u_max_value : opts->value;
gptr *result_pos= ((set_maximum_value) ?
opts->u_max_value : opts->value);
if (!result_pos)
return EXIT_NO_PTR_TO_VARIABLE;
......
......@@ -19,13 +19,22 @@
#include <errno.h>
/* Read a chunk of bytes from a file */
/*
Read a chunk of bytes from a file with retry's if needed
The parameters are:
File descriptor
Buffer to hold at least Count bytes
Bytes to read
Flags on what to do on error
Return:
-1 on error
0 if flag has bits MY_NABP or MY_FNABP set
N number of bytes read.
*/
uint my_read(File Filedes, byte *Buffer, uint Count, myf MyFlags)
/* File descriptor */
/* Buffer must be at least count bytes */
/* Max number of bytes returnd */
/* Flags on what to do on error */
{
uint readbytes,save_count;
DBUG_ENTER("my_read");
......
......@@ -15,8 +15,8 @@
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
/*
** Functions to handle initializating and allocationg of all mysys & debug
** thread variables.
Functions to handle initializating and allocationg of all mysys & debug
thread variables.
*/
#include "mysys_priv.h"
......@@ -44,10 +44,6 @@ pthread_mutexattr_t my_fast_mutexattr;
pthread_mutexattr_t my_errchk_mutexattr;
#endif
/* FIXME Note. TlsAlloc does not set an auto destructor, so
the function my_thread_global_free must be called from
somewhere before final exit of the library */
my_bool my_thread_global_init(void)
{
if (pthread_key_create(&THR_KEY_mysys,free))
......@@ -86,6 +82,7 @@ my_bool my_thread_global_init(void)
return my_thread_init();
}
void my_thread_global_end(void)
{
#if defined(USE_TLS)
......@@ -158,6 +155,7 @@ my_bool my_thread_init(void)
return error;
}
void my_thread_end(void)
{
struct st_my_thread_var *tmp=my_thread_var;
......@@ -204,8 +202,9 @@ struct st_my_thread_var *_my_thread_var(void)
return tmp;
}
/****************************************************************************
** Get name of current thread.
Get name of current thread.
****************************************************************************/
#define UNKNOWN_THREAD -1
......
......@@ -173,11 +173,13 @@ static int queue_fix_cmp(QUEUE *queue, void **a, void **b)
(char*) (*b)+queue->offset_to_key);
}
/* Fix heap when every element was changed
actually, it can be done in linear time,
not in n*log(n), but some code (myisam/ft_boolean_search.c)
requires a strict order here, not just a queue property
/*
Fix heap when every element was changed
actually, it can be done in linear time,
not in n*log(n), but some code (myisam/ft_boolean_search.c)
requires a strict order here, not just a queue property
*/
void queue_fix(QUEUE *queue)
{
qsort2(queue->root+1,queue->elements, sizeof(void *),
......
This diff is collapsed.
......@@ -141,7 +141,7 @@ bool test_if_int(const char *str,int length)
str++;
if (str == end)
return 0; // Error: Empty string
for ( ; str != end ; str++)
for (; str != end ; str++)
{
if (!isdigit(*str))
{
......@@ -204,7 +204,7 @@ static bool test_if_real(const char *str,int length)
length--; str++;
}
}
for ( ; length ; length--, str++)
for (; length ; length--, str++)
{ // Allow end space
if (!isspace(*str))
return 0;
......@@ -3336,9 +3336,9 @@ void Field_datetime::sql_type(String &res) const
void Field_string::store(const char *from,uint length)
{
#ifdef USE_TIS620
if(!binary_flag) {
if (!binary_flag) {
ThNormalize((uchar *)ptr, field_length, (uchar *)from, length);
if(length < field_length) {
if (length < field_length) {
bfill(ptr + length, field_length - length, ' ');
}
}
......@@ -3540,7 +3540,7 @@ uint Field_string::max_packed_col_length(uint max_length)
void Field_varstring::store(const char *from,uint length)
{
#ifdef USE_TIS620
if(!binary_flag)
if (!binary_flag)
{
ThNormalize((uchar *) ptr+2, field_length, (uchar *) from, length);
}
......@@ -3869,7 +3869,7 @@ void Field_blob::store(const char *from,uint len)
if (table->copy_blobs || len <= MAX_FIELD_WIDTH)
{ // Must make a copy
#ifdef USE_TIS620
if(!binary_flag)
if (!binary_flag)
{
/* If there isn't enough memory, use original string */
if ((th_ptr=(char * ) my_malloc(sizeof(char) * len,MYF(0))))
......@@ -4489,7 +4489,7 @@ ulonglong find_set(TYPELIB *lib,const char *x,uint length)
for (;;)
{
const char *pos=start;
for ( ; pos != end && *pos != field_separator ; pos++) ;
for (; pos != end && *pos != field_separator ; pos++) ;
uint find=find_enum(lib,start,(uint) (pos-start));
if (!find)
error=1;
......
......@@ -358,7 +358,7 @@ berkeley_cmp_packed_key(DB *file, const DBT *new_key, const DBT *saved_key)
KEY_PART_INFO *key_part= key->key_part, *end=key_part+key->key_parts;
uint key_length=new_key->size;
for ( ; key_part != end && (int) key_length > 0; key_part++)
for (; key_part != end && (int) key_length > 0; key_part++)
{
int cmp;
if (key_part->null_bit)
......@@ -396,7 +396,7 @@ berkeley_cmp_fix_length_key(DB *file, const DBT *new_key, const DBT *saved_key)
KEY_PART_INFO *key_part= key->key_part, *end=key_part+key->key_parts;
uint key_length=new_key->size;
for ( ; key_part != end && (int) key_length > 0 ; key_part++)
for (; key_part != end && (int) key_length > 0 ; key_part++)
{
int cmp;
if ((cmp=key_part->field->pack_cmp(new_key_ptr,saved_key_ptr,0)))
......@@ -417,7 +417,7 @@ berkeley_key_cmp(TABLE *table, KEY *key_info, const char *key, uint key_length)
KEY_PART_INFO *key_part= key_info->key_part,
*end=key_part+key_info->key_parts;
for ( ; key_part != end && (int) key_length > 0; key_part++)
for (; key_part != end && (int) key_length > 0; key_part++)
{
int cmp;
if (key_part->null_bit)
......@@ -561,7 +561,7 @@ int ha_berkeley::open(const char *name, int mode, uint test_if_locked)
ref_length=0;
KEY_PART_INFO *key_part= table->key_info[primary_key].key_part;
KEY_PART_INFO *end=key_part+table->key_info[primary_key].key_parts;
for ( ; key_part != end ; key_part++)
for (; key_part != end ; key_part++)
ref_length+= key_part->field->max_packed_col_length(key_part->length);
share->fixed_length_primary_key=
(ref_length == table->key_info[primary_key].key_length);
......@@ -701,7 +701,7 @@ void ha_berkeley::unpack_key(char *record, DBT *key, uint index)
*end=key_part+key_info->key_parts;
char *pos=(char*) key->data;
for ( ; key_part != end; key_part++)
for (; key_part != end; key_part++)
{
if (key_part->null_bit)
{
......@@ -747,7 +747,7 @@ DBT *ha_berkeley::create_key(DBT *key, uint keynr, char *buff,
key->data=buff;
key->app_private= key_info;
for ( ; key_part != end && key_length > 0; key_part++)
for (; key_part != end && key_length > 0; key_part++)
{
if (key_part->null_bit)
{
......@@ -925,7 +925,7 @@ int ha_berkeley::key_cmp(uint keynr, const byte * old_row,
KEY_PART_INFO *key_part=table->key_info[keynr].key_part;
KEY_PART_INFO *end=key_part+table->key_info[keynr].key_parts;
for ( ; key_part != end ; key_part++)
for (; key_part != end ; key_part++)
{
if (key_part->null_bit)
{
......@@ -1584,7 +1584,7 @@ DBT *ha_berkeley::get_pos(DBT *to, byte *pos)
KEY_PART_INFO *key_part=table->key_info[primary_key].key_part;
KEY_PART_INFO *end=key_part+table->key_info[primary_key].key_parts;
for ( ; key_part != end ; key_part++)
for (; key_part != end ; key_part++)
pos+=key_part->field->packed_col_length((char*) pos,key_part->length);
to->size= (uint) (pos- (byte*) to->data);
}
......
......@@ -45,6 +45,7 @@ TYPELIB myisam_recover_typelib= {array_elements(myisam_recover_names)-1,"",
*****************************************************************************/
// collect errors printed by mi_check routines
static void mi_check_print_msg(MI_CHECK *param, const char* msg_type,
const char *fmt, va_list args)
{
......@@ -134,7 +135,7 @@ int ha_myisam::net_read_dump(NET* net)
int error = 0;
my_seek(data_fd, 0L, MY_SEEK_SET, MYF(MY_WME));
for(;;)
for (;;)
{
ulong packet_len = my_net_read(net);
if (!packet_len)
......@@ -171,7 +172,7 @@ int ha_myisam::dump(THD* thd, int fd)
int error = 0;
my_seek(data_fd, 0L, MY_SEEK_SET, MYF(MY_WME));
for(; bytes_to_read > 0;)
for (; bytes_to_read > 0;)
{
uint bytes = my_read(data_fd, buf, blocksize, MYF(MY_WME));
if (bytes == MY_FILE_ERROR)
......@@ -494,8 +495,8 @@ int ha_myisam::repair(THD* thd, HA_CHECK_OPT *check_opt)
while ((error=repair(thd,param,0)) && param.retry_repair)
{
param.retry_repair=0;
if ((param.testflag & T_RETRY_WITHOUT_QUICK) &&
(param.testflag & T_QUICK))
if (test_all_bits(param.testflag,
(uint) (T_RETRY_WITHOUT_QUICK | T_QUICK)))
{
param.testflag&= ~T_RETRY_WITHOUT_QUICK;
sql_print_error("Warning: Retrying repair of: '%s' without quick",
......
......@@ -118,7 +118,10 @@ class Item_field :public Item_ident
double val_result();
longlong val_int_result();
String *str_result(String* tmp);
bool send(THD *thd, String *str_arg) { return result_field->send(thd,str_arg); }
bool send(THD *thd, String *str_arg)
{
return result_field->send(thd,str_arg);
}
void make_field(Send_field *field);
bool fix_fields(THD *,struct st_table_list *);
bool save_in_field(Field *field);
......
......@@ -549,7 +549,7 @@ Item_func_nullif::fix_length_and_dec()
}
/*
nullif() returns NULL if arguments are different, else it returns the
nullif () returns NULL if arguments are different, else it returns the
first argument.
Note that we have to evaluate the first argument twice as the compare
may have been done with a different type than return value
......@@ -1296,7 +1296,7 @@ bool Item_func_like::fix_fields(THD *thd,struct st_table_list *tlist)
*last == wild_many)
{
const char* tmp = first + 1;
for ( ; *tmp != wild_many && *tmp != wild_one && *tmp != escape; tmp++) ;
for (; *tmp != wild_many && *tmp != wild_one && *tmp != escape; tmp++) ;
canDoTurboBM = tmp == last;
}
......
......@@ -1502,10 +1502,11 @@ void debug_sync_point(const char* lock_name, uint lock_timeout)
thd->ull=0;
}
/* if the lock has not been aquired by some client, we do not want to
create an entry for it, since we immediately release the lock. In
this case, we will not be waiting, but rather, just waste CPU and
memory on the whole deal
/*
If the lock has not been aquired by some client, we do not want to
create an entry for it, since we immediately release the lock. In
this case, we will not be waiting, but rather, just waste CPU and
memory on the whole deal
*/
if (!(ull= ((ULL*) hash_search(&hash_user_locks,lock_name,
lock_name_len))))
......@@ -1515,8 +1516,10 @@ void debug_sync_point(const char* lock_name, uint lock_timeout)
}
ull->count++;
/* structure is now initialized. Try to get the lock */
/* Set up control struct to allow others to abort locks */
/*
Structure is now initialized. Try to get the lock.
Set up control struct to allow others to abort locks
*/
thd->proc_info="User lock";
thd->mysys_var->current_mutex= &LOCK_user_locks;
thd->mysys_var->current_cond= &ull->cond;
......@@ -1603,8 +1606,10 @@ longlong Item_func_get_lock::val_int()
}
ull->count++;
/* structure is now initialized. Try to get the lock */
/* Set up control struct to allow others to abort locks */
/*
Structure is now initialized. Try to get the lock.
Set up control struct to allow others to abort locks.
*/
thd->proc_info="User lock";
thd->mysys_var->current_mutex= &LOCK_user_locks;
thd->mysys_var->current_cond= &ull->cond;
......@@ -1645,10 +1650,11 @@ longlong Item_func_get_lock::val_int()
/*
** Release a user level lock.
** Returns 1 if lock released
** 0 if lock wasn't held
** NULL if no such lock
Release a user level lock.
Return:
1 if lock released
0 if lock wasn't held
(SQL) NULL if no such lock
*/
longlong Item_func_release_lock::val_int()
......@@ -1717,6 +1723,7 @@ longlong Item_func_benchmark::val_int()
return 0;
}
#define extra_size sizeof(double)
static user_var_entry *get_variable(HASH *hash, LEX_STRING &name,
......@@ -1980,6 +1987,7 @@ void Item_func_get_user_var::print(String *str)
str->append(')');
}
bool Item_func_get_user_var::eq(const Item *item, bool binary_cmp) const
{
/* Assume we don't have rtti */
......@@ -2087,10 +2095,11 @@ bool Item_func_match::fix_fields(THD *thd,struct st_table_list *tlist)
maybe_null=1;
join_key=0;
/* const_item is assumed in quite a bit of places, so it would be difficult
to remove; If it would ever to be removed, this should include
modifications to find_best and auto_close as complement to auto_init code
above.
/*
const_item is assumed in quite a bit of places, so it would be difficult
to remove; If it would ever to be removed, this should include
modifications to find_best and auto_close as complement to auto_init code
above.
*/
if (Item_func::fix_fields(thd,tlist) || !const_item())
{
......@@ -2110,7 +2119,7 @@ bool Item_func_match::fix_fields(THD *thd,struct st_table_list *tlist)
}
/* check that all columns come from the same table */
if (count_bits(used_tables_cache) != 1)
key=NO_SUCH_KEY;
key=NO_SUCH_KEY;
const_item_cache=0;
table=((Item_field *)fields.head())->field->table;
table->fulltext_searched=1;
......@@ -2124,6 +2133,7 @@ bool Item_func_match::fix_fields(THD *thd,struct st_table_list *tlist)
return 0;
}
bool Item_func_match::fix_index()
{
List_iterator_fast<Item> li(fields);
......@@ -2200,16 +2210,15 @@ bool Item_func_match::fix_index()
return 0;
}
my_printf_error(ER_FT_MATCHING_KEY_NOT_FOUND,
ER(ER_FT_MATCHING_KEY_NOT_FOUND),MYF(0));
ER(ER_FT_MATCHING_KEY_NOT_FOUND),MYF(0));
return 1;
}
bool Item_func_match::eq(const Item *item, bool binary_cmp) const
{
if (item->type() != FUNC_ITEM)
return 0;
if (func_name() != ((Item_func*)item)->func_name())
if (item->type() != FUNC_ITEM ||
func_name() != ((Item_func*)item)->func_name())
return 0;
Item_func_match *ifm=(Item_func_match*) item;
......@@ -2221,6 +2230,7 @@ bool Item_func_match::eq(const Item *item, bool binary_cmp) const
return 0;
}
double Item_func_match::val()
{
if (ft_handler == NULL)
......@@ -2230,14 +2240,13 @@ double Item_func_match::val()
{
if (table->file->ft_handler)
return ft_handler->please->get_relevance(ft_handler);
join_key=0;
}
if (key == NO_SUCH_KEY)
{
String *a=concat->val_str(&value);
if ((null_value= (a==0)))
String *a= concat->val_str(&value);
if ((null_value= (a == 0)))
return 0;
return ft_handler->please->find_relevance(ft_handler,
(byte *)a->ptr(), a->length());
......@@ -2246,6 +2255,7 @@ double Item_func_match::val()
return ft_handler->please->find_relevance(ft_handler, record, 0);
}
/***************************************************************************
System variables
This has to be recoded after we get more than 3 system variables
......
......@@ -921,7 +921,8 @@ class Item_func_match :public Item_real_func
Item_func_match(List<Item> &a, Item *b): Item_real_func(b),
fields(a), table(0), master(0), ft_handler(0),
concat(0), key(0), join_key(0) {}
concat(0), key(0), join_key(0)
{}
~Item_func_match()
{
if (!master && ft_handler)
......@@ -932,7 +933,8 @@ class Item_func_match :public Item_real_func
table->file->ft_handler=0;
table->fulltext_searched=0;
}
if (concat) delete concat;
if (concat)
delete concat;
}
enum Functype functype() const { return FT_FUNC; }
void update_used_tables() {}
......@@ -945,19 +947,23 @@ class Item_func_match :public Item_real_func
void init_search(bool no_order);
};
class Item_func_match_nl :public Item_func_match
{
public:
Item_func_match_nl(List<Item> &a, Item *b):
Item_func_match(a,b) { mode=FT_NL; }
Item_func_match_nl(List<Item> &a, Item *b)
:Item_func_match(a,b)
{ mode=FT_NL; }
const char *func_name() const { return "match_nl"; }
};
class Item_func_match_bool :public Item_func_match
{
public:
Item_func_match_bool(List<Item> &a, Item *b):
Item_func_match(a,b) { mode=FT_BOOL; }
Item_func_match_bool(List<Item> &a, Item *b)
:Item_func_match(a,b)
{ mode=FT_BOOL; }
const char *func_name() const { return "match_bool"; }
};
......
......@@ -42,7 +42,7 @@ uint nr_of_decimals(const char *str)
if ((str=strchr(str,'.')))
{
const char *start= ++str;
for ( ; isdigit(*str) ; str++) ;
for (; isdigit(*str) ; str++) ;
return (uint) (str-start);
}
return 0;
......@@ -208,8 +208,7 @@ void Item_func_concat::fix_length_and_dec()
/*
Function des_encrypt() by tonu@spam.ee & monty
Works only if compiled with OpenSSL library support.
This returns a binary string where first character is
CHAR(128 | key-number).
This returns a binary string where first character is CHAR(128 | key-number).
If one uses a string key key_number is 127.
Encryption result is longer than original by formula:
new_length= org_length + (8-(org_length % 8))+1
......@@ -1903,7 +1902,7 @@ String* Item_func_export_set::val_str(String* str)
str->append(*yes);
else
str->append(*no);
if(i != num_set_values - 1)
if (i != num_set_values - 1)
str->append(*sep);
}
return str;
......
......@@ -1102,7 +1102,7 @@ bool Item_sum_count_distinct::add()
*/
if (tree.elements_in_tree > max_elements_in_tree)
{
if(tree_to_myisam())
if (tree_to_myisam())
return 1;
}
else if (!tree_insert(&tree, table->record[0] + rec_offset, 0))
......
......@@ -683,7 +683,7 @@ String *Item_func_date_format::val_str(String *str)
/* Create the result string */
const char *ptr=format->ptr();
const char *end=ptr+format->length();
for ( ; ptr != end ; ptr++)
for (; ptr != end ; ptr++)
{
if (*ptr != '%' || ptr+1 == end)
str->append(*ptr);
......@@ -691,7 +691,7 @@ String *Item_func_date_format::val_str(String *str)
{
switch (*++ptr) {
case 'M':
if(!l_time.month)
if (!l_time.month)
{
null_value=1;
return 0;
......@@ -699,7 +699,7 @@ String *Item_func_date_format::val_str(String *str)
str->append(month_names[l_time.month-1]);
break;
case 'b':
if(!l_time.month)
if (!l_time.month)
{
null_value=1;
return 0;
......@@ -707,7 +707,7 @@ String *Item_func_date_format::val_str(String *str)
str->append(month_names[l_time.month-1].ptr(),3);
break;
case 'W':
if(date_or_time)
if (date_or_time)
{
null_value=1;
return 0;
......@@ -716,7 +716,7 @@ String *Item_func_date_format::val_str(String *str)
str->append(day_names[weekday]);
break;
case 'a':
if(date_or_time)
if (date_or_time)
{
null_value=1;
return 0;
......@@ -725,7 +725,7 @@ String *Item_func_date_format::val_str(String *str)
str->append(day_names[weekday].ptr(),3);
break;
case 'D':
if(date_or_time)
if (date_or_time)
{
null_value=1;
return 0;
......@@ -791,7 +791,7 @@ String *Item_func_date_format::val_str(String *str)
str->append(intbuff);
break;
case 'j':
if(date_or_time)
if (date_or_time)
{
null_value=1;
return 0;
......
......@@ -135,7 +135,7 @@ static int lock_external(TABLE **tables,uint count)
if ((error=(*tables)->file->external_lock(thd,lock_type)))
{
for ( ; i-- ; tables--)
for (; i-- ; tables--)
{
(*tables)->file->external_lock(thd, F_UNLCK);
(*tables)->current_lock=F_UNLCK;
......@@ -473,7 +473,7 @@ void unlock_table_name(THD *thd, TABLE_LIST *table_list)
static bool locked_named_table(THD *thd, TABLE_LIST *table_list)
{
for ( ; table_list ; table_list=table_list->next)
for (; table_list ; table_list=table_list->next)
{
if (table_list->table && table_is_used(table_list->table,0))
return 1;
......
......@@ -384,6 +384,7 @@ int MYSQL_LOG::reset_logs(THD* thd)
int error=0;
const char* save_name;
enum_log_type save_log_type;
pthread_mutex_lock(&LOCK_log);
if (find_first_log(&linfo,""))
{
......@@ -406,6 +407,7 @@ int MYSQL_LOG::reset_logs(THD* thd)
need_start_event=1;
open(save_name,save_log_type,0,io_cache_type,no_auto_events);
my_free((gptr)save_name,MYF(0));
err:
pthread_mutex_unlock(&LOCK_log);
return error;
......@@ -414,17 +416,19 @@ int MYSQL_LOG::reset_logs(THD* thd)
int MYSQL_LOG::purge_first_log(struct st_relay_log_info* rli)
{
// pre-conditions
DBUG_ASSERT(is_open());
DBUG_ASSERT(index_file >= 0);
DBUG_ASSERT(rli->slave_running == 1);
DBUG_ASSERT(!strcmp(rli->linfo.log_file_name,rli->relay_log_name));
/*
Test pre-conditions.
Assume that we have previously read the first log and
stored it in rli->relay_log_name
*/
DBUG_ASSERT(is_open());
DBUG_ASSERT(index_file >= 0);
DBUG_ASSERT(rli->slave_running == 1);
DBUG_ASSERT(!strcmp(rli->linfo.log_file_name,rli->relay_log_name));
DBUG_ASSERT(rli->linfo.index_file_offset ==
strlen(rli->relay_log_name) + 1);
int tmp_fd;
char* fname, *io_buf;
int error = 0;
......@@ -486,9 +490,11 @@ int MYSQL_LOG::purge_first_log(struct st_relay_log_info* rli)
pthread_mutex_lock(&rli->log_space_lock);
rli->log_space_total -= s.st_size;
pthread_mutex_unlock(&rli->log_space_lock);
// ok to broadcast after the critical region as there is no risk of
// the mutex being destroyed by this thread later - this helps save
// context switches
/*
Ok to broadcast after the critical region as there is no risk of
the mutex being destroyed by this thread later - this helps save
context switches
*/
pthread_cond_broadcast(&rli->log_space_cond);
if ((error=find_first_log(&rli->linfo,"",0/*no mutex*/)))
......@@ -500,8 +506,8 @@ int MYSQL_LOG::purge_first_log(struct st_relay_log_info* rli)
goto err2;
}
rli->relay_log_pos = BIN_LOG_HEADER_SIZE;
strnmov(rli->relay_log_name,rli->linfo.log_file_name,
sizeof(rli->relay_log_name));
strmake(rli->relay_log_name,rli->linfo.log_file_name,
sizeof(rli->relay_log_name)-1);
flush_relay_log_info(rli);
}
/*
......@@ -689,7 +695,7 @@ void MYSQL_LOG::new_file(bool inside_mutex)
if (!no_rotate)
{
/*
only rotate open logs that are marked non-rotatable
Only rotate open logs that are marked non-rotatable
(binlog with constant name are non-rotatable)
*/
if (generate_new_name(new_name, name))
......@@ -720,9 +726,11 @@ void MYSQL_LOG::new_file(bool inside_mutex)
r.write(&log_file);
bytes_written += r.get_event_len();
}
// update needs to be signaled even if there is no rotate event
// log rotation should give the waiting thread a signal to
// discover EOF and move on to the next log
/*
Update needs to be signaled even if there is no rotate event
log rotation should give the waiting thread a signal to
discover EOF and move on to the next log.
*/
signal_update();
}
else
......@@ -745,8 +753,10 @@ bool MYSQL_LOG::append(Log_event* ev)
pthread_mutex_lock(&LOCK_log);
DBUG_ASSERT(log_file.type == SEQ_READ_APPEND);
// Log_event::write() is smart enough to use my_b_write() or
// my_b_append() depending on the kind of cache we have
/*
Log_event::write() is smart enough to use my_b_write() or
my_b_append() depending on the kind of cache we have.
*/
if (ev->write(&log_file))
{
error=1;
......@@ -758,11 +768,13 @@ bool MYSQL_LOG::append(Log_event* ev)
new_file(1);
}
signal_update();
err:
pthread_mutex_unlock(&LOCK_log);
return error;
}
bool MYSQL_LOG::appendv(const char* buf, uint len,...)
{
bool error = 0;
......@@ -1232,8 +1244,12 @@ void MYSQL_LOG::close(bool exiting)
}
/* Check if a string is a valid number */
/* Output: TRUE -> number */
/*
Check if a string is a valid number
Return:
TRUE String is a number
FALSE Error
*/
static bool test_if_number(register const char *str,
long *res, bool allow_wildcards)
......
This diff is collapsed.
This diff is collapsed.
......@@ -354,7 +354,7 @@ mc_net_safe_read(MYSQL *mysql)
if (socket_errno != SOCKET_EINTR)
{
mc_end_server(mysql);
if(net->last_errno != ER_NET_PACKET_TOO_LARGE)
if (net->last_errno != ER_NET_PACKET_TOO_LARGE)
{
net->last_errno=CR_SERVER_LOST;
strmov(net->last_error,ER(net->last_errno));
......@@ -375,7 +375,7 @@ max_allowed_packet on this server");
net->last_errno=uint2korr(pos);
pos+=2;
len-=2;
if(!net->last_errno)
if (!net->last_errno)
net->last_errno = CR_UNKNOWN_ERROR;
}
else
......@@ -791,7 +791,7 @@ mc_mysql_connect(MYSQL *mysql,const char *host, const char *user,
else
{
user = getenv("USER");
if(!user) user = "mysql";
if (!user) user = "mysql";
strmov((char*) buff+5, user );
}
......
This diff is collapsed.
This diff is collapsed.
......@@ -87,9 +87,9 @@ void send_warning(NET *net, uint sql_errno, const char *err)
DBUG_VOID_RETURN;
}
/**
** write error package and flush to client
** It's a little too low level, but I don't want to allow another buffer
/*
Write error package and flush to client
It's a little too low level, but I don't want to allow another buffer
*/
/* VARARGS3 */
......@@ -339,9 +339,9 @@ bool net_store_data(String* packet, I_List<i_string>* str_list)
I_List_iterator<i_string> it(*str_list);
i_string* s;
while((s=it++))
while ((s=it++))
{
if(tmp.length())
if (tmp.length())
tmp.append(',');
tmp.append(s->ptr);
}
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment