Show a patch.

GET /api/1.1/patches/20757/?format=api
HTTP 200 OK
Allow: GET, PUT, PATCH, HEAD, OPTIONS
Content-Type: application/json
Vary: Accept

{
    "id": 20757,
    "url": "https://patchwork.libcamera.org/api/1.1/patches/20757/?format=api",
    "web_url": "https://patchwork.libcamera.org/patch/20757/",
    "project": {
        "id": 1,
        "url": "https://patchwork.libcamera.org/api/1.1/projects/1/?format=api",
        "name": "libcamera",
        "link_name": "libcamera",
        "list_id": "libcamera_core",
        "list_email": "libcamera-devel@lists.libcamera.org",
        "web_url": "",
        "scm_url": "",
        "webscm_url": ""
    },
    "msgid": "<20240804133605.8234-1-laurent.pinchart@ideasonboard.com>",
    "date": "2024-08-04T13:36:05",
    "name": "[v2] libcamera: software_isp: Replace malloc() with std::vector<>",
    "commit_ref": "57396a0e3f08a5cd1ea6f48c66f3decdfeaa7dfd",
    "pull_url": null,
    "state": "accepted",
    "archived": false,
    "hash": "d9b70c953e191f0a7cede21f66923e3320f17169",
    "submitter": {
        "id": 2,
        "url": "https://patchwork.libcamera.org/api/1.1/people/2/?format=api",
        "name": "Laurent Pinchart",
        "email": "laurent.pinchart@ideasonboard.com"
    },
    "delegate": null,
    "mbox": "https://patchwork.libcamera.org/patch/20757/mbox/",
    "series": [
        {
            "id": 4481,
            "url": "https://patchwork.libcamera.org/api/1.1/series/4481/?format=api",
            "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=4481",
            "date": "2024-08-04T13:36:05",
            "name": "[v2] libcamera: software_isp: Replace malloc() with std::vector<>",
            "version": 2,
            "mbox": "https://patchwork.libcamera.org/series/4481/mbox/"
        }
    ],
    "comments": "https://patchwork.libcamera.org/api/patches/20757/comments/",
    "check": "pending",
    "checks": "https://patchwork.libcamera.org/api/patches/20757/checks/",
    "tags": {},
    "headers": {
        "Return-Path": "<libcamera-devel-bounces@lists.libcamera.org>",
        "X-Original-To": "parsemail@patchwork.libcamera.org",
        "Delivered-To": "parsemail@patchwork.libcamera.org",
        "Received": [
            "from lancelot.ideasonboard.com (lancelot.ideasonboard.com\n\t[92.243.16.209])\n\tby patchwork.libcamera.org (Postfix) with ESMTPS id DFA9FBDC71\n\tfor <parsemail@patchwork.libcamera.org>;\n\tSun,  4 Aug 2024 13:36:31 +0000 (UTC)",
            "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id E56B163380;\n\tSun,  4 Aug 2024 15:36:30 +0200 (CEST)",
            "from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 2A7DE6192D\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tSun,  4 Aug 2024 15:36:29 +0200 (CEST)",
            "from pendragon.ideasonboard.com (81-175-209-231.bb.dnainternet.fi\n\t[81.175.209.231])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 2B6AC1BA\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tSun,  4 Aug 2024 15:35:38 +0200 (CEST)"
        ],
        "Authentication-Results": "lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"iQA+f52W\"; dkim-atps=neutral",
        "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1722778538;\n\tbh=hWTjZl9JhSEWi0GmULDLVT7KO1QF4o+VejB8ZRaeTNY=;\n\th=From:To:Subject:Date:From;\n\tb=iQA+f52W0zsGm9uTexIp5KoyqhXhw+l8Bbk10zqedziPMqXBlAmsJHFW2qYBuxjoi\n\tB/TWdu802YmvNkg8t7lrQWCsLtGKXBq9TUR9RZ0mwkJ/glJBeLL963b9frXi3gS0Lf\n\trLo1wYRFHetI3kljg7uUtg/2btXDUIGt634LqVU8=",
        "From": "Laurent Pinchart <laurent.pinchart@ideasonboard.com>",
        "To": "libcamera-devel@lists.libcamera.org",
        "Subject": "[PATCH v2] libcamera: software_isp: Replace malloc() with\n\tstd::vector<>",
        "Date": "Sun,  4 Aug 2024 16:36:05 +0300",
        "Message-ID": "<20240804133605.8234-1-laurent.pinchart@ideasonboard.com>",
        "X-Mailer": "git-send-email 2.44.2",
        "MIME-Version": "1.0",
        "Content-Transfer-Encoding": "8bit",
        "X-BeenThere": "libcamera-devel@lists.libcamera.org",
        "X-Mailman-Version": "2.1.29",
        "Precedence": "list",
        "List-Id": "<libcamera-devel.lists.libcamera.org>",
        "List-Unsubscribe": "<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>",
        "List-Archive": "<https://lists.libcamera.org/pipermail/libcamera-devel/>",
        "List-Post": "<mailto:libcamera-devel@lists.libcamera.org>",
        "List-Help": "<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>",
        "List-Subscribe": "<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>",
        "Errors-To": "libcamera-devel-bounces@lists.libcamera.org",
        "Sender": "\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"
    },
    "content": "libcamera is implemented in C++, use std::vector<> to manage the\ndynamically allocated line buffers instead of malloc() and free(). This\nsimplifies the code and improves memory safety by ensuring no allocation\nwill be leaked.\n\nSigned-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n---\nChanges since v1:\n\n- Use std::vector instead of new[]() and delete[]()\n---\n src/libcamera/software_isp/debayer_cpu.cpp | 31 +++++++++-------------\n src/libcamera/software_isp/debayer_cpu.h   |  2 +-\n 2 files changed, 13 insertions(+), 20 deletions(-)\n\n\nbase-commit: 19bbca3c0b376ba0183f5db53472c8c46cd402b5",
    "diff": "diff --git a/src/libcamera/software_isp/debayer_cpu.cpp b/src/libcamera/software_isp/debayer_cpu.cpp\nindex f8d2677d657a..077f7f4bc45b 100644\n--- a/src/libcamera/software_isp/debayer_cpu.cpp\n+++ b/src/libcamera/software_isp/debayer_cpu.cpp\n@@ -49,16 +49,9 @@ DebayerCpu::DebayerCpu(std::unique_ptr<SwStatsCpu> stats)\n \t/* Initialize color lookup tables */\n \tfor (unsigned int i = 0; i < DebayerParams::kRGBLookupSize; i++)\n \t\tred_[i] = green_[i] = blue_[i] = i;\n-\n-\tfor (unsigned int i = 0; i < kMaxLineBuffers; i++)\n-\t\tlineBuffers_[i] = nullptr;\n }\n \n-DebayerCpu::~DebayerCpu()\n-{\n-\tfor (unsigned int i = 0; i < kMaxLineBuffers; i++)\n-\t\tfree(lineBuffers_[i]);\n-}\n+DebayerCpu::~DebayerCpu() = default;\n \n #define DECLARE_SRC_POINTERS(pixel_t)                            \\\n \tconst pixel_t *prev = (const pixel_t *)src[0] + xShift_; \\\n@@ -526,13 +519,10 @@ int DebayerCpu::configure(const StreamConfiguration &inputCfg,\n \tlineBufferPadding_ = inputConfig_.patternSize.width * inputConfig_.bpp / 8;\n \tlineBufferLength_ = window_.width * inputConfig_.bpp / 8 +\n \t\t\t    2 * lineBufferPadding_;\n-\tfor (unsigned int i = 0;\n-\t     i < (inputConfig_.patternSize.height + 1) && enableInputMemcpy_;\n-\t     i++) {\n-\t\tfree(lineBuffers_[i]);\n-\t\tlineBuffers_[i] = (uint8_t *)malloc(lineBufferLength_);\n-\t\tif (!lineBuffers_[i])\n-\t\t\treturn -ENOMEM;\n+\n+\tif (enableInputMemcpy_) {\n+\t\tfor (unsigned int i = 0; i <= inputConfig_.patternSize.height; i++)\n+\t\t\tlineBuffers_[i].resize(lineBufferLength_);\n \t}\n \n \tmeasuredFrames_ = 0;\n@@ -587,9 +577,10 @@ void DebayerCpu::setupInputMemcpy(const uint8_t *linePointers[])\n \t\treturn;\n \n \tfor (unsigned int i = 0; i < patternHeight; i++) {\n-\t\tmemcpy(lineBuffers_[i], linePointers[i + 1] - lineBufferPadding_,\n+\t\tmemcpy(lineBuffers_[i].data(),\n+\t\t       linePointers[i + 1] - lineBufferPadding_,\n \t\t       lineBufferLength_);\n-\t\tlinePointers[i + 1] = lineBuffers_[i] + lineBufferPadding_;\n+\t\tlinePointers[i + 1] = lineBuffers_[i].data() + lineBufferPadding_;\n \t}\n \n \t/* Point lineBufferIndex_ to first unused lineBuffer */\n@@ -614,9 +605,11 @@ void DebayerCpu::memcpyNextLine(const uint8_t *linePointers[])\n \tif (!enableInputMemcpy_)\n \t\treturn;\n \n-\tmemcpy(lineBuffers_[lineBufferIndex_], linePointers[patternHeight] - lineBufferPadding_,\n+\tmemcpy(lineBuffers_[lineBufferIndex_].data(),\n+\t       linePointers[patternHeight] - lineBufferPadding_,\n \t       lineBufferLength_);\n-\tlinePointers[patternHeight] = lineBuffers_[lineBufferIndex_] + lineBufferPadding_;\n+\tlinePointers[patternHeight] = lineBuffers_[lineBufferIndex_].data()\n+\t\t\t\t    + lineBufferPadding_;\n \n \tlineBufferIndex_ = (lineBufferIndex_ + 1) % (patternHeight + 1);\n }\ndiff --git a/src/libcamera/software_isp/debayer_cpu.h b/src/libcamera/software_isp/debayer_cpu.h\nindex 1dac64351f1d..8237a64be733 100644\n--- a/src/libcamera/software_isp/debayer_cpu.h\n+++ b/src/libcamera/software_isp/debayer_cpu.h\n@@ -146,7 +146,7 @@ private:\n \tDebayerInputConfig inputConfig_;\n \tDebayerOutputConfig outputConfig_;\n \tstd::unique_ptr<SwStatsCpu> stats_;\n-\tuint8_t *lineBuffers_[kMaxLineBuffers];\n+\tstd::vector<uint8_t> lineBuffers_[kMaxLineBuffers];\n \tunsigned int lineBufferLength_;\n \tunsigned int lineBufferPadding_;\n \tunsigned int lineBufferIndex_;\n",
    "prefixes": [
        "v2"
    ]
}