-
Notifications
You must be signed in to change notification settings - Fork 7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Drop virtual from private member functions of Decoder class #4027
Drop virtual from private member functions of Decoder class #4027
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Given that the classes are public, have you checked if anyone else inherits it outside of TorchVision (Github and FBcode)? What if we replace the reinterpret_cast
with dynamic_cast
and keep the fields virtual?
Edit:
Yeah that's not going to be a simple change:
decoder.cpp:106:17: error: 'void' is not a class type
decoder = dynamic_cast<Decoder*>(context->opaque);
^ ~~~~~~~~~~~~~~~
Dynamic casting is not going to happen if we use void* pointers all over the place. Also I don't see any other way to make the following method compile and maintaining readCallback
virtual without changing the method signature and rewriting large parts of the code:
vision/torchvision/csrc/io/decoder/decoder.cpp
Lines 170 to 176 in 810811f
int Decoder::readFunction(void* opaque, uint8_t* buf, int size) { | |
Decoder* decoder = reinterpret_cast<Decoder*>(opaque); | |
if (decoder == nullptr) { | |
return 0; | |
} | |
return decoder->readCallback(buf, size); | |
} |
I have not checked on GitHub. Here is the diff to check tests in fbcode with this change: D28995387. |
@prabhat00155 I was editing my reply as you were responding... That's the 2nd time this happens to me today. 😄 Check again... |
Yeah, opaque is a void *. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thanks!
…4027) Reviewed By: fmassa Differential Revision: D29097737 fbshipit-source-id: b317a34c7a0fa4dc77efbc05a54141c69bf3c1fd
Only
SyncDecoder
class inheritsDecoder
class and I don't see any of these functions(marked virtual) being overwritten there.enableLogLevel() and logCallback() functions being marked virtual is causing segfault when we cast void * to Decoder * and then call these virtual functions. Objects of classes with virtual function have a VPTR data member pointing to the VTABLE. Since, we are type-casting to Decoder * here, I think it doesn't have that information and hence throwing SIGSEGV.
For more information, check T91816044(FB internal task).