Subject: | Compiler warns about unused variables |
Compilation of development tree spits out some warnings:
gcc -c -D_REENTRANT -D_GNU_SOURCE -fno-strict-aliasing -pipe
-fstack-protector -I/usr/local/include -D_LARGEFILE_SOURCE
-D_FILE_OFFSET_BITS=64 -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2
-fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64
-mtune=generic -DVERSION=\"0.53\" -DXS_VERSION=\"0.53\" -fPIC
"-I/usr/lib64/perl5/CORE" CPU.c
CPU.xs:272:17: warning: extra tokens at end of #ifdef directive [enabled
by default]
CPU.xs: In function 'get_cpu_count':
CPU.xs:292:11: warning: unused variable 'p' [-Wunused-variable]
CPU.c: In function 'XS_Sys__CPU_cpu_count':
CPU.c:469:2: warning: unused variable 'targ' [-Wunused-variable]
CPU.c:468:6: warning: unused variable 'RETVAL' [-Wunused-variable]
CPU.xs: In function 'XS_Sys__CPU_cpu_clock':
CPU.xs:330:9: warning: unused variable 'retcode' [-Wunused-variable]
CPU.c:495:2: warning: unused variable 'targ' [-Wunused-variable]
CPU.c:494:6: warning: unused variable 'RETVAL' [-Wunused-variable]
CPU.xs: In function 'XS_Sys__CPU_cpu_type':
CPU.xs:375:17: warning: extra tokens at end of #ifdef directive [enabled
by default]
CPU.xs:373:9: warning: unused variable 'retcode' [-Wunused-variable]
CPU.c:549:7: warning: unused variable 'RETVAL' [-Wunused-variable]
CPU.c: In function 'proc_cpuinfo_field':
CPU.xs:245:12: warning: ignoring return value of 'fgets', declared with
attribute warn_unused_result [-Wunused-result]
Attached patch reduces the number of warnings. Other ones are introduced
by XS translator or probably suboptimally used XS API.
Subject: | 0002-Silent-compiler-warnings.patch |
From 6917f265b79a2f59e92c3b2d5116d065b39a2e72 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Petr=20P=C3=ADsa=C5=99?= <ppisar@redhat.com>
Date: Thu, 8 Nov 2012 09:11:37 +0100
Subject: [PATCH 2/2] Silent compiler warnings
---
CPU.xs | 12 +++---------
1 file changed, 3 insertions(+), 9 deletions(-)
diff --git a/CPU.xs b/CPU.xs
index 9563830..5a571c6 100644
--- a/CPU.xs
+++ b/CPU.xs
@@ -242,7 +242,7 @@ char *proc_cpuinfo_field (const char *field) {
char *result = NULL;
if (NULL!=(fp = fopen ("/proc/cpuinfo", "r"))) {
while (!feof(fp) && result==NULL) {
- fgets (line, 990, fp);
+ if (NULL == fgets (line, 990, fp) && !feof(fp)) break;
if (0==strncasecmp (field, line, len)) {
char *loc = strchr (line, ':');
if (loc) {
@@ -288,8 +288,6 @@ char *processor_machine_field (char *processor) {
int get_cpu_count() {
int ret;
- char buffer[255];
- char *p = buffer;
#ifdef WINDOWS /* WINDOWS */
SYSTEM_INFO info;
@@ -327,7 +325,6 @@ cpu_clock()
CODE:
{
int clock = 0;
- int retcode = 0;
#ifdef __linux__
int value = proc_cpuinfo_clock();
if (value) clock = value;
@@ -335,8 +332,7 @@ CODE:
#ifdef WINDOWS
char *clock_str = malloc(MAX_IDENT_SIZE);
/*!! untested !!*/
- retcode = GetSysInfoKey("~MHz",clock_str);
- if (retcode != 0) {
+ if (GetSysInfoKey("~MHz",clock_str)) {
clock = 0;
} else {
clock = atoi(clock_str);
@@ -370,7 +366,6 @@ cpu_type()
CODE:
{
char *value = NULL;
- int retcode = 0;
#ifdef __linux__
#if defined __s390__ || defined __s390x__
value = processor_machine_field (proc_cpuinfo_field ("processor") );
@@ -380,8 +375,7 @@ CODE:
if (!value) value = proc_cpuinfo_field ("vendor_id");
#endif
#ifdef WINDOWS
- retcode = GetSysInfoKey("Identifier",value);
- if (retcode != 0) {
+ if (GetSysInfoKey("Identifier",value)) {
value = NULL;
}
#endif
--
1.7.11.7