Commits

Dan Villiom Podlaski Christiansen committed fc17372

New patches; rebased.

Comments (0)

Files changed (9)

PyErr_SetFromErrnoWithFilename.diff

+# HG changeset patch
+# User Dan Villiom Podlaski Christiansen <danchr@gmail.com>
+# Date 1291283968 -3600
+# Node ID 51b13e0929ed26abb1658076aeff941d88cfda7d
+# Parent  9514352b706ff8f34f6f79f256f3d25e73b41021
+Add PyErr_SetFromErrnoWithFilename() to cpyext.
+
+diff --git a/pypy/module/cpyext/pyerrors.py b/pypy/module/cpyext/pyerrors.py
+--- a/pypy/module/cpyext/pyerrors.py
++++ b/pypy/module/cpyext/pyerrors.py
+@@ -114,10 +114,29 @@ def PyErr_SetFromErrno(space, w_type):
+     function around a system call can write return PyErr_SetFromErrno(type);
+     when the system call returns an error.
+     Return value: always NULL."""
++    PyErr_SetFromErrnoWithFilename(space, w_type,
++                                   lltype.nullptr(rffi.CCHARP.TO))
++
++@cpython_api([PyObject, rffi.CCHARP], PyObject)
++def PyErr_SetFromErrnoWithFilename(space, w_type, llfilename):
++    """Similar to PyErr_SetFromErrno(), with the additional behavior that if
++    filename is not NULL, it is passed to the constructor of type as a third
++    parameter.  In the case of exceptions such as IOError and OSError,
++    this is used to define the filename attribute of the exception instance.
++    Return value: always NULL."""
+     # XXX Doesn't actually do anything with PyErr_CheckSignals.
+     errno = get_errno()
+     msg = os.strerror(errno)
+-    w_error = space.call_function(w_type, space.wrap(errno), space.wrap(msg))
++    if llfilename:
++        w_filename = rffi.charp2str(llfilename)
++        w_error = space.call_function(w_type,
++                                      space.wrap(errno),
++                                      space.wrap(msg),
++                                      space.wrap(w_filename))
++    else:
++        w_error = space.call_function(w_type,
++                                      space.wrap(errno),
++                                      space.wrap(msg))
+     raise OperationError(w_type, w_error)
+ 
+ @cpython_api([], rffi.INT_real, error=-1)
+diff --git a/pypy/module/cpyext/stubs.py b/pypy/module/cpyext/stubs.py
+--- a/pypy/module/cpyext/stubs.py
++++ b/pypy/module/cpyext/stubs.py
+@@ -677,15 +677,6 @@ def PyErr_NormalizeException(space, exc,
+     The delayed normalization is implemented to improve performance."""
+     raise NotImplementedError
+ 
+-@cpython_api([PyObject, rffi.CCHARP], PyObject)
+-def PyErr_SetFromErrnoWithFilename(space, type, filename):
+-    """Similar to PyErr_SetFromErrno(), with the additional behavior that if
+-    filename is not NULL, it is passed to the constructor of type as a third
+-    parameter.  In the case of exceptions such as IOError and OSError,
+-    this is used to define the filename attribute of the exception instance.
+-    Return value: always NULL."""
+-    raise NotImplementedError
+-
+ @cpython_api([rffi.INT_real], PyObject)
+ def PyErr_SetFromWindowsErr(space, ierr):
+     """This is a convenience function to raise WindowsError. If called with
+diff --git a/pypy/module/cpyext/test/test_pyerrors.py b/pypy/module/cpyext/test/test_pyerrors.py
+--- a/pypy/module/cpyext/test/test_pyerrors.py
++++ b/pypy/module/cpyext/test/test_pyerrors.py
+@@ -149,3 +149,26 @@ class AppTestFetch(AppTestCpythonExtensi
+         except OSError, e:
+             assert e.errno == errno.EBADF
+             assert e.strerror == os.strerror(errno.EBADF)
++            assert e.filename == None
++
++    def test_SetFromErrnoWithFilename(self):
++        import sys
++        if sys.platform != 'win32':
++            skip("callbacks through ll2ctypes modify errno")
++        import errno, os
++
++        module = self.import_extension('foo', [
++                ("set_from_errno", "METH_NOARGS",
++                 '''
++                 errno = EBADF;
++                 PyErr_SetFromErrnoWithFilename(PyExc_OSError, "blyf");
++                 return NULL;
++                 '''),
++                ],
++                prologue="#include <errno.h>")
++        try:
++            module.set_from_errno()
++        except OSError, e:
++            assert e.filename == "blyf"
++            assert e.errno == errno.EBADF
++            assert e.strerror == os.strerror(errno.EBADF)

PyFile_GetLine.diff

 # HG changeset patch
-# Parent 75c929374e5954f5e52618825c074901e83a8652
 # User Dan Villiom Podlaski Christiansen <danchr@gmail.com>
+# Date 1291299275 -3600
+# Node ID 6c2786bd510f774e572e64ac5db5a4c5dc0d3971
+# Parent  51b13e0929ed26abb1658076aeff941d88cfda7d
 Add PyFile_GetLine() to cpyext.
 
-
 diff --git a/pypy/module/cpyext/object.py b/pypy/module/cpyext/object.py
 --- a/pypy/module/cpyext/object.py
 +++ b/pypy/module/cpyext/object.py
-@@ -438,3 +438,36 @@ def PyFile_FromString(space, filename, m
+@@ -438,3 +438,29 @@ def PyFile_FromString(space, filename, m
      w_mode = space.wrap(rffi.charp2str(mode))
      return space.call_method(space.builtin, 'file', w_filename, w_mode)
  
 +    0, however, one line is read regardless of length, but EOFError is
 +    raised if the end of the file is reached immediately."""
 +    try:
