From: Jim C. <jim...@gm...> - 2012-05-19 07:38:22
|
Create a better version of decl_or_stub macro added previously to merge.h. This version accepts an arg which chooses whether result expands to a declaration (of a function defined elsewhere), or a static inline stub function. Its purpose is to avoid double entries in 2 legs of a big #if/#else/#endif. Signed-off-by: Jim Cromie <jim...@gm...> --- acx.h | 59 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ merge.h | 70 ++++++++++++++++++++++++++++++++--------------------------------- 2 files changed, 93 insertions(+), 36 deletions(-) diff --git a/acx.h b/acx.h index d96f123..6557cef 100644 --- a/acx.h +++ b/acx.h @@ -23,6 +23,65 @@ * #define CONFIG_PM 0 // in include/generated/autoconf.h */ +/* + DECL_OR_STUB(X, proto, stubret) macro: expands as either a + prototype declaring a function defined elsewhere, or a static + inline function stub. + + It reads like if (X) ? proto : stubret; + if X is true, expand as declaration matching the fn-defn elsewhere + if X is false, expand as a stub function, returning stubret. + + stubret: body of function used in stub expansion. + For void use { }, for int use { return 0; }, etc + + proto: full function prototype, excluding "static inline" which is + added in stub expansion. Ex: int foo(void), void bar(int). + + X: condition. if X is true, expansion is a declaration. + if X is NOTHING, expands as an static inline stub. + Note that defined(X) expands as 0 or 1, so cant be used directly. + + How It Works: + 4 macros; 3 xDECL_OR_STUB, and __unshift_A + 2nd assembles args: "proto;", "static inline proto subret" + 3rd selects one of them. + 1st is key: it concats symbol to "__unshift_". + If symbol is true, result is __unshift_<true>, it expands as empty, + If symbol NOTHING, result is __unshift_, which expands to add + another arg, shifting others, thus 4th macro selects decl, + not inline defn + + Usage: avoid direct use of defined(X) conditions, instead do: + #if (complex CPP expression) + # define X + #else + // dont even mention X, best just drop the #else + #endif + + Based upon: + commit 69349c2dc01c489eccaa4c472542c08e370c6d7e + Author: Paul Gortmaker <pau...@wi...> + Date: Thu Apr 12 19:46:32 2012 -0400 +*/ + +#define __unshift_1 /* if cat expands to this, no shift */ +#define __unshift_ 0, +/* if cat expands to this, unshift arg (ala perl) */ + +#define DECL_OR_STUB(_X_, proto, stubret) \ + _DECL_OR_STUB(_X_, proto, stubret) \ + +#define _DECL_OR_STUB(_X_, proto, stubret) \ + __DECL_OR_STUB(__unshift_##_X_, proto, stubret) + +#define __DECL_OR_STUB(arg1_or_empty, proto, stubret) \ + ___DECL_OR_STUB(arg1_or_empty proto; , static inline proto stubret) + +#define ___DECL_OR_STUB(__ignored, val, ...) val + + + #include "acx_config.h" #include "acx_struct_hw.h" #include "acx_struct_dev.h" diff --git a/merge.h b/merge.h index 296efdb..337aa46 100644 --- a/merge.h +++ b/merge.h @@ -2,6 +2,7 @@ #define _MERGE_H_ #include <linux/irq.h> +#include "acx.h" /* these 2 externs are defined in common.c (but we dont have a * common.h), so expose them here. Theyre used in debugfs.c @@ -29,142 +30,140 @@ static void __exit acx_debugfs_exit(void) { } #endif /* defined CONFIG_DEBUG_FS */ #if defined CONFIG_ACX_MAC80211_PCI || defined CONFIG_ACX_MAC80211_MEM -#define decl_or_stub(proto, stubret) proto; -#else -#define decl_or_stub(proto, stubret) static inline proto stubret +# define PCI_OR_MEM #endif -decl_or_stub( +DECL_OR_STUB ( PCI_OR_MEM, void acx_create_desc_queues(acx_device_t *adev, u32 tx_queue_start, u32 rx_queue_start), { } ) -decl_or_stub( +DECL_OR_STUB ( PCI_OR_MEM, int acx_create_hostdesc_queues(acx_device_t *adev), { return 0; } ) -decl_or_stub( +DECL_OR_STUB ( PCI_OR_MEM, void acx_free_desc_queues(acx_device_t *adev), { } ) -decl_or_stub( +DECL_OR_STUB ( PCI_OR_MEM, int _acx_read_phy_reg(acx_device_t *adev, u32 reg, u8 *charbuf), { return 0; } ) -decl_or_stub( +DECL_OR_STUB ( PCI_OR_MEM, int _acx_write_phy_reg(acx_device_t *adev, u32 reg, u8 value), { return 0; } ) -decl_or_stub( +DECL_OR_STUB ( PCI_OR_MEM, void acx_irq_enable(acx_device_t *adev), { } ) -decl_or_stub( +DECL_OR_STUB ( PCI_OR_MEM, void acx_irq_disable(acx_device_t *adev), { } ) -decl_or_stub( +DECL_OR_STUB ( PCI_OR_MEM, int acx_read_eeprom_byte(acx_device_t *adev, u32 addr, u8 *charbuf), { return 0; } ) -decl_or_stub( +DECL_OR_STUB ( PCI_OR_MEM, char *acx_proc_eeprom_output(int *length, acx_device_t *adev), { return (char*) NULL; } ) -decl_or_stub( +DECL_OR_STUB ( PCI_OR_MEM, void acx_up(struct ieee80211_hw *hw), { } ) -decl_or_stub( +DECL_OR_STUB ( PCI_OR_MEM, void acx_set_interrupt_mask(acx_device_t *adev), { } ) -decl_or_stub( +DECL_OR_STUB ( PCI_OR_MEM, void acx_show_card_eeprom_id(acx_device_t *adev), { } ) -decl_or_stub( +DECL_OR_STUB ( PCI_OR_MEM, unsigned int acx_tx_clean_txdesc(acx_device_t *adev), { return 0; } ) -decl_or_stub( +DECL_OR_STUB ( PCI_OR_MEM, int acx_reset_dev(acx_device_t *adev), { return 0; } ) /* wrappers on acx_upload_radio(adev, filename */ -decl_or_stub( +DECL_OR_STUB ( PCI_OR_MEM, int acxmem_upload_radio(acx_device_t *adev), { return 0; } ) -decl_or_stub( +DECL_OR_STUB ( PCI_OR_MEM, int acxpci_upload_radio(acx_device_t *adev), { return 0; } ) -decl_or_stub( +DECL_OR_STUB ( PCI_OR_MEM, void acxmem_update_queue_indicator(acx_device_t *adev, int txqueue), { } ) -decl_or_stub( +DECL_OR_STUB ( PCI_OR_MEM, void _acx_tx_data(acx_device_t *adev, tx_t *tx_opaque, int len, struct ieee80211_tx_info *info, struct sk_buff *skb), { } ) -decl_or_stub( +DECL_OR_STUB ( PCI_OR_MEM, void acx_irq_work(struct work_struct *work), { } ) -decl_or_stub( +DECL_OR_STUB ( PCI_OR_MEM, int acx_write_fw(acx_device_t *adev, const firmware_image_t *fw_image, u32 offset), { return 0; } ) -decl_or_stub( +DECL_OR_STUB ( PCI_OR_MEM, int acx_validate_fw(acx_device_t *adev, const firmware_image_t *fw_image, u32 offset), { return 0; } ) -decl_or_stub( +DECL_OR_STUB ( PCI_OR_MEM, u32 acx_read_cmd_type_status(acx_device_t *adev), { return 0; } ) -decl_or_stub( +DECL_OR_STUB ( PCI_OR_MEM, void acx_write_cmd_type_status(acx_device_t *adev, u16 type, u16 status), { } ) -decl_or_stub( +DECL_OR_STUB ( PCI_OR_MEM, int acx_op_start(struct ieee80211_hw *hw), { return 0; } ) -decl_or_stub( +DECL_OR_STUB ( PCI_OR_MEM, void acx_op_stop(struct ieee80211_hw *hw), { } ) -decl_or_stub( +DECL_OR_STUB ( PCI_OR_MEM, irqreturn_t acx_interrupt(int irq, void *dev_id), { return (irqreturn_t) NULL; } ) -decl_or_stub( +DECL_OR_STUB ( PCI_OR_MEM, void acx_delete_dma_regions(acx_device_t *adev), { } ) -decl_or_stub( +DECL_OR_STUB ( PCI_OR_MEM, void acx_power_led(acx_device_t * adev, int enable), { } ) -decl_or_stub( +DECL_OR_STUB ( PCI_OR_MEM, void acx_clean_txdesc_emergency(acx_device_t *adev), { } ) -decl_or_stub( +DECL_OR_STUB ( PCI_OR_MEM, void acx_log_rxbuffer(const acx_device_t *adev), { } ) -decl_or_stub( +DECL_OR_STUB ( PCI_OR_MEM, void acx_log_txbuffer(acx_device_t *adev), { } ) -decl_or_stub( +DECL_OR_STUB ( PCI_OR_MEM, void *_acx_get_txbuf(acx_device_t * adev, tx_t * tx_opaque), { return (void*) NULL; } ) @@ -201,5 +200,4 @@ static inline txdesc_t* acx_advance_txdesc(acx_device_t *adev, #endif /* !(CONFIG_ACX_MAC80211_PCI || CONFIG_ACX_MAC80211_MEM) */ - #endif /* _MERGE_H_ */ -- 1.7.10.1.487.ga3935e6 |