| 1 |
|
| 2 |
1.x vs 2.x |
| 3 |
========== |
| 4 |
|
| 5 |
Allocation |
| 6 |
---------- |
| 7 |
|
| 8 |
Allocation mechanisms has been revised. All objects are still allocated from a private storage (called heap), |
| 9 |
but now the heap serves properly aligned memory chunks. Implementation of the heap is (hopefully) platform |
| 10 |
independent, so all ``ARM_COMPLIANT`` checks has been removed. Some details work differently on 32/64-bit |
| 11 |
machines, this distinction seems inevitable. Allocation related code has been moved to ``util/utilmem*.c`` files. |
| 12 |
|
| 13 |
[There are actually 3 different allocators - **heap**, **stock**, and **pool** - each of which has 4 variants |
| 14 |
for 1, 2, 4 and 8 bytes alignment. So far ``pplib`` uses only the **heap**, but I want to have this part |
| 15 |
in a single place for a while. More notes about allocators in ``utilmemallc.h``.] |
| 16 |
|
| 17 |
``pplib`` uses two heaps: |
| 18 |
|
| 19 |
* bytes heap - providing 2-bytes aligned memory chunks for byte data |
| 20 |
* structures heap - providing 8-bytes aligned chunks for all structures |
| 21 |
|
| 22 |
2-bytes alignment of byte data is caused by implementation details / limits, ``pplib`` doesn't make a use of it |
| 23 |
(could be unaligned as well). All the structures are stored in 8-bytes aligned chunks on both 32 and 64-bit machines |
| 24 |
(in some structures we use ``double`` and ``int64_t``, which generally needs 8-bytes). |
| 25 |
|
| 26 |
Strings And Names |
| 27 |
----------------- |
| 28 |
|
| 29 |
So far, both ``ppname`` and ``ppstring`` were aliases to ``char *`` with an extra structure hidden just below |
| 30 |
the data address. The idea was to make a string or name usable whenever chars array can, at the cost of some |
| 31 |
pointers trickery. Both names and strings keep an information about pdf-encoded data, as well as plain bytes data. |
| 32 |
I implemented this feature once ``pplib 1.0`` was almost done, and to avoid a revolution, I made that with yet |
| 33 |
another trick. This all was dirty and caused lots of alignment issues. |
| 34 |
|
| 35 |
Now ``ppstring`` and ``ppname`` are **structures**, keeping data and size members, pretty much like ``pparray``:: |
| 36 |
|
| 37 |
struct ppname { |
| 38 |
ppbyte *data; |
| 39 |
size_t size; |
| 40 |
ppname *alterego; |
| 41 |
int flags; |
| 42 |
}; |
| 43 |
|
| 44 |
struct ppstring { |
| 45 |
ppbyte *data; |
| 46 |
size_t size; |
| 47 |
ppstring *alterego; |
| 48 |
int flags; |
| 49 |
}; |
| 50 |
|
| 51 |
Data member is a pointer to (2-bytes aligned) bytes array -- ``ppbyte *``. ``ppbyte`` is an alias to ``char``. |
| 52 |
``pplib`` makes no assumptions about ``ppbyte`` signedness. [I'd prefer to have ``uint8_t``, but better |
| 53 |
keep that in sync with ``ppdict_get_*`` suite, which accepts ``char *``. Using ``"string literals"`` |
| 54 |
with ``ppdict_get`` function is the most common case, I guess.] |
| 55 |
|
| 56 |
``ppname_size()`` and ``ppstring_size() `` now have |
| 57 |
trivial ``ppname_data()`` and ``ppstring_data()`` counterparts:: |
| 58 |
|
| 59 |
#define ppname_size(name) ((name)->size) |
| 60 |
#define ppname_data(name) ((name)->data) |
| 61 |
|
| 62 |
#define ppstring_size(string) ((string)->size) |
| 63 |
#define ppstring_data(string) ((string)->data) |
| 64 |
|
| 65 |
Switching between encoded / decoded variants is made via explicit ``alterego`` member. If encoded and decoded forms |
| 66 |
are identical, then ``self->alfterego == self`` (never NULL). Helper functions for that:: |
| 67 |
|
| 68 |
PPAPI ppname * ppname_decoded (ppname *name); |
| 69 |
PPAPI ppname * ppname_encoded (ppname *name); |
| 70 |
|
| 71 |
PPAPI ppbyte * ppname_decoded_data (ppname *name); |
| 72 |
PPAPI ppbyte * ppname_encoded_data (ppname *name); |
| 73 |
|
| 74 |
PPAPI ppstring * ppstring_decoded (ppstring *string); |
| 75 |
PPAPI ppstring * ppstring_encoded (ppstring *string); |
| 76 |
|
| 77 |
PPAPI ppbyte * ppstring_decoded_data (ppstring *string); |
| 78 |
PPAPI ppbyte * ppstring_encoded_data (ppstring *string); |
| 79 |
|
| 80 |
Since ``ppname`` and ``ppstring`` are now structures, all API functions returning name/string or taking name/string |
| 81 |
as an argument, now take **a pointer to name/string**. Watch out for ``ppdict_get_*`` functions suite. They still accept |
| 82 |
``const char *`` key as an argument, but ``ppname`` type can no longer be used there:: |
| 83 |
|
| 84 |
ppname key; |
| 85 |
ppdict_get_something(dict, key); // wrong |
| 86 |
ppdict_get_something(dict, key.data); // ok |
| 87 |
|
| 88 |
ppname *pkey; |
| 89 |
ppdict_get_something(dict, (const char *)pkey); // wrong |
| 90 |
ppdict_get_something(dict, pkey->data); // ok |
| 91 |
|
| 92 |
Consequently, functions / macros that used pointer to ``ppname`` (``ppdict_first()`` / ``ppdict_next()``), |
| 93 |
now needs ``ppname **pname``. |
| 94 |
|
| 95 |
Cleanups |
| 96 |
-------- |
| 97 |
|
| 98 |
Some of unused utils were removed. There is still some code in utils part that is not used by the library, |
| 99 |
but I need this tollbox in many other places and don't want to maintain two versions. |
| 100 |
|
| 101 |
Some unification in integer types; ``size_t`` seems to be the best choice for and integer representing machine |
| 102 |
word (``unsigned long`` is not long enough on windows), less utils dependencies, less compiler warnings. |
| 103 |
|