[Cbe-oss-dev] [PATCH] libspe2: initialize handler array functions via index values

Patrick Mansfield patmans at us.ibm.com
Wed May 16 03:37:14 EST 2007


Initialize the handler array functions via index values.

Note that prior to this change, the last element was uninitialized and
never used it, now the first element is intialized to NULL and never used.

Signed-off-by: Patrick Mansfield <patmans at us.ibm.com>

Index: libspe2/spebase/default_posix1_handler.c
===================================================================
--- libspe2.orig/spebase/default_posix1_handler.c
+++ libspe2/spebase/default_posix1_handler.c
@@ -86,7 +86,8 @@
 #define SPE_POSIX1_DATA(_v) ((_v) & SPE_POSIX1_DATA_MASK)
 
 enum {
-	SPE_POSIX1_ADJTIMEX=0x1,
+	SPE_POSIX1_UNUSED,
+	SPE_POSIX1_ADJTIMEX,
 	SPE_POSIX1_CLOSE,
 	SPE_POSIX1_CREAT,
 	SPE_POSIX1_FSTAT,
@@ -1176,37 +1177,38 @@ int default_posix1_handler_gettimeofday(
 }
 
 int (*default_posix1_funcs[SPE_POSIX1_NR_OPCODES]) (char *, unsigned long) = {
-	default_posix1_handler_adjtimex,
-	default_posix1_handler_close,
-	default_posix1_handler_creat,
-	default_posix1_handler_fstat,
-	default_posix1_handler_ftok,
-	default_posix1_handler_getpagesize,
-	default_posix1_handler_gettimeofday,
-	default_posix1_handler_kill,
-	default_posix1_handler_lseek,
-	default_posix1_handler_lstat,
-	default_posix1_handler_mmap,
-	default_posix1_handler_mremap,
-	default_posix1_handler_msync,
-	default_posix1_handler_munmap,
-	default_posix1_handler_open,
-	default_posix1_handler_read,
-	default_posix1_handler_shmat,
-	default_posix1_handler_shmctl,
-	default_posix1_handler_shmdt,
-	default_posix1_handler_shmget,
-	default_posix1_handler_shm_open,
-	default_posix1_handler_shm_unlink,
-	default_posix1_handler_stat,
-	default_posix1_handler_unlink,
-	default_posix1_handler_wait,
-	default_posix1_handler_waitpid,
-	default_posix1_handler_write,
-	default_posix1_handler_ftruncate,
-	default_posix1_handler_access,
-	default_posix1_handler_dup,
-	default_posix1_handler_time,
+	[SPE_POSIX1_UNUSED]		= NULL,
+	[SPE_POSIX1_ADJTIMEX]		= default_posix1_handler_adjtimex,
+	[SPE_POSIX1_CLOSE]		= default_posix1_handler_close,
+	[SPE_POSIX1_CREAT]		= default_posix1_handler_creat,
+	[SPE_POSIX1_FSTAT]		= default_posix1_handler_fstat,
+	[SPE_POSIX1_FTOK]		= default_posix1_handler_ftok,
+	[SPE_POSIX1_GETPAGESIZE]	= default_posix1_handler_getpagesize,
+	[SPE_POSIX1_GETTIMEOFDAY]	= default_posix1_handler_gettimeofday,
+	[SPE_POSIX1_KILL]		= default_posix1_handler_kill,
+	[SPE_POSIX1_LSEEK]		= default_posix1_handler_lseek,
+	[SPE_POSIX1_LSTAT]		= default_posix1_handler_lstat,
+	[SPE_POSIX1_MMAP]		= default_posix1_handler_mmap,
+	[SPE_POSIX1_MREMAP]		= default_posix1_handler_mremap,
+	[SPE_POSIX1_MSYNC]		= default_posix1_handler_msync,
+	[SPE_POSIX1_MUNMAP]		= default_posix1_handler_munmap,
+	[SPE_POSIX1_OPEN]		= default_posix1_handler_open,
+	[SPE_POSIX1_READ]		= default_posix1_handler_read,
+	[SPE_POSIX1_SHMAT]		= default_posix1_handler_shmat,
+	[SPE_POSIX1_SHMCTL]		= default_posix1_handler_shmctl,
+	[SPE_POSIX1_SHMDT]		= default_posix1_handler_shmdt,
+	[SPE_POSIX1_SHMGET]		= default_posix1_handler_shmget,
+	[SPE_POSIX1_SHM_OPEN]		= default_posix1_handler_shm_open,
+	[SPE_POSIX1_SHM_UNLINK]		= default_posix1_handler_shm_unlink,
+	[SPE_POSIX1_STAT]		= default_posix1_handler_stat,
+	[SPE_POSIX1_UNLINK]		= default_posix1_handler_unlink,
+	[SPE_POSIX1_WAIT]		= default_posix1_handler_wait,
+	[SPE_POSIX1_WAITPID]		= default_posix1_handler_waitpid,
+	[SPE_POSIX1_WRITE]		= default_posix1_handler_write,
+	[SPE_POSIX1_FTRUNCATE]		= default_posix1_handler_ftruncate,
+	[SPE_POSIX1_ACCESS]		= default_posix1_handler_access,
+	[SPE_POSIX1_DUP]		= default_posix1_handler_dup,
+	[SPE_POSIX1_TIME]		= default_posix1_handler_time,
 };
 
 /**
@@ -1233,7 +1235,7 @@ int default_posix1_handler(char *base, u
         return 1;
     }
 
-    default_posix1_funcs[op-1] (base, opdata);
+    default_posix1_funcs[op] (base, opdata);
 
     return 0;
 }
Index: libspe2/spebase/default_c99_handler.c
===================================================================
--- libspe2.orig/spebase/default_c99_handler.c
+++ libspe2/spebase/default_c99_handler.c
@@ -81,7 +81,8 @@
 #define SPE_C99_DATA(_v) 	((_v) & SPE_C99_DATA_MASK)
 
 enum { 
-	SPE_C99_CLEARERR=0x01,
+	SPE_C99_UNUSED,
+	SPE_C99_CLEARERR,
 	SPE_C99_FCLOSE,
 	SPE_C99_FEOF,
 	SPE_C99_FERROR,
@@ -1912,47 +1913,48 @@ int default_c99_handler_system(char *ls,
 }
 
 int (*default_c99_funcs[SPE_C99_NR_OPCODES]) (char *, unsigned long) = {
-	default_c99_handler_clearerr,
-	default_c99_handler_fclose,
-	default_c99_handler_feof,
-	default_c99_handler_ferror,
-	default_c99_handler_fflush,
-	default_c99_handler_fgetc,
-	default_c99_handler_fgetpos,
-	default_c99_handler_fgets,
-	default_c99_handler_fileno,
-	default_c99_handler_fopen,
-	default_c99_handler_fputc,
-	default_c99_handler_fputs,
-	default_c99_handler_fread,
-	default_c99_handler_freopen,
-	default_c99_handler_fseek,
-	default_c99_handler_fsetpos,
-	default_c99_handler_ftell,
-	default_c99_handler_fwrite,
-	default_c99_handler_getc,
-	default_c99_handler_getchar,
-	default_c99_handler_gets,
-	default_c99_handler_perror,
-	default_c99_handler_putc,
-	default_c99_handler_putchar,
-	default_c99_handler_puts,
-	default_c99_handler_remove,
-	default_c99_handler_rename,
-	default_c99_handler_rewind,
-	default_c99_handler_setbuf,
-	default_c99_handler_setvbuf,
-	default_c99_handler_system,
-	default_c99_handler_tmpfile,
-	default_c99_handler_tmpnam,
-	default_c99_handler_ungetc,
-	default_c99_handler_vfprintf,
-	default_c99_handler_vfscanf,
-	default_c99_handler_vprintf,
-	default_c99_handler_vscanf,
-	default_c99_handler_vsnprintf,
-	default_c99_handler_vsprintf,
-	default_c99_handler_vsscanf,
+	[SPE_C99_UNUSED]	= NULL,
+	[SPE_C99_CLEARERR]	= default_c99_handler_clearerr,
+	[SPE_C99_FCLOSE]	= default_c99_handler_fclose,
+	[SPE_C99_FEOF]		= default_c99_handler_feof,
+	[SPE_C99_FERROR]	= default_c99_handler_ferror,
+	[SPE_C99_FFLUSH]	= default_c99_handler_fflush,
+	[SPE_C99_FGETC]		= default_c99_handler_fgetc,
+	[SPE_C99_FGETPOS]	= default_c99_handler_fgetpos,
+	[SPE_C99_FGETS]		= default_c99_handler_fgets,
+	[SPE_C99_FILENO]	= default_c99_handler_fileno,
+	[SPE_C99_FOPEN]		= default_c99_handler_fopen,
+	[SPE_C99_FPUTC]		= default_c99_handler_fputc,
+	[SPE_C99_FPUTS]		= default_c99_handler_fputs,
+	[SPE_C99_FREAD]		= default_c99_handler_fread,
+	[SPE_C99_FREOPEN]	= default_c99_handler_freopen,
+	[SPE_C99_FSEEK]		= default_c99_handler_fseek,
+	[SPE_C99_FSETPOS]	= default_c99_handler_fsetpos,
+	[SPE_C99_FTELL]		= default_c99_handler_ftell,
+	[SPE_C99_FWRITE]	= default_c99_handler_fwrite,
+	[SPE_C99_GETC]		= default_c99_handler_getc,
+	[SPE_C99_GETCHAR]	= default_c99_handler_getchar,
+	[SPE_C99_GETS]		= default_c99_handler_gets,
+	[SPE_C99_PERROR]	= default_c99_handler_perror,
+	[SPE_C99_PUTC]		= default_c99_handler_putc,
+	[SPE_C99_PUTCHAR]	= default_c99_handler_putchar,
+	[SPE_C99_PUTS]		= default_c99_handler_puts,
+	[SPE_C99_REMOVE]	= default_c99_handler_remove,
+	[SPE_C99_RENAME]	= default_c99_handler_rename,
+	[SPE_C99_REWIND]	= default_c99_handler_rewind,
+	[SPE_C99_SETBUF]	= default_c99_handler_setbuf,
+	[SPE_C99_SETVBUF]	= default_c99_handler_setvbuf,
+	[SPE_C99_SYSTEM]	= default_c99_handler_system,
+	[SPE_C99_TMPFILE]	= default_c99_handler_tmpfile,
+	[SPE_C99_TMPNAM]	= default_c99_handler_tmpnam,
+	[SPE_C99_UNGETC]	= default_c99_handler_ungetc,
+	[SPE_C99_VFPRINTF]	= default_c99_handler_vfprintf,
+	[SPE_C99_VFSCANF]	= default_c99_handler_vfscanf,
+	[SPE_C99_VPRINTF]	= default_c99_handler_vprintf,
+	[SPE_C99_VSCANF]	= default_c99_handler_vscanf,
+	[SPE_C99_VSNPRINTF]	= default_c99_handler_vsnprintf,
+	[SPE_C99_VSPRINTF]	= default_c99_handler_vsprintf,
+	[SPE_C99_VSSCANF]	= default_c99_handler_vsscanf,
 };
 
 /**
@@ -1979,7 +1981,7 @@ int default_c99_handler(unsigned long *b
         return 1;
     }
 
-    default_c99_funcs[op-1] ((char *) base, opdata);
+    default_c99_funcs[op] ((char *) base, opdata);
 
     return 0;
 }



More information about the cbe-oss-dev mailing list