这是indexloc提供的服务,不要输入任何密码
Skip to content
Open
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 MANIFEST
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ t/bug/doesnt-stringify.t
t/bug/rt-41141.t
t/bug/rt-49404-double_free.t
t/bug/rt-54167.t
t/escape-special-chars.t
t/json-basic.t
t/json-circular-ref.t
t/json-crlf.t
Expand Down
79 changes: 38 additions & 41 deletions emitter.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
* $Date: 2006-05-09 12:03:50 +0800 (二, 09 5 2006) $
*
* Copyright (C) 2003 why the lucky stiff
*
*
* All Base64 code from Ruby's pack.c.
* Ruby is Copyright (C) 1993-2003 Yukihiro Matsumoto
* Ruby is Copyright (C) 1993-2003 Yukihiro Matsumoto
*/
#include <stdio.h>
#include <string.h>
Expand All @@ -16,7 +16,7 @@

#define DEFAULT_ANCHOR_FORMAT "id%03d"

const unsigned char hex_table[] =
const unsigned char hex_table[] =
"0123456789ABCDEF";
static unsigned char b64_table[] =
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
Expand Down Expand Up @@ -137,13 +137,13 @@ syck_new_emitter()
e->output_handler = NULL;
e->lvl_idx = 0;
e->lvl_capa = ALLOC_CT;
e->levels = S_ALLOC_N( SyckLevel, e->lvl_capa );
e->levels = S_ALLOC_N( SyckLevel, e->lvl_capa );
syck_emitter_reset_levels( e );
e->bonus = NULL;
return e;
}

int
enum st_retval
syck_st_free_anchors( char *key, char *name, char *arg )
{
S_FREE( name );
Expand Down Expand Up @@ -203,7 +203,7 @@ syck_emitter_pop_level( SyckEmitter *e )
free( e->levels[e->lvl_idx].domain );
}

void
void
syck_emitter_add_level( SyckEmitter *e, int len, enum syck_level_status status )
{
ASSERT( e != NULL );
Expand Down Expand Up @@ -295,7 +295,7 @@ syck_emitter_write( SyckEmitter *e, const char *str, long len )
{
syck_emitter_clear( e );
}

/*
* Flush if at end of buffer
*/
Expand Down Expand Up @@ -366,7 +366,7 @@ syck_emit( SyckEmitter *e, st_data_t n )
int indent = 0;
SyckLevel *parent;
SyckLevel *lvl = syck_emitter_current_level( e );

/*
* Determine headers.
*/
Expand Down Expand Up @@ -397,15 +397,15 @@ syck_emit( SyckEmitter *e, st_data_t n )

/* Look for anchor */
if ( e->anchors != NULL &&
st_lookup( e->markers, n, (st_data_t *)&oid ) &&
st_lookup( e->anchors, (st_data_t)oid, (st_data_t *)&anchor_name ) )
st_lookup( e->markers, (char*)n, (char* *)&oid ) &&
st_lookup( e->anchors, (char*)(st_data_t)oid, (char* *)(st_data_t *)&anchor_name ) )
{
if ( e->anchored == NULL )
{
e->anchored = st_init_numtable();
}

if ( ! st_lookup( e->anchored, (st_data_t)anchor_name, 0 ) )
if ( ! st_lookup( e->anchored, (char*)(st_data_t)anchor_name, (char* *)0 ) )
{
char *an = S_ALLOC_N( char, strlen( anchor_name ) + 3 );
sprintf( an, "&%s ", anchor_name );
Expand All @@ -419,7 +419,7 @@ syck_emit( SyckEmitter *e, st_data_t n )
syck_emitter_write( e, an, strlen( anchor_name ) + 2 );
free( an );

st_insert( e->anchored, (st_data_t)anchor_name, 0 );
st_insert( e->anchored, (char*)(st_data_t)anchor_name, 0 );
lvl->anctag = 1;
}
else
Expand Down Expand Up @@ -498,7 +498,7 @@ void syck_emit_tag( SyckEmitter *e, const char *tag, const char *ignore )
lvl->anctag = 1;
}

