From 00a283400d6b4480673370037ac208cc8265f193 Mon Sep 17 00:00:00 2001 From: zhanghuanhuan Date: Tue, 10 Oct 2023 15:19:19 +0800 Subject: [PATCH 1/3] called func bind_variable_internal and enter next loop --- bash-5.1/r_variables/src/lib.rs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/bash-5.1/r_variables/src/lib.rs b/bash-5.1/r_variables/src/lib.rs index 3023ddb..53d9e40 100644 --- a/bash-5.1/r_variables/src/lib.rs +++ b/bash-5.1/r_variables/src/lib.rs @@ -98,6 +98,17 @@ pub unsafe extern "C" fn bind_variable( ); } } + + vc = (*vc).down; + } + + return bind_variable_internal( + name, + value, + (*global_variables).table, + 0 as libc::c_int, + flags, + ); } #[derive(Copy, Clone)] -- Gitee From 1c41e92d74a2d68b37468959e3d42e759e65c2b3 Mon Sep 17 00:00:00 2001 From: zhanghuanhuan Date: Tue, 10 Oct 2023 15:22:48 +0800 Subject: [PATCH 2/3] define static var last_table_searched and add func atoi --- bash-5.1/r_variables/src/lib.rs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/bash-5.1/r_variables/src/lib.rs b/bash-5.1/r_variables/src/lib.rs index 53d9e40..f8b02fd 100644 --- a/bash-5.1/r_variables/src/lib.rs +++ b/bash-5.1/r_variables/src/lib.rs @@ -132,3 +132,15 @@ macro_rules! vc_istempenv { ((*$vc).flags & VC_TEMPFLAGS as libc::c_int) == VC_TEMPFLAGS as libc::c_int } } + +static mut last_table_searched: *mut HASH_TABLE = 0 as *const HASH_TABLE + as *mut HASH_TABLE; + +#[inline] +unsafe extern "C" fn atoi(mut __nptr: *const libc::c_char) -> libc::c_int { + return strtol( + __nptr, + 0 as *mut libc::c_void as *mut *mut libc::c_char, + 10 as libc::c_int, + ) as libc::c_int; +} -- Gitee From b85703fcaa29b6caea41f8f1eb81f2bd8a30e33a Mon Sep 17 00:00:00 2001 From: zhanghuanhuan Date: Tue, 10 Oct 2023 15:25:25 +0800 Subject: [PATCH 3/3] realize func create_variable_tables --- bash-5.1/r_variables/src/lib.rs | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/bash-5.1/r_variables/src/lib.rs b/bash-5.1/r_variables/src/lib.rs index f8b02fd..cb0e1fe 100644 --- a/bash-5.1/r_variables/src/lib.rs +++ b/bash-5.1/r_variables/src/lib.rs @@ -1,3 +1,4 @@ + use libc::*; use r_bash::*; use std::ffi::CStr; @@ -144,3 +145,24 @@ unsafe extern "C" fn atoi(mut __nptr: *const libc::c_char) -> libc::c_int { 10 as libc::c_int, ) as libc::c_int; } + +unsafe extern "C" fn create_variable_tables() { + if shell_variables.is_null() { + // new_var_context 下面会实现 + global_variables = new_var_context( + 0 as *mut libc::c_void as *mut libc::c_char, + 0 as libc::c_int, + ); + shell_variables = global_variables; + (*shell_variables).scope = 0 as libc::c_int; + //hash_create 为外部函数 + (*shell_variables).table = hash_create(VARIABLES_HASH_BUCKETS!() as libc::c_int); + } + if shell_functions.is_null() { + shell_functions = hash_create(FUNCTIONS_HASH_BUCKETS!() as libc::c_int); + } + // debugger + if shell_function_defs.is_null() { + shell_function_defs = hash_create(FUNCTIONS_HASH_BUCKETS!() as libc::c_int); + } +} -- Gitee