From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Stefan Kangas Newsgroups: gmane.emacs.devel Subject: Re: master d995429e7bc: Use SBYTES instead of strlen in treesit.c Date: Wed, 24 Jul 2024 04:33:32 -0700 Message-ID: References: <172164369582.30827.14373383262408294645@vcs2.savannah.gnu.org> <20240722102136.6C9D6C3534A@vcs2.savannah.gnu.org> <87o76pyb5h.fsf@yahoo.com> <8634o1br4c.fsf@gnu.org> Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="15901"; mail-complaints-to="usenet@ciao.gmane.io" Cc: Eli Zaretskii , Yuan Fu , luangruo@yahoo.com, emacs-devel@gnu.org To: =?UTF-8?Q?Mattias_Engdeg=C3=A5rd?= Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Wed Jul 24 13:34:26 2024 Return-path: Envelope-to: ged-emacs-devel@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1sWaGH-00041m-01 for ged-emacs-devel@m.gmane-mx.org; Wed, 24 Jul 2024 13:34:25 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sWaFX-0008Pi-T6; Wed, 24 Jul 2024 07:33:39 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sWaFW-0008PU-5Q for emacs-devel@gnu.org; Wed, 24 Jul 2024 07:33:38 -0400 Original-Received: from mail-ed1-x52e.google.com ([2a00:1450:4864:20::52e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sWaFU-0000sR-FB; Wed, 24 Jul 2024 07:33:37 -0400 Original-Received: by mail-ed1-x52e.google.com with SMTP id 4fb4d7f45d1cf-5a2ffc34722so1525058a12.0; Wed, 24 Jul 2024 04:33:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1721820814; x=1722425614; darn=gnu.org; h=content-transfer-encoding:cc:to:subject:message-id:date :mime-version:references:in-reply-to:from:from:to:cc:subject:date :message-id:reply-to; bh=b6goU0qpPwkL+v2B9z/zH0xnY3E0IsJDJNeUyW7sLxs=; b=Bx/xk25mnclHtdnGclsQbG9DwxM2dE37/3dXAMAy1KKz/4baG5AEitT+bRZkEh2n5I 6G3bnysl6AYIQnTraa8tCY7CUbvX/Xw+MNOxkoWszvgm7gnr5w+aATbzTv+JJiDye4Rk C54UB2TNOhPBt0IA+Xm3/A4Hud/3Zl2hbEw4eVz8I3QTtUIO5Xc+EoT4B5F3uhOpcvgv MwgNF6C0KLicS5yKQxdWZ6eI78dkuPRXgtndzmhnkrpH0RwLhjU5xRVZ8YrU/K9By07h /fMsGx25rl9Rauxlyok1IkWcgrcrXY/m0YyCpoDf63RrfKkqdsx1/z/W+Ey/MXppeK6p mAIw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1721820814; x=1722425614; h=content-transfer-encoding:cc:to:subject:message-id:date :mime-version:references:in-reply-to:from:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=b6goU0qpPwkL+v2B9z/zH0xnY3E0IsJDJNeUyW7sLxs=; b=HAH/c2fVMHclfAtMHyzCkh6L5RjdBYGinH7ZnSjIBaeaTKGK9PptwKH2M/EXiKaXz+ x+SefKX/rtBvgMg+cyDuE2AC+jrqHHKY1bpQ+qObGyF4uAc/OOLF6icsUe8O1tTMh3bF X4Tsnn5rHIPvKzFHxl5ZqS3KJr51QC8vgwXx2gJxsACNozLDCUeNwliuS0kdNaXBG2wY /CBlJGEajjoGa7gRGnt2LKCWoRl/gv2LpGyXSYJBRqMKFYUJ9kNh8htzvz2EngPobLZ1 2JRx0TKcG0R87QF62d3ZVoaOvb08jwgTEt1rvnpbtK99DJuEbXlGekIdknKj8hZblGfo ahRg== X-Forwarded-Encrypted: i=1; AJvYcCXLljOAr9WGlFK0RocW0KwKKYtVqgyBK8ENrhdSvfJS8Bzxd0K5FDDZGhw/OZOiLO3WfDcDe7/M78gJMl+/WFeTSF4z X-Gm-Message-State: AOJu0YyQMMzu7Nk/pmOzsLbZNjQyk23mQ2ewO5AzhayXoQIicsaVZWrp HXgNO5xI9RoCU1tLaM45wFAioIZ5uQR+QejVxOhSEKrTWjdvB0IJcMT7RUYdcc/z7G/12HbU6jP LnCxyoLoBnruZBFNba0LMJbhNxANXBfY0 X-Google-Smtp-Source: AGHT+IFTrNpVStPmb5QAr0HdFH8VVPRAgkjp1nQ4Vq1ndxlNukg/TY2qsdnjSJPErdqJ8auD85oV5et+DTVVYfXrGlo= X-Received: by 2002:a50:ab50:0:b0:57d:3df:ba2d with SMTP id 4fb4d7f45d1cf-5ab19dccee9mr2019431a12.2.1721820813580; Wed, 24 Jul 2024 04:33:33 -0700 (PDT) Original-Received: from 753933720722 named unknown by gmailapi.google.com with HTTPREST; Wed, 24 Jul 2024 04:33:32 -0700 In-Reply-To: Received-SPF: pass client-ip=2a00:1450:4864:20::52e; envelope-from=stefankangas@gmail.com; helo=mail-ed1-x52e.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.devel:322039 Archived-At: Mattias Engdeg=C3=A5rd writes: > 23 juli 2024 kl. 22.42 skrev Stefan Kangas : > >>> We avoid that when they are converted from a sexp (see >>> treesit_query_string_string). >>> >>> Perhaps we should do the same when we get a string? > > Tree-sitter is something of which I know very little, but if you mean > taking care of NULs when we create a Lisp string from what we get from > tree-sitter, then it doesn't seem to be too broken at a quick glance: It's not about what we get from tree-sitter, but what we pass to it. I recently changed calls to ts_node_child_by_field_name and treesit_query from using strlen for the length argument to using SBYTES. But that meant that we now pass a length of 7 instead of 3 for Lisp strings like "abc\^@def". The question is if tree-sitter will accept that. If it doesn't, I proposed that we might want to escape the NULs using treesit_query_string_string. I'm struggling to find anything clear in the tree-sitter documentation about this, but I see your recent change. The other options are either warning about such Lisp strings when we get them, or (my least favorite option) just revert back to using strlen. > (We have too many string constructors in general and several of them > don't do precisely what the caller thought they would but that's a > different problem, to be dealt with another day.) Cleaning that up would be welcome in my book, FWIW.