Mark deprecated functions so they give a warning on use
PATCH 1/1 Mark deprecated functions so they give a warning on use
If anyone can think of a better way, please share. This should speed up the removal of functions like check_region() (which, despite William's janitorial efforts, is still not at the stage where it can be removed).
Thanks,
Rusty.
--
Anyone who quotes me in their sig is an idiot. -- Rusty Russell.
Name: Mark deprecated functions so they give a warning on use
Author: Rusty Russell
Status: Trivial
D: Should speed elimination of deprecated functions (eg. check_region,
D: deprecated since 2.3, still used in about 120 files).
D:
D: This patch causes an "unused label" warning: hopefully unusual D: enough to make people look twice. eg: D: drivers/net/depca.c: In function `isa_probe': D: drivers/net/depca.c:1413: warning: label `DEPRECATED_use_request_region_return_value' defined but not used
include/linux/compiler.h +6 -0
@@ -19,4 +19,10 @@ ({unsigned long __ptr; \ __asm__ ("" :"=g" (__ptr) :"0" (ptr)); \ (typeof (ptr)) (__ptr + (off)); }) + +/* Used to give a warning on use of deprecated functions. eg: +#define some_old_function(arg) \ +__DEPRECATED(use_newfunction_instead), __some_old_function(arg) +*/ +#define __DEPRECATED (msg) ({DEPRECATED_##msg: 1; })#endif /* __LINUX_COMPILER_H */
include/linux/ioport.h +2 -1
@@ -7,6 +7,7 @@#ifndef _LINUX_IOPORT_H#define _LINUX_IOPORT_H +#include <linux/compiler.h> /* * Resources are tree-like, allowing
@@ -102,7 +103,7 @@ extern int allocate_resource(struct resoextern struct resource *__request_region (struct resource *,unsigned long start,unsigned long n,const char *name);/* Compatibility cruft */ -#define check_region (start,n) __check_region(&ioport_resource, (start), (n)) +#define check_region (start,n) __DEPRECATED(use_request_region_return_value), __check_region(&ioport_resource, (start), (n))#define release_region (start,n) __release_region(&ioport_resource, (start), (n))#define check_mem_region (start,n) __check_region(&iomem_resource, (start), (n))#define release_mem_region (start,n) __release_region(&iomem_resource, (start), (n))
Quoted 1 line · Rusty Russell
+#define
__DEPRECATED(msg)({DEPRECATED_##msg: 1; })
[...]
Quoted 1 line
+#define
check_region(start,n)__DEPRECATED(use_request_region_return_value),__check_region(&ioport_resource, (start), (n))
So now it's a syntax error to use check_region twice in the same function?
r~
Quoted 4 lines · Rusty Russell
If anyone can think of a better way, please share. This should speed up the removal of functions like
check_region()(which, despite William's janitorial efforts, is still not at the stage where it can be removed).
can gcc 3.2's __attribute__((deprecated)) be used?
(someone noted this on kde lists a few days back)
Alex
PATCH 1/1 deprecated function attribute
Quoted 1 line · Alexander Kellett
can gcc 3.2's __attribute__((deprecated)) be used?
I just tested it and it seems to work. If we mark a function as deprecated, then each use of the function emits a warning like:
foo.c:12: warning: `baz' is deprecated (declared at bar.c:60)
Which is very informative, giving both the location of each usage and where the little bastard is declared.
It seems like this was added in gcc 3.0, not 3.2? It was at least in 3.1...
Attached patch adds support for usage of the attribute as "deprecated" and is backward-compatible. Usage is:
int deprecated foo(void)
etc.. The attached patch is _entirely_ untested.
Robert Love
compiler.h | 13 +++++++++++++ 1 files changed, 13 insertions(+)
include/linux/compiler.h +13 -0
@@ -13,6 +13,19 @@#define likely (x) __builtin_expect((x),1)#define unlikely (x) __builtin_expect((x),0) +/* +* Allow us to mark functions as 'deprecated' and have gcc emit a nice +* warning for each use, in hopes of speeding the functions removal. +* Usage is: +* int deprecated foo(void) +* and then gcc will emit a warning for each usage of the function. +*/ +#if __GNUC__ ==3 +#define deprecated __attribute__((deprecated)) +#else +#define deprecated +#endif +/* This macro obfuscates arithmetic on a variable address so that gcc shouldn't recognize the original var, and make assumptions about it */ #define RELOC_HIDE (ptr, off) \
Re: [PATCH] deprecated function attribute
include/linux/compiler.h line 27
Quoted 5 lines · Robert Love
include/linux/compiler.h +5
-0+#if __GNUC__ ==3 +#define deprecated __attribute__((deprecated)) +#else +#define deprecated +#endif
Before someone points it out: I grepped the tree and did not see any uses of "deprecated" as a token on first glance. So the above is safe.
If we want to be preemptive, we can rename the above to "__deprecated__" but I think plain "deprecated" is much better looking.
Robert Love
Re: [PATCH] deprecated function attribute
Quoted 11 lines · Robert Love
include/linux/compiler.h line 27
Quoted 5 lines · Robert Love
include/linux/compiler.h +5
-0+#if __GNUC__ ==3 +#define deprecated __attribute__((deprecated)) +#else +#define deprecated +#endif Before someone points it out: I grepped the tree and did not see any uses of "deprecated" as a token on first glance. So the above is safe.
Quoted 2 lines
If we want to be preemptive, we can rename the above to "
__deprecated__" but I think plain "deprecated" is much better looking.
Eek, please call it something else - something that looks visibly like a syntax rather than a name. __deprecated or __deprecated__ or DEPRECATED.
Signature · 2 lines
Daniel Jacobowitz MontaVista Software Debian GNU/Linux Developer
Re: [PATCH] deprecated function attribute
Quoted 6 lines · Daniel Jacobowitz
Quoted 2 lines
If we want to be preemptive, we can rename the above to "
__deprecated__" but I think plain "deprecated" is much better looking.Eek, please call it something else - something that looks visibly like a syntax rather than a name.
__deprecatedor__deprecated__or DEPRECATED.
Like I said, that is fine with me...
Attached. Still untested :-)
Robert Love
compiler.h | 13 +++++++++++++ 1 files changed, 13 insertions(+)
include/linux/compiler.h +13 -0
@@ -13,6 +13,19 @@#define likely (x) __builtin_expect((x),1)#define unlikely (x) __builtin_expect((x),0) +/* +* Allow us to mark functions as 'deprecated' and have gcc emit a nice +* warning for each use, in hopes of speeding the functions removal. +* Usage is: +* int deprecated foo(void) +* and then gcc will emit a warning for each usage of the function. +*/ +#if __GNUC__ ==3 +#define __deprecated__ __attribute__((deprecated)) +#else +#define __deprecated__ +#endif +/* This macro obfuscates arithmetic on a variable address so that gcc shouldn't recognize the original var, and make assumptions about it */ #define RELOC_HIDE (ptr, off) \