joshiayush / stlc Goto Github PK
View Code? Open in Web Editor NEWStandard Template Library for C.
License: BSD 3-Clause "New" or "Revised" License
Standard Template Library for C.
License: BSD 3-Clause "New" or "Revised" License
Current version of Map
modifiers for example, MapInsert() do not re-allocate the Map
instance if the size of the map becomes equal or greater than the capacity.
Using macro JSON_LIST_ADD_VAL()
doesn't add the given data to the given JSON
list instance which is clearly visible in the test CJSONTest.JSONStringifiyTestWithAListAndAObjectInstance.
After debugging it many times what I observed is, steps upto the following macro are properly doing their job,
But when the control flow returns from the following function, everything just seems to be wiped out.
Pointed out a serious bug when testing stringstream_alloc()
function which takes in an argument of const size_t
i.e., the number of char
sized blocks to allocate in the free store.
stringstream
instance has a length
and a capacity
instance in it which tells the number of characters a stringstream
instance currently holds plus the number of characters it can hold respectively.
The way the capacity is calculated is broken, at least in here, as the spectrum the length
is in is (0, +18446744073709551615)
but the capacity
will break as the length
exceeds by 2147483648
(which is the decimal value of binary 10000000000000000000000000000000
) which means the length
will increase but at a certain point the following code will wipe out the entire memory the capacity
instance has.
while (capacity < length)
capacity <<= 1;
Leaving a simple Python list resize routine in case you want to start contributing to cjson
.
typedef struct {
PyObject_HEAD
Py_ssize_t ob_size;
/* Vector of pointers to list elements. list[0] is ob_item[0], etc. */
PyObject **ob_item;
/* ob_item contains space for 'allocated' elements. The number
* currently in use is ob_size.
* Invariants:
* 0 <= ob_size <= allocated
* len(list) == ob_size
* ob_item == NULL implies ob_size == allocated == 0
*/
Py_ssize_t allocated;
} PyListObject;
As you can see PyListObject
has a corresponding attribute allocated
to capacity
which is later calculated the following way:
new_allocated = (newsize >> 3) + (newsize < 9 ? 3 : 6);
new_allocated += newsize;
where the newsize
is the requested size for stringstream
instance and the new_allocated
is the new capacity
for the stringstream
instance.
Contributions are welcome!
Currently function StringStreamWriteFile()
is not compact properly which you can clearly see in the below lines of code:
What we want to achieve is a more compact version of this function by replacing the if
ladder into a single if
clause:
void StringStreamWriteFile(StringStream* const sstream, FILE* const file,
size_t begin, size_t end) {
if ((sstream == NULL || file == NULL) || (begin >= sstream->length) || !end ||
(end < begin))
return;
if (end > sstream->length)
end = sstream->length;
fwrite(sstream->data + begin, sizeof(char), end - begin, file);
}
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.