Skip to content

Commit 24cb4e2

Browse files
authored
builtin: cleanup -d vplayground related code (#21329)
1 parent dbf48ea commit 24cb4e2

File tree

1 file changed

+14
-29
lines changed

1 file changed

+14
-29
lines changed

vlib/builtin/builtin.c.v

Lines changed: 14 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -366,17 +366,10 @@ pub fn malloc(n isize) &u8 {
366366
C.fprintf(C.stderr, c'_v_malloc %6d total %10d\n', n, total_m)
367367
// print_backtrace()
368368
}
369+
vplayground_mlimit(n)
369370
if n < 0 {
370371
panic('malloc(${n} < 0)')
371372
}
372-
$if vplayground ? {
373-
if n > 10000 {
374-
panic('allocating more than 10 KB at once is not allowed in the V playground')
375-
}
376-
if total_m > 50 * 1024 * 1024 {
377-
panic('allocating more than 50 MB is not allowed in the V playground')
378-
}
379-
}
380373
mut res := &u8(0)
381374
$if prealloc {
382375
return unsafe { prealloc_malloc(n) }
@@ -409,17 +402,10 @@ pub fn malloc_noscan(n isize) &u8 {
409402
C.fprintf(C.stderr, c'malloc_noscan %6d total %10d\n', n, total_m)
410403
// print_backtrace()
411404
}
405+
vplayground_mlimit(n)
412406
if n < 0 {
413407
panic('malloc_noscan(${n} < 0)')
414408
}
415-
$if vplayground ? {
416-
if n > 10000 {
417-
panic('allocating more than 10 KB at once is not allowed in the V playground')
418-
}
419-
if total_m > 50 * 1024 * 1024 {
420-
panic('allocating more than 50 MB is not allowed in the V playground')
421-
}
422-
}
423409
mut res := &u8(0)
424410
$if prealloc {
425411
return unsafe { prealloc_malloc(n) }
@@ -468,17 +454,10 @@ pub fn malloc_uncollectable(n isize) &u8 {
468454
C.fprintf(C.stderr, c'malloc_uncollectable %6d total %10d\n', n, total_m)
469455
// print_backtrace()
470456
}
457+
vplayground_mlimit(n)
471458
if n < 0 {
472459
panic('malloc_uncollectable(${n} < 0)')
473460
}
474-
$if vplayground ? {
475-
if n > 10000 {
476-
panic('allocating more than 10 KB at once is not allowed in the V playground')
477-
}
478-
if total_m > 50 * 1024 * 1024 {
479-
panic('allocating more than 50 MB is not allowed in the V playground')
480-
}
481-
}
482461
mut res := &u8(0)
483462
$if prealloc {
484463
return unsafe { prealloc_malloc(n) }
@@ -604,14 +583,10 @@ pub fn vcalloc_noscan(n isize) &u8 {
604583
total_m += n
605584
C.fprintf(C.stderr, c'vcalloc_noscan %6d total %10d\n', n, total_m)
606585
}
586+
vplayground_mlimit(n)
607587
$if prealloc {
608588
return unsafe { prealloc_calloc(n) }
609589
} $else $if gcboehm ? {
610-
$if vplayground ? {
611-
if n > 10000 {
612-
panic('allocating more than 10 KB is not allowed in the playground')
613-
}
614-
}
615590
if n < 0 {
616591
panic('calloc_noscan(${n} < 0)')
617592
}
@@ -744,3 +719,13 @@ __global g_main_argc = int(0)
744719

745720
@[markused]
746721
__global g_main_argv = unsafe { nil }
722+
723+
@[if vplayground ?]
724+
fn vplayground_mlimit(n isize) {
725+
if n > 10000 {
726+
panic('allocating more than 10 KB at once is not allowed in the V playground')
727+
}
728+
if total_m > 50 * 1024 * 1024 {
729+
panic('allocating more than 50 MB is not allowed in the V playground')
730+
}
731+
}

0 commit comments

Comments
 (0)