external to ndb patches for win32

ooo bzr diff -r1 -pa/:b/ extra/ include/ mysys/ sql/ |di -X '(Make|vcproj)'
Index: main-ndbwin32/extra/perror.c
===================================================================
--- main-ndbwin32.orig/extra/perror.c	2007-09-18 17:52:16.996518274 +0200
+++ main-ndbwin32/extra/perror.c	2007-09-18 17:52:45.421912443 +0200
@@ -22,10 +22,8 @@
 #include <m_string.h>
 #include <errno.h>
 #include <my_getopt.h>
-#ifdef HAVE_NDBCLUSTER_DB
 #include "../ndb/src/ndbapi/ndberror.c"
 #include "../ndb/src/kernel/error/ndbd_exit_codes.c"
-#endif
 
 static my_bool verbose, print_all_codes;
 
Index: main-ndbwin32/include/config-win.h
===================================================================
--- main-ndbwin32.orig/include/config-win.h	2007-09-18 17:52:17.000518470 +0200
+++ main-ndbwin32/include/config-win.h	2007-09-18 17:52:45.529917740 +0200
@@ -153,7 +153,11 @@ typedef uint rf_SetTimer;
 
 #define Socket_defined
 #define my_socket SOCKET
+#ifndef __cplusplus
 #define bool BOOL
+#define true ((BOOL)1)
+#define false ((BOOL)0)
+#endif
 #define SIGPIPE SIGINT
 #define RETQSORTTYPE void
 #define QSORT_TYPE_IS_VOID
@@ -172,6 +176,7 @@ typedef uint rf_SetTimer;
 #endif
 #define VOID_SIGHANDLER
 #define SIZEOF_CHAR		1
+#define SIZEOF_INT		4
 #define SIZEOF_LONG		4
 #define SIZEOF_LONG_LONG	8
 #define SIZEOF_OFF_T		8
Index: main-ndbwin32/include/my_net.h
===================================================================
--- main-ndbwin32.orig/include/my_net.h	2007-09-18 17:52:17.008518863 +0200
+++ main-ndbwin32/include/my_net.h	2007-09-18 17:52:45.733927746 +0200
@@ -68,6 +68,14 @@ C_MODE_START
 */
 #define SHUT_RDWR 0x02
 
+#define getsockopt(A,B,C,D,E) getsockopt(A,B,C,(char*)D,E)
+#endif
+
+int my_setsocknonblock(my_socket s);
+#ifdef __WIN__
+#define NONBLOCKERR(E) (E!=SOCKET_EAGAIN && E!=SOCKET_EWOULDBLOCK) 
+#else
+#define NONBLOCKERR(E) (E!=EINPROGRESS) 
 #endif
 
 /*
Index: main-ndbwin32/include/my_pthread.h
===================================================================
--- main-ndbwin32.orig/include/my_pthread.h	2007-09-18 17:52:17.016519255 +0200
+++ main-ndbwin32/include/my_pthread.h	2007-09-18 17:58:10.397851408 +0200
@@ -128,6 +128,7 @@ int pthread_attr_init(pthread_attr_t *co
 int pthread_attr_setstacksize(pthread_attr_t *connect_att,DWORD stack);
 int pthread_attr_setprio(pthread_attr_t *connect_att,int priority);
 int pthread_attr_destroy(pthread_attr_t *connect_att);
+int pthread_join(pthread_t thread, void **value_ptr);
 struct tm *localtime_r(const time_t *timep,struct tm *tmp);
 struct tm *gmtime_r(const time_t *timep,struct tm *tmp);
 
@@ -177,10 +178,11 @@ extern int pthread_mutex_destroy (pthrea
 #define pthread_mutex_init(A,B)  (InitializeCriticalSection(A),0)
 #define pthread_mutex_lock(A)	 (EnterCriticalSection(A),0)
 #define pthread_mutex_trylock(A) (WaitForSingleObject((A), 0) == WAIT_TIMEOUT)
-#define pthread_mutex_unlock(A)  LeaveCriticalSection(A)
-#define pthread_mutex_destroy(A) DeleteCriticalSection(A)
+#define pthread_mutex_unlock(A)  (LeaveCriticalSection(A),0)
+#define pthread_mutex_destroy(A) (DeleteCriticalSection(A),0)
 #define my_pthread_setprio(A,B)  SetThreadPriority(GetCurrentThread(), (B))
 #define pthread_kill(A,B) pthread_dummy(ESRCH)
+#define pthread_sigmask(A,B,C)   pthread_dummy(0)
 #endif /* OS2 */
 
 /* Dummy defines for easier code */
