[pypy-svn] r64495 - in pypy/release/1.1.x: lib-python lib-python/2.5.2 lib-python/modified-2.5.2 lib-python/modified-2.5.2/test pypy pypy/lang/gameboy/test pypy/lib pypy/lib/app_test pypy/lib/test2 pypy/module/_stackless/test pypy/module/md5/test pypy/module/posix pypy/module/unicodedata pypy/rlib pypy/rlib/test pypy/rpython/module pypy/rpython/module/test pypy/rpython/tool pypy/translator/c/test pypy/translator/platform

iko at codespeak.net iko at codespeak.net
Tue Apr 21 12:04:20 CEST 2009


Author: iko
Date: Tue Apr 21 12:04:19 2009
New Revision: 64495

Modified:
   pypy/release/1.1.x/lib-python/   (props changed)
   pypy/release/1.1.x/lib-python/2.5.2/   (props changed)
   pypy/release/1.1.x/lib-python/conftest.py
   pypy/release/1.1.x/lib-python/modified-2.5.2/   (props changed)
   pypy/release/1.1.x/lib-python/modified-2.5.2/test/test_import.py
   pypy/release/1.1.x/lib-python/modified-2.5.2/test/test_mmap.py
   pypy/release/1.1.x/lib-python/modified-2.5.2/test/test_peepholer.py   (props changed)
   pypy/release/1.1.x/lib-python/modified-2.5.2/test/test_sets.py   (props changed)
   pypy/release/1.1.x/pypy/   (props changed)
   pypy/release/1.1.x/pypy/lang/gameboy/test/test_cpu_register.py   (props changed)
   pypy/release/1.1.x/pypy/lib/_sha256.py
   pypy/release/1.1.x/pypy/lib/_sha512.py
   pypy/release/1.1.x/pypy/lib/app_test/test_hashlib.py
   pypy/release/1.1.x/pypy/lib/test2/test_collections.py   (props changed)
   pypy/release/1.1.x/pypy/module/_stackless/test/test_interp_coroutine.py
   pypy/release/1.1.x/pypy/module/_stackless/test/test_pickle_infrastructure.py   (props changed)
   pypy/release/1.1.x/pypy/module/md5/test/test_md5.py
   pypy/release/1.1.x/pypy/module/posix/interp_posix.py
   pypy/release/1.1.x/pypy/module/unicodedata/triegenerator.py   (props changed)
   pypy/release/1.1.x/pypy/rlib/_rsocket_rffi.py
   pypy/release/1.1.x/pypy/rlib/rcoroutine.py
   pypy/release/1.1.x/pypy/rlib/rsocket.py
   pypy/release/1.1.x/pypy/rlib/rwin32.py
   pypy/release/1.1.x/pypy/rlib/streamio.py
   pypy/release/1.1.x/pypy/rlib/test/test_rsocket.py
   pypy/release/1.1.x/pypy/rpython/module/ll_os.py
   pypy/release/1.1.x/pypy/rpython/module/ll_os_stat.py
   pypy/release/1.1.x/pypy/rpython/module/test/test_ll_os.py
   pypy/release/1.1.x/pypy/rpython/tool/rffi_platform.py
   pypy/release/1.1.x/pypy/translator/c/test/test_extfunc.py
   pypy/release/1.1.x/pypy/translator/platform/darwin.py
Log:
(iko, pedronis) Merge changes from trunk

------------------------------------------------------------------------
r64410 | iko | 2009-04-19 19:39:45 +0200 (Sun, 19 Apr 2009) | 3 lines
Changed paths:
   M /pypy/trunk/pypy/rlib/streamio.py

truncate() needs to raise IOError on failure

------------------------------------------------------------------------
r64415 | iko | 2009-04-19 22:16:57 +0200 (Sun, 19 Apr 2009) | 3 lines
Changed paths:
   M /pypy/trunk/pypy/rlib/streamio.py

IOError is spelled OSError here

------------------------------------------------------------------------
r64416 | iko | 2009-04-19 22:41:04 +0200 (Sun, 19 Apr 2009) | 3 lines
Changed paths:
   M /pypy/trunk/lib-python/conftest.py

Change timeout to 1000s (test_hashlib takes ~350s on bigboard buildbot)

------------------------------------------------------------------------
r64419 | pedronis | 2009-04-19 23:35:23 +0200 (Sun, 19 Apr 2009) | 3 lines
Changed paths:
   M /pypy/trunk/pypy/doc/download.txt

fix spurious or (for the final)

------------------------------------------------------------------------
r64427 | iko | 2009-04-20 00:44:58 +0200 (Mon, 20 Apr 2009) | 3 lines
Changed paths:
   M /pypy/trunk/pypy/rlib/_rsocket_rffi.py
   M /pypy/trunk/pypy/rlib/rsocket.py

Fix win32 nonblocking connect

------------------------------------------------------------------------
r64434 | arigo | 2009-04-20 11:30:16 +0200 (Mon, 20 Apr 2009) | 2 lines
Changed paths:
   M /pypy/trunk/pypy/module/md5/test/test_md5.py

Missing import.
------------------------------------------------------------------------
r64458 | iko | 2009-04-20 16:21:50 +0200 (Mon, 20 Apr 2009) | 3 lines
Changed paths:
   M /pypy/trunk/pypy/module/_stackless/test/test_interp_coroutine.py
   M /pypy/trunk/pypy/rlib/rcoroutine.py

