Commit 10420e82 authored by Kirill Smelkov's avatar Kirill Smelkov

X gc.collect on loadblk -> pybuf.ob_refcnt != 1

parent f1e12596
......@@ -53,6 +53,7 @@ typedef struct _frame PyFrameObject;
void PyBufferObject_Unpin(PyBufferObject *bufo);
void PyBuffer_Unpin(Py_buffer *view);
static PyObject *gcmodule;
/*
......@@ -560,6 +561,19 @@ out:
if (pybuf)
BUG_ON(pybuf->ob_refcnt != 1);
#endif
if (pybuf && pybuf->ob_refcnt != 1) {
PyObject *pybuf_users = PyObject_CallMethod(gcmodule, "get_referrers", "O", pybuf);
BUG_ON(!pybuf_users);
//PyObject_Repr(pybuf_users);
fprintf(stderr, "\n");
_PyObject_Dump(pybuf_users);
fprintf(stderr, "\n");
PyObject_Print(pybuf_users, stderr, 0);
fprintf(stderr, "curexc_tb:\t%p\n", x_curexc_traceback);
fprintf(stderr, "exc_tb:\t%p\n", x_exc_traceback);
Py_DECREF(pybuf_users);
BUG();
}
/* drop pybuf
*
......@@ -911,6 +925,11 @@ _init_bigfile(void)
CSTi(WRITEOUT_STORE);
CSTi(WRITEOUT_MARKSTORED);
/* import gc */
gcmodule = PyImport_ImportModule("gc");
if (!gcmodule)
return NULL;
return m;
}
......
......@@ -124,6 +124,21 @@ def test_basic():
# TODO close f
def zzz():
try:
1/0
except ZeroDivisionError:
pass
exc_type, exc_value, exc_traceback = sys.exc_info()
if PY2:
assert exc_type is ZeroDivisionError
else:
# on python3 exception state is cleared upon exiting from `except`
assert exc_type is None
# del exc_traceback
# test that python exception state is preserved across pagefaulting
def test_pagefault_savestate():
class BadFile(BigFile):
......@@ -159,12 +174,23 @@ def test_pagefault_savestate():
# # gc.collect() which cannot be perform in pagefault handler.
# #
# # Not breaking this loop will BUG with `buf.refcnt != 1` on return
# del exc_traceback
del exc_traceback
zzz()
raise Exception('eee')
assert len(buf) > 0
self.loadblk_run = 1
self.loadblk_buf = buf
#self.loadblk_buf = buf
#self.loadblk_buf2 = buffer(buf)
#self.loadblk_mbuf = memoryview(buf)
#print
#print
#print '111'
#print `buf`
#print `self.loadblk_buf2`
#print `self.loadblk_mbuf`
f = BadFile(PS)
......@@ -189,7 +215,14 @@ def test_pagefault_savestate():
assert exc_tb is exc_tb2
# TODO check f.loadblk_buf for access -- len=0, read/write - index error
print
print '222'
print `f.loadblk_buf`
print `f.loadblk_buf2`
print `f.loadblk_mbuf`
assert len(f.loadblk_buf) == 0
assert len(f.loadblk_buf2) == 0
assert len(f.loadblk_mbuf) == 0
raises(IndexError, "f.loadblk_buf[0]")
raises(IndexError, "f.loadblk_buf[0] = b'1'")
......
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