Author: Armin Rigo <[email protected]>
Branch: errno-again
Changeset: r75340:8f429ef3128d
Date: 2015-01-15 12:11 +0100
http://bitbucket.org/pypy/pypy/changeset/8f429ef3128d/

Log:    Translation fix. Add translated test.

diff --git a/rpython/jit/backend/llsupport/llerrno.py 
b/rpython/jit/backend/llsupport/llerrno.py
--- a/rpython/jit/backend/llsupport/llerrno.py
+++ b/rpython/jit/backend/llsupport/llerrno.py
@@ -13,7 +13,7 @@
 def get_rpy_errno_offset(cpu):
     if cpu.translate_support_code:
         from rpython.rlib import rthread
-        return rthread.tlfield_rpy_errno.offset
+        return rthread.tlfield_rpy_errno.getoffset()
     else:
         return 3 * WORD
 
@@ -32,8 +32,10 @@
 def get_p_errno_offset(cpu):
     if cpu.translate_support_code:
         from rpython.rlib import rthread
-        return rthread.tlfield_p_errno.offset
+        return rthread.tlfield_p_errno.getoffset()
     else:
+        # fetch the real address of errno (in this thread), and store it
+        # at offset 2 in the _debug_errno_container
         if cpu._debug_errno_container[2] == 0:
             addr_errno = _fetch_addr_errno()
             assert addr_errno != 0
diff --git a/rpython/jit/backend/llsupport/test/zrpy_releasegil_test.py 
b/rpython/jit/backend/llsupport/test/zrpy_releasegil_test.py
--- a/rpython/jit/backend/llsupport/test/zrpy_releasegil_test.py
+++ b/rpython/jit/backend/llsupport/test/zrpy_releasegil_test.py
@@ -2,6 +2,8 @@
 from rpython.rlib.jit import dont_look_inside
 from rpython.rlib.objectmodel import invoke_around_extcall
 from rpython.jit.metainterp.optimizeopt import ALL_OPTS_NAMES
+from rpython.translator.tool.cbuild import ExternalCompilationInfo
+from rpython.rlib import rposix
 
 from rpython.rtyper.annlowlevel import llhelper
 
@@ -96,23 +98,36 @@
         self.run('close_stack')
         assert 'call_release_gil' in 
udir.join('TestCompileFramework.log').read()
 
-    ## def define_get_set_errno(self):
+    def define_get_set_errno(self):
+        eci = ExternalCompilationInfo(
+            post_include_bits=[r'''
+                #include <errno.h>
+                static int test_get_set_errno(void) {
+                    int r = errno;
+                    //fprintf(stderr, "read saved errno: %d\n", r);
+                    errno = 42;
+                    return r;
+                }
+            '''])
 
-    ##     c_strchr = rffi.llexternal('strchr', [rffi.CCHARP, lltype.Signed],
-    ##                                rffi.CCHARP, ...
+        c_test = rffi.llexternal('test_get_set_errno', [], rffi.INT,
+                                 compilation_info=eci,
+                                 save_err=rffi.RFFI_FULL_ERRNO)
 
-    ##     def before(n, x):
-    ##         return (n, None, None, None, None, None,
-    ##                 None, None, None, None, None, None)
-    ##     #
-    ##     def f(n, x, *args):
-    ##         a = rffi.str2charp(str(n))
-    ##         c_strchr(a, ord('0'))
-    ##         lltype.free(a, flavor='raw')
-    ##         n -= 1
-    ##         return (n, x) + args
-    ##     return before, f, None
+        def before(n, x):
+            return (n, None, None, None, None, None,
+                    None, None, None, None, None, None)
+        #
+        def f(n, x, *args):
+            rposix.set_saved_errno(24)
+            result1 = c_test()
+            result2 = rposix.get_saved_errno()
+            assert result1 == 24
+            assert result2 == 42
+            n -= 1
+            return (n, x) + args
+        return before, f, None
 
-    ## def test_get_set_errno(self):
-    ##     self.run('get_set_errno')
-    ##     assert 'call_release_gil' in 
udir.join('TestCompileFramework.log').read()
+    def test_get_set_errno(self):
+        self.run('get_set_errno')
+        assert 'call_release_gil' in 
udir.join('TestCompileFramework.log').read()
diff --git a/rpython/rlib/rthread.py b/rpython/rlib/rthread.py
--- a/rpython/rlib/rthread.py
+++ b/rpython/rlib/rthread.py
@@ -309,9 +309,14 @@
             else:
                 self.local.rawvalue = value
 
+        def getoffset():
+            _threadlocalref_seeme(self)
+            return offset
+
         self.getraw = getraw
         self.get_or_make_raw = get_or_make_raw
         self.setraw = setraw
+        self.getoffset = getoffset
 
     def _freeze_(self):
         return True
diff --git a/rpython/translator/c/src/threadlocal.c 
b/rpython/translator/c/src/threadlocal.c
--- a/rpython/translator/c/src/threadlocal.c
+++ b/rpython/translator/c/src/threadlocal.c
@@ -12,6 +12,9 @@
 static void _RPy_ThreadLocals_Init(void *p)
 {
     memset(p, 0, sizeof(struct pypy_threadlocal_s));
+#ifdef RPY_TLOFS_p_errno
+    ((struct pypy_threadlocal_s *)p)->p_errno = &errno;
+#endif
 #ifdef RPY_TLOFS_thread_ident
     ((struct pypy_threadlocal_s *)p)->thread_ident =
 #    ifdef _WIN32
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to