(iko, pedronis, arigo): Fix hanging stackless test

------------------------------------------------------------------------
r64459 | arigo | 2009-04-20 16:46:52 +0200 (Mon, 20 Apr 2009) | 3 lines
Changed paths:
   M /pypy/trunk/lib-python/modified-2.5.2/test/test_import.py

on PyPy, we don't support .PY and other case-mismatching
extensions, even on Windows

------------------------------------------------------------------------
r64460 | arigo | 2009-04-20 16:49:38 +0200 (Mon, 20 Apr 2009) | 2 lines
Changed paths:
   M /pypy/trunk/lib-python/modified-2.5.2/test/test_import.py

Add a comment.

------------------------------------------------------------------------
r64463 | pedronis | 2009-04-20 17:18:08 +0200 (Mon, 20 Apr 2009) | 3 lines
Changed paths:
   M /pypy/trunk/pypy/translator/platform/darwin.py

try to be more consistent between standalone and so builds on darwin

------------------------------------------------------------------------
r64464 | arigo | 2009-04-20 17:18:30 +0200 (Mon, 20 Apr 2009) | 2 lines
Changed paths:
   M /pypy/trunk/pypy/lib/_sha256.py
   M /pypy/trunk/pypy/lib/_sha512.py
   M /pypy/trunk/pypy/lib/app_test/test_hashlib.py

Implement and test copy() for sha256 etc. written in pure Python.

------------------------------------------------------------------------
r64470 | cfbolz | 2009-04-20 18:44:37 +0200 (Mon, 20 Apr 2009) | 2 lines
Changed paths:
   M /pypy/trunk/pypy/rlib/rcoroutine.py

nice comment that explains the strange code

------------------------------------------------------------------------
r64475 | iko | 2009-04-20 19:33:34 +0200 (Mon, 20 Apr 2009) | 4 lines
Changed paths:
   M /pypy/trunk/pypy/rlib/rsocket.py
   M /pypy/trunk/pypy/rlib/test/test_rsocket.py

- windows variant of socket.connect() 
- fix gethostbyaddr test for windows (127.0.0.1 is not known as localhost)

------------------------------------------------------------------------
r64476 | iko | 2009-04-20 19:47:29 +0200 (Mon, 20 Apr 2009) | 3 lines
Changed paths:
   M /pypy/trunk/lib-python/modified-2.5.2/test/test_mmap.py

Fix test_mmap not closing files

------------------------------------------------------------------------
r64479 | tismer | 2009-04-20 20:37:32 +0200 (Mon, 20 Apr 2009) | 1 line
Changed paths:
   M /pypy/trunk/pypy/rpython/module/ll_os.py
   M /pypy/trunk/pypy/rpython/tool/rffi_platform.py
   M /pypy/trunk/pypy/translator/c/test/test_extfunc.py

generalized implementation of os.setpgrp and os.getpgrp. The latter is not really tested, because on OSX getpgrp seems to take no argument. It is probably not worse than before now
------------------------------------------------------------------------
r64482 | afa | 2009-04-21 03:30:53 +0200 (Tue, 21 Apr 2009) | 3 lines
Changed paths:
   M /pypy/trunk/pypy/module/posix/interp_posix.py
   M /pypy/trunk/pypy/rlib/rwin32.py
   M /pypy/trunk/pypy/rpython/module/ll_os.py
   M /pypy/trunk/pypy/rpython/module/ll_os_stat.py
   M /pypy/trunk/pypy/rpython/module/test/test_ll_os.py

On Windows, os.utime now calls the win32 API function SetFileTime.
This should fix the failure in test_os

------------------------------------------------------------------------
r64483 | afa | 2009-04-21 03:53:09 +0200 (Tue, 21 Apr 2009) | 2 lines
Changed paths:
   M /pypy/trunk/pypy/rpython/module/ll_os.py

translation fix




