Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow bootstrap jimsh to build with MSVC on Windows #321

Merged
merged 2 commits into from
Oct 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions initjimsh.tcl
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,14 @@ proc _jimsh_init {} {
if {[string match "*/*" $jim::argv0]} {
set jim::exe [file join [pwd] $jim::argv0]
} else {
foreach path [split [env PATH ""] $tcl_platform(pathSeparator)] {
set exec [file join [pwd] [string map {\\ /} $path] $jim::argv0]
set jim::argv0 [file tail $jim::argv0]
set path [split [env PATH ""] $tcl_platform(pathSeparator)]
if {$tcl_platform(platform) eq "windows"} {
# Windows searches the current directory first, and convert backslashes to slashes
set path [lmap p [list "" {*}$path] { string map {\\ /} $p }]
}
foreach p $path {
set exec [file join [pwd] $p $jim::argv0]
if {[file executable $exec]} {
set jim::exe $exec
break
Expand Down
39 changes: 21 additions & 18 deletions jim-aio.c
Original file line number Diff line number Diff line change
Expand Up @@ -723,7 +723,26 @@ static void aio_consume(Jim_Obj *objPtr, int n)
}

/* forward declaration */
static int aio_autoflush(Jim_Interp *interp, void *clientData, int mask);
static int aio_flush(Jim_Interp *interp, AioFile *af);

#ifdef jim_ext_eventloop
/**
* Called when the channel is writable.
* Write what we can and return -1 when the write buffer is empty to remove the handler.
*/
static int aio_autoflush(Jim_Interp *interp, void *clientData, int mask)
{
AioFile *af = clientData;

aio_flush(interp, af);
if (Jim_Length(af->writebuf) == 0) {
/* Done, so remove the handler */
return -1;
}
return 0;
}
#endif


/**
* Flushes af->writebuf to the channel and removes that data
Expand Down Expand Up @@ -771,22 +790,6 @@ static int aio_flush(Jim_Interp *interp, AioFile *af)
return JIM_OK;
}

/**
* Called when the channel is writable.
* Write what we can and return -1 when the write buffer is empty to remove the handler.
*/
static int aio_autoflush(Jim_Interp *interp, void *clientData, int mask)
{
AioFile *af = clientData;

aio_flush(interp, af);
if (Jim_Length(af->writebuf) == 0) {
/* Done, so remove the handler */
return -1;
}
return 0;
}

/**
* Read until 'len' bytes are available in readbuf.
*
Expand Down Expand Up @@ -1682,6 +1685,7 @@ static int aio_cmd_readsize(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
return JIM_OK;
}

#ifdef jim_ext_eventloop
static int aio_cmd_timeout(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
{
#ifdef HAVE_SELECT
Expand All @@ -1699,7 +1703,6 @@ static int aio_cmd_timeout(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
#endif
}

#ifdef jim_ext_eventloop
static int aio_eventinfo(Jim_Interp *interp, AioFile * af, unsigned mask,
int argc, Jim_Obj * const *argv)
{
Expand Down
11 changes: 5 additions & 6 deletions jim-win32compat.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ char *dlerror(void);

#include <limits.h>
#define jim_wide _int64
#ifndef HAVE_LONG_LONG
#define HAVE_LONG_LONG
#endif
#ifndef LLONG_MAX
#define LLONG_MAX 9223372036854775807I64
#endif
Expand All @@ -43,12 +46,8 @@ char *dlerror(void);
#define strtoull _strtoui64

#include <io.h>

struct timeval {
long tv_sec;
long tv_usec;
};

/* For struct timeval */
#include <winsock.h>
int gettimeofday(struct timeval *tv, void *unused);

#define HAVE_OPENDIR
Expand Down
2 changes: 1 addition & 1 deletion jimiocompat.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ void Jim_SetResultErrno(Jim_Interp *interp, const char *msg)
Jim_SetResultFormatted(interp, "%s: %s", msg, strerror(Jim_Errno()));
}

#if defined(__MINGW32__)
#if defined(_WIN32) || defined(WIN32)
#include <sys/stat.h>

int Jim_Errno(void)
Expand Down
10 changes: 6 additions & 4 deletions jimiocompat.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ int Jim_OpenForWrite(const char *filename, int append);
*/
int Jim_OpenForRead(const char *filename);

#if defined(__MINGW32__)
#if defined(__MINGW32__) || defined(_WIN32)
#ifndef STRICT
#define STRICT
#endif
Expand Down Expand Up @@ -69,6 +69,7 @@ int Jim_OpenForRead(const char *filename);
#define Jim_Stat _stat64
#define Jim_FileStat _fstat64
#define Jim_Lseek _lseeki64
#define O_TEXT _O_TEXT

#else
#if defined(HAVE_STAT64)
Expand Down Expand Up @@ -111,10 +112,11 @@ int Jim_OpenForRead(const char *filename);
#define execvpe(ARG0, ARGV, ENV) execvp(ARG0, ARGV)
#endif
#endif
#endif

#ifndef O_TEXT
#define O_TEXT 0
#ifndef O_TEXT
#define O_TEXT 0
#endif

#endif

/* jim-file.c */
Expand Down
4 changes: 2 additions & 2 deletions make-bootstrap-jim
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,11 @@ EOF
echo "}"
}

cexts="aio readdir regexp file exec clock array posix"
cexts="aio readdir regexp file exec clock array"
tclexts="bootstrap initjimsh glob stdlib tclcompat"

# Note ordering
allexts="bootstrap aio readdir regexp file glob exec posix clock array stdlib tclcompat"
allexts="bootstrap aio readdir regexp file glob exec clock array stdlib tclcompat"

echo "/* This is single source file, bootstrap version of Jim Tcl. See http://jim.tcl.tk/ */"

Expand Down
Loading