Commit 6f8dea37 authored by Matti Picus's avatar Matti Picus
Browse files

merge default into release

--HG--
branch : release-5.x
......@@ -137,6 +137,8 @@ class gdbm(object):
lib.gdbm_sync(self.__ll_dbm)
def open(filename, flags='r', mode=0666):
if isinstance(filename, unicode):
filename = filename.encode()
if flags[0] == 'r':
iflags = lib.GDBM_READER
elif flags[0] == 'w':
......
......@@ -3,6 +3,6 @@ What's new in PyPy2.7 5.4+
==========================
.. this is a revision shortly after release-pypy2.7-v5.4
.. startrev: 531050b1f410
.. startrev: 4176c6f63109
......@@ -159,3 +159,7 @@ Extends the cpyext emulation layer.
.. branch: redirect-assembler-jitlog
Log more information to properly rebuild the redirected traces in jitviewer.
.. branch: cpyext-subclass
Copy Py_TPFLAGS_CHECKTYPES, Py_TPFLAGS_HAVE_INPLACEOPS when inheriting
......@@ -120,7 +120,7 @@ pypy_decl = 'pypy_decl.h'
constant_names = """
Py_TPFLAGS_READY Py_TPFLAGS_READYING Py_TPFLAGS_HAVE_GETCHARBUFFER
METH_COEXIST METH_STATIC METH_CLASS Py_TPFLAGS_BASETYPE
METH_NOARGS METH_VARARGS METH_KEYWORDS METH_O
METH_NOARGS METH_VARARGS METH_KEYWORDS METH_O Py_TPFLAGS_HAVE_INPLACEOPS
Py_TPFLAGS_HEAPTYPE Py_TPFLAGS_HAVE_CLASS Py_TPFLAGS_HAVE_NEWBUFFER
Py_LT Py_LE Py_EQ Py_NE Py_GT Py_GE Py_TPFLAGS_CHECKTYPES
""".split()
......
#ifdef _MSC_VER
#define _CRT_SECURE_NO_WARNINGS 1
#endif
#include <Python.h>
#include <stdlib.h>
#include <stdio.h>
......@@ -10,7 +13,7 @@
/* Structure defines a 1-dimensional strided array */
typedef struct{
int* arr;
long length;
Py_ssize_t length;
} MyArray;
/* initialize the array with integers 0...length */
......@@ -61,13 +64,13 @@ typedef struct {
static int
PyMyArray_init(PyMyArray *self, PyObject *args, PyObject *kwds)
{
int length = 0;
static char *kwlist[] = {"length", NULL};
// init may have already been called
if (self->arr.arr != NULL) {
deallocate_MyArray(&self->arr);
}
int length = 0;
static char *kwlist[] = {"length", NULL};
if (! PyArg_ParseTupleAndKeywords(args, kwds, "|i", kwlist, &length))
return -1;
......@@ -103,16 +106,19 @@ PyMyArray_str(PyMyArray * self)
static int
PyMyArray_getbuffer(PyObject *obj, Py_buffer *view, int flags)
{
PyMyArray* self = (PyMyArray*)obj;
fprintf(stdout, "in PyMyArray_getbuffer\n");
if (view == NULL) {
fprintf(stdout, "view is NULL\n");
PyErr_SetString(PyExc_ValueError, "NULL view in getbuffer");
return -1;
}
if (flags == 0) {
fprintf(stdout, "flags is 0\n");
PyErr_SetString(PyExc_ValueError, "flags == 0 in getbuffer");
return -1;
}
PyMyArray* self = (PyMyArray*)obj;
view->obj = (PyObject*)self;
view->buf = (void*)self->arr.arr;
view->len = self->arr.length * sizeof(int);
......@@ -218,7 +224,6 @@ PyInit_buffer_test(void)
#ifdef __GNUC__
extern __attribute__((visibility("default")))
#else
extern __declspec(dllexport)
#endif
PyMODINIT_FUNC
......
......@@ -87,4 +87,13 @@ class AppTestArrayModule(AppTestCpythonExtensionBase):
module.switch_multiply()
res = [1, 2, 3] * arr
assert res == [2, 4, 6]
def test_subclass(self):
module = self.import_module(name='array')
class Sub(module.array):
pass
arr = Sub('i', [2])
res = [1, 2, 3] * arr
assert res == [1, 2, 3, 1, 2, 3]
......@@ -18,7 +18,8 @@ from pypy.module.cpyext.api import (
Py_TPFLAGS_HEAPTYPE, METH_VARARGS, METH_KEYWORDS, CANNOT_FAIL,
Py_TPFLAGS_HAVE_GETCHARBUFFER, build_type_checkers, StaticObjectBuilder,
PyObjectFields, Py_TPFLAGS_BASETYPE, PyTypeObject, PyTypeObjectPtr,
Py_TPFLAGS_HAVE_NEWBUFFER)
Py_TPFLAGS_HAVE_NEWBUFFER, Py_TPFLAGS_CHECKTYPES,
Py_TPFLAGS_HAVE_INPLACEOPS)
from pypy.module.cpyext.methodobject import (W_PyCClassMethodObject,
W_PyCWrapperObject, PyCFunction_NewEx, PyCFunction_typedef, PyMethodDef,
W_PyCMethodObject, W_PyCFunctionObject)
......@@ -386,6 +387,8 @@ def inherit_special(space, pto, base_pto):
pto.c_tp_basicsize = base_pto.c_tp_basicsize
if pto.c_tp_itemsize < base_pto.c_tp_itemsize:
pto.c_tp_itemsize = base_pto.c_tp_itemsize
pto.c_tp_flags |= base_pto.c_tp_flags & Py_TPFLAGS_CHECKTYPES
pto.c_tp_flags |= base_pto.c_tp_flags & Py_TPFLAGS_HAVE_INPLACEOPS
flags = rffi.cast(lltype.Signed, pto.c_tp_flags)
base_object_pyo = make_ref(space, space.w_object)
base_object_pto = rffi.cast(PyTypeObjectPtr, base_object_pyo)
......@@ -814,8 +817,13 @@ def _type_realize(space, py_obj):
# inheriting tp_as_* slots
base = py_type.c_tp_base
if base:
if not py_type.c_tp_as_number: py_type.c_tp_as_number = base.c_tp_as_number
if not py_type.c_tp_as_sequence: py_type.c_tp_as_sequence = base.c_tp_as_sequence
if not py_type.c_tp_as_number:
py_type.c_tp_as_number = base.c_tp_as_number
py_type.c_tp_flags |= base.c_tp_flags & Py_TPFLAGS_CHECKTYPES
py_type.c_tp_flags |= base.c_tp_flags & Py_TPFLAGS_HAVE_INPLACEOPS
if not py_type.c_tp_as_sequence:
py_type.c_tp_as_sequence = base.c_tp_as_sequence
py_type.c_tp_flags |= base.c_tp_flags & Py_TPFLAGS_HAVE_INPLACEOPS
if not py_type.c_tp_as_mapping: py_type.c_tp_as_mapping = base.c_tp_as_mapping
if not py_type.c_tp_as_buffer: py_type.c_tp_as_buffer = base.c_tp_as_buffer
......
......@@ -15,3 +15,7 @@ def test_len():
assert len(g) == 2
del g['abc']
assert len(g) == 1
def test_unicode():
path = unicode(udir.join('test_gdm_unicode'))
g = gdbm.open(path, 'c') # does not crash
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