annotate Objects/stringlib/count.h @ 79063:2bdc8c8ea42e

Issue #15977: Fix memory leak in Modules/_ssl.c when the function _set_npn_protocols() is called multiple times
author Christian Heimes <christian@cheimes.de>
date Thu, 20 Sep 2012 12:42:54 +0200
parents 8beaa9a37387
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
38453
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1 /* stringlib: count implementation */
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
2
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
3 #ifndef STRINGLIB_FASTSEARCH_H
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
4 #error must include "stringlib/fastsearch.h" before including this module
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
5 #endif
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
6
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
7 Py_LOCAL_INLINE(Py_ssize_t)
72475
8beaa9a37387 Implement PEP 393.
Martin v. Löwis <martin@v.loewis.de>
parents: 58289
diff changeset
8 STRINGLIB(count)(const STRINGLIB_CHAR* str, Py_ssize_t str_len,
58289
5ca1948a8fd6 Merged revisions 77461 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 49310
diff changeset
9 const STRINGLIB_CHAR* sub, Py_ssize_t sub_len,
5ca1948a8fd6 Merged revisions 77461 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 49310
diff changeset
10 Py_ssize_t maxcount)
38453
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
11 {
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
12 Py_ssize_t count;
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
13
49310
6403f1edecc1 Merged revisions 66631 via svnmerge from
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 38669
diff changeset
14 if (str_len < 0)
6403f1edecc1 Merged revisions 66631 via svnmerge from
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 38669
diff changeset
15 return 0; /* start > len(str) */
6403f1edecc1 Merged revisions 66631 via svnmerge from
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 38669
diff changeset
16 if (sub_len == 0)
58289
5ca1948a8fd6 Merged revisions 77461 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 49310
diff changeset
17 return (str_len < maxcount) ? str_len + 1 : maxcount;
38453
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
18
72475
8beaa9a37387 Implement PEP 393.
Martin v. Löwis <martin@v.loewis.de>
parents: 58289
diff changeset
19 count = FASTSEARCH(str, str_len, sub, sub_len, maxcount, FAST_COUNT);
38453
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
20
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
21 if (count < 0)
58289
5ca1948a8fd6 Merged revisions 77461 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 49310
diff changeset
22 return 0; /* no match */
38453
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
23
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
24 return count;
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
25 }
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
26
72475
8beaa9a37387 Implement PEP 393.
Martin v. Löwis <martin@v.loewis.de>
parents: 58289
diff changeset
27