Use the new tag type/return type getters everywhere
- Instead of masking and bitfiddling all over the place, use the new getters to get the exact (enum) type directly. rpmTagGetType() is now unused within rpm but leaving around for backwards compatibility
This commit is contained in:
parent
bf4a383892
commit
be488096e0
|
@ -156,12 +156,13 @@ static int headerPutType(Header h, rpmTag tag, rpmTagType reqtype,
|
|||
rpm_constdata_t data, rpm_count_t size)
|
||||
{
|
||||
struct rpmtd_s td;
|
||||
rpmTagType type = rpmTagGetType(tag);
|
||||
rpmTagType type = rpmTagGetTagType(tag);
|
||||
rpmTagReturnType retype = rpmTagGetReturnType(tag);
|
||||
headerPutFlags flags = HEADERPUT_APPEND;
|
||||
int valid = 1;
|
||||
|
||||
/* Basic sanity checks: type must match and there must be data to put */
|
||||
if ((type & RPM_MASK_TYPE) != reqtype
|
||||
if (type != reqtype
|
||||
|| size < 1 || data == NULL || h == NULL) {
|
||||
valid = 0;
|
||||
}
|
||||
|
@ -170,9 +171,9 @@ static int headerPutType(Header h, rpmTag tag, rpmTagType reqtype,
|
|||
* Non-array types can't be appended to. Binary types use size
|
||||
* for data length, for other non-array types size must be 1.
|
||||
*/
|
||||
if ((type & RPM_MASK_RETURN_TYPE) != RPM_ARRAY_RETURN_TYPE) {
|
||||
if (retype != RPM_ARRAY_RETURN_TYPE) {
|
||||
flags = HEADERPUT_DEFAULT;
|
||||
if ((type & RPM_MASK_TYPE) != RPM_BIN_TYPE && size != 1) {
|
||||
if (type != RPM_BIN_TYPE && size != 1) {
|
||||
valid = 0;
|
||||
}
|
||||
}
|
||||
|
@ -180,7 +181,7 @@ static int headerPutType(Header h, rpmTag tag, rpmTagType reqtype,
|
|||
if (valid) {
|
||||
rpmtdReset(&td);
|
||||
td.tag = tag;
|
||||
td.type = type & RPM_MASK_TYPE;
|
||||
td.type = type;
|
||||
td.data = (void *) data;
|
||||
td.count = size;
|
||||
|
||||
|
@ -192,7 +193,7 @@ static int headerPutType(Header h, rpmTag tag, rpmTagType reqtype,
|
|||
|
||||
int headerPutString(Header h, rpmTag tag, const char *val)
|
||||
{
|
||||
rpmTagType type = rpmTagGetType(tag) & RPM_MASK_TYPE;
|
||||
rpmTagType type = rpmTagGetTagType(tag);
|
||||
const void *sptr = NULL;
|
||||
|
||||
/* string arrays expect char **, arrange that */
|
||||
|
|
|
@ -253,7 +253,7 @@ void rpmDisplayQueryTags(FILE * fp)
|
|||
sname = tname + strlen("RPMTAG_");
|
||||
if (rpmIsVerbose()) {
|
||||
rpmTag tag = rpmTagGetValue(sname);
|
||||
rpmTagType type = rpmTagGetType(tag) & RPM_MASK_TYPE;
|
||||
rpmTagType type = rpmTagGetTagType(tag);
|
||||
fprintf(fp, "%-20s %6d", sname, tag);
|
||||
if (type > RPM_NULL_TYPE && type <= RPM_MAX_TYPE)
|
||||
fprintf(fp, " %s", tagTypeNames[type]);
|
||||
|
|
32
lib/rpmtd.c
32
lib/rpmtd.c
|
@ -264,7 +264,7 @@ char *rpmtdFormat(rpmtd td, rpmtdFormats fmt, const char *errmsg)
|
|||
int rpmtdSetTag(rpmtd td, rpmTag tag)
|
||||
{
|
||||
assert(td != NULL);
|
||||
rpmTagType newtype = rpmTagGetType(tag);
|
||||
rpmTagType newtype = rpmTagGetTagType(tag);
|
||||
int rc = 0;
|
||||
|
||||
/*
|
||||
|
@ -276,13 +276,13 @@ int rpmtdSetTag(rpmtd td, rpmTag tag)
|
|||
goto exit;
|
||||
|
||||
if (td->data || td->count > 0) {
|
||||
if (rpmTagGetType(td->tag) != rpmTagGetType(tag)) {
|
||||
if (rpmTagGetTagType(td->tag) != rpmTagGetTagType(tag)) {
|
||||
goto exit;
|
||||
}
|
||||
}
|
||||
|
||||
td->tag = tag;
|
||||
td->type = newtype & RPM_MASK_TYPE;
|
||||
td->type = newtype;
|
||||
rc = 1;
|
||||
|
||||
exit:
|
||||
|
@ -307,8 +307,8 @@ static inline int rpmtdSet(rpmtd td, rpmTag tag, rpmTagType type,
|
|||
|
||||
int rpmtdFromUint8(rpmtd td, rpmTag tag, uint8_t *data, rpm_count_t count)
|
||||
{
|
||||
rpmTagType type = rpmTagGetType(tag) & RPM_MASK_TYPE;
|
||||
rpmTagReturnType retype = rpmTagGetType(tag) & RPM_MASK_RETURN_TYPE;
|
||||
rpmTagType type = rpmTagGetTagType(tag);
|
||||
rpmTagReturnType retype = rpmTagGetReturnType(tag);
|
||||
|
||||
if (count < 1)
|
||||
return 0;
|
||||
|
@ -334,8 +334,8 @@ int rpmtdFromUint8(rpmtd td, rpmTag tag, uint8_t *data, rpm_count_t count)
|
|||
|
||||
int rpmtdFromUint16(rpmtd td, rpmTag tag, uint16_t *data, rpm_count_t count)
|
||||
{
|
||||
rpmTagType type = rpmTagGetType(tag) & RPM_MASK_TYPE;
|
||||
rpmTagReturnType retype = rpmTagGetType(tag) & RPM_MASK_RETURN_TYPE;
|
||||
rpmTagType type = rpmTagGetTagType(tag);
|
||||
rpmTagReturnType retype = rpmTagGetReturnType(tag);
|
||||
if (type != RPM_INT16_TYPE || count < 1)
|
||||
return 0;
|
||||
if (retype != RPM_ARRAY_RETURN_TYPE && count > 1)
|
||||
|
@ -346,8 +346,8 @@ int rpmtdFromUint16(rpmtd td, rpmTag tag, uint16_t *data, rpm_count_t count)
|
|||
|
||||
int rpmtdFromUint32(rpmtd td, rpmTag tag, uint32_t *data, rpm_count_t count)
|
||||
{
|
||||
rpmTagType type = rpmTagGetType(tag) & RPM_MASK_TYPE;
|
||||
rpmTagReturnType retype = rpmTagGetType(tag) & RPM_MASK_RETURN_TYPE;
|
||||
rpmTagType type = rpmTagGetTagType(tag);
|
||||
rpmTagReturnType retype = rpmTagGetReturnType(tag);
|
||||
if (type != RPM_INT32_TYPE || count < 1)
|
||||
return 0;
|
||||
if (retype != RPM_ARRAY_RETURN_TYPE && count > 1)
|
||||
|
@ -358,8 +358,8 @@ int rpmtdFromUint32(rpmtd td, rpmTag tag, uint32_t *data, rpm_count_t count)
|
|||
|
||||
int rpmtdFromUint64(rpmtd td, rpmTag tag, uint64_t *data, rpm_count_t count)
|
||||
{
|
||||
rpmTagType type = rpmTagGetType(tag) & RPM_MASK_TYPE;
|
||||
rpmTagReturnType retype = rpmTagGetType(tag) & RPM_MASK_RETURN_TYPE;
|
||||
rpmTagType type = rpmTagGetTagType(tag);
|
||||
rpmTagReturnType retype = rpmTagGetReturnType(tag);
|
||||
if (type != RPM_INT64_TYPE || count < 1)
|
||||
return 0;
|
||||
if (retype != RPM_ARRAY_RETURN_TYPE && count > 1)
|
||||
|
@ -370,7 +370,7 @@ int rpmtdFromUint64(rpmtd td, rpmTag tag, uint64_t *data, rpm_count_t count)
|
|||
|
||||
int rpmtdFromString(rpmtd td, rpmTag tag, const char *data)
|
||||
{
|
||||
rpmTagType type = rpmTagGetType(tag) & RPM_MASK_TYPE;
|
||||
rpmTagType type = rpmTagGetTagType(tag);
|
||||
int rc = 0;
|
||||
|
||||
if (type == RPM_STRING_TYPE) {
|
||||
|
@ -384,7 +384,7 @@ int rpmtdFromString(rpmtd td, rpmTag tag, const char *data)
|
|||
|
||||
int rpmtdFromStringArray(rpmtd td, rpmTag tag, const char **data, rpm_count_t count)
|
||||
{
|
||||
rpmTagType type = rpmTagGetType(tag) & RPM_MASK_TYPE;
|
||||
rpmTagType type = rpmTagGetTagType(tag);
|
||||
if (type != RPM_STRING_ARRAY_TYPE || count < 1)
|
||||
return 0;
|
||||
if (type == RPM_STRING_TYPE && count != 1)
|
||||
|
@ -396,7 +396,7 @@ int rpmtdFromStringArray(rpmtd td, rpmTag tag, const char **data, rpm_count_t co
|
|||
int rpmtdFromArgv(rpmtd td, rpmTag tag, ARGV_t argv)
|
||||
{
|
||||
int count = argvCount(argv);
|
||||
rpmTagType type = rpmTagGetType(tag) & RPM_MASK_TYPE;
|
||||
rpmTagType type = rpmTagGetTagType(tag);
|
||||
|
||||
if (type != RPM_STRING_ARRAY_TYPE || count < 1)
|
||||
return 0;
|
||||
|
@ -407,8 +407,8 @@ int rpmtdFromArgv(rpmtd td, rpmTag tag, ARGV_t argv)
|
|||
int rpmtdFromArgi(rpmtd td, rpmTag tag, ARGI_t argi)
|
||||
{
|
||||
int count = argiCount(argi);
|
||||
rpmTagType type = rpmTagGetType(tag) & RPM_MASK_TYPE;
|
||||
rpmTagReturnType retype = rpmTagGetType(tag) & RPM_MASK_RETURN_TYPE;
|
||||
rpmTagType type = rpmTagGetTagType(tag);
|
||||
rpmTagReturnType retype = rpmTagGetReturnType(tag);
|
||||
|
||||
if (type != RPM_INT32_TYPE || retype != RPM_ARRAY_RETURN_TYPE || count < 1)
|
||||
return 0;
|
||||
|
|
|
@ -292,7 +292,7 @@ rpmTagClass rpmTagTypeGetClass(rpmTagType type)
|
|||
|
||||
rpmTagClass rpmTagGetClass(rpmTag tag)
|
||||
{
|
||||
return rpmTagTypeGetClass(rpmTagGetType(tag));
|
||||
return rpmTagTypeGetClass(rpmTagGetTagType(tag));
|
||||
}
|
||||
|
||||
rpmTag rpmTagGetValue(const char * tagstr)
|
||||
|
|
|
@ -485,10 +485,9 @@ static int validItem(rpmTagClass class, PyObject *item)
|
|||
return rc;
|
||||
}
|
||||
|
||||
static int validData(rpmTag tag, rpmTagType type, PyObject *value)
|
||||
static int validData(rpmTag tag, rpmTagType type, rpmTagReturnType retype, PyObject *value)
|
||||
{
|
||||
rpmTagClass class = rpmTagGetClass(tag);
|
||||
rpmTagReturnType retype = (type & RPM_MASK_RETURN_TYPE);
|
||||
int valid = 1;
|
||||
|
||||
if (retype == RPM_SCALAR_RETURN_TYPE) {
|
||||
|
@ -513,7 +512,7 @@ static int hdrAppendItem(Header h, rpmTag tag, rpmTagType type, PyObject *item)
|
|||
{
|
||||
int rc = 0;
|
||||
|
||||
switch ((type & RPM_MASK_TYPE)) {
|
||||
switch (type) {
|
||||
case RPM_I18NSTRING_TYPE: /* XXX this needs to be handled separately */
|
||||
case RPM_STRING_TYPE:
|
||||
case RPM_STRING_ARRAY_TYPE: {
|
||||
|
@ -552,8 +551,8 @@ static int hdrAppendItem(Header h, rpmTag tag, rpmTagType type, PyObject *item)
|
|||
|
||||
static int hdrPutTag(Header h, rpmTag tag, PyObject *value)
|
||||
{
|
||||
rpmTagType type = rpmTagGetType(tag);
|
||||
rpmTagReturnType retype = (type & RPM_MASK_RETURN_TYPE);
|
||||
rpmTagType type = rpmTagGetTagType(tag);
|
||||
rpmTagReturnType retype = rpmTagGetReturnType(tag);
|
||||
int rc = 0;
|
||||
|
||||
/* XXX this isn't really right (i18n strings etc) but for now ... */
|
||||
|
@ -563,7 +562,7 @@ static int hdrPutTag(Header h, rpmTag tag, PyObject *value)
|
|||
}
|
||||
|
||||
/* validate all data before trying to insert */
|
||||
if (!validData(tag, type, value)) {
|
||||
if (!validData(tag, type, retype, value)) {
|
||||
PyErr_SetString(PyExc_TypeError, "invalid type for tag");
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -35,8 +35,7 @@ static PyObject * rpmtd_ItemAsPyobj(rpmtd td, rpmTagClass class)
|
|||
PyObject *rpmtd_AsPyobj(rpmtd td)
|
||||
{
|
||||
PyObject *res = NULL;
|
||||
rpmTagType type = rpmTagGetType(td->tag);
|
||||
int array = ((type & RPM_MASK_RETURN_TYPE) == RPM_ARRAY_RETURN_TYPE);
|
||||
int array = (rpmTagGetReturnType(td->tag) == RPM_ARRAY_RETURN_TYPE);
|
||||
rpmTagClass class = rpmtdClass(td);
|
||||
|
||||
if (!array && rpmtdCount(td) < 1) {
|
||||
|
|
Loading…
Reference in New Issue