[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [45725] trunk/blender/source/blender/ blenloader: code cleanup: use const args for writing files.
Campbell Barton
ideasman42 at gmail.com
Tue Apr 17 21:51:40 CEST 2012
Revision: 45725
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=45725
Author: campbellbarton
Date: 2012-04-17 19:51:40 +0000 (Tue, 17 Apr 2012)
Log Message:
-----------
code cleanup: use const args for writing files.
Modified Paths:
--------------
trunk/blender/source/blender/blenloader/BLO_undofile.h
trunk/blender/source/blender/blenloader/BLO_writefile.h
trunk/blender/source/blender/blenloader/intern/undofile.c
trunk/blender/source/blender/blenloader/intern/writefile.c
Modified: trunk/blender/source/blender/blenloader/BLO_undofile.h
===================================================================
--- trunk/blender/source/blender/blenloader/BLO_undofile.h 2012-04-17 19:10:57 UTC (rev 45724)
+++ trunk/blender/source/blender/blenloader/BLO_undofile.h 2012-04-17 19:51:40 UTC (rev 45725)
@@ -47,7 +47,7 @@
} MemFile;
/* actually only used writefile.c */
-extern void add_memfilechunk(MemFile *compare, MemFile *current, char *buf, unsigned int size);
+extern void add_memfilechunk(MemFile *compare, MemFile *current, const char *buf, unsigned int size);
/* exports */
extern void BLO_free_memfile(MemFile *memfile);
Modified: trunk/blender/source/blender/blenloader/BLO_writefile.h
===================================================================
--- trunk/blender/source/blender/blenloader/BLO_writefile.h 2012-04-17 19:10:57 UTC (rev 45724)
+++ trunk/blender/source/blender/blenloader/BLO_writefile.h 2012-04-17 19:51:40 UTC (rev 45725)
@@ -37,7 +37,7 @@
struct Main;
struct ReportList;
-extern int BLO_write_file(struct Main *mainvar, const char *filepath, int write_flags, struct ReportList *reports, int *thumb);
+extern int BLO_write_file(struct Main *mainvar, const char *filepath, int write_flags, struct ReportList *reports, const int *thumb);
extern int BLO_write_file_mem(struct Main *mainvar, struct MemFile *compare, struct MemFile *current, int write_flags);
#define BLEN_THUMB_SIZE 128
Modified: trunk/blender/source/blender/blenloader/intern/undofile.c
===================================================================
--- trunk/blender/source/blender/blenloader/intern/undofile.c 2012-04-17 19:10:57 UTC (rev 45724)
+++ trunk/blender/source/blender/blenloader/intern/undofile.c 2012-04-17 19:51:40 UTC (rev 45725)
@@ -85,9 +85,11 @@
BLO_free_memfile(first);
}
-static int my_memcmp(int *mem1, int *mem2, int len)
+static int my_memcmp(const int *mem1, const int *mem2, const int len)
{
- register int a= len, *mema= mem1, *memb= mem2;
+ register int a = len;
+ register const int *mema = mem1;
+ register const int *memb = mem2;
while (a--) {
if ( *mema != *memb) return 1;
@@ -97,7 +99,7 @@
return 0;
}
-void add_memfilechunk(MemFile *compare, MemFile *current, char *buf, unsigned int size)
+void add_memfilechunk(MemFile *compare, MemFile *current, const char *buf, unsigned int size)
{
static MemFileChunk *compchunk=NULL;
MemFileChunk *curchunk;
@@ -121,7 +123,7 @@
/* we compare compchunk with buf */
if (compchunk) {
if (compchunk->size == curchunk->size) {
- if ( my_memcmp((int *)compchunk->buf, (int *)buf, size/4)==0) {
+ if (my_memcmp((int *)compchunk->buf, (const int *)buf, size / 4) == 0) {
curchunk->buf= compchunk->buf;
curchunk->ident= 1;
}
Modified: trunk/blender/source/blender/blenloader/intern/writefile.c
===================================================================
--- trunk/blender/source/blender/blenloader/intern/writefile.c 2012-04-17 19:10:57 UTC (rev 45724)
+++ trunk/blender/source/blender/blenloader/intern/writefile.c 2012-04-17 19:51:40 UTC (rev 45725)
@@ -204,7 +204,7 @@
return wd;
}
-static void writedata_do_write(WriteData *wd, void *mem, int memlen)
+static void writedata_do_write(WriteData *wd, const void *mem, int memlen)
{
if ((wd == NULL) || wd->error || (mem == NULL) || memlen < 1) return;
if (wd->error) return;
@@ -239,7 +239,7 @@
#define MYWRITE_FLUSH NULL
-static void mywrite( WriteData *wd, void *adr, int len)
+static void mywrite( WriteData *wd, const void *adr, int len)
{
if (wd->error) return;
@@ -265,7 +265,7 @@
do {
int writelen= MIN2(len, MYWRITE_MAX_CHUNK);
writedata_do_write(wd, adr, writelen);
- adr = (char*)adr + writelen;
+ adr = (const char *)adr + writelen;
len -= writelen;
} while (len > 0);
@@ -354,22 +354,22 @@
mywrite(wd, adr, bh.len);
}
-static void writedata(WriteData *wd, int filecode, int len, void *adr) /* do not use for structs */
+static void writedata(WriteData *wd, int filecode, int len, const void *adr) /* do not use for structs */
{
BHead bh;
if (adr==NULL) return;
if (len==0) return;
- len+= 3;
- len-= ( len % 4);
+ len += 3;
+ len -= (len % 4);
/* init BHead */
- bh.code= filecode;
- bh.old= adr;
- bh.nr= 1;
- bh.SDNAnr= 0;
- bh.len= len;
+ bh.code = filecode;
+ bh.old = (void *)adr; /* this is safe to cast from const */
+ bh.nr = 1;
+ bh.SDNAnr = 0;
+ bh.len = len;
mywrite(wd, &bh, sizeof(BHead));
if (len) mywrite(wd, adr, len);
@@ -2764,7 +2764,7 @@
* second are an RGBA image (unsigned char)
* note, this uses 'TEST' since new types will segfault on file load for older blender versions.
*/
-static void write_thumb(WriteData *wd, int *img)
+static void write_thumb(WriteData *wd, const int *img)
{
if (img)
writedata(wd, TEST, (2 + img[0] * img[1]) * sizeof(int), img);
@@ -2772,7 +2772,7 @@
/* if MemFile * there's filesave to memory */
static int write_file_handle(Main *mainvar, int handle, MemFile *compare, MemFile *current,
- int write_user_block, int write_flags, int *thumb)
+ int write_user_block, int write_flags, const int *thumb)
{
BHead bhead;
ListBase mainlist;
@@ -2880,7 +2880,7 @@
}
/* return: success (1) */
-int BLO_write_file(Main *mainvar, const char *filepath, int write_flags, ReportList *reports, int *thumb)
+int BLO_write_file(Main *mainvar, const char *filepath, int write_flags, ReportList *reports, const int *thumb)
{
char userfilename[FILE_MAX];
char tempname[FILE_MAX+1];
More information about the Bf-blender-cvs
mailing list