Skip to content

Commit

Permalink
Copy symbol backing (#306)
Browse files Browse the repository at this point in the history
  • Loading branch information
ohler55 committed Jan 16, 2023
1 parent cb8f1af commit bf71563
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 8 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

All changes to the Ox gem are documented here. Releases follow semantic versioning.

## [2.14.13] - 2023-01-16

### Fixed

- Fixed the intern cache to handle symbol memory changes.

## [2.14.12] - 2022-12-27

### Fixed
Expand Down
2 changes: 1 addition & 1 deletion ext/ox/hash_load.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ mark_value(PInfo pi, VALUE val) {
pi->mark_size = MARK_INC;
} else if (pi->mark_size <= pi->mark_cnt) {
pi->mark_size += MARK_INC;
pi->marked = REALLOC_N(pi->marked, VALUE, pi->mark_size);
REALLOC_N(pi->marked, VALUE, pi->mark_size);
}
pi->marked[pi->mark_cnt] = val;
pi->mark_cnt++;
Expand Down
10 changes: 6 additions & 4 deletions ext/ox/sax.c
Original file line number Diff line number Diff line change
Expand Up @@ -762,6 +762,7 @@ static char read_comment(SaxDrive dr) {
*/
static char read_element_start(SaxDrive dr) {
const char *ename = 0;
size_t nlen;
volatile VALUE name = Qnil;
char c;
int closed;
Expand Down Expand Up @@ -790,6 +791,7 @@ static char read_element_start(SaxDrive dr) {
0 == strcasecmp("html", dr->buf.str)) {
dr->options.hints = ox_hints_html();
}
nlen = dr->buf.tail - dr->buf.str - 1;
if (NULL != dr->options.hints) {
hint_clear_empty(dr);
h = ox_hint_find(dr->options.hints, dr->buf.str);
Expand All @@ -810,7 +812,7 @@ static char read_element_start(SaxDrive dr) {
if (rb_respond_to(dr->handler, ox_abort_id)) {
VALUE args[1];

args[0] = str2sym(dr, dr->buf.str, dr->buf.tail - dr->buf.str - 1, NULL);
args[0] = str2sym(dr, dr->buf.str, nlen, NULL);
rb_funcall2(dr->handler, ox_abort_id, 1, args);
}
dr->abort = true;
Expand Down Expand Up @@ -861,7 +863,7 @@ static char read_element_start(SaxDrive dr) {
}
}
}
name = str2sym(dr, dr->buf.str, dr->buf.tail - dr->buf.str - 1, &ename);
name = str2sym(dr, dr->buf.str, nlen, &ename);
if (dr->has_start_element && 0 >= dr->blocked &&
(NULL == h || ActiveOverlay == h->overlay || NestOverlay == h->overlay)) {
VALUE args[1];
Expand Down Expand Up @@ -894,15 +896,15 @@ static char read_element_start(SaxDrive dr) {
} else if (stackless) {
end_element_cb(dr, name, pos, line, col, h);
} else if (NULL != h && h->jump) {
stack_push(&dr->stack, ename, name, h);
stack_push(&dr->stack, ename, nlen, name, h);
if ('>' != c) {
ox_sax_drive_error(dr, WRONG_CHAR "element not closed");
return c;
}
read_jump(dr, h->name);
return '<';
} else {
stack_push(&dr->stack, ename, name, h);
stack_push(&dr->stack, ename, nlen, name, h);
}
if ('>' != c) {
ox_sax_drive_error(dr, WRONG_CHAR "element not closed");
Expand Down
18 changes: 16 additions & 2 deletions ext/ox/sax_stack.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,16 @@
#ifndef OX_SAX_STACK_H
#define OX_SAX_STACK_H

#include <stdlib.h>

#include "intern.h"
#include "sax_hint.h"

#define STACK_INC 32
#define NV_BUF_MAX 64

typedef struct _nv {
char name_buf[NV_BUF_MAX];
const char *name;
VALUE val;
int childCnt;
Expand Down Expand Up @@ -44,7 +49,7 @@ stack_cleanup(NStack stack) {
}

inline static void
stack_push(NStack stack, const char *name, VALUE val, Hint hint) {
stack_push(NStack stack, const char *name, size_t nlen, VALUE val, Hint hint) {
if (stack->end <= stack->tail) {
size_t len = stack->end - stack->head;
size_t toff = stack->tail - stack->head;
Expand All @@ -58,7 +63,13 @@ stack_push(NStack stack, const char *name, VALUE val, Hint hint) {
stack->tail = stack->head + toff;
stack->end = stack->head + len + STACK_INC;
}
stack->tail->name = name;
if (NV_BUF_MAX <= nlen) {
stack->tail->name = ox_strndup(name, nlen);
} else {
strncpy(stack->tail->name_buf, name, nlen);
stack->tail->name_buf[nlen] = '\0';
stack->tail->name = stack->tail->name_buf;
}
stack->tail->val = val;
stack->tail->hint = hint;
stack->tail->childCnt = 0;
Expand All @@ -77,6 +88,9 @@ inline static Nv
stack_pop(NStack stack) {
if (stack->head < stack->tail) {
stack->tail--;
if (stack->tail->name != stack->tail->name_buf) {
free((char*)(stack->tail->name));
}
return stack->tail;
}
return 0;
Expand Down
2 changes: 1 addition & 1 deletion lib/ox/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

module Ox
# Current version of the module.
VERSION = '2.14.12'
VERSION = '2.14.13'
end

0 comments on commit bf71563

Please sign in to comment.