Author: Matti Picus <matti.pi...@gmail.com> Branch: Changeset: r91848:5a93d0b7ba23 Date: 2017-07-10 05:04 +0300 http://bitbucket.org/pypy/pypy/changeset/5a93d0b7ba23/
Log: test, fix for PyObject_Print(NULL, ...), which occurred in Numpy f2py --debug-capi diff --git a/pypy/module/cpyext/object.py b/pypy/module/cpyext/object.py --- a/pypy/module/cpyext/object.py +++ b/pypy/module/cpyext/object.py @@ -436,15 +436,19 @@ Py_PRINT_RAW = 1 # No string quotes etc. @cpython_api([PyObject, FILEP, rffi.INT_real], rffi.INT_real, error=-1) -def PyObject_Print(space, w_obj, fp, flags): +def PyObject_Print(space, pyobj, fp, flags): """Print an object o, on file fp. Returns -1 on error. The flags argument is used to enable certain printing options. The only option currently supported is Py_PRINT_RAW; if given, the str() of the object is written instead of the repr().""" - if rffi.cast(lltype.Signed, flags) & Py_PRINT_RAW: - w_str = space.str(w_obj) + if not pyobj: + w_str = space.newtext("<nil>") else: - w_str = space.repr(w_obj) + w_obj = from_ref(space, pyobj) + if rffi.cast(lltype.Signed, flags) & Py_PRINT_RAW: + w_str = space.str(w_obj) + else: + w_str = space.repr(w_obj) count = space.len_w(w_str) data = space.text_w(w_str) diff --git a/pypy/module/cpyext/test/test_object.py b/pypy/module/cpyext/test/test_object.py --- a/pypy/module/cpyext/test/test_object.py +++ b/pypy/module/cpyext/test/test_object.py @@ -315,13 +315,20 @@ if (fp == NULL) Py_RETURN_NONE; ret = PyObject_Print(obj, fp, Py_PRINT_RAW); + if (ret < 0) { + fclose(fp); + return NULL; + } + ret = PyObject_Print(NULL, fp, Py_PRINT_RAW); + if (ret < 0) { + fclose(fp); + return NULL; + } fclose(fp); - if (ret < 0) - return NULL; Py_RETURN_TRUE; """)]) assert module.dump(self.tmpname, None) - assert open(self.tmpname).read() == 'None' + assert open(self.tmpname).read() == 'None<nil>' def test_issue1970(self): module = self.import_extension('foo', [ _______________________________________________ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit