Skip to content

Commit

Permalink
Rename addMacro() and delMacro() to rpmPushMacro() and rpmPopMacro()
Browse files Browse the repository at this point in the history
These are not deprecated at all no matter what the header has been
saying for the past 15+ years, they're used by rpm itself all over
the place as rpmDefineMacro() serves a slightly different purpose
and there's no rpmUndefineMacro() anyway.

Lets make 'em into proper citizens and move them into rpm namespace,
and while at it, call the operations push and pop since that's much
closer to what actually happens.

Finally, add simple wrapper macros to keep external code compilable
while getting the non-namespaced stuff out of ABI.
  • Loading branch information
pmatilai committed Oct 24, 2016
1 parent 34e839b commit 5517d26
Show file tree
Hide file tree
Showing 16 changed files with 59 additions and 56 deletions.
4 changes: 2 additions & 2 deletions build/files.c
Original file line number Diff line number Diff line change
Expand Up @@ -2026,7 +2026,7 @@ static rpmRC readFilesManifest(rpmSpec spec, Package pkg, const char *path)
}

/* XXX unmask %license while parsing files manifest*/
addMacro(spec->macros, "license", NULL, "%%license", RMIL_SPEC);
rpmPushMacro(spec->macros, "license", NULL, "%%license", RMIL_SPEC);

while (fgets(buf, sizeof(buf), fd)) {
if (handleComments(buf))
Expand Down Expand Up @@ -2055,7 +2055,7 @@ static rpmRC readFilesManifest(rpmSpec spec, Package pkg, const char *path)
rc = RPMRC_OK;

exit:
delMacro(NULL, "license");
rpmPopMacro(NULL, "license");
if (fd) fclose(fd);
free(fn);
return rc;
Expand Down
4 changes: 2 additions & 2 deletions build/parseFiles.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ int parseFiles(rpmSpec spec)
};

/* XXX unmask %license while parsing %files */
addMacro(spec->macros, "license", NULL, "%%license", RMIL_SPEC);
rpmPushMacro(spec->macros, "license", NULL, "%%license", RMIL_SPEC);

if ((rc = poptParseArgvString(spec->line, &argc, &argv))) {
rpmlog(RPMLOG_ERR, _("line %d: Error parsing %%files: %s\n"),
Expand Down Expand Up @@ -106,7 +106,7 @@ int parseFiles(rpmSpec spec)
res = nextPart;

exit:
delMacro(NULL, "license");
rpmPopMacro(NULL, "license");
free(argv);
poptFreeContext(optCon);

Expand Down
12 changes: 6 additions & 6 deletions build/parsePreamble.c
Original file line number Diff line number Diff line change
Expand Up @@ -301,11 +301,11 @@ static int addSource(rpmSpec spec, Package pkg, const char *field, rpmTagVal tag

rasprintf(&buf, "%s%d",
(flag & RPMBUILD_ISPATCH) ? "PATCH" : "SOURCE", num);
addMacro(spec->macros, buf, NULL, body, RMIL_SPEC);
rpmPushMacro(spec->macros, buf, NULL, body, RMIL_SPEC);
free(buf);
rasprintf(&buf, "%sURL%d",
(flag & RPMBUILD_ISPATCH) ? "PATCH" : "SOURCE", num);
addMacro(spec->macros, buf, NULL, p->fullSource, RMIL_SPEC);
rpmPushMacro(spec->macros, buf, NULL, p->fullSource, RMIL_SPEC);
free(buf);
#ifdef WITH_LUA
{
Expand Down Expand Up @@ -801,8 +801,8 @@ static rpmRC handlePreambleTag(rpmSpec spec, Package pkg, rpmTagVal tag,
goto exit;
}
macro = NULL;
delMacro(NULL, "_docdir");
addMacro(NULL, "_docdir", NULL, field, RMIL_SPEC);
rpmPopMacro(NULL, "_docdir");
rpmPushMacro(NULL, "_docdir", NULL, field, RMIL_SPEC);
break;
case RPMTAG_EPOCH: {
SINGLE_TOKEN_ONLY;
Expand Down Expand Up @@ -917,7 +917,7 @@ static rpmRC handlePreambleTag(rpmSpec spec, Package pkg, rpmTagVal tag,
}

if (macro)
addMacro(spec->macros, macro, NULL, field, RMIL_SPEC);
rpmPushMacro(spec->macros, macro, NULL, field, RMIL_SPEC);
rc = RPMRC_OK;
exit:
return rc;
Expand Down Expand Up @@ -1155,7 +1155,7 @@ int parsePreamble(rpmSpec spec, int initialPackage)
}
free(spec->buildRoot);
spec->buildRoot = buildRoot;
addMacro(spec->macros, "buildroot", NULL, spec->buildRoot, RMIL_SPEC);
rpmPushMacro(spec->macros, "buildroot", NULL, spec->buildRoot, RMIL_SPEC);
}

/* XXX Skip valid arch check if not building binary package */
Expand Down
2 changes: 1 addition & 1 deletion build/parsePrep.c
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ static int doSetupMacro(rpmSpec spec, const char *line)
buildInPlace = 1;
spec->buildSubdir = NULL;
}
addMacro(spec->macros, "buildsubdir", NULL, spec->buildSubdir, RMIL_SPEC);
rpmPushMacro(spec->macros, "buildsubdir", NULL, spec->buildSubdir, RMIL_SPEC);
if (buildInPlace) {
rc = RPMRC_OK;
goto exit;
Expand Down
8 changes: 4 additions & 4 deletions build/parseSpec.c
Original file line number Diff line number Diff line change
Expand Up @@ -781,8 +781,8 @@ static rpmSpec parseSpec(const char *specFile, rpmSpecFlags flags,
} else {
spec->buildRoot = rpmGetPath("%{?buildroot:%{buildroot}}", NULL);
}
addMacro(NULL, "_docdir", NULL, "%{_defaultdocdir}", RMIL_SPEC);
addMacro(NULL, "_licensedir", NULL, "%{_defaultlicensedir}", RMIL_SPEC);
rpmPushMacro(NULL, "_docdir", NULL, "%{_defaultdocdir}", RMIL_SPEC);
rpmPushMacro(NULL, "_licensedir", NULL, "%{_defaultlicensedir}", RMIL_SPEC);
spec->recursing = recursing;
spec->flags = flags;

Expand Down Expand Up @@ -874,13 +874,13 @@ static rpmSpec parseSpec(const char *specFile, rpmSpecFlags flags,
/* Skip if not arch is not compatible. */
if (!rpmMachineScore(RPM_MACHTABLE_BUILDARCH, spec->BANames[x]))
continue;
addMacro(NULL, "_target_cpu", NULL, spec->BANames[x], RMIL_RPMRC);
rpmPushMacro(NULL, "_target_cpu", NULL, spec->BANames[x], RMIL_RPMRC);
spec->BASpecs[index] = parseSpec(specFile, flags, buildRoot, 1);
if (spec->BASpecs[index] == NULL) {
spec->BACount = index;
goto errxit;
}
delMacro(NULL, "_target_cpu");
rpmPopMacro(NULL, "_target_cpu");
index++;
}

Expand Down
4 changes: 2 additions & 2 deletions lib/poptALL.c
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ static void rpmcliAllArgCallback( poptContext con,
rpmcliConfigured();
if (*arg == '%')
arg++;
delMacro(NULL, arg);
rpmPopMacro(NULL, arg);
break;
case 'E':
rpmcliConfigured();
Expand All @@ -123,7 +123,7 @@ static void rpmcliAllArgCallback( poptContext con,
break;
case POPT_DBPATH:
rpmcliConfigured();
addMacro(NULL, "_dbpath", NULL, arg, RMIL_CMDLINE);
rpmPushMacro(NULL, "_dbpath", NULL, arg, RMIL_CMDLINE);
break;
case POPT_SHOWVERSION:
printVersion(stdout);
Expand Down
4 changes: 2 additions & 2 deletions lib/relocation.c
Original file line number Diff line number Diff line change
Expand Up @@ -383,10 +383,10 @@ static void rpmInstallLoadMacros(Header h, int define)
default:
if (define) {
body = rpmtdFormat(&td, RPMTD_FORMAT_STRING, NULL);
addMacro(NULL, tagm->macroname, NULL, body, -1);
rpmPushMacro(NULL, tagm->macroname, NULL, body, -1);
free(body);
} else {
delMacro(NULL, tagm->macroname);
rpmPopMacro(NULL, tagm->macroname);
}
break;
case RPM_NULL_TYPE:
Expand Down
24 changes: 12 additions & 12 deletions lib/rpmrc.c
Original file line number Diff line number Diff line change
Expand Up @@ -585,7 +585,7 @@ static rpmRC doReadRC(rpmrcCtx ctx, const char * urlfn)
if (option->localize)
*n++ = '_';
strcpy(n, option->name);
addMacro(NULL, name, NULL, val, RMIL_RPMRC);
rpmPushMacro(NULL, name, NULL, val, RMIL_RPMRC);
free(name);
}
rpmSetVarArch(ctx, option->var, val, arch);
Expand Down Expand Up @@ -716,9 +716,9 @@ static rpmRC rpmPlatform(rpmrcCtx ctx, const char * platform)
if (*p != '\0') *p = '\0';
}

addMacro(NULL, "_host_cpu", NULL, cpu, -1);
addMacro(NULL, "_host_vendor", NULL, vendor, -1);
addMacro(NULL, "_host_os", NULL, os, -1);
rpmPushMacro(NULL, "_host_cpu", NULL, cpu, -1);
rpmPushMacro(NULL, "_host_vendor", NULL, vendor, -1);
rpmPushMacro(NULL, "_host_os", NULL, os, -1);

char *plat = rpmExpand("%{_host_cpu}-%{_host_vendor}-%{_host_os}",
(gnu && *gnu ? "-" : NULL), gnu, NULL);
Expand Down Expand Up @@ -1527,19 +1527,19 @@ static void rpmRebuildTargetVars(rpmrcCtx ctx,
* XXX All this macro pokery/jiggery could be achieved by doing a delayed
* rpmInitMacros(NULL, PER-PLATFORM-MACRO-FILE-NAMES);
*/
delMacro(NULL, "_target");
addMacro(NULL, "_target", NULL, ct, RMIL_RPMRC);
delMacro(NULL, "_target_cpu");
addMacro(NULL, "_target_cpu", NULL, ca, RMIL_RPMRC);
delMacro(NULL, "_target_os");
addMacro(NULL, "_target_os", NULL, co, RMIL_RPMRC);
rpmPopMacro(NULL, "_target");
rpmPushMacro(NULL, "_target", NULL, ct, RMIL_RPMRC);
rpmPopMacro(NULL, "_target_cpu");
rpmPushMacro(NULL, "_target_cpu", NULL, ca, RMIL_RPMRC);
rpmPopMacro(NULL, "_target_os");
rpmPushMacro(NULL, "_target_os", NULL, co, RMIL_RPMRC);
/*
* XXX Make sure that per-arch optflags is initialized correctly.
*/
{ const char *optflags = rpmGetVarArch(ctx, RPMVAR_OPTFLAGS, ca);
if (optflags != NULL) {
delMacro(NULL, "optflags");
addMacro(NULL, "optflags", NULL, optflags, RMIL_RPMRC);
rpmPopMacro(NULL, "optflags");
rpmPushMacro(NULL, "optflags", NULL, optflags, RMIL_RPMRC);
}
}

Expand Down
4 changes: 2 additions & 2 deletions python/rpmmacro-py.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ rpmmacro_AddMacro(PyObject * self, PyObject * args, PyObject * kwds)
&name, &val))
return NULL;

addMacro(NULL, name, NULL, val, -1);
rpmPushMacro(NULL, name, NULL, val, -1);

Py_RETURN_NONE;
}
Expand All @@ -28,7 +28,7 @@ rpmmacro_DelMacro(PyObject * self, PyObject * args, PyObject * kwds)
if (!PyArg_ParseTupleAndKeywords(args, kwds, "s:DelMacro", kwlist, &name))
return NULL;

delMacro(NULL, name);
rpmPopMacro(NULL, name);

Py_RETURN_NONE;
}
Expand Down
4 changes: 2 additions & 2 deletions python/rpmmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -150,10 +150,10 @@ static PyObject * setInterruptSafety(PyObject * self, PyObject * args, PyObject

static PyMethodDef rpmModuleMethods[] = {
{ "addMacro", (PyCFunction) rpmmacro_AddMacro, METH_VARARGS|METH_KEYWORDS,
"addMacro(macro, value)\n"
"rpmPushMacro(macro, value)\n"
},
{ "delMacro", (PyCFunction) rpmmacro_DelMacro, METH_VARARGS|METH_KEYWORDS,
"delMacro(macro)\n"
"rpmPopMacro(macro)\n"
},
{ "expandMacro", (PyCFunction) rpmmacro_ExpandMacro, METH_VARARGS|METH_KEYWORDS,
"expandMacro(string, numeric=False) -- expands a string containing macros\n\n"
Expand Down
2 changes: 1 addition & 1 deletion python/spec-py.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
* For example
* \code
* import rpm
* rpm.addMacro("_topdir","/path/to/topdir")
* rpm.rpmPushMacro("_topdir","/path/to/topdir")
* s=rpm.spec("foo.spec")
* print s.prep()
* \endcode
Expand Down
4 changes: 2 additions & 2 deletions rpmbuild.c
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,7 @@ static int buildForTarget(rpmts ts, const char * arg, BTA_t ba)
/* Override default BUILD value for _builddir */
if (buildInPlace) {
char *cwd = rpmGetCwd();
addMacro(NULL, "_builddir", NULL, cwd, 0);
rpmPushMacro(NULL, "_builddir", NULL, cwd, 0);
free(cwd);
}

Expand Down Expand Up @@ -459,7 +459,7 @@ static int buildForTarget(rpmts ts, const char * arg, BTA_t ba)
dir = xstrdup(arg);
}
srcdir = dirname(dir);
addMacro(NULL, "_sourcedir", NULL, srcdir, RMIL_TARBALL);
rpmPushMacro(NULL, "_sourcedir", NULL, srcdir, RMIL_TARBALL);
free(dir);
} else {
specFile = xstrdup(arg);
Expand Down
4 changes: 2 additions & 2 deletions rpmio/macro.c
Original file line number Diff line number Diff line change
Expand Up @@ -1498,15 +1498,15 @@ rpmDumpMacroTable(rpmMacroContext mc, FILE * fp)
rpmmctxRelease(mc);
}

void addMacro(rpmMacroContext mc,
void rpmPushMacro(rpmMacroContext mc,
const char * n, const char * o, const char * b, int level)
{
mc = rpmmctxAcquire(mc);
pushMacro(mc, n, o, b, level, ME_NONE);
rpmmctxRelease(mc);
}

void delMacro(rpmMacroContext mc, const char * n)
void rpmPopMacro(rpmMacroContext mc, const char * n)
{
mc = rpmmctxAcquire(mc);
popMacro(mc, n);
Expand Down
13 changes: 8 additions & 5 deletions rpmio/rpmmacro.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ extern const char * macrofiles;
#define RMIL_OLDSPEC -1
#define RMIL_GLOBAL 0

/* Deprecated compatibility wrappers */
#define addMacro(_mc, _n, _o, _b, _l) rpmPushMacro(_mc, _n, _o, _b, _l)
#define delMacro(_mc, _n) rpmPopMacro(_mc, _n)

/** \ingroup rpmmacro
* Print macros to file stream.
* @param mc macro context (NULL uses global context).
Expand All @@ -65,24 +69,23 @@ int rpmExpandMacros (rpmMacroContext mc, const char * sbuf,
char ** obuf, int flags);

/** \ingroup rpmmacro
* Add macro to context.
* @deprecated Use rpmDefineMacro().
* Push macro to context.
* @param mc macro context (NULL uses global context).
* @param n macro name
* @param o macro paramaters
* @param b macro body
* @param level macro recursion level (0 is entry API)
*/
void addMacro (rpmMacroContext mc, const char * n,
void rpmPushMacro (rpmMacroContext mc, const char * n,
const char * o,
const char * b, int level);

/** \ingroup rpmmacro
* Delete macro from context.
* Pop macro from context.
* @param mc macro context (NULL uses global context).
* @param n macro name
*/
void delMacro (rpmMacroContext mc, const char * n);
void rpmPopMacro (rpmMacroContext mc, const char * n);

/** \ingroup rpmmacro
* Define macro in context.
Expand Down
4 changes: 2 additions & 2 deletions rpmsign.c
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ static int doSign(poptContext optCon)
}

if (fileSigningKey) {
addMacro(NULL, "_file_signing_key", NULL, fileSigningKey, RMIL_GLOBAL);
rpmPushMacro(NULL, "_file_signing_key", NULL, fileSigningKey, RMIL_GLOBAL);
}

if (signfiles) {
Expand All @@ -86,7 +86,7 @@ static int doSign(poptContext optCon)
#endif
}

addMacro(NULL, "_file_signing_key_password", NULL,
rpmPushMacro(NULL, "_file_signing_key_password", NULL,
fileSigningKeyPassword, RMIL_CMDLINE);
if (fileSigningKeyPassword) {
memset(fileSigningKeyPassword, 0, strlen(fileSigningKeyPassword));
Expand Down
18 changes: 9 additions & 9 deletions sign/rpmgensig.c
Original file line number Diff line number Diff line change
Expand Up @@ -257,8 +257,8 @@ static int runGPG(sigTarget sigt, const char *sigfile)

namedPipeName = mkTempFifo();

addMacro(NULL, "__plaintext_filename", NULL, namedPipeName, -1);
addMacro(NULL, "__signature_filename", NULL, sigfile, -1);
rpmPushMacro(NULL, "__plaintext_filename", NULL, namedPipeName, -1);
rpmPushMacro(NULL, "__signature_filename", NULL, sigfile, -1);

if (!(pid = fork())) {
char *const *av;
Expand All @@ -279,8 +279,8 @@ static int runGPG(sigTarget sigt, const char *sigfile)
_exit(EXIT_FAILURE);
}

delMacro(NULL, "__plaintext_filename");
delMacro(NULL, "__signature_filename");
rpmPopMacro(NULL, "__plaintext_filename");
rpmPopMacro(NULL, "__signature_filename");

fnamedPipe = Fopen(namedPipeName, "w");
if (!fnamedPipe) {
Expand Down Expand Up @@ -521,7 +521,7 @@ static rpmRC replaceSigDigests(FD_t fd, const char *rpm, Header *sigp,
}

/* Set reserved space to 0 */
addMacro(NULL, "__gpg_reserved_space", NULL, 0, RMIL_GLOBAL);
rpmPushMacro(NULL, "__gpg_reserved_space", NULL, 0, RMIL_GLOBAL);

/* Replace old digests in sigh */
rc = rpmGenerateSignature(SHA1, MD5, sigTargetSize, archiveSize, fd);
Expand Down Expand Up @@ -872,22 +872,22 @@ int rpmPkgSign(const char *path, const struct rpmSignArgs * args)
if (args->hashalgo) {
char *algo = NULL;
rasprintf(&algo, "%d", args->hashalgo);
addMacro(NULL, "_gpg_digest_algo", NULL, algo, RMIL_GLOBAL);
rpmPushMacro(NULL, "_gpg_digest_algo", NULL, algo, RMIL_GLOBAL);
free(algo);
}
if (args->keyid) {
addMacro(NULL, "_gpg_name", NULL, args->keyid, RMIL_GLOBAL);
rpmPushMacro(NULL, "_gpg_name", NULL, args->keyid, RMIL_GLOBAL);
}
}

rc = rpmSign(path, 0, args ? args->signfiles : 0);

if (args) {
if (args->hashalgo) {
delMacro(NULL, "_gpg_digest_algo");
rpmPopMacro(NULL, "_gpg_digest_algo");
}
if (args->keyid) {
delMacro(NULL, "_gpg_name");
rpmPopMacro(NULL, "_gpg_name");
}
}

Expand Down

0 comments on commit 5517d26

Please sign in to comment.