Skip to content

Commit

Permalink
libnuma: numa_parse_cpustring and similar should take a const char* p…
Browse files Browse the repository at this point in the history
…arameter

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>
  • Loading branch information
Petr Holasek authored and filbranden committed Jul 23, 2014
1 parent 69484c9 commit 2255817
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 24 deletions.
17 changes: 9 additions & 8 deletions affinity.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "";
Expand All @@ -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))
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -279,7 +280,7 @@ static int affinity_ip(struct bitmask *mask, char *cls, char *id)
}

/* 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;
Expand Down Expand Up @@ -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 },
Expand All @@ -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;

Expand Down
2 changes: 1 addition & 1 deletion affinity.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

14 changes: 7 additions & 7 deletions libnuma.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -1843,7 +1843,7 @@ __numa_parse_nodestring(char *s, struct bitmask *allowed_nodes_ptr)
* 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);
}
Expand All @@ -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);
}
Expand All @@ -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();
Expand Down Expand Up @@ -1956,7 +1956,7 @@ __numa_parse_cpustring(char *s, struct bitmask *allowed_cpus_ptr)
* 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);
}
Expand All @@ -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);
}
8 changes: 4 additions & 4 deletions numa.3
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions numa.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 2255817

Please sign in to comment.