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>
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
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 `{
# 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);
#
# 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);
# 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;
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;
# 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;
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
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
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