Browse Source

Add the few last things to get gcc_complete working

jD91mZM2 6 years ago
parent
commit
441bf9f00b
9 changed files with 52 additions and 17 deletions
  1. 14 0
      include/assert.h
  2. 2 2
      include/stddef.h
  3. 12 12
      include/stdint.h
  4. 7 3
      src/stdlib/src/lib.rs
  5. 1 0
      tests/.gitignore
  6. 1 0
      tests/Makefile
  7. 14 0
      tests/assert.c
  8. 0 0
      tests/expected/assert.stderr
  9. 1 0
      tests/expected/assert.stdout

+ 14 - 0
include/assert.h

@@ -0,0 +1,14 @@
+#ifndef _ASSERT_H
+#define _ASSERT_H
+
+#ifdef NDEBUG
+# define assert(cond)
+#else
+# include <stdio.h>
+# define assert(cond) if (!(cond)) { \
+    fprintf(stderr, "%s: %s:%d: Assertion `%s` failed.\n", __func__, __FILE__, __LINE__, #cond); \
+    abort(); \
+    }
+#endif
+
+#endif

+ 2 - 2
include/stddef.h

@@ -3,10 +3,10 @@
 
 #define NULL 0
 
-typedef signed long long ptrdiff_t;
+typedef signed long ptrdiff_t;
 
 typedef unsigned char wchar_t;
 
-typedef unsigned long long size_t;
+typedef unsigned long size_t;
 
 #endif /* _STDDEF_H */

+ 12 - 12
include/stdint.h

@@ -56,54 +56,54 @@ typedef unsigned short uint_fast16_t;
 #define INT32_C(value) value ## L
 #define INT32_MIN -0x80000000
 #define INT32_MAX 0x7FFFFFFF
-typedef signed long int32_t;
+typedef signed int int32_t;
 
 #define INT_LEAST32_MIN -0x80000000
 #define INT_LEAST32_MAX 0x7FFFFFFF
-typedef signed long int_least32_t;
+typedef signed int int_least32_t;
 
 #define INT_FAST32_MIN -0x80000000
 #define INT_FAST32_MAX 0x7FFFFFFF
-typedef signed long int_fast32_t;
+typedef signed int int_fast32_t;
 
 #define UINT32_C(value) value ## UL
 #define UINT32_MIN 0x00000000
 #define UINT32_MAX 0xFFFFFFFF
-typedef unsigned long uint32_t;
+typedef unsigned int uint32_t;
 
 #define UINT_LEAST32_MIN 0x00000000
 #define UINT_LEAST32_MAX 0xFFFFFFFF
-typedef unsigned long uint_least32_t;
+typedef unsigned int uint_least32_t;
 
 #define UINT_FAST32_MIN 0x00000000
 #define UINT_FAST32_MAX 0xFFFFFFFF
-typedef unsigned long uint_fast32_t;
+typedef unsigned int uint_fast32_t;
 
 #define INT64_C(value) value ## LL
 #define INT64_MIN -0x8000000000000000
 #define INT64_MAX 0x7FFFFFFFFFFFFFFF
-typedef signed long long int64_t;
+typedef signed long int64_t;
 
 #define INT_LEAST64_MIN -0x8000000000000000
 #define INT_LEAST64_MAX 0x7FFFFFFFFFFFFFFF
-typedef signed long long int_least64_t;
+typedef signed long int_least64_t;
 
 #define INT_FAST64_MIN -0x8000000000000000
 #define INT_FAST64_MAX 0x7FFFFFFFFFFFFFFF
-typedef signed long long int_fast64_t;
+typedef signed long int_fast64_t;
 
 #define UINT64_C(value) value ## ULL
 #define UINT64_MIN 0x0000000000000000
 #define UINT64_MAX 0xFFFFFFFFFFFFFFFF
-typedef unsigned long long uint64_t;
+typedef unsigned long uint64_t;
 
 #define UINT_LEAST64_MIN 0x0000000000000000
 #define UINT_LEAST64_MAX 0xFFFFFFFFFFFFFFFF
-typedef unsigned long long uint_least64_t;
+typedef unsigned long uint_least64_t;
 
 #define UINT_FAST64_MIN 0x0000000000000000
 #define UINT_FAST64_MAX 0xFFFFFFFFFFFFFFFF
-typedef unsigned long long uint_fast64_t;
+typedef unsigned long uint_fast64_t;
 
 #define INTMAX_C(value) value ## LL
 #define INTMAX_MIN INT64_MIN

+ 7 - 3
src/stdlib/src/lib.rs

@@ -620,7 +620,11 @@ macro_rules! strto_impl {
 
         let set_endptr = |idx: isize| {
             if !$endptr.is_null() {
-                *$endptr = $s.offset(idx);
+                // This is stupid, but apparently strto* functions want
+                // const input but mut output, yet the man page says
+                // "stores the address of the first invalid character in *endptr"
+                // so obviously it doesn't want us to clone it.
+                *$endptr = $s.offset(idx) as *mut _;
             }
         };
 
@@ -712,7 +716,7 @@ macro_rules! strto_impl {
 
 #[no_mangle]
 pub unsafe extern "C" fn strtoul(s: *const c_char,
-                                 endptr: *mut *const c_char,
+                                 endptr: *mut *mut c_char,
                                  base: c_int)
                                  -> c_ulong {
     strto_impl!(
@@ -728,7 +732,7 @@ pub unsafe extern "C" fn strtoul(s: *const c_char,
 
 #[no_mangle]
 pub unsafe extern "C" fn strtol(s: *const c_char,
-                                endptr: *mut *const c_char,
+                                endptr: *mut *mut c_char,
                                 base: c_int)
                                 -> c_long {
     strto_impl!(

+ 1 - 0
tests/.gitignore

@@ -1,6 +1,7 @@
 /*.out
 /gen/
 /alloc
+/assert
 /args
 /atof
 /atoi

+ 1 - 0
tests/Makefile

@@ -1,5 +1,6 @@
 # Binaries that should generate the same output every time
 EXPECT_BINS=\
+	assert \
 	atof \
 	atoi \
 	brk \

+ 14 - 0
tests/assert.c

@@ -0,0 +1,14 @@
+#include <assert.h>
+#include <stdlib.h>
+#include <stdio.h>
+
+int main() {
+    assert(1 == 1);
+    assert(1 + 1 == 2);
+
+    puts("yay!");
+
+    //This fails, but I can't test it because that'd
+    //make the test fail lol
+    //assert(42 == 1337);
+}

+ 0 - 0
tests/expected/assert.stderr


+ 1 - 0
tests/expected/assert.stdout

@@ -0,0 +1 @@
+yay!