Commits

Dan Villiom Podlaski Christiansen  committed c2234e9

Rebased.

  • Participants
  • Parent commits 5e43501

Comments (0)

Files changed (10)

File PyErr_SetFromErrnoWithFilename.diff

-# HG changeset patch
-# User Dan Villiom Podlaski Christiansen <danchr@gmail.com>
-# Date 1291283968 -3600
-# Node ID 99ab5db13b38598d0495a18014e4945a9bb4ff83
-# Parent a0af46c5ab4aee94602f673bf1786431adddc6b5
-Implement PyErr_SetFromErrnoWithFilename()
-
-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
-@@ -129,10 +129,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
-@@ -668,15 +668,6 @@ def PyDict_MergeFromSeq2(space, a, seq2,
-     """
-     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
-@@ -185,3 +185,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)

File PyFile_Check.diff

-Implement PyFile_Check & PyFile_CheckExact
-
-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
-@@ -2,12 +2,13 @@ from pypy.rpython.lltypesystem import rf
- from pypy.module.cpyext.api import (
-     cpython_api, generic_cpy_call, CANNOT_FAIL, Py_ssize_t, Py_ssize_tP,
-     PyVarObject, Py_TPFLAGS_HEAPTYPE, Py_LT, Py_LE, Py_EQ, Py_NE, Py_GT,
--    Py_GE, CONST_STRING, FILEP, fwrite)
-+    Py_GE, CONST_STRING, FILEP, fwrite, build_type_checkers)
- from pypy.module.cpyext.pyobject import (
-     PyObject, PyObjectP, create_ref, from_ref, Py_IncRef, Py_DecRef,
-     track_reference, get_typedescr, RefcountState)
- from pypy.module.cpyext.typeobject import PyTypeObjectPtr
- from pypy.module.cpyext.pyerrors import PyErr_NoMemory, PyErr_BadInternalCall
-+from pypy.module._file.interp_file import W_File
- from pypy.objspace.std.objectobject import W_ObjectObject
- from pypy.objspace.std.typeobject import W_TypeObject
- from pypy.interpreter.error import OperationError
-@@ -428,6 +429,8 @@ def PyObject_Print(space, w_obj, fp, fla
-         rffi.free_nonmovingbuffer(data, buf)
-     return 0
- 
-+PyFile_Check, PyFile_CheckExact = build_type_checkers("File", W_File)
-+
- @cpython_api([CONST_STRING, CONST_STRING], PyObject)
- def PyFile_FromString(space, filename, mode):
-     """
-@@ -437,4 +440,3 @@ def PyFile_FromString(space, filename, m
-     w_filename = space.wrap(rffi.charp2str(filename))
-     w_mode = space.wrap(rffi.charp2str(mode))
-     return space.call_method(space.builtin, 'file', w_filename, w_mode)
--
-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
-@@ -791,21 +791,6 @@ def Py_LeaveRecursiveCall(space, ):
-     successful invocation of Py_EnterRecursiveCall()."""
-     raise NotImplementedError
- 
--@cpython_api([PyObject], rffi.INT_real, error=CANNOT_FAIL)
--def PyFile_Check(space, p):
--    """Return true if its argument is a PyFileObject or a subtype of
--    PyFileObject.
--    
--    Allowed subtypes to be accepted."""
--    raise NotImplementedError
--
--@cpython_api([PyObject], rffi.INT_real, error=CANNOT_FAIL)
--def PyFile_CheckExact(space, p):
--    """Return true if its argument is a PyFileObject, but not a subtype of
--    PyFileObject.
--    """
--    raise NotImplementedError
--
- @cpython_api([FILE, rffi.CCHARP, rffi.CCHARP, rffi.INT_real], PyObject)
- def PyFile_FromFile(space, fp, name, mode, close):
-     """Create a new PyFileObject from the already-open standard C file
-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
-@@ -188,6 +188,10 @@ class TestObject(BaseApiTest):
-         rffi.free_charp(filename)
-         rffi.free_charp(mode)
- 
-+        assert api.PyFile_Check(w_file)
-+        assert api.PyFile_CheckExact(w_file)
-+        assert not api.PyFile_Check(space.wrap("text"))
-+
-         space.call_method(w_file, "write", space.wrap("text"))
-         space.call_method(w_file, "close")
-         assert (udir / "_test_file").read() == "text"

File PyFile_GetLine.diff

-# HG changeset patch
-# User Dan Villiom Podlaski Christiansen <danchr@gmail.com>
-# Date 1291299275 -3600
-# Node ID 441af35de2a883632de8b79a6b7e9b8dcfd651aa
-# Parent e37f4a3d54ba8f2d01902feabea7f083f08bdf48
-Implement PyFile_GetLine()
-
-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
-@@ -431,6 +431,32 @@ def PyObject_Print(space, w_obj, fp, fla
- 
- PyFile_Check, PyFile_CheckExact = build_type_checkers("File", W_File)
- 
-+@cpython_api([PyObject, rffi.INT_real], PyObject)
-+def PyFile_GetLine(space, w_obj, n):
-+    """
-+    Equivalent to p.readline([n]), this function reads one line from the
-+    object p.  p may be a file object or any object with a readline()
-+    method.  If n is 0, exactly one line is read, regardless of the length of
-+    the line.  If n is greater than 0, no more than n bytes will be read
-+    from the file; a partial line can be returned.  In both cases, an empty string
-+    is returned if the end of the file is reached immediately.  If n is less than
-+    0, however, one line is read regardless of length, but EOFError is
-+    raised if the end of the file is reached immediately."""
-+    try:
-+        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."))
-+
-+    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:
-+        # XXX Raise EOFError as specified
-+        return space.call_function(w_readline)
- @cpython_api([CONST_STRING, CONST_STRING], PyObject)
- def PyFile_FromString(space, filename, mode):
-     """
-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
-@@ -824,22 +824,6 @@ def PyFile_DecUseCount(space, p):
-     """
-     raise NotImplementedError
- 
--@cpython_api([PyObject, rffi.INT_real], PyObject)
--def PyFile_GetLine(space, p, n):
--    """
--    
--    
--    
--    Equivalent to p.readline([n]), this function reads one line from the
--    object p.  p may be a file object or any object with a readline()
--    method.  If n is 0, exactly one line is read, regardless of the length of
--    the line.  If n is greater than 0, no more than n bytes will be read
--    from the file; a partial line can be returned.  In both cases, an empty string
--    is returned if the end of the file is reached immediately.  If n is less than
--    0, however, one line is read regardless of length, but EOFError is
--    raised if the end of the file is reached immediately."""
--    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):
-@@ -196,6 +196,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)

File distutils-darwin.diff

-# HG changeset patch
-# User Dan Villiom Podlaski Christiansen <danchr@gmail.com>
-# Date 1291319752 -3600
-# Node ID a0af46c5ab4aee94602f673bf1786431adddc6b5
-# Parent  1e986c193e5cc3e250ee3d7d4ace588b30a1a155
-distutils: Add hack to allow building C extensions on Mac OS X.
-
-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

File hgignore.diff

 # HG changeset patch
 # User Dan Villiom Podlaski Christiansen <danchr@gmail.com>
 # Date 1291082220 -3600
-# Node ID bcd9c01261490dd6c2eb1f357551c9d7af31abcc
-# Parent 46a96f7bb3a69c837e3fa1931cb788f05bf0e1ea
+# Node ID 2ee51a5071556ba8eb7fc67efbb4c84138a633fd
+# Parent  29e62ab543ac62c117ee2522eaed6f49c51e480f
 Add .hgignore file.
 
 diff --git a/.hgignore b/.hgignore

File ldflags.diff

-# HG changeset patch
-# User Dan Villiom Podlaski Christiansen <danchr@gmail.com>
-# Date 1291082222 -3600
-# Node ID 9b443916cc6560481dfbdc8ec3c6f1be2f3667cf
-# Parent  4115b2d56b6e4d46f857ea56351556e5e0fecdd5
-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
---- a/pypy/translator/platform/posix.py
-+++ b/pypy/translator/platform/posix.py
-@@ -166,7 +166,7 @@ class BasePosix(Platform):
-                    'int main(int argc, char* argv[]) '
-                    '{ return $(PYPY_MAIN_FUNCTION)(argc, argv); }" > $@')
-             m.rule('$(DEFAULT_TARGET)', ['$(TARGET)', 'main.o'],
--                   '$(CC_LINK) main.o -L. -l$(SHARED_IMPORT_LIB) -o $@')
-+                   '$(CC_LINK) $(LDFLAGS) $(LDFLAGSEXTRA) main.o -L. -l$(SHARED_IMPORT_LIB) -o $@')
- 
-         return m
- 

