Age | Commit message (Collapse) | Author | Files | Lines |
|
|
|
- Various places within the bindings use PyArg_ParseTuple[AndKeywords] to
extract (char*) string arguments. These are pointers to the internal
representation of a PyStringObject, and shouldn't be modified, hence
it's safest to explicitly mark these values as (const char*), rather
than just (char*).
Signed-off-by: Ales Kozumplik <akozumpl@redhat.com>
|
|
|
|
- Various functions in the Python bindings construct lists of objects, but
assume that all calls succeed. Each of these could segfault under
low-memory conditions: if the PyList_New() call fails,
PyList_Append(NULL, item ) will segfault. Similarly, although
Py_List_Append(list, NULL) is safe, Py_DECREF(NULL) will segfault.
Signed-off-by: Ales Kozumplik <akozumpl@redhat.com>
|
|
- Various functions in the Python bindings have expressions of the form:
PyObject_Call(callable,
Py_BuildValue(fmtstring, ...), NULL);
This leaks memory for the case when Py_BuildValue succeeds (it returns a
new reference, which is never freed; PyObject_Call doesn't steal the
reference): the argument tuple and all of its components will not be
freed (until the process exits).
Signed-off-by: Ales Kozumplik <akozumpl@redhat.com>
|
|
|
|
- rpm.header.new() will still keep accepting PyCObject for now in case a
client library depends on this.
- involves macro trickery to make rpm buildable against python 2.6 still.
|
|
|
|
- Tags as header attributes seemed like a nice idea at the time... but
has been a PITA due to side-effects it causes, such as breaking
getattr() use for "capability testing", eg:
>>> h2 = copy.deepcopy(h)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib64/python2.7/copy.py", line 172, in deepcopy
copier = getattr(x, "__deepcopy__", None)
ValueError: unknown header tag
- Since we can't really go removing the brainded feature (somebody might
actually be using it) try harder to fix it: if its not an actual
attribute, save the exception we got from PyObject_GenericGetAttr()
and if its not a valid tag either, restore the original exception.
This allows cases like the above __deepcopy__ to work properly.
|
|
- This allows header objects to be pickled and also copied correctly
with python's copy.copy()
- Split the header to string-conversion into a separate helper function,
used by the now largely unnecessary unload() method and __reduce__().
|
|
|
|
|
|
- While this /nearly/ qualifies for enum, places like python
argument converting will not be able to produce "true enum" values.
So dont even try.
|
|
- None of these are true enum uses as the value typically originates
from python integers etc.
|
|
|
|
- Eliminate uses of "class" which is a reserved keyword in C++
|
|
- 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
|
|
- PyList_Append() bumps the object reference count, callers need to
explicitly decref them... oops :)
|
|
- this is how python built-in dictionary works, be consistent with that
- also avoids having to decide what to do with rpm.td type right now...
|
|
|
|
- hdr.fiFromHeader() is just a deprecated backwards compatibility dummy
and doesn't need to pass anything as there were no meaningful
parameters in older versions
|
|
|
|
- no proper i18n string support yet, just the basic types
- basic data type validation only, no overflow checking for integer types
- for lists, validate all items before trying to insert anything
- duplicate tag creation not permitted
- appending not permitted, only assignment (and deletion already)
- there are probably bugs...
- watch out for librpm bugs when passed incomplete headers, ugh
|
|
|
|
- Python 3 removed has_key() from dictionaries, as the 'in' way is the
way of the future support that from the start (has_key() is not in
any released rpm version so its safe to remove)
|
|
- this is available through tag extension now, no point having a
separate method for it
|
|
- needed for generating header objects from other extension modules &
might be handy in some other cases too
- patently type-unsafe but as long as python doesn't provide a better
way, not really our headache
|
|
- Avoids another Python 3 incompatibility as it doesn't have tp_compare
anymore
- We could add a compatible tp_richcompare, but comparisons like
'if h1 < h2: do foo' are highly ambiguous, callers are better of
using explicit rpm.versinCompare(h1, h2) instead
|
|
|
|
- In Python 3 everything is unicode, forcing each and every caller to
convert manually is a bit much.
|
|
- In Python 2.6 PyBytes is just an alias for PyString, Python 3.0
removed PyString entirely
- Add compatibility defines for Python < 2.6
- Based on David Malcolm's Python 3.x efforts
|
|
- rpmSingleHeaderFromFD() and hdrLoad() are now implemented in python,
declarations accidentally left here
- make rpmMergeHeaders() static, nothing outside header-py.c needs
|
|
Python 3.*
The layout of PyVarObject changed between python 2 and python 3, and this leads
to the existing code for all of the various PyTypeObject initializers failing to
compile with python 3
Change the way we initialize these structs to use PyVarObject_HEAD_INIT directly,
rather than merely PyObject_HEAD_INIT, so that it compiles cleanly with both major
versions of Python
|
|
Python 3.*
Python 2's various object structs use macros to implement common fields at the top of each
struct.
Python 3's objects instead embed a PyObject struct as the first member within the more refined
object structs.
Use the Py_TYPE() macro when accessing ob_type in order to encapsulate this difference.
|
|
- turn rpmfdFromPyObject() into a python-level object converter, add
a separate C-level getter for the fd pointer itself
- take advantage of python refcounting to handle differences between
native vs converted rpm.fd in callers so we can simply decref the
rpmfdFromPyObject() result without having to worry whether it was
converted or not (ie should we close it or not)
|
|
|
|
- for now we only support tag deletion and assigning rpmtd objects, limiting
this to copying data from other headers
|
|
- tp_alloc failing is likely to be OOM but we dont know that for a fact,
and the failing method is responsible for setting the exception
|
|
- either it takes a header + tag, or (name, flags, version) tuple + tag
to generate a single dep
- push rpm.dsSingle() compatibility out to python side
- hdr.dsFromHeader() and hdr.dsOfHeader() no longer need to be in rpmds-py.c
|
|
|
|
- use PyErr_WarnEx() for better control and leave the tracking up to python
- use PendingDeprecationWarning for now
- document the replacing functionality in the deprecation messages
- make hdr.sprintf() just an alias to hdr.format() without deprecating,
at least for now it'd be only a gratuitous incompatible change on python side
|
|
|
|
- avoids whole lotta unnecessary copying of data, we're only interested
in tag numbers here
- dont filter out stuff - python consumers can look at i18n data too
|
|
|
|
|
|
- when generic getattr fails, only try retrieving header tag as attribute
if it's a valid tag
- clear any python errors if generic getattr failed
- split generating a python object from header + tag to an internal helper
|
|
|
|
|
|
|
|
|