pax_global_header00006660000000000000000000000064147556764460014542gustar00rootroot0000000000000052 comment=21ea803527735cfaf54fa6059e71d1ef65004864 calamares-3.3.14/000077500000000000000000000000001475567644600135625ustar00rootroot00000000000000calamares-3.3.14/.clang-format000066400000000000000000000020371475567644600161370ustar00rootroot00000000000000# SPDX-FileCopyrightText: no # SPDX-License-Identifier: CC0-1.0 --- BasedOnStyle: WebKit AlignAfterOpenBracket: Align AlignEscapedNewlines: DontAlign AllowAllParametersOfDeclarationOnNextLine: "false" AllowShortFunctionsOnASingleLine: Inline AllowShortIfStatementsOnASingleLine: "false" AllowShortLambdasOnASingleLine: All AllowShortLoopsOnASingleLine: "false" AlwaysBreakAfterReturnType: TopLevelDefinitions AlwaysBreakTemplateDeclarations: Yes BinPackArguments: "false" BinPackParameters: "false" BreakBeforeBraces: Allman BreakBeforeTernaryOperators: "true" BreakConstructorInitializers: BeforeComma ColumnLimit: 120 Cpp11BracedListStyle: "false" FixNamespaceComments: "true" IncludeBlocks: Preserve IndentWidth: "4" InsertBraces: "true" MaxEmptyLinesToKeep: "2" NamespaceIndentation: None PointerAlignment: Left ReflowComments: "false" SortIncludes: "true" SpaceAfterCStyleCast: "false" SpaceInEmptyBlock: "false" SpacesBeforeTrailingComments: "2" SpacesInAngles: "true" SpacesInParentheses: "true" SpacesInSquareBrackets: "true" Standard: c++17 calamares-3.3.14/.gersemirc000066400000000000000000000003151475567644600155420ustar00rootroot00000000000000# SPDX-FileCopyrightText: no # SPDX-License-Identifier: CC0-1.0 # # Gersemi configuration color: false definitions: [ CMakeModules/CalamaresAddTest.cmake ] line_length: 120 quiet: false unsafe: false calamares-3.3.14/.git-blame-ignore-revs000066400000000000000000000002301475567644600176550ustar00rootroot00000000000000# SPDX-FileCopyrightText: no # SPDX-License-Identifier: CC0-1.0 # 18fef8dfe5d926ec0bc979562553adf4db8db2e9 874a0c1f38b0da4e5bc83083b13a63b1c7eed935 calamares-3.3.14/.reuse/000077500000000000000000000000001475567644600147635ustar00rootroot00000000000000calamares-3.3.14/.reuse/dep5000066400000000000000000000047551475567644600155560ustar00rootroot00000000000000Format: https://www.debian.org/doc/packaging-manuals/copyright-format/1.0/ Upstream-Name: Calamares Source: https://github.com/calamares/calamares.git ### ACTUAL LICENSES # # Images in the locale module are a bit unclear; they were added # by Teo in 2014 but I suspect they came from somewhere else. # Files: src/modules/locale/images/timezone*.png License: GPL-3.0-or-later Copyright: 2014 Teo Mrnjavac Files: man/calamares.8 License: GPL-3.0-or-later Copyright: 2017 Jonathan Carter Files: 3rdparty/kdsingleapplication/* License: MIT Copyright: Copyright (C) 2019-2021 Klarälvdalens Datakonsult AB, a KDAB Group company, info@ kdab.com ### BUILD ARTIFACTS / NOT SOURCE # # QRC Files are basically build artifacts # FILES: src/modules/*/*.qrc License: CC0-1.0 Copyright: no # GitHub issue templates are not part of the source # Files: .github/ISSUE_TEMPLATE/* License: CC0-1.0 Copyright: no # GitHub actions are not part of the source Files: .github/workflows/*.yml License: CC0-1.0 Copyright: no # Packaging information # Files: data/FreeBSD/distinfo data/FreeBSD/pkg-descr data/FreeBSD/pkg-plist License: CC0-1.0 Copyright: no # Example data for timezones, which is copied out of zoneinfo, # which has this notice: # # This file is in the public domain, so clarified as of # 2009-05-17 by Arthur David Olson. # Files: data/example-root/usr/share/zoneinfo/Zulu data/example-root/usr/share/zoneinfo/UTC data/example-root/usr/share/zoneinfo/America/New_York License: CC0-1.0 Copyright: no # Test data # # These first files are mere lists of locale identifiers Files: src/modules/locale/tests/locale-data-neon src/modules/locale/tests/locale-data-freebsd License: CC0-1.0 Copyright: no ### TRANSLATIONS # # .desktop files and template change only with translation # FILES: calamares.desktop* License: CC0-1.0 Copyright: no # Transifex translations derive from the source, and have no # embedded copyright information. # Files: lang/*.ts License: GPL-3.0-or-later Copyright: 2020 Calamares authors and translators # Translations of branding slideshow are the same Files: src/branding/default/lang/*.ts License: GPL-3.0-or-later Copyright: 2020 Calamares authors and translators # Python translation files have some copyright information, but # it's generally very sketchy. # Files: lang/python.pot License: GPL-3.0-or-later Copyright: 2020 Calamares authors and translators Files: lang/python/*/LC_MESSAGES/python.po License: GPL-3.0-or-later Copyright: 2020 Calamares authors and translators calamares-3.3.14/3rdparty/000077500000000000000000000000001475567644600153325ustar00rootroot00000000000000calamares-3.3.14/3rdparty/kdsingleapplication/000077500000000000000000000000001475567644600213565ustar00rootroot00000000000000calamares-3.3.14/3rdparty/kdsingleapplication/CMakeLists.txt000066400000000000000000000022751475567644600241240ustar00rootroot00000000000000set(KDSINGLEAPPLICATION_STATIC ON) set(KDSINGLEAPPLICATION_SRCS kdsingleapplication.cpp kdsingleapplication_localsocket.cpp) set(KDSINGLEAPPLICATION_INSTALLABLE_INCLUDES kdsingleapplication.h kdsingleapplication_lib.h) set(KDSINGLEAPPLICATION_NON_INSTALLABLE_INCLUDES kdsingleapplication_localsocket_p.h) if(KDSINGLEAPPLICATION_STATIC) add_library(kdsingleapplication STATIC ${KDSINGLEAPPLICATION_INSTALLABLE_INCLUDES} ${KDSINGLEAPPLICATION_SRCS}) target_compile_definitions(kdsingleapplication PUBLIC KDSINGLEAPPLICATION_STATIC_BUILD) else() add_library(kdsingleapplication SHARED ${KDSINGLEAPPLICATION_INSTALLABLE_INCLUDES} ${KDSINGLEAPPLICATION_SRCS}) target_compile_definitions(kdsingleapplication PRIVATE KDSINGLEAPPLICATION_SHARED_BUILD) endif() set_target_properties( kdsingleapplication PROPERTIES AUTOMOC TRUE ) set(KDSINGLEAPPLICATION_INCLUDEDIR ${CMAKE_INSTALL_INCLUDEDIR}/kdsingleapplication) target_include_directories( kdsingleapplication PUBLIC $ $ PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} ) target_link_libraries(kdsingleapplication ${qtname}::Core ${qtname}::Network) calamares-3.3.14/3rdparty/kdsingleapplication/LICENSE.MIT.txt000066400000000000000000000021511475567644600236300ustar00rootroot00000000000000MIT License Copyright (C) 2019-2021 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. calamares-3.3.14/3rdparty/kdsingleapplication/kdsingleapplication.cpp000066400000000000000000000070121475567644600261060ustar00rootroot00000000000000/* MIT License Copyright (C) 2019-2021 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ #include "kdsingleapplication.h" #include #include // TODO: make this pluggable. #include "kdsingleapplication_localsocket_p.h" // Avoiding dragging in Qt private APIs for now, so this does not inherit // from QObjectPrivate. class KDSingleApplicationPrivate { public: explicit KDSingleApplicationPrivate(const QString &name, KDSingleApplication *q); void initialize(); QString name() const { return m_name; } bool isPrimaryInstance() const { return m_impl.isPrimaryInstance(); } bool sendMessage(const QByteArray &message, int timeout) { return m_impl.sendMessage(message, timeout); } private: Q_DECLARE_PUBLIC(KDSingleApplication) KDSingleApplication *q_ptr; QString m_name; KDSingleApplicationLocalSocket m_impl; }; KDSingleApplicationPrivate::KDSingleApplicationPrivate(const QString &name, KDSingleApplication *q) : q_ptr(q) , m_name(name) , m_impl(name) { if (Q_UNLIKELY(name.isEmpty())) qFatal("KDSingleApplication requires a non-empty application name"); if (isPrimaryInstance()) { QObject::connect(&m_impl, &KDSingleApplicationLocalSocket::messageReceived, q, &KDSingleApplication::messageReceived); } } static QString extractExecutableName(const QString &applicationFilePath) { return QFileInfo(applicationFilePath).fileName(); } KDSingleApplication::KDSingleApplication(QObject *parent) : KDSingleApplication(extractExecutableName(QCoreApplication::applicationFilePath()), parent) { } KDSingleApplication::KDSingleApplication(const QString &name, QObject *parent) : QObject(parent) , d_ptr(new KDSingleApplicationPrivate(name, this)) { } QString KDSingleApplication::name() const { Q_D(const KDSingleApplication); return d->name(); } bool KDSingleApplication::isPrimaryInstance() const { Q_D(const KDSingleApplication); return d->isPrimaryInstance(); } bool KDSingleApplication::sendMessage(const QByteArray &message) { return sendMessageWithTimeout(message, 5000); } bool KDSingleApplication::sendMessageWithTimeout(const QByteArray &message, int timeout) { Q_ASSERT(!isPrimaryInstance()); Q_D(KDSingleApplication); return d->sendMessage(message, timeout); } KDSingleApplication::~KDSingleApplication() = default; calamares-3.3.14/3rdparty/kdsingleapplication/kdsingleapplication.h000066400000000000000000000043221475567644600255540ustar00rootroot00000000000000/* MIT License Copyright (C) 2019-2021 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ #ifndef KDSINGLEAPPLICATION_H #define KDSINGLEAPPLICATION_H #include #include #include "kdsingleapplication_lib.h" class KDSingleApplicationPrivate; class KDSINGLEAPPLICATION_EXPORT KDSingleApplication : public QObject { Q_OBJECT Q_PROPERTY(QString name READ name CONSTANT) Q_PROPERTY(bool isPrimaryInstance READ isPrimaryInstance CONSTANT) public: explicit KDSingleApplication(QObject *parent = nullptr); explicit KDSingleApplication(const QString &name, QObject *parent = nullptr); ~KDSingleApplication(); QString name() const; bool isPrimaryInstance() const; public Q_SLOTS: // avoid default arguments and overloads, as they don't mix with connections bool sendMessage(const QByteArray &message); bool sendMessageWithTimeout(const QByteArray &message, int timeout); Q_SIGNALS: void messageReceived(const QByteArray &message); private: Q_DECLARE_PRIVATE(KDSingleApplication) std::unique_ptr d_ptr; }; #endif // KDSINGLEAPPLICATION_H calamares-3.3.14/3rdparty/kdsingleapplication/kdsingleapplication_lib.h000066400000000000000000000030501475567644600263770ustar00rootroot00000000000000/* MIT License Copyright (C) 2019-2021 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ #ifndef KDSINGLEAPPLICATION_LIB_H #define KDSINGLEAPPLICATION_LIB_H #include #if defined(KDSINGLEAPPLICATION_STATIC_BUILD) #define KDSINGLEAPPLICATION_EXPORT #elif defined(KDSINGLEAPPLICATION_SHARED_BUILD) #define KDSINGLEAPPLICATION_EXPORT Q_DECL_EXPORT #else #define KDSINGLEAPPLICATION_EXPORT Q_DECL_IMPORT #endif #endif // KDSINGLEAPPLICATION_LIB_H calamares-3.3.14/3rdparty/kdsingleapplication/kdsingleapplication_localsocket.cpp000066400000000000000000000241101475567644600304670ustar00rootroot00000000000000/* MIT License Copyright (C) 2019-2021 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ #include "kdsingleapplication_localsocket_p.h" #include #include #include #include #include #include #include #include #include #include #include #if defined(Q_OS_UNIX) // for ::getuid() #include #include #endif #if defined(Q_OS_WIN) #include #endif static const auto LOCALSOCKET_CONNECTION_TIMEOUT = std::chrono::seconds(5); static const char LOCALSOCKET_PROTOCOL_VERSION = 2; Q_LOGGING_CATEGORY(kdsaLocalSocket, "kdsingleapplication.localsocket", QtWarningMsg); KDSingleApplicationLocalSocket::KDSingleApplicationLocalSocket(const QString &name, QObject *parent) : QObject(parent) { #if defined(Q_OS_UNIX) m_socketName = QStringLiteral("kdsingleapp-%1-%2-%3") .arg(::getuid()) .arg(qEnvironmentVariable("XDG_SESSION_ID"), name); #elif defined(Q_OS_WIN) // I'm not sure of a "global session identifier" on Windows; are // multiple logins from the same user a possibility? For now, following this: // https://docs.microsoft.com/en-us/windows/desktop/devnotes/getting-the-session-id-of-the-current-process DWORD sessionId; BOOL haveSessionId = ProcessIdToSessionId(GetCurrentProcessId(), &sessionId); m_socketName = QString::fromUtf8("kdsingleapp-%1-%2") .arg(haveSessionId ? sessionId : 0) .arg(name); #else #error "KDSingleApplication has not been ported to this platform" #endif const QString lockFilePath = QDir::tempPath() + QLatin1Char('/') + m_socketName + QLatin1String(".lock"); qCDebug(kdsaLocalSocket) << "Socket name is" << m_socketName; qCDebug(kdsaLocalSocket) << "Lock file path is" << lockFilePath; std::unique_ptr lockFile(new QLockFile(lockFilePath)); lockFile->setStaleLockTime(0); if (!lockFile->tryLock()) { // someone else has the lock => we're secondary return; } std::unique_ptr server = std::make_unique(); if (!server->listen(m_socketName)) { // maybe the primary crashed, leaving a stale socket; delete it and try again QLocalServer::removeServer(m_socketName); if (!server->listen(m_socketName)) { // TODO: better error handling. qWarning("KDSingleApplication: unable to make the primary instance listen on %ls: %ls", qUtf16Printable(m_socketName), qUtf16Printable(server->errorString())); return; } } connect(server.get(), &QLocalServer::newConnection, this, &KDSingleApplicationLocalSocket::handleNewConnection); m_lockFile = std::move(lockFile); m_localServer = std::move(server); } KDSingleApplicationLocalSocket::~KDSingleApplicationLocalSocket() = default; bool KDSingleApplicationLocalSocket::isPrimaryInstance() const { return m_localServer != nullptr; } bool KDSingleApplicationLocalSocket::sendMessage(const QByteArray &message, int timeout) { Q_ASSERT(!isPrimaryInstance()); QLocalSocket socket; qCDebug(kdsaLocalSocket) << "Preparing to send message" << message << "with timeout" << timeout; QDeadlineTimer deadline(timeout); // There is an inherent race here with the setup of the server side. // Even if the socket lock is held by the server, the server may not // be listening yet. So this connection may fail; keep retrying // until we hit the timeout. do { socket.connectToServer(m_socketName); if (socket.waitForConnected(deadline.remainingTime())) break; } while (!deadline.hasExpired()); qCDebug(kdsaLocalSocket) << "Socket state:" << socket.state() << "Timer remaining" << deadline.remainingTime() << "Expired?" << deadline.hasExpired(); if (deadline.hasExpired()) return false; socket.write(&LOCALSOCKET_PROTOCOL_VERSION, 1); { QByteArray encodedMessage; QDataStream ds(&encodedMessage, QIODevice::WriteOnly); ds << message; socket.write(encodedMessage); } qCDebug(kdsaLocalSocket) << "Wrote message in the socket" << "Timer remaining" << deadline.remainingTime() << "Expired?" << deadline.hasExpired(); // There is no acknowledgement mechanism here. // Should there be one? while (socket.bytesToWrite() > 0) { if (!socket.waitForBytesWritten(deadline.remainingTime())) return false; } qCDebug(kdsaLocalSocket) << "Bytes written, now disconnecting" << "Timer remaining" << deadline.remainingTime() << "Expired?" << deadline.hasExpired(); socket.disconnectFromServer(); if (socket.state() == QLocalSocket::UnconnectedState) return true; if (!socket.waitForDisconnected(deadline.remainingTime())) return false; qCDebug(kdsaLocalSocket) << "Disconnected -- success!"; return true; } void KDSingleApplicationLocalSocket::handleNewConnection() { Q_ASSERT(m_localServer); QLocalSocket *socket = m_localServer->nextPendingConnection(); qCDebug(kdsaLocalSocket) << "Got new connection on" << m_socketName << "state" << socket->state(); Connection c(socket); c.readDataConnection = QObjectConnectionHolder( connect(c.socket.get(), &QLocalSocket::readyRead, this, &KDSingleApplicationLocalSocket::readDataFromSecondary)); c.secondaryDisconnectedConnection = QObjectConnectionHolder( connect(c.socket.get(), &QLocalSocket::disconnected, this, &KDSingleApplicationLocalSocket::secondaryDisconnected)); c.abortConnection = QObjectConnectionHolder( connect(c.timeoutTimer.get(), &QTimer::timeout, this, &KDSingleApplicationLocalSocket::abortConnectionToSecondary)); m_clients.push_back(std::move(c)); // Note that by the time we get here, the socket could've already been closed, // and no signals emitted (hello, Windows!). Read what's already in the socket. if (readDataFromSecondarySocket(socket)) return; if (socket->state() == QLocalSocket::UnconnectedState) secondarySocketDisconnected(socket); } template static auto findConnectionBySocket(Container &container, QLocalSocket *socket) { auto i = std::find_if(container.begin(), container.end(), [socket](const auto &c) { return c.socket.get() == socket; }); Q_ASSERT(i != container.end()); return i; } template static auto findConnectionByTimer(Container &container, QTimer *timer) { auto i = std::find_if(container.begin(), container.end(), [timer](const auto &c) { return c.timeoutTimer.get() == timer; }); Q_ASSERT(i != container.end()); return i; } void KDSingleApplicationLocalSocket::readDataFromSecondary() { QLocalSocket *socket = static_cast(sender()); readDataFromSecondarySocket(socket); } bool KDSingleApplicationLocalSocket::readDataFromSecondarySocket(QLocalSocket *socket) { auto i = findConnectionBySocket(m_clients, socket); Connection &c = *i; c.readData.append(socket->readAll()); qCDebug(kdsaLocalSocket) << "Got more data from a secondary. Data read so far:" << c.readData; const QByteArray &data = c.readData; if (data.size() >= 1) { if (data[0] != LOCALSOCKET_PROTOCOL_VERSION) { qCDebug(kdsaLocalSocket) << "Got an invalid protocol version"; m_clients.erase(i); return true; } } QDataStream ds(data); ds.skipRawData(1); ds.startTransaction(); QByteArray message; ds >> message; if (ds.commitTransaction()) { qCDebug(kdsaLocalSocket) << "Got a complete message:" << message; Q_EMIT messageReceived(message); m_clients.erase(i); return true; } return false; } void KDSingleApplicationLocalSocket::secondaryDisconnected() { QLocalSocket *socket = static_cast(sender()); secondarySocketDisconnected(socket); } void KDSingleApplicationLocalSocket::secondarySocketDisconnected(QLocalSocket *socket) { auto i = findConnectionBySocket(m_clients, socket); Connection c = std::move(*i); m_clients.erase(i); qCDebug(kdsaLocalSocket) << "Secondary disconnected. Data read:" << c.readData; } void KDSingleApplicationLocalSocket::abortConnectionToSecondary() { QTimer *timer = static_cast(sender()); auto i = findConnectionByTimer(m_clients, timer); Connection c = std::move(*i); m_clients.erase(i); qCDebug(kdsaLocalSocket) << "Secondary timed out. Data read:" << c.readData; } KDSingleApplicationLocalSocket::Connection::Connection(QLocalSocket *socket) : socket(socket) , timeoutTimer(new QTimer) { timeoutTimer->start(LOCALSOCKET_CONNECTION_TIMEOUT); } calamares-3.3.14/3rdparty/kdsingleapplication/kdsingleapplication_localsocket_p.h000066400000000000000000000077721475567644600304720ustar00rootroot00000000000000/* MIT License Copyright (C) 2019-2021 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ #ifndef KDSINGLEAPPLICATION_LOCALSOCKET_P_H #define KDSINGLEAPPLICATION_LOCALSOCKET_P_H #include #include #include QT_BEGIN_NAMESPACE class QLockFile; class QLocalServer; class QLocalSocket; class QTimer; QT_END_NAMESPACE #include #include struct QObjectDeleteLater { void operator()(QObject *o) { o->deleteLater(); } }; class QObjectConnectionHolder { Q_DISABLE_COPY(QObjectConnectionHolder) QMetaObject::Connection c; public: QObjectConnectionHolder() {} explicit QObjectConnectionHolder(QMetaObject::Connection c) : c(std::move(c)) { } ~QObjectConnectionHolder() { QObject::disconnect(c); } QObjectConnectionHolder(QObjectConnectionHolder &&other) noexcept : c(std::exchange(other.c, {})) {} QObjectConnectionHolder &operator=(QObjectConnectionHolder &&other) noexcept { QObjectConnectionHolder moved(std::move(other)); swap(moved); return *this; } void swap(QObjectConnectionHolder &other) noexcept { using std::swap; swap(c, other.c); } }; class KDSingleApplicationLocalSocket : public QObject { Q_OBJECT public: explicit KDSingleApplicationLocalSocket(const QString &name, QObject *parent = nullptr); ~KDSingleApplicationLocalSocket(); bool isPrimaryInstance() const; public Q_SLOTS: bool sendMessage(const QByteArray &message, int timeout); Q_SIGNALS: void messageReceived(const QByteArray &message); private: void handleNewConnection(); void readDataFromSecondary(); bool readDataFromSecondarySocket(QLocalSocket *socket); void secondaryDisconnected(); void secondarySocketDisconnected(QLocalSocket *socket); void abortConnectionToSecondary(); QString m_socketName; std::unique_ptr m_lockFile; // protects m_localServer std::unique_ptr m_localServer; struct Connection { explicit Connection(QLocalSocket *s); std::unique_ptr socket; std::unique_ptr timeoutTimer; QByteArray readData; // socket/timeoutTimer are deleted via deleteLater (as we delete them // in slots connected to their signals). Before the deleteLater is acted upon, // they may emit further signals, triggering logic that it's not supposed // to be triggered (as the Connection has already been destroyed). // Use this Holder to break the connections. QObjectConnectionHolder readDataConnection; QObjectConnectionHolder secondaryDisconnectedConnection; QObjectConnectionHolder abortConnection; }; std::vector m_clients; }; #endif // KDSINGLEAPPLICATION_LOCALSOCKET_P_H calamares-3.3.14/3rdparty/kdsingleapplication/src.pro000066400000000000000000000005671475567644600226770ustar00rootroot00000000000000include(../common.pri) TEMPLATE = lib TARGET = kdsingleapplication QT = core network CONFIG += static SOURCES += \ kdsingleapplication.cpp \ kdsingleapplication_localsocket.cpp \ HEADERS += \ kdsingleapplication.h \ kdsingleapplication_lib.h \ kdsingleapplication_localsocket_p.h \ DEFINES += \ KDSINGLEAPPLICATION_BUILD win32:LIBS += -lkernel32 calamares-3.3.14/3rdparty/pybind11/000077500000000000000000000000001475567644600167615ustar00rootroot00000000000000calamares-3.3.14/3rdparty/pybind11/CMakeLists.txt000066400000000000000000000010311475567644600215140ustar00rootroot00000000000000# === This file is part of Calamares - === # # SPDX-FileCopyrightText: 2023 Adriaan de Groot # SPDX-License-Identifier: BSD-2-Clause # ### # # This is a very-stripped-down way of getting the bundled pybind11 add_library(pybind11_headers INTERFACE) add_library(pybind11::headers ALIAS pybind11_headers) target_include_directories(pybind11_headers INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}/include) target_link_libraries(pybind11_headers INTERFACE Python::Python) # Was searched-for at top-level calamares-3.3.14/3rdparty/pybind11/LICENSE000066400000000000000000000032241475567644600177670ustar00rootroot00000000000000Copyright (c) 2016 Wenzel Jakob , All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. 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. 3. Neither the name of the copyright holder 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 HOLDER 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. Please also refer to the file .github/CONTRIBUTING.md, which clarifies licensing of external contributions to this project including patches, pull requests, etc. calamares-3.3.14/3rdparty/pybind11/MANIFEST.in000066400000000000000000000003671475567644600205250ustar00rootroot00000000000000prune tests recursive-include pybind11/include/pybind11 *.h recursive-include pybind11 *.py recursive-include pybind11 py.typed include pybind11/share/cmake/pybind11/*.cmake include LICENSE README.rst SECURITY.md pyproject.toml setup.py setup.cfg calamares-3.3.14/3rdparty/pybind11/README.rst000066400000000000000000000170071475567644600204550ustar00rootroot00000000000000.. figure:: https://github.com/pybind/pybind11/raw/master/docs/pybind11-logo.png :alt: pybind11 logo **pybind11 — Seamless operability between C++11 and Python** |Latest Documentation Status| |Stable Documentation Status| |Gitter chat| |GitHub Discussions| |CI| |Build status| |Repology| |PyPI package| |Conda-forge| |Python Versions| `Setuptools example `_ • `Scikit-build example `_ • `CMake example `_ .. start **pybind11** is a lightweight header-only library that exposes C++ types in Python and vice versa, mainly to create Python bindings of existing C++ code. Its goals and syntax are similar to the excellent `Boost.Python `_ library by David Abrahams: to minimize boilerplate code in traditional extension modules by inferring type information using compile-time introspection. The main issue with Boost.Python—and the reason for creating such a similar project—is Boost. Boost is an enormously large and complex suite of utility libraries that works with almost every C++ compiler in existence. This compatibility has its cost: arcane template tricks and workarounds are necessary to support the oldest and buggiest of compiler specimens. Now that C++11-compatible compilers are widely available, this heavy machinery has become an excessively large and unnecessary dependency. Think of this library as a tiny self-contained version of Boost.Python with everything stripped away that isn't relevant for binding generation. Without comments, the core header files only require ~4K lines of code and depend on Python (3.6+, or PyPy) and the C++ standard library. This compact implementation was possible thanks to some of the new C++11 language features (specifically: tuples, lambda functions and variadic templates). Since its creation, this library has grown beyond Boost.Python in many ways, leading to dramatically simpler binding code in many common situations. Tutorial and reference documentation is provided at `pybind11.readthedocs.io `_. A PDF version of the manual is available `here `_. And the source code is always available at `github.com/pybind/pybind11 `_. Core features ------------- pybind11 can map the following core C++ features to Python: - Functions accepting and returning custom data structures per value, reference, or pointer - Instance methods and static methods - Overloaded functions - Instance attributes and static attributes - Arbitrary exception types - Enumerations - Callbacks - Iterators and ranges - Custom operators - Single and multiple inheritance - STL data structures - Smart pointers with reference counting like ``std::shared_ptr`` - Internal references with correct reference counting - C++ classes with virtual (and pure virtual) methods can be extended in Python Goodies ------- In addition to the core functionality, pybind11 provides some extra goodies: - Python 3.6+, and PyPy3 7.3 are supported with an implementation-agnostic interface (pybind11 2.9 was the last version to support Python 2 and 3.5). - It is possible to bind C++11 lambda functions with captured variables. The lambda capture data is stored inside the resulting Python function object. - pybind11 uses C++11 move constructors and move assignment operators whenever possible to efficiently transfer custom data types. - It's easy to expose the internal storage of custom data types through Pythons' buffer protocols. This is handy e.g. for fast conversion between C++ matrix classes like Eigen and NumPy without expensive copy operations. - pybind11 can automatically vectorize functions so that they are transparently applied to all entries of one or more NumPy array arguments. - Python's slice-based access and assignment operations can be supported with just a few lines of code. - Everything is contained in just a few header files; there is no need to link against any additional libraries. - Binaries are generally smaller by a factor of at least 2 compared to equivalent bindings generated by Boost.Python. A recent pybind11 conversion of PyRosetta, an enormous Boost.Python binding project, `reported `_ a binary size reduction of **5.4x** and compile time reduction by **5.8x**. - Function signatures are precomputed at compile time (using ``constexpr``), leading to smaller binaries. - With little extra effort, C++ types can be pickled and unpickled similar to regular Python objects. Supported compilers ------------------- 1. Clang/LLVM 3.3 or newer (for Apple Xcode's clang, this is 5.0.0 or newer) 2. GCC 4.8 or newer 3. Microsoft Visual Studio 2017 or newer 4. Intel classic C++ compiler 18 or newer (ICC 20.2 tested in CI) 5. Cygwin/GCC (previously tested on 2.5.1) 6. NVCC (CUDA 11.0 tested in CI) 7. NVIDIA PGI (20.9 tested in CI) About ----- This project was created by `Wenzel Jakob `_. Significant features and/or improvements to the code were contributed by Jonas Adler, Lori A. Burns, Sylvain Corlay, Eric Cousineau, Aaron Gokaslan, Ralf Grosse-Kunstleve, Trent Houliston, Axel Huebl, @hulucc, Yannick Jadoul, Sergey Lyskov, Johan Mabille, Tomasz Miąsko, Dean Moldovan, Ben Pritchard, Jason Rhinelander, Boris Schäling, Pim Schellart, Henry Schreiner, Ivan Smirnov, Boris Staletic, and Patrick Stewart. We thank Google for a generous financial contribution to the continuous integration infrastructure used by this project. Contributing ~~~~~~~~~~~~ See the `contributing guide `_ for information on building and contributing to pybind11. License ~~~~~~~ pybind11 is provided under a BSD-style license that can be found in the `LICENSE `_ file. By using, distributing, or contributing to this project, you agree to the terms and conditions of this license. .. |Latest Documentation Status| image:: https://readthedocs.org/projects/pybind11/badge?version=latest :target: http://pybind11.readthedocs.org/en/latest .. |Stable Documentation Status| image:: https://img.shields.io/badge/docs-stable-blue.svg :target: http://pybind11.readthedocs.org/en/stable .. |Gitter chat| image:: https://img.shields.io/gitter/room/gitterHQ/gitter.svg :target: https://gitter.im/pybind/Lobby .. |CI| image:: https://github.com/pybind/pybind11/workflows/CI/badge.svg :target: https://github.com/pybind/pybind11/actions .. |Build status| image:: https://ci.appveyor.com/api/projects/status/riaj54pn4h08xy40?svg=true :target: https://ci.appveyor.com/project/wjakob/pybind11 .. |PyPI package| image:: https://img.shields.io/pypi/v/pybind11.svg :target: https://pypi.org/project/pybind11/ .. |Conda-forge| image:: https://img.shields.io/conda/vn/conda-forge/pybind11.svg :target: https://github.com/conda-forge/pybind11-feedstock .. |Repology| image:: https://repology.org/badge/latest-versions/python:pybind11.svg :target: https://repology.org/project/python:pybind11/versions .. |Python Versions| image:: https://img.shields.io/pypi/pyversions/pybind11.svg :target: https://pypi.org/project/pybind11/ .. |GitHub Discussions| image:: https://img.shields.io/static/v1?label=Discussions&message=Ask&color=blue&logo=github :target: https://github.com/pybind/pybind11/discussions calamares-3.3.14/3rdparty/pybind11/SECURITY.md000066400000000000000000000012601475567644600205510ustar00rootroot00000000000000# Security Policy ## Supported Versions Security updates are applied only to the latest release. ## Reporting a Vulnerability If you have discovered a security vulnerability in this project, please report it privately. **Do not disclose it as a public issue.** This gives us time to work with you to fix the issue before public exposure, reducing the chance that the exploit will be used before a patch is released. Please disclose it at [security advisory](https://github.com/pybind/pybind11/security/advisories/new). This project is maintained by a team of volunteers on a reasonable-effort basis. As such, please give us at least 90 days to work on a fix before public exposure. calamares-3.3.14/3rdparty/pybind11/include/000077500000000000000000000000001475567644600204045ustar00rootroot00000000000000calamares-3.3.14/3rdparty/pybind11/include/pybind11/000077500000000000000000000000001475567644600220335ustar00rootroot00000000000000calamares-3.3.14/3rdparty/pybind11/include/pybind11/attr.h000066400000000000000000000574161475567644600231730ustar00rootroot00000000000000/* pybind11/attr.h: Infrastructure for processing custom type and function attributes Copyright (c) 2016 Wenzel Jakob All rights reserved. Use of this source code is governed by a BSD-style license that can be found in the LICENSE file. */ #pragma once #include "detail/common.h" #include "cast.h" #include PYBIND11_NAMESPACE_BEGIN(PYBIND11_NAMESPACE) /// \addtogroup annotations /// @{ /// Annotation for methods struct is_method { handle class_; explicit is_method(const handle &c) : class_(c) {} }; /// Annotation for setters struct is_setter {}; /// Annotation for operators struct is_operator {}; /// Annotation for classes that cannot be subclassed struct is_final {}; /// Annotation for parent scope struct scope { handle value; explicit scope(const handle &s) : value(s) {} }; /// Annotation for documentation struct doc { const char *value; explicit doc(const char *value) : value(value) {} }; /// Annotation for function names struct name { const char *value; explicit name(const char *value) : value(value) {} }; /// Annotation indicating that a function is an overload associated with a given "sibling" struct sibling { handle value; explicit sibling(const handle &value) : value(value.ptr()) {} }; /// Annotation indicating that a class derives from another given type template struct base { PYBIND11_DEPRECATED( "base() was deprecated in favor of specifying 'T' as a template argument to class_") base() = default; }; /// Keep patient alive while nurse lives template struct keep_alive {}; /// Annotation indicating that a class is involved in a multiple inheritance relationship struct multiple_inheritance {}; /// Annotation which enables dynamic attributes, i.e. adds `__dict__` to a class struct dynamic_attr {}; /// Annotation which enables the buffer protocol for a type struct buffer_protocol {}; /// Annotation which requests that a special metaclass is created for a type struct metaclass { handle value; PYBIND11_DEPRECATED("py::metaclass() is no longer required. It's turned on by default now.") metaclass() = default; /// Override pybind11's default metaclass explicit metaclass(handle value) : value(value) {} }; /// Specifies a custom callback with signature `void (PyHeapTypeObject*)` that /// may be used to customize the Python type. /// /// The callback is invoked immediately before `PyType_Ready`. /// /// Note: This is an advanced interface, and uses of it may require changes to /// work with later versions of pybind11. You may wish to consult the /// implementation of `make_new_python_type` in `detail/classes.h` to understand /// the context in which the callback will be run. struct custom_type_setup { using callback = std::function; explicit custom_type_setup(callback value) : value(std::move(value)) {} callback value; }; /// Annotation that marks a class as local to the module: struct module_local { const bool value; constexpr explicit module_local(bool v = true) : value(v) {} }; /// Annotation to mark enums as an arithmetic type struct arithmetic {}; /// Mark a function for addition at the beginning of the existing overload chain instead of the end struct prepend {}; /** \rst A call policy which places one or more guard variables (``Ts...``) around the function call. For example, this definition: .. code-block:: cpp m.def("foo", foo, py::call_guard()); is equivalent to the following pseudocode: .. code-block:: cpp m.def("foo", [](args...) { T scope_guard; return foo(args...); // forwarded arguments }); \endrst */ template struct call_guard; template <> struct call_guard<> { using type = detail::void_type; }; template struct call_guard { static_assert(std::is_default_constructible::value, "The guard type must be default constructible"); using type = T; }; template struct call_guard { struct type { T guard{}; // Compose multiple guard types with left-to-right default-constructor order typename call_guard::type next{}; }; }; /// @} annotations PYBIND11_NAMESPACE_BEGIN(detail) /* Forward declarations */ enum op_id : int; enum op_type : int; struct undefined_t; template struct op_; void keep_alive_impl(size_t Nurse, size_t Patient, function_call &call, handle ret); /// Internal data structure which holds metadata about a keyword argument struct argument_record { const char *name; ///< Argument name const char *descr; ///< Human-readable version of the argument value handle value; ///< Associated Python object bool convert : 1; ///< True if the argument is allowed to convert when loading bool none : 1; ///< True if None is allowed when loading argument_record(const char *name, const char *descr, handle value, bool convert, bool none) : name(name), descr(descr), value(value), convert(convert), none(none) {} }; /// Internal data structure which holds metadata about a bound function (signature, overloads, /// etc.) struct function_record { function_record() : is_constructor(false), is_new_style_constructor(false), is_stateless(false), is_operator(false), is_method(false), is_setter(false), has_args(false), has_kwargs(false), prepend(false) {} /// Function name char *name = nullptr; /* why no C++ strings? They generate heavier code.. */ // User-specified documentation string char *doc = nullptr; /// Human-readable version of the function signature char *signature = nullptr; /// List of registered keyword arguments std::vector args; /// Pointer to lambda function which converts arguments and performs the actual call handle (*impl)(function_call &) = nullptr; /// Storage for the wrapped function pointer and captured data, if any void *data[3] = {}; /// Pointer to custom destructor for 'data' (if needed) void (*free_data)(function_record *ptr) = nullptr; /// Return value policy associated with this function return_value_policy policy = return_value_policy::automatic; /// True if name == '__init__' bool is_constructor : 1; /// True if this is a new-style `__init__` defined in `detail/init.h` bool is_new_style_constructor : 1; /// True if this is a stateless function pointer bool is_stateless : 1; /// True if this is an operator (__add__), etc. bool is_operator : 1; /// True if this is a method bool is_method : 1; /// True if this is a setter bool is_setter : 1; /// True if the function has a '*args' argument bool has_args : 1; /// True if the function has a '**kwargs' argument bool has_kwargs : 1; /// True if this function is to be inserted at the beginning of the overload resolution chain bool prepend : 1; /// Number of arguments (including py::args and/or py::kwargs, if present) std::uint16_t nargs; /// Number of leading positional arguments, which are terminated by a py::args or py::kwargs /// argument or by a py::kw_only annotation. std::uint16_t nargs_pos = 0; /// Number of leading arguments (counted in `nargs`) that are positional-only std::uint16_t nargs_pos_only = 0; /// Python method object PyMethodDef *def = nullptr; /// Python handle to the parent scope (a class or a module) handle scope; /// Python handle to the sibling function representing an overload chain handle sibling; /// Pointer to next overload function_record *next = nullptr; }; /// Special data structure which (temporarily) holds metadata about a bound class struct type_record { PYBIND11_NOINLINE type_record() : multiple_inheritance(false), dynamic_attr(false), buffer_protocol(false), default_holder(true), module_local(false), is_final(false) {} /// Handle to the parent scope handle scope; /// Name of the class const char *name = nullptr; // Pointer to RTTI type_info data structure const std::type_info *type = nullptr; /// How large is the underlying C++ type? size_t type_size = 0; /// What is the alignment of the underlying C++ type? size_t type_align = 0; /// How large is the type's holder? size_t holder_size = 0; /// The global operator new can be overridden with a class-specific variant void *(*operator_new)(size_t) = nullptr; /// Function pointer to class_<..>::init_instance void (*init_instance)(instance *, const void *) = nullptr; /// Function pointer to class_<..>::dealloc void (*dealloc)(detail::value_and_holder &) = nullptr; /// List of base classes of the newly created type list bases; /// Optional docstring const char *doc = nullptr; /// Custom metaclass (optional) handle metaclass; /// Custom type setup. custom_type_setup::callback custom_type_setup_callback; /// Multiple inheritance marker bool multiple_inheritance : 1; /// Does the class manage a __dict__? bool dynamic_attr : 1; /// Does the class implement the buffer protocol? bool buffer_protocol : 1; /// Is the default (unique_ptr) holder type used? bool default_holder : 1; /// Is the class definition local to the module shared object? bool module_local : 1; /// Is the class inheritable from python classes? bool is_final : 1; PYBIND11_NOINLINE void add_base(const std::type_info &base, void *(*caster)(void *) ) { auto *base_info = detail::get_type_info(base, false); if (!base_info) { std::string tname(base.name()); detail::clean_type_id(tname); pybind11_fail("generic_type: type \"" + std::string(name) + "\" referenced unknown base type \"" + tname + "\""); } if (default_holder != base_info->default_holder) { std::string tname(base.name()); detail::clean_type_id(tname); pybind11_fail("generic_type: type \"" + std::string(name) + "\" " + (default_holder ? "does not have" : "has") + " a non-default holder type while its base \"" + tname + "\" " + (base_info->default_holder ? "does not" : "does")); } bases.append((PyObject *) base_info->type); #if PY_VERSION_HEX < 0x030B0000 dynamic_attr |= base_info->type->tp_dictoffset != 0; #else dynamic_attr |= (base_info->type->tp_flags & Py_TPFLAGS_MANAGED_DICT) != 0; #endif if (caster) { base_info->implicit_casts.emplace_back(type, caster); } } }; inline function_call::function_call(const function_record &f, handle p) : func(f), parent(p) { args.reserve(f.nargs); args_convert.reserve(f.nargs); } /// Tag for a new-style `__init__` defined in `detail/init.h` struct is_new_style_constructor {}; /** * Partial template specializations to process custom attributes provided to * cpp_function_ and class_. These are either used to initialize the respective * fields in the type_record and function_record data structures or executed at * runtime to deal with custom call policies (e.g. keep_alive). */ template struct process_attribute; template struct process_attribute_default { /// Default implementation: do nothing static void init(const T &, function_record *) {} static void init(const T &, type_record *) {} static void precall(function_call &) {} static void postcall(function_call &, handle) {} }; /// Process an attribute specifying the function's name template <> struct process_attribute : process_attribute_default { static void init(const name &n, function_record *r) { r->name = const_cast(n.value); } }; /// Process an attribute specifying the function's docstring template <> struct process_attribute : process_attribute_default { static void init(const doc &n, function_record *r) { r->doc = const_cast(n.value); } }; /// Process an attribute specifying the function's docstring (provided as a C-style string) template <> struct process_attribute : process_attribute_default { static void init(const char *d, function_record *r) { r->doc = const_cast(d); } static void init(const char *d, type_record *r) { r->doc = d; } }; template <> struct process_attribute : process_attribute {}; /// Process an attribute indicating the function's return value policy template <> struct process_attribute : process_attribute_default { static void init(const return_value_policy &p, function_record *r) { r->policy = p; } }; /// Process an attribute which indicates that this is an overloaded function associated with a /// given sibling template <> struct process_attribute : process_attribute_default { static void init(const sibling &s, function_record *r) { r->sibling = s.value; } }; /// Process an attribute which indicates that this function is a method template <> struct process_attribute : process_attribute_default { static void init(const is_method &s, function_record *r) { r->is_method = true; r->scope = s.class_; } }; /// Process an attribute which indicates that this function is a setter template <> struct process_attribute : process_attribute_default { static void init(const is_setter &, function_record *r) { r->is_setter = true; } }; /// Process an attribute which indicates the parent scope of a method template <> struct process_attribute : process_attribute_default { static void init(const scope &s, function_record *r) { r->scope = s.value; } }; /// Process an attribute which indicates that this function is an operator template <> struct process_attribute : process_attribute_default { static void init(const is_operator &, function_record *r) { r->is_operator = true; } }; template <> struct process_attribute : process_attribute_default { static void init(const is_new_style_constructor &, function_record *r) { r->is_new_style_constructor = true; } }; inline void check_kw_only_arg(const arg &a, function_record *r) { if (r->args.size() > r->nargs_pos && (!a.name || a.name[0] == '\0')) { pybind11_fail("arg(): cannot specify an unnamed argument after a kw_only() annotation or " "args() argument"); } } inline void append_self_arg_if_needed(function_record *r) { if (r->is_method && r->args.empty()) { r->args.emplace_back("self", nullptr, handle(), /*convert=*/true, /*none=*/false); } } /// Process a keyword argument attribute (*without* a default value) template <> struct process_attribute : process_attribute_default { static void init(const arg &a, function_record *r) { append_self_arg_if_needed(r); r->args.emplace_back(a.name, nullptr, handle(), !a.flag_noconvert, a.flag_none); check_kw_only_arg(a, r); } }; /// Process a keyword argument attribute (*with* a default value) template <> struct process_attribute : process_attribute_default { static void init(const arg_v &a, function_record *r) { if (r->is_method && r->args.empty()) { r->args.emplace_back( "self", /*descr=*/nullptr, /*parent=*/handle(), /*convert=*/true, /*none=*/false); } if (!a.value) { #if defined(PYBIND11_DETAILED_ERROR_MESSAGES) std::string descr("'"); if (a.name) { descr += std::string(a.name) + ": "; } descr += a.type + "'"; if (r->is_method) { if (r->name) { descr += " in method '" + (std::string) str(r->scope) + "." + (std::string) r->name + "'"; } else { descr += " in method of '" + (std::string) str(r->scope) + "'"; } } else if (r->name) { descr += " in function '" + (std::string) r->name + "'"; } pybind11_fail("arg(): could not convert default argument " + descr + " into a Python object (type not registered yet?)"); #else pybind11_fail("arg(): could not convert default argument " "into a Python object (type not registered yet?). " "#define PYBIND11_DETAILED_ERROR_MESSAGES or compile in debug mode for " "more information."); #endif } r->args.emplace_back(a.name, a.descr, a.value.inc_ref(), !a.flag_noconvert, a.flag_none); check_kw_only_arg(a, r); } }; /// Process a keyword-only-arguments-follow pseudo argument template <> struct process_attribute : process_attribute_default { static void init(const kw_only &, function_record *r) { append_self_arg_if_needed(r); if (r->has_args && r->nargs_pos != static_cast(r->args.size())) { pybind11_fail("Mismatched args() and kw_only(): they must occur at the same relative " "argument location (or omit kw_only() entirely)"); } r->nargs_pos = static_cast(r->args.size()); } }; /// Process a positional-only-argument maker template <> struct process_attribute : process_attribute_default { static void init(const pos_only &, function_record *r) { append_self_arg_if_needed(r); r->nargs_pos_only = static_cast(r->args.size()); if (r->nargs_pos_only > r->nargs_pos) { pybind11_fail("pos_only(): cannot follow a py::args() argument"); } // It also can't follow a kw_only, but a static_assert in pybind11.h checks that } }; /// Process a parent class attribute. Single inheritance only (class_ itself already guarantees /// that) template struct process_attribute::value>> : process_attribute_default { static void init(const handle &h, type_record *r) { r->bases.append(h); } }; /// Process a parent class attribute (deprecated, does not support multiple inheritance) template struct process_attribute> : process_attribute_default> { static void init(const base &, type_record *r) { r->add_base(typeid(T), nullptr); } }; /// Process a multiple inheritance attribute template <> struct process_attribute : process_attribute_default { static void init(const multiple_inheritance &, type_record *r) { r->multiple_inheritance = true; } }; template <> struct process_attribute : process_attribute_default { static void init(const dynamic_attr &, type_record *r) { r->dynamic_attr = true; } }; template <> struct process_attribute { static void init(const custom_type_setup &value, type_record *r) { r->custom_type_setup_callback = value.value; } }; template <> struct process_attribute : process_attribute_default { static void init(const is_final &, type_record *r) { r->is_final = true; } }; template <> struct process_attribute : process_attribute_default { static void init(const buffer_protocol &, type_record *r) { r->buffer_protocol = true; } }; template <> struct process_attribute : process_attribute_default { static void init(const metaclass &m, type_record *r) { r->metaclass = m.value; } }; template <> struct process_attribute : process_attribute_default { static void init(const module_local &l, type_record *r) { r->module_local = l.value; } }; /// Process a 'prepend' attribute, putting this at the beginning of the overload chain template <> struct process_attribute : process_attribute_default { static void init(const prepend &, function_record *r) { r->prepend = true; } }; /// Process an 'arithmetic' attribute for enums (does nothing here) template <> struct process_attribute : process_attribute_default {}; template struct process_attribute> : process_attribute_default> {}; /** * Process a keep_alive call policy -- invokes keep_alive_impl during the * pre-call handler if both Nurse, Patient != 0 and use the post-call handler * otherwise */ template struct process_attribute> : public process_attribute_default> { template = 0> static void precall(function_call &call) { keep_alive_impl(Nurse, Patient, call, handle()); } template = 0> static void postcall(function_call &, handle) {} template = 0> static void precall(function_call &) {} template = 0> static void postcall(function_call &call, handle ret) { keep_alive_impl(Nurse, Patient, call, ret); } }; /// Recursively iterate over variadic template arguments template struct process_attributes { static void init(const Args &...args, function_record *r) { PYBIND11_WORKAROUND_INCORRECT_MSVC_C4100(r); PYBIND11_WORKAROUND_INCORRECT_GCC_UNUSED_BUT_SET_PARAMETER(r); using expander = int[]; (void) expander{ 0, ((void) process_attribute::type>::init(args, r), 0)...}; } static void init(const Args &...args, type_record *r) { PYBIND11_WORKAROUND_INCORRECT_MSVC_C4100(r); PYBIND11_WORKAROUND_INCORRECT_GCC_UNUSED_BUT_SET_PARAMETER(r); using expander = int[]; (void) expander{0, (process_attribute::type>::init(args, r), 0)...}; } static void precall(function_call &call) { PYBIND11_WORKAROUND_INCORRECT_MSVC_C4100(call); using expander = int[]; (void) expander{0, (process_attribute::type>::precall(call), 0)...}; } static void postcall(function_call &call, handle fn_ret) { PYBIND11_WORKAROUND_INCORRECT_MSVC_C4100(call, fn_ret); PYBIND11_WORKAROUND_INCORRECT_GCC_UNUSED_BUT_SET_PARAMETER(fn_ret); using expander = int[]; (void) expander{ 0, (process_attribute::type>::postcall(call, fn_ret), 0)...}; } }; template using is_call_guard = is_instantiation; /// Extract the ``type`` from the first `call_guard` in `Extras...` (or `void_type` if none found) template using extract_guard_t = typename exactly_one_t, Extra...>::type; /// Check the number of named arguments at compile time template ::value...), size_t self = constexpr_sum(std::is_same::value...)> constexpr bool expected_num_args(size_t nargs, bool has_args, bool has_kwargs) { PYBIND11_WORKAROUND_INCORRECT_MSVC_C4100(nargs, has_args, has_kwargs); return named == 0 || (self + named + size_t(has_args) + size_t(has_kwargs)) == nargs; } PYBIND11_NAMESPACE_END(detail) PYBIND11_NAMESPACE_END(PYBIND11_NAMESPACE) calamares-3.3.14/3rdparty/pybind11/include/pybind11/buffer_info.h000066400000000000000000000171061475567644600244750ustar00rootroot00000000000000/* pybind11/buffer_info.h: Python buffer object interface Copyright (c) 2016 Wenzel Jakob All rights reserved. Use of this source code is governed by a BSD-style license that can be found in the LICENSE file. */ #pragma once #include "detail/common.h" PYBIND11_NAMESPACE_BEGIN(PYBIND11_NAMESPACE) PYBIND11_NAMESPACE_BEGIN(detail) // Default, C-style strides inline std::vector c_strides(const std::vector &shape, ssize_t itemsize) { auto ndim = shape.size(); std::vector strides(ndim, itemsize); if (ndim > 0) { for (size_t i = ndim - 1; i > 0; --i) { strides[i - 1] = strides[i] * shape[i]; } } return strides; } // F-style strides; default when constructing an array_t with `ExtraFlags & f_style` inline std::vector f_strides(const std::vector &shape, ssize_t itemsize) { auto ndim = shape.size(); std::vector strides(ndim, itemsize); for (size_t i = 1; i < ndim; ++i) { strides[i] = strides[i - 1] * shape[i - 1]; } return strides; } template struct compare_buffer_info; PYBIND11_NAMESPACE_END(detail) /// Information record describing a Python buffer object struct buffer_info { void *ptr = nullptr; // Pointer to the underlying storage ssize_t itemsize = 0; // Size of individual items in bytes ssize_t size = 0; // Total number of entries std::string format; // For homogeneous buffers, this should be set to // format_descriptor::format() ssize_t ndim = 0; // Number of dimensions std::vector shape; // Shape of the tensor (1 entry per dimension) std::vector strides; // Number of bytes between adjacent entries // (for each per dimension) bool readonly = false; // flag to indicate if the underlying storage may be written to buffer_info() = default; buffer_info(void *ptr, ssize_t itemsize, const std::string &format, ssize_t ndim, detail::any_container shape_in, detail::any_container strides_in, bool readonly = false) : ptr(ptr), itemsize(itemsize), size(1), format(format), ndim(ndim), shape(std::move(shape_in)), strides(std::move(strides_in)), readonly(readonly) { if (ndim != (ssize_t) shape.size() || ndim != (ssize_t) strides.size()) { pybind11_fail("buffer_info: ndim doesn't match shape and/or strides length"); } for (size_t i = 0; i < (size_t) ndim; ++i) { size *= shape[i]; } } template buffer_info(T *ptr, detail::any_container shape_in, detail::any_container strides_in, bool readonly = false) : buffer_info(private_ctr_tag(), ptr, sizeof(T), format_descriptor::format(), static_cast(shape_in->size()), std::move(shape_in), std::move(strides_in), readonly) {} buffer_info(void *ptr, ssize_t itemsize, const std::string &format, ssize_t size, bool readonly = false) : buffer_info(ptr, itemsize, format, 1, {size}, {itemsize}, readonly) {} template buffer_info(T *ptr, ssize_t size, bool readonly = false) : buffer_info(ptr, sizeof(T), format_descriptor::format(), size, readonly) {} template buffer_info(const T *ptr, ssize_t size, bool readonly = true) : buffer_info( const_cast(ptr), sizeof(T), format_descriptor::format(), size, readonly) {} explicit buffer_info(Py_buffer *view, bool ownview = true) : buffer_info( view->buf, view->itemsize, view->format, view->ndim, {view->shape, view->shape + view->ndim}, /* Though buffer::request() requests PyBUF_STRIDES, ctypes objects * ignore this flag and return a view with NULL strides. * When strides are NULL, build them manually. */ view->strides ? std::vector(view->strides, view->strides + view->ndim) : detail::c_strides({view->shape, view->shape + view->ndim}, view->itemsize), (view->readonly != 0)) { // NOLINTNEXTLINE(cppcoreguidelines-prefer-member-initializer) this->m_view = view; // NOLINTNEXTLINE(cppcoreguidelines-prefer-member-initializer) this->ownview = ownview; } buffer_info(const buffer_info &) = delete; buffer_info &operator=(const buffer_info &) = delete; buffer_info(buffer_info &&other) noexcept { (*this) = std::move(other); } buffer_info &operator=(buffer_info &&rhs) noexcept { ptr = rhs.ptr; itemsize = rhs.itemsize; size = rhs.size; format = std::move(rhs.format); ndim = rhs.ndim; shape = std::move(rhs.shape); strides = std::move(rhs.strides); std::swap(m_view, rhs.m_view); std::swap(ownview, rhs.ownview); readonly = rhs.readonly; return *this; } ~buffer_info() { if (m_view && ownview) { PyBuffer_Release(m_view); delete m_view; } } Py_buffer *view() const { return m_view; } Py_buffer *&view() { return m_view; } /* True if the buffer item type is equivalent to `T`. */ // To define "equivalent" by example: // `buffer_info::item_type_is_equivalent_to(b)` and // `buffer_info::item_type_is_equivalent_to(b)` may both be true // on some platforms, but `int` and `unsigned` will never be equivalent. // For the ground truth, please inspect `detail::compare_buffer_info<>`. template bool item_type_is_equivalent_to() const { return detail::compare_buffer_info::compare(*this); } private: struct private_ctr_tag {}; buffer_info(private_ctr_tag, void *ptr, ssize_t itemsize, const std::string &format, ssize_t ndim, detail::any_container &&shape_in, detail::any_container &&strides_in, bool readonly) : buffer_info( ptr, itemsize, format, ndim, std::move(shape_in), std::move(strides_in), readonly) {} Py_buffer *m_view = nullptr; bool ownview = false; }; PYBIND11_NAMESPACE_BEGIN(detail) template struct compare_buffer_info { static bool compare(const buffer_info &b) { // NOLINTNEXTLINE(bugprone-sizeof-expression) Needed for `PyObject *` return b.format == format_descriptor::format() && b.itemsize == (ssize_t) sizeof(T); } }; template struct compare_buffer_info::value>> { static bool compare(const buffer_info &b) { return (size_t) b.itemsize == sizeof(T) && (b.format == format_descriptor::value || ((sizeof(T) == sizeof(long)) && b.format == (std::is_unsigned::value ? "L" : "l")) || ((sizeof(T) == sizeof(size_t)) && b.format == (std::is_unsigned::value ? "N" : "n"))); } }; PYBIND11_NAMESPACE_END(detail) PYBIND11_NAMESPACE_END(PYBIND11_NAMESPACE) calamares-3.3.14/3rdparty/pybind11/include/pybind11/cast.h000066400000000000000000002033601475567644600231420ustar00rootroot00000000000000/* pybind11/cast.h: Partial template specializations to cast between C++ and Python types Copyright (c) 2016 Wenzel Jakob All rights reserved. Use of this source code is governed by a BSD-style license that can be found in the LICENSE file. */ #pragma once #include "detail/common.h" #include "detail/descr.h" #include "detail/type_caster_base.h" #include "detail/typeid.h" #include "pytypes.h" #include #include #include #include #include #include #include #include #include #include #include PYBIND11_NAMESPACE_BEGIN(PYBIND11_NAMESPACE) PYBIND11_WARNING_DISABLE_MSVC(4127) PYBIND11_NAMESPACE_BEGIN(detail) template class type_caster : public type_caster_base {}; template using make_caster = type_caster>; // Shortcut for calling a caster's `cast_op_type` cast operator for casting a type_caster to a T template typename make_caster::template cast_op_type cast_op(make_caster &caster) { return caster.operator typename make_caster::template cast_op_type(); } template typename make_caster::template cast_op_type::type> cast_op(make_caster &&caster) { return std::move(caster).operator typename make_caster:: template cast_op_type::type>(); } template class type_caster> { private: using caster_t = make_caster; caster_t subcaster; using reference_t = type &; using subcaster_cast_op_type = typename caster_t::template cast_op_type; static_assert( std::is_same::type &, subcaster_cast_op_type>::value || std::is_same::value, "std::reference_wrapper caster requires T to have a caster with an " "`operator T &()` or `operator const T &()`"); public: bool load(handle src, bool convert) { return subcaster.load(src, convert); } static constexpr auto name = caster_t::name; static handle cast(const std::reference_wrapper &src, return_value_policy policy, handle parent) { // It is definitely wrong to take ownership of this pointer, so mask that rvp if (policy == return_value_policy::take_ownership || policy == return_value_policy::automatic) { policy = return_value_policy::automatic_reference; } return caster_t::cast(&src.get(), policy, parent); } template using cast_op_type = std::reference_wrapper; explicit operator std::reference_wrapper() { return cast_op(subcaster); } }; #define PYBIND11_TYPE_CASTER(type, py_name) \ protected: \ type value; \ \ public: \ static constexpr auto name = py_name; \ template >::value, \ int> \ = 0> \ static ::pybind11::handle cast( \ T_ *src, ::pybind11::return_value_policy policy, ::pybind11::handle parent) { \ if (!src) \ return ::pybind11::none().release(); \ if (policy == ::pybind11::return_value_policy::take_ownership) { \ auto h = cast(std::move(*src), policy, parent); \ delete src; \ return h; \ } \ return cast(*src, policy, parent); \ } \ operator type *() { return &value; } /* NOLINT(bugprone-macro-parentheses) */ \ operator type &() { return value; } /* NOLINT(bugprone-macro-parentheses) */ \ operator type &&() && { return std::move(value); } /* NOLINT(bugprone-macro-parentheses) */ \ template \ using cast_op_type = ::pybind11::detail::movable_cast_op_type template using is_std_char_type = any_of, /* std::string */ #if defined(PYBIND11_HAS_U8STRING) std::is_same, /* std::u8string */ #endif std::is_same, /* std::u16string */ std::is_same, /* std::u32string */ std::is_same /* std::wstring */ >; template struct type_caster::value && !is_std_char_type::value>> { using _py_type_0 = conditional_t; using _py_type_1 = conditional_t::value, _py_type_0, typename std::make_unsigned<_py_type_0>::type>; using py_type = conditional_t::value, double, _py_type_1>; public: bool load(handle src, bool convert) { py_type py_value; if (!src) { return false; } #if !defined(PYPY_VERSION) auto index_check = [](PyObject *o) { return PyIndex_Check(o); }; #else // In PyPy 7.3.3, `PyIndex_Check` is implemented by calling `__index__`, // while CPython only considers the existence of `nb_index`/`__index__`. auto index_check = [](PyObject *o) { return hasattr(o, "__index__"); }; #endif if (std::is_floating_point::value) { if (convert || PyFloat_Check(src.ptr())) { py_value = (py_type) PyFloat_AsDouble(src.ptr()); } else { return false; } } else if (PyFloat_Check(src.ptr()) || (!convert && !PYBIND11_LONG_CHECK(src.ptr()) && !index_check(src.ptr()))) { return false; } else { handle src_or_index = src; // PyPy: 7.3.7's 3.8 does not implement PyLong_*'s __index__ calls. #if PY_VERSION_HEX < 0x03080000 || defined(PYPY_VERSION) object index; if (!PYBIND11_LONG_CHECK(src.ptr())) { // So: index_check(src.ptr()) index = reinterpret_steal(PyNumber_Index(src.ptr())); if (!index) { PyErr_Clear(); if (!convert) return false; } else { src_or_index = index; } } #endif if (std::is_unsigned::value) { py_value = as_unsigned(src_or_index.ptr()); } else { // signed integer: py_value = sizeof(T) <= sizeof(long) ? (py_type) PyLong_AsLong(src_or_index.ptr()) : (py_type) PYBIND11_LONG_AS_LONGLONG(src_or_index.ptr()); } } // Python API reported an error bool py_err = py_value == (py_type) -1 && PyErr_Occurred(); // Check to see if the conversion is valid (integers should match exactly) // Signed/unsigned checks happen elsewhere if (py_err || (std::is_integral::value && sizeof(py_type) != sizeof(T) && py_value != (py_type) (T) py_value)) { PyErr_Clear(); if (py_err && convert && (PyNumber_Check(src.ptr()) != 0)) { auto tmp = reinterpret_steal(std::is_floating_point::value ? PyNumber_Float(src.ptr()) : PyNumber_Long(src.ptr())); PyErr_Clear(); return load(tmp, false); } return false; } value = (T) py_value; return true; } template static typename std::enable_if::value, handle>::type cast(U src, return_value_policy /* policy */, handle /* parent */) { return PyFloat_FromDouble((double) src); } template static typename std::enable_if::value && std::is_signed::value && (sizeof(U) <= sizeof(long)), handle>::type cast(U src, return_value_policy /* policy */, handle /* parent */) { return PYBIND11_LONG_FROM_SIGNED((long) src); } template static typename std::enable_if::value && std::is_unsigned::value && (sizeof(U) <= sizeof(unsigned long)), handle>::type cast(U src, return_value_policy /* policy */, handle /* parent */) { return PYBIND11_LONG_FROM_UNSIGNED((unsigned long) src); } template static typename std::enable_if::value && std::is_signed::value && (sizeof(U) > sizeof(long)), handle>::type cast(U src, return_value_policy /* policy */, handle /* parent */) { return PyLong_FromLongLong((long long) src); } template static typename std::enable_if::value && std::is_unsigned::value && (sizeof(U) > sizeof(unsigned long)), handle>::type cast(U src, return_value_policy /* policy */, handle /* parent */) { return PyLong_FromUnsignedLongLong((unsigned long long) src); } PYBIND11_TYPE_CASTER(T, const_name::value>("int", "float")); }; template struct void_caster { public: bool load(handle src, bool) { if (src && src.is_none()) { return true; } return false; } static handle cast(T, return_value_policy /* policy */, handle /* parent */) { return none().release(); } PYBIND11_TYPE_CASTER(T, const_name("None")); }; template <> class type_caster : public void_caster {}; template <> class type_caster : public type_caster { public: using type_caster::cast; bool load(handle h, bool) { if (!h) { return false; } if (h.is_none()) { value = nullptr; return true; } /* Check if this is a capsule */ if (isinstance(h)) { value = reinterpret_borrow(h); return true; } /* Check if this is a C++ type */ const auto &bases = all_type_info((PyTypeObject *) type::handle_of(h).ptr()); if (bases.size() == 1) { // Only allowing loading from a single-value type value = values_and_holders(reinterpret_cast(h.ptr())).begin()->value_ptr(); return true; } /* Fail */ return false; } static handle cast(const void *ptr, return_value_policy /* policy */, handle /* parent */) { if (ptr) { return capsule(ptr).release(); } return none().release(); } template using cast_op_type = void *&; explicit operator void *&() { return value; } static constexpr auto name = const_name("capsule"); private: void *value = nullptr; }; template <> class type_caster : public void_caster {}; template <> class type_caster { public: bool load(handle src, bool convert) { if (!src) { return false; } if (src.ptr() == Py_True) { value = true; return true; } if (src.ptr() == Py_False) { value = false; return true; } if (convert || (std::strcmp("numpy.bool_", Py_TYPE(src.ptr())->tp_name) == 0)) { // (allow non-implicit conversion for numpy booleans) Py_ssize_t res = -1; if (src.is_none()) { res = 0; // None is implicitly converted to False } #if defined(PYPY_VERSION) // On PyPy, check that "__bool__" attr exists else if (hasattr(src, PYBIND11_BOOL_ATTR)) { res = PyObject_IsTrue(src.ptr()); } #else // Alternate approach for CPython: this does the same as the above, but optimized // using the CPython API so as to avoid an unneeded attribute lookup. else if (auto *tp_as_number = src.ptr()->ob_type->tp_as_number) { if (PYBIND11_NB_BOOL(tp_as_number)) { res = (*PYBIND11_NB_BOOL(tp_as_number))(src.ptr()); } } #endif if (res == 0 || res == 1) { value = (res != 0); return true; } PyErr_Clear(); } return false; } static handle cast(bool src, return_value_policy /* policy */, handle /* parent */) { return handle(src ? Py_True : Py_False).inc_ref(); } PYBIND11_TYPE_CASTER(bool, const_name("bool")); }; // Helper class for UTF-{8,16,32} C++ stl strings: template struct string_caster { using CharT = typename StringType::value_type; // Simplify life by being able to assume standard char sizes (the standard only guarantees // minimums, but Python requires exact sizes) static_assert(!std::is_same::value || sizeof(CharT) == 1, "Unsupported char size != 1"); #if defined(PYBIND11_HAS_U8STRING) static_assert(!std::is_same::value || sizeof(CharT) == 1, "Unsupported char8_t size != 1"); #endif static_assert(!std::is_same::value || sizeof(CharT) == 2, "Unsupported char16_t size != 2"); static_assert(!std::is_same::value || sizeof(CharT) == 4, "Unsupported char32_t size != 4"); // wchar_t can be either 16 bits (Windows) or 32 (everywhere else) static_assert(!std::is_same::value || sizeof(CharT) == 2 || sizeof(CharT) == 4, "Unsupported wchar_t size != 2/4"); static constexpr size_t UTF_N = 8 * sizeof(CharT); bool load(handle src, bool) { handle load_src = src; if (!src) { return false; } if (!PyUnicode_Check(load_src.ptr())) { return load_raw(load_src); } // For UTF-8 we avoid the need for a temporary `bytes` object by using // `PyUnicode_AsUTF8AndSize`. if (UTF_N == 8) { Py_ssize_t size = -1; const auto *buffer = reinterpret_cast(PyUnicode_AsUTF8AndSize(load_src.ptr(), &size)); if (!buffer) { PyErr_Clear(); return false; } value = StringType(buffer, static_cast(size)); return true; } auto utfNbytes = reinterpret_steal(PyUnicode_AsEncodedString(load_src.ptr(), UTF_N == 8 ? "utf-8" : UTF_N == 16 ? "utf-16" : "utf-32", nullptr)); if (!utfNbytes) { PyErr_Clear(); return false; } const auto *buffer = reinterpret_cast(PYBIND11_BYTES_AS_STRING(utfNbytes.ptr())); size_t length = (size_t) PYBIND11_BYTES_SIZE(utfNbytes.ptr()) / sizeof(CharT); // Skip BOM for UTF-16/32 if (UTF_N > 8) { buffer++; length--; } value = StringType(buffer, length); // If we're loading a string_view we need to keep the encoded Python object alive: if (IsView) { loader_life_support::add_patient(utfNbytes); } return true; } static handle cast(const StringType &src, return_value_policy /* policy */, handle /* parent */) { const char *buffer = reinterpret_cast(src.data()); auto nbytes = ssize_t(src.size() * sizeof(CharT)); handle s = decode_utfN(buffer, nbytes); if (!s) { throw error_already_set(); } return s; } PYBIND11_TYPE_CASTER(StringType, const_name(PYBIND11_STRING_NAME)); private: static handle decode_utfN(const char *buffer, ssize_t nbytes) { #if !defined(PYPY_VERSION) return UTF_N == 8 ? PyUnicode_DecodeUTF8(buffer, nbytes, nullptr) : UTF_N == 16 ? PyUnicode_DecodeUTF16(buffer, nbytes, nullptr, nullptr) : PyUnicode_DecodeUTF32(buffer, nbytes, nullptr, nullptr); #else // PyPy segfaults when on PyUnicode_DecodeUTF16 (and possibly on PyUnicode_DecodeUTF32 as // well), so bypass the whole thing by just passing the encoding as a string value, which // works properly: return PyUnicode_Decode(buffer, nbytes, UTF_N == 8 ? "utf-8" : UTF_N == 16 ? "utf-16" : "utf-32", nullptr); #endif } // When loading into a std::string or char*, accept a bytes/bytearray object as-is (i.e. // without any encoding/decoding attempt). For other C++ char sizes this is a no-op. // which supports loading a unicode from a str, doesn't take this path. template bool load_raw(enable_if_t::value, handle> src) { if (PYBIND11_BYTES_CHECK(src.ptr())) { // We were passed raw bytes; accept it into a std::string or char* // without any encoding attempt. const char *bytes = PYBIND11_BYTES_AS_STRING(src.ptr()); if (!bytes) { pybind11_fail("Unexpected PYBIND11_BYTES_AS_STRING() failure."); } value = StringType(bytes, (size_t) PYBIND11_BYTES_SIZE(src.ptr())); return true; } if (PyByteArray_Check(src.ptr())) { // We were passed a bytearray; accept it into a std::string or char* // without any encoding attempt. const char *bytearray = PyByteArray_AsString(src.ptr()); if (!bytearray) { pybind11_fail("Unexpected PyByteArray_AsString() failure."); } value = StringType(bytearray, (size_t) PyByteArray_Size(src.ptr())); return true; } return false; } template bool load_raw(enable_if_t::value, handle>) { return false; } }; template struct type_caster, enable_if_t::value>> : string_caster> {}; #ifdef PYBIND11_HAS_STRING_VIEW template struct type_caster, enable_if_t::value>> : string_caster, true> {}; #endif // Type caster for C-style strings. We basically use a std::string type caster, but also add the // ability to use None as a nullptr char* (which the string caster doesn't allow). template struct type_caster::value>> { using StringType = std::basic_string; using StringCaster = make_caster; StringCaster str_caster; bool none = false; CharT one_char = 0; public: bool load(handle src, bool convert) { if (!src) { return false; } if (src.is_none()) { // Defer accepting None to other overloads (if we aren't in convert mode): if (!convert) { return false; } none = true; return true; } return str_caster.load(src, convert); } static handle cast(const CharT *src, return_value_policy policy, handle parent) { if (src == nullptr) { return pybind11::none().release(); } return StringCaster::cast(StringType(src), policy, parent); } static handle cast(CharT src, return_value_policy policy, handle parent) { if (std::is_same::value) { handle s = PyUnicode_DecodeLatin1((const char *) &src, 1, nullptr); if (!s) { throw error_already_set(); } return s; } return StringCaster::cast(StringType(1, src), policy, parent); } explicit operator CharT *() { return none ? nullptr : const_cast(static_cast(str_caster).c_str()); } explicit operator CharT &() { if (none) { throw value_error("Cannot convert None to a character"); } auto &value = static_cast(str_caster); size_t str_len = value.size(); if (str_len == 0) { throw value_error("Cannot convert empty string to a character"); } // If we're in UTF-8 mode, we have two possible failures: one for a unicode character that // is too high, and one for multiple unicode characters (caught later), so we need to // figure out how long the first encoded character is in bytes to distinguish between these // two errors. We also allow want to allow unicode characters U+0080 through U+00FF, as // those can fit into a single char value. if (StringCaster::UTF_N == 8 && str_len > 1 && str_len <= 4) { auto v0 = static_cast(value[0]); // low bits only: 0-127 // 0b110xxxxx - start of 2-byte sequence // 0b1110xxxx - start of 3-byte sequence // 0b11110xxx - start of 4-byte sequence size_t char0_bytes = (v0 & 0x80) == 0 ? 1 : (v0 & 0xE0) == 0xC0 ? 2 : (v0 & 0xF0) == 0xE0 ? 3 : 4; if (char0_bytes == str_len) { // If we have a 128-255 value, we can decode it into a single char: if (char0_bytes == 2 && (v0 & 0xFC) == 0xC0) { // 0x110000xx 0x10xxxxxx one_char = static_cast(((v0 & 3) << 6) + (static_cast(value[1]) & 0x3F)); return one_char; } // Otherwise we have a single character, but it's > U+00FF throw value_error("Character code point not in range(0x100)"); } } // UTF-16 is much easier: we can only have a surrogate pair for values above U+FFFF, thus a // surrogate pair with total length 2 instantly indicates a range error (but not a "your // string was too long" error). else if (StringCaster::UTF_N == 16 && str_len == 2) { one_char = static_cast(value[0]); if (one_char >= 0xD800 && one_char < 0xE000) { throw value_error("Character code point not in range(0x10000)"); } } if (str_len != 1) { throw value_error("Expected a character, but multi-character string found"); } one_char = value[0]; return one_char; } static constexpr auto name = const_name(PYBIND11_STRING_NAME); template using cast_op_type = pybind11::detail::cast_op_type<_T>; }; // Base implementation for std::tuple and std::pair template