2009/12/22 Vladimir 'φ-coder/phcoder' Serbinenko <[email protected]>:
>> ./include/grub/list.h:44: warning: 'error' attribute directive ignored
> This situation is acceptable. In unlikely case that cast is indeed bad
> you will get runtime error instead of compile error. But it would be a
> benefit if abort message would de improved by defining intermidiate
> macro while will pass __LINE__ and __FILE__ to bad_cast_real which will
> use it to tell developper where there is a problem
Attached patch has __LINE__ and __FILE__ tags added.
I ran indent on modified headers (list.h, handler.h) so patch has few
coding style changes extra.
--
bvk.chaitanya
=== modified file 'include/grub/handler.h'
--- include/grub/handler.h 2009-03-01 17:51:44 +0000
+++ include/grub/handler.h 2009-12-23 04:14:29 +0000
@@ -27,8 +27,8 @@
{
struct grub_handler *next;
const char *name;
- grub_err_t (*init) (void);
- grub_err_t (*fini) (void);
+ grub_err_t (*init) (void);
+ grub_err_t (*fini) (void);
};
typedef struct grub_handler *grub_handler_t;
@@ -41,20 +41,20 @@
};
typedef struct grub_handler_class *grub_handler_class_t;
-extern grub_handler_class_t EXPORT_VAR(grub_handler_class_list);
+extern grub_handler_class_t EXPORT_VAR (grub_handler_class_list);
-void EXPORT_FUNC(grub_handler_register) (grub_handler_class_t class,
- grub_handler_t handler);
-void EXPORT_FUNC(grub_handler_unregister) (grub_handler_class_t class,
- grub_handler_t handler);
-grub_err_t EXPORT_FUNC(grub_handler_set_current) (grub_handler_class_t class,
- grub_handler_t handler);
+void EXPORT_FUNC (grub_handler_register) (grub_handler_class_t class,
+ grub_handler_t handler);
+void EXPORT_FUNC (grub_handler_unregister) (grub_handler_class_t class,
+ grub_handler_t handler);
+grub_err_t EXPORT_FUNC (grub_handler_set_current) (grub_handler_class_t class,
+ grub_handler_t handler);
#define GRUB_AS_HANDLER(ptr) \
((GRUB_FIELD_MATCH (ptr, grub_handler_t, next) && \
GRUB_FIELD_MATCH (ptr, grub_handler_t, name) && \
GRUB_FIELD_MATCH (ptr, grub_handler_t, init) && \
GRUB_FIELD_MATCH (ptr, grub_handler_t, fini)) ? \
- (grub_handler_t) ptr : grub_assert_fail ())
+ (grub_handler_t) ptr : grub_bad_type_cast (__LINE__, __FILE__))
#endif /* ! GRUB_HANDLER_HEADER */
=== modified file 'include/grub/list.h'
--- include/grub/list.h 2009-11-09 14:25:03 +0000
+++ include/grub/list.h 2009-12-23 05:54:34 +0000
@@ -22,6 +22,7 @@
#include <grub/symbol.h>
#include <grub/types.h>
+#include <grub/misc.h>
struct grub_list
{
@@ -32,38 +33,34 @@
typedef int (*grub_list_hook_t) (grub_list_t item);
typedef int (*grub_list_test_t) (grub_list_t new_item, grub_list_t item);
-void EXPORT_FUNC(grub_list_push) (grub_list_t *head, grub_list_t item);
-void * EXPORT_FUNC(grub_list_pop) (grub_list_t *head);
-void EXPORT_FUNC(grub_list_remove) (grub_list_t *head, grub_list_t item);
-int EXPORT_FUNC(grub_list_iterate) (grub_list_t head, grub_list_hook_t hook);
-void EXPORT_FUNC(grub_list_insert) (grub_list_t *head, grub_list_t item,
- grub_list_test_t test);
-
-/* This function doesn't exist, so if assertion is false for some reason, the
- linker would fail. */
-#ifdef APPLE_CC
-/* This approach fails with Apple's gcc. Use grub_abort. */
-#include <grub/misc.h>
+void EXPORT_FUNC (grub_list_push) (grub_list_t * head, grub_list_t item);
+void *EXPORT_FUNC (grub_list_pop) (grub_list_t * head);
+void EXPORT_FUNC (grub_list_remove) (grub_list_t * head, grub_list_t item);
+int EXPORT_FUNC (grub_list_iterate) (grub_list_t head, grub_list_hook_t hook);
+void EXPORT_FUNC (grub_list_insert) (grub_list_t * head, grub_list_t item,
+ grub_list_test_t test);
+
+static inline void *grub_bad_type_cast (int line, const char *file)
+ __attribute__ ((error ("bad type cast between incompatible grub types")));
+
static inline void *
-grub_assert_fail (void)
+grub_bad_type_cast (int line, const char *file)
{
- grub_abort ();
- return 0;
+ grub_fatal ("error:%s:%u: bad type cast between incompatible grub types",
+ file, line);
+ return 0;
}
-#else
-extern void* grub_assert_fail (void);
-#endif
#define GRUB_FIELD_MATCH(ptr, type, field) \
((char *) &(ptr)->field == (char *) &((type) (ptr))->field)
#define GRUB_AS_LIST(ptr) \
(GRUB_FIELD_MATCH (ptr, grub_list_t, next) ? \
- (grub_list_t) ptr : grub_assert_fail ())
+ (grub_list_t) ptr : grub_bad_type_cast (__LINE__, __FILE__))
#define GRUB_AS_LIST_P(pptr) \
(GRUB_FIELD_MATCH (*pptr, grub_list_t, next) ? \
- (grub_list_t *) (void *) pptr : grub_assert_fail ())
+ (grub_list_t *) (void *) pptr : grub_bad_type_cast (__LINE__, __FILE__))
struct grub_named_list
{
@@ -72,18 +69,18 @@
};
typedef struct grub_named_list *grub_named_list_t;
-void * EXPORT_FUNC(grub_named_list_find) (grub_named_list_t head,
+void *EXPORT_FUNC (grub_named_list_find) (grub_named_list_t head,
const char *name);
#define GRUB_AS_NAMED_LIST(ptr) \
((GRUB_FIELD_MATCH (ptr, grub_named_list_t, next) && \
GRUB_FIELD_MATCH (ptr, grub_named_list_t, name))? \
- (grub_named_list_t) ptr : grub_assert_fail ())
+ (grub_named_list_t) ptr : grub_bad_type_cast (__LINE__, __FILE__))
#define GRUB_AS_NAMED_LIST_P(pptr) \
((GRUB_FIELD_MATCH (*pptr, grub_named_list_t, next) && \
GRUB_FIELD_MATCH (*pptr, grub_named_list_t, name))? \
- (grub_named_list_t *) (void *) pptr : grub_assert_fail ())
+ (grub_named_list_t *) (void *) pptr : grub_bad_type_cast (__LINE__,
__FILE__))
#define GRUB_PRIO_LIST_PRIO_MASK 0xff
#define GRUB_PRIO_LIST_FLAG_ACTIVE 0x100
@@ -96,11 +93,11 @@
};
typedef struct grub_prio_list *grub_prio_list_t;
-void EXPORT_FUNC(grub_prio_list_insert) (grub_prio_list_t *head,
- grub_prio_list_t item);
+void EXPORT_FUNC (grub_prio_list_insert) (grub_prio_list_t * head,
+ grub_prio_list_t item);
static inline void
-grub_prio_list_remove (grub_prio_list_t *head, grub_prio_list_t item)
+grub_prio_list_remove (grub_prio_list_t * head, grub_prio_list_t item)
{
if ((item->prio & GRUB_PRIO_LIST_FLAG_ACTIVE) && (item->next))
item->next->prio |= GRUB_PRIO_LIST_FLAG_ACTIVE;
@@ -111,12 +108,12 @@
((GRUB_FIELD_MATCH (ptr, grub_prio_list_t, next) && \
GRUB_FIELD_MATCH (ptr, grub_prio_list_t, name) && \
GRUB_FIELD_MATCH (ptr, grub_prio_list_t, prio))? \
- (grub_prio_list_t) ptr : grub_assert_fail ())
+ (grub_prio_list_t) ptr : grub_bad_type_cast (__LINE__, __FILE__))
#define GRUB_AS_PRIO_LIST_P(pptr) \
((GRUB_FIELD_MATCH (*pptr, grub_prio_list_t, next) && \
GRUB_FIELD_MATCH (*pptr, grub_prio_list_t, name) && \
GRUB_FIELD_MATCH (*pptr, grub_prio_list_t, prio))? \
- (grub_prio_list_t *) (void *) pptr : grub_assert_fail ())
+ (grub_prio_list_t *) (void *) pptr : grub_bad_type_cast (__LINE__,
__FILE__))
#endif /* ! GRUB_LIST_HEADER */
_______________________________________________
Grub-devel mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/grub-devel