linux-sparse.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Christopher Li" <sparse@chrisli.org>
To: Linux-Sparse <linux-sparse@vger.kernel.org>,
	Alexey Zaytsev <alexey.zaytsev@gmail.com>,
	Josh Triplett <josh@freedesktop.org>
Subject: [1/2] find ptr in a list
Date: Wed, 3 Sep 2008 22:34:29 -0700	[thread overview]
Message-ID: <70318cbf0809032234y3dbc6968kde3dbfef0af8108f@mail.gmail.com> (raw)

[-- Attachment #1: Type: text/plain, Size: 51 bytes --]

Signed-Off-By: Christopher Li <sparse@chrisli.org>

[-- Attachment #2: find-ptr-in-list --]
[-- Type: application/octet-stream, Size: 1197 bytes --]

Adding some helper function to find a pointer in the ptrlist.

Index: sparse/ptrlist.h
===================================================================
--- sparse.orig/ptrlist.h
+++ sparse/ptrlist.h
@@ -45,6 +45,8 @@ extern void concat_ptr_list(struct ptr_l
 extern void __free_ptr_list(struct ptr_list **);
 extern int ptr_list_size(struct ptr_list *);
 extern int linearize_ptr_list(struct ptr_list *, void **, int);
+extern int find_ptr_in_list(struct ptr_list* list, void *ptr);
+extern int find_ptr_index(struct ptr_list* list, void *ptr);
 
 /*
  * Hey, who said that you can't do overloading in C?
Index: sparse/ptrlist.c
===================================================================
--- sparse.orig/ptrlist.c
+++ sparse/ptrlist.c
@@ -246,3 +246,29 @@ void __free_ptr_list(struct ptr_list **l
 
 	*listp = NULL;
 }
+
+int find_ptr_in_list(struct ptr_list* list, void *ptr)
+{
+	void *p;
+	FOR_EACH_PTR(list, p) {
+		if (p == ptr)
+			return 1;
+	} END_FOR_EACH_PTR(p);
+	return 0;
+}
+
+int find_ptr_index(struct ptr_list* list, void *ptr)
+{
+	void *p;
+	int i = 0;
+	FOR_EACH_PTR(list, p) {
+		if (p == ptr)
+			return i;
+		i++;
+	} END_FOR_EACH_PTR(p);
+	return -1;
+}
+
+
+
+

                 reply	other threads:[~2008-09-04  5:34 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=70318cbf0809032234y3dbc6968kde3dbfef0af8108f@mail.gmail.com \
    --to=sparse@chrisli.org \
    --cc=alexey.zaytsev@gmail.com \
    --cc=josh@freedesktop.org \
    --cc=linux-sparse@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).