mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
checker: require unsafe for free()
This commit is contained in:
parent
fa447443ca
commit
46f32fc10c
@ -47,8 +47,10 @@ fn (mut a App) init() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn (mut a App) cleanup() {
|
fn (mut a App) cleanup() {
|
||||||
|
unsafe {
|
||||||
a.ps.free()
|
a.ps.free()
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn (mut a App) run() {
|
fn (mut a App) run() {
|
||||||
title := 'V Particle Example'
|
title := 'V Particle Example'
|
||||||
|
@ -26,8 +26,10 @@ fn handle_client(mut socket net.TcpConn) {
|
|||||||
eprintln('> new client: $client_addr')
|
eprintln('> new client: $client_addr')
|
||||||
mut reader := io.new_buffered_reader(reader: socket)
|
mut reader := io.new_buffered_reader(reader: socket)
|
||||||
defer {
|
defer {
|
||||||
|
unsafe {
|
||||||
reader.free()
|
reader.free()
|
||||||
}
|
}
|
||||||
|
}
|
||||||
socket.write_string('server: hello\n') or { return }
|
socket.write_string('server: hello\n') or { return }
|
||||||
for {
|
for {
|
||||||
received_line := reader.read_line() or { return }
|
received_line := reader.read_line() or { return }
|
||||||
|
@ -470,8 +470,10 @@ fn frame(x voidptr) {
|
|||||||
|
|
||||||
fn cleanup(x voidptr) {
|
fn cleanup(x voidptr) {
|
||||||
mut app := &App(x)
|
mut app := &App(x)
|
||||||
|
unsafe {
|
||||||
app.free()
|
app.free()
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn fail(error string) {
|
fn fail(error string) {
|
||||||
eprintln(error)
|
eprintln(error)
|
||||||
|
@ -23,8 +23,10 @@ pub fn (mut cb Clipboard) clear_all() {
|
|||||||
|
|
||||||
// destroy destroys the clipboard and frees its resources.
|
// destroy destroys the clipboard and frees its resources.
|
||||||
pub fn (mut cb Clipboard) destroy() {
|
pub fn (mut cb Clipboard) destroy() {
|
||||||
|
unsafe {
|
||||||
cb.free()
|
cb.free()
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// check_ownership returns `true` if the `Clipboard` has the content ownership.
|
// check_ownership returns `true` if the `Clipboard` has the content ownership.
|
||||||
pub fn (cb Clipboard) check_ownership() bool {
|
pub fn (cb Clipboard) check_ownership() bool {
|
||||||
|
@ -88,8 +88,10 @@ fn (mut s Server) parse_and_respond(mut conn net.TcpConn) {
|
|||||||
|
|
||||||
mut reader := io.new_buffered_reader(reader: conn)
|
mut reader := io.new_buffered_reader(reader: conn)
|
||||||
defer {
|
defer {
|
||||||
|
unsafe {
|
||||||
reader.free()
|
reader.free()
|
||||||
}
|
}
|
||||||
|
}
|
||||||
req := parse_request(mut reader) or {
|
req := parse_request(mut reader) or {
|
||||||
$if debug {
|
$if debug {
|
||||||
// only show in debug mode to prevent abuse
|
// only show in debug mode to prevent abuse
|
||||||
|
@ -1164,6 +1164,10 @@ pub fn (mut c Checker) method_call(mut node ast.CallExpr) ast.Type {
|
|||||||
return ast.int_type
|
return ast.int_type
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if !c.is_builtin_mod && !c.inside_unsafe && method_name == 'free' {
|
||||||
|
c.warn('manual memory management with `free()` is only allowed in unsafe code',
|
||||||
|
node.pos)
|
||||||
|
}
|
||||||
if left_type == ast.void_type {
|
if left_type == ast.void_type {
|
||||||
// No need to print this error, since this means that the variable is unknown,
|
// No need to print this error, since this means that the variable is unknown,
|
||||||
// and there already was an error before.
|
// and there already was an error before.
|
||||||
|
@ -100,8 +100,8 @@ mut:
|
|||||||
pub fn change_test_runner(x &TestRunner) {
|
pub fn change_test_runner(x &TestRunner) {
|
||||||
pobj := unsafe { &C.main__TestRunner(&test_runner)._object }
|
pobj := unsafe { &C.main__TestRunner(&test_runner)._object }
|
||||||
if pobj != 0 {
|
if pobj != 0 {
|
||||||
test_runner.free()
|
|
||||||
unsafe {
|
unsafe {
|
||||||
|
test_runner.free()
|
||||||
(&C.main__TestRunner(&test_runner))._object = nil
|
(&C.main__TestRunner(&test_runner))._object = nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -442,8 +442,10 @@ fn handle_conn<T>(mut conn net.TcpConn, mut app T, routes map[string]Route) {
|
|||||||
|
|
||||||
mut reader := io.new_buffered_reader(reader: conn)
|
mut reader := io.new_buffered_reader(reader: conn)
|
||||||
defer {
|
defer {
|
||||||
|
unsafe {
|
||||||
reader.free()
|
reader.free()
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
page_gen_start := time.ticks()
|
page_gen_start := time.ticks()
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user