Skip to content

Commit

Permalink
hard coding windows stack size for limit checks
Browse files Browse the repository at this point in the history
  • Loading branch information
ohler55 committed Oct 15, 2012
1 parent 1b22cf5 commit a6b48f1
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 10 deletions.
17 changes: 12 additions & 5 deletions ext/oj/fast.c
Expand Up @@ -834,7 +834,6 @@ parse_json(VALUE clas, char *json, int given, int allocated) {
VALUE result = Qnil;
Doc doc;
int ex = 0;
struct rlimit lim;

if (given) {
doc = ALLOCA_N(struct _Doc, 1);
Expand All @@ -845,10 +844,18 @@ parse_json(VALUE clas, char *json, int given, int allocated) {
pi.s = pi.str;
doc_init(doc);
pi.doc = doc;
if (0 == getrlimit(RLIMIT_STACK, &lim)) {
pi.stack_min = (uint64_t)&lim - (lim.rlim_cur / 4 * 3); // let 3/4ths of the stack be used only
} else {
pi.stack_min = 0; // indicates not to check stack limit
{
#if IS_WINDOWS
pi.stack_min = (uint64_t)&pi - (512 * 1024); // assume a 1M stack and give half to ruby
#else
struct rlimit lim;

if (0 == getrlimit(RLIMIT_STACK, &lim)) {
pi.stack_min = (uint64_t)&pi - (lim.rlim_cur / 4 * 3); // let 3/4ths of the stack be used only
#endif
} else {
pi.stack_min = 0; // indicates not to check stack limit
}
}
// last arg is free func void* func(void*)
doc->self = rb_data_object_alloc(clas, doc, 0, free_doc_cb);
Expand Down
17 changes: 12 additions & 5 deletions ext/oj/load.c
Expand Up @@ -1005,7 +1005,6 @@ VALUE
oj_parse(char *json, Options options) {
VALUE obj;
struct _ParseInfo pi;
struct rlimit lim;

if (0 == json) {
raise_error("Invalid arg, xml string can not be null", json, 0);
Expand All @@ -1018,10 +1017,18 @@ oj_parse(char *json, Options options) {
pi.circ_array = circ_array_new();
}
pi.options = options;
if (0 == getrlimit(RLIMIT_STACK, &lim)) {
pi.stack_min = (uint64_t)&lim - (lim.rlim_cur / 4 * 3); // let 3/4ths of the stack be used only
} else {
pi.stack_min = 0; // indicates not to check stack limit
{
#if IS_WINDOWS
pi.stack_min = (uint64_t)&obj - (512 * 1024); // assume a 1M stack and give half to ruby
#else
struct rlimit lim;

if (0 == getrlimit(RLIMIT_STACK, &lim)) {
pi.stack_min = (uint64_t)&obj - (lim.rlim_cur / 4 * 3); // let 3/4ths of the stack be used only
#endif
} else {
pi.stack_min = 0; // indicates not to check stack limit
}
}
obj = read_next(&pi, 0);
if (Yes == options->circular) {
Expand Down

0 comments on commit a6b48f1

Please sign in to comment.