2

私は現在、libxml2での c-binding を使用して、crystal-lang の c14n サポートを追加しようとしています。xmlC14NDocSave を使用して、正規の xml をファイルに保存することに成功しました。私が抱えている問題は、xmlC14NDocSaveTo と xmlC14NExecute の両方の xmlOutputBufferPtr にあります。

私が受け取るエラーは(MacおよびLinux)です

xmlC14NExecute: 出力バッファ エンコーダー != NULL ですが、C14N には UTF8 出力が必要です

ドキュメントの状態

C14N は UTF-8 出力を必要とするため、このバッファはエンコーダ==NULL を持たなければなりません (MUST)。

私はsrc/C14N/lib_C14N.cr次のコードを持っています

type CharEncodingHandler = Void*
type Buff = Void*
#type OutputBuffer = Void*
struct OutputBuffer
  context : Void*
  writecallback : OutputWriteCallback
  closecallback : OutputCloseCallback
  encoder : CharEncodingHandler
  buffer  : Buff
  conv    : Buff
  written : Int32
  error   : Int32
end
....
fun xmlC14NDocSaveTo(doc : LibXML::Node*, nodes : LibXML::NodeSet*, mode : Mode, inclusive_ns_prefixes : UInt8**, with_comments : Int32, buf : OutputBuffer*) : Int32
fun xmlC14NExecute(doc : LibXML::Node*, is_visible_callback : IsVisibleCallback, user_data : Void*, mode : Mode, inclusive_ns_prefixes : UInt8**, with_comments : Int32, buf : OutputBuffer*) : Int32

src/C14N.cr

output = XML::LibC14N::OutputBuffer.new
p output.encoder
XML::LibC14N.xmlC14NDocSaveTo(@xml, nil, @mode, nil, 0, out output)

p ouput.encoder の結果はPointer(Void).null、値が null のようです。

関数は、c14n.cbuf->encoder 構造体で null をチェックしているだけです

if (buf->encoder != NULL) {
    xmlGenericError(xmlGenericErrorContext,
                    "xmlC14NExecute: output buffer encoder != NULL but C14N requires UTF8 output\n");
    return (-1);
}

コードは私のgithubアカウントにあります。クローンして実行crystal spec

4

1 に答える 1

1

を指定しないでください。これはout output、単にスタック上の構造体のサイズのメモリ ブロックを予約し、それにポインターを渡します。Crystal 0.7.6 の時点ではゼロに設定されていないため、ガベージを渡します。

メモリをゼロにするため、使用output = XML::LibC14N::OutputBuffer.newはすでに最初の正しいステップです。渡すには、単純に に置き換えout outputますpointerof(output)

于 2015-08-27T00:01:12.783 に答える