<html><head><meta http-equiv="Content-Type" content="text/html charset=koi8-r"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div class=""><div class="">Приветствую.</div><div class=""><br class=""></div><div class="">Вот еще столкнулся со странным поведением JSON::XS (3.01).</div><div class=""><br class=""></div><div class="">Пытаюсь сериализовать объект, содержащий объекты, используя функцию FREEZE. Один из объектов содержит большое число аргументов (61 пара ключ-значение). При сериализации такого объекта скрипт падает с ошибкой "Segmentation fault" или метод encode() возвращает undef.</div><div class=""><br class=""></div><div class="">Иногда скрипт работает корректно. В этом случае незначительное увеличение кол-ва аргументов или уровня вложенности объектов снова приводит к выше описанному результату.</div><div class=""><br class=""></div><div class=""><div class="">Cpanel::JSON::XS ведет себя также. Ошибка проявляется на разных машинах и OS (Linux, FreeBSD, OS X).</div></div><div class=""><br class=""></div><div class="">Пример:</div><div class=""><br class=""></div><div class="">#!/usr/bin/env perl</div><div class=""><br class=""></div><div class="">use 5.010000;</div><div class="">use strict;</div><div class="">use warnings;</div><div class=""><br class=""></div><div class="">use JSON::XS;</div><div class=""><br class=""></div><div class="">my $json_szr = JSON::XS->new();</div><div class="">$json_szr->allow_tags( 1 );</div><div class=""><br class=""></div><div class="">my @foo_params;</div><div class="">for ( 1 .. 61 ) {</div><div class="">  push ( @foo_params, "coo$_" => 1 );</div><div class="">}</div><div class="">my $foo1 = Foo->new( @foo_params );</div><div class="">my $foo2 = Foo->new( @foo_params );</div><div class=""><br class=""></div><div class="">my $bar1 = Bar->new(</div><div class="">  foo => $foo1,</div><div class="">);</div><div class=""><br class=""></div><div class="">my $bar2 = Bar->new(</div><div class="">  foo => $foo2,</div><div class="">  bar => $bar1</div><div class="">);</div><div class=""><br class=""></div><div class="">my $bar_json = $json_szr->encode( $bar2 );</div><div class="">if ( defined $bar_json ) {</div><div class="">  say $bar_json;</div><div class="">}</div><div class=""><br class=""></div><div class=""><br class=""></div><div class="">package Foo;</div><div class=""><br class=""></div><div class="">####</div><div class="">sub new {</div><div class="">  my $class = shift;</div><div class="">  my %params = @_;</div><div class=""> </div><div class="">  return bless \%params, $class;</div><div class="">}</div><div class=""><br class=""></div><div class="">####</div><div class="">sub FREEZE {</div><div class="">  my $self = shift;</div><div class="">  </div><div class="">  return %{$self};</div><div class="">}</div><div class=""><br class=""></div><div class="">####</div><div class="">sub THAW {</div><div class="">  my $class = shift;</div><div class="">  my $szr   = shift;</div><div class=""><br class=""></div><div class="">  return $class->new( @_ );</div><div class="">}</div><div class=""><br class=""></div><div class=""><br class=""></div><div class="">package Bar;</div><div class=""><br class=""></div><div class="">####</div><div class="">sub new {</div><div class="">  my $class = shift;</div><div class="">  my %params = @_;</div><div class=""> </div><div class="">  return bless \%params, $class;</div><div class="">}</div><div class=""><br class=""></div><div class="">####</div><div class="">sub FREEZE {</div><div class="">  my $self = shift;</div><div class="">  </div><div class="">  return %{$self};</div><div class="">}</div></div><br class=""><div><blockquote type="cite" class=""><div class="">29 нояб. 2014 г., в 10:42, TheAthlete <<a href="mailto:theathlet@yandex.ru" class="">theathlet@yandex.ru</a>> написал(а):</div><br class="Apple-interchange-newline"><div class=""><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">Согласен, что перекрывает, но здесь JSON::XS создан с методом</span><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">convert_blessed, который говорит, что переданный обхект должен иметь метод</span><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">TO_JSON. Объект модуля boolean имеет данный метод.</span><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">$  perl -MData::Printer -MCpanel::JSON::XS -Mboolean=-truth -E '$j =</span><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">Cpanel::JSON::XS->new->convert_blessed; $b = (0 == 1); say</span><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">$j->encode({false => $b}); p$b'</span><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">{"false":false}</span><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">boolean  {</span><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">     Parents       Exporter</span><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">     public methods (9) : boolean, false, import, isBoolean, isFalse,</span><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">isTrue, TO_JSON, true, truth</span><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">     private methods (1) : __ANON__</span><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">     internals: 0</span><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">}</span><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">$  perl -MData::Printer -MJSON::XS -Mboolean=-truth -E '$j =</span><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">JSON::XS->new->convert_blessed; $b = (0 == 1); say $j->encode({false =></span><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">$b}); p $b'</span><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">Modification of a read-only value attempted at -e line 1.</span><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">Насколько я понял, эта ошибка связана с приведением к строке булевых</span><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">значений (Boolean stringify) в модуле boolean.</span><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">Данная ошибка была скорее всего исправлена в Cpanel::JSON::XS начиная с версии 2.3311 -</span><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><a href="https://github.com/rurban/Cpanel-JSON-XS/commit/a42d7b7ec05c9aad18ba9b0ef12c721c31a47317" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class="">https://github.com/rurban/Cpanel-JSON-XS/commit/a42d7b7ec05c9aad18ba9b0ef12c721c31a47317</a><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">Victor Efimov <</span><a href="mailto:victor@vsespb.ru" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class="">victor@vsespb.ru</a><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">> писал(а) в своём письме Fri, 28 Nov 2014</span><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">20:44:50 +0300:</span><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><blockquote type="cite" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class="">28 ноября 2014 г., 18:41 пользователь TheAthlete <<a href="mailto:theathlet@yandex.ru" class="">theathlet@yandex.ru</a>> написал:<br class=""><blockquote type="cite" class="">Неделя багов в JSON::XS! :)<br class=""></blockquote><br class="">Почему это баг JSON::XS ?<br class=""><br class="">use strict; use warnings;<br class="">use Test::More tests => 3;<br class="">use boolean -truth;<br class="">use JSON::XS;<br class="">my $json = JSON::XS->new;<br class="">is($json->encode({"hey" => !!0}), 'abc',  'JSON false works');<br class=""><br class="">тоже фейлится. если<br class=""><br class="">use boolean -truth;<br class=""><br class="">закоментировать, то работает норм.<br class=""><br class="">Это потому что опция<br class=""><br class="">-truth<br class=""><br class="">You can specify the -truth option to override truth operators to<br class="">return boolean values.<br class=""><br class="">use boolean -truth;<br class="">print ref("hello" eq "world"), "\n";<br class=""><br class=""><br class="">перекрывает операторы Perl, чтобы они возвращали объект. Почему<br class="">считается что JSON::XS должен с этим работать ? Почему это не баг в<br class="">"boolean" ?<br class=""><br class=""><br class=""><blockquote type="cite" class="">Тоже столкнулся с багом в JSON::XS - при установке модуля boolean, который<br class="">в зависимостях у Test::DBIx::Class, не был пройден тест json.t.<br class="">Заглянув в issue данного модуля на github, нашел такой тикет:<br class=""><br class="">json.t fails on many Linux systems -<br class=""><a href="https://github.com/ingydotnet/boolean-pm/issues/5" class="">https://github.com/ingydotnet/boolean-pm/issues/5</a><br class=""><br class="">Там некоторые советуют установить Cpanel::JSON::XS - установил и все<br class="">заработало, хотя не у всех падает при установленном JSON::XS.<br class=""><br class="">Если модифицировать тест:<br class=""><br class="">use strict; use warnings;<br class="">use Test::More tests => 3;<br class="">use boolean -truth;<br class="">my $HAVE_JSON = eval { require JSON::MaybeXS };<br class="">SKIP: {<br class="">     skip "JSON is missing", 3 unless $HAVE_JSON;<br class="">     eval{<br class="">         my $json = JSON::MaybeXS->new->convert_blessed();<br class="">         is($json->encode({false => (0 == 1)}), '{"false":false}',<br class="">             'JSON false works');<br class="">       is($json->encode({true  => (1 == 1)}), '{"true":true}',<br class="">           'JSON true works');<br class="">       is(ref(boolean::TO_JSON(true)), 'SCALAR',<br class="">           'Make sure we can call boolean::TO_JSON($b)');<br class="">       }<br class="">};<br class=""><br class="">в следующий:<br class=""><br class="">use strict; use warnings;<br class="">use Test::More tests => 3;<br class="">use boolean -truth;<br class="">my $HAVE_JSON = eval { require JSON::XS };<br class="">SKIP: {<br class="">     skip "JSON is missing", 3 unless $HAVE_JSON;<br class="">     my $json = JSON::XS->new->convert_blessed();<br class="">     is($json->encode({false => (0 == 1)}), '{"false":false}',<br class="">       'JSON false works');<br class="">     is($json->encode({true  => (1 == 1)}), '{"true":true}',<br class="">       'JSON true works');<br class="">     is(ref(boolean::TO_JSON(true)), 'SCALAR',<br class="">       'Make sure we can call boolean::TO_JSON($b)');<br class="">};<br class=""><br class="">и запустить, то тест сваливается с ошибкой "Modification of a read-only<br class="">value attempted at test/json.t line 9"<br class=""><br class="">Если заменить на Cpanel::JSON::XS или JSON::PP, то все ок<br class=""><br class="">Вадим Власов <scripter.vrn@gmail.com> писал(а) в своём письме Wed, 26 Nov<br class="">2014 20:01:33 +0300:<br class=""><br class=""><blockquote type="cite" class="">Исследуя новый сериализатор в JSON::XS наткнулся:<br class=""><br class="">$ echo 'use strict;<br class="">use warnings;<br class="">use feature "say";<br class=""><br class="">use JSON::XS;<br class="">my $j=JSON::XS->new->allow_tags;<br class=""><br class="">say "JSON::XS: $JSON::XS::VERSION";<br class="">say "Types::Serialiser: $Types::Serialiser::VERSION";<br class=""><br class="">my $t = $j->encode( Foo->new );<br class="">say $t;<br class=""><br class="">my @t = $j->encode( Foo->new );<br class=""><br class="">package Foo;<br class="">sub new { bless {}, $_[0]; }<br class="">sub FREEZE { ( 123, 456 ); }' | perl<br class="">*JSON::XS: 3.01*<br class="">*Types::Serialiser: 1.0*<br class="">*("Foo")[123,456]*<br class="">*panic: attempt to copy freed scalar c37a18 to c37a00 at - line 14.*<br class=""><br class="">$ perl -MJSON::XS -wE 'say JSON::XS->new->allow_tags->encode( bless {},<br class="">Foo<br class="">); package Foo; sub FREEZE{ return 123 }'<br class="">*Use of uninitialized value in say at -e line 1.*<br class="">*("Foo")[123]*<br class=""><br class="">$ perl -MJSON::XS -wE 'say scalar( JSON::XS->new->allow_tags->encode(<br class="">bless<br class="">{}, Foo )); package Foo; sub FREEZE{ return 123 }'<br class="">*("Foo")[123]*<br class=""><br class="">Проверили на разных машинах и на разных версиях perl-а - одно и то же.<br class=""><br class=""></blockquote><br class=""><br class="">--<br class="">Написано в почтовом клиенте браузера Opera: http://www.opera.com/mail/<br class=""><br class="">--<br class="">Moscow.pm mailing list<br class="">moscow-pm@pm.org | http://moscow.pm.org<br class=""></blockquote></blockquote><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">--<span class="Apple-converted-space"> </span></span><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">Написано в почтовом клиенте браузера Opera:<span class="Apple-converted-space"> </span></span><a href="http://www.opera.com/mail/" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class="">http://www.opera.com/mail/</a><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">--<span class="Apple-converted-space"> </span></span><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">Moscow.pm mailing list</span><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><a href="mailto:moscow-pm@pm.org" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class="">moscow-pm@pm.org</a><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class=""><span class="Apple-converted-space"> </span>|<span class="Apple-converted-space"> </span></span><a href="http://moscow.pm.org/" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class="">http://moscow.pm.org</a></div></blockquote></div><br class=""></body></html>