Skip to content

Commit b23d48e

Browse files
Issues/0111 ctlrender pickup module_name function (#111) (#112)
* fix ctlrender's main function finding function on Windows, fixes #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]>
1 parent c362379 commit b23d48e

File tree

4 files changed

+39
-2
lines changed

4 files changed

+39
-2
lines changed

ctlrender/transform.cc

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -343,8 +343,13 @@ void run_ctl_transform(const ctl_operation_t &ctl_operation, CTLResults *ctl_res
343343
memset(name, 0, strlen(ctl_operation.filename) + 1);
344344
strcpy(name, ctl_operation.filename);
345345

346-
// XXX probably not windows friendly
346+
#ifdef WIN32
347+
char *backslash = strrchr(name, '\\');
348+
char *forwardslash = strrchr(name, '/');
349+
slash = backslash != NULL ? backslash : forwardslash;
350+
#else
347351
slash = strrchr(name, '/');
352+
#endif
348353
if (slash == NULL)
349354
{
350355
module = name;
@@ -377,6 +382,9 @@ void run_ctl_transform(const ctl_operation_t &ctl_operation, CTLResults *ctl_res
377382
{
378383
// XXX CTL library needs to be changed so that we have a better
379384
// XXX 'function not exists' exception.
385+
if (verbosity > 1) {
386+
fprintf(stderr, "No function named main() found, trying <module_name> (%s) instead\n", module);
387+
}
380388
}
381389

382390
try {
@@ -385,7 +393,9 @@ void run_ctl_transform(const ctl_operation_t &ctl_operation, CTLResults *ctl_res
385393
fn = interpreter.newFunctionCall(std::string(module));
386394
}
387395
} catch (...) {
388-
396+
char message_text[512] = {'\0'};
397+
sprintf( message_text, "CTL file must contain either a main or <module_name> (%s) function", module);
398+
THROW(Iex::ArgExc, message_text);
389399
}
390400

391401
if (fn->returnValue()->type().cast<Ctl::VoidType>().refcount() == 0)

unittest/ctlrender/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,7 @@ elseif( NOT TARGET TIFF::TIFF AND NOT OpenEXR_FOUND )
2929
set_property(TEST ctlrender PROPERTY ENVIRONMENT "IS_TIFF_FOUND=0;IS_OPENEXR_FOUND=0")
3030
endif()
3131

32+
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)
3233

34+
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)
35+
set_tests_properties("ctlrender-ctl-function-name-is-incorrect" PROPERTIES WILL_FAIL TRUE)
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
void functionname_is_filename
2+
(output varying half rOut,
3+
output varying half gOut,
4+
output varying half bOut,
5+
input varying half rIn,
6+
input varying half gIn,
7+
input varying half bIn)
8+
{
9+
rOut=rIn;
10+
gOut=gIn;
11+
bOut=bIn;
12+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
void bad_functionname
2+
(output varying half rOut,
3+
output varying half gOut,
4+
output varying half bOut,
5+
input varying half rIn,
6+
input varying half gIn,
7+
input varying half bIn)
8+
{
9+
rOut = rIn;
10+
gOut = gIn;
11+
bOut = bIn;
12+
}

0 commit comments

Comments
 (0)