From nobody Wed Mar 27 11:26:15 2024 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4V4PWC6jhYz5FHgQ; Wed, 27 Mar 2024 11:26:15 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4V4PWC5V2nz4bhY; Wed, 27 Mar 2024 11:26:15 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1711538775; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=TaNQrVZEb4GbIlidk8yY82y6sVXNSBLY4Sgo3PFiAY4=; b=Kl3qpPgrplm9580NSZmpGH4XnrTvW/MeCcM8vtfRFg8bL/6DvvkYntS1RsFXOJJyZ0slVU kyVqQsyq5iER8HWonaIOg01qFG6pWi9rmvDR3JQC3QpxesifYEXZuqlpWi0k/CtX5f3/KA K1BS9qAqp4hnrwxnG1WHFNdtRAQLDeWaT3mjwjV9cEDN6dQRnYqvoAchpZfwoW6NJFUWwT vW7CutHG+YsfAo10bb6nBHWDrGeFgS0MPwKqKvkriRGqm1aDxS7w4dOXDE4tXVDiMmk0Y5 W3yUPL8wS0sNlVFMiL4LCWtYGRbV2GbXrc1YfHrKS6RNwRuXLDdaa9ZjWQYnnQ== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1711538775; a=rsa-sha256; cv=none; b=YE9p+arLlGCWNrSCkelQ5sxSAuem28MT3z+r4K/LKrmSri5fpRN3fdiUb+Jt5WcPDua78b z5+lcMGiA3aAsazAnBUqwc5jz8QaFFZHVxcvB5fYE3zNYMxApLUPhYZXhEj97eFW4Vqc7q psRRN9PKLudpOlU1iUltbLTDz+C5zKOiFqlHtAFk9ki+p2yvgvd0XmEPYmYANcGJ4aRv7R AnmTJMkB9mw82r1n56fdasCoFNQUvFAFnFMLnmX67/C/lsr5yx/bUnPV73sv8bxLdyEao/ r6oKk7Oet6HguLlYI3Ctd5FOQTSRkQ5WvJjYksrINCJWGVL0EH4V47syBMq8QA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1711538775; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=TaNQrVZEb4GbIlidk8yY82y6sVXNSBLY4Sgo3PFiAY4=; b=XwDhLr7LOf+UEvpSMmw/BPJupioQvEL7KCRw+MiK0lBBN0a33ngln6HfC9uch58csjxzdX +2gxVrw4r0MaqbjR0l+bFH13i3DLBFuM+Vvcm/bftyxDYmwyp2gmts9CG+ZplxZpbhGvDv IJ0vhclpLL8ntY0E5oyf9ARlYmBnA7D5rMa/iHrykWBPni2/OIZISw8+lVyrAIAcvCUXx4 arBIPp6+LeFnIO1W4FK0WyBcI9IYTHdWogvGjALpUmfJVslPRUDCylrlbi16O1u8OSdN5N Tyiflw31+1aDT3eBsvwqN49hBEXokktmG6cVTbPUlTRApMLB45bxInUOWYzpGA== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4V4PWC4ySkzhZD; Wed, 27 Mar 2024 11:26:15 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.17.1/8.17.1) with ESMTP id 42RBQFZc003640; Wed, 27 Mar 2024 11:26:15 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 42RBQF2C003637; Wed, 27 Mar 2024 11:26:15 GMT (envelope-from git) Date: Wed, 27 Mar 2024 11:26:15 GMT Message-Id: <202403271126.42RBQF2C003637@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Dag-Erling =?utf-8?Q?Sm=C3=B8rgrav?= Subject: git: 5fbe8912d6a2 - main - libdiff: Improve function prototype detection. List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: des X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 5fbe8912d6a2d1178468d1994c301d4c7cd4f975 Auto-Submitted: auto-generated The branch main has been updated by des: URL: https://cgit.FreeBSD.org/src/commit/?id=5fbe8912d6a2d1178468d1994c301d4c7cd4f975 commit 5fbe8912d6a2d1178468d1994c301d4c7cd4f975 Author: Dag-Erling Smørgrav AuthorDate: 2024-03-27 10:03:29 +0000 Commit: Dag-Erling Smørgrav CommitDate: 2024-03-27 10:03:29 +0000 libdiff: Improve function prototype detection. - Recognize ObjC methods. - Start searching within the leading context. Sponsored by: Klara, Inc. Reviewed by: thj Differential Revision: https://reviews.freebsd.org/D44301 --- contrib/libdiff/lib/diff_internal.h | 2 +- contrib/libdiff/lib/diff_output.c | 9 +++++---- contrib/libdiff/lib/diff_output_unidiff.c | 24 ++++++++++++------------ 3 files changed, 18 insertions(+), 17 deletions(-) diff --git a/contrib/libdiff/lib/diff_internal.h b/contrib/libdiff/lib/diff_internal.h index 46bbadf3cb64..16ee6776a71f 100644 --- a/contrib/libdiff/lib/diff_internal.h +++ b/contrib/libdiff/lib/diff_internal.h @@ -148,7 +148,7 @@ int diff_output_trailing_newline_msg(struct diff_output_info *outinfo, int diff_output_match_function_prototype(char *prototype, size_t prototype_size, int *last_prototype_idx, const struct diff_result *result, - const struct diff_chunk_context *cc); + int chunk_start_line); struct diff_output_info *diff_output_info_alloc(void); diff --git a/contrib/libdiff/lib/diff_output.c b/contrib/libdiff/lib/diff_output.c index 7ac63bb6c433..78d9b8942077 100644 --- a/contrib/libdiff/lib/diff_output.c +++ b/contrib/libdiff/lib/diff_output.c @@ -255,7 +255,8 @@ diff_output_trailing_newline_msg(struct diff_output_info *outinfo, FILE *dest, static bool is_function_prototype(unsigned char ch) { - return (isalpha((unsigned char)ch) || ch == '_' || ch == '$'); + return (isalpha((unsigned char)ch) || ch == '_' || ch == '$' || + ch == '-' || ch == '+'); } #define begins_with(s, pre) (strncmp(s, pre, sizeof(pre)-1) == 0) @@ -263,7 +264,7 @@ is_function_prototype(unsigned char ch) int diff_output_match_function_prototype(char *prototype, size_t prototype_size, int *last_prototype_idx, const struct diff_result *result, - const struct diff_chunk_context *cc) + int chunk_start_line) { struct diff_atom *start_atom, *atom; const struct diff_data *data; @@ -271,9 +272,9 @@ diff_output_match_function_prototype(char *prototype, size_t prototype_size, const char *state = NULL; int rc, i, ch; - if (result->left->atoms.len > 0 && cc->left.start > 0) { + if (result->left->atoms.len > 0 && chunk_start_line > 0) { data = result->left; - start_atom = &data->atoms.head[cc->left.start - 1]; + start_atom = &data->atoms.head[chunk_start_line - 1]; } else return DIFF_RC_OK; diff --git a/contrib/libdiff/lib/diff_output_unidiff.c b/contrib/libdiff/lib/diff_output_unidiff.c index d480a022a9a7..88c98c663c00 100644 --- a/contrib/libdiff/lib/diff_output_unidiff.c +++ b/contrib/libdiff/lib/diff_output_unidiff.c @@ -301,10 +301,21 @@ output_unidiff_chunk(struct diff_output_info *outinfo, FILE *dest, else right_start = cc->right.start + 1; + /* Got the absolute line numbers where to start printing, and the index + * of the interesting (non-context) chunk. + * To print context lines above the interesting chunk, nipping on the + * previous chunk index may be necessary. + * It is guaranteed to be only context lines where left == right, so it + * suffices to look on the left. */ + const struct diff_chunk *first_chunk; + int chunk_start_line; + first_chunk = &result->chunks.head[cc->chunk.start]; + chunk_start_line = diff_atom_root_idx(result->left, + first_chunk->left_start); if (show_function_prototypes) { rc = diff_output_match_function_prototype(state->prototype, sizeof(state->prototype), &state->last_prototype_idx, - result, cc); + result, chunk_start_line); if (rc) return rc; } @@ -344,17 +355,6 @@ output_unidiff_chunk(struct diff_output_info *outinfo, FILE *dest, *typep = DIFF_LINE_HUNK; } - /* Got the absolute line numbers where to start printing, and the index - * of the interesting (non-context) chunk. - * To print context lines above the interesting chunk, nipping on the - * previous chunk index may be necessary. - * It is guaranteed to be only context lines where left == right, so it - * suffices to look on the left. */ - const struct diff_chunk *first_chunk; - int chunk_start_line; - first_chunk = &result->chunks.head[cc->chunk.start]; - chunk_start_line = diff_atom_root_idx(result->left, - first_chunk->left_start); if (cc->left.start < chunk_start_line) { rc = diff_output_lines(outinfo, dest, " ", &result->left->atoms.head[cc->left.start],