Skip to content

Commit

Permalink
all: Unify header guard usage.
Browse files Browse the repository at this point in the history
The code conventions suggest using header guards, but do not define how
those should look like and instead point to existing files. However, not
all existing files follow the same scheme, sometimes omitting header guards
altogether, sometimes using non-standard names, making it easy to
accidentally pick a "wrong" example.

This commit ensures that all header files of the MicroPython project (that
were not simply copied from somewhere else) follow the same pattern, that
was already present in the majority of files, especially in the py folder.

The rules are as follows.

Naming convention:
* start with the words MICROPY_INCLUDED
* contain the full path to the file
* replace special characters with _

In addition, there are no empty lines before #ifndef, between #ifndef and
one empty line before #endif. #endif is followed by a comment containing
the name of the guard macro.

py/grammar.h cannot use header guards by design, since it has to be
included multiple times in a single C file. Several other files also do not
need header guards as they are only used internally and guaranteed to be
included only once:
* MICROPY_MPHALPORT_H
* mpconfigboard.h
* mpconfigport.h
* mpthreadport.h
* pin_defs_*.h
* qstrdefs*.h
  • Loading branch information
webmeister authored and dpgeorge committed Jul 18, 2017
1 parent d91c117 commit 299bc62
Show file tree
Hide file tree
Showing 181 changed files with 574 additions and 414 deletions.
7 changes: 3 additions & 4 deletions cc3200/bootmgr/bootmgr.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,8 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

#ifndef __BOOTMGR_H__
#define __BOOTMGR_H__
#ifndef MICROPY_INCLUDED_CC3200_BOOTMGR_BOOTMGR_H
#define MICROPY_INCLUDED_CC3200_BOOTMGR_BOOTMGR_H

//****************************************************************************
//
Expand Down Expand Up @@ -66,4 +65,4 @@ extern void Run(unsigned long);
}
#endif

#endif //__BOOTMGR_H__
#endif // MICROPY_INCLUDED_CC3200_BOOTMGR_BOOTMGR_H
7 changes: 3 additions & 4 deletions cc3200/bootmgr/flc.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,8 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

#ifndef __FLC_H__
#define __FLC_H__
#ifndef MICROPY_INCLUDED_CC3200_BOOTMGR_FLC_H
#define MICROPY_INCLUDED_CC3200_BOOTMGR_FLC_H

/******************************************************************************
Expand Down Expand Up @@ -93,4 +92,4 @@ typedef struct _sBootInfo_t
}
#endif

#endif /* __FLC_H__ */
#endif // MICROPY_INCLUDED_CC3200_BOOTMGR_FLC_H
7 changes: 3 additions & 4 deletions cc3200/ftp/ftp.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,8 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

#ifndef FTP_H_
#define FTP_H_
#ifndef MICROPY_INCLUDED_CC3200_FTP_FTP_H
#define MICROPY_INCLUDED_CC3200_FTP_FTP_H

/******************************************************************************
DECLARE EXPORTED FUNCTIONS
Expand All @@ -36,4 +35,4 @@ extern void ftp_enable (void);
extern void ftp_disable (void);
extern void ftp_reset (void);

#endif /* FTP_H_ */
#endif // MICROPY_INCLUDED_CC3200_FTP_FTP_H
8 changes: 3 additions & 5 deletions cc3200/ftp/updater.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,8 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/


#ifndef UPDATER_H_
#define UPDATER_H_
#ifndef MICROPY_INCLUDED_CC3200_FTP_UPDATER_H
#define MICROPY_INCLUDED_CC3200_FTP_UPDATER_H

extern void updater_pre_init (void);
extern bool updater_check_path (void *path);
Expand All @@ -35,4 +33,4 @@ extern bool updater_write (uint8_t *buf, uint32_t len);
extern void updater_finnish (void);
extern bool updater_verify (uint8_t *rbuff, uint8_t *hasbuff);

#endif /* UPDATER_H_ */
#endif // MICROPY_INCLUDED_CC3200_FTP_UPDATER_H
5 changes: 0 additions & 5 deletions cc3200/hal/cc3200_hal.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,6 @@
* THE SOFTWARE.
*/

#ifndef CC3200_LAUNCHXL_HAL_CC3200_HAL_H_
#define CC3200_LAUNCHXL_HAL_CC3200_HAL_H_

