Skip to content

Commit c008ca1

Browse files
committed
cgen: reduce the empty lines for small programs
1 parent 2b7492e commit c008ca1

3 files changed

Lines changed: 25 additions & 30 deletions

File tree

vlib/v/builder/cc.v

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@ const c_compilation_error_title = 'C compilation error'
2222
fn (mut v Builder) show_c_compiler_output(ccompiler string, res os.Result) {
2323
header := '======== Output of the C Compiler (${ccompiler}) ========'
2424
println(header)
25-
println(res.output.trim_space())
25+
if res.output.len > 0 {
26+
println(res.output.trim_space())
27+
}
2628
println('='.repeat(header.len))
2729
}
2830

vlib/v/gen/c/cgen.v

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -990,8 +990,7 @@ pub fn (mut g Gen) init() {
990990
g.cheaders.writeln('#include <stddef.h>')
991991
} else {
992992
tcc_undef_has_include := '
993-
#if defined(__TINYC__) && defined(__has_include)
994-
// tcc does not support has_include properly yet, turn it off completely
993+
#if defined(__TINYC__) && defined(__has_include) // tcc does not support has_include properly yet, turn it off completely
995994
#undef __has_include
996995
#endif'
997996
g.preincludes.writeln(tcc_undef_has_include)
@@ -8538,13 +8537,11 @@ fn (mut g Gen) panic_debug_info(pos token.Pos) (int, string, string, string) {
85388537
pub fn get_guarded_include_text(iname string, imessage string) string {
85398538
res := '
85408539
|#if defined(__has_include)
8541-
|
85428540
|#if __has_include(${iname})
85438541
|#include ${iname}
85448542
|#else
85458543
|#error VERROR_MESSAGE ${imessage}
85468544
|#endif
8547-
|
85488545
|#else
85498546
|#include ${iname}
85508547
|#endif

vlib/v/gen/c/cheaders.v

Lines changed: 21 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -188,8 +188,7 @@ const c_common_macros = '
188188
#else
189189
#define _MOV
190190
#endif
191-
// tcc does not support has_include properly yet, turn it off completely
192-
#if defined(__TINYC__) && defined(__has_include)
191+
#if defined(__TINYC__) && defined(__has_include) // tcc does not support has_include properly yet, turn it off completely
193192
#undef __has_include
194193
#endif
195194
//likely and unlikely macros
@@ -314,15 +313,6 @@ typedef int (*qsort_callback_func)(const void*, const void*);
314313
// gnu headers use to #define __attribute__ to empty for non-gcc compilers
315314
#undef __attribute__
316315
#endif
317-
#ifdef __TERMUX__
318-
#if !defined(__BIONIC_AVAILABILITY_GUARD)
319-
#define __BIONIC_AVAILABILITY_GUARD(api_level) 0
320-
#endif
321-
#if __BIONIC_AVAILABILITY_GUARD(28)
322-
#else
323-
void * aligned_alloc(size_t alignment, size_t size) { return malloc(size); }
324-
#endif
325-
#endif
326316
//================================== GLOBALS =================================*/
327317
void _vinit(int ___argc, voidptr ___argv);
328318
void _vcleanup(void);
@@ -354,25 +344,34 @@ void _vcleanup(void);
354344
#include <sys/time.h>
355345
#include <unistd.h> // sleep
356346
extern char **environ;
347+
#include <pthread.h>
348+
#ifndef PTHREAD_RWLOCK_PREFER_WRITER_NONRECURSIVE_NP
349+
// musl does not have that
350+
#define pthread_rwlockattr_setkind_np(a, b)
351+
#endif
357352
#endif
358-
#if defined(__CYGWIN__) && !defined(_WIN32)
359-
#error Cygwin is not supported, please use MinGW or Visual Studio.
360-
#endif
361-
#if defined(__linux__) || defined(__APPLE__) || defined(__FreeBSD__) || defined(__DragonFly__) || defined(__vinix__) || defined(__serenity__) || defined(__sun) || defined(__plan9__)
353+
#if defined(__linux__) || defined(__APPLE__) || defined(__FreeBSD__) || defined(__DragonFly__) || defined(__vinix__) || defined(__serenity__) || defined(__sun) || defined(__plan9__) || defined(__OpenBSD__)
362354
#include <sys/types.h>
363-
#include <sys/wait.h> // os__wait uses wait on nix
355+
#include <sys/wait.h> // for os__wait
364356
#endif
365357
#ifdef __OpenBSD__
366-
#include <sys/types.h>
367358
#include <sys/resource.h>
368-
#include <sys/wait.h> // os__wait uses wait on nix
369359
#endif
370360
#ifdef __FreeBSD__
371361
#include <signal.h>
372362
#include <execinfo.h>
373363
#endif
374364
#ifdef __NetBSD__
375-
#include <sys/wait.h> // os__wait uses wait on nix
365+
#include <sys/wait.h> // for os__wait
366+
#endif
367+
#ifdef __TERMUX__
368+
#if !defined(__BIONIC_AVAILABILITY_GUARD)
369+
#define __BIONIC_AVAILABILITY_GUARD(api_level) 0
370+
#endif
371+
#if __BIONIC_AVAILABILITY_GUARD(28)
372+
#else
373+
void * aligned_alloc(size_t alignment, size_t size) { return malloc(size); }
374+
#endif
376375
#endif
377376
#ifdef _WIN32
378377
#define WINVER 0x0600
@@ -406,12 +405,9 @@ void _vcleanup(void);
406405
#include <dbghelp.h>
407406
#pragma comment(lib, "Dbghelp")
408407
#endif
409-
#else
410-
#include <pthread.h>
411-
#ifndef PTHREAD_RWLOCK_PREFER_WRITER_NONRECURSIVE_NP
412-
// musl does not have that
413-
#define pthread_rwlockattr_setkind_np(a, b)
414-
#endif
408+
#endif
409+
#if defined(__CYGWIN__) && !defined(_WIN32)
410+
#error Cygwin is not supported, please use MinGW or Visual Studio.
415411
#endif
416412
#if defined(__MINGW32__) || defined(__MINGW64__) || (defined(_WIN32) && defined(__TINYC__))
417413
#undef PRId64

0 commit comments

Comments
 (0)