Grapheme clustering in Swift and ObjC produce different output!
This swift program:
let s = "வணக்கம்" // This is a word in the Tamil language.
var n = 0
for cluster in Array(s) {
print("cluster \(n) = '\(cluster)'")
n += 1
}
| #import <Cocoa/Cocoa.h> | |
| #import <MetalKit/MetalKit.h> | |
| // | |
| // Compile and run: | |
| // | |
| // clang -O2 -fobjc-arc metal-mouse-lag.m -framework AppKit -framework Metal -framework MetalKit | |
| // ./a.out | |
| // |
| // | |
| // Adding zero to a null-pointer is undefined behavior! | |
| // | |
| // In the following code, String a is dynamically sized array of chars. | |
| // UB is triggerred when appending an empty string to an freshly initialized String. | |
| // See line 50. | |
| // | |
| // What is the recommended approach to avoid this error? | |
| // | |
| // Compile and run with: |
Grapheme clustering in Swift and ObjC produce different output!
This swift program:
let s = "வணக்கம்" // This is a word in the Tamil language.
var n = 0
for cluster in Array(s) {
print("cluster \(n) = '\(cluster)'")
n += 1
}
| diff --git a/sokol/sokol_app.h b/sokol/sokol_app.h | |
| index 0115970..149c336 100644 | |
| --- a/sokol/sokol_app.h | |
| +++ b/sokol/sokol_app.h | |
| @@ -3016,7 +3016,17 @@ _SOKOL_PRIVATE void _sapp_macos_frame(void) { | |
| _sapp.macos.win_dlg = [[_sapp_macos_window_delegate alloc] init]; | |
| _sapp.macos.window.delegate = _sapp.macos.win_dlg; | |
| #if defined(SOKOL_METAL) | |
| - _sapp.macos.mtl_device = MTLCreateSystemDefaultDevice(); | |
| + id<MTLDevice> chosen = nil; |
| // | |
| // This appears to be a bug in MTKView. | |
| // | |
| // To reproduce the bug: | |
| // 1. Create a zero-sized window. | |
| // 2. Add MTKView to window. | |
| // 3. Set window size to a non-zero value. | |
| // | |
| // The MTKView never displays its content! | |
| // It's as if the MTKView doesn't even exist. |
| #import <AppKit/AppKit.h> | |
| int main() { | |
| while (1) { | |
| NSColor *color1 = [NSColor textColor]; | |
| NSColor *color2 = [color1 colorUsingColorSpace:[NSColorSpace deviceRGBColorSpace]]; | |
| CGFloat r, g, b, a; | |
| [color2 getRed:&r green:&g blue:&b alpha:&a]; | |
| printf("text-color: (%f, %f, %f, %f)\n", r, g, b, a); | |
| [NSThread sleepForTimeInterval:1.0]; |
| #include <stdio.h> | |
| #include <stdlib.h> | |
| int is_space[256]; | |
| int next_states[3 * 2]; | |
| int increments[3]; | |
| void initialize_tables(void) { | |
| is_space[' '] = 1; | |
| is_space['\n'] = 1; |
| #include <stdio.h> | |
| #include <stdlib.h> | |
| int is_space(unsigned char ch) { | |
| return (ch == ' ') || (ch == '\n') || (ch == '\r') || (ch == '\t'); | |
| } | |
| long count_words(unsigned char *ptr_begin, unsigned char *ptr_end) { | |
| long n = 0; | |
| unsigned char *ptr = ptr_begin; |
| /* | |
| This program triggers a bug in Clang when compiling with optimizations. | |
| When compiling with no-optimizations, the correct output is produced. | |
| $ clang -O0 test-bug.c && ./a.out | |
| value = 1 |
| Modeling C Ambiguity. |