argra****@users*****
argra****@users*****
2012年 9月 11日 (火) 18:54:08 JST
Index: docs/perl/5.10.0/perlguts.pod diff -u docs/perl/5.10.0/perlguts.pod:1.12 docs/perl/5.10.0/perlguts.pod:1.13 --- docs/perl/5.10.0/perlguts.pod:1.12 Wed Aug 29 21:44:13 2012 +++ docs/perl/5.10.0/perlguts.pod Tue Sep 11 18:54:08 2012 @@ -467,7 +467,8 @@ =end original -スカラ変数の名前がわかれば、その SV へのポインタは +スカラ変数の名前がわかれば、その SV へのポインタは以下のようにして +得られます: SV* get_sv("package::varname", FALSE); @@ -477,8 +478,7 @@ =end original -を使って得ることができます。 -その変数が存在しない場合には NULL が返されます。 +これは変数が存在していない場合には NULL を返します。 =begin original @@ -904,7 +904,7 @@ =end original 配列変数の名前がわかっているのであれば、次のようにしてその配列に -対応する AV へのポインタを得ることができます。 +対応する AV へのポインタが得られます: AV* get_av("package::varname", FALSE); @@ -1100,7 +1100,8 @@ =end original -配列変数の名前がわかるのであれば、 +配列変数の名前がわかるのであれば、以下のようにしてその変数の HV への +ポインタが得られます: HV* get_hv("package::varname", FALSE); @@ -1110,8 +1111,7 @@ =end original -を使えば、その変数の HV へのポインタが得られます。 -その変数が存在しない場合には NULL を返します。 +これは変数が存在していない場合には NULL を返します。 =begin original @@ -1976,7 +1976,7 @@ =end original -揮発性のルーチンは、単に SV のためだけではありません。 +揮発性のルーチンは、単に SV のためだけではありません -- AV や HV も、C<sv_2mortal> や C<sv_mortalcopy> ルーチンに、アドレスを (C<SV*> にキャストして) 渡すことで、揮発性にすることができます。 @@ -4598,14 +4598,12 @@ =end original -The Perl interpreter can be regarded as a closed box: it has an API -for feeding it code or otherwise making it do things, but it also has -functions for its own use. This smells a lot like an object, and -there are ways for you to build Perl so that you can have multiple -interpreters, with one interpreter represented either as a C structure, -or inside a thread-specific structure. These structures contain all -the context, the state of that interpreter. -(TBT) +Perl インタプリタはブラックボックスとして扱われます: コードに与えたり、 +何かをするための API がありますが、自分自身で使うための関数もあります。 +これはオブジェクトのような匂いがして、それぞれを C の構造体や +スレッド固有の構造体の内部として表現する、複数のインタプリタを使えるように +Perl をビルドするための方法があります。 +これらの構造体はそのインタプリタの全てのコンテキストと状態を含みます。 =begin original @@ -4619,14 +4617,14 @@ =end original -One macro controls the major Perl build flavor: MULTIPLICITY. The -MULTIPLICITY build has a C structure that packages all the interpreter -state. With multiplicity-enabled perls, PERL_IMPLICIT_CONTEXT is also -normally defined, and enables the support for passing in a "hidden" first -argument that represents all three data structures. MULTIPLICITY makes -mutli-threaded perls possible (with the ithreads threading model, related -to the macro USE_ITHREADS.) -(TBT) +一つのマクロは主な Perl ビルド設定: MULTIPLICITY です。 +MULTIPLICITY ビルドは全てのインタプリタ状態をパッケージした C の構造体を +持ちます。 +MULTIPLICITY を遊行した perl では、PERL_IMPLICIT_CONTEXT も普通設定され、 +三つのデータ構造体全てを表現する「隠された」最初の引数を渡すことへの +対応が有効になります。 +MULTIPLICITY は(マクロ USE_ITHREADS に関連する ithread スレッドモデルで) +マルチスレッド perl を可能にします。 =begin original @@ -4647,21 +4645,22 @@ =end original -Two other "encapsulation" macros are the PERL_GLOBAL_STRUCT and -PERL_GLOBAL_STRUCT_PRIVATE (the latter turns on the former, and the -former turns on MULTIPLICITY.) The PERL_GLOBAL_STRUCT causes all the -internal variables of Perl to be wrapped inside a single global struct, -struct perl_vars, accessible as (globals) &PL_Vars or PL_VarsPtr or -the function Perl_GetVars(). The PERL_GLOBAL_STRUCT_PRIVATE goes -one step further, there is still a single struct (allocated in main() -either from heap or from stack) but there are no global data symbols -pointing to it. In either case the global struct should be initialised -as the very first thing in main() using Perl_init_global_struct() and -correspondingly tear it down after perl_free() using Perl_free_global_struct(), -please see F<miniperlmain.c> for usage details. You may also need -to use C<dVAR> in your coding to "declare the global variables" -when you are using them. dTHX does this for you automatically. -(TBT) +あと二つの「カプセル化」マクロは PERL_GLOBAL_STRUCT と +PERL_GLOBAL_STRUCT_PRIVATE です(後者は前者を有効にして、前者は +MULTIPLICITY を有効にします。) +PERL_GLOBAL_STRUCT は Perl の全ての内部変数を一つグローバル構造体である +struct perl_vars にラップして、(グローバルに) &PL_Vars, PL_VarsPtr, +Perl_GetVars() 関数でアクセスできます。 +PERL_GLOBAL_STRUCT_PRIVATE はもう一歩進めて、やはり(main() でヒープか +スタックに割り当てられた)一つの構造体ですが、これを示すグローバルな +データシンボルはありません。 +どちらの場合でもグローバルな構造体は Perl_init_global_struct() を使って +main() の最初で初期化され、Perl_free_global_struct() を使って perl_free() の +後で解放されます; 詳細な使用法については F<miniperlmain.c> を +参照してください。 +これらを使う時、「グローバル変数を宣言する」ためにコード中で C<dVAR> を +使う必要があるかもしれません。 +dTHX はこれを自動的に行います。 =begin original @@ -4669,8 +4668,7 @@ =end original -To see whether you have non-const data you can use a BSD-compatible C<nm>: -(TBT) +非 const データがあるかどうかを見るには、BSD 互換の C<nm> を使えます: nm libperl.a | grep -v ' [TURtr] ' @@ -4680,8 +4678,7 @@ =end original -If this displays any C<D> or C<d> symbols, you have non-const data. -(TBT) +C<D> または C<d> シンボルが表示されたら、非 const データがあります。 =begin original @@ -4692,11 +4689,11 @@ =end original -For backward compatibility reasons defining just PERL_GLOBAL_STRUCT -doesn't actually hide all symbols inside a big global struct: some -PerlIO_xxx vtables are left visible. The PERL_GLOBAL_STRUCT_PRIVATE -then hides everything (see how the PERLIO_FUNCS_DECL is used). -(TBT) +後方互換性のために、単に PERL_GLOBAL_STRUCT を定義しただけでは +大きなグローバル構造体の全てのシンボルは隠れません: いくつかの +PerlIO_xxx vtables は見えるままです。 +PERL_GLOBAL_STRUCT_PRIVATE は全てを隠します ( PERLIO_FUNCS_DECL の +使い方を参照してください)。 =begin original @@ -4709,13 +4706,12 @@ =end original -All this obviously requires a way for the Perl internal functions to be -either subroutines taking some kind of structure as the first -argument, or subroutines taking nothing as the first argument. To -enable these two very different ways of building the interpreter, -the Perl source (as it does in so many other situations) makes heavy -use of macros and subroutine naming conventions. -(TBT) +これら全ては明らかに、Perl 内部関数を、ある種の構造体を最初の引数として取る +サブルーチンか、最初の引数に何も取らないサブルーチンにする方法が +必要です。 +インタプリタのビルドをかなり異なった方法でこれら二つを有効にするために、 +Perl ソースは(その他の多くの状況で行うのと同様) マクロとサブルーチンの +命名規則を激しく使っています。 =begin original @@ -4731,16 +4727,19 @@ =end original -First problem: deciding which functions will be public API functions and -which will be private. All functions whose names begin C<S_> are private -(think "S" for "secret" or "static"). All other functions begin with -"Perl_", but just because a function begins with "Perl_" does not mean it is -part of the API. (See L</Internal Functions>.) The easiest way to be B<sure> a -function is part of the API is to find its entry in L<perlapi>. -If it exists in L<perlapi>, it's part of the API. If it doesn't, and you -think it should be (i.e., you need it for your extension), send mail via -L<perlbug> explaining why you think it should be. -(TBT) +最初の問題: どの関数が公的な API 関数になる関数で、どの関数が +プライベートかを決定する。 +名前が C<S_> で始まる全ての関数はプライベートです ("S" は "secret" または +"static" と考えてください)。 +その他の全ての関数は "Perl_" で始まりますが、"Perl_" で始まっているからと +いって API の一部とは限りません。 +(L</Internal Functions> を参照してください。) +関数が API の一部であることを B<確認する> 最も簡単な方法は、 +L<perlapi> からエントリを探すことです。 +もし L<perlapi> にあれば、API の一部です。 +もしなくて、あなたが これは API であるべきと考える(つまり、あなたの +エクステンションに必要)なら、どうしてそう考えるかを説明したメールを +L<perlbug> で送ってください。 =begin original @@ -4752,12 +4751,10 @@ =end original -Second problem: there must be a syntax so that the same subroutine -declarations and calls can pass a structure as their first argument, -or pass nothing. To solve this, the subroutines are named and -declared in a particular way. Here's a typical start of a static -function used within the Perl guts: -(TBT) +二番目の問題: 同じサブルーチン定義と呼び出しが最初の引数として構造体を +渡せるようにするか、何も渡さないようにする文法でなければなりません。 +問題を解決するために、サブルーチンは決められた方法で命名して宣言されます。 +以下は、Perl の内部で使われている静的関数の典型的な開始部分です: STATIC void S_incline(pTHX_ char *s) @@ -4769,9 +4766,8 @@ =end original -STATIC becomes "static" in C, and may be #define'd to nothing in some -configurations in future. -(TBT) +STATIC は C では "static" になり、将来一部の設定では何もしないように +#define されます。 =begin original @@ -4780,9 +4776,8 @@ =end original -A public function (i.e. part of the internal API, but not necessarily -sanctioned for use in extensions) begins like this: -(TBT) +公的な関数(つまり内部 API の一部ですが、エクステンションで使うのに許可は +不要なもの)は以下のように始まります: void Perl_sv_setiv(pTHX_ SV* dsv, IV num) @@ -4798,13 +4793,13 @@ =end original -C<pTHX_> is one of a number of macros (in perl.h) that hide the -details of the interpreter's context. THX stands for "thread", "this", -or "thingy", as the case may be. (And no, George Lucas is not involved. :-) -The first character could be 'p' for a B<p>rototype, 'a' for B<a>rgument, -or 'd' for B<d>eclaration, so we have C<pTHX>, C<aTHX> and C<dTHX>, and -their variants. -(TBT) +C<pTHX_> は、インタプリタのコンテキストの詳細を隠すための(perl.h にある) +多くのマクロの一つです。 +THX は "thread", "this", "thingy" などから来ています。 +(そしてジョージルーカスは関係ありません。:-) +最初の文字は 'p' がプロトタイプ(B<p>rototype)、'a' が引数(B<a>rgument)、 +'d' が宣言(B<d>eclaration) を意味するので、C<pTHX>, C<aTHX>, C<dTHX> および +その変形があります。 =begin original @@ -4819,15 +4814,13 @@ =end original -When Perl is built without options that set PERL_IMPLICIT_CONTEXT, there is no -first argument containing the interpreter's context. The trailing underscore -in the pTHX_ macro indicates that the macro expansion needs a comma -after the context argument because other arguments follow it. If -PERL_IMPLICIT_CONTEXT is not defined, pTHX_ will be ignored, and the -subroutine is not prototyped to take the extra argument. The form of the -macro without the trailing underscore is used when there are no additional -explicit arguments. -(TBT) +PERL_IMPLICIT_CONTEXT が設定されたオプションなしで Perl がビルドされると、 +インタプリタのコンテキストに最初の引数は含まれません。 +pTHX_ マクロの末尾の下線は、他の引数が引き続くのでマクロ拡張はコンテキスト +引数の後にカンマが必要であることを示しています。 +PERL_IMPLICIT_CONTEXT が定義されていない場合、pTHX_ は無視され、 +サブルーチンは追加の引数を取るようなプロトタイプを持ちません。 +引き続く下線なしのマクロの形式は、追加の明示的な引数がない場合に使われます。 =begin original @@ -4837,10 +4830,10 @@ =end original -When a core function calls another, it must pass the context. This -is normally hidden via macros. Consider C<sv_setiv>. It expands into -something like this: -(TBT) +コア関数が他の関数を呼び出すとき、コンテキストを渡さなければなりません。 +これは普通マクロ経由で隠されます。 +C<sv_setiv> を考えてみます。 +これは以下のような感じに展開されます: #ifdef PERL_IMPLICIT_CONTEXT #define sv_setiv(a,b) Perl_sv_setiv(aTHX_ a, b) @@ -4855,8 +4848,7 @@ =end original -This works well, and means that XS authors can gleefully write: -(TBT) +これはうまく動きますし、XS 作者は喜んで以下のように書けます: sv_setiv(foo, bar); @@ -4867,9 +4859,7 @@ =end original -and still have it work under all the modes Perl could have been -compiled with. -(TBT) +そしてやはり Perl がコンパイルされる全てのモードで動作します。 =begin original @@ -4881,12 +4871,11 @@ =end original -This doesn't work so cleanly for varargs functions, though, as macros -imply that the number of arguments is known in advance. Instead we -either need to spell them out fully, passing C<aTHX_> as the first -argument (the Perl core tends to do this with functions like -Perl_warner), or use a context-free version. -(TBT) +しかし、可変長関数ではそれほどきれいには動作しません; マクロは事前に +引数の数が分かっていることを仮定しているからです。 +どちらかを完全に綴る必要があるようにする代わりに、最初の引数として +C<aTHX_> を渡す(Perl コアは Perl_warner のような関数でこれをする +傾向があります)か、コンテキストの影響を受けないバージョンを使います。 =begin original @@ -4899,13 +4888,14 @@ =end original -The context-free version of Perl_warner is called -Perl_warner_nocontext, and does not take the extra argument. Instead -it does dTHX; to get the context from thread-local storage. We -C<#define warner Perl_warner_nocontext> so that extensions get source -compatibility at the expense of performance. (Passing an arg is -cheaper than grabbing it from thread-local storage.) -(TBT) +Perl_warner のコンテキストの影響を受けないバージョンは +Perl_warner_nocontext と呼ばれ、追加の引数を取りません。 +代わりに、スレッドローカルなストレージからコンテキストを得るために +dTHX; します。 +エクステンションが性能のコストでソース互換性を得るために +C<#define warner Perl_warner_nocontext> とします。 +(一つの引数を渡すのはスレッドローカルなストレージから値を取り出すよりも +安価です。) =begin original @@ -4915,10 +4905,9 @@ =end original -You can ignore [pad]THXx when browsing the Perl headers/sources. -Those are strictly for use within the core. Extensions and embedders -need only be aware of [pad]THX. -(TBT) +Perl ヘッダ/ソースを見るときには [pad]THXx を無視できます。 +これらは純粋にコア内部での使用のためのものです。 +エクステンションと組み込みだけが [pad]THX の存在を汁必要があります。 =head2 So what happened to dTHR? @@ -4934,12 +4923,12 @@ =end original -C<dTHR> was introduced in perl 5.005 to support the older thread model. -The older thread model now uses the C<THX> mechanism to pass context -pointers around, so C<dTHR> is not useful any more. Perl 5.6.0 and -later still have it for backward source compatibility, but it is defined -to be a no-op. -(TBT) +C<dTHR> は、古いスレッドモデルに対応するために perl 5.005 で +導入されました。 +古いスレッドモデルは今ではコンテキストのポインタを渡すのに C<THX> 機構を +使うので、C<dTHR> はもはや有用ではありません。 +Perl 5.6.0 以降では、ソースの後方互換性のためにまだ存在していますが、 +何もしないように定義されています。 =head2 How do I use all this in extensions? @@ -4955,12 +4944,11 @@ =end original -When Perl is built with PERL_IMPLICIT_CONTEXT, extensions that call -any functions in the Perl API will need to pass the initial context -argument somehow. The kicker is that you will need to write it in -such a way that the extension still compiles when Perl hasn't been -built with PERL_IMPLICIT_CONTEXT enabled. -(TBT) +Perl が PERL_IMPLICIT_CONTEXT 付きでビルドされると、Perl API の +関数を呼び出すエクステンションは何か初期コンテキスト引数を渡す必要が +あります。 +キッカーは、Perl が PERL_IMPLICIT_CONTEXT を有効にせずにビルドされたときにも +エクステンションがコンパイルできるようにそれを書く方法が必要ということです。 =begin original @@ -4972,12 +4960,12 @@ =end original -There are three ways to do this. First, the easy but inefficient way, -which is also the default, in order to maintain source compatibility -with extensions: whenever XSUB.h is #included, it redefines the aTHX -and aTHX_ macros to call a function that will return the context. -Thus, something like: -(TBT) +これをするには三つの方法があります。 +最初に、簡単だけれども効率的ではない方法ですが、エクステンションのソース +互換性を維持するために、これがデフォルトです: XSUB.h が #include されると、 +コンテキストを返す関数を呼び出すように aTHX と aTHX_ のマクロを +再定義します。 +従って、以下のようなものが: sv_setiv(sv, num); @@ -4988,9 +4976,8 @@ =end original -in your extension will translate to this when PERL_IMPLICIT_CONTEXT is -in effect: -(TBT) +エクステンションにあると、PERL_IMPLICIT_CONTEXT が有効なら、以下のように +翻訳します: Perl_sv_setiv(Perl_get_context(), sv, num); @@ -5000,8 +4987,7 @@ =end original -or to this otherwise: -(TBT) +さもなければ、こうなります: Perl_sv_setiv(sv, num); @@ -5013,10 +4999,9 @@ =end original -You have to do nothing new in your extension to get this; since -the Perl library provides Perl_get_context(), it will all just -work. -(TBT) +これをするためにエクステンション何の新しいこともする必要はありません; +Perl ライブラリは Perl_get_context() を提供するので、全てうまく +動作します。 =begin original @@ -5025,9 +5010,7 @@ =end original -The second, more efficient way is to use the following template for -your Foo.xs: -(TBT) +次に、より効率的な方法は、Foo.xs に以下のテンプレートを使うことです: #define PERL_NO_GET_CONTEXT /* we want efficiency */ #include "EXTERN.h" @@ -5068,15 +5051,14 @@ =end original -Note that the only two changes from the normal way of writing an -extension is the addition of a C<#define PERL_NO_GET_CONTEXT> before -including the Perl headers, followed by a C<dTHX;> declaration at -the start of every function that will call the Perl API. (You'll -know which functions need this, because the C compiler will complain -that there's an undeclared identifier in those functions.) No changes -are needed for the XSUBs themselves, because the XS() macro is -correctly defined to pass in the implicit context if needed. -(TBT) +エクステンションを書く通常の方法とただ二つの違いは、Perl ヘッダを +インクルードする前に C<#define PERL_NO_GET_CONTEXT> を追加して、 +Perl API を呼び出す全ての関数の先頭に C<dTHX;> 宣言を書くということに +注意してください。 +(どの関数にこれが必要なのかは分かります; これらの関数に未宣言の識別子が +あると C コンパイラがエラーを出すからです。) +XSUB 自身には変更は必要荒れません; なぜなら XS() マクロは、もし必要なら +暗黙のコンテキストを渡すように正しく定義されるからです。 =begin original @@ -5085,9 +5067,8 @@ =end original -The third, even more efficient way is to ape how it is done within -the Perl guts: -(TBT) +3 番目に、さらに効率的な方法は、Perl の内部で行われている方法を +真似ることです: #define PERL_NO_GET_CONTEXT /* we want efficiency */ #include "EXTERN.h" @@ -5125,11 +5106,10 @@ =end original -This implementation never has to fetch the context using a function -call, since it is always passed as an extra argument. Depending on -your needs for simplicity or efficiency, you may mix the previous -two approaches freely. -(TBT) +この実装は、関数呼び出しを使ってコンテキストを取得する必要はありません; +なぜなら常に追加の引数として渡されるからです。 +単純さと効率性のどちらが必要かに応じて、前述の二つの手法と自由に +混ぜてもかまいません。 =begin original @@ -5139,10 +5119,9 @@ =end original -Never add a comma after C<pTHX> yourself--always use the form of the -macro with the underscore for functions that take explicit arguments, -or the form without the argument for functions with no explicit arguments. -(TBT) +C<pTHX> の後ろに自分でカンマを追加しないでください -- 明示的な引数を +取る関数の場合は下線のあるマクロの形式を、明示的な引数のない関数では +引数なしの形式を、常に使ってください。 =begin original @@ -5155,13 +5134,12 @@ =end original -If one is compiling Perl with the C<-DPERL_GLOBAL_STRUCT> the C<dVAR> -definition is needed if the Perl global variables (see F<perlvars.h> -or F<globvar.sym>) are accessed in the function and C<dTHX> is not -used (the C<dTHX> includes the C<dVAR> if necessary). One notices -the need for C<dVAR> only with the said compile-time define, because -otherwise the Perl global variables are visible as-is. -(TBT) +C<-DPERL_GLOBAL_STRUCT> 付きで Perl をコンパイルすると、Perl グローバル変数 +(F<perlvars.h> や F<globvar.sym> を参照)が関数内でアクセスされて、 +C<dVAR> が使われない(C<dTHX> は、必要なら C<dVAR> をインクルードします)場合、 +C<dVAR> 定義が必要です。 +C<dVAR> の必要性はコンパイル時の定義でのみ気付きます; なぜならさもなければ +Perl グローバル変数はそのまま見えるからです。 =head2 Should I do anything special if I call perl from multiple threads? @@ -5175,10 +5153,10 @@ =end original -If you create interpreters in one thread and then proceed to call them in -another, you need to make sure perl's own Thread Local Storage (TLS) slot is -initialized correctly in each of those threads. -(TBT) +あるスレッドでインタプリタを作成して、それから他のスレッドでそれを +呼び出そうとするなら、perl の独自のスレッドローカルストレージ +(Thread Local Storage (TLS)) スロットがそれぞれのスレッドで正しく +初期化されるようにする必要があります。 =begin original @@ -5193,15 +5171,14 @@ =end original -The C<perl_alloc> and C<perl_clone> API functions will automatically set -the TLS slot to the interpreter they created, so that there is no need to do -anything special if the interpreter is always accessed in the same thread that -created it, and that thread did not create or call any other interpreters -afterwards. If that is not the case, you have to set the TLS slot of the -thread before calling any functions in the Perl API on that particular -interpreter. This is done by calling the C<PERL_SET_CONTEXT> macro in that -thread as the first thing you do: -(TBT) +C<perl_alloc> と C<perl_clone> の API 関数は、作成されたインタプリタへの +TLS スロットを自動的に設定するので、インタプリタを作成したスレッドと +同じスレッドでだけ使って、そのスレッドがその後他のインタプリタを作成したり +呼び出したりしないのなら、何も特別なことをする必要はありません。 +そうでない場合、特定のインタプリタの Perl API の関数を呼び出す前に、 +そのスレッドの TLS スロットを設定する必要があります。 +これは、そのスレッドで最初にすることとして C<PERL_SET_CONTEXT> マクロを +呼び出すことで行われます: /* do this before doing anything else with some_perl */ PERL_SET_CONTEXT(some_perl); @@ -5223,13 +5200,12 @@ =end original -Just as PERL_IMPLICIT_CONTEXT provides a way to bundle up everything -that the interpreter knows about itself and pass it around, so too are -there plans to allow the interpreter to bundle up everything it knows -about the environment it's running on. This is enabled with the -PERL_IMPLICIT_SYS macro. Currently it only works with USE_ITHREADS on -Windows. -(TBT) +PERL_IMPLICIT_CONTEXT が、インタプリタが自分自身および渡されたものに関して +知っていること全てをまとめる方法を提供しているのとちょうど同じように、 +インタプリタが自分が実行している環境について知っている全てを +まとられるようにする計画があります。 +これは PERL_IMPLICIT_SYS マクロで有効にされます。 +現在のところ、これは Windows で USE_ITHREADS 付きの場合にのみ動作します。 =begin original @@ -5244,15 +5220,15 @@ =end original -This allows the ability to provide an extra pointer (called the "host" -environment) for all the system calls. This makes it possible for -all the system stuff to maintain their own state, broken down into -seven C structures. These are thin wrappers around the usual system -calls (see win32/perllib.c) for the default perl executable, but for a -more ambitious host (like the one that would do fork() emulation) all -the extra work needed to pretend that different interpreters are -actually different "processes", would be done here. -(TBT) +これにより、全てのシステムコールのための(「ホスト」環境と呼ばれる) +追加のポインタを提供する能力を持つようになります。 +これにより、独自の状態を保守する全てのシステムの機能について、七つの +C 構造体に分解することが可能になります。 +デフォルトの perl 実行ファイルのために、通常のシステムコールへの +薄いラッパです (win32/perllib.c を参照してください) が、 +(fork() エミュレーションを行うような)より意欲的なホストのために、 +異なるインタプリタが実際には異なる「プロセス」であることを装うために +必要になる全ての作業は、ここで行われます。 =begin original @@ -5262,10 +5238,9 @@ =end original -The Perl engine/interpreter and the host are orthogonal entities. -There could be one or more interpreters in a process, and one or -more "hosts", with free association between them. -(TBT) +Perl エンジン/インタプリタとホストは直交する概念です。 +一つのプロセスに複数のインタプリタがあることもありますし、複数の「ホスト」が +互いに自由に関連しながらあることもあります。 =head1 Internal Functions @@ -5631,10 +5606,10 @@ =end original -There are a couple of macros to do very basic exception handling in XS -modules. You have to define C<NO_XSLOCKS> before including F<XSUB.h> to -be able to use these macros: -(TBT) +XS モジュールでのとても基本的な例外処理を行うためのいくつかのマクロが +あります。 +これらのマクロを使えるようにするために F<XSUB.h> をインクルードする前に +C<NO_XSLOCKS> を定義する必要があります: #define NO_XSLOCKS #include "XSUB.h" @@ -5646,9 +5621,9 @@ =end original -You can use these macros if you call code that may croak, but you need -to do some cleanup before giving control back to Perl. For example: -(TBT) +croak するかもしれないコードを呼び出すときにこれらのマクロが使えますが、 +Perl に制御を戻す前に一部掃除掃除をする必要があります。 +例えば: dXCPT; /* set up necessary variables */ @@ -5671,11 +5646,9 @@ =end original -Note that you always have to rethrow an exception that has been -caught. Using these macros, it is not possible to just catch the -exception and ignore it. If you have to ignore the exception, you -have to use the C<call_*> function. -(TBT) +捕捉した例外を常に再スローする必要があることに注意してください。 +これらのマクロを使って、単に例外を捕捉して無視することはできません。 +例外を無視する必要があるなら、C<call_*> 関数を使う必要があります。 =begin original @@ -5685,10 +5658,9 @@ =end original -The advantage of using the above macros is that you don't have -to setup an extra function for C<call_*>, and that using these -macros is faster than using C<call_*>. -(TBT) +上述のマクロを使う利点は、C<call_*> のための追加の関数を設定する +必要がないことと、これらのマクロを使うと C<call_*> を使うよりも +高速であることです。 =head2 Source Documentation @@ -5704,12 +5676,11 @@ =end original -There's an effort going on to document the internal functions and -automatically produce reference manuals from them - L<perlapi> is one -such manual which details all the functions which are available to XS -writers. L<perlintern> is the autogenerated manual for the functions -which are not part of the API and are supposedly for internal use only. -(TBT) +内部関数の文書を書いて、そこからリファレンスマニュアルを自動的に +生成しようという作業が行われています - L<perlapi> はその一つで、XS 作者が +利用可能な全ての関数の詳細に関するマニュアルです; +L<perlintern> は、API の一部ではなく、内部使用専用と想定されている関数の +自動生成マニュアルです。 =begin original @@ -5718,9 +5689,8 @@ =end original -Source documentation is created by putting POD comments into the C -source, like this: -(TBT) +ソース文書は、以下のように、C ソースに POD コメントを書くことで +作成されます: /* =for apidoc sv_setiv @@ -5738,9 +5708,7 @@ =end original -Please try and supply some documentation if you add functions to the -Perl core. -(TBT) +Perl コアに関数を追加するなら、文書を書いて提供するようにしてください。 =head2 Backwards compatibility @@ -5755,11 +5723,12 @@ =end original -The Perl API changes over time. New functions are added or the interfaces -of existing functions are changed. The C<Devel::PPPort> module tries to -provide compatibility code for some of these changes, so XS writers don't -have to code it themselves when supporting multiple versions of Perl. -(TBT) +Perl API は時が経つにつれて変わります。 +新しい関数が追加されたり、既にある関数のインターフェースが +変更されたりします。 +C<Devel::PPPort> モジュールはこれらの変更の一部に関して互換コードを +提供しようとするので、XS 作者は複数バージョンの Perl に対応するときに +そのためのコードを自分自身で作る必要はありません。 =begin original @@ -5768,9 +5737,9 @@ =end original -C<Devel::PPPort> generates a C header file F<ppport.h> that can also -be run as a Perl script. To generate F<ppport.h>, run: -(TBT) +C<Devel::PPPort> は、Perl スクリプトとしても実行される C ヘッダファイル +F<ppport.h> を生成します。 +F<ppport.h> を生成するには、以下のものを実行します: perl -MDevel::PPPort -eDevel::PPPort::WriteFile @@ -5782,10 +5751,10 @@ =end original -Besides checking existing XS code, the script can also be used to retrieve -compatibility information for various API calls using the C<--api-info> -command line switch. For example: -(TBT) +既にある XS コードをチェックするほかに、このスクリプトは、C<--api-info> +コマンドラインオプションを使うことで、様々な API 呼び出しの互換性情報を +取得するのにも使えます。 +例えば: % perl ppport.h --api-info=sv_magicext @@ -5809,10 +5778,9 @@ =end original -Perl 5.6.0 introduced Unicode support. It's important for porters and XS -writers to understand this support and make sure that the code they -write does not corrupt Unicode data. -(TBT) +Perl 5.6.0 から Unicode 対応が導入されました。 +porters と XS 作者にとって、この対応を理解して、書いたコードが Unicode +データを壊さないようにすることは重要です。 =head2 What B<is> Unicode, anyway? @@ -5831,15 +5799,15 @@ =end original -In the olden, less enlightened times, we all used to use ASCII. Most of -us did, anyway. The big problem with ASCII is that it's American. Well, -no, that's not actually the problem; the problem is that it's not -particularly useful for people who don't use the Roman alphabet. What -used to happen was that particular languages would stick their own -alphabet in the upper range of the sequence, between 128 and 255. Of -course, we then ended up with plenty of variants that weren't quite -ASCII, and the whole point of it being a standard was lost. -(TBT) +古く、あまり啓蒙されていなかった時代、私たち全ては ASCII を使っていました。 +とりあえず、私たちのほとんどはそうでした。 +ASCII の大きな問題は、これは英語だったことです。 +えっと、これは本当の問題ではありません; 問題は、英文字を使わない +人々にとっては特に有用ではないということです。 +起こったことは、ある種の言語は独自のアルファベットを並びの上半分、 +128 から 255 にくっつけるということでした。 +もちろん、結局完全に ASCII ではないものの変種だらけになり、標準となるものは +失われました。 =begin original @@ -5851,12 +5819,10 @@ =end original -Worse still, if you've got a language like Chinese or -Japanese that has hundreds or thousands of characters, then you really -can't fit them into a mere 256, so they had to forget about ASCII -altogether, and build their own systems using pairs of numbers to refer -to one character. -(TBT) +さらに悪いことに、数百または数千の文字がある中国語や日本語のような言語を +使うとき、これらを単に 256 に納めるのは不可能なので、ASCII を完全に +忘れてしまって、一つの文字を参照するのに二つの数の組み合わせを使う +独自のシステムを構築しました。 =begin original @@ -5869,13 +5835,12 @@ =end original -To fix this, some people formed Unicode, Inc. and -produced a new character set containing all the characters you can -possibly think of and more. There are several ways of representing these -characters, and the one Perl uses is called UTF-8. UTF-8 uses -a variable number of bytes to represent a character. You can learn more -about Unicode and Perl's Unicode model in L<perlunicode>. -(TBT) +これを修正するために、一部の人々は Unicode, Inc. を作り、考えられる全ての +文字以上のものを含む新しい文字集合を作成しました。 +これらの文字を表現するにはいくつかの方法があり、Perl が使うものは +UTF-8 と呼ばれます。 +UTF-8 は 1 文字を表現するのに可変の数のバイトを使います。 +Unicode と Perl の Unicode モデルについては、L<perlunicode> で学べます。 =head2 How can I recognise a UTF-8 string? @@ -5892,13 +5857,15 @@ =end original -You can't. This is because UTF-8 data is stored in bytes just like -non-UTF-8 data. The Unicode character 200, (C<0xC8> for you hex types) -capital E with a grave accent, is represented by the two bytes -C<v196.172>. Unfortunately, the non-Unicode string C<chr(196).chr(172)> -has that byte sequence as well. So you can't tell just by looking - this -is what makes Unicode input an interesting problem. -(TBT) +出来ません。 +これは、UTF-8 データは非 UTF-8 データと同じようにバイトとして +保管されるからです。 +Unicode 文字 200 (16 進数で書くなら C<0xC8>) である、 +大文字 E(重アクセント記号付) は 2 バイト C<v196.172> で表現されます。 +残念ながら、非 Unicode 文字列 C<chr(196).chr(172)> も同じバイト並びを +持ちます。 +従って、見ただけで判断することは出来ません - これが Unicode 入力を +興味深い問題にしているものです。 =begin original @@ -5910,12 +5877,12 @@ =end original -In general, you either have to know what you're dealing with, or you -have to guess. The API function C<is_utf8_string> can help; it'll tell -you if a string contains only valid UTF-8 characters. However, it can't -do the work for you. On a character-by-character basis, C<is_utf8_char> -will tell you whether the current character in a string is valid UTF-8. -(TBT) +一般的に、どうやって扱うかを知るか、推測するかのどちらかが必要です。 +API 関数 C<is_utf8_string> が助けになります; これは、文字列が有効な UTF-8 +文字列のみを含んでいるかを返します。 +しかし、これはあなたのための作業は出来ません。 +文字単位では、C<is_utf8_char> は文字列中の現在の文字が有効な +UTF-8 かどうかを返します。 =head2 How does UTF-8 represent Unicode characters? @@ -5932,13 +5899,13 @@ =end original -As mentioned above, UTF-8 uses a variable number of bytes to store a -character. Characters with values 0...127 are stored in one byte, just -like good ol' ASCII. Character 128 is stored as C<v194.128>; this -continues up to character 191, which is C<v194.191>. Now we've run out of -bits (191 is binary C<10111111>) so we move on; 192 is C<v195.128>. And -so it goes on, moving to three bytes at character 2048. -(TBT) +上述したように、UTF-8 は文字を格納するのに可変の数のバイトを使います。 +値 0...127 の文字はちょうど ASCII と同じように 1 バイトで保管されます。 +文字 128 は C<v194.128> として保管されます; これは 文字 191 C<v194.191> まで +続きます。 +ここでビットがなくなるので (191 は 2 進数では C<10111111>)、次に進みます; +192 は C<v195.128> です。 +このように進んでいき、文字 2048 では 3 バイトになります。 =begin original @@ -5947,9 +5914,8 @@ =end original -Assuming you know you're dealing with a UTF-8 string, you can find out -how long the first character in it is with the C<UTF8SKIP> macro: -(TBT) +UTF-8 文字列の扱い方を知っていると仮定すると、最初の文字の長さは +C<UTF8SKIP> マクロで知ることができます: char *utf = "\305\233\340\240\201"; I32 len; @@ -5967,11 +5933,9 @@ =end original -Another way to skip over characters in a UTF-8 string is to use -C<utf8_hop>, which takes a string and a number of characters to skip -over. You're on your own about bounds checking, though, so don't use it -lightly. -(TBT) +UTF-8 文字列で文字をスキップするもう一つの方法は、C<utf8_hop> を使うことで、 +これは文字列とスキップする文字数を取ります。 +しかし、独自でも境界チェックは出来るので、これを軽率に使わないでください。 =begin original @@ -5982,11 +5946,10 @@ =end original -All bytes in a multi-byte UTF-8 character will have the high bit set, -so you can test if you need to do something special with this -character like this (the UTF8_IS_INVARIANT() is a macro that tests -whether the byte can be encoded as a single byte even in UTF-8): -(TBT) +マルチバイト UTF-8 文字の全てのバイトは最上位ビットが設定されているので、 +このようにこの文字に何か特別のことをする必要がある場合は、これで +テストできます(UTF8_IS_INVARIANT() は、たとえ UTF-8 であったとしても +単一のバイトでエンコードされているかどうかをテストします): U8 *utf; UV uv; /* Note: a UV, not a U8, not a char */ @@ -6006,10 +5969,8 @@ =end original -You can also see in that example that we use C<utf8_to_uv> to get the -value of the character; the inverse function C<uv_to_utf8> is available -for putting a UV into UTF-8: -(TBT) +この例では、文字の値を得るために C<utf8_to_uv> を使うところも見られます; +逆関数 C<uv_to_utf8> は、UV を UTF-8 にするのに使えます: if (!UTF8_IS_INVARIANT(uv)) /* Must treat this as UTF8 */ @@ -6030,14 +5991,13 @@ =end original -You B<must> convert characters to UVs using the above functions if -you're ever in a situation where you have to match UTF-8 and non-UTF-8 -characters. You may not skip over UTF-8 characters in this case. If you -do this, you'll lose the ability to match hi-bit non-UTF-8 characters; -for instance, if your UTF-8 string contains C<v196.172>, and you skip -that character, you can never match a C<chr(200)> in a non-UTF-8 string. -So don't do that! -(TBT) +UTF-8 文字列と非 UTF-8 文字列のマッチングをする必要がある場合は、上述の +関数を使って UV に変換 B<しなければなりません> 。 +このような場合では UTF-8 文字列を読み飛ばすことはできません。 +これをすると、最上位ビットの立った非 UTF-8 文字をマッチングする能力を +失います; 例えば、UTF-8 文字列に C<v196.172> が含まれていて、この文字を +スキップすると、非 UTF-8 文字列の C<chr(200)> にマッチングできません。 +従って、そうしないでください! =head2 How does Perl store UTF-8 strings? @@ -6054,13 +6014,13 @@ =end original -Currently, Perl deals with Unicode strings and non-Unicode strings -slightly differently. A flag in the SV, C<SVf_UTF8>, indicates that the -string is internally encoded as UTF-8. Without it, the byte value is the -codepoint number and vice versa (in other words, the string is encoded -as iso-8859-1). You can check and manipulate this flag with the -following macros: -(TBT) +現在のところ、Perl は Unicode 文字列と非 Unicode 文字列を少し違う形で +扱います。 +SV のフラグ C<SVf_UTF8> は、文字列が内部で UTF-8 で +エンコードされていることを示します。 +これがない場合は、バイトの値が符号位置で、逆も成り立ちます (言い換えると、 +文字列は iso-8859-1 としてエンコードされます)。 +以下のマクロでこのフラグのチェックと操作ができます: SvUTF8(sv) SvUTF8_on(sv) @@ -6075,11 +6035,9 @@ =end original -This flag has an important effect on Perl's treatment of the string: if -Unicode data is not properly distinguished, regular expressions, -C<length>, C<substr> and other string handling operations will have -undesirable results. -(TBT) +このフラグは、Perl の文字列の扱いに重要な効果があります: Unicode データが +適切に識別されないと、正規表現、C<length>、C<substr> およびその他の +文字列操作演算子が想定外の結果となります。 =begin original @@ -6089,10 +6047,9 @@ =end original -The problem comes when you have, for instance, a string that isn't -flagged as UTF-8, and contains a byte sequence that could be UTF-8 - -especially when combining non-UTF-8 and UTF-8 strings. -(TBT) +問題は、例えば、UTF-8 としてフラグが経っていない文字列と、UTF-8 になり得る +バイト並びがある時に起こります - 特に非 UTF-8 文字列と UTF-8 文字列を +結合するときに起こります。 =begin original @@ -6102,10 +6059,9 @@ =end original -Never forget that the C<SVf_UTF8> flag is separate to the PV value; you -need be sure you don't accidentally knock it off while you're -manipulating SVs. More specifically, you cannot expect to do this: -(TBT) +C<SVf_UTF8> フラグは PV の値とは分かれていることを決して忘れないでください; +SV の捜査中に間違ってオフにしないように注意する必要があります。 +より具体的には、以下のようにすることは想定できません: SV *sv; SV *nsv; @@ -6124,10 +6080,10 @@ =end original -The C<char*> string does not tell you the whole story, and you can't -copy or reconstruct an SV just by copying the string value. Check if the -old SV has the UTF8 flag set, and act accordingly: -(TBT) +C<char*> 文字列は一部始終を示しはせず、単に文字列の値をコピーするだけでは +SV のコピーや再構成は出来ません。 +もし古い SV の UTF8 フラグがセットされているかどうかを調べて、それに従って +行動します: p = SvPV(sv, len); frobnicate(p); @@ -6143,10 +6099,8 @@ =end original -In fact, your C<frobnicate> function should be made aware of whether or -not it's dealing with UTF-8 data, so that it can handle the string -appropriately. -(TBT) +実際、C<frobnicate> 関数は、文字列を適切に扱えるようにするために、 +UTF-8 データを扱えるかどうかが分かるようにするべきです。 =begin original @@ -6156,10 +6110,9 @@ =end original -Since just passing an SV to an XS function and copying the data of -the SV is not enough to copy the UTF8 flags, even less right is just -passing a C<char *> to an XS function. -(TBT) +単に XS 関数に SV を渡して、SV のデータをコピーするだけでは、 +UTF8 フラグをコピーするのは不十分です; 正しいのが C<char *> を XS 関数に +渡すことでもです。 =head2 How do I convert a string to UTF-8? @@ -6444,7 +6397,7 @@ Translate: KIMURA Koichi Update: Kentaro Shirakata <argra****@ub32*****> (5.10.0-) -Status: in progress +Status: completed =end meta