Procházet zdrojové kódy

Always mark input values const, and specify void in functions taking no argument.

Emmanuel Gil Peyrot před 9 roky
rodič
revize
df5edd6cfa
5 změnil soubory, kde provedl 14 přidání a 14 odebrání
  1. 4 4
      include/openhmd.h
  2. 1 1
      src/drv_external/external.c
  3. 1 1
      src/log.h
  4. 5 5
      src/openhmd.c
  5. 3 3
      src/openhmdi.h

+ 4 - 4
include/openhmd.h

@@ -151,7 +151,7 @@ typedef struct ohmd_device ohmd_device;
  *
  * @return a pointer to an allocated ohmd_context on success or NULL if it fails.
  **/
-OHMD_APIENTRYDLL ohmd_context* OHMD_APIENTRY ohmd_ctx_create();
+OHMD_APIENTRYDLL ohmd_context* OHMD_APIENTRY ohmd_ctx_create(void);
 
 /**
  * Destroy an OpenHMD context.
@@ -260,7 +260,7 @@ OHMD_APIENTRYDLL int OHMD_APIENTRY ohmd_device_getf(ohmd_device* device, ohmd_fl
  * @param in A pointer to a float, or float array where the new value is stored.
  * @return 0 on success, <0 on failure.
  **/
-OHMD_APIENTRYDLL int OHMD_APIENTRY ohmd_device_setf(ohmd_device* device, ohmd_float_value type, float* in);
+OHMD_APIENTRYDLL int OHMD_APIENTRY ohmd_device_setf(ohmd_device* device, ohmd_float_value type, const float* in);
 
 /**
  * Get an integer value from a device.
@@ -280,7 +280,7 @@ OHMD_APIENTRYDLL int OHMD_APIENTRY ohmd_device_geti(ohmd_device* device, ohmd_in
  * @param in A pointer to a int, or int array where the new value is stored.
  * @return 0 on success, <0 on failure.
  **/
-OHMD_APIENTRYDLL int OHMD_APIENTRY ohmd_device_seti(ohmd_device* device, ohmd_int_value type, int* in);
+OHMD_APIENTRYDLL int OHMD_APIENTRY ohmd_device_seti(ohmd_device* device, ohmd_int_value type, const int* in);
 
 /**
  * Set an void* data value for a device.
@@ -290,7 +290,7 @@ OHMD_APIENTRYDLL int OHMD_APIENTRY ohmd_device_seti(ohmd_device* device, ohmd_in
  * @param in A pointer to the void* casted object.
  * @return 0 on success, <0 on failure.
  **/
-OHMD_APIENTRYDLL int OHMD_APIENTRY ohmd_device_set_data(ohmd_device* device, ohmd_data_value type, void* in);
+OHMD_APIENTRYDLL int OHMD_APIENTRY ohmd_device_set_data(ohmd_device* device, ohmd_data_value type, const void* in);
 
 #ifdef __cplusplus
 }

+ 1 - 1
src/drv_external/external.c

@@ -43,7 +43,7 @@ static int getf(ohmd_device* device, ohmd_float_value type, float* out)
 	return 0;
 }
 
-static int setf(ohmd_device* device, ohmd_float_value type, float* in)
+static int setf(ohmd_device* device, ohmd_float_value type, const float* in)
 {
 	external_priv* priv = (external_priv*)device;
 

+ 1 - 1
src/log.h

@@ -10,7 +10,7 @@
 #ifndef LOG_H
 #define LOG_H
 
-void* ohmd_allocfn(ohmd_context* ctx, char* e_msg, size_t size);
+void* ohmd_allocfn(ohmd_context* ctx, const char* e_msg, size_t size);
 #define ohmd_alloc(_ctx, _size) ohmd_allocfn(_ctx, "could not allocate " #_size " bytes of RAM @ " __FILE__ ":" OHMD_STRINGIFY(__LINE__), _size)
 
 #ifndef LOGLEVEL

+ 5 - 5
src/openhmd.c

@@ -12,7 +12,7 @@
 #include <string.h>
 #include <stdio.h>
 
-ohmd_context* OHMD_APIENTRY ohmd_ctx_create()
+ohmd_context* OHMD_APIENTRY ohmd_ctx_create(void)
 {
 	ohmd_context* ctx = calloc(1, sizeof(ohmd_context));
 	if(!ctx){
@@ -230,7 +230,7 @@ int OHMD_APIENTRY ohmd_device_getf(ohmd_device* device, ohmd_float_value type, f
 	}
 }
 
-int OHMD_APIENTRY ohmd_device_setf(ohmd_device* device, ohmd_float_value type, float* in)
+int OHMD_APIENTRY ohmd_device_setf(ohmd_device* device, ohmd_float_value type, const float* in)
 {
 	switch(type){
 	case OHMD_EYE_IPD:
@@ -296,7 +296,7 @@ int OHMD_APIENTRY ohmd_device_geti(ohmd_device* device, ohmd_int_value type, int
 	}
 }
 
-int OHMD_APIENTRY ohmd_device_seti(ohmd_device* device, ohmd_int_value type, int* in)
+int OHMD_APIENTRY ohmd_device_seti(ohmd_device* device, ohmd_int_value type, const int* in)
 {
 	switch(type){
 	default:
@@ -304,7 +304,7 @@ int OHMD_APIENTRY ohmd_device_seti(ohmd_device* device, ohmd_int_value type, int
 	}
 }
 
-int OHMD_APIENTRY ohmd_device_set_data(ohmd_device* device, ohmd_data_value type, void* in)
+int OHMD_APIENTRY ohmd_device_set_data(ohmd_device* device, ohmd_data_value type, const void* in)
 {
     switch(type){
     case OHMD_DRIVER_DATA:{
@@ -321,7 +321,7 @@ int OHMD_APIENTRY ohmd_device_set_data(ohmd_device* device, ohmd_data_value type
     }
 }
 
-void* ohmd_allocfn(ohmd_context* ctx, char* e_msg, size_t size)
+void* ohmd_allocfn(ohmd_context* ctx, const char* e_msg, size_t size)
 {
 	void* ret = calloc(1, size);
 	if(!ret)

+ 3 - 3
src/openhmdi.h

@@ -78,9 +78,9 @@ struct ohmd_device {
 	vec3f position_correction;
 
 	int (*getf)(ohmd_device* device, ohmd_float_value type, float* out);
-	int (*setf)(ohmd_device* device, ohmd_float_value type, float* in);
-	int (*seti)(ohmd_device* device, ohmd_int_value type, int* in);
-	int (*set_data)(ohmd_device* device, ohmd_data_value type, void* in);
+	int (*setf)(ohmd_device* device, ohmd_float_value type, const float* in);
+	int (*seti)(ohmd_device* device, ohmd_int_value type, const int* in);
+	int (*set_data)(ohmd_device* device, ohmd_data_value type, const void* in);
 
 	void (*update)(ohmd_device* device);
 	void (*close)(ohmd_device* device);