/*
/*
* Emit a newline and an appropriately spaced indent.
*/
void syck_emit_indent( SyckEmitter *e )
Expand Down Expand Up @@ -582,7 +582,7 @@ syck_scan_scalar( int req_width, char *cursor, long len )
} else if ( len > 1 && cursor[len-2] == '\n' ) {
flags |= SCAN_MANYNL_E;
}
if (
if (
( len > 0 && ( cursor[0] == ' ' || cursor[0] == '\t' ) ) ||
( len > 1 && ( cursor[len-1] == ' ' || cursor[len-1] == '\t' ) )
) {
Expand All @@ -609,7 +609,7 @@ syck_scan_scalar( int req_width, char *cursor, long len )
flags |= SCAN_NEWLINE;
if ( len - i >= 3 && strncmp( &cursor[i+1], "---", 3 ) == 0 )
flags |= SCAN_DOCSEP;
if ( cursor[i+1] == ' ' || cursor[i+1] == '\t' )
if ( cursor[i+1] == ' ' || cursor[i+1] == '\t' )
flags |= SCAN_INDENTED;
if ( req_width > 0 && i - start > req_width )
flags |= SCAN_WIDE;
Expand All @@ -633,12 +633,12 @@ syck_scan_scalar( int req_width, char *cursor, long len )
}
/* remember, if plain collections get implemented, to add nb-plain-flow-char */
else if ( ( cursor[i] == ' ' && cursor[i+1] == '#' ) ||
( cursor[i] == ':' &&
( cursor[i] == ':' &&
( cursor[i+1] == ' ' || cursor[i+1] == '\n' || i == len - 1 ) ) )
{
flags |= SCAN_INDIC_C;
}
else if ( cursor[i] == ',' &&
else if ( cursor[i] == ',' &&
( cursor[i+1] == ' ' || cursor[i+1] == '\n' || i == len - 1 ) )
{
flags |= SCAN_FLOWMAP;
Expand All @@ -661,12 +661,12 @@ void syck_emit_scalar( SyckEmitter *e, char *tag, enum scalar_style force_style,
SyckLevel *lvl = syck_emitter_current_level( e );
int scan = 0;
char *implicit;

if ( str == NULL ) str = "";

/* No empty nulls as map keys */
if ( len == 0 && ( parent->status == syck_lvl_map || parent->status == syck_lvl_imap ) &&
parent->ncount % 2 == 1 && syck_tagcmp( tag, "tag:yaml.org,2002:null" ) == 0 )
if ( len == 0 && ( parent->status == syck_lvl_map || parent->status == syck_lvl_imap ) &&
parent->ncount % 2 == 1 && syck_tagcmp( tag, "tag:yaml.org,2002:null" ) == 0 )
{
str = "~";
len = 1;
Expand All @@ -678,7 +678,7 @@ void syck_emit_scalar( SyckEmitter *e, char *tag, enum scalar_style force_style,
/* quote strings which default to implicits */
if (
(
(strncmp( implicit, "bool", 4 ) == 0) ||
(strncmp( implicit, "bool", 4 ) == 0) ||
(strncmp( implicit, "null", 4 ) == 0)
)
&&
Expand All @@ -690,8 +690,8 @@ void syck_emit_scalar( SyckEmitter *e, char *tag, enum scalar_style force_style,
} else {
/* complex key -- disabled by Audrey Tang -/
if ( parent->status == syck_lvl_map && parent->ncount % 2 == 1 &&
( !( tag == NULL ||
( implicit != NULL && syck_tagcmp( tag, implicit ) == 0 && e->explicit_typing == 0 ) ) ) )
( !( tag == NULL ||
( implicit != NULL && syck_tagcmp( tag, implicit ) == 0 && e->explicit_typing == 0 ) ) ) )
{
syck_emitter_write( e, "? ", 2 );
parent->status = syck_lvl_mapx;
Expand Down Expand Up @@ -955,7 +955,17 @@ void syck_emit_2quoted( SyckEmitter *e, int width, char *str, long len )

/* Escape sequences allowed within double quotes. */
case '"': syck_emitter_write( e, "\\\"", 2 ); break;
case '\\': syck_emitter_write( e, "\\\\", 2 ); break;
case '\\':
/* Check if next char is a special char that needs escaping */
if (mark + 1 < str + len &&
(mark[1] == 't' || mark[1] == 'r' || mark[1] == 'n' ||
mark[1] == '0' || mark[1] == 'a' || mark[1] == 'b' ||
mark[1] == 'f' || mark[1] == 'v' || mark[1] == 'e')) {
syck_emitter_write( e, "\\\\", 2 );
} else {
syck_emitter_write( e, "\\\\", 2 );
}
break;
case '\0': syck_emitter_write( e, "\\0", 2 ); break;
case '\a': syck_emitter_write( e, "\\a", 2 ); break;
case '\b': syck_emitter_write( e, "\\b", 2 ); break;
Expand All @@ -966,18 +976,6 @@ void syck_emit_2quoted( SyckEmitter *e, int width, char *str, long len )
case 0x1b: syck_emitter_write( e, "\\e", 2 ); break;
case '\n': syck_emitter_write( e, "\\n", 2 ); break;

/* XXX - Disabled by Audrey Tang for YAML.pm compat
case '\n':
end = mark + 1;
syck_emitter_write( e, "\\n", 2 );
do_indent = e->indent;
start = mark + 1;
if ( start < str + len && ( *start == ' ' || *start == '\n' ) ) {
do_indent = 0;
}
break;
*/

case ' ':
if ( width > 0 && *start != ' ' && mark - end > width ) {
do_indent = 1;
Expand Down Expand Up @@ -1314,13 +1312,13 @@ syck_emitter_mark_node( SyckEmitter *e, st_data_t n, int flags )
* object. Doesn't yet create an anchor, simply notes the
* position.
*/
if ( ! st_lookup( e->markers, n, (st_data_t *)&oid ) )
if ( ! st_lookup( e->markers, (char*)n, (char* *)(st_data_t *)&oid ) )
{
/*
* Store all markers
*/
oid = e->markers->num_entries + 1;
st_insert( e->markers, n, (st_data_t)oid );
st_insert( e->markers, (char*)n, (char*)(st_data_t)oid );
}
else
{
Expand All @@ -1329,7 +1327,7 @@ syck_emitter_mark_node( SyckEmitter *e, st_data_t n, int flags )
e->anchors = st_init_numtable();
}

if ( ! st_lookup( e->anchors, (st_data_t)oid, (st_data_t *)&anchor_name ) )
if ( ! st_lookup( e->anchors, (char*)(st_data_t)oid, (char* *)(st_data_t *)&anchor_name ) )
{
int idx = 0;
char *anc = ( e->anchor_format == NULL ? DEFAULT_ANCHOR_FORMAT : e->anchor_format );
Expand All @@ -1345,7 +1343,7 @@ syck_emitter_mark_node( SyckEmitter *e, st_data_t n, int flags )
/*
* Insert into anchors table
*/
st_insert( e->anchors, (st_data_t)oid, (st_data_t)anchor_name );
st_insert( e->anchors, (char*)(st_data_t)oid, (char*)(st_data_t)anchor_name );
}

/* XXX - Flag added by BDRACO as the perl_syck.h now has a max_depth - XXX */
Expand All @@ -1356,4 +1354,3 @@ syck_emitter_mark_node( SyckEmitter *e, st_data_t n, int flags )
}
return oid;
}

16 changes: 8 additions & 8 deletions handler.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ syck_hdlr_add_anchor( SyckParser *p, char *a, SyckNode *n )
if ( p->bad_anchors != NULL )
{
SyckNode *bad;
if ( st_lookup( p->bad_anchors, (st_data_t)a, (st_data_t *)&bad ) )
if ( st_lookup( p->bad_anchors, (char*)(st_data_t)a, (char* *)(st_data_t *)&bad ) )
{
if ( n->kind != syck_str_kind )
{
Expand All @@ -59,14 +59,14 @@ syck_hdlr_add_anchor( SyckParser *p, char *a, SyckNode *n )
{
p->anchors = st_init_strtable();
}
if ( st_lookup( p->anchors, (st_data_t)a, (st_data_t *)&ntmp ) )
if ( st_lookup( p->anchors, (char*)(st_data_t)a, (char* *)(st_data_t *)&ntmp ) )
{
if ( ntmp != (void *)1 )
{
syck_free_node( ntmp );
}
}
st_insert( p->anchors, (st_data_t)a, (st_data_t)n );
st_insert( p->anchors, (char*)(st_data_t)a, (char*)(st_data_t)n );
return n;
}

Expand All @@ -79,14 +79,14 @@ syck_hdlr_remove_anchor( SyckParser *p, char *a )
{
p->anchors = st_init_strtable();
}
if ( st_delete( p->anchors, (st_data_t *)&atmp, (st_data_t *)&ntmp ) )
if ( st_delete( p->anchors, (char* *)(st_data_t *)&atmp, (char* *)(st_data_t *)&ntmp ) )
{
if ( ntmp != (void *)1 )
{
syck_free_node( ntmp );
}
}
st_insert( p->anchors, (st_data_t)a, (st_data_t)1 );
st_insert( p->anchors, (char*)(st_data_t)a, (char*)(st_data_t)1 );
}

SyckNode *
Expand All @@ -96,7 +96,7 @@ syck_hdlr_get_anchor( SyckParser *p, char *a )

if ( p->anchors != NULL )
{
if ( st_lookup( p->anchors, (st_data_t)a, (st_data_t *)&n ) )
if ( st_lookup( p->anchors, (char*)(st_data_t)a, (char* *)(st_data_t *)&n ) )
{
if ( n != (void *)1 )
{
Expand All @@ -109,10 +109,10 @@ syck_hdlr_get_anchor( SyckParser *p, char *a )
{
p->bad_anchors = st_init_strtable();
}
if ( ! st_lookup( p->bad_anchors, (st_data_t)a, (st_data_t *)&n ) )
if ( ! st_lookup( p->bad_anchors, (char*)(st_data_t)a, (char* *)(st_data_t *)&n ) )
{
n = (p->bad_anchor_handler)( p, a );
st_insert( p->bad_anchors, (st_data_t)a, (st_data_t)n );
st_insert( p->bad_anchors, (char*)(st_data_t)a, (char*)(st_data_t)n );
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions perl_syck.h
Original file line number Diff line number Diff line change
Expand Up @@ -828,7 +828,7 @@ yaml_syck_mark_emitter
if (SvROK(sv)) {
PERL_SYCK_MARK_EMITTER(e, SvRV(sv));
#ifdef YAML_IS_JSON
st_insert(e->markers, (st_data_t)sv, 0);
st_insert(e->markers, (char*)(st_data_t)sv, 0);
e->depth--;
#endif
return;
Expand Down Expand Up @@ -868,7 +868,7 @@ yaml_syck_mark_emitter
}

#ifdef YAML_IS_JSON
st_insert(e->markers, (st_data_t)sv, 0);
st_insert(e->markers, (char*)(st_data_t)sv, 0);
--e->depth;
#endif
}
Expand Down
9 changes: 5 additions & 4 deletions syck_.c
Original file line number Diff line number Diff line change
Expand Up @@ -184,20 +184,21 @@ syck_add_sym( SyckParser *p, char *data )
p->syms = st_init_numtable();
}
id = p->syms->num_entries + 1;
st_insert( p->syms, id, (st_data_t)data );
st_insert( p->syms, (char*)id, (char*)(st_data_t)data );
return id;
}

int
syck_lookup_sym( SyckParser *p, SYMID id, char **data )
{
if ( p->syms == NULL ) return 0;
return st_lookup( p->syms, id, (st_data_t *)data );
return st_lookup( p->syms, (char *)id, (char**)(st_data_t *)data );
}

int
syck_st_free_nodes( char *key, SyckNode *n, char *arg )
enum st_retval
syck_st_free_nodes( char *key, char * proto_n, char *arg )
{
SyckNode *n = (SyckNode *)proto_n;
if ( n != (void *)1 ) syck_free_node( n );
n = NULL;
return ST_CONTINUE;
Expand Down
Loading