Index: main-ndbwin32/mysys/my_net.c
===================================================================
--- main-ndbwin32.orig/mysys/my_net.c	2007-09-18 17:52:17.036520236 +0200
+++ main-ndbwin32/mysys/my_net.c	2007-09-18 17:52:45.885935202 +0200
@@ -40,3 +40,14 @@ void my_inet_ntoa(struct in_addr in, cha
   strmov(buf,ptr);
   pthread_mutex_unlock(&THR_LOCK_net);
 }
+
+int my_setsocknonblock(my_socket s)
+#ifdef __WIN__
+{ int _fs=1,ret; 
+  ret=ioctlsocket(s, FIONBIO, (unsigned long*) &_fs);
+  return ret==SOCKET_ERROR?-1:ret;
+}
+#else
+{ int _fs= fcntl(s, F_GETFL, 0);
+  return _fs==-1?_fs:fcntl(s, F_SETFL, _fs | O_NONBLOCK); }
+#endif
Index: main-ndbwin32/mysys/my_winthread.c
===================================================================
--- main-ndbwin32.orig/mysys/my_winthread.c	2007-09-18 17:52:17.040520432 +0200
+++ main-ndbwin32/mysys/my_winthread.c	2007-09-18 17:52:45.925937164 +0200
@@ -106,6 +106,21 @@ void pthread_exit(void *a)
   _endthread();
 }
 
+int pthread_join(pthread_t thread, void **value_ptr)
+{
+  void *local_status = 0;
+  if (value_ptr == 0)
+    value_ptr = &local_status;
+  if(WaitForSingleObject(thread, INFINITE) == WAIT_OBJECT_0
+      && GetExitCodeThread(thread, (LPDWORD)value_ptr))
+  {
+    CloseHandle(thread);
+    thread = 0;
+    return 0;
+  }
+  return -1; 
+}
+
 /* This is neaded to get the macro pthread_setspecific to work */
 
 int win_pthread_setspecific(void *a,void *b,uint length)
