ccxvii / mujs

An embeddable Javascript interpreter in C.
http://mujs.com/
ISC License
812 stars 98 forks source link

regexp.c: three trivial-to-fix C89-compatibility compilation errors #106

Closed sgbeal closed 5 years ago

sgbeal commented 5 years ago

i'll just leave these here in case you're interested in patching them:

regexp.c:82:9: error: comma at end of enumerator list [-Werror=pedantic]
  L_COUNT, /* {M,N} */
         ^
regexp.c:395:7: error: comma at end of enumerator list [-Werror=pedantic]
  P_REF,
       ^
regexp.c: In function ‘default_alloc’:
regexp.c:906:34: error: unused parameter ‘ctx’ [-Werror=unused-parameter]
 static void *default_alloc(void *ctx, void *p, int n)
                                  ^~~

The fixes for the first two are simply to remove the trailing commas. Stupidly enough, fixing the unused function parameter by removing its name will, in that same build mode, then fail with "parameter name omitted". The portable workaround is ugly but works:

static void *default_alloc(void *ctx, void *p, int n)
{
    if(!ctx){/*unused parameter*/}
    return realloc(p, (size_t)n);
}

With those 3 tweaks, regex.c compiles in strict/pedantic C89 mode. (FWIW, i use your regexp code as a loadable module for my own scripting language.)

ccxvii commented 5 years ago

There are very many other things in MuJS that do not work in strict C89 (use of NAN, INFINITY, snprintf, signbit, etc) that I don't feel this is worth fixing for one file.