-+        w_meth = space.getattr(w_obj, space.wrap('readline'))
++        w_readline = space.getattr(w_obj, space.wrap('readline'))
 +    except OperationError:
 +        raise OperationError(
 +            space.w_TypeError, space.wrap(
 +            "argument must be a file, or have a readline() method."))
 +
-+    if n > 0:
-+        return space.call_method(p, 'readline', n)
-+    elif n == 0:
-+        return space.call_method(p, 'readline')
++    n = rffi.cast(lltype.Signed, n)
++    if space.is_true(space.gt(space.wrap(n), space.wrap(0))):
++        return space.call_function(w_readline, space.wrap(n))
++    elif space.is_true(space.lt(space.wrap(n), space.wrap(0))):
++        return space.call_function(w_readline)
 +    else:
-+        r = space.call_method(p, 'readline')
-+        offset = space.int_w(space.call_method(p, 'readline'))
-+
-+    if fd < 0:
-+        raise OperationError(
-+            space.w_ValueError, space.wrap(
-+            "file descriptor cannot be a negative integer"))
-+
-+    return rffi.cast(rffi.INT_real, fd)
-+        t = 
++        # XXX Raise EOFError as specified
++        return space.call_function(w_readline)
 diff --git a/pypy/module/cpyext/stubs.py b/pypy/module/cpyext/stubs.py
 --- a/pypy/module/cpyext/stubs.py
 +++ b/pypy/module/cpyext/stubs.py
