Author: Alex Gaynor <[email protected]>
Branch: python-loop-unroll
Changeset: r64691:3743a8d7b24f
Date: 2013-05-29 10:14 -0700
http://bitbucket.org/pypy/pypy/changeset/3743a8d7b24f/
Log: merged default
diff --git a/pypy/module/_minimal_curses/fficurses.py
b/pypy/module/_minimal_curses/fficurses.py
--- a/pypy/module/_minimal_curses/fficurses.py
+++ b/pypy/module/_minimal_curses/fficurses.py
@@ -11,21 +11,50 @@
from sys import platform
import os.path
-_CYGWIN = platform == 'cygwin'
-_NCURSES_CURSES = os.path.isfile("/usr/include/ncurses/curses.h")
+# We cannot trust ncurses5-config, it's broken in various ways in
+# various versions. For example it might not list -ltinfo even though
+# it's needed, or --cflags might be completely empty. On Ubuntu 10.04
+# it gives -I/usr/include/ncurses, which doesn't exist at all. Crap.
-if _CYGWIN or _NCURSES_CURSES:
- eci = ExternalCompilationInfo(
- includes = ['ncurses/curses.h', 'ncurses/term.h'],
- libraries = ['curses'],
- )
-else:
- eci = ExternalCompilationInfo(
- includes = ['curses.h', 'term.h'],
- libraries = ['curses'],
- )
+def try_cflags():
+ yield ExternalCompilationInfo(includes=['curses.h', 'term.h'])
+ yield ExternalCompilationInfo(includes=['curses.h', 'term.h'],
+ include_dirs=['/usr/include/ncurses'])
+ yield ExternalCompilationInfo(includes=['ncurses/curses.h',
+ 'ncurses/term.h'])
-rffi_platform.verify_eci(eci)
+def try_ldflags():
+ yield ExternalCompilationInfo(libraries=['curses'])
+ yield ExternalCompilationInfo(libraries=['curses', 'tinfo'])
+
+def try_tools():
+ try:
+ yield ExternalCompilationInfo.from_pkg_config("ncurses")
+ except Exception:
+ pass
+ try:
+ yield ExternalCompilationInfo.from_config_tool("ncurses5-config")
+ except Exception:
+ pass
+
+def try_eci():
+ for eci in try_tools():
+ yield eci.merge(ExternalCompilationInfo(includes=['curses.h',
+ 'term.h']))
+ for eci1 in try_cflags():
+ for eci2 in try_ldflags():
+ yield eci1.merge(eci2)
+
+def guess_eci():
+ for eci in try_eci():
+ class CConfig:
+ _compilation_info_ = eci
+ HAS = rffi_platform.Has("setupterm")
+ if rffi_platform.configure(CConfig)['HAS']:
+ return eci
+ raise ImportError("failed to guess where ncurses is installed")
+
+eci = guess_eci()
INT = rffi.INT
diff --git a/pypy/module/_multiprocessing/__init__.py
b/pypy/module/_multiprocessing/__init__.py
--- a/pypy/module/_multiprocessing/__init__.py
+++ b/pypy/module/_multiprocessing/__init__.py
@@ -1,11 +1,11 @@
+import sys
+
from pypy.interpreter.mixedmodule import MixedModule
-import sys
class Module(MixedModule):
interpleveldefs = {
'Connection' : 'interp_connection.W_FileConnection',
- 'PipeConnection' : 'interp_connection.W_PipeConnection',
'SemLock' : 'interp_semaphore.W_SemLock',
'address_of_buffer' : 'interp_memory.address_of_buffer',
@@ -15,4 +15,6 @@
}
if sys.platform == 'win32':
+ interpleveldefs['PipeConnection'] = \
+ 'interp_connection.W_PipeConnection'
interpleveldefs['win32'] = 'interp_win32.win32_namespace(space)'
diff --git a/pypy/module/_multiprocessing/interp_connection.py
b/pypy/module/_multiprocessing/interp_connection.py
--- a/pypy/module/_multiprocessing/interp_connection.py
+++ b/pypy/module/_multiprocessing/interp_connection.py
@@ -1,17 +1,17 @@
-from __future__ import with_statement
-from pypy.interpreter.baseobjspace import W_Root
-from pypy.interpreter.typedef import TypeDef, GetSetProperty
-from pypy.interpreter.gateway import interp2app, unwrap_spec, WrappedDefault
-from pypy.interpreter.error import (
- OperationError, wrap_oserror, operationerrfmt)
-from rpython.rtyper.lltypesystem import rffi, lltype
-from rpython.rlib.rarithmetic import intmask
-from rpython.rlib import rpoll, rsocket
import sys
-READABLE = 1
-WRITABLE = 2
+from rpython.rlib import rpoll, rsocket
+from rpython.rlib.rarithmetic import intmask
+from rpython.rtyper.lltypesystem import lltype, rffi
+from pypy.interpreter.baseobjspace import W_Root
+from pypy.interpreter.error import (
+ OperationError, operationerrfmt, wrap_oserror)
+from pypy.interpreter.gateway import (
+ WrappedDefault, interp2app, interpindirect2app, unwrap_spec)
+from pypy.interpreter.typedef import GetSetProperty, TypeDef
+
+READABLE, WRITABLE = range(1, 3)
PY_SSIZE_T_MAX = sys.maxint
PY_SSIZE_T_MIN = -sys.maxint - 1
@@ -46,10 +46,12 @@
raise NotImplementedError
def is_valid(self):
return False
- def do_send_string(self, space, buffer, offset, size):
+ def do_send_string(self, space, buf, offset, size):
raise NotImplementedError
def do_recv_string(self, space, buflength, maxlength):
raise NotImplementedError
+ def do_poll(self, space, timeout):
+ raise NotImplementedError
def close(self):
self.do_close()
@@ -61,6 +63,14 @@
def writable_get(self, space):
return space.newbool(bool(self.flags & WRITABLE))
+ def _repr(self, space, handle):
+ conn_type = ["read-only", "write-only", "read-write"][self.flags - 1]
+ return space.wrap("<%s %s, handle %d>" % (
+ conn_type, space.type(self).getname(space), handle))
+
+ def descr_repr(self, space):
+ raise NotImplementedError
+
def _check_readable(self, space):
if not self.flags & READABLE:
raise OperationError(space.w_IOError,
@@ -70,9 +80,9 @@
raise OperationError(space.w_IOError,
space.wrap("connection is read-only"))
- @unwrap_spec(buffer='bufferstr', offset='index', size='index')
- def send_bytes(self, space, buffer, offset=0, size=PY_SSIZE_T_MIN):
- length = len(buffer)
+ @unwrap_spec(buf='bufferstr', offset='index', size='index')
+ def send_bytes(self, space, buf, offset=0, size=PY_SSIZE_T_MIN):
+ length = len(buf)
self._check_writable(space)
if offset < 0:
raise OperationError(space.w_ValueError,
@@ -90,7 +100,7 @@
raise OperationError(space.w_ValueError,
space.wrap("buffer length > offset + size"))
- self.do_send_string(space, buffer, offset, size)
+ self.do_send_string(space, buf, offset, size)
@unwrap_spec(maxlength='index')
def recv_bytes(self, space, maxlength=PY_SSIZE_T_MAX):
@@ -139,8 +149,8 @@
w_pickled = space.call_method(
w_picklemodule, "dumps", w_obj, w_protocol)
- buffer = space.bufferstr_w(w_pickled)
- self.do_send_string(space, buffer, 0, len(buffer))
+ buf = space.bufferstr_w(w_pickled)
+ self.do_send_string(space, buf, 0, len(buf))
def recv(self, space):
self._check_readable(space)
@@ -177,6 +187,7 @@
W_BaseConnection.typedef = TypeDef(
'BaseConnection',
+ __repr__ = interpindirect2app(W_BaseConnection.descr_repr),
closed = GetSetProperty(W_BaseConnection.closed_get),
readable = GetSetProperty(W_BaseConnection.readable_get),
writable = GetSetProperty(W_BaseConnection.writable_get),
@@ -226,7 +237,8 @@
def __init__(self, space, fd, flags):
if fd == self.INVALID_HANDLE_VALUE or fd < 0:
- raise OperationError(space.w_IOError, space.wrap("invalid handle
%d" % fd))
+ raise OperationError(space.w_IOError,
+ space.wrap("invalid handle %d" % fd))
W_BaseConnection.__init__(self, flags)
self.fd = fd
@@ -238,6 +250,9 @@
W_FileConnection.__init__(self, space, fd, flags)
return space.wrap(self)
+ def descr_repr(self, space):
+ return self._repr(space, self.fd)
+
def fileno(self, space):
return space.wrap(self.fd)
@@ -249,8 +264,8 @@
self.CLOSE()
self.fd = self.INVALID_HANDLE_VALUE
- def do_send_string(self, space, buffer, offset, size):
- # Since str2charp copies the buffer anyway, always combine the
+ def do_send_string(self, space, buf, offset, size):
+ # Since str2charp copies the buf anyway, always combine the
# "header" and the "body" of the message and send them at once.
message = lltype.malloc(rffi.CCHARP.TO, size + 4, flavor='raw')
try:
@@ -259,7 +274,7 @@
rffi.cast(rffi.UINTP, message)[0] = length
i = size - 1
while i >= 0:
- message[4 + i] = buffer[offset + i]
+ message[4 + i] = buf[offset + i]
i -= 1
self._sendall(space, message, size + 4)
finally:
@@ -296,7 +311,7 @@
size -= count
message = rffi.ptradd(message, count)
- def _recvall(self, space, buffer, length):
+ def _recvall(self, space, buf, length):
length = intmask(length)
remaining = length
while remaining > 0:
@@ -313,9 +328,9 @@
"got end of file during message"))
# XXX inefficient
for i in range(count):
- buffer[i] = data[i]
+ buf[i] = data[i]
remaining -= count
- buffer = rffi.ptradd(buffer, count)
+ buf = rffi.ptradd(buf, count)
if sys.platform == 'win32':
def _check_fd(self):
@@ -330,10 +345,7 @@
"handle out of range in select()"))
r, w, e = rpoll.select([self.fd], [], [], timeout)
- if r:
- return True
- else:
- return False
+ return bool(r)
W_FileConnection.typedef = TypeDef(
'Connection', W_BaseConnection.typedef,
@@ -351,7 +363,8 @@
self.handle = handle
@unwrap_spec(readable=bool, writable=bool)
- def descr_new_pipe(space, w_subtype, w_handle, readable=True,
writable=True):
+ def descr_new_pipe(space, w_subtype, w_handle, readable=True,
+ writable=True):
from pypy.module._multiprocessing.interp_win32 import handle_w
handle = handle_w(space, w_handle)
flags = (readable and READABLE) | (writable and WRITABLE)
@@ -361,10 +374,7 @@
return space.wrap(self)
def descr_repr(self, space):
- conn_type = ["read-only", "write-only", "read-write"][self.flags]
-
- return space.wrap("<%s %s, handle %zd>" % (
- conn_type, space.type(self).getname(space), self.do_fileno()))
+ return self._repr(space, self.handle)
def is_valid(self):
return self.handle != self.INVALID_HANDLE_VALUE
@@ -378,12 +388,12 @@
CloseHandle(self.handle)
self.handle = self.INVALID_HANDLE_VALUE
- def do_send_string(self, space, buffer, offset, size):
+ def do_send_string(self, space, buf, offset, size):
from pypy.module._multiprocessing.interp_win32 import (
_WriteFile, ERROR_NO_SYSTEM_RESOURCES)
from rpython.rlib import rwin32
- charp = rffi.str2charp(buffer)
+ charp = rffi.str2charp(buf)
written_ptr = lltype.malloc(rffi.CArrayPtr(rwin32.DWORD).TO, 1,
flavor='raw')
try:
diff --git a/pypy/module/_multiprocessing/interp_memory.py
b/pypy/module/_multiprocessing/interp_memory.py
--- a/pypy/module/_multiprocessing/interp_memory.py
+++ b/pypy/module/_multiprocessing/interp_memory.py
@@ -1,5 +1,6 @@
+from rpython.rtyper.lltypesystem import rffi
+
from pypy.interpreter.error import OperationError
-from rpython.rtyper.lltypesystem import rffi
from pypy.module.mmap.interp_mmap import W_MMap
def address_of_buffer(space, w_obj):
diff --git a/pypy/module/_multiprocessing/interp_semaphore.py
b/pypy/module/_multiprocessing/interp_semaphore.py
--- a/pypy/module/_multiprocessing/interp_semaphore.py
+++ b/pypy/module/_multiprocessing/interp_semaphore.py
@@ -1,23 +1,26 @@
-from __future__ import with_statement
+import errno
+import os
+import sys
+import time
+
+from rpython.rlib import rgc, rthread
+from rpython.rlib.rarithmetic import r_uint
+from rpython.rtyper.lltypesystem import rffi, lltype
+from rpython.rtyper.tool import rffi_platform as platform
+from rpython.translator.tool.cbuild import ExternalCompilationInfo
+
from pypy.interpreter.baseobjspace import W_Root
-from pypy.interpreter.typedef import TypeDef, GetSetProperty
+from pypy.interpreter.error import OperationError, wrap_oserror
from pypy.interpreter.gateway import interp2app, unwrap_spec
-from pypy.interpreter.error import wrap_oserror, OperationError
-from rpython.rtyper.lltypesystem import rffi, lltype
-from rpython.rlib import rgc
-from rpython.rlib.rarithmetic import r_uint
-from rpython.translator.tool.cbuild import ExternalCompilationInfo
-from rpython.rtyper.tool import rffi_platform as platform
-from rpython.rlib import rthread
+from pypy.interpreter.typedef import GetSetProperty, TypeDef
from pypy.module._multiprocessing.interp_connection import w_handle
-import sys, os, time, errno
RECURSIVE_MUTEX, SEMAPHORE = range(2)
if sys.platform == 'win32':
from rpython.rlib import rwin32
from pypy.module._multiprocessing.interp_win32 import (
- handle_w, _GetTickCount)
+ _GetTickCount, handle_w)
SEM_VALUE_MAX = sys.maxint
@@ -62,7 +65,8 @@
TIMEVALP = rffi.CArrayPtr(TIMEVAL)
TIMESPECP = rffi.CArrayPtr(TIMESPEC)
SEM_T = rffi.COpaquePtr('sem_t', compilation_info=eci)
- SEM_FAILED = config['SEM_FAILED'] # rffi.cast(SEM_T,
config['SEM_FAILED'])
+ # rffi.cast(SEM_T, config['SEM_FAILED'])
+ SEM_FAILED = config['SEM_FAILED']
SEM_VALUE_MAX = config['SEM_VALUE_MAX']
SEM_TIMED_WAIT = config['SEM_TIMED_WAIT']
SEM_T_SIZE = config['SEM_T_SIZE']
@@ -160,7 +164,8 @@
return -1
if SEM_TIMED_WAIT:
- _sem_timedwait = external('sem_timedwait', [SEM_T, TIMESPECP],
rffi.INT)
+ _sem_timedwait = external('sem_timedwait', [SEM_T, TIMESPECP],
+ rffi.INT)
else:
_sem_timedwait = _sem_timedwait_save
@@ -185,7 +190,8 @@
res = _gettimeofday(now, None)
if res < 0:
raise OSError(rposix.get_errno(), "gettimeofday failed")
- return rffi.getintfield(now[0], 'c_tv_sec'),
rffi.getintfield(now[0], 'c_tv_usec')
+ return (rffi.getintfield(now[0], 'c_tv_sec'),
+ rffi.getintfield(now[0], 'c_tv_usec'))
finally:
lltype.free(now, flavor='raw')
@@ -330,8 +336,8 @@
deadline = lltype.malloc(TIMESPECP.TO, 1, flavor='raw')
rffi.setintfield(deadline[0], 'c_tv_sec', now_sec + sec)
rffi.setintfield(deadline[0], 'c_tv_nsec', now_usec * 1000 + nsec)
- val = rffi.getintfield(deadline[0], 'c_tv_sec') + \
- rffi.getintfield(deadline[0], 'c_tv_nsec') /
1000000000
+ val = (rffi.getintfield(deadline[0], 'c_tv_sec') +
+ rffi.getintfield(deadline[0], 'c_tv_nsec') / 1000000000)
rffi.setintfield(deadline[0], 'c_tv_sec', val)
val = rffi.getintfield(deadline[0], 'c_tv_nsec') % 1000000000
rffi.setintfield(deadline[0], 'c_tv_nsec', val)
diff --git a/pypy/module/_multiprocessing/interp_win32.py
b/pypy/module/_multiprocessing/interp_win32.py
--- a/pypy/module/_multiprocessing/interp_win32.py
+++ b/pypy/module/_multiprocessing/interp_win32.py
@@ -1,11 +1,12 @@
-from pypy.interpreter.gateway import unwrap_spec, interp2app
-from pypy.interpreter.function import StaticMethod
-from pypy.interpreter.error import wrap_windowserror, OperationError
from rpython.rlib import rwin32
from rpython.rlib.rarithmetic import r_uint
-from rpython.rtyper.lltypesystem import rffi, lltype
+from rpython.rtyper.lltypesystem import lltype, rffi
+from rpython.rtyper.tool import rffi_platform
from rpython.translator.tool.cbuild import ExternalCompilationInfo
-from rpython.rtyper.tool import rffi_platform
+
+from pypy.interpreter.error import OperationError, wrap_windowserror
+from pypy.interpreter.function import StaticMethod
+from pypy.interpreter.gateway import interp2app, unwrap_spec
from pypy.module._multiprocessing.interp_connection import w_handle
CONSTANTS = """
@@ -130,10 +131,12 @@
if not _ConnectNamedPipe(handle, rffi.NULL):
raise wrap_windowserror(space, rwin32.lastWindowsError())
-def SetNamedPipeHandleState(space, w_handle, w_pipemode, w_maxinstances,
w_timeout):
+def SetNamedPipeHandleState(space, w_handle, w_pipemode, w_maxinstances,
+ w_timeout):
handle = handle_w(space, w_handle)
state = lltype.malloc(rffi.CArrayPtr(rffi.UINT).TO, 3, flavor='raw')
- statep = lltype.malloc(rffi.CArrayPtr(rffi.UINTP).TO, 3, flavor='raw',
zero=True)
+ statep = lltype.malloc(rffi.CArrayPtr(rffi.UINTP).TO, 3, flavor='raw',
+ zero=True)
try:
if not space.is_w(w_pipemode, space.w_None):
state[0] = space.uint_w(w_pipemode)
@@ -144,7 +147,8 @@
if not space.is_w(w_timeout, space.w_None):
state[2] = space.uint_w(w_timeout)
statep[2] = rffi.ptradd(state, 2)
- if not _SetNamedPipeHandleState(handle, statep[0], statep[1],
statep[2]):
+ if not _SetNamedPipeHandleState(handle, statep[0], statep[1],
+ statep[2]):
raise wrap_windowserror(space, rwin32.lastWindowsError())
finally:
lltype.free(state, flavor='raw')
diff --git a/pypy/module/_multiprocessing/test/test_connection.py
b/pypy/module/_multiprocessing/test/test_connection.py
--- a/pypy/module/_multiprocessing/test/test_connection.py
+++ b/pypy/module/_multiprocessing/test/test_connection.py
@@ -173,3 +173,11 @@
assert data1 == '\x00\x00\x00\x03abc'
data2 = sock.recv(8)
assert data2 == '\x00\x00\x00\x04defg'
+
+ def test_repr(self):
+ import _multiprocessing
+ c = _multiprocessing.Connection(1)
+ assert repr(c) == '<read-write Connection, handle 1>'
+ if hasattr(_multiprocessing, 'PipeConnection'):
+ c = _multiprocessing.PipeConnection(1)
+ assert repr(c) == '<read-write Connection, handle 1>'
diff --git a/rpython/translator/tool/cbuild.py
b/rpython/translator/tool/cbuild.py
--- a/rpython/translator/tool/cbuild.py
+++ b/rpython/translator/tool/cbuild.py
@@ -1,5 +1,5 @@
import py
-import sys
+import sys, subprocess
from rpython.translator.platform import host
from rpython.tool.udir import udir
@@ -99,6 +99,7 @@
return platform
return self._platform
+ @classmethod
def from_compiler_flags(cls, flags):
"""Returns a new ExternalCompilationInfo instance by parsing
the string 'flags', which is in the typical Unix compiler flags
@@ -124,8 +125,8 @@
return cls(pre_include_bits=pre_include_bits,
include_dirs=include_dirs,
compile_extra=compile_extra)
- from_compiler_flags = classmethod(from_compiler_flags)
+ @classmethod
def from_linker_flags(cls, flags):
"""Returns a new ExternalCompilationInfo instance by parsing
the string 'flags', which is in the typical Unix linker flags
@@ -146,8 +147,8 @@
return cls(libraries=libraries,
library_dirs=library_dirs,
link_extra=link_extra)
- from_linker_flags = classmethod(from_linker_flags)
+ @classmethod
def from_config_tool(cls, execonfigtool):
"""Returns a new ExternalCompilationInfo instance by executing
the 'execonfigtool' with --cflags and --libs arguments."""
@@ -156,12 +157,29 @@
raise ImportError("cannot find %r" % (execonfigtool,))
# we raise ImportError to be nice to the pypy.config.pypyoption
# logic of skipping modules depending on non-installed libs
- cflags = py.process.cmdexec('"%s" --cflags' % (str(path),))
+ return cls._run_config_tool('"%s"' % (str(path),))
+
+ @classmethod
+ def from_pkg_config(cls, pkgname):
+ """Returns a new ExternalCompilationInfo instance by executing
+ 'pkg-config <pkgname>' with --cflags and --libs arguments."""
+ assert isinstance(pkgname, str)
+ try:
+ popen = subprocess.Popen(['pkg-config', pkgname, '--exists'])
+ result = popen.wait()
+ except OSError:
+ result = -1
+ if result != 0:
+ raise ImportError("failed: 'pkg-config %s --exists'" % pkgname)
+ return cls._run_config_tool('pkg-config "%s"' % pkgname)
+
+ @classmethod
+ def _run_config_tool(cls, command):
+ cflags = py.process.cmdexec('%s --cflags' % command)
eci1 = cls.from_compiler_flags(cflags)
- libs = py.process.cmdexec('"%s" --libs' % (str(path),))
+ libs = py.process.cmdexec('%s --libs' % command)
eci2 = cls.from_linker_flags(libs)
return eci1.merge(eci2)
- from_config_tool = classmethod(from_config_tool)
def _value(self):
return tuple([getattr(self, x)
diff --git a/rpython/translator/tool/test/test_cbuild.py
b/rpython/translator/tool/test/test_cbuild.py
--- a/rpython/translator/tool/test/test_cbuild.py
+++ b/rpython/translator/tool/test/test_cbuild.py
@@ -127,6 +127,18 @@
ExternalCompilationInfo.from_config_tool,
'dxowqbncpqympqhe-config')
+ def test_from_pkg_config(self):
+ try:
+ cmd = ['pkg-config', 'ncurses', '--exists']
+ popen = Popen(cmd)
+ result = popen.wait()
+ except OSError:
+ result = -1
+ if result != 0:
+ py.test.skip("failed: %r" % (' '.join(cmd),))
+ eci = ExternalCompilationInfo.from_pkg_config('ncurses')
+ assert 'ncurses' in eci.libraries
+
def test_platforms(self):
from rpython.translator.platform import Platform
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit