Merge: Activate C warnings in FFI code and revert `NativeString` to `char *`
authorJean Privat <jean@pryen.org>
Wed, 10 Jun 2015 01:47:19 +0000 (21:47 -0400)
committerJean Privat <jean@pryen.org>
Wed, 10 Jun 2015 01:47:19 +0000 (21:47 -0400)
The revert commit is partial, it affects only NativeString and does not touch Char.

Pull-Request: #1451
Reviewed-by: Jean Privat <jean@pryen.org>
Reviewed-by: Lucas Bajolet <r4pass@hotmail.com>

lib/cpp.nit
lib/sdl.nit
lib/sha1.nit
lib/socket/socket_c.nit
lib/standard/file.nit
lib/standard/time.nit
src/c_tools.nit
src/nitni/nitni_base.nit

index c64ae33..a2896d3 100644 (file)
@@ -31,6 +31,6 @@ end
 redef class NativeString
        # Get `self` as a `CppString`
        fun to_cpp_string(length: Int): CppString in "C++" `{
-               return new std::string(reinterpret_cast<char*>(self), length);
+               return new std::string(self, length);
        `}
 end
index c5e1ec9..db0f700 100644 (file)
@@ -164,13 +164,13 @@ extern class SDLDisplay `{SDL_Surface *`}
        fun show_cursor=(val: Bool) `{ SDL_ShowCursor(val? SDL_ENABLE: SDL_DISABLE); `}
 
        # Is the cursor visible?
-       fun show_cursor: Bool `{ SDL_ShowCursor(SDL_QUERY); `}
+       fun show_cursor: Bool `{ return SDL_ShowCursor(SDL_QUERY); `}
 
        # Grab or release the input
        fun grab_input=(val: Bool) `{ SDL_WM_GrabInput(val? SDL_GRAB_ON: SDL_GRAB_OFF); `}
 
        # Is the input grabbed?
-       fun grab_input: Bool `{ SDL_WM_GrabInput(SDL_GRAB_QUERY) == SDL_GRAB_ON; `}
+       fun grab_input: Bool `{ return SDL_WM_GrabInput(SDL_GRAB_QUERY) == SDL_GRAB_ON; `}
 
        # Are instances of `SDLMouseMotionEvent` ignored?
        fun ignore_mouse_motion_events: Bool `{
index eea4c03..8a5acc9 100644 (file)
@@ -231,7 +231,6 @@ redef class String
        #     import base64
        #     assert "The quick brown fox jumps over the lazy dog".sha1.encode_base64 == "L9ThxnotKPzthJ7hu3bnORuT6xI="
        fun sha1: String import String.to_cstring, String.length, NativeString.to_s_with_length `{
-               uint32_t a;
                sha1nfo s;
 
                sha1_init(&s);
@@ -254,7 +253,6 @@ redef class String
        #
        #     assert "The quick brown fox jumps over the lazy dog".sha1_to_s == "2FD4E1C67A2D28FCED849EE1BB76E7391B93EB12"
        fun sha1_to_s: String import String.to_cstring, String.length, NativeString.to_s_with_length `{
-               uint32_t a;
                sha1nfo s;
 
                sha1_init(&s);
index 94eecd7..03d9ddc 100644 (file)
@@ -332,7 +332,9 @@ class NativeSocketObserver
        # are boxed objects, passing them to a C function is illegal.
        fun select(max: NativeSocket, reads: nullable NativeSocketSet, write: nullable NativeSocketSet,
                         except: nullable NativeSocketSet, timeout: NativeTimeval): Int `{
-               fd_set *rds, *wts, *exs = NULL;
+               fd_set *rds = NULL,
+                      *wts = NULL,
+                      *exs = NULL;
                struct timeval *tm = NULL;
                if (reads != NULL) rds = (fd_set*)reads;
                if (write != NULL) wts = (fd_set*)write;
index 9687b0c..b081e84 100644 (file)
@@ -1195,7 +1195,6 @@ redef class Sys
        private fun intern_poll(in_fds: Array[Int], out_fds: Array[Int]) : nullable Int is extern import Array[Int].length, Array[Int].[], Int.as(nullable Int) `{
                int in_len, out_len, total_len;
                struct pollfd *c_fds;
-               sigset_t sigmask;
                int i;
                int first_polled_fd = -1;
                int result;
index 99a9f35..fe2d4c5 100644 (file)
@@ -129,12 +129,11 @@ extern class Tm `{struct tm *`}
        # TODO document allowed format.
        fun strftime(format: String): String import String.to_cstring, NativeString.to_s `{
                char* buf, *c_format;
-               size_t res;
 
                buf = (char*)malloc(100);
                c_format = String_to_cstring(format);
 
-               res = strftime(buf, 100, c_format, self);
+               strftime(buf, 100, c_format, self);
                String s = NativeString_to_s_with_copy(buf);
                free(buf);
                return s;
index 0b80817..50bbcd3 100644 (file)
@@ -148,7 +148,7 @@ class ExternCFile
                if not pkgconfigs.is_empty then
                        pkg = "`pkg-config --cflags {pkgconfigs.join(" ")}`"
                end
-               return "$(CC) $(CFLAGS) {self.cflags} {pkg} -c -o {o} {ff}"
+               return "$(CC) $(CFLAGS) -Wall {self.cflags} {pkg} -c -o {o} {ff}"
        end
 
        redef fun compiles_to_o_file do return true
index f5cccc0..23c72d8 100644 (file)
@@ -94,7 +94,7 @@ redef class MClassType
                if name == "Float" then return "double"
                if name == "Int" then return "long"
                if name == "Byte" then return "unsigned char"
-               if name == "NativeString" then return "unsigned char*"
+               if name == "NativeString" then return "char*"
                if mclass.kind == extern_kind then
                        var ctype = mclass.ctype
                        assert ctype != null
@@ -110,7 +110,7 @@ redef class MClassType
                if name == "Float" then return "double"
                if name == "Int" then return "long"
                if name == "Byte" then return "unsigned char"
-               if name == "NativeString" then return "unsigned char*"
+               if name == "NativeString" then return "char*"
                if mclass.kind == extern_kind then return "void*"
                return super
        end