-@@ -857,22 +857,6 @@ def PyFile_DecUseCount(space, p):
+@@ -848,22 +848,6 @@ def PyFile_DecUseCount(space, p):
      """
      raise NotImplementedError
  
  @cpython_api([PyObject], PyObject)
  def PyFile_Name(space, p):
      """Return the name of the file specified by p as a string object."""
+diff --git a/pypy/module/cpyext/test/test_object.py b/pypy/module/cpyext/test/test_object.py
+--- a/pypy/module/cpyext/test/test_object.py
++++ b/pypy/module/cpyext/test/test_object.py
+@@ -4,7 +4,7 @@ from pypy.module.cpyext.test.test_api im
+ from pypy.module.cpyext.test.test_cpyext import AppTestCpythonExtensionBase
+ from pypy.rpython.lltypesystem import rffi, lltype
+ from pypy.module.cpyext.api import Py_LT, Py_LE, Py_NE, Py_EQ,\
+-    Py_GE, Py_GT
++    Py_GE, Py_GT, fopen, fclose, fwrite
+ from pypy.tool.udir import udir
+ 
+ class TestObject(BaseApiTest):
+@@ -192,6 +192,37 @@ class TestObject(BaseApiTest):
+         space.call_method(w_file, "close")
+         assert (udir / "_test_file").read() == "text"
+ 
++    def test_file_getline(self, space, api):
++        filename = rffi.str2charp(str(udir / "_test_file"))
++
++        mode = rffi.str2charp("w")
++        w_file = api.PyFile_FromString(filename, mode)
++        space.call_method(w_file, "write",
++                          space.wrap("line1\nline2\nline3\nline4"))
++        space.call_method(w_file, "close")
++
++        rffi.free_charp(mode)
++        mode = rffi.str2charp("r")
++        w_file = api.PyFile_FromString(filename, mode)
++        rffi.free_charp(filename)
++        rffi.free_charp(mode)
++
++        w_line = api.PyFile_GetLine(w_file, 0)
++        assert space.str_w(w_line) == "line1\n"
++
++        w_line = api.PyFile_GetLine(w_file, 4)
++        assert space.str_w(w_line) == "line"
++
++        w_line = api.PyFile_GetLine(w_file, 0)
++        assert space.str_w(w_line) == "2\n"
++
++        # XXX We ought to raise an EOFError here, but don't
++        w_line = api.PyFile_GetLine(w_file, -1)
++        # assert api.PyErr_Occurred() is space.w_EOFError
++        assert space.str_w(w_line) == "line3\n"
++
++        space.call_method(w_file, "close")
++
+ class AppTestObject(AppTestCpythonExtensionBase):
+     def setup_class(cls):
+         AppTestCpythonExtensionBase.setup_class.im_func(cls)

distutils-darwin.diff

+# HG changeset patch
+# User Dan Villiom Podlaski Christiansen <danchr@gmail.com>
+# Date 1291319752 -3600
+# Node ID 269f0bc3faa12d2e55c13334f98844d5ec650d34
+# Parent 8545686ba120ea723bfcea9b4b8f5747cc5aca8d
+[mq]: distutils-darwin.diff
+
+diff --git a/lib-python/modified-2.5.2/distutils/unixccompiler.py b/lib-python/modified-2.5.2/distutils/unixccompiler.py
+--- a/lib-python/modified-2.5.2/distutils/unixccompiler.py
++++ b/lib-python/modified-2.5.2/distutils/unixccompiler.py
+@@ -121,7 +121,22 @@ class UnixCCompiler(CCompiler):
+                   }
+ 
+     if sys.platform[:6] == "darwin":
++        import platform
++        if platform.machine() == 'i386':
++            if platform.architecture()[0] == '32bit':
++                arch = 'i386'
++            else:
++                arch = 'x86_64'
++        else:
++            # just a guess
++            arch = platform.machine()
+         executables['ranlib'] = ["ranlib"]
++        executables['linker_so'] += ['-undefined', 'dynamic_lookup']
++
++        for k, v in executables.iteritems():
++            if v and v[0] == 'cc':
++                v += ['-arch', arch]
++
+ 
+     # Needed for the filename generation methods provided by the base
+     # class, CCompiler.  NB. whoever instantiates/uses a particular
 # HG changeset patch
-# Parent 5e253a7ab8f2b81de45bc31221c96879df1dbc6f
 # User Dan Villiom Podlaski Christiansen <danchr@gmail.com>
+# Date 1291082220 -3600
+# Node ID e7363c4981e93730b8e255a17cdae4684a6d7830
+# Parent  b21897a43cd1f47eebd986d72dd95dafcdd47ce3
 Add .hgignore file.
 
-
 diff --git a/.hgignore b/.hgignore
 new file mode 100644
 --- /dev/null
 # HG changeset patch
-# Parent 4500e46d368791b77def42e0b3fc1b2dab0d69cb
 # User Dan Villiom Podlaski Christiansen <danchr@gmail.com>
+# Date 1291082222 -3600
+# Node ID 4dd3038d50e42a15fcca3d0a6662978e4889ebd8
+# Parent  8684f2b4d0185417e69bdba8a91e853dba39be3f
 Fix building --shared on Mac OS X, when non-default architecture is used.
 
 diff --git a/pypy/translator/platform/posix.py b/pypy/translator/platform/posix.py
 # HG changeset patch
 # User Dan Villiom Podlaski Christiansen <danchr@gmail.com>
 # Date 1291027470 -3600
-# Node ID 4500e46d368791b77def42e0b3fc1b2dab0d69cb
-# Parent  a1e1bdba7d9a5299c4abf18a9f96cdd08f98c32b
+# Node ID 8684f2b4d0185417e69bdba8a91e853dba39be3f
+# Parent  e7363c4981e93730b8e255a17cdae4684a6d7830
 don't search MacPorts & Fink by default.
 
 diff --git a/pypy/translator/platform/darwin.py b/pypy/translator/platform/darwin.py
 no-macports.diff
 ldflags.diff
 strip-x.diff
-PyFile_GetLine.diff #+incomplete
+PyErr_SetFromErrnoWithFilename.diff
+PyFile_GetLine.diff
+visibility.diff
+distutils-darwin.diff
 # HG changeset patch
-# Parent a8e1a141165890dd6f6b2dc304df3ac406e668ac
 # User Dan Villiom Podlaski Christiansen <danchr@gmail.com>
+# Date 1291114821 -3600
+# Node ID 9514352b706ff8f34f6f79f256f3d25e73b41021
+# Parent  4dd3038d50e42a15fcca3d0a6662978e4889ebd8
 Don't strip exported symbols in package.py
 
 Doing so breaks cpyext on Mac OS X.
 
-
 diff --git a/pypy/tool/release/package.py b/pypy/tool/release/package.py
 --- a/pypy/tool/release/package.py
 +++ b/pypy/tool/release/package.py
+# HG changeset patch
+# User Dan Villiom Podlaski Christiansen <danchr@gmail.com>
+# Date 1291299495 -3600
+# Node ID 8545686ba120ea723bfcea9b4b8f5747cc5aca8d
+# Parent  6c2786bd510f774e572e64ac5db5a4c5dc0d3971
+Make symbols hidden by default.
+
+diff --git a/pypy/module/cpyext/include/Python.h b/pypy/module/cpyext/include/Python.h
+--- a/pypy/module/cpyext/include/Python.h
++++ b/pypy/module/cpyext/include/Python.h
+@@ -9,8 +9,13 @@
+ # include <limits.h>
+ # include <math.h>
+ # define Py_DEPRECATED(VERSION_UNUSED) __attribute__((__deprecated__))
+-# define PyAPI_FUNC(RTYPE) RTYPE
+-# define PyAPI_DATA(RTYPE) extern RTYPE
++# if defined(__GCC__) && defined(Py_BUILD_CORE)
++#  define PyAPI_FUNC(RTYPE) __attribute__((externally_visible)) RTYPE
++#  define PyAPI_DATA(RTYPE) __attribute__((externally_visible)) extern RTYPE
++# else
++#  define PyAPI_FUNC(RTYPE) RTYPE
++#  define PyAPI_DATA(RTYPE) extern RTYPE
++# endif
+ # define Py_LOCAL_INLINE(type) static inline type
+ #else
+ # define MS_WIN32 1
+diff --git a/pypy/module/test_lib_pypy/ctypes_tests/_ctypes_test.c b/pypy/module/test_lib_pypy/ctypes_tests/_ctypes_test.c
+--- a/pypy/module/test_lib_pypy/ctypes_tests/_ctypes_test.c
++++ b/pypy/module/test_lib_pypy/ctypes_tests/_ctypes_test.c
+@@ -5,6 +5,8 @@
+ 
+ #if defined(MS_WIN32)
+ #define EXPORT(x) __declspec(dllexport) x
++#elif defined(__GCC__)
++#define EXPORT(x) __attribute__((externally_visible)) x
+ #else
+ #define EXPORT(x) x
+ #endif
+diff --git a/pypy/translator/platform/darwin.py b/pypy/translator/platform/darwin.py
+--- a/pypy/translator/platform/darwin.py
++++ b/pypy/translator/platform/darwin.py
+@@ -5,7 +5,7 @@ from pypy.translator.platform import pos
+ class Darwin(posix.BasePosix):
+     name = "darwin"
+ 
+-    link_flags = ('-mmacosx-version-min=10.4',)
++    link_flags = ('-mmacosx-version-min=10.4', '-fvisibility=hidden')
+     cflags = ('-O3', '-fomit-frame-pointer', '-mmacosx-version-min=10.4')
+     standalone_only = ('-mdynamic-no-pic',)
+     shared_only = ()