Commit db8b9589 authored by Kevin Modzelewski's avatar Kevin Modzelewski

Merge commit '5e640' into refcounting

parents 1e516e5d 5e64050e
......@@ -16,13 +16,6 @@
#define PYSTON_NOEXCEPT
#endif
// HACK: we should set this manually rather than cluing off of the C++ version
#ifdef __cplusplus
#if __cplusplus > 199711L
#define _PYSTON_API
#endif
#endif
#define Py_PROTO(x) x
// Pyston change: these are just hard-coded for now:
......
......@@ -168,6 +168,12 @@ class _closedsocket(object):
__slots__ = []
def _dummy(*args):
raise error(EBADF, 'Bad file descriptor')
# Pyston change: socket close: add refcounting similar to pypy approach
def _reuse(self):
pass
def _drop(self):
pass
# All _delegate_methods must also be initialized here.
send = recv = recv_into = sendto = recvfrom = recvfrom_into = _dummy
__getattr__ = _dummy
......@@ -176,6 +182,9 @@ class _closedsocket(object):
# a platform-independent dup() functionality. The
# implementation currently relies on reference counting
# to close the underlying socket object.
# Pyston change: socket close: we workaround the socket closing problem similar to pypy
# by manually keeping track of the ref count.
# When we switch to ref counting we should remove this changes!
class _socketobject(object):
__doc__ = _realsocket.__doc__
......@@ -185,6 +194,11 @@ class _socketobject(object):
def __init__(self, family=AF_INET, type=SOCK_STREAM, proto=0, _sock=None):
if _sock is None:
_sock = _realsocket(family, type, proto)
# Pyston change: socket close: add refcounting similar to pypys approach
else:
_sock._reuse()
self._sock = _sock
for method in _delegate_methods:
setattr(self, method, getattr(_sock, method))
......@@ -192,6 +206,10 @@ class _socketobject(object):
def close(self, _closedsocket=_closedsocket,
_delegate_methods=_delegate_methods, setattr=setattr):
# This function should not reference any globals. See issue #808164.
# Pyston change: socket close: add refcounting similar to pypys approach
self._sock._drop()
self._sock = _closedsocket()
dummy = self._sock._dummy
for method in _delegate_methods:
......@@ -200,7 +218,13 @@ class _socketobject(object):
def accept(self):
sock, addr = self._sock.accept()
return _socketobject(_sock=sock), addr
# Pyston change: socket close: add refcounting similar to pypys approach
# return _socketobject(_sock=sock), addr
sockcopy = _socketobject(_sock=sock)
sock._drop()
return sockcopy, addr
accept.__doc__ = _realsocket.accept.__doc__
def dup(self):
......@@ -245,6 +269,10 @@ class _fileobject(object):
def __init__(self, sock, mode='rb', bufsize=-1, close=False):
self._sock = sock
# Pyston change: socket close: add refcounting similar to pypys approach
sock._reuse()
self.mode = mode # Not actually used in this version
if bufsize < 0:
bufsize = self.default_bufsize
......@@ -280,6 +308,11 @@ class _fileobject(object):
finally:
if self._close:
self._sock.close()
# Pyston change: socket close: add refcounting similar to pypys approach
else:
self._sock._drop()
self._sock = None
def __del__(self):
......
......@@ -156,6 +156,9 @@ class SSLSocket(socket):
self.suppress_ragged_eofs = suppress_ragged_eofs
self._makefile_refs = 0
# Pyston change: socket close: we have to decrease the socket refcount by calling close (pypy does the same)
sock.close()
def read(self, len=1024):
"""Read up to LEN bytes and return them.
......@@ -371,11 +374,21 @@ class SSLSocket(socket):
works with the SSL connection. Just use the code
from the socket module."""
self._makefile_refs += 1
# Pyston change: socket close: we increase the refcount inside _fileobject.__init__
# self._makefile_refs += 1
# close=True so as to decrement the reference count when done with
# the file-like object.
return _fileobject(self, mode, bufsize, close=True)
# Pyston change: socket close: add refcounting similar to pypys approach
def _reuse(self):
self._makefile_refs += 1
def _drop(self):
if self._makefile_refs < 1:
self.close()
else:
self._makefile_refs -= 1
def wrap_socket(sock, keyfile=None, certfile=None,
......
# expected: fail
# test asynchat
import asyncore, asynchat, socket, time
......
# expected: fail
import asyncore
import unittest
import select
......
# expected: fail
"""Test script for ftplib module."""
# Modified by Giampaolo Rodola' to test FTP class, IPv6 and TLS
......
# expected: fail
import httplib
import array
import httplib
......
# expected: fail
"""Test script for poplib module."""
# Modified by Giampaolo Rodola' to give poplib.POP3 and poplib.POP3_SSL
......
# expected: fail
# Test the support for SSL and sockets
import sys
......
# expected: fail
import socket
import telnetlib
import time
......
# expected: fail
import unittest
from test import test_support
from test.test_urllib2 import sanepathname2url
......
# expected: fail
import unittest
from test import test_support
......
......@@ -1200,6 +1200,11 @@ class AbstractHTTPHandler(BaseHandler):
# out of socket._fileobject() and into a base class.
r.recv = r.read
# Pyston change: socket close: add refcounting similar to pypys approach
r._reuse = lambda: None
r._drop = lambda: None
fp = socket._fileobject(r, close=True)
resp = addinfourl(fp, r.msg, req.get_full_url())
......
......@@ -789,6 +789,9 @@ init_sockobject(PySocketSockObject *s,
s->errorhandler = &set_error;
// Pyston change: socket close: add refcounting similar to pypys approach
s->close_ref_count = 1;
if (defaulttimeout >= 0.0)
internal_setblocking(s, 0);
......@@ -2983,6 +2986,21 @@ sock_shutdown(PySocketSockObject *s, PyObject *arg)
return Py_None;
}
// Pyston change: socket close: add refcounting similar to pypys approach
static PyObject *
sock_reuse(PySocketSockObject *s) {
assert(s->close_ref_count > 0);
++s->close_ref_count;
return Py_None;
}
static PyObject *
sock_drop(PySocketSockObject *s) {
--s->close_ref_count;
if (s->close_ref_count <= 0)
sock_close(s);
return Py_None;
}
PyDoc_STRVAR(shutdown_doc,
"shutdown(flag)\n\
\n\
......@@ -3099,6 +3117,11 @@ static PyMethodDef sock_methods[] = {
{"sleeptaskw", (PyCFunction)sock_sleeptaskw, METH_O,
sleeptaskw_doc},
#endif
// Pyston change: socket close: add refcounting similar to pypys approach
{"_reuse", (PyCFunction)sock_reuse, METH_NOARGS, NULL},
{"_drop", (PyCFunction)sock_drop, METH_NOARGS, NULL},
{NULL, NULL} /* sentinel */
};
......
......@@ -132,6 +132,9 @@ typedef struct {
sets a Python exception */
double sock_timeout; /* Operation timeout in seconds;
0.0 means non-blocking */
// Pyston change: socket close: add refcounting similar to pypys approach
int close_ref_count;
} PySocketSockObject;
/* --- C API ----------------------------------------------------*/
......
set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_CXX_FLAGS_DEBUG "-g -DBINARY_SUFFIX= -DBINARY_STRIPPED_SUFFIX=_stripped -DPy_BUILD_CORE")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -fstrict-aliasing -enable-tbaa -DNVALGRIND -DBINARY_SUFFIX=_release -DBINARY_STRIPPED_SUFFIX= -DPy_BUILD_CORE")
set(CMAKE_CXX_FLAGS_DEBUG "-g -DBINARY_SUFFIX= -DBINARY_STRIPPED_SUFFIX=_stripped -DPy_BUILD_CORE -D_PYSTON_API")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -fstrict-aliasing -enable-tbaa -DNVALGRIND -DBINARY_SUFFIX=_release -DBINARY_STRIPPED_SUFFIX= -DPy_BUILD_CORE -D_PYSTON_API")
execute_process(COMMAND git rev-parse HEAD WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} OUTPUT_VARIABLE GITREV OUTPUT_STRIP_TRAILING_WHITESPACE)
set_source_files_properties(jit.cpp PROPERTIES COMPILE_DEFINITIONS "GITREV=${GITREV}")
......
......@@ -21,6 +21,7 @@
#include "llvm/Support/Memory.h"
#include "codegen/irgen/util.h"
#include "codegen/unwinding.h"
#include "core/common.h"
#include "core/stats.h"
#include "core/util.h"
......@@ -211,6 +212,11 @@ uint64_t PystonMemoryManager::getSymbolAddress(const std::string& name) {
if (base)
return base;
// make sure our own c++ exc implementations symbols get used instead of gcc ones.
base = getCXXUnwindSymbolAddress(name);
if (base)
return base;
base = RTDyldMemoryManager::getSymbolAddress(name);
if (base)
return base;
......
......@@ -32,6 +32,8 @@ class BoxedTraceback;
struct FrameInfo;
void registerDynamicEhFrame(uint64_t code_addr, size_t code_size, uint64_t eh_frame_addr, size_t eh_frame_size);
uint64_t getCXXUnwindSymbolAddress(llvm::StringRef sym);
bool isUnwinding(); // use this instead of std::uncaught_exception
void setupUnwinding();
BoxedModule* getCurrentModule();
......
......@@ -22,6 +22,7 @@
#include "Python.h"
#include "analysis/scoping_analysis.h"
#include "codegen/unwinding.h"
#include "core/ast.h"
#include "core/options.h"
#include "core/types.h"
......@@ -197,8 +198,8 @@ public:
~CFGVisitor() {
// if we're being destroyed due to an exception, our internal invariants may be violated, but that's okay; the
// CFG isn't going to get used anyway. (Maybe we should check that it won't be used somehow?)
assert(continuations.size() == 0 || std::uncaught_exception());
assert(exc_handlers.size() == 0 || std::uncaught_exception());
assert(continuations.size() == 0 || isUnwinding());
assert(exc_handlers.size() == 0 || isUnwinding());
}
// ---------- private methods ----------
......
......@@ -379,6 +379,16 @@ static int main(int argc, char** argv) noexcept {
setvbuf(stderr, (char*)NULL, _IONBF, BUFSIZ);
}
#ifdef SIGPIPE
PyOS_setsig(SIGPIPE, SIG_IGN);
#endif
#ifdef SIGXFZ
PyOS_setsig(SIGXFZ, SIG_IGN);
#endif
#ifdef SIGXFSZ
PyOS_setsig(SIGXFSZ, SIG_IGN);
#endif
#ifndef NDEBUG
if (LOG_IC_ASSEMBLY || LOG_BJIT_ASSEMBLY) {
assembler::disassemblyInitialize();
......
......@@ -35,6 +35,7 @@
#define PYSTON_CUSTOM_UNWINDER 1 // set to 0 to use C++ unwinder
#define NORETURN __attribute__((__noreturn__))
#define HIDDEN __attribute__((visibility("hidden")))
// An action of 0 in the LSDA action table indicates cleanup.
#define CLEANUP_ACTION 0
......@@ -62,7 +63,7 @@
#define DW_EH_PE_indirect 0x80
// end dwarf encoding modes
extern "C" void __gxx_personality_v0(); // wrong type signature, but that's ok, it's extern "C"
extern "C" HIDDEN void __gxx_personality_v0(); // wrong type signature, but that's ok, it's extern "C"
// check(EXPR) is like assert((EXPR) == 0), but evaluates EXPR even in debug mode.
template <typename T> static inline void check(T x) {
......@@ -91,6 +92,10 @@ static __thread bool in_cleanup_code = false;
#endif
static __thread bool is_unwinding = false;
bool isUnwinding() {
return is_unwinding;
}
extern "C" {
static NORETURN void panic(void) {
......@@ -609,16 +614,12 @@ void std::terminate() noexcept {
RELEASE_ASSERT(0, "std::terminate() called!");
}
bool std::uncaught_exception() noexcept {
return pyston::is_unwinding;
}
// wrong type signature, but that's okay, it's extern "C"
extern "C" void __gxx_personality_v0() {
extern "C" HIDDEN void __gxx_personality_v0() {
RELEASE_ASSERT(0, "__gxx_personality_v0 should never get called");
}
extern "C" void _Unwind_Resume(struct _Unwind_Exception* _exc) {
extern "C" HIDDEN void _Unwind_Resume(struct _Unwind_Exception* _exc) {
assert(pyston::in_cleanup_code);
#ifndef NDEBUG
pyston::in_cleanup_code = false;
......@@ -635,7 +636,7 @@ extern "C" void _Unwind_Resume(struct _Unwind_Exception* _exc) {
// C++ ABI functionality
namespace __cxxabiv1 {
extern "C" void* __cxa_allocate_exception(size_t size) noexcept {
extern "C" HIDDEN void* __cxa_allocate_exception(size_t size) noexcept {
// we should only ever be throwing ExcInfos
RELEASE_ASSERT(size == sizeof(pyston::ExcInfo), "allocating exception whose size doesn't match ExcInfo");
......@@ -647,7 +648,7 @@ extern "C" void* __cxa_allocate_exception(size_t size) noexcept {
// Takes the value that resume() sent us in RAX, and returns a pointer to the exception object actually thrown. In our
// case, these are the same, and should always be &pyston::exception_ferry.
extern "C" void* __cxa_begin_catch(void* exc_obj_in) noexcept {
extern "C" HIDDEN void* __cxa_begin_catch(void* exc_obj_in) noexcept {
assert(exc_obj_in);
pyston::us_unwind_resume_catch.log(pyston::per_thread_resume_catch_timer.end());
......@@ -659,7 +660,7 @@ extern "C" void* __cxa_begin_catch(void* exc_obj_in) noexcept {
return e;
}
extern "C" void __cxa_end_catch() {
extern "C" HIDDEN void __cxa_end_catch() {
if (VERBOSITY("cxx_unwind") >= 4)
printf("***** __cxa_end_catch() *****\n");
// See comment in __cxa_begin_catch for why we don't clear the exception ferry here.
......@@ -673,7 +674,7 @@ extern "C" std::type_info EXCINFO_TYPE_INFO;
static uint64_t* unwinding_stattimer = pyston::Stats::getStatCounter("us_timer_unwinding");
#endif
extern "C" void __cxa_throw(void* exc_obj, std::type_info* tinfo, void (*dtor)(void*)) {
extern "C" HIDDEN void __cxa_throw(void* exc_obj, std::type_info* tinfo, void (*dtor)(void*)) {
static pyston::StatCounter num_cxa_throw("num_cxa_throw");
num_cxa_throw.log();
......@@ -699,7 +700,7 @@ extern "C" void __cxa_throw(void* exc_obj, std::type_info* tinfo, void (*dtor)(v
pyston::unwind(exc_data);
}
extern "C" void* __cxa_get_exception_ptr(void* exc_obj_in) noexcept {
extern "C" HIDDEN void* __cxa_get_exception_ptr(void* exc_obj_in) noexcept {
assert(exc_obj_in);
pyston::ExcInfo* e = (pyston::ExcInfo*)exc_obj_in;
checkExcInfo(e);
......@@ -715,9 +716,31 @@ extern "C" void* __cxa_get_exception_ptr(void* exc_obj_in) noexcept {
// throw e;
// }
//
extern "C" void __cxa_rethrow() {
extern "C" HIDDEN void __cxa_rethrow() {
RELEASE_ASSERT(0, "__cxa_rethrow() unimplemented; please don't use bare `throw' in Pyston!");
}
}
#endif // PYSTON_CUSTOM_UNWINDER
namespace pyston {
static llvm::StringMap<uint64_t> cxx_unwind_syms;
uint64_t getCXXUnwindSymbolAddress(llvm::StringRef sym) {
#if PYSTON_CUSTOM_UNWINDER
if (unlikely(cxx_unwind_syms.empty())) {
cxx_unwind_syms["_Unwind_Resume"] = (uint64_t)_Unwind_Resume;
cxx_unwind_syms["__gxx_personality_v0"] = (uint64_t)__gxx_personality_v0;
cxx_unwind_syms["__cxa_allocate_exception"] = (uint64_t)__cxxabiv1::__cxa_allocate_exception;
cxx_unwind_syms["__cxa_begin_catch"] = (uint64_t)__cxxabiv1::__cxa_begin_catch;
cxx_unwind_syms["__cxa_end_catch"] = (uint64_t)__cxxabiv1::__cxa_end_catch;
cxx_unwind_syms["__cxa_get_exception_ptr"] = (uint64_t)__cxxabiv1::__cxa_get_exception_ptr;
cxx_unwind_syms["__cxa_rethrow"] = (uint64_t)__cxxabiv1::__cxa_rethrow;
cxx_unwind_syms["__cxa_throw"] = (uint64_t)__cxxabiv1::__cxa_throw;
}
auto&& it = cxx_unwind_syms.find(sym);
if (it != cxx_unwind_syms.end())
return it->second;
#endif
return 0;
}
}
......@@ -16,6 +16,7 @@
#define PYSTON_RUNTIME_REWRITEARGS_H
#include "asm_writing/rewriter.h"
#include "codegen/unwinding.h"
namespace pyston {
......@@ -73,7 +74,7 @@ public:
#ifndef NDEBUG
~_ReturnConventionBase() {
if (out_success && !std::uncaught_exception())
if (out_success && !isUnwinding())
assert(return_convention_checked && "Didn't check the return convention of this rewrite...");
}
#endif
......
......@@ -24,8 +24,6 @@ test_al No module named al
test_applesingle Not really a failure, but it tries to skip itself and we don't support that
test_argparse [unknown]
test_ascii_formatd segfault in ctypes (but only on CI)
test_asynchat [unknown]
test_asyncore [unknown]
test_atexit [unknown]
test_audioop [unknown]
test_bigmem [unknown]
......@@ -92,7 +90,6 @@ test_extcall f(**kw) crashes if kw isn't a dict
test_fileio [unknown]
test_fork1 [unknown]
test_frozen [unknown]
test_ftplib [unknown]
test_funcattrs we don't allow changing numing of function defaults
test_functools unknown errors
test_future5 [unknown]
......@@ -108,7 +105,6 @@ test_gl [unknown]
test_grammar bug in our tokenizer
test_heapq [unknown]
test_hotshot [unknown]
test_httplib [unknown]
test_httpservers [unknown]
test_idle [unknown]
test_imageop [unknown]
......@@ -147,7 +143,6 @@ test_pdb [unknown]
test_peepholer [unknown]
test_pep352 various unique bugs
test_pkg unknown bug
test_poplib SSLError (but only on CI)
test_pprint [unknown]
test_profile [unknown]
test_py3kwarn [unknown]
......@@ -164,11 +159,10 @@ test_scope eval of code object from existing function (not currentl
test_scriptpackages [unknown]
test_shelve [unknown]
test_site [unknown]
test_socketserver [unknown]
test_socketserver missing imp.lock_held, otherwise works
test_socket [unknown]
test_sort argument specification issue in listSort?
test_sqlite [unknown]
test_ssl [unknown]
test_startfile [unknown]
test_str memory leak?
test_structmembers [unknown]
......@@ -185,7 +179,6 @@ test_sys_settrace [unknown]
test_sys [unknown]
test_tarfile [unknown]
test_tcl [unknown]
test_telnetlib [unknown]
test_tempfile [unknown]
test_threaded_import [unknown]
test_threading_local [unknown]
......@@ -208,8 +201,6 @@ test_unicode_file exit code 139, no error message
test_unittest serialize_ast assert
test_univnewlines2k [unknown]
test_univnewlines [unknown]
test_urllib2net [unknown]
test_urllibnet [unknown]
test_userdict segfault: repr of recursive dict?
test_userlist slice(1L, 1L)
test_userstring float(1L); hangs in test_replace
......
../../from_cpython/Lib/test/badcert.pem
\ No newline at end of file
../../from_cpython/Lib/test/badkey.pem
\ No newline at end of file
../../from_cpython/Lib/test/https_svn_python_org_root.pem
\ No newline at end of file
../../from_cpython/Lib/test/keycert.pem
\ No newline at end of file
../../from_cpython/Lib/test/nokia.pem
\ No newline at end of file
../../from_cpython/Lib/test/nullbytecert.pem
\ No newline at end of file
../../from_cpython/Lib/test/nullcert.pem
\ No newline at end of file
../../from_cpython/Lib/test/sha256.pem
\ No newline at end of file
../../from_cpython/Lib/test/wrongcert.pem
\ No newline at end of file
......@@ -20,4 +20,18 @@ diff -ur M2Crypto-0.21.1.orig/SWIG/_lib.i ./SWIG/_lib.i
new_style_callback = 1;
}
} else {
diff -ur M2Crypto-0.21.1/M2Crypto/m2urllib2.py ./M2Crypto/m2urllib2.py
--- M2Crypto-0.21.1/M2Crypto/m2urllib2.py 2011-01-15 19:10:05.000000000 +0000
+++ ./M2Crypto/m2urllib2.py 2016-02-10 14:36:12.091812337 +0000
@@ -97,6 +97,11 @@
# out of socket._fileobject() and into a base class.
r.recv = r.read
+
+ # Pyston change: our socket implementation needs this functions
+ r._reuse = lambda: None
+ r._drop = lambda: None
+
fp = _closing_fileobject(r)
resp = addinfourl(fp, r.msg, req.get_full_url())
# skip-if: 'clang' in os.environ['CC']
# looks like libsass only builds using gcc...
import os, sys, subprocess
sys.path.append(os.path.dirname(__file__) + "/../lib")
from test_helper import create_virtenv, run_test
ENV_NAME = "sass_test_env_" + os.path.basename(sys.executable)
SRC_DIR = os.path.abspath(os.path.join(ENV_NAME, "src"))
PYTHON_EXE = os.path.abspath(os.path.join(ENV_NAME, "bin", "python"))
SASS_DIR = os.path.abspath(os.path.join(ENV_NAME, "src", "libsass"))
packages = ["six==1.10", "werkzeug==0.9"]
packages += ["-e", "git+https://github.com/dahlia/libsass-python@0.8.3#egg=libsass"]
create_virtenv(ENV_NAME, packages, force_create = True)
expected = [{'ran': 75}]
run_test([PYTHON_EXE, "setup.py", "test"], cwd=SASS_DIR, expected=expected)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-undef")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-undef -D_PYSTON_API")
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})
add_definitions(-DGTEST_HAS_RTTI=0 ${LLVM_DEFINITIONS})
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment