From: Petr Holasek <pholasek@redhat.com>
To: Cliff Wickman <cpw@sgi.com>
Cc: linux-numa@vger.kernel.org, Andi Kleen <andi@firstfloor.org>,
Anton Arapov <anton@redhat.com>,
Petr Holasek <pholasek@redhat.com>
Subject: [PATCH v2 5/7] libnuma: numa_parse_cpustring and similar should take a const char* parameter
Date: Thu, 23 Aug 2012 18:01:57 +0200 [thread overview]
Message-ID: <1345737719-11433-6-git-send-email-pholasek@redhat.com> (raw)
In-Reply-To: <1345737719-11433-1-git-send-email-pholasek@redhat.com>
Input string is handled like it was a const and it doesn't actually modify the
string that it is parsing. It raises warning with following C++ reproducer:
using namespace std;
int main (int argc, char **argv)
{
bitmask *pbm = numa_allocate_cpumask();
pbm = numa_bitmask_clearall(pbm);
if ((pbm = numa_parse_cpustring("2-5,8,10")) != NULL) {
cout << " cpumask bitmask 2-5,8,10 = ";
for (int n=0;n<numa_num_configured_cpus();++n) {
cout << numa_bitmask_isbitset(pbm, n);
}
cout << endl;
}
}
Signed-off-by: Petr Holasek <pholasek@redhat.com>
---
affinity.c | 17 +++++++++--------
affinity.h | 2 +-
libnuma.c | 14 +++++++-------
numa.3 | 8 ++++----
numa.h | 8 ++++----
5 files changed, 25 insertions(+), 24 deletions(-)
diff --git a/affinity.c b/affinity.c
index 2c0cabc..a226b59 100644
--- a/affinity.c
+++ b/affinity.c
@@ -49,14 +49,14 @@
#include "affinity.h"
#include "rtnetlink.h"
-static int badchar(char *s)
+static int badchar(const char *s)
{
if (strpbrk(s, "/."))
return 1;
return 0;
}
-static int node_parse_failure(int ret, char *cls, char *dev)
+static int node_parse_failure(int ret, char *cls, const char *dev)
{
if (!cls)
cls = "";
@@ -72,7 +72,8 @@ static int node_parse_failure(int ret, char *cls, char *dev)
}
/* Generic sysfs class lookup */
-static int affinity_class(struct bitmask *mask, char *cls, char *dev)
+static int
+affinity_class(struct bitmask *mask, char *cls, const const char *dev)
{
int ret;
while (isspace(*dev))
@@ -121,7 +122,7 @@ static int affinity_class(struct bitmask *mask, char *cls, char *dev)
/* Turn file (or device node) into class name */
-static int affinity_file(struct bitmask *mask, char *cls, char *file)
+static int affinity_file(struct bitmask *mask, char *cls, const char *file)
{
struct stat st;
DIR *dir;
@@ -249,7 +250,7 @@ static int iif_to_name(int iif, struct ifreq *ifr)
This generally only attempts to handle simple cases:
no multi-path, no bounding etc. In these cases only
the first interface or none is chosen. */
-static int affinity_ip(struct bitmask *mask, char *cls, char *id)
+static int affinity_ip(struct bitmask *mask, char *cls, const char *id)
{
struct addrinfo *ai;
int n;
@@ -279,7 +280,7 @@ out_ai:
}
/* Look up affinity for a PCI device */
-static int affinity_pci(struct bitmask *mask, char *cls, char *id)
+static int affinity_pci(struct bitmask *mask, char *cls, const char *id)
{
unsigned seg, bus, dev, func;
int n, ret;
@@ -310,7 +311,7 @@ static struct handler {
char first;
char *name;
char *cls;
- int (*handler)(struct bitmask *mask, char *cls, char *desc);
+ int (*handler)(struct bitmask *mask, char *cls, const char *desc);
} handlers[] = {
{ 'n', "netdev:", "net", affinity_class },
{ 'i', "ip:", NULL, affinity_ip },
@@ -320,7 +321,7 @@ static struct handler {
{}
};
-hidden int resolve_affinity(char *id, struct bitmask *mask)
+hidden int resolve_affinity(const char *id, struct bitmask *mask)
{
struct handler *h;
diff --git a/affinity.h b/affinity.h
index 4863d8f..a513749 100644
--- a/affinity.h
+++ b/affinity.h
@@ -2,5 +2,5 @@ enum {
NO_IO_AFFINITY = -2
};
-int resolve_affinity(char *id, struct bitmask *mask);
+int resolve_affinity(const char *id, struct bitmask *mask);
diff --git a/libnuma.c b/libnuma.c
index 0fb3b11..9c9a1de 100755
--- a/libnuma.c
+++ b/libnuma.c
@@ -1718,7 +1718,7 @@ void numa_set_strict(int flag)
* Allow a relative node / processor specification within the allowed
* set if "relative" is nonzero
*/
-static unsigned long get_nr(char *s, char **end, struct bitmask *bmp, int relative)
+static unsigned long get_nr(const char *s, char **end, struct bitmask *bmp, int relative)
{
long i, nr;
@@ -1747,7 +1747,7 @@ static unsigned long get_nr(char *s, char **end, struct bitmask *bmp, int relati
* The caller must free the returned bitmask.
*/
static struct bitmask *
-__numa_parse_nodestring(char *s, struct bitmask *allowed_nodes_ptr)
+__numa_parse_nodestring(const char *s, struct bitmask *allowed_nodes_ptr)
{
int invert = 0, relative = 0;
int conf_nodes = numa_num_configured_nodes();
@@ -1843,7 +1843,7 @@ err:
* for this task.
*/
-struct bitmask * numa_parse_nodestring(char *s)
+struct bitmask * numa_parse_nodestring(const char *s)
{
return __numa_parse_nodestring(s, numa_all_nodes_ptr);
}
@@ -1853,7 +1853,7 @@ struct bitmask * numa_parse_nodestring(char *s)
* available.
*/
-struct bitmask * numa_parse_nodestring_all(char *s)
+struct bitmask * numa_parse_nodestring_all(const char *s)
{
return __numa_parse_nodestring(s, numa_possible_nodes_ptr);
}
@@ -1871,7 +1871,7 @@ struct bitmask * numa_parse_nodestring_all(char *s)
* The caller must free the returned bitmask.
*/
static struct bitmask *
-__numa_parse_cpustring(char *s, struct bitmask *allowed_cpus_ptr)
+__numa_parse_cpustring(const char *s, struct bitmask *allowed_cpus_ptr)
{
int invert = 0, relative=0;
int conf_cpus = numa_num_configured_cpus();
@@ -1956,7 +1956,7 @@ err:
* for this task.
*/
-struct bitmask * numa_parse_cpustring(char *s)
+struct bitmask * numa_parse_cpustring(const char *s)
{
return __numa_parse_cpustring(s, numa_all_cpus_ptr);
}
@@ -1966,7 +1966,7 @@ struct bitmask * numa_parse_cpustring(char *s)
* available.
*/
-struct bitmask * numa_parse_cpustring_all(char *s)
+struct bitmask * numa_parse_cpustring_all(const char *s)
{
return __numa_parse_cpustring(s, numa_possible_cpus_ptr);
}
diff --git a/numa.3 b/numa.3
index b302b8f..e0da131 100755
--- a/numa.3
+++ b/numa.3
@@ -50,13 +50,13 @@ numa \- NUMA policy library
.sp
.BI "int numa_parse_bitmap(char *" line " , struct bitmask *" mask ");
.br
-.BI "struct bitmask *numa_parse_nodestring(char *" string );
+.BI "struct bitmask *numa_parse_nodestring(const char *" string );
.br
-.BI "struct bitmask *numa_parse_nodestring_all(char *" string );
+.BI "struct bitmask *numa_parse_nodestring_all(const char *" string );
.br
-.BI "struct bitmask *numa_parse_cpustring(char *" string );
+.BI "struct bitmask *numa_parse_cpustring(const char *" string );
.br
-.BI "struct bitmask *numa_parse_cpustring_all(char *" string );
+.BI "struct bitmask *numa_parse_cpustring_all(const char *" string );
.sp
.BI "long numa_node_size(int " node ", long *" freep );
.br
diff --git a/numa.h b/numa.h
index ea28774..86d3b2e 100755
--- a/numa.h
+++ b/numa.h
@@ -310,18 +310,18 @@ int numa_sched_getaffinity(pid_t, struct bitmask *);
int numa_sched_setaffinity(pid_t, struct bitmask *);
/* Convert an ascii list of nodes to a bitmask */
-struct bitmask *numa_parse_nodestring(char *);
+struct bitmask *numa_parse_nodestring(const char *);
/* Convert an ascii list of nodes to a bitmask without current nodeset
* dependency */
-struct bitmask *numa_parse_nodestring_all(char *);
+struct bitmask *numa_parse_nodestring_all(const char *);
/* Convert an ascii list of cpu to a bitmask */
-struct bitmask *numa_parse_cpustring(char *);
+struct bitmask *numa_parse_cpustring(const char *);
/* Convert an ascii list of cpu to a bitmask without current taskset
* dependency */
-struct bitmask *numa_parse_cpustring_all(char *);
+struct bitmask *numa_parse_cpustring_all(const char *);
/*
* The following functions are for source code compatibility
--
1.7.11.4
next prev parent reply other threads:[~2012-08-23 16:01 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-08-23 16:01 [PATCH v2 0/7] couple of numactl-2.0.8-rc4 bugfixes and new interface Petr Holasek
2012-08-23 16:01 ` [PATCH v2 1/7] libnuma: Fix calculation of maxconfiguredcpu Petr Holasek
2012-08-23 16:01 ` [PATCH v2 2/7] libnuma: do not recalculate maxconfiguredcpu Petr Holasek
2012-08-23 16:01 ` [PATCH v2 3/7] libnuma: numa_num_possible_cpus symbol is exported from the library Petr Holasek
2012-08-23 16:01 ` [RFC PATCH v2 4/7] libnuma: introduced _all versions of numa_parse_{cpu,node}string() Petr Holasek
2012-08-23 16:01 ` Petr Holasek [this message]
2012-08-23 16:01 ` [PATCH v2 6/7] libnuma: removed unused bufferlen variable Petr Holasek
2012-08-23 16:01 ` [PATCH v2 7/7] libnuma: no warnings when there are holes in numbering of nodes Petr Holasek
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=1345737719-11433-6-git-send-email-pholasek@redhat.com \
--to=pholasek@redhat.com \
--cc=andi@firstfloor.org \
--cc=anton@redhat.com \
--cc=cpw@sgi.com \
--cc=linux-numa@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).