Upgrade to Pro — share decks privately, control downloads, hide ads and more …

せっかくなのでYokohama.pmでGoとPerlの話

acidlemon
November 28, 2014

 せっかくなのでYokohama.pmでGoとPerlの話

Yokohama.pm #12 スライド

acidlemon

November 28, 2014
Tweet

More Decks by acidlemon

Other Decks in Technology

Transcript

  1. ࣗݾ঺հ w ɹɹɹ!BDJEMFNPO w ໘ന๏ਓΧϠοΫ
 ιʔγϟϧήʔϜࣄۀ෦νʔϑΤϯδχΞ ࣗশ  w $

    ೥+BWB೥1FSM೥(P൒೥
 ͋ͱ0CKFDUJWF$$ ͱ͔ w *46$0/ഊୀɺग़୊ɺഊୀ w Ίͬͨʹ֎෦Ͱొஃ͠·ͤΜ ͻ͖͜΋Γ 
 ࠓճ͸ձ৔͕ࣗࣾʹདྷͨͷͰొஃͨ͠
  2. (PͰॻ͍ͯΈΔ w (Pʹ͸DHPͱ͍͏࢓૊Έ͕͋Δɻ
 (PͷϑΝΠϧͷ࠷ॳʹ$ͷίʔυΛίϝϯτͰ ॻ͘ͱΑ͠ͳʹऔΓࠐΜͰ͘ΕΔ package main /* #include <stdio.h>

    const char* MyWorldName() { return "Go and C"; } */ import "C" import "fmt" func main() { fmt.Println("Hello!", C.GoString(C.MyWorldName()), "World!") }
  3. ͔ͤͬ͘ͳͷͰฒྻ࣮ߦ func main() { C.init_perl() // Perl準備 wg := sync.WaitGroup{}

    // goroutine待ち合わせの準備 // 並列列実⾏行行するルーチン test_func := func() { defer wg.Done() // Perlの⽂文を評価してスカラ値を取得 sval := C.Perl_eval_pv(C.CString("my $powawa = 3; $powawa *= 3"), 1) fmt.Printf("powawa = %v\n", C.Sv2Iv(sval)) } // 2並列列で実⾏行行して結果を待つ wg.Add(2) go test_func() go test_func() wg.Wait() C.term_perl() }
  4. ࣮ߦ݁Ռ w ཧ૝ w ݱ࣮ powawa = 9 powawa =

    9 fatal error: unexpected signal during runtime execution [signal 0xb code=0x1 addr=0x262d2750 pc=0x40890bc] runtime stack: runtime: unexpected return pc for runtime.sigpanic called from 0x40890bc runtime.throw(0x426ca16) /Users/kawazoel/.homebrew/Cellar/go/1.3.1/libexec/src/pkg/runtime/ panic.c:520 +0x69 runtime: unexpected return pc for runtime.sigpanic called from 0x40890bc runtime.sigpanic() /Users/kawazoel/.homebrew/Cellar/go/1.3.1/libexec/src/pkg/runtime/ os_darwin.c:439 +0x3d
  5. --%#ͰݪҼΛ֬ೝ w ຖճࢮ͵৔ॴ͕มΘΔ w ͭͷΠϯλϓϦλͰಉ࣮࣌ߦͨ͠ͷͰΠϯλϓϦλ಺ͷ
 εςʔτΛഁյͨͬ͠Ά͍งғؾΛײ͡Δ ͬͯͨ͠ (lldb) run Process

    11751 launched: '/Users/kawazoel/letsgo_perl/golang/parallel' (x86_64) Process 11751 stopped * thread #1: tid = 0xb7a9af, 0x0000000004084fd2 parallel`Perl_op_clear(o=0x0000000005100350) + 498 at op.c:625, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=EXC_I386_GPFLT) frame #0: 0x0000000004084fd2 parallel`Perl_op_clear(o=0x0000000005100350) + 498 at op.c:625 622 allowed to raise and lower references during global destruction, 623 so any *valid* code that happens to do this during global 624 destruction might well trigger premature cleanup. */ -> 625 bool still_valid = gv && SvREFCNT(gv); 626 627 if (still_valid) 628 SvREFCNT_inc_simple_void(gv);
  6. ࣮ࡍʹ΍ͬͯΈΔ w ͍͖ͳΓίϯύΠϧ͕௨Βͳ͍ w ௐ΂ͯΈΔͱɺ1FSMͷ$ؔ਺͸VTFUISFBET͢Δͱ͖ͱ
 ͠ͳ͍ͱ͖Ͱؔ਺ͷએݴ͕มΘΔ w VTFUISFBET͢Δͱ΄΅શ෦ୈҰҾ਺ʹ1FSM*OUFSQSFUFSͷ
 ϙΠϯλΛͱΔˠ౉͢ඞཁ͕ w

    ࢓ํͳ͍ͷͰΤϥʔݟͳ͕Β͕Μ͹ͬͯ௚͢ In file included from ./parallel.go:4:0: ./parallel.go: In function 'init_perl': /usr/lib64/perl5/CORE/perl.h:189:16: error: 'my_perl' undeclared (first use in this function) # define aTHX my_perl
  7. ϥΠϒϥϦԽ΁ͷಓ w Α͠΍ΔͧͱࢥͬͯHJUIVCΛ୳ͨ͠Β͋ͬͨ w HJUIVCDPNCSBEpU[DBNQIFS
 $BNFM ϥΫμ  (PQIFS (PͷϚείοτ

    DBNQIFSΒ͍͠ w (PPHMFͷਓ͔ͩͯ༗໊ͳਓ΍ͳ͍͔ w ιʔεͷίϝϯτʹ஫໨
 1BUDIFTXFMDPNF PSZPVDBOUBLFPWFSNBJOUBJOFSTIJQUPP 
 ͩͦ͏Ͱ͢