71 |
71 |
module = self.import_extension('foo', [ |
72 |
72 |
("test_mod", 'METH_VARARGS', |
73 |
73 |
""" |
74 |
|
PyObject *obj, *collect, *tup; |
|
74 |
PyObject *obj; |
75 |
75 |
Py_buffer bp; |
76 |
|
if (!PyArg_ParseTuple(args, "OO", &obj, &collect)) |
|
76 |
if (!PyArg_ParseTuple(args, "O", &obj)) |
77 |
77 |
return NULL; |
78 |
78 |
|
79 |
79 |
assert(obj); |
80 |
80 |
|
81 |
81 |
if (PyObject_GetBuffer(obj, &bp, PyBUF_SIMPLE) == -1) |
82 |
82 |
return NULL; |
83 |
|
|
84 |
|
tup = PyTuple_New(0); /* for collect() */ |
85 |
83 |
if (((unsigned char*)bp.buf)[0] != '0') { |
86 |
84 |
PyErr_Format(PyExc_ValueError, |
87 |
85 |
"mismatch: 0x%x [%x %x %x %x...] instead of '0' (got len=%d)", |
… |
92 |
90 |
((unsigned char*)bp.buf)[4], |
93 |
91 |
bp.len); |
94 |
92 |
PyBuffer_Release(&bp); |
95 |
|
Py_DECREF(tup); |
96 |
93 |
return NULL; |
97 |
94 |
} |
98 |
95 |
|
99 |
96 |
PyBuffer_Release(&bp); |
100 |
|
Py_DECREF(tup); |
101 |
97 |
Py_RETURN_NONE; |
102 |
98 |
"""), |
103 |
99 |
]) |
… |
114 |
110 |
block = getdata(bufsize) |
115 |
111 |
assert block[:8] == '01234567' |
116 |
112 |
try: |
117 |
|
module.test_mod(block, gc.collect) |
|
113 |
module.test_mod(block) |
118 |
114 |
except ValueError as e: |
119 |
115 |
print("%s at it=%d" % (e, j)) |
120 |
116 |
assert False |