#include <stdint.h>
#include <stdbool.h>

Expand Down Expand Up @@ -69,5 +66,3 @@ extern void mp_hal_set_interrupt_char (int c);

#define mp_hal_delay_us(usec) UtilsDelay(UTILS_DELAY_US_TO_COUNT(usec))
#define mp_hal_ticks_cpu() (SysTickPeriodGet() - SysTickValueGet())

#endif /* CC3200_LAUNCHXL_HAL_CC3200_HAL_H_ */
7 changes: 3 additions & 4 deletions cc3200/misc/antenna.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,8 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

#ifndef _ANTENNA_H_
#define _ANTENNA_H_
#ifndef MICROPY_INCLUDED_CC3200_MISC_ANTENNA_H
#define MICROPY_INCLUDED_CC3200_MISC_ANTENNA_H

typedef enum {
ANTENNA_TYPE_INTERNAL = 0,
Expand All @@ -35,4 +34,4 @@ typedef enum {
extern void antenna_init0 (void);
extern void antenna_select (antenna_type_t antenna_type);

#endif /* _ANTENNA_H_ */
#endif // MICROPY_INCLUDED_CC3200_MISC_ANTENNA_H
7 changes: 3 additions & 4 deletions cc3200/misc/mperror.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,8 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

#ifndef MPERROR_H_
#define MPERROR_H_
#ifndef MICROPY_INCLUDED_CC3200_MISC_MPERROR_H
#define MICROPY_INCLUDED_CC3200_MISC_MPERROR_H

extern void NORETURN __fatal_error(const char *msg);

Expand All @@ -39,4 +38,4 @@ void mperror_heartbeat_signal (void);
void mperror_enable_heartbeat (bool enable);
bool mperror_is_heartbeat_enabled (void);

#endif // MPERROR_H_
#endif // MICROPY_INCLUDED_CC3200_MISC_MPERROR_H
7 changes: 3 additions & 4 deletions cc3200/misc/mpexception.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,8 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

#ifndef MPEXCEPTION_H_
#define MPEXCEPTION_H_
#ifndef MICROPY_INCLUDED_CC3200_MISC_MPEXCEPTION_H
#define MICROPY_INCLUDED_CC3200_MISC_MPEXCEPTION_H

extern const char mpexception_value_invalid_arguments[];
extern const char mpexception_num_type_invalid_arguments[];
Expand All @@ -40,4 +39,4 @@ extern void mpexception_set_interrupt_char (int c);
extern void mpexception_nlr_jump (void *o);
extern void mpexception_keyboard_nlr_jump (void);

#endif /* MPEXCEPTION_H_ */
#endif // MICROPY_INCLUDED_CC3200_MISC_MPEXCEPTION_H
7 changes: 3 additions & 4 deletions cc3200/misc/mpirq.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,8 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

#ifndef MPIRQ_H_
#define MPIRQ_H_
#ifndef MICROPY_INCLUDED_CC3200_MISC_MPIRQ_H
#define MICROPY_INCLUDED_CC3200_MISC_MPIRQ_H

/******************************************************************************
DEFINE CONSTANTS
Expand Down Expand Up @@ -72,4 +71,4 @@ void mp_irq_remove (const mp_obj_t parent);
void mp_irq_handler (mp_obj_t self_in);
uint mp_irq_translate_priority (uint priority);

#endif /* MPIRQ_H_ */
#endif // MICROPY_INCLUDED_CC3200_MISC_MPIRQ_H
7 changes: 3 additions & 4 deletions cc3200/mods/modnetwork.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,8 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

#ifndef MODNETWORK_H_
#define MODNETWORK_H_
#ifndef MICROPY_INCLUDED_CC3200_MODS_MODNETWORK_H
#define MICROPY_INCLUDED_CC3200_MODS_MODNETWORK_H

/******************************************************************************
DEFINE CONSTANTS
Expand Down Expand Up @@ -71,4 +70,4 @@ extern const mod_network_nic_type_t mod_network_nic_type_wlan;
******************************************************************************/
void mod_network_init0(void);

#endif // MODNETWORK_H_
#endif // MICROPY_INCLUDED_CC3200_MODS_MODNETWORK_H
7 changes: 3 additions & 4 deletions cc3200/mods/modubinascii.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,8 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#ifndef MICROPY_INCLUDED_CC3200_MODS_MODUBINASCII_H
#define MICROPY_INCLUDED_CC3200_MODS_MODUBINASCII_H

#ifndef MODUBINASCII_H_
#define MODUBINASCII_H_


#endif /* MODUBINASCII_H_ */
#endif // MICROPY_INCLUDED_CC3200_MODS_MODUBINASCII_H
7 changes: 3 additions & 4 deletions cc3200/mods/moduos.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,8 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

#ifndef MODUOS_H_
#define MODUOS_H_
#ifndef MICROPY_INCLUDED_CC3200_MODS_MODUOS_H
#define MICROPY_INCLUDED_CC3200_MODS_MODUOS_H

#include "py/obj.h"

Expand All @@ -45,4 +44,4 @@ typedef struct _os_term_dup_obj_t {
******************************************************************************/
void osmount_unmount_all (void);

#endif // MODUOS_H_
#endif // MICROPY_INCLUDED_CC3200_MODS_MODUOS_H
7 changes: 3 additions & 4 deletions cc3200/mods/modusocket.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,8 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

#ifndef MODUSOCKET_H_
#define MODUSOCKET_H_
#ifndef MICROPY_INCLUDED_CC3200_MODS_MODUSOCKET_H
#define MICROPY_INCLUDED_CC3200_MODS_MODUSOCKET_H

extern const mp_obj_dict_t socket_locals_dict;
extern const mp_stream_p_t socket_stream_p;
Expand All @@ -36,4 +35,4 @@ extern void modusocket_socket_delete (int16_t sd);
extern void modusocket_enter_sleep (void);
extern void modusocket_close_all_user_sockets (void);

#endif /* MODUSOCKET_H_ */
#endif // MICROPY_INCLUDED_CC3200_MODS_MODUSOCKET_H
7 changes: 3 additions & 4 deletions cc3200/mods/modwlan.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,8 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

#ifndef MODWLAN_H_
#define MODWLAN_H_
#ifndef MICROPY_INCLUDED_CC3200_MODS_MODWLAN_H
#define MICROPY_INCLUDED_CC3200_MODS_MODWLAN_H

/******************************************************************************
DEFINE CONSTANTS
Expand Down Expand Up @@ -97,4 +96,4 @@ extern bool wlan_is_connected (void);
extern void wlan_set_current_time (uint32_t seconds_since_2000);
extern void wlan_off_on (void);

#endif /* MODWLAN_H_ */
#endif // MICROPY_INCLUDED_CC3200_MODS_MODWLAN_H
7 changes: 3 additions & 4 deletions cc3200/mods/pybadc.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,9 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

#ifndef PYBADC_H_
#define PYBADC_H_
#ifndef MICROPY_INCLUDED_CC3200_MODS_PYBADC_H
#define MICROPY_INCLUDED_CC3200_MODS_PYBADC_H

extern const mp_obj_type_t pyb_adc_type;

#endif /* PYBADC_H_ */
#endif // MICROPY_INCLUDED_CC3200_MODS_PYBADC_H
7 changes: 3 additions & 4 deletions cc3200/mods/pybi2c.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,9 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

#ifndef PYBI2C_H_
#define PYBI2C_H_
#ifndef MICROPY_INCLUDED_CC3200_MODS_PYBI2C_H
#define MICROPY_INCLUDED_CC3200_MODS_PYBI2C_H

extern const mp_obj_type_t pyb_i2c_type;

#endif // PYBI2C_H_
#endif // MICROPY_INCLUDED_CC3200_MODS_PYBI2C_H
7 changes: 3 additions & 4 deletions cc3200/mods/pybpin.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,8 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

#ifndef PYBPIN_H_
#define PYBPIN_H_
#ifndef MICROPY_INCLUDED_CC3200_MODS_PYBPIN_H
#define MICROPY_INCLUDED_CC3200_MODS_PYBPIN_H

enum {
PORT_A0 = GPIOA0_BASE,
Expand Down Expand Up @@ -138,4 +137,4 @@ uint8_t pin_find_peripheral_unit (const mp_obj_t pin, uint8_t fn, uint8_t type);
uint8_t pin_find_peripheral_type (const mp_obj_t pin, uint8_t fn, uint8_t unit);
int8_t pin_find_af_index (const pin_obj_t* pin, uint8_t fn, uint8_t unit, uint8_t type);;

#endif // PYBPIN_H_
#endif // MICROPY_INCLUDED_CC3200_MODS_PYBPIN_H
7 changes: 3 additions & 4 deletions cc3200/mods/pybrtc.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,8 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

#ifndef PYBRTC_H_
#define PYBRTC_H_
#ifndef MICROPY_INCLUDED_CC3200_MODS_PYBRTC_H
#define MICROPY_INCLUDED_CC3200_MODS_PYBRTC_H

// RTC triggers
#define PYB_RTC_ALARM0 (0x01)
Expand Down Expand Up @@ -56,4 +55,4 @@ extern void pyb_rtc_calc_future_time (uint32_t a_mseconds, uint32_t *f_seconds,
extern void pyb_rtc_repeat_alarm (pyb_rtc_obj_t *self);
extern void pyb_rtc_disable_alarm (void);

#endif // PYBRTC_H_
#endif // MICROPY_INCLUDED_CC3200_MODS_PYBRTC_H
6 changes: 3 additions & 3 deletions cc3200/mods/pybsd.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#ifndef PYBSD_H_
#define PYBSD_H_
#ifndef MICROPY_INCLUDED_CC3200_MODS_PYBSD_H
#define MICROPY_INCLUDED_CC3200_MODS_PYBSD_H

/******************************************************************************
DEFINE PUBLIC TYPES
Expand All @@ -41,4 +41,4 @@ typedef struct {
extern pybsd_obj_t pybsd_obj;
extern const mp_obj_type_t pyb_sd_type;

#endif // PYBSD_H_
#endif // MICROPY_INCLUDED_CC3200_MODS_PYBSD_H
7 changes: 3 additions & 4 deletions cc3200/mods/pybsleep.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,8 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

#ifndef PYBSLEEP_H_
#define PYBSLEEP_H_
#ifndef MICROPY_INCLUDED_CC3200_MODS_PYBSLEEP_H
#define MICROPY_INCLUDED_CC3200_MODS_PYBSLEEP_H

/******************************************************************************
DEFINE CONSTANTS
Expand Down Expand Up @@ -70,4 +69,4 @@ void pyb_sleep_deepsleep (void);
pybsleep_reset_cause_t pyb_sleep_get_reset_cause (void);
pybsleep_wake_reason_t pyb_sleep_get_wake_reason (void);

#endif /* PYBSLEEP_H_ */
#endif // MICROPY_INCLUDED_CC3200_MODS_PYBSLEEP_H
7 changes: 3 additions & 4 deletions cc3200/mods/pybspi.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,9 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

#ifndef PYBSPI_H_
#define PYBSPI_H_
#ifndef MICROPY_INCLUDED_CC3200_MODS_PYBSPI_H
#define MICROPY_INCLUDED_CC3200_MODS_PYBSPI_H

extern const mp_obj_type_t pyb_spi_type;

#endif // PYBSPI_H_
#endif // MICROPY_INCLUDED_CC3200_MODS_PYBSPI_H
3 changes: 3 additions & 0 deletions cc3200/mods/pybtimer.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#ifndef MICROPY_INCLUDED_CC3200_MODS_PYBTIMER_H
#define MICROPY_INCLUDED_CC3200_MODS_PYBTIMER_H

/******************************************************************************
DECLARE EXPORTED DATA
Expand All @@ -35,3 +37,4 @@ extern const mp_obj_type_t pyb_timer_type;
******************************************************************************/
void timer_init0 (void);

#endif // MICROPY_INCLUDED_CC3200_MODS_PYBTIMER_H
7 changes: 3 additions & 4 deletions cc3200/mods/pybuart.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,8 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

#ifndef PYBUART_H_
#define PYBUART_H_
#ifndef MICROPY_INCLUDED_CC3200_MODS_PYBUART_H
#define MICROPY_INCLUDED_CC3200_MODS_PYBUART_H

typedef enum {
PYB_UART_0 = 0,
Expand All @@ -43,4 +42,4 @@ int uart_rx_char(pyb_uart_obj_t *uart_obj);
bool uart_tx_char(pyb_uart_obj_t *self, int c);
bool uart_tx_strn(pyb_uart_obj_t *uart_obj, const char *str, uint len);

#endif // PYBUART_H_
#endif // MICROPY_INCLUDED_CC3200_MODS_PYBUART_H
Loading

0 comments on commit 299bc62

Please sign in to comment.