홈>
이
localtime
를 노출하려는 시도에서 뭔가 잘못하고있는 것 같습니다
Perl 6의 기능 :
use NativeCall;
my class TimeStruct is repr<CStruct> {
has int32 $!tm_sec;
has int32 $!tm_min;
has int32 $!tm_hour;
has int32 $!tm_mday;
has int32 $!tm_mon;
has int32 $!tm_year;
has int32 $!tm_wday;
has int32 $!tm_yday;
has int32 $!tm_isdst;
has Str $!tm_zone;
has long $!tm_gmtoff;
}
sub localtime(uint32 $epoch --> TimeStruct) is native {*}
dd localtime(time); # segfault
perl6-lldb-m
에서 달리기
, 나는 얻는다 :
Process 82758 stopped
* thread #1, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=1, address=0x5ae5dda1)
frame #0: 0x00007fffe852efb4 libsystem_c.dylib`_st_localsub + 13
libsystem_c.dylib`_st_localsub:
-> 0x7fffe852efb4 <+13>: movq (%rdi), %rax
0x7fffe852efb7 <+16>: movq %rax, -0x20(%rbp)
0x7fffe852efbb <+20>: movq 0x8e71d3e(%rip), %rbx ; lclptr
0x7fffe852efc2 <+27>: testq %rbx, %rbx
Target 0: (moar) stopped.
여기서 내가 잘못하고있는 것은 무엇입니까?
업데이트 : 최종 작업 솔루션 :
class TimeStruct is repr<CStruct> {
has int32 $.tm_sec; # *must* be public attributes
has int32 $.tm_min;
has int32 $.tm_hour;
has int32 $.tm_mday;
has int32 $.tm_mon;
has int32 $.tm_year;
has int32 $.tm_wday;
has int32 $.tm_yday;
has int32 $.tm_isdst;
has long $.tm_gmtoff; # these two were
has Str $.time_zone; # in the wrong order
}
sub localtime(int64 $epoch is rw --> TimeStruct) is native {*}
my int64 $epoch = time; # needs a separate definition somehow
dd localtime($epoch);
-
답변 # 1
관련 질문
- c - fcntl을 사용하여 stdout에서 새 파일 설명자를 작성하면 파일에서 실패
- rakudo - NativeCall을 통해 Raku에서 void 구조체 사용
- regex - 프로토 토큰 후보 주문
- perl6 - raku - 문자열에서 그룹을 캡처하는 한 줄 식?
- raku - perl6에서 하위 또는 연산자를 추가하는 것과 다른 유형에 메소드를 추가하는 이유는 무엇입니까?
- perl6 - perl raku 명령 행 프로그램을 실행하면 lib 디렉토리가 현재 작업 디렉토리에 나타납니다어떻게 방지 할 수 있습니까?
- perl6 - 분포 dist-id
- perl6 - 클래스의 오버로드 연산자
- math - Raku에서 C ++과 NativeCall의 다른 출력
localtime()
time_t*
유형의 포인터를 예상합니다. 논쟁으로.time_t
가정 그리고uint32_t
특정 플랫폼에서 호환되는 유형입니다.해야합니다 (속성을 공개하지 않으면 아무것도 볼 수 없지만).
난 당신의
time_t
에 조금 놀랐습니다 64 비트 유형이 아니며apple time.h
를 googled했습니다. 또한 구조체 선언의 마지막 두 속성이 잘못된 순서로되어 있다고 생각합니다.