ibara/oksh

Latest code fails to build on OSX (Yosemite) due to clock_gettime / CLOCK_MONOTONIC

larryhynes opened this issue · 6 comments

Hi

I don't think any version of OSX / MacOS has clock_gettime; Yosemite certainly doesn't, so the latest update won't build:

$ make
cc -O2 -pipe -Wall -DEMACS -DVI   -c -o alloc.o alloc.c
cc -O2 -pipe -Wall -DEMACS -DVI   -c -o c_ksh.o c_ksh.c
cc -O2 -pipe -Wall -DEMACS -DVI   -c -o c_sh.o c_sh.c
c_sh.c:735:2: warning: implicit declaration of function 'clock_gettime' is invalid in C99
      [-Wimplicit-function-declaration]
        clock_gettime(CLOCK_MONOTONIC, &ts0);
        ^
c_sh.c:735:16: error: use of undeclared identifier 'CLOCK_MONOTONIC'
        clock_gettime(CLOCK_MONOTONIC, &ts0);
                      ^
c_sh.c:752:17: error: use of undeclared identifier 'CLOCK_MONOTONIC'
                clock_gettime(CLOCK_MONOTONIC, &ts1);
                              ^
1 warning and 2 errors generated.
make: *** [c_sh.o] Error 1
ibara commented

Good to know. For reference, I don't own a Mac so I'm dependent on people helping out on that platform.

It seems that adding

#define CLOCK_MONOTONIC SYSTEM_CLOCK

to portable/darwin/darwin.h will be necessary and something with the Mac OS X clock_get_time() function, but I'm not sure what.

I've hacked around this before, but it has been real duct tape stuff and I wouldn't like to pollute your project with it as it's really beyond my realm. I'll test, enthusiastically, anything you or anyone here throws at me, though, and can answer any enquiries you have about header files that do or don't exist on Yosemite (OSX 10.10.5).

(I saw a mention on Stack Overflow that MacOS Sierra and above might natively handle clock_gettime but I have no hard confirmation of that right now and it's getting late so I'll revisit it tomorrow, perhaps.)

ibara commented

That's what the portable/ directory is for: all the pollution goes there :)

ibara commented

Hi. I fixed it (according to TravisCI). Could you please test on your machine?

You certainly did - thanks! :)

Builds OK, with some warnings but no errors - see make output below for reference:

cc -O2 -pipe -Wall -DEMACS -DVI   -c -o alloc.o alloc.c
cc -O2 -pipe -Wall -DEMACS -DVI   -c -o c_ksh.o c_ksh.c
cc -O2 -pipe -Wall -DEMACS -DVI   -c -o c_sh.o c_sh.c
cc -O2 -pipe -Wall -DEMACS -DVI   -c -o c_test.o c_test.c
cc -O2 -pipe -Wall -DEMACS -DVI   -c -o c_ulimit.o c_ulimit.c
cc -O2 -pipe -Wall -DEMACS -DVI   -c -o edit.o edit.c
cc -O2 -pipe -Wall -DEMACS -DVI   -c -o emacs.o emacs.c
emacs.c:872:15: warning: passing 'unsigned char *' to parameter of type 'const char *' converts between pointers to integer types with different sign [-Wpointer-sign]
                if (!strcmp(k->seq, line))
                            ^~~~~~
/usr/include/string.h:77:25: note: passing argument to parameter here
int      strcmp(const char *, const char *);
                            ^
emacs.c:1326:10: warning: passing 'unsigned char *' to parameter of type 'char *' converts between pointers to integer types with different sign [-Wpointer-sign]
        strlcpy(k->seq, str, count + 1);
                ^~~~~~
/usr/include/secure/_string.h:105:28: note: expanded from macro 'strlcpy'
  __builtin___strlcpy_chk (dest, src, len, __darwin_obsz (dest))
                           ^
emacs.c:1359:17: warning: passing 'unsigned char *' to parameter of type 'const char *' converts between pointers to integer types with different sign [-Wpointer-sign]
                    kb_decode(k->seq), k->ftab->xf_name);
                              ^~~~~~
emacs.c:1255:23: note: passing argument to parameter 's' here
kb_decode(const char *s)
                      ^
emacs.c:1361:31: warning: passing 'unsigned char *' to parameter of type 'const char *' converts between pointers to integer types with different sign [-Wpointer-sign]
                shprintf("%s = ", kb_decode(k->seq));
                                            ^~~~~~
emacs.c:1255:23: note: passing argument to parameter 's' here
kb_decode(const char *s)
                      ^
