Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Port to WASI by adding a check for getrlimit #921

Merged
merged 2 commits into from
May 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions ext/oj/extconf.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
have_func('rb_gc_mark_movable')
have_func('stpcpy')
have_func('pthread_mutex_init')
have_func('getrlimit', 'sys/resource.h')
have_func('rb_enc_interned_str')
have_func('rb_ext_ractor_safe', 'ruby.h')

Expand Down
6 changes: 3 additions & 3 deletions ext/oj/fast.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ typedef struct _doc {
Leaf *where; // points to current location
Leaf where_path[MAX_STACK]; // points to head of path
char *json;
unsigned long size; // number of leaves/branches in the doc
unsigned long size; // number of leaves/branches in the doc
VALUE self;
Batch batches;
struct _batch batch0;
Expand Down Expand Up @@ -573,7 +573,7 @@ static char *read_quoted_value(ParseInfo pi) {
char *h = pi->s; // head
char *t = h; // tail

h++; // skip quote character
h++; // skip quote character
t++;
value = h;
for (; '"' != *h; h++, t++) {
Expand Down Expand Up @@ -765,7 +765,7 @@ static VALUE parse_json(VALUE clas, char *json, bool given) {
pi.s = pi.str;
doc_init(doc);
pi.doc = doc;
#if IS_WINDOWS
#if IS_WINDOWS || !defined(HAVE_GETRLIMIT)
// assume a 1M stack and give half to ruby
pi.stack_min = (void *)((char *)&pi - (512L * 1024L));
#else
Expand Down
4 changes: 2 additions & 2 deletions ext/oj/parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ typedef struct _num {
long double dub;
int64_t fixnum; // holds all digits
uint32_t len;
int16_t div; // 10^div
int16_t div; // 10^div
int16_t exp;
uint8_t shift; // shift of fixnum to get decimal
uint8_t shift; // shift of fixnum to get decimal
bool neg;
bool exp_neg;
// for numbers as strings, reuse buf
Expand Down
2 changes: 1 addition & 1 deletion ext/oj/reader.c
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ int oj_reader_read(Reader reader) {
} else {
shift = reader->pro - reader->head - 1; // leave one character so we can backup one
}
if (0 >= shift) { /* no space left so allocate more */
if (0 >= shift) { /* no space left so allocate more */
const char *old = reader->head;
size_t size = reader->end - reader->head + BUF_PAD;

Expand Down
4 changes: 2 additions & 2 deletions ext/oj/saj.c
Original file line number Diff line number Diff line change
Expand Up @@ -578,7 +578,7 @@ static void saj_parse(VALUE handler, char *json) {
/* initialize parse info */
pi.str = json;
pi.s = json;
#if IS_WINDOWS
#if IS_WINDOWS || !defined(HAVE_GETRLIMIT)
pi.stack_min = (void *)((char *)&obj - (512L * 1024L)); /* assume a 1M stack and give half to ruby */
#else
{
Expand All @@ -587,7 +587,7 @@ static void saj_parse(VALUE handler, char *json) {
if (0 == getrlimit(RLIMIT_STACK, &lim) && RLIM_INFINITY != lim.rlim_cur) {
pi.stack_min = (void *)((char *)&obj - (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 */
pi.stack_min = 0; /* indicates not to check stack limit */
}
}
#endif
Expand Down
Loading