Commit Graph

77 Commits

Author SHA1 Message Date
Florian Festi 2f04d42f95 Add python doc strings for rpm.fi 2014-12-18 12:50:31 +01:00
Panu Matilainen 8da9919885 Python 3 compatibility wrt python fi.FindFN()
- Strings from rpm are byte arrays from python 3 perspective
2013-12-13 16:20:30 +02:00
Panu Matilainen 56c8977e18 Allow a shared pool with python rpmds and rpmfi objects
- Add an optional pool argument to python rpmds and rpmfi constructors
  to allow using a shared string pool from python too
2013-12-13 15:47:50 +02:00
Panu Matilainen 68a24e72b0 Use the pool-aware constructors for rpmfi and all rpmds types
- Doesn't actually change anything yet as pool is always NULL
2013-12-13 15:43:39 +02:00
Florian Festi 8fcab70a47 Python binding for rpm.fi.FindFN() 2013-10-29 15:11:59 +01:00
Florian Festi a4a05bd259 Python bindings for rpmfiFLinks() 2013-10-29 15:11:58 +01:00
Panu Matilainen 06a2f1269b Don't assume rpmfiNew() always succeeds
- Add NULL checks and add/adjust comments where appropriate.
- The remaining callers should handle NULL fi gracefully if not
  entirely correctly: rpmfiFC() returns 0 on NULL fi, so these
  callers just see the erronous file info set as "no files" case.
  Something to fine-tune later...
2012-01-28 17:07:42 +02:00
David Malcolm 59378e5220 fix the signatures of the METH_NOARGS callbacks
Various Python method callbacks have signatures of the form:

  static PyObject *
  foo(some_object_subclass *obj)

and are registered within the PyMethodDef tables with the METH_NOARGS
flag [1], with a cast to (PyCFunction) due to the PyObject/subclass
mismatch.

However, such callbacks do receive two arguments: they are invoked with
a signature of this form:

  static PyObject *
  foo(some_object_subclass *obj, PyObject *ignored)

The CPython interpreter only uses METH_NOARGS to allow it to pass NULL as the
second parameter: there are still two parameters.  The dispatch code is in
Python's Python/ceval.c:call_function:

            if (flags & METH_NOARGS && na == 0) {
                C_TRACE(x, (*meth)(self,NULL));
            }

The fact that this has ever worked may be a coincidence of the
platform/compiler's calling conventions, and I don't think it's guaranteed to
keep working.

[1] http://docs.python.org/c-api/structures.html#METH_NOARGS

Signed-off-by: Ales Kozumplik <akozumpl@redhat.com>
2012-01-02 08:39:39 +01:00
Panu Matilainen a71a7981cc Revert the ds, ts, fi and spec python object creation commits
- Hasty push-finger syndrom, while its not exactly plain wrong to
  do things this way, it doesn't really make sense for these types
  either. Python's own file object permits reinitialization though,
  so leaving rpm.fd() the way it is now.
- This reverts the following commits:
  d056df28c3
  3f77c3146d
  7214b2e0a2
  dc50fb2863
2011-07-06 08:16:12 +03:00
Panu Matilainen 7214b2e0a2 Fix/sanitize rpm.fi python object creation a bit
- Move all actual initialization work into tp_init, permit
  reinitialization without leaking and use PyType_GenericNew for
  tp_new, eliminate internal rpmfi_Wrap() use.
  There's one user for rpmfi_Wrap() in rpmte-py.c which needs fixing
  later...
- Remove unused fiFromFi() helper function
2011-07-01 13:37:48 +03:00
Panu Matilainen 99f9c67ad4 Python bindings dont need our debug.h for anything 2011-03-09 15:06:11 +02:00
Panu Matilainen e8f777b69d Switch python bindings to use rpm(Dbi)TagVal as appropriate
- None of these are true enum uses as the value typically originates
  from python integers etc.
2010-10-22 11:57:38 +03:00
Panu Matilainen 16f9d7f4dc Remove unnecessary (cmpfunc) casts from our type objects
- cmpfunc is no more in Python 3 and casting NULL to anything makes
  little sense anyhow
2009-10-28 16:35:32 +02:00
David Malcolm 4b8e0ebde6 Generalize type object initialization to work with both Python 2.* and 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
2009-10-19 11:02:13 +03:00
David Malcolm 7b51c4a1eb Generalize access to ob_type so that they work with both Python 2.* and 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.
2009-10-19 10:50:24 +03:00
Panu Matilainen dc6946e72e Revert explicit PyErr_NoMemory() returns to just returning NULL
- 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
2009-10-09 11:57:46 +03:00
Panu Matilainen 55e6a4b905 Dont leak memory from rpm.fi() methods
- Py_BuildValue() always copies the data mallocing here is just wrong
2009-10-05 17:23:34 +03:00
Panu Matilainen b53f599596 Turn hdrGetHeader() into argument parsing converter interface 2009-09-30 12:11:43 +03:00
Panu Matilainen 2507ab6797 Enable subtyping on the rest of our type-objects
- not very useful atm as various places return hard-wired built-in types
2009-09-24 13:57:55 +03:00
Panu Matilainen df40d9b27b Eliminate all custom tp_free() type methods
- tp_free()'s purpose is only to free up the memory used by the python
  object structure, cleaning up our own allocations belongs to tp_dealloc()
