Skip to content

Commit

Permalink
dlibs: make expand_for_kernel work if invoked more than once
Browse files Browse the repository at this point in the history
The expand_for_kernel macro had an extremely embarrassing bug:
because it always defined a macro with the same name, and because M4
defines all macros before doing any expansions, calling
define_for_kernel twice always duplicated the expansion of the first
in the second invocation, no matter what the second invocation was.

This is unlikely to be what anyone wants.

Fixed by introducing a name (required to be unique, though we do not
validate this) and using that name to inflect the name of the macro
we define in expand_for_kernel.

Signed-off-by: Nick Alcock <nick.alcock@oracle.com>
Reviewed-by: Kris Van Hees <kris.van.hees@oracle.com>
  • Loading branch information
nickalcock committed Nov 25, 2020
1 parent f3a6e95 commit c0683b7
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
8 changes: 4 additions & 4 deletions libdtrace/d-kern.m4
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Oracle Linux DTrace.
* Copyright (c) 2015, 2017, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2015, 2020, Oracle and/or its affiliates. All rights reserved.
* Licensed under the Universal Permissive License v 1.0 as shown at
* http://oss.oracle.com/licenses/upl.
*
Expand Down Expand Up @@ -51,9 +51,9 @@ m4_define([[__define_for_kernel]], [[ m4_dnl
m4_define([[define_for_kernel]], [[m4_divert(-1) __define_for_kernel($@) m4_divert(0)]])m4_dnl

/*
* expand_for_kernel([[(kver, value), (kver, value), ...]], [[default]])
* expand_for_kernel(name, [[(kver, value), (kver, value), ...]], [[default]])
*
* As define_for_kernel, but simply substitutes the result into the output
* rather than defining a macro.
* rather than defining a macro. Every NAME should be unique.
*/
m4_define([[expand_for_kernel]], [[define_for_kernel(__foo, $@)__foo]])m4_dnl
m4_define([[expand_for_kernel]], [[define_for_kernel(__expand_for_kernel_$1, m4_shift($@))__expand_for_kernel_$1]])m4_dnl
2 changes: 1 addition & 1 deletion libdtrace/procfs.d.in
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ define_for_kernel([[__pidtype_sid]], [[ m4_dnl

inline int PIDTYPE_PID = 0;
#pragma D binding "1.0" PIDTYPE_PID
expand_for_kernel([[ (m4_kver(4,19,0), [[ m4_dnl
expand_for_kernel([[pidtype_tgid]], [[ (m4_kver(4,19,0), [[ m4_dnl
inline int PIDTYPE_TGID = 1;
#pragma D binding "1.0" PIDTYPE_TGID]])]])
inline int PIDTYPE_PGID = __pidtype_pgid;
Expand Down

0 comments on commit c0683b7

Please sign in to comment.