xiaoxiang781216 commented on code in PR #11458: URL: https://github.com/apache/nuttx/pull/11458#discussion_r1438470065
########## arch/sim/src/sim/sim_checknuttxtypes.c: ########## @@ -0,0 +1,100 @@ +/**************************************************************************** + * arch/sim/src/sim/sim_checknuttxtypes.c + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include <assert.h> + +/* nuttx types */ + +#include <dirent.h> +#include <sys/statfs.h> +#include <sys/stat.h> + +/* hostfs types */ + +#define __SIM__ +#include <nuttx/fs/hostfs.h> +#undef __SIM__ + +/* Here we make static assertions to ensure nuttx types (eg. struct stat) + * match the corresponding hostfs types. (eg. struct nuttx_stat_s) + * + * TODO: check the alignment as well. (_Alignof) + */ + +#define STATIC_ASSERT(c) static_assert(c, #c) +#define FIELD(a, b, f) \ + STATIC_ASSERT(offsetof(struct a, f) == offsetof(struct b, f)); \ + STATIC_ASSERT(sizeof(((struct a *)0)->f) == sizeof(((struct b *)0)->f)) + +/* dirent */ + +FIELD(nuttx_dirent_s, dirent, d_type); +FIELD(nuttx_dirent_s, dirent, d_name); + +STATIC_ASSERT(sizeof(struct nuttx_dirent_s) == sizeof(struct dirent)); + +/* stat */ + +FIELD(nuttx_stat_s, stat, st_dev); +FIELD(nuttx_stat_s, stat, st_ino); +FIELD(nuttx_stat_s, stat, st_mode); +FIELD(nuttx_stat_s, stat, st_nlink); +FIELD(nuttx_stat_s, stat, st_uid); +FIELD(nuttx_stat_s, stat, st_gid); +FIELD(nuttx_stat_s, stat, st_rdev); +FIELD(nuttx_stat_s, stat, st_size); +FIELD(nuttx_stat_s, stat, st_atim); +FIELD(nuttx_stat_s, stat, st_mtim); +FIELD(nuttx_stat_s, stat, st_ctim); +FIELD(nuttx_stat_s, stat, st_blksize); +FIELD(nuttx_stat_s, stat, st_blocks); +FIELD(nuttx_stat_s, stat, st_size); + +STATIC_ASSERT(sizeof(struct nuttx_stat_s) == sizeof(struct stat)); Review Comment: add new macro STATIC_ASSERT_STRUCT? like this: ``` STATIC_ASSERT_STRUCT(nuttx_stat_s, stat); ``` ########## arch/sim/src/sim/sim_checknuttxtypes.c: ########## @@ -0,0 +1,100 @@ +/**************************************************************************** + * arch/sim/src/sim/sim_checknuttxtypes.c Review Comment: should we move the check to fs/hostfs/hostfs.c? ########## arch/sim/src/sim/sim_checknuttxtypes.c: ########## @@ -0,0 +1,100 @@ +/**************************************************************************** + * arch/sim/src/sim/sim_checknuttxtypes.c + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include <assert.h> + +/* nuttx types */ + +#include <dirent.h> +#include <sys/statfs.h> +#include <sys/stat.h> + +/* hostfs types */ + +#define __SIM__ +#include <nuttx/fs/hostfs.h> +#undef __SIM__ + +/* Here we make static assertions to ensure nuttx types (eg. struct stat) + * match the corresponding hostfs types. (eg. struct nuttx_stat_s) + * + * TODO: check the alignment as well. (_Alignof) + */ + +#define STATIC_ASSERT(c) static_assert(c, #c) +#define FIELD(a, b, f) \ Review Comment: STATIC_ASSERT_FIELD ########## arch/sim/src/sim/sim_checknuttxtypes.c: ########## @@ -0,0 +1,100 @@ +/**************************************************************************** + * arch/sim/src/sim/sim_checknuttxtypes.c + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include <assert.h> + +/* nuttx types */ + +#include <dirent.h> +#include <sys/statfs.h> +#include <sys/stat.h> + +/* hostfs types */ + +#define __SIM__ Review Comment: why need define manually? ########## arch/sim/src/sim/sim_checknuttxtypes.c: ########## @@ -0,0 +1,100 @@ +/**************************************************************************** + * arch/sim/src/sim/sim_checknuttxtypes.c + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include <assert.h> + +/* nuttx types */ + +#include <dirent.h> +#include <sys/statfs.h> +#include <sys/stat.h> + +/* hostfs types */ + +#define __SIM__ +#include <nuttx/fs/hostfs.h> +#undef __SIM__ + +/* Here we make static assertions to ensure nuttx types (eg. struct stat) + * match the corresponding hostfs types. (eg. struct nuttx_stat_s) + * + * TODO: check the alignment as well. (_Alignof) + */ + +#define STATIC_ASSERT(c) static_assert(c, #c) Review Comment: why not directly use static_assert -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
