Rev 3740: Move more compatibility code into python-compat.h in http://bzr.arbash-meinel.com/branches/bzr/1.8-dev/trivial_python_compat

John Arbash Meinel john at arbash-meinel.com
Thu Sep 25 23:22:37 BST 2008


At http://bzr.arbash-meinel.com/branches/bzr/1.8-dev/trivial_python_compat

------------------------------------------------------------
revno: 3740
revision-id: john at arbash-meinel.com-20080925222222-tnqd86ru8jv2q3jy
parent: john at arbash-meinel.com-20080925221207-nkvw06twhw8gfrsc
committer: John Arbash Meinel <john at arbash-meinel.com>
branch nick: trivial_python_compat
timestamp: Thu 2008-09-25 17:22:22 -0500
message:
  Move more compatibility code into python-compat.h
  
  Update the definitions and extension compiling so that the faster iter
  changes now builds on win32.
-------------- next part --------------
=== modified file 'bzrlib/_dirstate_helpers_c.pyx'
--- a/bzrlib/_dirstate_helpers_c.pyx	2008-09-25 02:01:39 +0000
+++ b/bzrlib/_dirstate_helpers_c.pyx	2008-09-25 22:22:22 +0000
@@ -39,9 +39,9 @@
 cdef int ERROR_DIRECTORY
 ERROR_DIRECTORY = 267
 
-#python2.4 support
+#python2.4 support, and other platform-dependent includes
 cdef extern from "python-compat.h":
-    pass
+    unsigned long htonl(unsigned long)
 
 # Give Pyrex some function definitions for it to understand.
 # All of these are just hints to Pyrex, so that it can try to convert python
@@ -57,9 +57,6 @@
     ctypedef int intptr_t
 
 
-cdef extern from "arpa/inet.h":
-    unsigned long htonl(unsigned long)
-
 
 cdef extern from "stdlib.h":
     unsigned long int strtoul(char *nptr, char **endptr, int base)
@@ -68,6 +65,7 @@
 cdef extern from 'sys/stat.h':
     int S_ISDIR(int mode)
     int S_ISREG(int mode)
+    # On win32, this actually comes from "python-compat.h"
     int S_ISLNK(int mode)
     int S_IXUSR
 

=== removed file 'bzrlib/_walkdirs_win32.h'
--- a/bzrlib/_walkdirs_win32.h	2008-07-17 03:46:13 +0000
+++ b/bzrlib/_walkdirs_win32.h	1970-01-01 00:00:00 +0000
@@ -1,25 +0,0 @@
-/*
- * Copyright (C) 2007 Canonical Ltd
- * 
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- * 
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- * 
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
- */
-
-/* Header includes, etc for _walkdirs_win32
- * Pyrex doesn't support #define, and defining WIN32_LEAN_AND_MEAN makes
- * importing windows.h a lot less painful.
- */
-
-#define WIN32_LEAN_AND_MEAN
-#include <windows.h>

=== modified file 'bzrlib/_walkdirs_win32.pyx'
--- a/bzrlib/_walkdirs_win32.pyx	2008-09-23 23:28:27 +0000
+++ b/bzrlib/_walkdirs_win32.pyx	2008-09-25 22:22:22 +0000
@@ -17,7 +17,7 @@
 """Helper functions for Walkdirs on win32."""
 
 
-cdef extern from "_walkdirs_win32.h":
+cdef extern from "python-compat.h":
     struct _HANDLE:
         pass
     ctypedef _HANDLE *HANDLE

=== modified file 'bzrlib/python-compat.h'
--- a/bzrlib/python-compat.h	2008-09-25 22:08:41 +0000
+++ b/bzrlib/python-compat.h	2008-09-25 22:22:22 +0000
@@ -34,4 +34,24 @@
     #define PyInt_AsSsize_t(o) PyInt_AsLong(o)
 #endif
 
+#if defined(_WIN32) || defined(WIN32)
+    /* Needed for htonl */
+    #include "Winsock.h"
+
+    /* Defining WIN32_LEAN_AND_MEAN makes including windows quite a bit
+     * lighter weight.
+     */
+    #define WIN32_LEAN_AND_MEAN
+    #include <windows.h>
+
+    /* sys/stat.h doesn't have S_ISLNK on win32, so we fake it by just always
+     * returning False
+     */
+    #define S_ISLNK(mode) (0)
+#else /* Not win32 */
+    /* For htonl */
+    #include "arpa/inet.h"
 #endif
+
+
+#endif /* _BZR_PYTHON_COMPAT_H */

=== modified file 'setup.py'
--- a/setup.py	2008-09-24 00:09:49 +0000
+++ b/setup.py	2008-09-25 22:22:22 +0000
@@ -226,15 +226,18 @@
 
 
 add_pyrex_extension('bzrlib._btree_serializer_c')
-add_pyrex_extension('bzrlib._dirstate_helpers_c')
 add_pyrex_extension('bzrlib._knit_load_data_c')
 if sys.platform == 'win32':
+    add_pyrex_extension('bzrlib._dirstate_helpers_c',
+                         libraries=['Ws2_32']
+                       )
     # pyrex uses the macro WIN32 to detect the platform, even though it should
     # be using something like _WIN32 or MS_WINDOWS, oh well, we can give it the
     # right value.
     add_pyrex_extension('bzrlib._walkdirs_win32',
                         define_macros=[('WIN32', None)])
 else:
+    add_pyrex_extension('bzrlib._dirstate_helpers_c')
     add_pyrex_extension('bzrlib._readdir_pyx')
 ext_modules.append(Extension('bzrlib._patiencediff_c', ['bzrlib/_patiencediff_c.c']))
 



More information about the bazaar-commits mailing list