Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
No results found
Show changes
Commits on Source (4)
......@@ -14,6 +14,8 @@
from pypy.module.cpyext.state import State
from pypy.module.cpyext.import_ import PyImport_Import
from rpython.rlib import rposix, jit
from rpython.rlib import rwin32
from rpython.rlib.rarithmetic import widen
PyStopIterationObjectStruct = lltype.ForwardReference()
PyStopIterationObject = lltype.Ptr(PyStopIterationObjectStruct)
......@@ -49,6 +51,9 @@
def PyErr_SetObject(space, w_type, w_value):
"""This function is similar to PyErr_SetString() but lets you specify an
arbitrary Python object for the "value" of the exception."""
pyerr_setobject(space, w_type, w_value)
def pyerr_setobject(space, w_type, w_value):
state = space.fromcache(State)
operr = OperationError(w_type, w_value)
operr.record_context(space, space.getexecutioncontext())
......@@ -57,8 +62,8 @@
@cpython_api([PyObject, CONST_STRING], lltype.Void)
def PyErr_SetString(space, w_type, message_ptr):
message = rffi.charp2str(message_ptr)
PyErr_SetObject(space, w_type, space.newtext(message))
pyerr_setobject(space, w_type, space.newtext(message))
@cpython_api([PyObject], lltype.Void, error=CANNOT_FAIL)
def PyErr_SetNone(space, w_type):
"""This is a shorthand for PyErr_SetObject(type, Py_None)."""
......@@ -61,11 +66,11 @@
@cpython_api([PyObject], lltype.Void, error=CANNOT_FAIL)
def PyErr_SetNone(space, w_type):
"""This is a shorthand for PyErr_SetObject(type, Py_None)."""
PyErr_SetObject(space, w_type, space.w_None)
pyerr_setobject(space, w_type, space.w_None)
if os.name == 'nt':
# For some reason CPython returns a (PyObject*)NULL
# This confuses the annotator, so set result_is_ll
@cpython_api([rffi.INT_real], PyObject, error=CANNOT_FAIL, result_is_ll=True)
def PyErr_SetFromWindowsErr(space, err):
......@@ -66,10 +71,54 @@
if os.name == 'nt':
# For some reason CPython returns a (PyObject*)NULL
# This confuses the annotator, so set result_is_ll
@cpython_api([rffi.INT_real], PyObject, error=CANNOT_FAIL, result_is_ll=True)
def PyErr_SetFromWindowsErr(space, err):
PyErr_SetObject(space, space.w_OSError, space.newint(err))
pyerr_setobject(space, space.w_OSError, space.newint(err))
return rffi.cast(PyObject, 0)
@cpython_api([rffi.INT_real, CONST_STRING], PyObject, error=CANNOT_FAIL, result_is_ll=True)
def PyErr_SetFromWindowsErrWithFilename(space, err, filename):
state = space.fromcache(State)
if filename:
filename = rffi.charp2str(filename)
try:
w_filename = space.fsdecode(space.newbytes(filename))
except:
w_filename = space.w_None
else:
w_filename = space.w_None
return pyerr_setexcfromwindows(space, space.w_WindowsError, err,
w_filename)
@cpython_api([PyObject, rffi.INT_real, PyObject], PyObject, error=CANNOT_FAIL, result_is_ll=True)
def PyErr_SetExcFromWindowsErrWithFilenameObject(space, w_exc, err, w_filename):
return pyerr_setexcfromwindows(space, w_exc, err, w_filename)
@cpython_api([PyObject, rffi.INT_real, PyObject, PyObject], PyObject, error=CANNOT_FAIL, result_is_ll=True)
def PyErr_SetExcFromWindowsErrWithFilenameObjects(space, w_exc, err, w_filename, w_filename2):
return pyerr_setexcfromwindows(space, w_exc, err, w_filename, w_filename2)
def pyerr_setexcfromwindows(space, w_exc, err, w_filename=None, w_filename2=None):
# Take from error._wrap_oserror2_impl
err = widen(err)
try:
msg, lgt = rwin32.FormatErrorW(err)
except ValueError:
msg = 'Windows Error %d' % err
lgt = len(msg)
w_msg = space.newtext(msg, lgt)
w_winerror = space.newint(err)
if not w_filename:
w_filename = space.w_None
if not w_filename2:
w_filename2 = space.w_None
w_error = space.call_function(w_exc, space.w_None, w_msg, w_filename,
w_winerror, w_filename2)
state = space.fromcache(State)
operr = OperationError(space.type(w_error), w_error)
operr.record_context(space, space.getexecutioncontext())
state.set_exception(operr)
return rffi.cast(PyObject, 0)
@cpython_api([], PyObject, result_borrowed=True)
......
......@@ -247,7 +247,7 @@
assert e.strerror == os.strerror(errno.EBADF)
assert e.filename is None
def test_SetFromErrnoWithFilename(self):
def test_SetFromErrnoWithFilename_basic(self):
char = self.special_char
if char is None:
char = "a" # boring
......@@ -251,9 +251,8 @@
char = self.special_char
if char is None:
char = "a" # boring
import errno, os
module = self.import_extension('foo', [
import errno, os, sys
codestr = [
("set_from_errno", "METH_NOARGS",
'''
errno = EBADF;
......@@ -266,7 +265,44 @@
PyErr_SetFromErrnoWithFilename(PyExc_OSError, "/path/to/%s");
return NULL;
''' % (char, )),
],
]
if sys.platform == "win32":
codestr += [
("set_from_windowserr", "METH_NOARGS",
"""
/* this error code has no message, Python formats it
as hexadecimal */
int code = 376526934;
PyObject *ret = PyErr_SetFromWindowsErr(code);
return NULL;
"""),
("set_from_windowserr_filename", "METH_O",
"""
int code = 376526934;
char *filename = NULL;
if (args != Py_None)
filename = PyBytes_AsString(args);
PyObject *ret = PyErr_SetFromWindowsErrWithFilename(code, filename);
return NULL;
"""),
("set_from_windowserr_filename_object", "METH_O",
"""
int code = 376526934;
PyObject *ret = PyErr_SetExcFromWindowsErrWithFilenameObject(PyExc_OSError, code, args);
return NULL;
"""),
("set_from_windowserr_filename_objects", "METH_VARARGS",
"""
int code = 376526934;
PyObject *arg1, *arg2;
if (!PyArg_ParseTuple(args, "OO", &arg1, &arg2)) {
return NULL;
}
PyObject *ret = PyErr_SetExcFromWindowsErrWithFilenameObjects(PyExc_OSError, code, arg1, arg2);
return NULL;
"""),
]
module = self.import_extension('foo', codestr,
prologue="#include <errno.h>")
exc_info = raises(OSError, module.set_from_errno)
assert exc_info.value.filename == "/path/to/file"
......@@ -281,6 +317,38 @@
# untranslated the errno can get reset by the calls to ll2ctypes
assert exc_info.value.errno == errno.EBADF
assert exc_info.value.strerror == os.strerror(errno.EBADF)
if sys.platform == "win32":
exc_info = raises(OSError, module.set_from_windowserr)
if self.runappdirect:
# untranslated the errno can get reset by the calls to ll2ctypes
assert exc_info.value.errno == 376526934
exc_info = raises(OSError, module.set_from_windowserr_filename,
None)
if self.runappdirect:
assert exc_info.value.errno == 376526934
exc_info = raises(OSError, module.set_from_windowserr_filename,
b"myfile.py")
if self.runappdirect:
assert exc_info.value.errno == 376526934
assert exc_info.value.filename == "myfile.py"
exc_info = raises(OSError, module.set_from_windowserr_filename_object,
"myfile.py")
print(exc_info.value.filename)
if self.runappdirect:
assert exc_info.value.errno == 376526934
assert exc_info.value.filename == "myfile.py"
exc_info = raises(OSError, module.set_from_windowserr_filename_objects,
"myfile.py", "myfile2.py")
print(exc_info.value, exc_info.value.filename)
if self.runappdirect:
assert exc_info.value.errno == 376526934
assert exc_info.value.filename == "myfile.py"
assert exc_info.value.filename2== "myfile2.py"
def test_SetFromErrnoWithFilename_NULL(self):
import errno, os
......
import pytest
import py
import os.path
import sys
from pypy.module.sys.initpath import (compute_stdlib_path_sourcetree,
find_executable, find_stdlib, resolvedirof, pypy_init_home, pypy_init_free,
find_pyvenv_cfg)
......@@ -14,8 +15,11 @@
return a, b
def build_hierarchy_package(prefix, platlibdir="lib"):
dot_ver = 'pypy%d.%d' % CPYTHON_VERSION[:2]
b = prefix.join(platlibdir, dot_ver).ensure(dir=1)
if sys.platform == "win32":
b = prefix.join(platlibdir).ensure(dir=1)
else:
dot_ver = 'pypy%d.%d' % CPYTHON_VERSION[:2]
b = prefix.join(platlibdir, dot_ver).ensure(dir=1)
b.join('site.py').ensure(dir=0)
return b
......@@ -32,7 +36,11 @@
assert prefix is not None
assert cwd.startswith(str(prefix))
@pytest.mark.parametrize("platlibdir", ["lib", "lib64"])
if sys.platform == "win32":
libdirnames = ["Lib"]
else:
libdirnames = ["lib", "lib64"]
@pytest.mark.parametrize("platlibdir", libdirnames)
def test_find_stdlib_package(tmpdir, platlibdir):
bin_dir = tmpdir.join('bin').ensure(dir=True)
pypy = bin_dir.join('pypy3').ensure(file=True)
......
......@@ -57,8 +57,6 @@
def setup_class(cls):
cls.w_appdirect = cls.space.wrap(cls.runappdirect)
filesystemenc = codecs.lookup(sys.getfilesystemencoding()).name
cls.w_filesystemenc = cls.space.wrap(filesystemenc)
def test_sys_in_modules(self):
import sys
......@@ -137,12 +135,8 @@
def test_getfilesystemencoding(self):
import sys
enc = sys.getfilesystemencoding()
# even before bootstraping, the encoding should match
assert enc == self.filesystemenc
if not self.appdirect:
# see comment in 'setup_after_space_initialization'
untranslated_enc = {'win32': 'utf-8', 'darwin': 'utf-8'}.get(enc, 'utf-8')
assert enc == untranslated_enc
# always utf-8
assert enc == "utf-8"
def test_float_info(self):
import sys
......@@ -230,5 +224,6 @@
def test_multiarch(self):
import sys
if sys.platform == 'linux':
multiarch = ''
try:
multiarch = sys.implementation._multiarch
......@@ -234,2 +229,5 @@
multiarch = sys.implementation._multiarch
except AttributeError:
assert sys.platform == 'win32'
else:
assert 'linux' in multiarch
......@@ -235,6 +233,4 @@
assert 'linux' in multiarch
else:
assert not sys.implemenation.hasattr('_multiarch')
def test_audit(self):
import sys
......
......@@ -31,7 +31,7 @@
cpyver = 'pypy%d.%d' % CPYTHON_VERSION[:2]
if sys.platform == 'win32':
stdlib = prefix.join('lib',)
stdpath = 'lib'
stdpath = 'Lib'
else:
stdlib = prefix.join('lib', cpyver)
stdpath = 'lib/%s' % cpyver
......