File no-macports.diff

 # HG changeset patch
 # User Dan Villiom Podlaski Christiansen <danchr@gmail.com>
 # Date 1291027470 -3600
-# Node ID 4115b2d56b6e4d46f857ea56351556e5e0fecdd5
-# Parent  bcd9c01261490dd6c2eb1f357551c9d7af31abcc
+# Node ID 95c89a393a7e6394645ad7da50be1e6095708593
+# Parent  2ee51a5071556ba8eb7fc67efbb4c84138a633fd
 don't search MacPorts & Fink by default.
 
 diff --git a/pypy/translator/platform/darwin.py b/pypy/translator/platform/darwin.py
 hgignore.diff
 no-macports.diff
-ldflags.diff
-strip-x.diff
-distutils-darwin.diff
-PyErr_SetFromErrnoWithFilename.diff
-PyFile_Check.diff
-PyFile_GetLine.diff
 visibility.diff

File strip-x.diff

-# HG changeset patch
-# User Dan Villiom Podlaski Christiansen <danchr@gmail.com>
-# Date 1291114821 -3600
-# Node ID 1e986c193e5cc3e250ee3d7d4ace588b30a1a155
-# Parent  9b443916cc6560481dfbdc8ec3c6f1be2f3667cf
-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
-@@ -78,7 +78,7 @@ def package(basedir, name='pypy-nightly'
-     old_dir = os.getcwd()
-     try:
-         os.chdir(str(builddir))
--        os.system("strip " + str(archive_pypy_c))    # ignore errors
-+        os.system("strip -x " + str(archive_pypy_c))    # ignore errors
-         if USE_TARFILE_MODULE:
-             import tarfile
-             tf = tarfile.open(str(builddir.join(name + '.tar.bz2')), 'w:bz2')

File visibility.diff

 # HG changeset patch
 # User Dan Villiom Podlaski Christiansen <danchr@gmail.com>
 # Date 1291299495 -3600
-# Node ID d19a93fb3d88f5375c7567aeb9a18548fc842040
-# Parent  441af35de2a883632de8b79a6b7e9b8dcfd651aa
+# Node ID f9d7ce274a489bfd1a7d19cca8177cfeddcdd31f
+# Parent  0a9df09ab71639e0ee064066b2895ea01a5f8063
 Make symbols hidden by default.
 
 diff --git a/pypy/module/cpyext/include/Python.h b/pypy/module/cpyext/include/Python.h