diff --git a/sql-bench/crash-me.sh b/sql-bench/crash-me.sh
index 00989fc0bc8791c6e6744a78c167cc5df44d082c..be24e015553c8f120e5f1950be5e9ec68399aa96 100644
--- a/sql-bench/crash-me.sh
+++ b/sql-bench/crash-me.sh
@@ -407,7 +407,7 @@ if ($dbh->do("create table crash_q (a integer, b integer,c1 CHAR(10))") &&
 		 ["with constraint and restrict/cascade",
 		  "alter table crash_q drop constraint u1 restrict"],
 		 ["with drop key",
-		  "alter table crash_q drop key c1"]);
+		  "alter table crash_q drop key u1"]);
   try_and_report("Alter table add primary key",'alter_add_primary_key',
 		 ["with constraint",
 		  "alter table crash_q1 add constraint p1 primary key(c1)"],
diff --git a/sql/mysql_priv.h b/sql/mysql_priv.h
index 499739d8d80c398f7b3b9006eb1ffaac7971f7dd..bd919d12348ad922efb00de36a483ebf1d4579d2 100644
--- a/sql/mysql_priv.h
+++ b/sql/mysql_priv.h
@@ -424,11 +424,6 @@ bool do_command(THD *thd);
 bool dispatch_command(enum enum_server_command command, THD *thd,
 		      char* packet, uint packet_length);
 bool check_dup(const char *db, const char *name, TABLE_LIST *tables);
-#ifndef EMBEDDED_LIBRARY
-bool check_stack_overrun(THD *thd,char *dummy);
-#else
-#define check_stack_overrun(A, B) 0
-#endif
 
 bool table_cache_init(void);
 void table_cache_free(void);
@@ -534,7 +529,6 @@ int mysql_multi_update(THD *thd, TABLE_LIST *table_list,
 int mysql_insert(THD *thd,TABLE_LIST *table,List<Item> &fields,
 		 List<List_item> &values, List<Item> &update_fields,
 		 List<Item> &update_values, enum_duplicates flag);
-void kill_delayed_threads(void);
 int mysql_delete(THD *thd, TABLE_LIST *table, COND *conds, SQL_LIST *order,
                  ha_rows rows, ulong options);
 int mysql_truncate(THD *thd, TABLE_LIST *table_list, bool dont_send_ok=0);
@@ -969,11 +963,6 @@ void make_datetime(DATE_TIME_FORMAT *format, TIME *l_time, String *str);
 
 int test_if_number(char *str,int *res,bool allow_wildcards);
 void change_byte(byte *,uint,char,char);
-#ifndef EMBEDDED_LIBRARY
-extern "C" void unireg_abort(int exit_code);
-#else
-#define unireg_abort(exit_code) DBUG_RETURN(exit_code)
-#endif
 void init_read_record(READ_RECORD *info, THD *thd, TABLE *reg_form,
 		      SQL_SELECT *select,
 		      int use_record_cache, bool print_errors);
@@ -1122,3 +1111,19 @@ inline void setup_table_map(TABLE *table, TABLE_LIST *table_list, uint tablenr)
   table->map= (table_map) 1 << tablenr;
   table->force_index= table_list->force_index;
 }
+
+
+/*
+  Some functions that are different in the embedded library and the normal
+  server
+*/
+
+#ifndef EMBEDDED_LIBRARY
+extern "C" void unireg_abort(int exit_code);
+void kill_delayed_threads(void);
+bool check_stack_overrun(THD *thd,char *dummy);
+#else
+#define unireg_abort(exit_code) DBUG_RETURN(exit_code)
+inline void kill_delayed_threads(void) {}
+#define check_stack_overrun(A, B) 0
+#endif
diff --git a/sql/sql_base.cc b/sql/sql_base.cc
index b4ee3df14e2c4a5414c0022fea2ba25a4f41feba..e8bb3187fb156eb59f6226bd6438b92b39b86dc9 100644
--- a/sql/sql_base.cc
+++ b/sql/sql_base.cc
@@ -284,8 +284,10 @@ bool close_cached_tables(THD *thd, bool if_wait_for_refresh,
     if (!found)
       if_wait_for_refresh=0;			// Nothing to wait for
   }
+#ifndef EMBEDDED_LIBRARY
   if (!tables)
     kill_delayed_threads();
+#endif
   if (if_wait_for_refresh)
   {
     /*
diff --git a/sql/sql_insert.cc b/sql/sql_insert.cc
index f463c6a27ff28c805d382c817d5f3f0ce7f85485..9eddba10db1b98832be7175c33dfe38d132a6376 100644
--- a/sql/sql_insert.cc
+++ b/sql/sql_insert.cc
@@ -112,14 +112,13 @@ int mysql_insert(THD *thd,TABLE_LIST *table_list,
                  List<Item> &update_values,
                  enum_duplicates duplic)
 {
-  int error;
+  int error, res;
   /*
     log_on is about delayed inserts only.
     By default, both logs are enabled (this won't cause problems if the server
     runs without --log-update or --log-bin).
   */
   int log_on= DELAYED_LOG_UPDATE | DELAYED_LOG_BIN ;
-
   bool transactional_table, log_delayed, bulk_insert;
   uint value_count;
   ulong counter = 1;
@@ -143,15 +142,20 @@ int mysql_insert(THD *thd,TABLE_LIST *table_list,
     if we are told to replace duplicates, the insert cannot be concurrent
     delayed insert changed to regular in slave thread
    */
+#ifdef EMBEDDED_LIBRARY
+  if (lock_type == TL_WRITE_DELAYED)
+    lock_type=TL_WRITE;
+#else
   if ((lock_type == TL_WRITE_DELAYED &&
        ((specialflag & (SPECIAL_NO_NEW_FUNC | SPECIAL_SAFE_MODE)) ||
 	thd->slave_thread || !thd->variables.max_insert_delayed_threads)) ||
       (lock_type == TL_WRITE_CONCURRENT_INSERT && duplic == DUP_REPLACE) ||
       (duplic == DUP_UPDATE))
     lock_type=TL_WRITE;
+#endif
   table_list->lock_type= lock_type;
 
-  int res;
+#ifndef EMBEDDED_LIBRARY
   if (lock_type == TL_WRITE_DELAYED)
   {
     if (thd->locked_tables)
@@ -180,6 +184,7 @@ int mysql_insert(THD *thd,TABLE_LIST *table_list,
     }
   }
   else
+#endif /* EMBEDDED_LIBRARY */
     res= open_and_lock_tables(thd, table_list);
   if (res)
     DBUG_RETURN(-1);
@@ -297,12 +302,14 @@ int mysql_insert(THD *thd,TABLE_LIST *table_list,
 	break;
       }
     }
+#ifndef EMBEDDED_LIBRARY
     if (lock_type == TL_WRITE_DELAYED)
     {
       error=write_delayed(thd,table,duplic,query, thd->query_length, log_on);
       query=0;
     }
     else
+#endif
       error=write_record(table,&info);
     if (error)
       break;
@@ -323,6 +330,7 @@ int mysql_insert(THD *thd,TABLE_LIST *table_list,
     Now all rows are inserted.  Time to update logs and sends response to
     user
   */
+#ifndef EMBEDDED_LIBRARY
   if (lock_type == TL_WRITE_DELAYED)
   {
     if (!error)
@@ -334,6 +342,7 @@ int mysql_insert(THD *thd,TABLE_LIST *table_list,
     query_cache_invalidate3(thd, table_list, 1);
   }
   else
+#endif
   {
     if (bulk_insert)
     {
@@ -430,8 +439,10 @@ int mysql_insert(THD *thd,TABLE_LIST *table_list,
   DBUG_RETURN(0);
 
 abort:
+#ifndef EMBEDDED_LIBRARY
   if (lock_type == TL_WRITE_DELAYED)
     end_delayed_insert(thd);
+#endif
   free_underlaid_joins(thd, &thd->lex->select_lex);
   table->insert_values=0;
   DBUG_RETURN(-1);
@@ -603,6 +614,8 @@ static int check_null_fields(THD *thd __attribute__((unused)),
   A thread is created for each table that one uses with the DELAYED attribute.
 *****************************************************************************/
 
+#ifndef EMBEDDED_LIBRARY
+
 class delayed_row :public ilink {
 public:
   char *record,*query;
@@ -1391,8 +1404,7 @@ bool delayed_insert::handle_inserts(void)
   pthread_mutex_lock(&mutex);
   DBUG_RETURN(1);
 }
-
-
+#endif /* EMBEDDED_LIBRARY */
 
 /***************************************************************************
   Store records in INSERT ... SELECT *
@@ -1669,7 +1681,9 @@ void select_create::abort()
 
 #ifdef __GNUC__
 template class List_iterator_fast<List_item>;
+#ifndef EMBEDDED_LIBRARY
 template class I_List<delayed_insert>;
 template class I_List_iterator<delayed_insert>;
 template class I_List<delayed_row>;
-#endif
+#endif /* EMBEDDED_LIBRARY */
+#endif /* __GNUC__ */
diff --git a/sql/sql_string.cc b/sql/sql_string.cc
index e15beac90b08b1b83cccac2ec5552ff93391e8fd..a4eae8a634603f40c86c4082a0a03c749c4f1a90 100644
--- a/sql/sql_string.cc
+++ b/sql/sql_string.cc
@@ -794,10 +794,14 @@ copy_and_convert(char *to, uint32 to_length, CHARSET_INFO *to_cs,
   const uchar *from_end= (const uchar*) from+from_length;
   char *to_start= to;
   uchar *to_end= (uchar*) to+to_length;
+  int (*mb_wc)(struct charset_info_st *, my_wc_t *, const uchar *,
+	       const uchar *) = from_cs->cset->mb_wc;
+  int (*wc_mb)(struct charset_info_st *, my_wc_t, uchar *s, uchar *e)=
+    to_cs->cset->wc_mb;
 
   while (1)
   {
-    if ((cnvres= from_cs->cset->mb_wc(from_cs, &wc, (uchar*) from,
+    if ((cnvres= (*mb_wc)(from_cs, &wc, (uchar*) from,
 				      from_end)) > 0)
       from+= cnvres;
     else if (cnvres == MY_CS_ILSEQ)
@@ -809,7 +813,7 @@ copy_and_convert(char *to, uint32 to_length, CHARSET_INFO *to_cs,
       break;					// Impossible char.
 
 outp:
-    if ((cnvres= to_cs->cset->wc_mb(to_cs, wc, (uchar*) to, to_end)) > 0)
+    if ((cnvres= (*wc_mb)(to_cs, wc, (uchar*) to, to_end)) > 0)
       to+= cnvres;
     else if (cnvres == MY_CS_ILUNI && wc != '?')
     {
@@ -822,6 +826,7 @@ copy_and_convert(char *to, uint32 to_length, CHARSET_INFO *to_cs,
   return (uint32) (to - to_start);
 }
 
+
 void String::print(String *str)
 {
   char *st= (char*)Ptr, *end= st+str_length;