1
0
Fork 0
mirror of git://git.psyced.org/git/psyced synced 2024-08-15 03:25:10 +00:00

float would only last for one more year.. we have to use strings for

bignum action
This commit is contained in:
psyc://psyced.org/~lynX 2009-06-16 20:07:03 +02:00
parent b22f2e8b9b
commit e1da3b144b
2 changed files with 27 additions and 13 deletions

View file

@ -527,9 +527,7 @@ PROTECTED mixed nextObject() {
if ((b >= '0' && b <= '9') || b == '.' || b == '-' || b == '+') { if ((b >= '0' && b <= '9') || b == '.' || b == '-' || b == '+') {
int a; float b_; string c_; int a; float b_; string c_;
sscanf(s, "%d%s", a, c_); sscanf(s, "%d%s", a, c_);
// some values of json ints exceed the limits of MAX_INT, in that case we need to use float -lynX if ((c_ && sizeof(c_))) {
// maybe it is more efficient, if we used float in all cases then
if ((c_ && sizeof(c_)) || (a && s != to_string(a))) {
#ifdef __PIKE__ #ifdef __PIKE__
sscanf(s, "%f", b_); sscanf(s, "%f", b_);
#else #else
@ -537,6 +535,18 @@ PROTECTED mixed nextObject() {
#endif #endif
return b_; return b_;
} }
if (!a || s != to_string(a)) {
// some values of json ints exceed the limits of MAX_INT.
// in that case we tried to use float, but rendering floats
// will produce something like 2.17734e+09 instead of just
// a long integer. we have to return a string here, and risk
// to run into runtime errors. we should probably stop trying
// to convert json integers into ints in the first place.
// javascript and lpc just aren't compatible. do we have a
// bignum package for ldmud?
P3(("Warning: JSON integer too big. Returning %O as string.\n", s))
return s;
}
else return a; else return a;
} }
if (s == "") { if (s == "") {

View file

@ -5,7 +5,7 @@
#include <net.h> #include <net.h>
persistent float lastid; persistent mixed lastid;
volatile object feed; volatile object feed;
@ -37,15 +37,20 @@ parse(string body, mapping headers) {
"[_source] received an empty structure."); "[_source] received an empty structure.");
return; return;
} }
// this used to fail on MAX_INT turning the ints to negative.. interestingly // this used to fail on MAX_INT turning the ints to negative.. it would work for
// it works out of the box now that i convert this to float. funny to run into // a while longer using floats, but since floating point mantissa in lpc is only
// such a weird problem only after months of usage, but if twitter never resets // 32 bits wide, it's just a question of time until we hit that roof again (when
// its packet ids, that's where you end up.. bignums! // status_id reaches 4294967296). so let's try strings instead. funny to run into
if (wurst[0]["id"] <= lastid) { // such a weird problem only after years that twitter has been in existence.
P1(("%O received %d old updates (id0 %O <= lastid %O).\n", ME, sizeof(wurst), wurst[0]["id"], lastid)) // twitterific may have run into the same problem, as the timing of its breakdown
// matches ours.
if (lastid && wurst[0]["id"] <= lastid) {
P1(("%O received %d old updates (id0 %O <= lastid %O).\n",
ME, sizeof(wurst), wurst[0]["id"], lastid))
return; return;
} }
lastid = wurst[0]["id"]; lastid = wurst[0]["id"];
P1(("%O -- new lastid %O\n", ME, lastid))
save_object(DATA_PATH "twitter"); save_object(DATA_PATH "twitter");
for (i=sizeof(wurst)-1; i>=0; i--) { for (i=sizeof(wurst)-1; i>=0; i--) {
d = wurst[i]; d = wurst[i];
@ -111,8 +116,7 @@ fetch() {
// twitter ignores since_id if count is present. stupid. // twitter ignores since_id if count is present. stupid.
feed -> fetch("http://twitter.com/statuses/friends_timeline.json?" feed -> fetch("http://twitter.com/statuses/friends_timeline.json?"
// +( lastid? ("since_id="+ lastid) : "count=23")); // +( lastid? ("since_id="+ lastid) : "count=23"));
"count="+( lastid? ("23&since_id="+ "count="+( lastid? ("23&since_id="+ lastid) : "23"));
sprintf("%F", lastid)) : "23"));
} }
create() { create() {