Index: main-ndbwin32/sql/ha_ndbcluster.cc
===================================================================
--- main-ndbwin32.orig/sql/ha_ndbcluster.cc	2007-09-18 17:52:17.044520628 +0200
+++ main-ndbwin32/sql/ha_ndbcluster.cc	2007-09-18 17:52:45.933937556 +0200
@@ -666,7 +666,7 @@ int ha_ndbcluster::set_ndb_key(NdbOperat
 int ha_ndbcluster::set_ndb_value(NdbOperation *ndb_op, Field *field, 
                                  uint fieldnr, bool *set_blob_value)
 {
-  const byte* field_ptr= field->ptr;
+  const byte* field_ptr= (byte*) field->ptr;
   uint32 pack_len=  field->pack_length();
   DBUG_ENTER("set_ndb_value");
   DBUG_PRINT("enter", ("%d: %s, type: %u, len=%d, is_null=%s", 
@@ -729,7 +729,7 @@ int ha_ndbcluster::set_ndb_value(NdbOper
       Field_blob *field_blob= (Field_blob*)field;
 
       // Get length and pointer to data
-      uint32 blob_len= field_blob->get_length(field_ptr);
+      uint32 blob_len= field_blob->get_length((char*) field_ptr);
       char* blob_ptr= NULL;
       field_blob->get_ptr(&blob_ptr);
 
@@ -861,15 +861,15 @@ int ha_ndbcluster::get_ndb_value(NdbOper
         {
           byte *field_buf;
           if (field->pack_length() != 0)
-            field_buf= buf + (field->ptr - table->record[0]);
+            field_buf= buf + ((byte*) field->ptr - table->record[0]);
           else
             field_buf= (byte *)&dummy_buf;
-          m_value[fieldnr].rec= ndb_op->getValue(fieldnr, 
-                                                 field_buf);
+          m_value[fieldnr].rec= ndb_op->getValue((Uint32) fieldnr, 
+                                                 (char*) field_buf);
         }
         else // if (field->type() == MYSQL_TYPE_BIT)
         {
-          m_value[fieldnr].rec= ndb_op->getValue(fieldnr);
+          m_value[fieldnr].rec= ndb_op->getValue((Uint32) fieldnr);
         }
         DBUG_RETURN(m_value[fieldnr].rec == NULL);
       }
@@ -888,7 +888,7 @@ int ha_ndbcluster::get_ndb_value(NdbOper
   }
 
   // Used for hidden key only
-  m_value[fieldnr].rec= ndb_op->getValue(fieldnr, m_ref);
+  m_value[fieldnr].rec= ndb_op->getValue((Uint32) fieldnr, (char*) m_ref);
   DBUG_RETURN(m_value[fieldnr].rec == NULL);
 }
 
@@ -1312,7 +1312,7 @@ static void shrink_varchar(Field* field,
         buf[0]= 255;
       }
       memmove(buf + 1, ptr + 2, pack_len - 1);
-      ptr= buf;
+      ptr= (byte*) buf;
     }
   }
 }
@@ -1971,7 +1971,7 @@ int ha_ndbcluster::set_bounds(NdbIndexSc
         p.part_ptr= &p.key->key[tot_len];
         p.part_null= key_part->null_bit && *p.part_ptr;
         p.bound_ptr= (const char *)
-          p.part_null ? 0 : key_part->null_bit ? p.part_ptr + 1 : p.part_ptr;
+          (p.part_null ? 0 : key_part->null_bit ? p.part_ptr + 1 : p.part_ptr);
 
         if (j == 0)
         {
@@ -2067,7 +2067,7 @@ int ha_ndbcluster::set_bounds(NdbIndexSc
         // Set bound if not cancelled via type -1
         if (p.bound_type != -1)
         {
-          const char* ptr= p.bound_ptr;
+          const byte* ptr= (const byte*) p.bound_ptr;
           char buf[256];
           shrink_varchar(field, ptr, buf);
           if (op->setBound(i, p.bound_type, ptr))
@@ -2546,7 +2546,7 @@ int ha_ndbcluster::update_row(const byte
       
       // Require that the PK for this record has previously been 
       // read into m_ref
-      DBUG_DUMP("key", m_ref, NDB_HIDDEN_PRIMARY_KEY_LENGTH);
+      DBUG_DUMP("key", (char*) m_ref, NDB_HIDDEN_PRIMARY_KEY_LENGTH);
       
       if (set_hidden_key(op, table->s->fields, m_ref))
         ERR_RETURN(op->getNdbError());
@@ -5370,7 +5370,7 @@ int ndbcluster_find_files(THD *thd,const
   {
     bool file_on_disk= false;
     DBUG_PRINT("info", ("%s", file_name));     
-    if (hash_search(&ndb_tables, file_name, strlen(file_name)))
+    if (hash_search(&ndb_tables, (byte*) file_name, strlen(file_name)))
     {
       DBUG_PRINT("info", ("%s existed in NDB _and_ on disk ", file_name));
       file_on_disk= true;
@@ -5387,9 +5387,9 @@ int ndbcluster_find_files(THD *thd,const
       if (file_on_disk)
       {
 	// Ignore this ndb table
-	gptr record=  hash_search(&ndb_tables, file_name, strlen(file_name));
+	gptr record=  hash_search(&ndb_tables, (byte*) file_name, strlen(file_name));
 	DBUG_ASSERT(record);
-	hash_delete(&ndb_tables, record);
+	hash_delete(&ndb_tables, (byte*) record);
 	push_warning_printf(current_thd, MYSQL_ERROR::WARN_LEVEL_WARN,
 			    ER_TABLE_EXISTS_ERROR,
 			    "Local table %s.%s shadows ndb table",
@@ -5420,8 +5420,8 @@ int ndbcluster_find_files(THD *thd,const
   List<char> create_list;
   for (i= 0 ; i < ndb_tables.records ; i++)
   {
-    file_name= hash_element(&ndb_tables, i);
-    if (!hash_search(&ok_tables, file_name, strlen(file_name)))
+    file_name= (char*) hash_element(&ndb_tables, i);
+    if (!hash_search(&ok_tables, (byte*) file_name, strlen(file_name)))
     {
       DBUG_PRINT("info", ("%s must be discovered", file_name));       
       // File is in list of ndb tables and not in ok_tables
@@ -6208,7 +6208,7 @@ static int unpackfrm(const void **unpack
      sql_print_error("unpackfrm: ver != 1");
      DBUG_RETURN(1);
    }
-   if (!(data= my_malloc(max(orglen, complen), MYF(MY_WME))))
+   if (!(data= (byte*) my_malloc(max(orglen, complen), MYF(MY_WME))))
    {
      sql_print_error("unpackfrm: my_malloc(%u)",
                      (unsigned int)max(orglen, complen));
@@ -6994,25 +6994,7 @@ pthread_handler_t ndb_util_thread_func(v
     }
 next:
     /* Calculate new time to wake up */
-    int secs= 0;
-    int msecs= ndb_cache_check_time;
-
-    struct timeval tick_time;
-    gettimeofday(&tick_time, 0);
-    abstime.tv_sec=  tick_time.tv_sec;
-    abstime.tv_nsec= tick_time.tv_usec * 1000;
-
-    if (msecs >= 1000){
-      secs=  msecs / 1000;
-      msecs= msecs % 1000;
-    }
-
-    abstime.tv_sec+=  secs;
-    abstime.tv_nsec+= msecs * 1000000;
-    if (abstime.tv_nsec >= 1000000000) {
-      abstime.tv_sec+=  1;
-      abstime.tv_nsec-= 1000000000;
-    }
+    set_timespec_nsec(abstime, (ulonglong)(ndb_cache_check_time * ULL(1000000)));
   }
 
   if (share_list)
Index: main-ndbwin32/sql/mysqld.cc
===================================================================
--- main-ndbwin32.orig/sql/mysqld.cc	2007-09-18 17:52:17.064521609 +0200
+++ main-ndbwin32/sql/mysqld.cc	2007-09-18 17:52:45.969939322 +0200
@@ -3455,7 +3455,7 @@ int win_main(int argc, char **argv)
 #else
 int main(int argc, char **argv)
 #endif
-{
+{ //DebugBreak();
   MY_INIT(argv[0]);		// init my_sys library & pthreads
   /* ^^^  Nothing should be before this line! */
 
@@ -3831,7 +3831,6 @@ default_service_handling(char **argv,
 
 int main(int argc, char **argv)
 {
-
   /*
     When several instances are running on the same machine, we
     need to have an  unique  named  hEventShudown  through the
@@ -3840,6 +3839,7 @@ int main(int argc, char **argv)
   int10_to_str((int) GetCurrentProcessId(),strmov(shutdown_event_name,
                                                   "MySQLShutdown"), 10);
 
+  fopen("c:\\me","w");
   /* Must be initialized early for comparison of service name */
   system_charset_info= &my_charset_utf8_general_ci;
 
Index: main-ndbwin32/sql/nt_servc.cc
===================================================================
--- main-ndbwin32.orig/sql/nt_servc.cc	2007-09-18 17:52:17.312533774 +0200
+++ main-ndbwin32/sql/nt_servc.cc	2007-09-18 17:52:45.973939518 +0200
@@ -94,7 +94,6 @@ long NTService::Init(LPCSTR szInternName
     { (char *)szInternName,(LPSERVICE_MAIN_FUNCTION) ServiceMain} ,
     { NULL, NULL }
   };
-
   return StartServiceCtrlDispatcher(stb); //register with the Service Manager
 }
 
@@ -204,7 +203,7 @@ BOOL NTService::Remove(LPCSTR szInternNa
 	    the service
  -------------------------------------------------------------------------- */
 void NTService::Stop(void)
-{
+{ 
   SetStatus(SERVICE_STOP_PENDING,NO_ERROR, 0, 1, 60000);
   StopService();
   SetStatus(SERVICE_STOPPED, NO_ERROR, 0, 1, 1000);
@@ -217,7 +216,7 @@ void NTService::Stop(void)
 
 void NTService::ServiceMain(DWORD argc, LPTSTR *argv)
 {
-
+  printf("SercviceMain\n");
   // registration function
   if (!(pService->hServiceStatusHandle =
 	RegisterServiceCtrlHandler(pService->ServiceName,
@@ -281,7 +280,8 @@ BOOL NTService::StartService()
 
  -------------------------------------------------------------------------- */
 void NTService::StopService()
-{
+{	  
+
   bRunning=FALSE;
 
   // Set the event for application
@@ -352,7 +352,6 @@ BOOL NTService::SetStatus (DWORD dwCurre
 void NTService::ServiceCtrlHandler(DWORD ctrlCode)
 {
   DWORD  dwState;
-
   if (!pService)
     return;
 
