문제

다음 예제와 같이 RB_PROTECT로 rb_require를 사용하고 싶습니다.

int error;
rb_protect( (VALUE (*)(VALUE))rb_require, (VALUE) "./test", &error);
.

하지만 컴파일 할 때이 오류가 발생합니다 :

passing argument 1 of ‘rb_protect’ from incompatible pointer type [enabled by default]
/usr/include/ruby-1.9.1/ruby/intern.h:357:7: note: expected ‘VALUE (*)(VALUE)’ but argument is of type ‘VALUE (*)(VALUE,  VALUE)’
.

Google을 검색하여 rb_protect로 rb_require를 사용하는 방법을 확인한 후 :

int error;
rb_protect( RUBY_METHOD_FUNC(rb_require), (VALUE) "./test", &error);
.

또는

VALUE require_wrap(VALUE arg)
{
return rb_require("./test");
}
/*in main:*/
rb_protect( require_wrap, 0, & error);
.

그러나 항상 동일한 오류가 발생합니다.이 오류는 컴파일을 중지하지 않지만 RB_PROTECT가없는 모든 것이 작동하는 반면에 이진 세그트가 작동합니다.

__ 편집 __

내 소스 파일에 오류가 발생했습니다.실제로 내가 테스트 한 모든 솔루션은 잘 작동합니다 :

int error;
rb_protect( (VALUE (*)(VALUE))rb_require, (VALUE) "./test", &error);
.

또는

int error;
rb_protect( RUBY_METHOD_FUNC(rb_require), (VALUE) "./test", &error);
.

또는

VALUE require_wrap(VALUE arg)
{
  return rb_require("./test");
}
/*in main:*/
rb_protect( require_wrap, 0, & error);
.

감사합니다

도움이 되었습니까?

해결책

잘 작동하는 솔루션 :

int error;
rb_protect( (VALUE (*)(VALUE))rb_require, (VALUE) "./test", &error);
.

또는

int error;
rb_protect( RUBY_METHOD_FUNC(rb_require), (VALUE) "./test", &error);
.

또는

VALUE require_wrap(VALUE arg)
{
  return rb_require("./test");
}
/*in main:*/
rb_protect( require_wrap, 0, & error);
.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top