From 03b4d5072aa044d8c6827e387b647dcc6c9d0ff6 Mon Sep 17 00:00:00 2001 From: Meador Inge Date: Fri, 10 Aug 2012 22:35:45 -0500 Subject: Issue #15424: Add a __sizeof__ implementation for array objects. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Patch by Ludwig Hähne. --- Lib/test/test_array.py | 13 +++++++++++++ Misc/ACKS | 1 + Misc/NEWS | 3 +++ Modules/arraymodule.c | 15 +++++++++++++++ 4 files changed, 32 insertions(+) diff --git a/Lib/test/test_array.py b/Lib/test/test_array.py index 5190c35..e26e9ad 100755 --- a/Lib/test/test_array.py +++ b/Lib/test/test_array.py @@ -988,6 +988,19 @@ class BaseTest(unittest.TestCase): a = array.array('H', b"1234") self.assertEqual(len(a) * a.itemsize, 4) + @support.cpython_only + def test_sizeof_with_buffer(self): + a = array.array(self.typecode, self.example) + basesize = support.calcvobjsize('4Pi') + buffer_size = a.buffer_info()[1] * a.itemsize + support.check_sizeof(self, a, basesize + buffer_size) + + @support.cpython_only + def test_sizeof_without_buffer(self): + a = array.array(self.typecode) + basesize = support.calcvobjsize('4Pi') + support.check_sizeof(self, a, basesize) + class StringTest(BaseTest): diff --git a/Misc/ACKS b/Misc/ACKS index 4d8f13c..36dc7fe 100644 --- a/Misc/ACKS +++ b/Misc/ACKS @@ -434,6 +434,7 @@ Jim Hugunin Greg Humphreys Eric Huss Jeremy Hylton +Ludwig Hähne Gerhard Häring Fredrik Håård Mihai Ibanescu diff --git a/Misc/NEWS b/Misc/NEWS index 99812d2..5a4d71b 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -101,6 +101,9 @@ Core and Builtins Library ------- +- Issue #15424: Add a __sizeof__ implementation for array objects. + Patch by Ludwig Hähne. + - Issue #13052: Fix IDLE crashing when replace string in Search/Replace dialog ended with '\'. Patch by Roger Serwy. diff --git a/Modules/arraymodule.c b/Modules/arraymodule.c index 641e283..2d4ee72 100644 --- a/Modules/arraymodule.c +++ b/Modules/arraymodule.c @@ -1510,6 +1510,19 @@ array.tobytes().decode() to obtain a unicode string from\n\ an array of some other type."); +static PyObject * +array_sizeof(arrayobject *self, PyObject *unused) +{ + Py_ssize_t res; + res = sizeof(arrayobject) + self->allocated * self->ob_descr->itemsize; + return PyLong_FromSsize_t(res); +} + +PyDoc_STRVAR(sizeof_doc, +"__sizeof__() -> int\n\ +\n\ +Size of the array in memory, in bytes."); + /*********************** Pickling support ************************/ @@ -2077,6 +2090,8 @@ static PyMethodDef array_methods[] = { tobytes_doc}, {"tounicode", (PyCFunction)array_tounicode, METH_NOARGS, tounicode_doc}, + {"__sizeof__", (PyCFunction)array_sizeof, METH_NOARGS, + sizeof_doc}, {NULL, NULL} /* sentinel */ }; -- cgit v0.12 >
path: root/doc/src/snippets/code/src_qdbus_qdbusabstractinterface.cpp
blob: 0aaf678763d861c1d52cd92b960ba811dcdab1e9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
/****************************************************************************
**
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** This file is part of the documentation of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:BSD$
** You may use this file under the terms of the BSD license as follows:
**
** "Redistribution and use in source and binary forms, with or without
** modification, are permitted provided that the following conditions are
** met:
**   * Redistributions of source code must retain the above copyright
**     notice, this list of conditions and the following disclaimer.
**   * Redistributions in binary form must reproduce the above copyright
**     notice, this list of conditions and the following disclaimer in
**     the documentation and/or other materials provided with the
**     distribution.
**   * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
**     the names of its contributors may be used to endorse or promote
**     products derived from this software without specific prior written
**     permission.
**
** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
** $QT_END_LICENSE$
**
****************************************************************************/

//! [0]
QString value = retrieveValue();
QDBusMessage reply;

QDBusReply<int> api = interface->call(QLatin1String("GetAPIVersion"));
if (api >= 14)
  reply = interface->call(QLatin1String("ProcessWorkUnicode"), value);
else
  reply = interface->call(QLatin1String("ProcessWork"), QLatin1String("UTF-8"), value.toUtf8());
//! [0]

//! [1]
QString value = retrieveValue();
QDBusPendingCall pcall = interface->asyncCall(QLatin1String("Process"), value);

QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(pcall, this);

QObject::connect(watcher, SIGNAL(finished(QDBusPendingCallWatcher*)),
                 this, SLOT(callFinishedSlot(QDBusPendingCallWatcher*)));
//! [1]