[pypy-svn] r79830 - in pypy/trunk: . lib-python/modified-2.5.2/distutils pypy pypy/jit/metainterp/optimizeopt pypy/module/array/benchmark pypy/module/array/test pypy/module/cpyext pypy/module/cpyext/test pypy/rlib pypy/rlib/test pypy/tool/release pypy/translator/platform

danchr at codespeak.net danchr at codespeak.net
Sat Dec 4 23:44:22 CET 2010


Author: danchr
Date: Sat Dec  4 23:44:20 2010
New Revision: 79830

Modified:
   pypy/trunk/   (props changed)
   pypy/trunk/lib-python/modified-2.5.2/distutils/unixccompiler.py
   pypy/trunk/pypy/   (props changed)
   pypy/trunk/pypy/jit/metainterp/optimizeopt/optimizer.py   (props changed)
   pypy/trunk/pypy/module/array/benchmark/Makefile   (props changed)
   pypy/trunk/pypy/module/array/benchmark/intimg.c   (props changed)
   pypy/trunk/pypy/module/array/benchmark/intimgtst.c   (props changed)
   pypy/trunk/pypy/module/array/benchmark/intimgtst.py   (props changed)
   pypy/trunk/pypy/module/array/benchmark/loop.c   (props changed)
   pypy/trunk/pypy/module/array/benchmark/sum.c   (props changed)
   pypy/trunk/pypy/module/array/benchmark/sumtst.c   (props changed)
   pypy/trunk/pypy/module/array/benchmark/sumtst.py   (props changed)
   pypy/trunk/pypy/module/array/test/test_array_old.py   (props changed)
   pypy/trunk/pypy/module/cpyext/object.py
   pypy/trunk/pypy/module/cpyext/pyerrors.py
   pypy/trunk/pypy/module/cpyext/stubs.py
   pypy/trunk/pypy/module/cpyext/test/test_object.py
   pypy/trunk/pypy/module/cpyext/test/test_pyerrors.py
   pypy/trunk/pypy/rlib/rerased.py   (props changed)
   pypy/trunk/pypy/rlib/test/test_rerased.py   (props changed)
   pypy/trunk/pypy/tool/release/package.py
   pypy/trunk/pypy/translator/platform/posix.py
Log:
Merge branch cpyext-darwin

This contains fixes to allow building C extensions on Darwin, and a few extra C APIs as well.



Modified: pypy/trunk/lib-python/modified-2.5.2/distutils/unixccompiler.py
==============================================================================
--- pypy/trunk/lib-python/modified-2.5.2/distutils/unixccompiler.py	(original)
+++ pypy/trunk/lib-python/modified-2.5.2/distutils/unixccompiler.py	Sat Dec  4 23:44:20 2010
@@ -121,7 +121,22 @@
                   }
 
     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

Modified: pypy/trunk/pypy/module/cpyext/object.py
==============================================================================
--- pypy/trunk/pypy/module/cpyext/object.py	(original)
+++ pypy/trunk/pypy/module/cpyext/object.py	Sat Dec  4 23:44:20 2010
@@ -2,12 +2,13 @@
 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,34 @@
         rffi.free_nonmovingbuffer(data, buf)
     return 0
 
+PyFile_Check, PyFile_CheckExact = build_type_checkers("File", W_File)
+
+ at 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):
     """
@@ -437,4 +466,3 @@
     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)
-

Modified: pypy/trunk/pypy/module/cpyext/pyerrors.py
==============================================================================
--- pypy/trunk/pypy/module/cpyext/pyerrors.py	(original)
+++ pypy/trunk/pypy/module/cpyext/pyerrors.py	Sat Dec  4 23:44:20 2010
@@ -129,10 +129,29 @@
     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))
+
+ at 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)

Modified: pypy/trunk/pypy/module/cpyext/stubs.py
==============================================================================
--- pypy/trunk/pypy/module/cpyext/stubs.py	(original)
+++ pypy/trunk/pypy/module/cpyext/stubs.py	Sat Dec  4 23:44:20 2010
@@ -668,15 +668,6 @@
     """
     raise NotImplementedError
 
- at 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
@@ -800,21 +791,6 @@
     successful invocation of Py_EnterRecursiveCall()."""
     raise NotImplementedError
 
- at 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
-
- at 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
@@ -848,22 +824,6 @@
     """
     raise NotImplementedError
 
- at 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."""

Modified: pypy/trunk/pypy/module/cpyext/test/test_object.py
==============================================================================
--- pypy/trunk/pypy/module/cpyext/test/test_object.py	(original)
+++ pypy/trunk/pypy/module/cpyext/test/test_object.py	Sat Dec  4 23:44:20 2010
@@ -4,7 +4,7 @@
 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):
@@ -188,10 +188,45 @@
         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"
 
+    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)

Modified: pypy/trunk/pypy/module/cpyext/test/test_pyerrors.py
==============================================================================
--- pypy/trunk/pypy/module/cpyext/test/test_pyerrors.py	(original)
+++ pypy/trunk/pypy/module/cpyext/test/test_pyerrors.py	Sat Dec  4 23:44:20 2010
@@ -184,3 +184,26 @@
         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)

Modified: pypy/trunk/pypy/tool/release/package.py
==============================================================================
--- pypy/trunk/pypy/tool/release/package.py	(original)
+++ pypy/trunk/pypy/tool/release/package.py	Sat Dec  4 23:44:20 2010
@@ -78,7 +78,7 @@
     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')

Modified: pypy/trunk/pypy/translator/platform/posix.py
==============================================================================
--- pypy/trunk/pypy/translator/platform/posix.py	(original)
+++ pypy/trunk/pypy/translator/platform/posix.py	Sat Dec  4 23:44:20 2010
@@ -166,7 +166,7 @@
                    '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
 



More information about the Pypy-commit mailing list