Somewhat inspired by your suggestion, and taking some things from the original generated C code, I've currently got something like this:
struct bar*
create_event(foo_sv)
SV* foo_sv
struct type_foo* foo = NULL;
CODE:
if ( SvROK(foo_sv)) {
SV *tmp = (SV*) SvRV(foo_sv);
if ( SvOK (tmp)) {
foo = (struct type_foo*) SvIV(tmp);
}
} else {
warn( "Foo::create_bar() -- foo is not an SV reference" );
XSRETURN_UNDEF;
}
RETVAL = my_c_create_bar(foo);
OUTPUT:
RETVAL
which successfully avoids the warning message I was getting originally. Unfortunately, this is one of those bits of code someone else wrote originally and didn't write tests for, so now I need to go and actually write some tests to make sure this works right.