Skip to content

Commit 03715ad

Browse files
authored
Merge pull request #98 from linqiaozhi/master
Fixing compile errors on Windows
2 parents d14f741 + 9390f6e commit 03715ad

File tree

7 files changed

+67
-11
lines changed

7 files changed

+67
-11
lines changed

fast_tsne.R

+1-1
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ fftRtsne <- function(X,
9696
fast_tsne_path = NULL, nthreads = 0, perplexity_list = NULL,
9797
get_costs = FALSE, df = 1.0) {
9898

99-
version_number <- '1.2.0'
99+
version_number <- '1.2.1'
100100

101101
if (is.null(fast_tsne_path)) {
102102
if (.Platform$OS.type == "unix") {

fast_tsne.m

+1-1
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@
121121
% IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
122122
% OF SUCH DAMAGE.
123123

124-
version_number = '1.2.0';
124+
version_number = '1.2.1';
125125

126126
% default parameters and flags
127127
p.perplexity = 30;

fast_tsne.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ def fast_tsne(
169169
is True.
170170
"""
171171

172-
version_number = "1.2.0"
172+
version_number = "1.2.1"
173173

174174
# X should be a numpy array of 64-bit doubles
175175
X = np.array(X).astype(float)

src/annoylib.h

+31-6
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ typedef unsigned __int64 uint64_t;
3939
#ifndef NOMINMAX
4040
#define NOMINMAX
4141
#endif
42-
#include "mman.h"
42+
#include "winlibs/mman.h"
4343
#include <windows.h>
4444
#else
4545
#include <sys/mman.h>
@@ -881,7 +881,12 @@ template<typename S, typename T, typename Distance, typename Random>
881881

882882
bool on_disk_build(const char* file, char** error=NULL) {
883883
_on_disk = true;
884-
_fd = open(file, O_RDWR | O_CREAT | O_TRUNC, (int) 0600);
884+
885+
#ifdef _WIN32
886+
_fd = _open(file, O_RDWR | O_CREAT | O_TRUNC, (int)0600);
887+
#else
888+
_fd = open(file, O_RDWR | O_CREAT | O_TRUNC, (int)0600);
889+
#endif
885890
if (_fd == -1) {
886891
showUpdate("Error: file descriptor is -1\n");
887892
if (error) *error = strerror(errno);
@@ -981,7 +986,11 @@ template<typename S, typename T, typename Distance, typename Random>
981986
return true;
982987
} else {
983988
// Delete file if it already exists (See issue #335)
984-
unlink(filename);
989+
#ifdef _WIN32
990+
_unlink(filename);
991+
#else
992+
unlink(filename);
993+
#endif
985994

986995
printf("path: %s\n", filename);
987996

@@ -1022,12 +1031,20 @@ template<typename S, typename T, typename Distance, typename Random>
10221031

10231032
void unload() {
10241033
if (_on_disk && _fd) {
1034+
#ifdef _WIN32
1035+
_close(_fd);
1036+
#else
10251037
close(_fd);
1038+
#endif
10261039
munmap(_nodes, _s * _nodes_size);
10271040
} else {
10281041
if (_fd) {
10291042
// we have mmapped data
1030-
close(_fd);
1043+
#ifdef _WIN32
1044+
_close(_fd);
1045+
#else
1046+
close(_fd);
1047+
#endif
10311048
munmap(_nodes, _n_nodes * _s);
10321049
} else if (_nodes) {
10331050
// We have heap allocated data
@@ -1039,14 +1056,22 @@ template<typename S, typename T, typename Distance, typename Random>
10391056
}
10401057

10411058
bool load(const char* filename, bool prefault=false, char** error=NULL) {
1042-
_fd = open(filename, O_RDONLY, (int)0400);
1059+
#ifdef _WIN32
1060+
_fd = _open(filename, O_RDONLY, (int)0400);
1061+
#else
1062+
_fd = open(filename, O_RDONLY, (int)0400);
1063+
#endif
10431064
if (_fd == -1) {
10441065
showUpdate("Error: file descriptor is -1\n");
10451066
if (error) *error = strerror(errno);
10461067
_fd = 0;
10471068
return false;
10481069
}
1049-
off_t size = lseek(_fd, 0, SEEK_END);
1070+
#ifdef _WIN32
1071+
off_t size = _lseek(_fd, 0, SEEK_END);
1072+
#else
1073+
off_t size = lseek(_fd, 0, SEEK_END);
1074+
#endif
10501075
if (size == -1) {
10511076
showUpdate("lseek returned -1\n");
10521077
if (error) *error = strerror(errno);

src/tsne.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -2038,7 +2038,7 @@ void TSNE::save_data(const char *result_path, double* data, double* costs, int n
20382038

20392039

20402040
int main(int argc, char *argv[]) {
2041-
const char version_number[] = "1.2.0";
2041+
const char version_number[] = "1.2.1";
20422042
printf("=============== t-SNE v%s ===============\n", version_number);
20432043

20442044
// Define some variables

src/winlibs/mman.c

+25
Original file line numberDiff line numberDiff line change
@@ -178,3 +178,28 @@ int munlock(const void *addr, size_t len)
178178

179179
return -1;
180180
}
181+
#if !defined(__MINGW32__)
182+
int ftruncate(int fd, unsigned int size) {
183+
if (fd < 0) {
184+
errno = EBADF;
185+
return -1;
186+
}
187+
188+
HANDLE h = (HANDLE)_get_osfhandle(fd);
189+
unsigned int cur = SetFilePointer(h, 0, NULL, FILE_CURRENT);
190+
if (cur == ~0 || SetFilePointer(h, size, NULL, FILE_BEGIN) == ~0 || !SetEndOfFile(h)) {
191+
int error = GetLastError();
192+
switch (GetLastError()) {
193+
case ERROR_INVALID_HANDLE:
194+
errno = EBADF;
195+
break;
196+
default:
197+
errno = EIO;
198+
break;
199+
}
200+
return -1;
201+
}
202+
203+
return 0;
204+
}
205+
#endif

src/winlibs/mman.h

+7-1
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,15 @@ MMANSHARED_EXPORT int _mprotect(void *addr, size_t len, int prot);
6868
MMANSHARED_EXPORT int msync(void *addr, size_t len, int flags);
6969
MMANSHARED_EXPORT int mlock(const void *addr, size_t len);
7070
MMANSHARED_EXPORT int munlock(const void *addr, size_t len);
71-
71+
#if !defined(__MINGW32__)
72+
MMANSHARED_EXPORT int ftruncate(int fd, unsigned int size);
73+
#endif
7274
#ifdef __cplusplus
7375
}
7476
#endif
7577

78+
79+
80+
81+
7682
#endif /* _SYS_MMAN_H_ */

0 commit comments

Comments
 (0)