summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCarlos Martín Nieto <cmn@dwim.me>2014-10-27 10:06:58 +0100
committerCarlos Martín Nieto <cmn@dwim.me>2014-10-27 10:06:58 +0100
commitccb1b990b0d105a7a9d7cb4d870d8033c47a69f2 (patch)
treebd5bcbe3c456fccd56d0165873d2dadfddbc69b2
parent94f74ad28f191e7dc17ae874c00e3ecd6a80fcf4 (diff)
parent62e562f92b45b6a9b124452f7de6b9e86a179224 (diff)
downloadlibgit2-development.tar.gz
Merge pull request #2366 from kitbellew/fix-indexer-mmap-castdevelopment
Fix compiler warning (git_off_t cast to size_t).
-rw-r--r--src/indexer.c12
-rw-r--r--src/map.h1
-rw-r--r--src/pool.c16
-rw-r--r--src/pool.h2
-rw-r--r--src/posix.c5
-rw-r--r--src/posix.h2
-rw-r--r--src/unix/map.c10
-rw-r--r--src/win32/map.c5
8 files changed, 29 insertions, 24 deletions
diff --git a/src/indexer.c b/src/indexer.c
index 25c3d0537..93fe9463a 100644
--- a/src/indexer.c
+++ b/src/indexer.c
@@ -427,15 +427,19 @@ static void hash_partially(git_indexer *idx, const uint8_t *data, size_t size)
static int write_at(git_indexer *idx, const void *data, git_off_t offset, size_t size)
{
git_file fd = idx->pack->mwf.fd;
- long page_size = git__page_size();
- git_off_t page_start, page_offset;
+ size_t page_size;
+ size_t page_offset;
+ git_off_t page_start;
unsigned char *map_data;
git_map map;
int error;
+ if ((error = git__page_size(&page_size)) < 0)
+ return error;
+
/* the offset needs to be at the beginning of the a page boundary */
- page_start = (offset / page_size) * page_size;
- page_offset = offset - page_start;
+ page_offset = offset % page_size;
+ page_start = offset - page_offset;
if ((error = p_mmap(&map, page_offset + size, GIT_PROT_WRITE, GIT_MAP_SHARED, fd, page_start)) < 0)
return error;
diff --git a/src/map.h b/src/map.h
index 722eb7a30..da3d1e19a 100644
--- a/src/map.h
+++ b/src/map.h
@@ -42,6 +42,5 @@ typedef struct { /* memory mapped buffer */
extern int p_mmap(git_map *out, size_t len, int prot, int flags, int fd, git_off_t offset);
extern int p_munmap(git_map *map);
-extern long git__page_size(void);
#endif /* INCLUDE_map_h__ */
diff --git a/src/pool.c b/src/pool.c
index 146f118b4..1042f7645 100644
--- a/src/pool.c
+++ b/src/pool.c
@@ -1,4 +1,5 @@
#include "pool.h"
+#include "posix.h"
#ifndef GIT_WIN32
#include <unistd.h>
#endif
@@ -305,17 +306,10 @@ uint32_t git_pool__system_page_size(void)
static uint32_t size = 0;
if (!size) {
-#ifdef GIT_WIN32
- SYSTEM_INFO info;
- GetSystemInfo(&info);
- size = (uint32_t)info.dwPageSize;
-#elif defined(__amigaos4__)
- size = (uint32_t)4096; /* 4K as there is no global value we can query */
-#else
- size = (uint32_t)sysconf(_SC_PAGE_SIZE);
-#endif
-
- size -= 2 * sizeof(void *); /* allow space for malloc overhead */
+ size_t page_size;
+ if (git__page_size(&page_size) < 0)
+ page_size = 4096;
+ size = page_size - 2 * sizeof(void *); /* allow space for malloc overhead */
}
return size;
diff --git a/src/pool.h b/src/pool.h
index 5ac9b764f..b0007f315 100644
--- a/src/pool.h
+++ b/src/pool.h
@@ -143,8 +143,6 @@ extern uint32_t git_pool__full_pages(git_pool *pool);
extern bool git_pool__ptr_in_pool(git_pool *pool, void *ptr);
-extern uint32_t git_pool__system_page_size(void);
-
extern uint32_t git_pool__suggest_items_per_page(uint32_t item_size);
#endif
diff --git a/src/posix.c b/src/posix.c
index 7aeb0e6c1..7db633628 100644
--- a/src/posix.c
+++ b/src/posix.c
@@ -207,10 +207,11 @@ int p_write(git_file fd, const void *buf, size_t cnt)
#include "map.h"
-long git__page_size(void)
+int git__page_size(size_t *page_size)
{
/* dummy; here we don't need any alignment anyway */
- return 4096;
+ *page_size = 4096;
+ return 0;
}
diff --git a/src/posix.h b/src/posix.h
index 965cd98d5..0ef35ac31 100644
--- a/src/posix.h
+++ b/src/posix.h
@@ -66,6 +66,8 @@ extern int p_creat(const char *path, mode_t mode);
extern int p_getcwd(char *buffer_out, size_t size);
extern int p_rename(const char *from, const char *to);
+extern int git__page_size(size_t *page_size);
+
#ifndef GIT_WIN32
#define p_stat(p,b) stat(p, b)
diff --git a/src/unix/map.c b/src/unix/map.c
index 3d0cbbaf8..0a235d5a1 100644
--- a/src/unix/map.c
+++ b/src/unix/map.c
@@ -13,9 +13,15 @@
#include <unistd.h>
#include <errno.h>
-long git__page_size(void)
+int git__page_size(size_t *page_size)
{
- return sysconf(_SC_PAGE_SIZE);
+ long sc_page_size = sysconf(_SC_PAGE_SIZE);
+ if (sc_page_size < 0) {
+ giterr_set_str(GITERR_OS, "Can't determine system page size");
+ return -1;
+ }
+ *page_size = (size_t) sc_page_size;
+ return 0;
}
int p_mmap(git_map *out, size_t len, int prot, int flags, int fd, git_off_t offset)
diff --git a/src/win32/map.c b/src/win32/map.c
index ef83f882e..a99c30f7e 100644
--- a/src/win32/map.c
+++ b/src/win32/map.c
@@ -23,9 +23,10 @@ static DWORD get_page_size(void)
return page_size;
}
-long git__page_size(void)
+int git__page_size(size_t *page_size)
{
- return (long)get_page_size();
+ *page_size = get_page_size();
+ return 0;
}
int p_mmap(git_map *out, size_t len, int prot, int flags, int fd, git_off_t offset)