Modified: pypy/release/1.1.x/lib-python/conftest.py
==============================================================================
--- pypy/release/1.1.x/lib-python/conftest.py	(original)
+++ pypy/release/1.1.x/lib-python/conftest.py	Tue Apr 21 12:04:19 2009
@@ -31,7 +31,7 @@
     def pytest_addoption(self, parser):
         group = parser.addgroup("complicance testing options") 
         group.addoption('-T', '--timeout', action="store", type="string", 
-           default="100mp", dest="timeout", 
+           default="1000", dest="timeout", 
            help="fail a test module after the given timeout. "
                 "specify in seconds or 'NUMmp' aka Mega-Pystones")
         group.addoption('--pypy', action="store", type="string",

Modified: pypy/release/1.1.x/lib-python/modified-2.5.2/test/test_import.py
==============================================================================
--- pypy/release/1.1.x/lib-python/modified-2.5.2/test/test_import.py	(original)
+++ pypy/release/1.1.x/lib-python/modified-2.5.2/test/test_import.py	Tue Apr 21 12:04:19 2009
@@ -74,9 +74,11 @@
 sys.path.insert(0, os.curdir)
 try:
     test_with_extension(os.extsep + "py")
-    if sys.platform.startswith("win"):
-        for ext in ".PY", ".Py", ".pY", ".pyw", ".PYW", ".pYw":
-            test_with_extension(ext)
+    #--- on PyPy, we don't support .PY and other case-mismatching
+    #--- extensions, even on Windows
+    #if sys.platform.startswith("win"):
+    #    for ext in ".PY", ".Py", ".pY", ".pyw", ".PYW", ".pYw":
+    #        test_with_extension(ext)
 finally:
     del sys.path[0]
 
@@ -101,6 +103,9 @@
     f = open(filename, 'r')
     py_compile.compile(filename)
     f.close()
+    #--- the following line is to check that the "exec" a few lines below
+    #--- manages to import the .pyc file alone.  We don't support it in
+    #--- PyPy in the default configuration.
     #os.unlink(filename)
 
     # need to be able to load from current dir

Modified: pypy/release/1.1.x/lib-python/modified-2.5.2/test/test_mmap.py
==============================================================================
--- pypy/release/1.1.x/lib-python/modified-2.5.2/test/test_mmap.py	(original)
+++ pypy/release/1.1.x/lib-python/modified-2.5.2/test/test_mmap.py	Tue Apr 21 12:04:19 2009
@@ -195,9 +195,13 @@
             pass
         else:
             verify(0, "Able to resize readonly memory map")
-        del m, f
-        verify(open(TESTFN, "rb").read() == 'a'*mapsize,
+        m.close()
+        f.close()
+
+        f = open(TESTFN, "rb")
+        verify(f.read() == 'a'*mapsize,
                "Readonly memory map data file was modified")
+        f.close()
 
         print "  Opening mmap with size too big"
         import sys
@@ -247,8 +251,10 @@
         verify(m[:] == 'd' * mapsize,
                "Copy-on-write memory map data not written correctly.")
         m.flush()
-        verify(open(TESTFN, "rb").read() == 'c'*mapsize,
+        f2 = open(TESTFN, "rb")
+        verify(f2.read() == 'c'*mapsize,
                "Copy-on-write test data file should not be modified.")
+        f2.close()
         try:
             print "  Ensuring copy-on-write maps cannot be resized."
             m.resize(2*mapsize)
@@ -256,7 +262,9 @@
             pass
         else:
             verify(0, "Copy-on-write mmap resize did not raise exception.")
-        del m, f
+        m.close()
+        f.close()
+
         try:
             print "  Ensuring invalid access parameter raises exception."
             f = open(TESTFN, "r+b")
@@ -265,6 +273,8 @@
             pass
         else:
             verify(0, "Invalid access code should have raised exception.")
+            m.close()
+        f.close()
 
         if os.name == "posix":
             # Try incompatible flags, prot and access parameters.
@@ -276,12 +286,13 @@
                 pass
             else:
                 verify(0, "Incompatible parameters should raise ValueError.")
+                m.close()
             f.close()
     finally:
         try:
             os.unlink(TESTFN)
         except OSError:
-            pass
+            print 'Could not unlink', TESTFN
 
     print '  Try opening a bad file descriptor...'
     try:

Modified: pypy/release/1.1.x/pypy/lib/_sha256.py
==============================================================================
--- pypy/release/1.1.x/pypy/lib/_sha256.py	(original)
+++ pypy/release/1.1.x/pypy/lib/_sha256.py	Tue Apr 21 12:04:19 2009
@@ -204,7 +204,7 @@
         dig.extend([ ((i>>24) & 0xff), ((i>>16) & 0xff), ((i>>8) & 0xff), (i & 0xff) ])
     return ''.join([chr(i) for i in dig])
 
-class sha256:
+class sha256(object):
     digest_size = digestsize = 32
 
     def __init__(self, s=None):
@@ -221,6 +221,11 @@
     def hexdigest(self):
         return ''.join(['%.2x' % ord(i) for i in self.digest()])
 
+    def copy(self):
+        new = sha256.__new__(sha256)
+        new._sha = self._sha.copy()
+        return new
+
 class sha224(sha256):
     digest_size = digestsize = 28
 
@@ -229,6 +234,11 @@
         if s:
             sha_update(self._sha, s)
 
+    def copy(self):
+        new = sha224.__new__(sha224)
+        new._sha = self._sha.copy()
+        return new
+
 def test():
     a_str = "just a test string"
     

Modified: pypy/release/1.1.x/pypy/lib/_sha512.py
==============================================================================
--- pypy/release/1.1.x/pypy/lib/_sha512.py	(original)
+++ pypy/release/1.1.x/pypy/lib/_sha512.py	Tue Apr 21 12:04:19 2009
@@ -234,7 +234,7 @@
         dig.extend([ ((i>>56) & 0xff), ((i>>48) & 0xff), ((i>>40) & 0xff), ((i>>32) & 0xff), ((i>>24) & 0xff), ((i>>16) & 0xff), ((i>>8) & 0xff), (i & 0xff) ])
     return ''.join([chr(i) for i in dig])
 
-class sha512:
+class sha512(object):
     digest_size = digestsize = 64
 
     def __init__(self, s=None):
@@ -251,6 +251,11 @@
     def hexdigest(self):
         return ''.join(['%.2x' % ord(i) for i in self.digest()])
 
+    def copy(self):
+        new = sha512.__new__(sha512)
+        new._sha = self._sha.copy()
+        return new
+
 class sha384(sha512):
     digest_size = digestsize = 48
 
@@ -259,6 +264,11 @@
         if s:
             sha_update(self._sha, s)
 
+    def copy(self):
+        new = sha384.__new__(sha384)
+        new._sha = self._sha.copy()
+        return new
+
 def test():
     a_str = "just a test string"
     

Modified: pypy/release/1.1.x/pypy/lib/app_test/test_hashlib.py
==============================================================================
--- pypy/release/1.1.x/pypy/lib/app_test/test_hashlib.py	(original)
+++ pypy/release/1.1.x/pypy/lib/app_test/test_hashlib.py	Tue Apr 21 12:04:19 2009
@@ -14,8 +14,28 @@
         h = hashlib.new(name)
         assert h.digest_size == expected_size
         assert h.digestsize == expected_size
+        #
+        h.update('abc')
+        h2 = h.copy()
+        h.update('def')
+        digest = h.digest()
+        hexdigest = h.hexdigest()
+        h2.update('d')
+        h2.update('ef')
+        assert digest == h.digest()
+        assert hexdigest == h.hexdigest()
 
         # also test the pure Python implementation
         h = hashlib.__get_builtin_constructor(name)('')
         assert h.digest_size == expected_size
         assert h.digestsize == expected_size
+        #
+        h.update('abc')
+        h2 = h.copy()
+        h.update('def')
+        digest = h.digest()
+        hexdigest = h.hexdigest()
+        h2.update('d')
+        h2.update('ef')
+        assert digest == h.digest()
+        assert hexdigest == h.hexdigest()

Modified: pypy/release/1.1.x/pypy/module/_stackless/test/test_interp_coroutine.py
==============================================================================
--- pypy/release/1.1.x/pypy/module/_stackless/test/test_interp_coroutine.py	(original)
+++ pypy/release/1.1.x/pypy/module/_stackless/test/test_interp_coroutine.py	Tue Apr 21 12:04:19 2009
@@ -299,6 +299,7 @@
         costate.hello_goodbye = 0
 
         def ep():
+            syncstate.default_costate = costate
             costate.hello_goodbye = 0
             c1 = C(4)
             c1.bind(T())

Modified: pypy/release/1.1.x/pypy/module/md5/test/test_md5.py
==============================================================================
--- pypy/release/1.1.x/pypy/module/md5/test/test_md5.py	(original)
+++ pypy/release/1.1.x/pypy/module/md5/test/test_md5.py	Tue Apr 21 12:04:19 2009
@@ -24,6 +24,7 @@
         """
         md5.digest_size should be 16.
         """
+        import sys
         assert self.md5.digest_size == 16
         #assert self.md5.digestsize == 16        -- not on CPython
         assert self.md5.md5().digest_size == 16

Modified: pypy/release/1.1.x/pypy/module/posix/interp_posix.py
==============================================================================
--- pypy/release/1.1.x/pypy/module/posix/interp_posix.py	(original)
+++ pypy/release/1.1.x/pypy/module/posix/interp_posix.py	Tue Apr 21 12:04:19 2009
@@ -544,12 +544,6 @@
 Set the access and modified time of the file to the given values.  If the
 second form is used, set the access and modified times to the current time.
     """
-    # XXX for now, ignore calls on directories on Windows,
-    # just because they always give EACCES so far
-    if _WIN:
-        if os.path.isdir(path):
-            return
-
     if space.is_w(w_tuple, space.w_None):
         try:
             os.utime(path, None)

Modified: pypy/release/1.1.x/pypy/rlib/_rsocket_rffi.py
==============================================================================
--- pypy/release/1.1.x/pypy/rlib/_rsocket_rffi.py	(original)
+++ pypy/release/1.1.x/pypy/rlib/_rsocket_rffi.py	Tue Apr 21 12:04:19 2009
@@ -117,6 +117,8 @@
     WSAEWOULDBLOCK = platform.DefinedConstantInteger('WSAEWOULDBLOCK')
     EAFNOSUPPORT = platform.DefinedConstantInteger('EAFNOSUPPORT')
     WSAEAFNOSUPPORT = platform.DefinedConstantInteger('WSAEAFNOSUPPORT')
+    EISCONN = platform.DefinedConstantInteger('EISCONN')
+    WSAEISCONN = platform.DefinedConstantInteger('WSAEISCONN')
 constant_names = '''
 AF_AAL5 AF_APPLETALK AF_ASH AF_ATMPVC AF_ATMSVC AF_AX25 AF_BLUETOOTH AF_BRIDGE
 AD_DECnet AF_ECONET AF_INET AF_INET6 AF_IPX AF_IRDA AF_KEY AF_LLC AF_NETBEUI
@@ -372,6 +374,7 @@
 EINPROGRESS = cConfig.EINPROGRESS or cConfig.WSAEINPROGRESS
 EWOULDBLOCK = cConfig.EWOULDBLOCK or cConfig.WSAEWOULDBLOCK
 EAFNOSUPPORT = cConfig.EAFNOSUPPORT or cConfig.WSAEAFNOSUPPORT
+EISCONN = cConfig.EISCONN or cConfig.WSAEISCONN
 
 linux = cConfig.linux
 WIN32 = cConfig.WIN32

Modified: pypy/release/1.1.x/pypy/rlib/rcoroutine.py
==============================================================================
--- pypy/release/1.1.x/pypy/rlib/rcoroutine.py	(original)
+++ pypy/release/1.1.x/pypy/rlib/rcoroutine.py	Tue Apr 21 12:04:19 2009
@@ -134,6 +134,10 @@
         else:
             self.things_to_do = False
 
+    def _freeze_(self):
+        self.reset()
+        return False
+
 syncstate = SyncState()
 
 
@@ -281,6 +285,8 @@
             pass # maybe print a warning?
         self.kill()
 
+    __already_postponed = False
+    
     def __del__(self):
         # provide the necessary clean-up
         # note that AppCoroutine has to take care about this
@@ -292,6 +298,15 @@
         # it is necessary to check whether syncstate is None because CPython
         # sets it to None when it cleans up the modules, which will lead to
         # very strange effects
+
+        if not we_are_translated():
+            # we need to make sure that we postpone each coroutine only once on
+            # top of CPython, because this resurrects the coroutine and CPython
+            # calls __del__ again, thus postponing and resurrecting the
+            # coroutine once more :-(
+            if self.__already_postponed:
+                return
+            self.__already_postponed = True
         if syncstate is not None:
             syncstate.postpone_deletion(self)
 

Modified: pypy/release/1.1.x/pypy/rlib/rsocket.py
==============================================================================
--- pypy/release/1.1.x/pypy/rlib/rsocket.py	(original)
+++ pypy/release/1.1.x/pypy/rlib/rsocket.py	Tue Apr 21 12:04:19 2009
@@ -663,49 +663,92 @@
             if res != 0:
                 raise self.error_handler()
 
-    def connect(self, address):
-        """Connect the socket to a remote address."""
-        addr = address.lock()
-        res = _c.socketconnect(self.fd, addr, address.addrlen)
-        address.unlock()
-        if self.timeout > 0.0:
+    if _c.WIN32:
+        def _connect(self, address):
+            """Connect the socket to a remote address."""
+            addr = address.lock()
+            res = _c.socketconnect(self.fd, addr, address.addrlen)
+            address.unlock()
             errno = _c.geterrno()
-            if res < 0 and errno == _c.EINPROGRESS:
+            timeout = self.timeout
+            if timeout > 0.0 and res < 0 and errno == _c.EWOULDBLOCK:
+                tv = rffi.make(_c.timeval)
+                rffi.setintfield(tv, 'c_tv_sec', int(timeout))
+                rffi.setintfield(tv, 'c_tv_usec',
+                                 int((timeout-int(timeout)) * 1000000))
+                fds = lltype.malloc(_c.fd_set.TO, flavor='raw')
+                _c.FD_ZERO(fds)
+                _c.FD_SET(self.fd, fds)
+                fds_exc = lltype.malloc(_c.fd_set.TO, flavor='raw')
+                _c.FD_ZERO(fds_exc)
+                _c.FD_SET(self.fd, fds_exc)
+                null = lltype.nullptr(_c.fd_set.TO)
+
+                try:
+                    n = _c.select(self.fd + 1, null, fds, fds_exc, tv)
+
+                    if n > 0:
+                        if _c.FD_ISSET(self.fd, fds):
+                            # socket writable == connected
+                            return (0, False)
+                        else:
+                            # per MS docs, call getsockopt() to get error
+                            assert _c.FD_ISSET(self.fd, fds_exc)
+                            return (self.getsockopt_int(_c.SOL_SOCKET,
+                                                        _c.SO_ERROR), False)
+                    elif n == 0:
+                        return (_c.EWOULDBLOCK, True)
+                    else:
+                        return (_c.geterrno(), False)
+
+                finally:
+                    lltype.free(fds, flavor='raw')
+                    lltype.free(fds_exc, flavor='raw')
+                    lltype.free(tv, flavor='raw')
+
+            if res == 0:
+                errno = 0
+            return (errno, False)
+    else:
+        def _connect(self, address):
+            """Connect the socket to a remote address."""
+            addr = address.lock()
+            res = _c.socketconnect(self.fd, addr, address.addrlen)
+            address.unlock()
+            errno = _c.geterrno()
+            if self.timeout > 0.0 and res < 0 and errno == _c.EINPROGRESS:
                 timeout = self._select(True)
+                errno = _c.geterrno()
                 if timeout == 0:
                     addr = address.lock()
                     res = _c.socketconnect(self.fd, addr, address.addrlen)
                     address.unlock()
+                    if res < 0:
+                        errno = _c.geterrno()
+                        if errno == _c.EISCONN:
+                            res = 0
                 elif timeout == -1:
-                    raise self.error_handler()
+                    return (errno, False)
                 else:
-                    raise SocketTimeout
-                
-        if res != 0:
-            raise self.error_handler()
+                    return (_c.EWOULDBLOCK, True)
 
+            if res == 0:
+                errno = 0
+            return (errno, False)
+        
+    def connect(self, address):
+        """Connect the socket to a remote address."""
+        err, timeout = self._connect(address)
+        if timeout:
+            raise SocketTimeout
+        if err:
+            raise CSocketError(err)
+        
     def connect_ex(self, address):
         """This is like connect(address), but returns an error code (the errno
         value) instead of raising an exception when an error occurs."""
-        addr = address.lock()
-        res = _c.socketconnect(self.fd, addr, address.addrlen)
-        address.unlock()
-        if self.timeout > 0.0:
-            errno = _c.geterrno()
-            if res < 0 and errno == _c.EINPROGRESS:
-                timeout = self._select(True)
-                if timeout == 0:
-                    addr = address.lock()
-                    res = _c.socketconnect(self.fd, addr, address.addrlen)
-                    address.unlock()
-                elif timeout == -1:
-                    return _c.geterrno()
-                else:
-                    return _c.EWOULDBLOCK
-                
-        if res != 0:
-            return _c.geterrno()
-        return res
+        err, timeout = self._connect(address)
+        return err
 
     if hasattr(_c, 'dup'):
         def dup(self, SocketClass=None):

Modified: pypy/release/1.1.x/pypy/rlib/rwin32.py
==============================================================================
--- pypy/release/1.1.x/pypy/rlib/rwin32.py	(original)
+++ pypy/release/1.1.x/pypy/rlib/rwin32.py	Tue Apr 21 12:04:19 2009
@@ -42,6 +42,8 @@
         FILETIME = rffi_platform.Struct('FILETIME',
                                         [('dwLowDateTime', rffi.UINT),
                                          ('dwHighDateTime', rffi.UINT)])
+        SYSTEMTIME = rffi_platform.Struct('SYSTEMTIME',
+                                          [])
 
         LPSECURITY_ATTRIBUTES = rffi_platform.SimpleType(
             "LPSECURITY_ATTRIBUTES", rffi.CCHARP)
@@ -76,6 +78,7 @@
     FreeLibrary = winexternal('FreeLibrary', [rffi.VOIDP], BOOL)
 
     LocalFree = winexternal('LocalFree', [HLOCAL], DWORD)
+    CloseHandle = winexternal('CloseHandle', [HANDLE], lltype.Void)
 
     FormatMessage = winexternal(
         'FormatMessageA',

Modified: pypy/release/1.1.x/pypy/rlib/streamio.py
==============================================================================
--- pypy/release/1.1.x/pypy/rlib/streamio.py	(original)
+++ pypy/release/1.1.x/pypy/rlib/streamio.py	Tue Apr 21 12:04:19 2009
@@ -161,6 +161,7 @@
     from pypy.rlib import rwin32
     from pypy.translator.tool.cbuild import ExternalCompilationInfo
     from pypy.rpython.lltypesystem import rffi
+    import errno
 
     _eci = ExternalCompilationInfo()
     _get_osfhandle = rffi.llexternal('_get_osfhandle', [rffi.INT], rffi.LONG,
@@ -175,9 +176,10 @@
             # Truncate.  Note that this may grow the file!
             handle = _get_osfhandle(fd)
             if handle == -1:
-                raise StreamError("Invalid file handle")
+                raise OSError(errno.EBADF, "Invalid file handle")
             if not SetEndOfFile(handle):
-                raise StreamError("Could not truncate file")
+                raise WindowsError(rwin32.GetLastError(),
+                                   "Could not truncate file")
         finally:
             os.lseek(fd, curpos, 0)
 

Modified: pypy/release/1.1.x/pypy/rlib/test/test_rsocket.py
==============================================================================
--- pypy/release/1.1.x/pypy/rlib/test/test_rsocket.py	(original)
+++ pypy/release/1.1.x/pypy/rlib/test/test_rsocket.py	Tue Apr 21 12:04:19 2009
@@ -69,7 +69,8 @@
     allnames = [name] + aliases
     for n in allnames:
         assert isinstance(n, str)
-    assert 'localhost' in allnames
+    if sys.platform != 'win32':
+        assert 'localhost' in allnames
     for a in address_list:
         if isinstance(a, INETAddress) and a.get_host() == "127.0.0.1":
             break  # ok

Modified: pypy/release/1.1.x/pypy/rpython/module/ll_os.py
==============================================================================
--- pypy/release/1.1.x/pypy/rpython/module/ll_os.py	(original)
+++ pypy/release/1.1.x/pypy/rpython/module/ll_os.py	Tue Apr 21 12:04:19 2009
@@ -31,12 +31,17 @@
 posix = __import__(os.name)
 
 if sys.platform.startswith('win'):
+    _WIN32 = True
+else:
+    _WIN32 = False
+
+if _WIN32:
     underscore_on_windows = '_'
 else:
     underscore_on_windows = ''
 
 includes = []
-if not sys.platform.startswith('win'):
+if not _WIN32:
     # XXX many of these includes are not portable at all
     includes += ['dirent.h', 'sys/stat.h',
                  'sys/times.h', 'utime.h', 'sys/types.h', 'unistd.h',
@@ -60,7 +65,7 @@
     _compilation_info_ = ExternalCompilationInfo(
         includes=includes
     )
-    if not sys.platform.startswith('win'):
+    if not _WIN32:
         CLOCK_T = platform.SimpleType('clock_t', rffi.INT)
 
         TMS = platform.Struct(
@@ -83,6 +88,11 @@
     def __init__(self):
         self.configure(CConfig)
 
+        if hasattr(os, 'getpgrp'):
+            self.GETPGRP_HAVE_ARG = platform.checkcompiles("getpgrp(0)", "#include <unistd.h>")
+        if hasattr(os, 'setpgrp'):
+            self.SETPGRP_HAVE_ARG = platform.checkcompiles("setpgrp(0,0)", "#include <unistd.h>")
+
         # we need an indirection via c functions to get macro calls working on llvm XXX still?
         if hasattr(os, 'WCOREDUMP'):
             decl_snippet = """
@@ -315,18 +325,96 @@
                 lltype.free(l_utimbuf, flavor='raw')
                 return error
 
-        def os_utime_llimpl(path, tp):
-            # NB. this function is specialized; we get one version where
-            # tp is known to be None, and one version where it is known
-            # to be a tuple of 2 floats.
-            if tp is None:
-                error = os_utime(path, lltype.nullptr(UTIMBUFP.TO))
-            else:
-                actime, modtime = tp
-                error = os_utime_platform(path, actime, modtime)
-            error = rffi.cast(lltype.Signed, error)
-            if error == -1:
-                raise OSError(rposix.get_errno(), "os_utime failed")
+        # NB. this function is specialized; we get one version where
+        # tp is known to be None, and one version where it is known
+        # to be a tuple of 2 floats.
+        if not _WIN32:
+            def os_utime_llimpl(path, tp):
+                if tp is None:
+                    error = os_utime(path, lltype.nullptr(UTIMBUFP.TO))
+                else:
+                    actime, modtime = tp
+                    error = os_utime_platform(path, actime, modtime)
+                    error = rffi.cast(lltype.Signed, error)
+                if error == -1:
+                    raise OSError(rposix.get_errno(), "os_utime failed")
+        else:
+            from pypy.rlib import rwin32
+            from pypy.rpython.module.ll_os_stat import time_t_to_FILE_TIME
+
+            class CConfig:
+                _compilation_info_ = ExternalCompilationInfo(
+                    includes = ['windows.h'],
+                    )
+
+                FILE_WRITE_ATTRIBUTES = platform.ConstantInteger(
+                    'FILE_WRITE_ATTRIBUTES')
+                OPEN_EXISTING = platform.ConstantInteger(
+                    'OPEN_EXISTING')
+                FILE_FLAG_BACKUP_SEMANTICS = platform.ConstantInteger(
+                    'FILE_FLAG_BACKUP_SEMANTICS')
+            globals().update(platform.configure(CConfig))
+
+            CreateFile = rffi.llexternal(
+                'CreateFileA',
+                [rwin32.LPCSTR, rwin32.DWORD, rwin32.DWORD,
+                 rwin32.LPSECURITY_ATTRIBUTES, rwin32.DWORD, rwin32.DWORD,
+                 rwin32.HANDLE],
+                rwin32.HANDLE,
+                calling_conv='win')
+
+            GetSystemTime = rffi.llexternal(
+                'GetSystemTime',
+                [lltype.Ptr(rwin32.SYSTEMTIME)],
+                lltype.Void,
+                calling_conv='win')
+
+            SystemTimeToFileTime = rffi.llexternal(
+                'SystemTimeToFileTime',
+                [lltype.Ptr(rwin32.SYSTEMTIME),
+                 lltype.Ptr(rwin32.FILETIME)],
+                rwin32.BOOL,
+                calling_conv='win')
+
+            SetFileTime = rffi.llexternal(
+                'SetFileTime',
+                [rwin32.HANDLE,
+                 lltype.Ptr(rwin32.FILETIME),
+                 lltype.Ptr(rwin32.FILETIME),
+                 lltype.Ptr(rwin32.FILETIME)],
+                rwin32.BOOL,
+                calling_conv = 'win')
+
+            def os_utime_llimpl(path, tp):
+                hFile = CreateFile(path, 
+                                   FILE_WRITE_ATTRIBUTES, 0, 
+                                   None, OPEN_EXISTING,
+                                   FILE_FLAG_BACKUP_SEMANTICS, 0)
+                if hFile == rwin32.INVALID_HANDLE_VALUE:
+                    raise rwin32.lastWindowsError()
+                ctime = lltype.nullptr(rwin32.FILETIME)
+                atime = lltype.malloc(rwin32.FILETIME, flavor='raw')
+                mtime = lltype.malloc(rwin32.FILETIME, flavor='raw')
+                try:
+                    if tp is None:
+                        now = lltype.malloc(rwin32.SYSTEMTIME, flavor='raw')
+                        try:
+                            GetSystemTime(now)
+                            if (not SystemTimeToFileTime(now, atime) or
+                                not SystemTimeToFileTime(now, mtime)):
+                                raise rwin32.lastWindowsError()
+                        finally:
+                            lltype.free(now, flavor='raw')
+                    else:
+                        actime, modtime = tp
+                        time_t_to_FILE_TIME(actime, atime)
+                        time_t_to_FILE_TIME(modtime, mtime)
+                    if not SetFileTime(hFile, ctime, atime, mtime):
+                        raise rwin32.lastWindowsError()
+                finally:
+                    rwin32.CloseHandle(hFile)
+                    lltype.free(atime, flavor='raw')
+                    lltype.free(mtime, flavor='raw')
         os_utime_llimpl._annspecialcase_ = 'specialize:argtype(1)'
 
         s_string = SomeString()
@@ -533,12 +621,26 @@
 
     @registering_if(os, 'getpgrp')
     def register_os_getpgrp(self):
-        return self.extdef_for_os_function_returning_int('getpgrp')
+        name = 'getpgrp'
+        if self.GETPGRP_HAVE_ARG:
+            c_func = self.llexternal(name, [rffi.INT], rffi.INT)
+            def c_func_llimpl():
+                res = rffi.cast(rffi.LONG, c_func(0))
+                if res == -1:
+                    raise OSError(rposix.get_errno(), "%s failed" % name)
+                return res
+
+            c_func_llimpl.func_name = name + '_llimpl'
+
+            return extdef([], int, llimpl=c_func_llimpl,
+                          export_name='ll_os.ll_os_' + name)
+        else:
+            return self.extdef_for_os_function_returning_int('getpgrp')
 
     @registering_if(os, 'setpgrp')
     def register_os_setpgrp(self):
         name = 'setpgrp'
-        if sys.platform.startswith('freebsd') or sys.platform == 'darwin':
+        if self.SETPGRP_HAVE_ARG:
             c_func = self.llexternal(name, [rffi.INT, rffi.INT], rffi.INT)
             def c_func_llimpl():
                 res = rffi.cast(rffi.LONG, c_func(0, 0))

Modified: pypy/release/1.1.x/pypy/rpython/module/ll_os_stat.py
==============================================================================
--- pypy/release/1.1.x/pypy/rpython/module/ll_os_stat.py	(original)
+++ pypy/release/1.1.x/pypy/rpython/module/ll_os_stat.py	Tue Apr 21 12:04:19 2009
@@ -398,6 +398,11 @@
         time = (ft / 10000000) - secs_between_epochs
         return time, nsec
 
+    def time_t_to_FILE_TIME(time, filetime):
+        ft = lltype.r_longlong((time + secs_between_epochs) * 10000000)
+        filetime.c_dwHighDateTime = lltype.r_uint(ft >> 32)
+        filetime.c_dwLowDateTime = lltype.r_uint(ft & ((1 << 32) - 1))
+        
     def attribute_data_to_stat(info):
         st_mode = attributes_to_mode(info.c_dwFileAttributes)
         st_size = make_longlong(info.c_nFileSizeHigh, info.c_nFileSizeLow)

Modified: pypy/release/1.1.x/pypy/rpython/module/test/test_ll_os.py
==============================================================================
--- pypy/release/1.1.x/pypy/rpython/module/test/test_ll_os.py	(original)
+++ pypy/release/1.1.x/pypy/rpython/module/test/test_ll_os.py	Tue Apr 21 12:04:19 2009
@@ -35,6 +35,19 @@
     for value in times:
         assert isinstance(value, float)
 
+def test_utimes():
+    if os.name != 'nt':
+        py.test.skip('Windows specific feature')
+    # Windows support centiseconds
+    def f(fname, t1):
+        os.utime(fname, (t1, t1))
+
+    fname = udir.join('test_utimes.txt')
+    fname.ensure()
+    t1 = 1159195039.25
+    compile(f, (str, float))(str(fname), t1)
+    assert t1 == os.stat(str(fname)).st_mtime
+
 def test__getfullpathname():
     if os.name != 'nt':
         py.test.skip('nt specific function')

Modified: pypy/release/1.1.x/pypy/rpython/tool/rffi_platform.py
==============================================================================
--- pypy/release/1.1.x/pypy/rpython/tool/rffi_platform.py	(original)
+++ pypy/release/1.1.x/pypy/rpython/tool/rffi_platform.py	Tue Apr 21 12:04:19 2009
@@ -56,7 +56,11 @@
         _compilation_info_ = eci
         WORKS = Works()
     configure(CConfig)
-
+    
+def checkcompiles(expression, c_header_source):
+    """Check if expression compiles. If not, returns False"""
+    return has(expression, c_header_source)
+    
 def sizeof(name, eci, **kwds):
     class CConfig:
         _compilation_info_ = eci
@@ -150,7 +154,7 @@
     def ask_gcc(self, question):
         self.start_main()
         self.f.write(question + "\n")
-        self.close()
+        self.close()	
         eci = self.config._compilation_info_
         try_compile_cache([self.path], eci)
 

Modified: pypy/release/1.1.x/pypy/translator/c/test/test_extfunc.py
==============================================================================
--- pypy/release/1.1.x/pypy/translator/c/test/test_extfunc.py	(original)
+++ pypy/release/1.1.x/pypy/translator/c/test/test_extfunc.py	Tue Apr 21 12:04:19 2009
@@ -502,6 +502,14 @@
         res = f1()
         assert res == os.getpid()
         
+if hasattr(os, 'getpgrp'):
+    def test_os_getpgrp():
+        def does_stuff():
+            return os.getpgrp()
+        f1 = compile(does_stuff, [])
+        res = f1()
+        assert res == os.getpgrp()
+
 if hasattr(os, 'setpgrp'):
     def test_os_setpgrp():
         def does_stuff():

Modified: pypy/release/1.1.x/pypy/translator/platform/darwin.py
==============================================================================
--- pypy/release/1.1.x/pypy/translator/platform/darwin.py	(original)
+++ pypy/release/1.1.x/pypy/translator/platform/darwin.py	Tue Apr 21 12:04:19 2009
@@ -5,10 +5,10 @@
 class Darwin(posix.BasePosix):
     name = "darwin"
     
-    link_flags = []
-    cflags = ['-O3', '-fomit-frame-pointer']
+    link_flags = ['-mmacosx-version-min=10.4']
+    cflags = ['-O3', '-fomit-frame-pointer', '-mmacosx-version-min=10.4']
     standalone_only = ['-mdynamic-no-pic']
-    shared_only = ['-mmacosx-version-min=10.4']
+    shared_only = []
 
     so_ext = 'so'
     



More information about the Pypy-commit mailing list