Bug 4220
Summary: | macro parameter numbers have wrong offset - rpm-3.0.2 | ||
---|---|---|---|
Product: | [Retired] Red Hat Linux | Reporter: | benedict |
Component: | rpm | Assignee: | Jeff Johnson <jbj> |
Status: | CLOSED CURRENTRELEASE | QA Contact: | |
Severity: | medium | Docs Contact: | |
Priority: | medium | ||
Version: | 6.0 | ||
Target Milestone: | --- | ||
Target Release: | --- | ||
Hardware: | All | ||
OS: | Linux | ||
Whiteboard: | |||
Fixed In Version: | Doc Type: | Bug Fix | |
Doc Text: | Story Points: | --- | |
Clone Of: | Environment: | ||
Last Closed: | 1999-07-30 21:20:01 UTC | Type: | --- |
Regression: | --- | Mount Type: | --- |
Documentation: | --- | CRM: | |
Verified Versions: | Category: | --- | |
oVirt Team: | --- | RHEL 7.3 requirements from Atomic Host: | |
Cloudforms Team: | --- | Target Upstream Version: | |
Embargoed: |
Description
benedict
1999-07-27 12:54:59 UTC
This works for me. I'll put the spec file snippet and output in attached email to avoid line wrap in bugzilla. On a linux box running rpm-3.0-6.0 the snippet works as intended. However, on Solaris2.7, HPUX10.20, and Irix6.5 boxes, running rpm-3.0.2, it fails. What platform are you using rpm on? Try this: %define testmacro() echo %0 ; echo %1 ; echo %* ; echo %#; echo %{#} %testmacro a b c %testmacro a b %testmacro a %testmacro on a linux box, it expands to echo testmacro ; echo a ; echo a b c ; echo #; echo 4 echo testmacro ; echo a ; echo a b ; echo #; echo 3 echo testmacro ; echo a ; echo a ; echo #; echo 2 echo %0 ; echo %1 ; echo ; echo #; echo %{#} That's hardly correct, either. 1) %# isn't expanded 2) %{#} is not 'the number of arguments' as docs/macros says 3) when no args are present, grabArgs isn't called at all and even %0 is not set. The problem lies in the code in lib/macro.c assigning to optind you are not supposed to do so. The following patch makes my unix boxes do the same as the linux box: --- rpm-3.0.2.orig/lib/macro.c Fri Jul 2 23:14:17 1999 +++ rpm-3.0.2/lib/macro.c Thu Jul 29 11:57:29 1999 @@ -590,6 +590,7 @@ const char **optv; int opte; int c; + int saveoptind; /* Copy macro name as argv[0] */ argc = 0; @@ -649,7 +650,7 @@ opts = me->opts; /* First count number of options ... */ - optind = 0; + saveoptind = optind; optc = 0; optc++; /* XXX count argv[0] too */ while((c = getopt(argc, (char **)argv, opts)) != -1) { @@ -668,7 +669,7 @@ optv[opte] = NULL; /* ... and finally define option macros. */ - optind = 0; + optind = saveoptind; optc = 0; optc++; /* XXX count optv[0] */ while((c = getopt(argc, (char **)argv, opts)) != -1) { Except for the expansion of %1 (which returns %1 not "") when given no parameters, these problems are fixed. Thanks *very* much for digging into the optind problem on non-linux platforms. Thanks for the fix. I'm looking forward to get it in 3.0.3 As for your comment: I think %1 *should* return %1 when there are no parameter, that is very logical. Otherwise, by generalisation, %4 should return "" when there are less than 4 parameters etc, and that doesn't sound right to me. BTW: I think bugzilla is good for tracking error reports, but I miss this kind of information on the rpm-list - have you guys considered making some kind of cross-posting, so everyone on the rpm-list are aware of bugs posted in bugzilla? Um, %1 is going to expand to the outre context's arg1 if ther are nested conetxts's but I'll deal with that when the time comes. Bugzilla is *way* too noisy to blindly copy onto rpm-list. Besides, I'd rather leave rpm-list for discussions rather than bugs. You can always add yourself to the CC list if you want notification of bug changes. You might think about requesting automatic notification for any rpm bug by filing a request for enhancement against bugzilla. That feature has been discussed already ... Thanks again for the patch. |