summaryrefslogtreecommitdiffstats
path: root/ppapi
diff options
context:
space:
mode:
authorteravest@chromium.org <teravest@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-04-19 14:25:18 +0000
committerteravest@chromium.org <teravest@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-04-19 14:25:18 +0000
commit135f59435e8aa4ee4ef60014569ab50fd5ff7775 (patch)
treeb56db7ff1af4b410d339ee849b756d5071279c40 /ppapi
parenta2553844dcff08889fb953ed629f46d0221a6ea1 (diff)
downloadchromium_src-135f59435e8aa4ee4ef60014569ab50fd5ff7775.zip
chromium_src-135f59435e8aa4ee4ef60014569ab50fd5ff7775.tar.gz
chromium_src-135f59435e8aa4ee4ef60014569ab50fd5ff7775.tar.bz2
Pepper: Simplify idl_thunk implementation.
This gets rid of some code duplication, and rewrites functions in thunk files which return void to an alternate, equivalent form. BUG= Review URL: https://codereview.chromium.org/14161017 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@195180 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ppapi')
-rwxr-xr-xppapi/generators/idl_thunk.py75
-rw-r--r--ppapi/thunk/ppb_audio_input_dev_thunk.cc7
-rw-r--r--ppapi/thunk/ppb_console_thunk.cc12
-rw-r--r--ppapi/thunk/ppb_content_decryptor_private_thunk.cc90
-rw-r--r--ppapi/thunk/ppb_file_io_thunk.cc7
-rw-r--r--ppapi/thunk/ppb_find_dev_thunk.cc14
-rw-r--r--ppapi/thunk/ppb_gamepad_thunk.cc6
-rw-r--r--ppapi/thunk/ppb_messaging_thunk.cc7
-rw-r--r--ppapi/thunk/ppb_url_loader_thunk.cc5
-rw-r--r--ppapi/thunk/ppb_url_loader_trusted_thunk.cc12
-rw-r--r--ppapi/thunk/ppb_widget_dev_thunk.cc12
11 files changed, 125 insertions, 122 deletions
diff --git a/ppapi/generators/idl_thunk.py b/ppapi/generators/idl_thunk.py
index d183e4b..7159412 100755
--- a/ppapi/generators/idl_thunk.py
+++ b/ppapi/generators/idl_thunk.py
@@ -279,60 +279,43 @@ def _MakeNormalMemberBody(filenode, release, node, member, rtype, args,
handle_errors = not (member.GetProperty('report_errors') == 'False')
out_params = _GetOutputParams(member, release)
if is_callback_func:
- # TODO(teravest): Reduce code duplication below.
body = '%s\n' % _MakeEnterLine(filenode, node, member, args[0],
handle_errors, args[len(args) - 1][1], meta)
- value = member.GetProperty('on_failure')
- if value is None:
- value = 'enter.retval()'
- if member.GetProperty('always_set_output_parameters'):
- body += 'if (enter.failed()) {\n'
- for param in out_params:
- body += ' memset(%s, 0, sizeof(*%s));\n' % (param, param)
- body += ' return %s;\n' % value
- body += '}\n'
- body += 'return enter.SetResult(%s);' % invocation
- meta.AddBuiltinInclude('string.h')
- else:
- body += 'if (enter.failed())\n'
- body += ' return %s;\n' % value
- body += 'return enter.SetResult(%s);' % invocation
+ failure_value = member.GetProperty('on_failure')
+ if failure_value is None:
+ failure_value = 'enter.retval()'
+ failure_return = 'return %s;' % failure_value
+ success_return = 'return enter.SetResult(%s);' % invocation
elif rtype == 'void':
body = '%s\n' % _MakeEnterLine(filenode, node, member, args[0],
handle_errors, None, meta)
- if member.GetProperty('always_set_output_parameters'):
- body += 'if (enter.succeeded()) {\n'
- body += ' %s;\n' % invocation
- body += ' return;\n'
- body += '}'
- for param in out_params:
- body += '\nmemset(%s, 0, sizeof(*%s));' % (param, param)
- meta.AddBuiltinInclude('string.h')
- else:
- body += 'if (enter.succeeded())\n'
- body += ' %s;' % invocation
-
+ failure_return = 'return;'
+ success_return = '%s;' % invocation # We don't return anything for void.
else:
- value = member.GetProperty('on_failure')
- if value is None:
- value = _GetDefaultFailureValue(rtype)
- if value is None:
- raise TGenError('No default value for rtype %s' % rtype)
-
body = '%s\n' % _MakeEnterLine(filenode, node, member, args[0],
handle_errors, None, meta)
- if member.GetProperty('always_set_output_parameters'):
- body += 'if (enter.failed()) {\n'
- for param in out_params:
- body += ' memset(%s, 0, sizeof(*%s));\n' % (param, param)
- body += ' return %s;\n' % value
- body += '}\n'
- body += 'return %s;' % invocation
- meta.AddBuiltinInclude('string.h')
- else:
- body += 'if (enter.failed())\n'
- body += ' return %s;\n' % value
- body += 'return %s;' % invocation
+ failure_value = member.GetProperty('on_failure')
+ if failure_value is None:
+ failure_value = _GetDefaultFailureValue(rtype)
+ if failure_value is None:
+ raise TGenError('There is no default value for rtype %s. '
+ 'Maybe you should provide an on_failure attribute '
+ 'in the IDL file.' % rtype)
+ failure_return = 'return %s;' % failure_value
+ success_return = 'return %s;' % invocation
+
+ if member.GetProperty('always_set_output_parameters'):
+ body += 'if (enter.failed()) {\n'
+ for param in out_params:
+ body += ' memset(%s, 0, sizeof(*%s));\n' % (param, param)
+ body += ' %s\n' % failure_return
+ body += '}\n'
+ body += '%s' % success_return
+ meta.AddBuiltinInclude('string.h')
+ else:
+ body += 'if (enter.failed())\n'
+ body += ' %s\n' % failure_return
+ body += '%s' % success_return
return body
diff --git a/ppapi/thunk/ppb_audio_input_dev_thunk.cc b/ppapi/thunk/ppb_audio_input_dev_thunk.cc
index 9eb2e3c..2a78737 100644
--- a/ppapi/thunk/ppb_audio_input_dev_thunk.cc
+++ b/ppapi/thunk/ppb_audio_input_dev_thunk.cc
@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-// From dev/ppb_audio_input_dev.idl modified Thu Mar 28 11:12:59 2013.
+// From dev/ppb_audio_input_dev.idl modified Tue Apr 16 11:25:44 2013.
#include "ppapi/c/dev/ppb_audio_input_dev.h"
#include "ppapi/c/pp_completion_callback.h"
@@ -110,8 +110,9 @@ PP_Bool StopCapture(PP_Resource audio_input) {
void Close(PP_Resource audio_input) {
VLOG(4) << "PPB_AudioInput_Dev::Close()";
EnterResource<PPB_AudioInput_API> enter(audio_input, true);
- if (enter.succeeded())
- enter.object()->Close();
+ if (enter.failed())
+ return;
+ enter.object()->Close();
}
const PPB_AudioInput_Dev_0_2 g_ppb_audioinput_dev_thunk_0_2 = {
diff --git a/ppapi/thunk/ppb_console_thunk.cc b/ppapi/thunk/ppb_console_thunk.cc
index 9af6b20..80b115c 100644
--- a/ppapi/thunk/ppb_console_thunk.cc
+++ b/ppapi/thunk/ppb_console_thunk.cc
@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-// From ppb_console.idl modified Thu Dec 20 13:10:26 2012.
+// From ppb_console.idl modified Tue Apr 16 11:25:44 2013.
#include "ppapi/c/pp_errors.h"
#include "ppapi/c/ppb_console.h"
@@ -20,8 +20,9 @@ namespace {
void Log(PP_Instance instance, PP_LogLevel level, struct PP_Var value) {
VLOG(4) << "PPB_Console::Log()";
EnterInstance enter(instance);
- if (enter.succeeded())
- enter.functions()->Log(instance, level, value);
+ if (enter.failed())
+ return;
+ enter.functions()->Log(instance, level, value);
}
void LogWithSource(PP_Instance instance,
@@ -30,8 +31,9 @@ void LogWithSource(PP_Instance instance,
struct PP_Var value) {
VLOG(4) << "PPB_Console::LogWithSource()";
EnterInstance enter(instance);
- if (enter.succeeded())
- enter.functions()->LogWithSource(instance, level, source, value);
+ if (enter.failed())
+ return;
+ enter.functions()->LogWithSource(instance, level, source, value);
}
const PPB_Console_1_0 g_ppb_console_thunk_1_0 = {
diff --git a/ppapi/thunk/ppb_content_decryptor_private_thunk.cc b/ppapi/thunk/ppb_content_decryptor_private_thunk.cc
index 03cd778..9450eed 100644
--- a/ppapi/thunk/ppb_content_decryptor_private_thunk.cc
+++ b/ppapi/thunk/ppb_content_decryptor_private_thunk.cc
@@ -3,7 +3,7 @@
// found in the LICENSE file.
// From private/ppb_content_decryptor_private.idl,
-// modified Thu Mar 28 11:12:59 2013.
+// modified Tue Apr 16 11:25:44 2013.
#include "ppapi/c/pp_errors.h"
#include "ppapi/c/private/ppb_content_decryptor_private.h"
@@ -24,8 +24,9 @@ void NeedKey(PP_Instance instance,
struct PP_Var init_data) {
VLOG(4) << "PPB_ContentDecryptor_Private::NeedKey()";
EnterInstance enter(instance);
- if (enter.succeeded())
- enter.functions()->NeedKey(instance, key_system, session_id, init_data);
+ if (enter.failed())
+ return;
+ enter.functions()->NeedKey(instance, key_system, session_id, init_data);
}
void KeyAdded(PP_Instance instance,
@@ -33,8 +34,9 @@ void KeyAdded(PP_Instance instance,
struct PP_Var session_id) {
VLOG(4) << "PPB_ContentDecryptor_Private::KeyAdded()";
EnterInstance enter(instance);
- if (enter.succeeded())
- enter.functions()->KeyAdded(instance, key_system, session_id);
+ if (enter.failed())
+ return;
+ enter.functions()->KeyAdded(instance, key_system, session_id);
}
void KeyMessage(PP_Instance instance,
@@ -44,12 +46,13 @@ void KeyMessage(PP_Instance instance,
struct PP_Var default_url) {
VLOG(4) << "PPB_ContentDecryptor_Private::KeyMessage()";
EnterInstance enter(instance);
- if (enter.succeeded())
- enter.functions()->KeyMessage(instance,
- key_system,
- session_id,
- message,
- default_url);
+ if (enter.failed())
+ return;
+ enter.functions()->KeyMessage(instance,
+ key_system,
+ session_id,
+ message,
+ default_url);
}
void KeyError(PP_Instance instance,
@@ -59,12 +62,13 @@ void KeyError(PP_Instance instance,
int32_t system_code) {
VLOG(4) << "PPB_ContentDecryptor_Private::KeyError()";
EnterInstance enter(instance);
- if (enter.succeeded())
- enter.functions()->KeyError(instance,
- key_system,
- session_id,
- media_error,
- system_code);
+ if (enter.failed())
+ return;
+ enter.functions()->KeyError(instance,
+ key_system,
+ session_id,
+ media_error,
+ system_code);
}
void DeliverBlock(PP_Instance instance,
@@ -72,10 +76,11 @@ void DeliverBlock(PP_Instance instance,
const struct PP_DecryptedBlockInfo* decrypted_block_info) {
VLOG(4) << "PPB_ContentDecryptor_Private::DeliverBlock()";
EnterInstance enter(instance);
- if (enter.succeeded())
- enter.functions()->DeliverBlock(instance,
- decrypted_block,
- decrypted_block_info);
+ if (enter.failed())
+ return;
+ enter.functions()->DeliverBlock(instance,
+ decrypted_block,
+ decrypted_block_info);
}
void DecoderInitializeDone(PP_Instance instance,
@@ -84,11 +89,12 @@ void DecoderInitializeDone(PP_Instance instance,
PP_Bool success) {
VLOG(4) << "PPB_ContentDecryptor_Private::DecoderInitializeDone()";
EnterInstance enter(instance);
- if (enter.succeeded())
- enter.functions()->DecoderInitializeDone(instance,
- decoder_type,
- request_id,
- success);
+ if (enter.failed())
+ return;
+ enter.functions()->DecoderInitializeDone(instance,
+ decoder_type,
+ request_id,
+ success);
}
void DecoderDeinitializeDone(PP_Instance instance,
@@ -96,10 +102,11 @@ void DecoderDeinitializeDone(PP_Instance instance,
uint32_t request_id) {
VLOG(4) << "PPB_ContentDecryptor_Private::DecoderDeinitializeDone()";
EnterInstance enter(instance);
- if (enter.succeeded())
- enter.functions()->DecoderDeinitializeDone(instance,
- decoder_type,
- request_id);
+ if (enter.failed())
+ return;
+ enter.functions()->DecoderDeinitializeDone(instance,
+ decoder_type,
+ request_id);
}
void DecoderResetDone(PP_Instance instance,
@@ -107,8 +114,9 @@ void DecoderResetDone(PP_Instance instance,
uint32_t request_id) {
VLOG(4) << "PPB_ContentDecryptor_Private::DecoderResetDone()";
EnterInstance enter(instance);
- if (enter.succeeded())
- enter.functions()->DecoderResetDone(instance, decoder_type, request_id);
+ if (enter.failed())
+ return;
+ enter.functions()->DecoderResetDone(instance, decoder_type, request_id);
}
void DeliverFrame(PP_Instance instance,
@@ -116,10 +124,11 @@ void DeliverFrame(PP_Instance instance,
const struct PP_DecryptedFrameInfo* decrypted_frame_info) {
VLOG(4) << "PPB_ContentDecryptor_Private::DeliverFrame()";
EnterInstance enter(instance);
- if (enter.succeeded())
- enter.functions()->DeliverFrame(instance,
- decrypted_frame,
- decrypted_frame_info);
+ if (enter.failed())
+ return;
+ enter.functions()->DeliverFrame(instance,
+ decrypted_frame,
+ decrypted_frame_info);
}
void DeliverSamples(
@@ -128,10 +137,11 @@ void DeliverSamples(
const struct PP_DecryptedBlockInfo* decrypted_block_info) {
VLOG(4) << "PPB_ContentDecryptor_Private::DeliverSamples()";
EnterInstance enter(instance);
- if (enter.succeeded())
- enter.functions()->DeliverSamples(instance,
- audio_frames,
- decrypted_block_info);
+ if (enter.failed())
+ return;
+ enter.functions()->DeliverSamples(instance,
+ audio_frames,
+ decrypted_block_info);
}
const PPB_ContentDecryptor_Private_0_6
diff --git a/ppapi/thunk/ppb_file_io_thunk.cc b/ppapi/thunk/ppb_file_io_thunk.cc
index 2f7d149..331d190 100644
--- a/ppapi/thunk/ppb_file_io_thunk.cc
+++ b/ppapi/thunk/ppb_file_io_thunk.cc
@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-// From ppb_file_io.idl modified Mon Mar 18 13:58:22 2013.
+// From ppb_file_io.idl modified Tue Apr 16 11:25:44 2013.
#include "ppapi/c/pp_completion_callback.h"
#include "ppapi/c/pp_errors.h"
@@ -120,8 +120,9 @@ int32_t Flush(PP_Resource file_io, struct PP_CompletionCallback callback) {
void Close(PP_Resource file_io) {
VLOG(4) << "PPB_FileIO::Close()";
EnterResource<PPB_FileIO_API> enter(file_io, true);
- if (enter.succeeded())
- enter.object()->Close();
+ if (enter.failed())
+ return;
+ enter.object()->Close();
}
int32_t ReadToArray(PP_Resource file_io,
diff --git a/ppapi/thunk/ppb_find_dev_thunk.cc b/ppapi/thunk/ppb_find_dev_thunk.cc
index 7fe79b4..79a1085 100644
--- a/ppapi/thunk/ppb_find_dev_thunk.cc
+++ b/ppapi/thunk/ppb_find_dev_thunk.cc
@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-// From dev/ppb_find_dev.idl modified Thu Dec 20 13:10:26 2012.
+// From dev/ppb_find_dev.idl modified Tue Apr 16 11:25:44 2013.
#include "ppapi/c/dev/ppb_find_dev.h"
#include "ppapi/c/pp_errors.h"
@@ -22,17 +22,17 @@ void NumberOfFindResultsChanged(PP_Instance instance,
PP_Bool final_result) {
VLOG(4) << "PPB_Find_Dev::NumberOfFindResultsChanged()";
EnterInstance enter(instance);
- if (enter.succeeded())
- enter.functions()->NumberOfFindResultsChanged(instance,
- total,
- final_result);
+ if (enter.failed())
+ return;
+ enter.functions()->NumberOfFindResultsChanged(instance, total, final_result);
}
void SelectedFindResultChanged(PP_Instance instance, int32_t index) {
VLOG(4) << "PPB_Find_Dev::SelectedFindResultChanged()";
EnterInstance enter(instance);
- if (enter.succeeded())
- enter.functions()->SelectedFindResultChanged(instance, index);
+ if (enter.failed())
+ return;
+ enter.functions()->SelectedFindResultChanged(instance, index);
}
const PPB_Find_Dev_0_3 g_ppb_find_dev_thunk_0_3 = {
diff --git a/ppapi/thunk/ppb_gamepad_thunk.cc b/ppapi/thunk/ppb_gamepad_thunk.cc
index e2f0160..e36af34 100644
--- a/ppapi/thunk/ppb_gamepad_thunk.cc
+++ b/ppapi/thunk/ppb_gamepad_thunk.cc
@@ -23,11 +23,11 @@ namespace {
void Sample(PP_Instance instance, struct PP_GamepadsSampleData* data) {
VLOG(4) << "PPB_Gamepad::Sample()";
EnterInstanceAPI<PPB_Gamepad_API> enter(instance);
- if (enter.succeeded()) {
- enter.functions()->Sample(instance, data);
+ if (enter.failed()) {
+ memset(data, 0, sizeof(*data));
return;
}
- memset(data, 0, sizeof(*data));
+ enter.functions()->Sample(instance, data);
}
const PPB_Gamepad_1_0 g_ppb_gamepad_thunk_1_0 = {
diff --git a/ppapi/thunk/ppb_messaging_thunk.cc b/ppapi/thunk/ppb_messaging_thunk.cc
index 98c6ccd..d485b3d 100644
--- a/ppapi/thunk/ppb_messaging_thunk.cc
+++ b/ppapi/thunk/ppb_messaging_thunk.cc
@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-// From ppb_messaging.idl modified Thu Mar 28 11:12:59 2013.
+// From ppb_messaging.idl modified Tue Apr 16 11:25:44 2013.
#include "ppapi/c/pp_errors.h"
#include "ppapi/c/ppb_messaging.h"
@@ -20,8 +20,9 @@ namespace {
void PostMessage(PP_Instance instance, struct PP_Var message) {
VLOG(4) << "PPB_Messaging::PostMessage()";
EnterInstance enter(instance);
- if (enter.succeeded())
- enter.functions()->PostMessage(instance, message);
+ if (enter.failed())
+ return;
+ enter.functions()->PostMessage(instance, message);
}
const PPB_Messaging_1_0 g_ppb_messaging_thunk_1_0 = {
diff --git a/ppapi/thunk/ppb_url_loader_thunk.cc b/ppapi/thunk/ppb_url_loader_thunk.cc
index 8fad53f..7df78b9 100644
--- a/ppapi/thunk/ppb_url_loader_thunk.cc
+++ b/ppapi/thunk/ppb_url_loader_thunk.cc
@@ -115,8 +115,9 @@ int32_t FinishStreamingToFile(PP_Resource loader,
void Close(PP_Resource loader) {
VLOG(4) << "PPB_URLLoader::Close()";
EnterResource<PPB_URLLoader_API> enter(loader, true);
- if (enter.succeeded())
- enter.object()->Close();
+ if (enter.failed())
+ return;
+ enter.object()->Close();
}
const PPB_URLLoader_1_0 g_ppb_urlloader_thunk_1_0 = {
diff --git a/ppapi/thunk/ppb_url_loader_trusted_thunk.cc b/ppapi/thunk/ppb_url_loader_trusted_thunk.cc
index 398c52d..3082f36 100644
--- a/ppapi/thunk/ppb_url_loader_trusted_thunk.cc
+++ b/ppapi/thunk/ppb_url_loader_trusted_thunk.cc
@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-// From trusted/ppb_url_loader_trusted.idl modified Wed Apr 17 09:21:10 2013.
+// From trusted/ppb_url_loader_trusted.idl modified Wed Apr 17 11:16:00 2013.
#include "ppapi/c/pp_errors.h"
#include "ppapi/c/trusted/ppb_url_loader_trusted.h"
@@ -21,16 +21,18 @@ namespace {
void GrantUniversalAccess(PP_Resource loader) {
VLOG(4) << "PPB_URLLoaderTrusted::GrantUniversalAccess()";
EnterResource<PPB_URLLoader_API> enter(loader, true);
- if (enter.succeeded())
- enter.object()->GrantUniversalAccess();
+ if (enter.failed())
+ return;
+ enter.object()->GrantUniversalAccess();
}
void RegisterStatusCallback(PP_Resource loader,
PP_URLLoaderTrusted_StatusCallback cb) {
VLOG(4) << "PPB_URLLoaderTrusted::RegisterStatusCallback()";
EnterResource<PPB_URLLoader_API> enter(loader, true);
- if (enter.succeeded())
- enter.object()->RegisterStatusCallback(cb);
+ if (enter.failed())
+ return;
+ enter.object()->RegisterStatusCallback(cb);
}
const PPB_URLLoaderTrusted_0_3 g_ppb_urlloadertrusted_thunk_0_3 = {
diff --git a/ppapi/thunk/ppb_widget_dev_thunk.cc b/ppapi/thunk/ppb_widget_dev_thunk.cc
index 3a6fab9..2232371 100644
--- a/ppapi/thunk/ppb_widget_dev_thunk.cc
+++ b/ppapi/thunk/ppb_widget_dev_thunk.cc
@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-// From dev/ppb_widget_dev.idl modified Thu Dec 20 13:10:26 2012.
+// From dev/ppb_widget_dev.idl modified Tue Apr 16 11:25:44 2013.
#include "ppapi/c/dev/ppb_widget_dev.h"
#include "ppapi/c/pp_errors.h"
@@ -53,15 +53,17 @@ PP_Bool GetLocation(PP_Resource widget, struct PP_Rect* location) {
void SetLocation(PP_Resource widget, const struct PP_Rect* location) {
VLOG(4) << "PPB_Widget_Dev::SetLocation()";
EnterResource<PPB_Widget_API> enter(widget, false);
- if (enter.succeeded())
- enter.object()->SetLocation(location);
+ if (enter.failed())
+ return;
+ enter.object()->SetLocation(location);
}
void SetScale(PP_Resource widget, float scale) {
VLOG(4) << "PPB_Widget_Dev::SetScale()";
EnterResource<PPB_Widget_API> enter(widget, false);
- if (enter.succeeded())
- enter.object()->SetScale(scale);
+ if (enter.failed())
+ return;
+ enter.object()->SetScale(scale);
}
const PPB_Widget_Dev_0_3 g_ppb_widget_dev_thunk_0_3 = {