emacs.c:1403:16: warning: passing 'unsigned char *' to parameter of type 'const char *' converts between pointers to integer types with different sign [-Wpointer-sign]
                        if (!strcmp(k->seq, in)) {
                                    ^~~~~~
/usr/include/string.h:77:25: note: passing argument to parameter here
int      strcmp(const char *, const char *);
                            ^
emacs.c:1414:16: warning: passing 'unsigned char *' to parameter of type 'const char *' converts between pointers to integer types with different sign [-Wpointer-sign]
                        if (!strcmp(k->seq, in)) {
                                    ^~~~~~
/usr/include/string.h:77:25: note: passing argument to parameter here
int      strcmp(const char *, const char *);
                            ^
emacs.c:1425:16: warning: passing 'unsigned char *' to parameter of type 'const char *' converts between pointers to integer types with different sign [-Wpointer-sign]
                        if (!strcmp(k->seq, in)) {
                                    ^~~~~~
/usr/include/string.h:77:25: note: passing argument to parameter here
int      strcmp(const char *, const char *);
                            ^
emacs.c:1440:17: warning: passing 'unsigned char *' to parameter of type 'const char *' converts between pointers to integer types with different sign [-Wpointer-sign]
                                if (!strcmp(k->seq, in)) {
                                            ^~~~~~
/usr/include/string.h:77:25: note: passing argument to parameter here
int      strcmp(const char *, const char *);
                            ^
8 warnings generated.
cc -O2 -pipe -Wall -DEMACS -DVI   -c -o eval.o eval.c
cc -O2 -pipe -Wall -DEMACS -DVI   -c -o exec.o exec.c
cc -O2 -pipe -Wall -DEMACS -DVI   -c -o expr.o expr.c
cc -O2 -pipe -Wall -DEMACS -DVI   -c -o history.o history.c
cc -O2 -pipe -Wall -DEMACS -DVI   -c -o io.o io.c
cc -O2 -pipe -Wall -DEMACS -DVI   -c -o jobs.o jobs.c
cc -O2 -pipe -Wall -DEMACS -DVI   -c -o lex.o lex.c
cc -O2 -pipe -Wall -DEMACS -DVI   -c -o mail.o mail.c
cc -O2 -pipe -Wall -DEMACS -DVI   -c -o main.o main.c
cc -O2 -pipe -Wall -DEMACS -DVI   -c -o misc.o misc.c
misc.c:741:22: warning: passing 'const unsigned char *' to parameter of type 'const char *' converts between pointers to integer types with different sign [-Wpointer-sign]
        if ((colon = strchr(pattern, ':')) == NULL || colon[1] != MAGIC) {
                            ^~~~~~~
/usr/include/string.h:76:26: note: passing argument to parameter here
char    *strchr(const char *, int);
                            ^
misc.c:741:13: warning: assigning to 'const unsigned char *' from 'char *' converts between pointers to integer types with different sign [-Wpointer-sign]
        if ((colon = strchr(pattern, ':')) == NULL || colon[1] != MAGIC) {
                   ^ ~~~~~~~~~~~~~~~~~~~~
misc.c:749:16: warning: passing 'const unsigned char *' to parameter of type 'const char *' converts between pointers to integer types with different sign [-Wpointer-sign]
                if (!strncmp(pattern, cc->name, len) && cc->name[len] == '\0') {
                             ^~~~~~~
/usr/include/string.h:84:26: note: passing argument to parameter here
int      strncmp(const char *, const char *, size_t);
                             ^
misc.c:774:17: warning: initializing 'const char *' with an expression of type 'const unsigned char *' converts between pointers to integer types with different sign [-Wpointer-sign]
                                const char *pp = p + (*p == MAGIC) + 2;
                                            ^    ~~~~~~~~~~~~~~~~~~~~~
misc.c:775:23: warning: passing 'const char *' to parameter of type 'const unsigned char *' converts between pointers to integer types with different sign [-Wpointer-sign]
                                rv = posix_cclass(pp, sub, &p);
                                                  ^~
misc.c:734:35: note: passing argument to parameter 'pattern' here
posix_cclass(const unsigned char *pattern, int test, const unsigned char **ep)
                                  ^
5 warnings generated.
cc -O2 -pipe -Wall -DEMACS -DVI   -c -o path.o path.c
cc -O2 -pipe -Wall -DEMACS -DVI   -c -o shf.o shf.c
cc -O2 -pipe -Wall -DEMACS -DVI   -c -o syn.o syn.c
cc -O2 -pipe -Wall -DEMACS -DVI   -c -o table.o table.c
cc -O2 -pipe -Wall -DEMACS -DVI   -c -o trap.o trap.c
cc -O2 -pipe -Wall -DEMACS -DVI   -c -o tree.o tree.c
cc -O2 -pipe -Wall -DEMACS -DVI   -c -o tty.o tty.c
cc -O2 -pipe -Wall -DEMACS -DVI   -c -o var.o var.c
cc -O2 -pipe -Wall -DEMACS -DVI   -c -o version.o version.c
cc -O2 -pipe -Wall -DEMACS -DVI   -c -o vi.o vi.c
cc -O2 -pipe -Wall -DEMACS -DVI   -c -o portable/common/reallocarray.o portable/common/reallocarray.c
cc -O2 -pipe -Wall -DEMACS -DVI   -c -o portable/common/strtonum.o portable/common/strtonum.c
cc -O2 -pipe -Wall -DEMACS -DVI   -c -o portable/darwin/vis.o portable/darwin/vis.c
cc -O2 -pipe -Wall -DEMACS -DVI  -o oksh alloc.o c_ksh.o c_sh.o c_test.o c_ulimit.o edit.o emacs.o eval.o exec.o expr.o history.o io.o jobs.o lex.o mail.o main.o misc.o path.o shf.o syn.o table.o trap.o tree.o tty.o var.o version.o vi.o portable/common/reallocarray.o portable/common/strtonum.o portable/darwin/vis.o
ibara commented

Looks the same as TravisCI. Those warnings are not anything to worry about,