[pypy-commit] pypy default: merge win32-cleanup to default
mattip
noreply at buildbot.pypy.org
Tue Feb 7 21:40:28 CET 2012
Author: mattip
Branch:
Changeset: r52207:5b7ecbf87681
Date: 2012-02-07 22:39 +0200
http://bitbucket.org/pypy/pypy/changeset/5b7ecbf87681/
Log: merge win32-cleanup to default
diff --git a/py/_io/terminalwriter.py b/py/_io/terminalwriter.py
--- a/py/_io/terminalwriter.py
+++ b/py/_io/terminalwriter.py
@@ -271,16 +271,24 @@
('srWindow', SMALL_RECT),
('dwMaximumWindowSize', COORD)]
+ _GetStdHandle = ctypes.windll.kernel32.GetStdHandle
+ _GetStdHandle.argtypes = [wintypes.DWORD]
+ _GetStdHandle.restype = wintypes.HANDLE
def GetStdHandle(kind):
- return ctypes.windll.kernel32.GetStdHandle(kind)
+ return _GetStdHandle(kind)
- SetConsoleTextAttribute = \
- ctypes.windll.kernel32.SetConsoleTextAttribute
-
+ SetConsoleTextAttribute = ctypes.windll.kernel32.SetConsoleTextAttribute
+ SetConsoleTextAttribute.argtypes = [wintypes.HANDLE, wintypes.WORD]
+ SetConsoleTextAttribute.restype = wintypes.BOOL
+
+ _GetConsoleScreenBufferInfo = \
+ ctypes.windll.kernel32.GetConsoleScreenBufferInfo
+ _GetConsoleScreenBufferInfo.argtypes = [wintypes.HANDLE,
+ ctypes.POINTER(CONSOLE_SCREEN_BUFFER_INFO)]
+ _GetConsoleScreenBufferInfo.restype = wintypes.BOOL
def GetConsoleInfo(handle):
info = CONSOLE_SCREEN_BUFFER_INFO()
- ctypes.windll.kernel32.GetConsoleScreenBufferInfo(\
- handle, ctypes.byref(info))
+ _GetConsoleScreenBufferInfo(handle, ctypes.byref(info))
return info
def _getdimensions():
diff --git a/pypy/interpreter/baseobjspace.py b/pypy/interpreter/baseobjspace.py
--- a/pypy/interpreter/baseobjspace.py
+++ b/pypy/interpreter/baseobjspace.py
@@ -1340,6 +1340,15 @@
def unicode_w(self, w_obj):
return w_obj.unicode_w(self)
+ def unicode0_w(self, w_obj):
+ "Like unicode_w, but rejects strings with NUL bytes."
+ from pypy.rlib import rstring
+ result = w_obj.unicode_w(self)
+ if u'\x00' in result:
+ raise OperationError(self.w_TypeError, self.wrap(
+ 'argument must be a unicode string without NUL characters'))
+ return rstring.assert_str0(result)
+
def realunicode_w(self, w_obj):
# Like unicode_w, but only works if w_obj is really of type
# 'unicode'.
@@ -1638,6 +1647,9 @@
'UnicodeEncodeError',
'UnicodeDecodeError',
]
+
+if sys.platform.startswith("win"):
+ ObjSpace.ExceptionTable += ['WindowsError']
## Irregular part of the interface:
#
diff --git a/pypy/interpreter/test/test_objspace.py b/pypy/interpreter/test/test_objspace.py
--- a/pypy/interpreter/test/test_objspace.py
+++ b/pypy/interpreter/test/test_objspace.py
@@ -178,6 +178,14 @@
res = self.space.interp_w(Function, w(None), can_be_None=True)
assert res is None
+ def test_str0_w(self):
+ space = self.space
+ w = space.wrap
+ assert space.str0_w(w("123")) == "123"
+ exc = space.raises_w(space.w_TypeError, space.str0_w, w("123\x004"))
+ assert space.unicode0_w(w(u"123")) == u"123"
+ exc = space.raises_w(space.w_TypeError, space.unicode0_w, w(u"123\x004"))
+
def test_getindex_w(self):
w_instance1 = self.space.appexec([], """():
class X(object):
diff --git a/pypy/module/_ffi/test/test__ffi.py b/pypy/module/_ffi/test/test__ffi.py
--- a/pypy/module/_ffi/test/test__ffi.py
+++ b/pypy/module/_ffi/test/test__ffi.py
@@ -190,6 +190,7 @@
def test_convert_strings_to_char_p(self):
"""
+ DLLEXPORT
long mystrlen(char* s)
{
long len = 0;
@@ -215,6 +216,7 @@
def test_convert_unicode_to_unichar_p(self):
"""
#include <wchar.h>
+ DLLEXPORT
long mystrlen_u(wchar_t* s)
{
long len = 0;
@@ -241,6 +243,7 @@
def test_keepalive_temp_buffer(self):
"""
+ DLLEXPORT
char* do_nothing(char* s)
{
return s;
@@ -525,5 +528,7 @@
from _ffi import CDLL, types
libfoo = CDLL(self.libfoo_name)
raises(AttributeError, "libfoo.getfunc('I_do_not_exist', [], types.void)")
+ if self.iswin32:
+ skip("unix specific")
libnone = CDLL(None)
raises(AttributeError, "libnone.getfunc('I_do_not_exist', [], types.void)")
diff --git a/pypy/module/_file/test/test_file.py b/pypy/module/_file/test/test_file.py
--- a/pypy/module/_file/test/test_file.py
+++ b/pypy/module/_file/test/test_file.py
@@ -265,6 +265,13 @@
if option.runappdirect:
py.test.skip("works with internals of _file impl on py.py")
+ import platform
+ if platform.system() == 'Windows':
+ # XXX This test crashes until someone implements something like
+ # XXX verify_fd from
+ # XXX http://hg.python.org/cpython/file/80ddbd822227/Modules/posixmodule.c#l434
+ # XXX and adds it to fopen
+ assert False
state = [0]
def read(fd, n=None):
diff --git a/pypy/module/posix/interp_posix.py b/pypy/module/posix/interp_posix.py
--- a/pypy/module/posix/interp_posix.py
+++ b/pypy/module/posix/interp_posix.py
@@ -48,7 +48,7 @@
return fsencode_w(self.space, self.w_obj)
def as_unicode(self):
- return self.space.unicode_w(self.w_obj)
+ return self.space.unicode0_w(self.w_obj)
class FileDecoder(object):
def __init__(self, space, w_obj):
@@ -62,7 +62,7 @@
space = self.space
w_unicode = space.call_method(self.w_obj, 'decode',
getfilesystemencoding(space))
- return space.unicode_w(w_unicode)
+ return space.unicode0_w(w_unicode)
@specialize.memo()
def dispatch_filename(func, tag=0):
diff --git a/pypy/module/posix/test/test_ztranslation.py b/pypy/module/posix/test/test_ztranslation.py
new file mode 100644
--- /dev/null
+++ b/pypy/module/posix/test/test_ztranslation.py
@@ -0,0 +1,4 @@
+from pypy.objspace.fake.checkmodule import checkmodule
+
+def test_posix_translates():
+ checkmodule('posix')
\ No newline at end of file
diff --git a/pypy/module/zipimport/interp_zipimport.py b/pypy/module/zipimport/interp_zipimport.py
--- a/pypy/module/zipimport/interp_zipimport.py
+++ b/pypy/module/zipimport/interp_zipimport.py
@@ -123,7 +123,9 @@
self.prefix = prefix
def getprefix(self, space):
- return space.wrap(self.prefix)
+ if ZIPSEP == os.path.sep:
+ return space.wrap(self.prefix)
+ return space.wrap(self.prefix.replace(ZIPSEP, os.path.sep))
def _find_relative_path(self, filename):
if filename.startswith(self.filename):
@@ -381,7 +383,7 @@
prefix = name[len(filename):]
if prefix.startswith(os.path.sep) or prefix.startswith(ZIPSEP):
prefix = prefix[1:]
- if prefix and not prefix.endswith(ZIPSEP):
+ if prefix and not prefix.endswith(ZIPSEP) and not prefix.endswith(os.path.sep):
prefix += ZIPSEP
w_result = space.wrap(W_ZipImporter(space, name, filename, zip_file, prefix))
zip_cache.set(filename, w_result)
diff --git a/pypy/module/zipimport/test/test_undocumented.py b/pypy/module/zipimport/test/test_undocumented.py
--- a/pypy/module/zipimport/test/test_undocumented.py
+++ b/pypy/module/zipimport/test/test_undocumented.py
@@ -119,7 +119,7 @@
zip_importer = zipimport.zipimporter(path)
assert isinstance(zip_importer, zipimport.zipimporter)
assert zip_importer.archive == zip_path
- assert zip_importer.prefix == prefix
+ assert zip_importer.prefix == prefix.replace('/', os.path.sep)
assert zip_path in zipimport._zip_directory_cache
finally:
self.cleanup_zipfile(self.created_paths)
diff --git a/pypy/module/zipimport/test/test_zipimport.py b/pypy/module/zipimport/test/test_zipimport.py
--- a/pypy/module/zipimport/test/test_zipimport.py
+++ b/pypy/module/zipimport/test/test_zipimport.py
@@ -15,7 +15,7 @@
cpy's regression tests
"""
compression = ZIP_STORED
- pathsep = '/'
+ pathsep = os.path.sep
def make_pyc(cls, space, co, mtime):
data = marshal.dumps(co)
@@ -129,7 +129,7 @@
self.writefile('sub/__init__.py', '')
self.writefile('sub/yy.py', '')
from zipimport import _zip_directory_cache, zipimporter
- sub_importer = zipimporter(self.zipfile + '/sub')
+ sub_importer = zipimporter(self.zipfile + os.path.sep + 'sub')
main_importer = zipimporter(self.zipfile)
assert main_importer is not sub_importer
diff --git a/pypy/rlib/ropenssl.py b/pypy/rlib/ropenssl.py
--- a/pypy/rlib/ropenssl.py
+++ b/pypy/rlib/ropenssl.py
@@ -54,6 +54,7 @@
ASN1_STRING = lltype.Ptr(lltype.ForwardReference())
ASN1_ITEM = rffi.COpaquePtr('ASN1_ITEM')
+ASN1_ITEM_EXP = lltype.Ptr(lltype.FuncType([], ASN1_ITEM))
X509_NAME = rffi.COpaquePtr('X509_NAME')
class CConfig:
@@ -101,12 +102,11 @@
X509_extension_st = rffi_platform.Struct(
'struct X509_extension_st',
[('value', ASN1_STRING)])
- ASN1_ITEM_EXP = lltype.FuncType([], ASN1_ITEM)
X509V3_EXT_D2I = lltype.FuncType([rffi.VOIDP, rffi.CCHARPP, rffi.LONG],
rffi.VOIDP)
v3_ext_method = rffi_platform.Struct(
'struct v3_ext_method',
- [('it', lltype.Ptr(ASN1_ITEM_EXP)),
+ [('it', ASN1_ITEM_EXP),
('d2i', lltype.Ptr(X509V3_EXT_D2I))])
GENERAL_NAME_st = rffi_platform.Struct(
'struct GENERAL_NAME_st',
@@ -118,6 +118,8 @@
('block_size', rffi.INT)])
EVP_MD_SIZE = rffi_platform.SizeOf('EVP_MD')
EVP_MD_CTX_SIZE = rffi_platform.SizeOf('EVP_MD_CTX')
+ OPENSSL_EXPORT_VAR_AS_FUNCTION = rffi_platform.Defined(
+ "OPENSSL_EXPORT_VAR_AS_FUNCTION")
for k, v in rffi_platform.configure(CConfig).items():
@@ -224,7 +226,10 @@
ssl_external('i2a_ASN1_INTEGER', [BIO, ASN1_INTEGER], rffi.INT)
ssl_external('ASN1_item_d2i',
[rffi.VOIDP, rffi.CCHARPP, rffi.LONG, ASN1_ITEM], rffi.VOIDP)
-ssl_external('ASN1_ITEM_ptr', [rffi.VOIDP], ASN1_ITEM, macro=True)
+if OPENSSL_EXPORT_VAR_AS_FUNCTION:
+ ssl_external('ASN1_ITEM_ptr', [ASN1_ITEM_EXP], ASN1_ITEM, macro=True)
+else:
+ ssl_external('ASN1_ITEM_ptr', [rffi.VOIDP], ASN1_ITEM, macro=True)
ssl_external('sk_GENERAL_NAME_num', [GENERAL_NAMES], rffi.INT,
macro=True)
diff --git a/pypy/rpython/module/ll_os.py b/pypy/rpython/module/ll_os.py
--- a/pypy/rpython/module/ll_os.py
+++ b/pypy/rpython/module/ll_os.py
@@ -43,7 +43,7 @@
arglist = ['arg%d' % (i,) for i in range(len(signature))]
transformed_arglist = arglist[:]
for i, arg in enumerate(signature):
- if arg is unicode:
+ if arg in (unicode, unicode0):
transformed_arglist[i] = transformed_arglist[i] + '.as_unicode()'
args = ', '.join(arglist)
@@ -67,7 +67,7 @@
exec source.compile() in miniglobals
new_func = miniglobals[func_name]
specialized_args = [i for i in range(len(signature))
- if signature[i] in (unicode, None)]
+ if signature[i] in (unicode, unicode0, None)]
new_func = specialize.argtype(*specialized_args)(new_func)
# Monkeypatch the function in pypy.rlib.rposix
More information about the pypy-commit
mailing list