Commit Graph

213 Commits

Author SHA1 Message Date
Panu Matilainen ecfece7ec0 Add support for nested Lua macro expansion (RhBug:490740)
- Lift the printbuffer accounting out of rpmlua into a struct of
  its own (Funny thing, this looks a whole lot like the macro
  expansion buffer and Good Ole StringBuf Brothers ... Boys ... Mam.
  Unify them one of these days maybe)
- Replace the simplistic on/off printbuffer with a stack of buffers,
  fixup the lone caller to use the new internal push/pop API.
2011-05-24 20:41:38 +03:00
Panu Matilainen 0b36a1f18e Eliminate bogus ferror() checks
- fopen() returns NULL on errors, never an opened stream with error
  flag set. These are leftovers from past where rpmio fd was used
  instead of FILE and probably the checks were bogus even back then too.
2011-05-18 10:59:54 +03:00
Michael Schroeder f4c79584d0 Always copy macro source when expanding it
- A macro can undefine itself, and unless we grab a copy of it we'll
  end up accessing already freed memory. Fixes a regression from
  commit ebc4ceaaeb which assumed
  a copy is not always needed.

Signed-off-by: Panu Matilainen <pmatilai@redhat.com>
2011-05-18 09:10:11 +03:00
Ville Skyttä e254f9b9d4 Add lrzip support.
Signed-off-by: Panu Matilainen <pmatilai@redhat.com>
2011-04-29 08:49:05 +03:00
Ville Skyttä bcad08867d Add lzip support.
Signed-off-by: Panu Matilainen <pmatilai@redhat.com>
2011-04-29 08:48:56 +03:00
Panu Matilainen 1817ac020e Plug memory leaks on macro definition error cases 2011-03-17 15:35:42 +02:00
Panu Matilainen 131d082aab Handle non-terminated substrings centrally in expandMacro()
- expandMacro() is big and ugly already, but handling the non-terminated
  substrings there once and for all avoids having to ping-pong recurse
  through couple of helpers to get there.
2010-09-27 17:15:15 +03:00
Panu Matilainen b1dbdf50af Dynamic expansion buffer reallocation for lua macros too 2010-09-27 16:32:15 +03:00
Panu Matilainen 800a1daa23 Whoops, fix typo/thinko from commit dc258bac41 2010-09-27 16:22:38 +03:00
Panu Matilainen 46f32d25ce Eliminate the internal in-place-expansion buffer limitation
- Return the dynamically allocated expansion buffer to callers from
  expandU(), except using a slightly less cryptic expandThis() name
  for it now. Also deal with non-terminated strings centrally in
  expandThis() instead of doing alloc + copy to terminate in every caller.
2010-09-27 16:10:36 +03:00
Panu Matilainen d8777387db Simplify / sanitize expandU() a bit
- Instead of saving and restoring the bits we'll mess with, just
  make a temporary expansion state struct with non-buffer state
  copied from "parent".
