Subject: | Patch to prevent segfaults on amd64 |
Hi,
as i was porting this module to OpenBSD/amd64 i saw tests failing that
even led to a perl.core:
Failed Test Stat Wstat Total Fail Failed List of Failed
-------------------------------------------------------------------------------
t/05exceptions.t 0 139 4 2 50.00% 4
t/12error.t 0 138 26 36 138.46% 9-26
t/15bom.t 0 138 5 8 160.00% 2-5
1 subtest skipped.
Failed 3/32 test scripts, 90.62% okay. 23/352 subtests failed, 93.47% okay.
Those failures relate to a warning i noticed already at compile time:
cc -c -Ilibjsonevt -fno-strict-aliasing
-fno-delete-null-pointer-checks -pipe -I/usr/local/include -O2
-DVERSION=\"0.27\" -DXS_VERSION=\"0.27\" -DPIC -fPIC
"-I/usr/libdata/perl5/amd64-openbsd/5.8.8/CORE" -DHAVE_JSONEVT
-DNO_VERSION_IN_ERROR DWIW.c
DWIW.xs: In function `vjson_encode_error':
DWIW.xs:61: warning: passing arg 4 of `Perl_sv_vcatpvfn' from
incompatible pointer type
Fixing this was done by changing the vjson_encode_error() function to
take a pointer to a va_list instead of the va_list itself.
With the attached patch all tests pass with the following result:
All tests successful, 1 subtest skipped.
Files=32, Tests=352, 3 wallclock secs ( 1.74 cusr + 0.42 csys = 2.16 CPU)
Kind regards,
Simon
Subject: | DWIW.diff |
--- DWIW.xs.orig Fri Aug 15 10:25:12 2008
+++ DWIW.xs Fri Aug 15 10:25:56 2008
@@ -51,14 +51,14 @@ JSON_TRACE(char *fmt, ...) {
static SV *
-vjson_encode_error(self_context * ctx, const char * file, int line_num, const char * fmt, va_list ap) {
+vjson_encode_error(self_context * ctx, const char * file, int line_num, const char * fmt, va_list *ap) {
SV * error = newSVpv("", 0);
bool junk = 0;
HV * error_data = Nullhv;
sv_setpvf(error, "JSON::DWIW v%s - ", MOD_VERSION);
- sv_vcatpvfn(error, fmt, strlen(fmt), &ap, (SV **)0, 0, &junk);
+ sv_vcatpvfn(error, fmt, strlen(fmt), ap, (SV **)0, 0, &junk);
error_data = newHV();
ctx->error_data = newRV_noinc((SV *)error_data);
@@ -74,7 +74,7 @@ json_encode_error(self_context * ctx, const char * fil
SV * error;
va_start(ap, fmt);
- error = vjson_encode_error(ctx, file, line_num, fmt, ap);
+ error = vjson_encode_error(ctx, file, line_num, fmt, &ap);
va_end(ap);
return error;
@@ -99,7 +99,7 @@ JSON_ENCODE_ERROR(self_context * ctx, const char * fmt
SV * error;
va_start(ap, fmt);
- error = vjson_encode_error(ctx, NULL, 0, fmt, ap);
+ error = vjson_encode_error(ctx, NULL, 0, fmt, &ap);
va_end(ap);
return error;
--- old_parse.c.orig Fri Aug 15 10:25:22 2008
+++ old_parse.c Fri Aug 15 10:25:28 2008
@@ -18,6 +18,7 @@ Copyright (c) 2007-2008 Don Owens <don@regexguy.com>.
*/
#include "old_parse.h"
+#include <stdio.h>
#define JsHaveMoreChars(ctx) ( (ctx)->pos < (ctx)->len )
@@ -235,7 +236,7 @@ get_new_bool_obj(int bool_val) {
static SV *
vjson_parse_error(json_context * ctx, const char * file, unsigned int line_num, const char * fmt,
- va_list ap) {
+ va_list *ap) {
SV * error = Nullsv;
bool junk = 0;
HV * error_data;
@@ -252,7 +253,7 @@ vjson_parse_error(json_context * ctx, const char * fil
}
sv_catpvn(error, " - ", 3);
- sv_vcatpvfn(error, fmt, strlen(fmt), &ap, (SV **)0, 0, &junk);
+ sv_vcatpvfn(error, fmt, strlen(fmt), ap, (SV **)0, 0, &junk);
sv_catpvf(error, " - at char %u (byte %u), line %u, col %u (byte col %u)", ctx->char_pos,
ctx->pos, ctx->line, ctx->char_col, ctx->col);
@@ -283,7 +284,7 @@ json_parse_error(json_context * ctx, const char * file
va_list ap;
va_start(ap, fmt);
- error = vjson_parse_error(ctx, file, line_num, fmt, ap);
+ error = vjson_parse_error(ctx, file, line_num, fmt, &ap);
va_end(ap);
return error;
@@ -297,7 +298,7 @@ JSON_PARSE_ERROR(json_context * ctx, const char * fmt,
va_list ap;
va_start(ap, fmt);
- error = vjson_parse_error(ctx, NULL, 0, fmt, ap);
+ error = vjson_parse_error(ctx, NULL, 0, fmt, &ap);
va_end(ap);
return error;