From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: storm@cua.dk (Kim F. Storm) Newsgroups: gmane.emacs.devel Subject: Re: valid_pointer_p Date: Sat, 12 Aug 2006 22:19:50 +0200 Message-ID: References: NNTP-Posting-Host: main.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: sea.gmane.org 1155414139 6466 80.91.229.2 (12 Aug 2006 20:22:19 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Sat, 12 Aug 2006 20:22:19 +0000 (UTC) Cc: Andreas Schwab , emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Sat Aug 12 22:22:16 2006 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by ciao.gmane.org with esmtp (Exim 4.43) id 1GBzzg-00055K-Bx for ged-emacs-devel@m.gmane.org; Sat, 12 Aug 2006 22:22:04 +0200 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1GBzzf-0005Zk-Ou for ged-emacs-devel@m.gmane.org; Sat, 12 Aug 2006 16:22:03 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1GBzzT-0005ZN-IJ for emacs-devel@gnu.org; Sat, 12 Aug 2006 16:21:51 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1GBzzR-0005ZB-RT for emacs-devel@gnu.org; Sat, 12 Aug 2006 16:21:50 -0400 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1GBzzR-0005Z8-MW for emacs-devel@gnu.org; Sat, 12 Aug 2006 16:21:49 -0400 Original-Received: from [195.41.46.235] (helo=pfepa.post.tele.dk) by monty-python.gnu.org with esmtp (Exim 4.52) id 1GC04q-0003q1-Ja; Sat, 12 Aug 2006 16:27:24 -0400 Original-Received: from kfs-l.imdomain.dk.cua.dk (0x503e2644.bynxx3.adsl-dhcp.tele.dk [80.62.38.68]) by pfepa.post.tele.dk (Postfix) with SMTP id BA3DCFAC024; Sat, 12 Aug 2006 22:21:25 +0200 (CEST) Original-To: Eli Zaretskii In-Reply-To: (Eli Zaretskii's message of "Sat, 12 Aug 2006 17:39:30 +0300") User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.0.50 (gnu/linux) X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:58332 Archived-At: Eli Zaretskii writes: >> From: Andreas Schwab >> Cc: storm@cua.dk (Kim F. Storm), emacs-devel@gnu.org >> Date: Sat, 12 Aug 2006 14:36:22 +0200 >> >> Eli Zaretskii writes: >> >> > ??? Don't we have macros, like INTEGERP, SUBRP, etc. to do that >> > without dereferencing? The length of the primitive Lisp types is >> > known, right? >> >> Try to find out the size of a vector object. >> >> /* Vector of Lisp objects, or something resembling it. >> XVECTOR (object) points to a struct Lisp_Vector, which contains >> the size and contents. The size field also contains the type >> information, if it's not a real vector object. */ >> Lisp_Vectorlike, > > I think something like this should work for such cases: > > struct Lisp_Vector *p = XVECTOR (obj); > > if (valid_pointer_p (p, offsetof (struct Lisp_Vector, size) > + sizeof (EMACS_INT)) > && valid_pointer_p (p, p->size)) > return 1; /* valid */ > > (Modulo the complications of storing other information in the leading > bits of the `size' field of struct Lisp_Vector.) This is what I meant > when I wrote: > > Even if you are right, dereferencing a pointer accesses a region in > memory whose length is known in advance, so at most we will need to > call valid_pointer_p twice. > > Am I missing something? No. My simple approach was simply to assume that if you can access the size field of a vector, you can access the rest as well. I don't mind making a more correct implementation, although I didn't see the need -- after all, this is for a corner case of debugging emacs. -- Kim F. Storm http://www.cua.dk