2010-09-27 14:55:12 +03:00
Panu Matilainen 49f99b8656 Dynamically reallocate macro expansion buffer (ticket #45)
- Eliminate the underlying limitation of macro expansion limit by
  growing the buffer as needed when adding characters to it. This
  doesn't fix the entire issue yet however: expandU() and expandMacros()
  are still limited to caller-specified buffer size, and output
  from lua-macros isn't dynamically resized. One step at a time...
2010-09-27 14:55:12 +03:00
Panu Matilainen 61a3fc4523 Let expandMacro() allocate its own buffer
- More pre-requisites for dynamic buffer resizing, callers have no
  clue how much expandMacro() is going to need.
2010-09-27 14:55:12 +03:00
Panu Matilainen dc258bac41 Track current expansion point via distance to buffer start
- Supposedly no functional changes, just paving way for dynamic
  buffer resizing which is impossible when accessing pointers directly.
2010-09-27 14:55:12 +03:00
Panu Matilainen 568ba0d242 Push the macro buffer size limit down by one level
- Turn expandMacros() into a wrapper around internal doExpandMacros()
  which returns the expanded string in a newly allocated buffer, use
  the internal version for rpmExpand() too.
2010-09-27 14:55:12 +03:00
Panu Matilainen a931202422 Eliminate unused spec field from macro expansion state struct 2010-09-27 14:55:11 +03:00
Panu Matilainen 8082eb48db Avoid calloc() in macro findEntry()
- It's just the macro name we're grabbing here, that ought to fit
  on stack comfortably enough.
2010-09-27 14:55:11 +03:00
Panu Matilainen ebc4ceaaeb Avoid unnecessary round-trip through expandT() where possible
- In the cases where expandT() was called with strlen(source) we can
  now just bypass it and call expandMacro() directly, avoiding an
  unnecessary string copy.
2010-09-27 14:55:11 +03:00
Panu Matilainen ccba5236a0 Use function arguments to pass, duh, arguments into functions. Duh.
- No functional changes, just eliminating mindless save-and-restore
  ping-pong through macro expansion state struct.
2010-09-27 14:55:11 +03:00
Jindrich Novy 7f220202f2 Redirect macro stack backtrace printing to debug log. 2010-07-13 13:35:22 +02:00
Jindrich Novy 60be56e317 Fix cryptic macro evaluation error message (RhBug:613010) 2010-07-13 13:34:05 +02:00
Panu Matilainen c16cde7a4d Revert "Always free locally defined macros when they go out of scope"
- the "fix" breaks seemingly legitimate use in fedora font package
  macros, possibly some funky interaction with %{lua: } macros or something
- this reverts commit f895acd285.
2010-01-07 12:04:53 +02:00
Panu Matilainen f895acd285 Always free locally defined macros when they go out of scope
- Prior to this, local defines in constructs like %{!?foo: %define foo bar}
  would remain defined until a parametrized macro gets called, causing
  obscure and confusing errors in specs such as RhBug:551971 and countless
  others. Use of %global is now always required for such constructs.
2010-01-04 12:45:18 +02:00
Panu Matilainen 2c5ea0b188 Remove -98 vintage ifdef'ed dead code 2010-01-04 10:52:22 +02:00
Panu Matilainen 2553ca2fe3 Move getopt() portability fiddles out of system.h
- only macro.c needs, no point polluting includes everywhere
2009-12-23 14:02:19 +02:00
Ville Skyttä 1892984f02 Decompress lzma files with xz. 2009-10-06 10:47:36 +03:00
Panu Matilainen f634253b32 Eliminate unused variable 2009-09-07 17:50:43 +03:00
Panu Matilainen f4b39519d3 Replace equal/not equal uses of str[n]cmp() with rstreq[n] in io code 2009-08-31 11:15:16 +03:00
Panu Matilainen 3d63df6220 Handle XZ in %uncompress macro
- should've been in commit 8078d0ba24
2009-03-27 14:11:43 +02:00
Panu Matilainen 2d2bda29c1 Add built-in %getconfdir macro for getting rpmConfigDir() value
- define %_rpmconfigdir via %getconfdir in the main macro config, this
  avoids it getting lost on macro reloads as happens when building
  several packages at once
2009-03-27 14:01:47 +02:00
Panu Matilainen 947ad7acb3 Add getenv macro, use instead of $(echo $HOME) for defauls
- inspired by http://lists.rpm.org/pipermail/rpm-maint/2009-January/002332.html
2009-01-16 09:09:40 +02:00
Panu Matilainen da83a562e1 Add function to retrieve rpm config base directory
- one-shot to determine configuration base directory path from
  RPM_CONFIGDIR environement or build-time default
- rpmfileutil is a bit strange place, this would really belong to librpm
  but Lua initialization needs the path so...
2008-11-22 18:06:31 +02:00
Panu Matilainen 49c515179a Permit tab as whitespace between macro arguments (rhbz#467567)
- another dumb regression from macro handling cleanups
2008-10-19 01:53:03 +03:00
Panu Matilainen 9f85707825 Macro argument handling regression regression (rhbz#461180)
- commit f366011c42 is too simplistic and
  broke other stuff in turn...
2008-09-11 16:56:50 +03:00
Panu Matilainen 1d9b4d00d7 Make rpmExpand() smarter wrt memory allocations
- precalculate unexpanded size and allocate enough for that plus MACROBUFSIZ
  for expansion
- typical allocation is way smaller than what gets allocated "just in case",
  calculate expanded size and realloc to actual size to avoid wasting
  memory
2008-07-16 10:52:33 +03:00
Panu Matilainen 889f9f5b41 Eliminate another unnecessary temp variable
- do all the copying inside a loop
2008-07-16 10:33:57 +03:00
Panu Matilainen 1b19676027 Eliminate unnecessary variable
- leftover from static buffer times..
2008-07-16 10:24:05 +03:00
Panu Matilainen f366011c42 Macro argument handling regression (rhbz#455333)
- expandMacro() wants the next \0 character to be returned, which might
  or might not be the same as lastc passed to grabArgs()
- use memcpy() instead of memmove() for the copy, the areas can't overlap
2008-07-16 09:40:10 +03:00
Panu Matilainen af9518dce2 Use correct type for strlen() 2008-06-10 10:02:52 +03:00
Panu Matilainen 485d195488 Plug memleak in macro doFoo() 2008-04-29 17:39:02 +03:00
Panu Matilainen 9ae911eefe Further simplify rpmInitMacros()
- Use argvSplit() for splitting the macro path to components instead of
  manual pointer-parsery.
- If URL's are to be supported or accepted at all (previous code attempted
  to skip them), ':' is a very poor delimiter character.
2008-04-19 16:42:56 +03:00
Panu Matilainen e336146a9e Use argvFree() to free, well, an argv, instead of manual freeing 2008-04-19 16:04:11 +03:00
Panu Matilainen 601b4d0e6a Avoid entirely silly rpmio FD_t use
- rdcl() converts to FILE internally anyway, might as well use fopen()
  to begin with...
2008-04-18 16:14:15 +03:00
Panu Matilainen 38a975b157 Remove unnecessary xstrdup() of dynamically allocated buffer
- leftover from when target buffer was static...
2008-04-18 15:39:07 +03:00
Panu Matilainen 94e64fec18 Cosmetics: group operations more logically... 2008-04-18 15:15:05 +03:00
Panu Matilainen 2d8a27ed16 Simplify macro option + argument processing
- eliminate ninja-voodoo pointer-hackery parsing, replace argvSplit() +
  argvJoin() and friends
- eliminate static sized buffers from the processing
2008-04-18 14:59:03 +03:00
Panu Matilainen 02939c15fa More accurate filtering of .rpmnew etc when reading macros
- strstr() can give false positives, use rpmFileHasSuffix() instead
2008-04-17 17:33:30 +03:00
Panu Matilainen 3c1126b2a5 Missing decompression arguments for bzip in uncompress macro 2008-04-04 15:52:52 +03:00
Panu Matilainen 7ddab3ab8d Dead code removal (macro stuff) 2008-03-31 10:44:23 +03:00
Panu Matilainen c908277be2 Minimal namespacing for locale-insensitive x*() string functions 2008-03-18 09:10:13 +02:00