390 |
|
|
391 |
=end original |
=end original |
392 |
|
|
393 |
If you want to write to an existing SV's buffer and set its value to a |
もし既存の SV のバッファに書き込みたくて、その値を文字列に設定したいなら、 |
394 |
string, use SvPV_force() or one of its variants to force the SV to be |
SV を PV に強制するために |
395 |
a PV. This will remove any of various types of non-stringness from |
SvPV_force() またはその変種の一つを使ってください。 |
396 |
the SV while preserving the content of the SV in the PV. This can be |
これは SV から様々な種類の非文字列性を除去する一方、PV の中の SV の |
397 |
used, for example, to append data from an API function to a buffer |
内容は保存します。 |
398 |
without extra copying: |
これは、例えば、追加のコピーなしに API 関数からバッファにデータを |
399 |
(TBT) |
追加するのに使えます: |
400 |
|
|
401 |
(void)SvPVbyte_force(sv, len); |
(void)SvPVbyte_force(sv, len); |
402 |
s = SvGROW(sv, len + needlen + 1); |
s = SvGROW(sv, len + needlen + 1); |
419 |
|
|
420 |
=end original |
=end original |
421 |
|
|
422 |
If you already have the data in memory or if you want to keep your |
既にメモリにデータを持っている場合や、コードを単純に保ちたい場合は、 |
423 |
code simple, you can use one of the sv_cat*() variants, such as |
sv_catpvn() のような sv_cat*() の変種の一つを使えます。 |
424 |
sv_catpvn(). If you want to insert anywhere in the string you can use |
もし文字列中のどこかに挿入したいなら、sv_insert() や |
425 |
sv_insert() or sv_insert_flags(). |
sv_insert_flags() が使えます。 |
|
(TBT) |
|
426 |
|
|
427 |
=begin original |
=begin original |
428 |
|
|
431 |
|
|
432 |
=end original |
=end original |
433 |
|
|
434 |
If you don't need the existing content of the SV, you can avoid some |
SV の既存の内容が必要でないなら、次のようにして一部のコピーを |
435 |
copying with: |
回避できます: |
|
(TBT) |
|
436 |
|
|
437 |
sv_setpvn(sv, "", 0); |
sv_setpvn(sv, "", 0); |
438 |
s = SvGROW(sv, needlen + 1); |
s = SvGROW(sv, needlen + 1); |
452 |
|
|
453 |
=end original |
=end original |
454 |
|
|
455 |
Again, if you already have the data in memory or want to avoid the |
再び、既にメモリにデータを持っている場合や、前述のような複雑さを |
456 |
complexity of the above, you can use sv_setpvn(). |
避けたい場合は、sv_setpvn() が使えます。 |
|
(TBT) |
|
457 |
|
|
458 |
=begin original |
=begin original |
459 |
|
|
464 |
|
|
465 |
=end original |
=end original |
466 |
|
|
467 |
If you have a buffer allocated with Newx() and want to set that as the |
If you have a buffer allocated with |
468 |
SV's value, you can use sv_usepvn_flags(). That has some requirements |
Newx() で割り当てられたバッファを持っていて、それを SV の値として |
469 |
if you want to avoid perl re-allocating the buffer to fit the trailing |
設定したいなら、sv_usepvn_flags() が使えます。 |
470 |
NUL: |
perl が末尾の NUL に収まるようにバッファを再配置するのを避けたいなら、 |
471 |
(TBT) |
いくつかの要求事項があります: |
472 |
|
|
473 |
Newx(buf, somesize+1, char); |
Newx(buf, somesize+1, char); |
474 |
/* ... fill in buf ... */ |
/* ... fill in buf ... */ |
483 |
|
|
484 |
=end original |
=end original |
485 |
|
|
486 |
手元にある SV の、Perl から見たデータの種類を知りたいときには、 |
ある SV があって、それに保管されているデータの種類が何であると |
487 |
その SV の型をチェックするのに |
Perl が考えているかを知りたいなら、 |
488 |
|
その SV の型をチェックするのに次のようなマクロが使えます。 |
489 |
|
|
490 |
SvIOK(SV*) |
SvIOK(SV*) |
491 |
SvNOK(SV*) |
SvNOK(SV*) |
2393 |
|
|
2394 |
=end original |
=end original |
2395 |
|
|
2396 |
Perl implements a copy-on-write (COW) mechanism for scalars, in which |
Perl は、スカラに関してコピーオンライト (COW) 機構を実装しています; |
2397 |
string copies are not immediately made when requested, but are deferred |
これは、文字列のコピーは要求されたときにすぐに行うのではなく、 |
2398 |
until made necessary by one or the other scalar changing. This is mostly |
どちらかのスカラが変更されることによって必要になるまで遅延させます。 |
2399 |
transparent, but one must take care not to modify string buffers that are |
これはほとんど透過ですが、複数の SV で共有されている文字列バッファを |
2400 |
shared by multiple SVs. |
変更しないように注意しなければなりません。 |
|
(TBT) |
|
2401 |
|
|
2402 |
=begin original |
=begin original |
2403 |
|
|
2405 |
|
|
2406 |
=end original |
=end original |
2407 |
|
|
2408 |
You can test whether an SV is using copy-on-write with C<SvIsCOW(sv)>. |
ある SV がコピーオンライトを使っているかどうかは C<SvIsCOW(sv)> で |
2409 |
(TBT) |
テストできます。 |
2410 |
|
|
2411 |
=begin original |
=begin original |
2412 |
|
|
2414 |
|
|
2415 |
=end original |
=end original |
2416 |
|
|
2417 |
You can force an SV to make its own copy of its string buffer by calling C<sv_force_normal(sv)> or SvPV_force_nolen(sv). |
C<sv_force_normal(sv)> か SvPV_force_nolen(sv) を呼び出すことで、 |
2418 |
(TBT) |
SV が文字列に関して自分自身のコピーを持つように強制できます。 |
2419 |
|
|
2420 |
=begin original |
=begin original |
2421 |
|
|
2425 |
|
|
2426 |
=end original |
=end original |
2427 |
|
|
2428 |
If you want to make the SV drop its string buffer, use |
SV に自分自身の文字列バッファを捨てさせたい場合は、 |
2429 |
C<sv_force_normal_flags(sv, SV_COW_DROP_PV)> or simply |
C<sv_force_normal_flags(sv, SV_COW_DROP_PV)> か、単に |
2430 |
C<sv_setsv(sv, NULL)>. |
C<sv_setsv(sv, NULL)> を使います。 |
|
(TBT) |
|
2431 |
|
|
2432 |
=begin original |
=begin original |
2433 |
|
|
2436 |
|
|
2437 |
=end original |
=end original |
2438 |
|
|
2439 |
All of these functions will croak on read-only scalars (see the previous |
これら全ての関数は、読み込み専用スカラに対しては croak します |
2440 |
section for more on those). |
(これに関する詳細は前の節を参照してください)。 |
|
(TBT) |
|
2441 |
|
|
2442 |
=begin original |
=begin original |
2443 |
|
|
2449 |
|
|
2450 |
=end original |
=end original |
2451 |
|
|
2452 |
To test that your code is behaving correctly and not modifying COW buffers, |
あなたのコードが正しく振る舞って、COW バッファを変更していないことを |
2453 |
on systems that support L<mmap(2)> (i.e., Unix) you can configure perl with |
テストするには、 |
2454 |
C<-Accflags=-DPERL_DEBUG_READONLY_COW> and it will turn buffer violations |
L<mmap(2)> に対応しているシステム (例えば Unix) では、 |
2455 |
into crashes. You will find it to be marvellously slow, so you may want to |
C<-Accflags=-DPERL_DEBUG_READONLY_COW> を有効にした perl を設定すると、 |
2456 |
skip perl's own tests. |
バッファ違反でクラッシュするようになります。 |
2457 |
(TBT) |
これは驚くほど遅いので、perl 自身のテストは飛ばした方が良いでしょう。 |
2458 |
|
|
2459 |
=head2 Magic Variables |
=head2 Magic Variables |
2460 |
|
|
7113 |
|
|
7114 |
Translate: KIMURA Koichi |
Translate: KIMURA Koichi |
7115 |
Update: Kentaro Shirakata <argrath@ub32.org> (5.10.0-) |
Update: Kentaro Shirakata <argrath@ub32.org> (5.10.0-) |
7116 |
Status: in progress |
Status: completed |
7117 |
|
|
7118 |
=end meta |
=end meta |
7119 |
|
|