Skip to content

Commit

Permalink
Issues/0111 ctlrender pickup module_name function (ampas#111) (ampas#112
Browse files Browse the repository at this point in the history
)

* fix ctlrender's main function finding function on Windows, fixes ampas#111 

* check for both forward and backslash in win32

* add test using functionname_is_filename.ctl

* add improved error handling when correct function name cannot be found

* add a test that checks ctlrender fails when a ctl module does not
  contain a function name that is either main or the same as the
  module name

* add incorrect_function_name.ctl

Co-authored-by: michaeldsmith <[email protected]>
  • Loading branch information
ThomasWilshaw and michaeldsmith authored Jan 6, 2023
1 parent c362379 commit b23d48e
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 2 deletions.
14 changes: 12 additions & 2 deletions ctlrender/transform.cc
Original file line number Diff line number Diff line change
Expand Up @@ -343,8 +343,13 @@ void run_ctl_transform(const ctl_operation_t &ctl_operation, CTLResults *ctl_res
memset(name, 0, strlen(ctl_operation.filename) + 1);
strcpy(name, ctl_operation.filename);

// XXX probably not windows friendly
#ifdef WIN32
char *backslash = strrchr(name, '\\');
char *forwardslash = strrchr(name, '/');
slash = backslash != NULL ? backslash : forwardslash;
#else
slash = strrchr(name, '/');
#endif
if (slash == NULL)
{
module = name;
Expand Down Expand Up @@ -377,6 +382,9 @@ void run_ctl_transform(const ctl_operation_t &ctl_operation, CTLResults *ctl_res
{
// XXX CTL library needs to be changed so that we have a better
// XXX 'function not exists' exception.
if (verbosity > 1) {
fprintf(stderr, "No function named main() found, trying <module_name> (%s) instead\n", module);
}
}

try {
Expand All @@ -385,7 +393,9 @@ void run_ctl_transform(const ctl_operation_t &ctl_operation, CTLResults *ctl_res
fn = interpreter.newFunctionCall(std::string(module));
}
} catch (...) {

char message_text[512] = {'\0'};
sprintf( message_text, "CTL file must contain either a main or <module_name> (%s) function", module);
THROW(Iex::ArgExc, message_text);
}

if (fn->returnValue()->type().cast<Ctl::VoidType>().refcount() == 0)
Expand Down
3 changes: 3 additions & 0 deletions unittest/ctlrender/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,7 @@ elseif( NOT TARGET TIFF::TIFF AND NOT OpenEXR_FOUND )
set_property(TEST ctlrender PROPERTY ENVIRONMENT "IS_TIFF_FOUND=0;IS_OPENEXR_FOUND=0")
endif()

add_test(NAME "ctlrender-ctl-function-name-is-filename" COMMAND ctlrender -force -format exr32 -ctl "${PROJECT_SOURCE_DIR}/unittest/ctlrender/functionname_is_filename.ctl" "${PROJECT_SOURCE_DIR}/unittest/ctlrender/bars_photoshop.exr" out.exr)

add_test(NAME "ctlrender-ctl-function-name-is-incorrect" COMMAND ctlrender -force -format exr32 -ctl "${PROJECT_SOURCE_DIR}/unittest/ctlrender/incorrect_function_name.ctl" "${PROJECT_SOURCE_DIR}/unittest/ctlrender/bars_photoshop.exr" out.exr)
set_tests_properties("ctlrender-ctl-function-name-is-incorrect" PROPERTIES WILL_FAIL TRUE)
12 changes: 12 additions & 0 deletions unittest/ctlrender/functionname_is_filename.ctl
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
void functionname_is_filename
(output varying half rOut,
output varying half gOut,
output varying half bOut,
input varying half rIn,
input varying half gIn,
input varying half bIn)
{
rOut=rIn;
gOut=gIn;
bOut=bIn;
}
12 changes: 12 additions & 0 deletions unittest/ctlrender/incorrect_function_name.ctl
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
void bad_functionname
(output varying half rOut,
output varying half gOut,
output varying half bOut,
input varying half rIn,
input varying half gIn,
input varying half bIn)
{
rOut = rIn;
gOut = gIn;
bOut = bIn;
}

0 comments on commit b23d48e

Please sign in to comment.