From 8433631d76e38d4f0c47fb4db9da90f3b5fb3627 Mon Sep 17 00:00:00 2001 From: Denis Slynko Date: Sat, 13 Sep 2025 14:35:31 +0300 Subject: [PATCH] [ANI] Remove deprecated mangling Issue: #ICXUTL Change-Id: Ic3e3b52e597302f47382c5f96b47b195f7097b84 Signed-off-by: Denis Slynko --- common/ani_rs/src/macros.rs | 4 +-- common/ani_rs/src/primitive.rs | 16 +++++------ common/ani_rs_macros/src/lib.rs | 1 - common/ani_test/src/ani_callback.rs | 2 +- common/ani_test/src/ani_enum.rs | 12 ++++---- common/ani_test/src/ani_json.rs | 4 +-- common/ani_test/src/ani_struct.rs | 4 +-- common/ani_test/src/array_buffer.rs | 2 +- common/ani_test/src/lib.rs | 2 +- common/ani_test/src/primitive.rs | 4 +-- common/docs/ani_rs_user_guide.md | 20 ++++++------- frameworks/ets/ani/connection/src/bridge.rs | 28 +++++++++---------- .../ets/ani/connection/src/connection.rs | 4 +-- frameworks/ets/ani/connection/src/lib.rs | 8 +++--- frameworks/ets/ani/statistics/src/bridge.rs | 14 +++++----- frameworks/ets/ani/statistics/src/lib.rs | 2 +- 16 files changed, 63 insertions(+), 64 deletions(-) diff --git a/common/ani_rs/src/macros.rs b/common/ani_rs/src/macros.rs index 54d682983..4732f4d07 100644 --- a/common/ani_rs/src/macros.rs +++ b/common/ani_rs/src/macros.rs @@ -23,7 +23,7 @@ macro_rules! bind { )* ]; - let path = unsafe { std::ffi::CStr::from_bytes_with_nul_unchecked(concat!($path, ";\0").as_bytes()) }; + let path = unsafe { std::ffi::CStr::from_bytes_with_nul_unchecked(concat!($path, "\0").as_bytes()) }; let namespace = $en.find_namespace(path).unwrap(); $en.bind_namespace_functions(namespace, &functions).unwrap(); @@ -39,7 +39,7 @@ macro_rules! bind { )* ]; - let path = unsafe { std::ffi::CStr::from_bytes_with_nul_unchecked(concat!($path, ";\0").as_bytes()) }; + let path = unsafe { std::ffi::CStr::from_bytes_with_nul_unchecked(concat!($path, "\0").as_bytes()) }; let class = $en.find_class(path).unwrap(); $en.bind_class_methods(class, &functions).unwrap(); }}; diff --git a/common/ani_rs/src/primitive.rs b/common/ani_rs/src/primitive.rs index 936d3d812..493f2a276 100644 --- a/common/ani_rs/src/primitive.rs +++ b/common/ani_rs/src/primitive.rs @@ -212,7 +212,7 @@ impl AniExt for bool { let class = env.find_class(signature::BOOLEAN)?; env.new_object_with_signature( &class, - CStr::from_bytes_with_nul_unchecked(b"Z:V\0"), + CStr::from_bytes_with_nul_unchecked(b"z:\0"), (value,), ) .map(|obj| obj.into()) @@ -392,7 +392,7 @@ impl AniExt for i8 { let class = env.find_class(signature::BYTE)?; env.new_object_with_signature( &class, - CStr::from_bytes_with_nul_unchecked(b"B:V\0"), + CStr::from_bytes_with_nul_unchecked(b"b:\0"), (value,), ) .map(|obj| obj.into()) @@ -572,7 +572,7 @@ impl AniExt for i16 { let class = env.find_class(signature::SHORT)?; env.new_object_with_signature( &class, - CStr::from_bytes_with_nul_unchecked(b"S:V\0"), + CStr::from_bytes_with_nul_unchecked(b"s:\0"), (value,), ) .map(|obj| obj.into()) @@ -751,7 +751,7 @@ impl AniExt for i32 { let class = env.find_class(signature::INT)?; env.new_object_with_signature( &class, - CStr::from_bytes_with_nul_unchecked(b"I:V\0"), + CStr::from_bytes_with_nul_unchecked(b"i:\0"), (value,), ) .map(|obj| obj.into()) @@ -930,7 +930,7 @@ impl AniExt for i64 { let class = env.find_class(signature::LONG)?; env.new_object_with_signature( &class, - CStr::from_bytes_with_nul_unchecked(b"J:V\0"), + CStr::from_bytes_with_nul_unchecked(b"l:\0"), (value,), ) .map(|obj| obj.into()) @@ -1110,7 +1110,7 @@ impl AniExt for f32 { let class = env.find_class(signature::FLOAT)?; env.new_object_with_signature( &class, - CStr::from_bytes_with_nul_unchecked(b"F:V\0"), + CStr::from_bytes_with_nul_unchecked(b"f:\0"), (value,), ) .map(|obj| obj.into()) @@ -1289,7 +1289,7 @@ impl AniExt for f64 { let class = env.find_class(signature::DOUBLE)?; env.new_object_with_signature( &class, - CStr::from_bytes_with_nul_unchecked(b"D:V\0"), + CStr::from_bytes_with_nul_unchecked(b"d:\0"), (value,), ) .map(|obj| obj.into()) @@ -1511,7 +1511,7 @@ impl AniExt for char { let class = env.find_class(signature::CHAR)?; env.new_object_with_signature( &class, - CStr::from_bytes_with_nul_unchecked(b"C:V\0"), + CStr::from_bytes_with_nul_unchecked(b"c:\0"), (value,), ) .map(|obj| obj.into()) diff --git a/common/ani_rs_macros/src/lib.rs b/common/ani_rs_macros/src/lib.rs index 975ce5a17..33c73ff83 100644 --- a/common/ani_rs_macros/src/lib.rs +++ b/common/ani_rs_macros/src/lib.rs @@ -80,7 +80,6 @@ fn entry(args: TokenStream2, item: TokenStream2) -> Result { let s = syn::parse2::(s) .map_err(|item| Error::new(item.span(), "Invalid Attribute `path`"))?; rename = s.value(); - rename.push(';'); rename.push('\0'); } if let Ok(mut item) = syn::parse2::(item.clone()) { diff --git a/common/ani_test/src/ani_callback.rs b/common/ani_test/src/ani_callback.rs index c7fa79e36..b45ec6360 100644 --- a/common/ani_test/src/ani_callback.rs +++ b/common/ani_test/src/ani_callback.rs @@ -183,7 +183,7 @@ pub fn execute_ani_ref_callback2(env: &AniEnv, callback: AniFnObject) -> Result< Ok(()) } -#[ani_rs::ani(path = "Lanirs/test/ani_test/AniRefStruct", output = "only")] +#[ani_rs::ani(path = "anirs.test.ani_test.AniRefStruct", output = "only")] struct AniRefCallbackStruct { ani_obj_string: GlobalRef>, ani_string: String, diff --git a/common/ani_test/src/ani_enum.rs b/common/ani_test/src/ani_enum.rs index 4071774c4..4c8e21dfb 100644 --- a/common/ani_test/src/ani_enum.rs +++ b/common/ani_test/src/ani_enum.rs @@ -13,7 +13,7 @@ use ani_rs::business_error::BusinessError; -#[ani_rs::ani(path = "Lanirs/test/ani_test/EnumNumber")] +#[ani_rs::ani(path = "anirs.test.ani_test.EnumNumber")] #[derive(Debug)] enum EnumNumber { One = 1, @@ -21,7 +21,7 @@ enum EnumNumber { Three = 3, } -#[ani_rs::ani(path = "Lanirs/test/ani_test/EnumString")] +#[ani_rs::ani(path = "anirs.test.ani_test.EnumString")] #[derive(Debug)] enum EnumString { One = 1, @@ -39,14 +39,14 @@ pub fn enum_test_string<'local>(input: EnumString) -> Result Result<(), Ok(()) } -#[ani_rs::ani(path = "Lanirs/test/ani_test/HttpDataType")] +#[ani_rs::ani(path = "anirs.test.ani_test.HttpDataType")] #[derive(Debug)] pub enum HttpDataType { String, @@ -98,7 +98,7 @@ pub fn json_request_test( Ok(res) } -#[ani_rs::ani(path = "Lanirs/test/ani_test/HttpResponse", output = "only")] +#[ani_rs::ani(path = "anirs.test.ani_test.HttpResponse", output = "only")] pub struct HttpResponse { pub result: GlobalRef>, pub result_type: HttpDataType, diff --git a/common/ani_test/src/ani_struct.rs b/common/ani_test/src/ani_struct.rs index 88bedad11..3ba4eab44 100644 --- a/common/ani_test/src/ani_struct.rs +++ b/common/ani_test/src/ani_struct.rs @@ -13,14 +13,14 @@ use ani_rs::business_error::BusinessError; -#[ani_rs::ani(path = "Lanirs/test/ani_test/Action")] +#[ani_rs::ani(path = "anirs.test.ani_test.Action")] #[derive(Debug)] pub enum Action { Download, Upload, } -#[ani_rs::ani(path = "Lanirs/test/ani_test/Config")] +#[ani_rs::ani(path = "anirs.test.ani_test.Config")] #[derive(Debug)] pub struct Config { pub action: Action, diff --git a/common/ani_test/src/array_buffer.rs b/common/ani_test/src/array_buffer.rs index 1a1252486..ca421d3e1 100644 --- a/common/ani_test/src/array_buffer.rs +++ b/common/ani_test/src/array_buffer.rs @@ -160,7 +160,7 @@ pub fn create_uint32_array(input: Uint32Array) -> Result(env: &AniEnv, input: AniRef<'local>) -> R Ok(raw1 == raw2) } -#[ani_rs::ani(path = "Lanirs/test/ani_test/AniRefStruct")] +#[ani_rs::ani(path = "anirs.test.ani_test.AniRefStruct")] #[derive(Debug)] struct AniRefStruct<'local> { ani_obj_string: AniObject<'local>, diff --git a/common/docs/ani_rs_user_guide.md b/common/docs/ani_rs_user_guide.md index 888ce1e98..7459b3e98 100644 --- a/common/docs/ani_rs_user_guide.md +++ b/common/docs/ani_rs_user_guide.md @@ -18,13 +18,13 @@ Rust 和 ArkTS的代码风格有很大区别,Rust 社区喜欢 `snake_case` - Rust枚举中的字段名必须保持大驼峰,最终会通过ani_rs过程宏将序列化名修改为全大写。Rust枚举字段名转换成全大写后必须和Arkts结构体字段名一致。 ```rust -#[ani_rs::ani(path = "L@ohos/anirs/test/ani_test/ActionInner")] +#[ani_rs::ani(path = "@ohos.anirs.test.ani_test.ActionInner")] pub enum Action { Download, //命名与Arkts一致,仅命名风格区别,ani_rs过程宏自动切换命名风格 Upload, } -#[ani_rs::ani(path = "L@ohos/anirs/test/ani_test/ConfigInner")] +#[ani_rs::ani(path = "@ohos.anirs.test.ani_test.ConfigInner")] pub struct Config { pub config_action: Action, //命名与Arkts一致,仅命名风格区别,ani_rs过程宏自动切换命名风格 pub config_url: String, @@ -48,7 +48,7 @@ export class ConfigInner { 如果结构体仅涉及序列化,不涉及反序列化(即仅存在rust到arkts的转换),可以如下定义: ```rust -#[ani_rs::ani(path = "L@ohos/anirs/test/ani_test/ConfigInner", output = "only")] +#[ani_rs::ani(path = "@ohos.anirs.test.ani_test.ConfigInner", output = "only")] pub struct Config { pub config_action: Action, pub config_url: String, @@ -73,11 +73,11 @@ Rust中完成函数/方法绑定: ```rust ani_constructor!( - namespace "L@ohos/net/connection/connection" + namespace "@ohos.net.connection.connection" [ "addCustomDnsRuleSync": connection::add_custom_dns_rule, ] - class "L@ohos/net/connection/connection/NetConnectionInner" + class "@ohos.net.connection.connection.NetConnectionInner" [ "onNetAvailable": connection::on_net_available, "onNetBlockStatusChange": connection::on_net_block_status_change, @@ -468,9 +468,9 @@ rust: ```rust #[derive(serde::Serialize, serde::Deserialize)] pub enum ResponseCodeOutput { - #[serde(rename = "Lanirs/test/ani_test/ResponseCode;")] + #[serde(rename = "anirs.test.ani_test.ResponseCode")] Code(ResponseCode), - #[serde(rename = "Lanirs/test/ani_test/HttpProtocol;")] + #[serde(rename = "anirs.test.ani_test.HttpProtocol")] Proto(HttpProtocol), I32(i32), } @@ -490,7 +490,7 @@ export native function enumTestStruct(input: ResponseCode | HttpProtocol | int): rust ```rust -#[ani_rs::ani(path = "L@ohos/anirs/test/ani_test/EnumNumber")] +#[ani_rs::ani(path = "@ohos.anirs.test.ani_test.EnumNumber")] enum EnumNumber { One = 1, Two = 2, @@ -521,7 +521,7 @@ export native function enumTestNumber ( input: EnumNumber): EnumNumber rust ```rust -#[ani_rs::ani(path = "L@ohos/anirs/test/ani_test/Config")] +#[ani_rs::ani(path = "@ohos.anirs.test.ani_test.Config")] pub struct Config { pub config_action: Action, pub config_url: String, @@ -567,7 +567,7 @@ pub struct AniObject<'local>(AniRef<'local>); rust: ```rust -#[ani_rs::ani(path = "Lanirs/test/ani_test/HttpDataType")] +#[ani_rs::ani(path = "anirs.test.ani_test.HttpDataType")] pub enum HttpDataType { String, Object = 1, diff --git a/frameworks/ets/ani/connection/src/bridge.rs b/frameworks/ets/ani/connection/src/bridge.rs index 76e40fcc9..30e1e0b1d 100644 --- a/frameworks/ets/ani/connection/src/bridge.rs +++ b/frameworks/ets/ani/connection/src/bridge.rs @@ -11,12 +11,12 @@ // See the License for the specific language governing permissions and // limitations under the License. -#[ani_rs::ani(path = "L@ohos/net/connection/connection/NetConnectionInner")] +#[ani_rs::ani(path = "@ohos.net.connection.connection.NetConnectionInner")] pub struct NetConnection { pub native_ptr: i64, } -#[ani_rs::ani(path = "L@ohos/net/connection/connection/Cleaner")] +#[ani_rs::ani(path = "@ohos.net.connection.connection.Cleaner")] pub struct Cleaner { pub ptr: i64, } @@ -28,18 +28,18 @@ pub struct NetSpecifier { pub bearer_private_identifier: Option, } -#[ani_rs::ani(path = "L@ohos/net/connection/connection/NetCapabilityInfoInner")] +#[ani_rs::ani(path = "@ohos.net.connection.connection.NetCapabilityInfoInner")] pub struct NetCapabilityInfo { pub net_handle: NetHandle, pub net_cap: NetCapabilities, } -#[ani_rs::ani(path = "L@ohos/net/connection/connection/NetHandleInner")] +#[ani_rs::ani(path = "@ohos.net.connection.connection.NetHandleInner")] pub struct NetHandle { pub net_id: i32, } -#[ani_rs::ani(path = "L@ohos/net/connection/connection/NetCapabilitiesInner")] +#[ani_rs::ani(path = "@ohos.net.connection.connection.NetCapabilitiesInner")] pub struct NetCapabilities { pub link_up_bandwidth_kbps: Option, @@ -50,19 +50,19 @@ pub struct NetCapabilities { pub bearer_types: Vec, } -#[ani_rs::ani(path = "L@ohos/net/connection/connection/NetConnectionPropertyInfoInner")] +#[ani_rs::ani(path = "@ohos.net.connection.connection.NetConnectionPropertyInfoInner")] pub struct NetConnectionPropertyInfo { pub net_handle: NetHandle, pub connection_properties: ConnectionProperties, } -#[ani_rs::ani(path = "L@ohos/net/connection/connection/NetBlockStatusInfoInner")] +#[ani_rs::ani(path = "@ohos.net.connection.connection.NetBlockStatusInfoInner")] pub struct NetBlockStatusInfo { pub net_handle: NetHandle, pub blocked: bool, } -#[ani_rs::ani(path = "L@ohos/net/connection/connection/NetCap")] +#[ani_rs::ani(path = "@ohos.net.connection.connection.NetCap")] pub enum NetCap { NetCapabilityMms = 0, NetCapabilityNotMetered = 11, @@ -73,7 +73,7 @@ pub enum NetCap { NetCapabilityCheckingConnectivity = 31, } -#[ani_rs::ani(path = "L@ohos/net/connection/connection/NetBearType")] +#[ani_rs::ani(path = "@ohos.net.connection.connection.NetBearType")] pub enum NetBearType { BearerCellular = 0, BearerWifi = 1, @@ -82,7 +82,7 @@ pub enum NetBearType { BearerVpn = 4, } -#[ani_rs::ani(path = "L@ohos/net/connection/connection/ConnectionPropertiesInner")] +#[ani_rs::ani(path = "@ohos.net.connection.connection.ConnectionPropertiesInner")] pub struct ConnectionProperties { pub interface_name: String, @@ -97,7 +97,7 @@ pub struct ConnectionProperties { pub mtu: i32, } -#[ani_rs::ani(path = "L@ohos/net/connection/connection/RouteInfoInner")] +#[ani_rs::ani(path = "@ohos.net.connection.connection.RouteInfoInner")] pub struct RouteInfo { pub iface: String, @@ -110,13 +110,13 @@ pub struct RouteInfo { pub is_default_route: bool, } -#[ani_rs::ani(path = "L@ohos/net/connection/connection/LinkAddressInner")] +#[ani_rs::ani(path = "@ohos.net.connection.connection.LinkAddressInner")] pub struct LinkAddress { pub address: NetAddress, pub prefix_length: i32, } -#[ani_rs::ani(path = "L@ohos/net/connection/connection/NetAddressInner")] +#[ani_rs::ani(path = "@ohos.net.connection.connection.NetAddressInner")] pub struct NetAddress { pub address: String, @@ -125,7 +125,7 @@ pub struct NetAddress { pub port: Option, } -#[ani_rs::ani(path = "L@ohos/net/connection/connection/HttpProxyInner")] +#[ani_rs::ani(path = "@ohos.net.connection.connection.HttpProxyInner")] pub struct HttpProxy { pub host: String, diff --git a/frameworks/ets/ani/connection/src/connection.rs b/frameworks/ets/ani/connection/src/connection.rs index 069748958..6db164b1b 100644 --- a/frameworks/ets/ani/connection/src/connection.rs +++ b/frameworks/ets/ani/connection/src/connection.rs @@ -225,10 +225,10 @@ pub(crate) fn create_net_connection<'local>( ) -> Result, BusinessError> { static CONNECTION_CLASS: &CStr = unsafe { CStr::from_bytes_with_nul_unchecked( - b"L@ohos/net/connection/connection/NetConnectionInner;\0", + b"@ohos.net.connection.connection.NetConnectionInner\0", ) }; - static CTOR_SIGNATURE: &CStr = unsafe { CStr::from_bytes_with_nul_unchecked(b"J:V\0") }; + static CTOR_SIGNATURE: &CStr = unsafe { CStr::from_bytes_with_nul_unchecked(b"l:\0") }; let connection = Box::new(Connection::new(None, None)); diff --git a/frameworks/ets/ani/connection/src/lib.rs b/frameworks/ets/ani/connection/src/lib.rs index 328dcccd9..713952671 100644 --- a/frameworks/ets/ani/connection/src/lib.rs +++ b/frameworks/ets/ani/connection/src/lib.rs @@ -22,7 +22,7 @@ pub mod wrapper; use ani_rs::ani_constructor; ani_constructor!( - namespace "L@ohos/net/connection/connection" + namespace "@ohos.net.connection.connection" [ "createNetConnection": connection::create_net_connection, "getDefaultNetSync" : connection::get_default_net, @@ -49,12 +49,12 @@ ani_constructor!( "addCustomDnsRuleSync" : connection::set_custom_dns_rule, "removeCustomDnsRuleSync" : connection::remove_custom_dns_rule, ] - class "L@ohos/net/connection/connection/NetHandleInner" + class "@ohos.net.connection.connection.NetHandleInner" [ "getAddressByNameSyncWithHandle" : connection::get_address_by_name_with_handle, "getAddressesByNameSyncWithHandle": connection::get_addresses_by_name_with_handle, ] - class "L@ohos/net/connection/connection/NetConnectionInner" + class "@ohos.net.connection.connection.NetConnectionInner" [ "onNetAvailable": connection::on_net_available, "onNetBlockStatusChange": connection::on_net_block_status_change, @@ -65,7 +65,7 @@ ani_constructor!( "registerSync" : connection::register_network_change, "unregisterSync" : connection::unregister_network_change, ] - class "L@ohos/net/connection/connection/Cleaner" + class "@ohos.net.connection.connection.Cleaner" [ "clean" : connection::connection_clean, ] diff --git a/frameworks/ets/ani/statistics/src/bridge.rs b/frameworks/ets/ani/statistics/src/bridge.rs index 90189d82d..c8995d0ed 100644 --- a/frameworks/ets/ani/statistics/src/bridge.rs +++ b/frameworks/ets/ani/statistics/src/bridge.rs @@ -17,7 +17,7 @@ use ani_rs::ani; use serde::{Deserialize, Serialize}; use std::collections::HashMap; -#[ani_rs::ani(path = "L@ohos/net/connection/connection/NetBearType")] +#[ani_rs::ani(path = "@ohos.net.connection.connection.NetBearType")] #[derive(Debug, Copy, Clone)] pub enum NetBearType { BearerCellular = 0, @@ -29,7 +29,7 @@ pub enum NetBearType { BearerDefault, } -#[ani_rs::ani(path = "L@ohos/net/statistics/statistics/NetworkInfo")] +#[ani_rs::ani(path = "@ohos.net.statistics.statistics.NetworkInfo")] pub struct AniNetworkInfo { pub type_: NetBearType, pub start_time: i32, @@ -42,27 +42,27 @@ pub struct AniUidNetStatsInfoPair { pub net_stats_info: NetStatsInfo, } -#[ani_rs::ani(path = "L@ohos/net/statistics/statistics/NetStatsInfoSequenceItemInner")] +#[ani_rs::ani(path = "@ohos.net.statistics.statistics.NetStatsInfoSequenceItemInner")] pub struct AniNetStatsInfoSequenceItem { pub start_time: i32, pub end_time: i32, pub info: NetStatsInfo, } -#[ani_rs::ani(path = "L@ohos/net/statistics/statistics/NetStatsChangeInfo")] +#[ani_rs::ani(path = "@ohos.net.statistics.statistics.NetStatsChangeInfo")] pub struct NetStatsChangeInfo { pub iface: String, pub uid: Option, } -#[ani_rs::ani(path = "L@ohos/net/statistics/statistics/IfaceInfo")] +#[ani_rs::ani(path = "@ohos.net.statistics.statistics.IfaceInfo")] pub struct IfaceInfo { pub iface: String, pub start_time: i32, pub end_time: i32, } -#[ani_rs::ani(path = "L@ohos/net/statistics/statistics/NetStatsInfoInner")] +#[ani_rs::ani(path = "@ohos.net.statistics.statistics.NetStatsInfoInner")] pub struct NetStatsInfo { pub rx_bytes: i64, pub tx_bytes: i64, @@ -70,7 +70,7 @@ pub struct NetStatsInfo { pub tx_packets: i64, } -#[ani_rs::ani(path = "L@ohos/net/statistics/statistics/UidInfo")] +#[ani_rs::ani(path = "@ohos.net.statistics.statistics.UidInfo")] pub struct UidInfo { pub iface_info: IfaceInfo, pub uid: i32, diff --git a/frameworks/ets/ani/statistics/src/lib.rs b/frameworks/ets/ani/statistics/src/lib.rs index 63d85800f..c7c320210 100644 --- a/frameworks/ets/ani/statistics/src/lib.rs +++ b/frameworks/ets/ani/statistics/src/lib.rs @@ -20,7 +20,7 @@ mod wrapper; use ani_rs::ani_constructor; ani_constructor! { - namespace "L@ohos/net/statistics/statistics" + namespace "@ohos.net.statistics.statistics" [ "getAllRxBytesSync" : statistics::get_all_rx_bytes, "getAllTxBytesSync" : statistics::get_all_tx_bytes, -- Gitee