2009-09-24 13:40:44 +03:00
Panu Matilainen 74c1040dbc Call (sub)type tp_free from destructors
- more preliminaries for subtyping
- remove pointless NULL checks
2009-09-24 12:52:32 +03:00
Panu Matilainen 36ada6c116 Make object allocation type agnostic
- pass (sub)type down to wrappers
- call subtype tp_alloc() instead of PyObject_New()
- preliminaries for allowing subtyping
2009-09-24 11:42:17 +03:00
Panu Matilainen 282efb6d4c Turn tagNumFromPyObject() into an object converter interface
- permits direct validation and conversion from arg parsing
2009-09-23 12:28:47 +03:00
Panu Matilainen c29492242c Remove tp_print methods from all rpm-python objects
- these violate the intended use of tp_print, python docs state
  "A type should never implement tp_print in a way that produces
  different output than tp_repr or tp_str would."
2009-09-23 10:44:41 +03:00
Panu Matilainen 6bbc19fb22 Lose the debug junk from python bindings 2009-09-23 10:39:40 +03:00
Panu Matilainen f0c3985a77 Make fiFromHeader() static inside header-py, deprecate 2009-09-23 10:19:46 +03:00
Panu Matilainen 39d79f9142 Rename python system.h for disambiguation 2009-09-22 23:02:47 +03:00
Panu Matilainen 14d5aaedcb Lose the empty doxygen markers
- nothing wrong with comments but empty comment placeholders
  are not exactly useful
2009-09-22 22:42:06 +03:00
Panu Matilainen 864220c441 Put some consistency to python object creation
- all type object creation goes through foo_Wrap() which handle OOM
  and all type specific initialization
2009-09-22 21:53:21 +03:00
Panu Matilainen ed557bbcf0 Make all python object creation wrappers return PyObject pointers
- this way the only place where casts are needed are in the wrapper itself
2009-09-22 21:24:55 +03:00
Panu Matilainen 0cb5de3fc0 Lose unnecessary next() methods
- python adds next() methods for objects supporting iterators
2009-09-22 20:50:41 +03:00
Panu Matilainen 0793b2cf23 All rpm-python iterators are self-iterators, just use PyObject_SelfIter 2009-09-22 20:20:07 +03:00
Panu Matilainen 07adc4e0d1 Simplify fiFromHeader()
- just call the fi object, no need to manually redo all this stuff
2009-09-22 19:44:59 +03:00
Panu Matilainen da74188fa6 Sanitize python object -> tag number exception handling
- raise exception in tagNumFromPyObject(), not in 12 different callers
- check against RPMTAG_NOT_FOUND consistently instead of -1 and whatnot
- unknown tags are value, not key or type errors
2009-09-22 19:19:02 +03:00
Panu Matilainen fdc62b3dec Move allocations out of rpmfi object init method
- tp_init can be called several times, allocating from there leaks memory
- tp_init gets called automatically on object creation, dont call manually
2009-09-22 18:50:32 +03:00
Panu Matilainen 96a1b0a681 Use Py_RETURN_NONE macro for returning None everywhere 2009-09-22 17:49:53 +03:00
Panu Matilainen 43f585fced Eliminate unnecessary custom object allocation functions
- these are just calling python defaults, no point at all...
2009-09-22 17:33:07 +03:00
Panu Matilainen ca6591e86c Use generic python get/set attribute functions directly where appropriate
- no point in wrapping all this stuff in our own functions
2009-09-22 17:27:44 +03:00
Panu Matilainen ae1fd3fa47 Make the python object structures opaque 2009-09-22 16:47:07 +03:00
Panu Matilainen ae1e7d8389 We dont support ancient python versions... 2009-09-22 16:28:58 +03:00
Panu Matilainen 7dc709b517 Make rpmfiFSize() return rpm_loff_t type, fixup callers
- Internally file sizes are still stored as 32bit, going to 64bit wouldn't
  make much sense (would only waste memory for nothing) as long as we're
  bound by cpio's 32bit per-file limit. Being "64bit ready" for filesizes
  doesn't hurt anything though...
2008-06-12 16:41:31 +03:00
Panu Matilainen fe5ff47868 Don't leak memory on python fi.Digest() calls 2008-06-03 09:09:00 +03:00
Panu Matilainen b9c69d1bab rpmfiFDigestHex() instead of manual hex conversion
- showQueryPackage() and python rpmfi_Digest() at least..
2008-06-02 09:50:48 +03:00
Panu Matilainen e1724c3d4a On a second thought, rename rpmfiDigest() to rpmfiFDigest() for consistency
- it operates on current file of the set, not on the entire set so while
  changing API, name it similarly to other things that operate on current file
2008-06-02 09:50:48 +03:00
Panu Matilainen fad3c10b90 Add fi.Digest() method to python bindings
- use same code for creating the digest object on iteration and method call
- fi.MD5() left around as alias for fi.Digest(), dunno if that's the best
  thing to do but it's just a python string so returned size isn't that
  critical..
2008-06-02 09:50:48 +03:00
Panu Matilainen d2ef49038a Include rpmtypes.h first instead of rpmtag.h everywhere 2008-05-21 15:59:39 +03:00
Panu Matilainen 5ef8b53108 Eliminate several copy-paste hex converters, use pgpHexStr() instead 2008-04-07 14:04:00 +03:00
Panu Matilainen d718b12f5b Mass convert (back) to rpmTag as it's usable everywhere now
- cast away a few cases where the enum usage causes ridiculous amount
  of compiler warnings from unhandled switch-cases
2008-02-05 17:42:19 +02:00
Panu Matilainen eb5dc35c19 Include spring-cleaning
- put some consistency into include ordering
- everything (apart from bits missed ;) is now ordered like this
  1. "system.h"
  2. other system includes
  3. rpm public headers
  4. rpm private headers
  5. "debug.h"
2008-01-30 17:05:29 +02:00
Panu Matilainen 99faa2735b rpmlib.h mass eviction
- explicitly include what's really needed instead
- document remaining uses
2008-01-30 13:53:51 +02:00