mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* ext/win32ole/win32ole.c: separate src of WIN32OLERuntimeError
from win32ole.c. * ext/win32ole/win32ole.h: ditto * ext/win32ole/depend: ditto. * ext/win32ole/win32ole_error.c: ditto. * ext/win32ole/win32ole_error.h: ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@47080 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
f01485b4ec
commit
75d1a6c9fc
6 changed files with 111 additions and 84 deletions
10
ChangeLog
10
ChangeLog
|
@ -1,3 +1,13 @@
|
|||
Wed Aug 6 18:42:58 2014 Masaki Suketa <masaki.suketa@nifty.ne.jp>
|
||||
|
||||
* ext/win32ole/win32ole.c: separate src of WIN32OLERuntimeError
|
||||
from win32ole.c.
|
||||
|
||||
* ext/win32ole/win32ole.h: ditto
|
||||
* ext/win32ole/depend: ditto.
|
||||
* ext/win32ole/win32ole_error.c: ditto.
|
||||
* ext/win32ole/win32ole_error.h: ditto.
|
||||
|
||||
Wed Aug 6 04:33:58 2014 NARUSE, Yui <naruse@ruby-lang.org>
|
||||
|
||||
* lib/net/http.rb (Net::HTTP.proxy_uri): use initializer instead
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
WIN32OLE_HEADERS = $(HDRS) $(ruby_headers)
|
||||
win32ole.o : win32ole.c $(WIN32OLE_HEADERS)
|
||||
win32ole_variant_m.o : win32ole_variant_m.c $(WIN32OLE_HEADERS)
|
||||
win32ole_error.o : win32ole_error.c $(WIN32OLE_HEADERS)
|
||||
|
|
|
@ -128,7 +128,6 @@ VALUE cWIN32OLE_METHOD;
|
|||
VALUE cWIN32OLE_PARAM;
|
||||
VALUE cWIN32OLE_EVENT;
|
||||
VALUE cWIN32OLE_VARIANT;
|
||||
VALUE eWIN32OLERuntimeError;
|
||||
VALUE cWIN32OLE_PROPERTY;
|
||||
VALUE cWIN32OLE_RECORD;
|
||||
|
||||
|
@ -153,7 +152,6 @@ static FNCOCREATEINSTANCEEX *gCoCreateInstanceEx = NULL;
|
|||
static VALUE com_hash;
|
||||
static IDispatchVtbl com_vtbl;
|
||||
static UINT cWIN32OLE_cp = CP_ACP;
|
||||
static LCID cWIN32OLE_lcid = LOCALE_SYSTEM_DEFAULT;
|
||||
static rb_encoding *cWIN32OLE_enc;
|
||||
static UINT g_cp_to_check = CP_ACP;
|
||||
static char g_lcid_to_check[8 + 1];
|
||||
|
@ -239,10 +237,8 @@ static void load_conv_function51932(void);
|
|||
#endif
|
||||
static UINT ole_init_cp(void);
|
||||
static char *ole_wc2mb(LPWSTR pw);
|
||||
static VALUE ole_hresult2msg(HRESULT hr);
|
||||
static void ole_freeexceptinfo(EXCEPINFO *pExInfo);
|
||||
static VALUE ole_excepinfo2msg(EXCEPINFO *pExInfo);
|
||||
static void ole_raise(HRESULT hr, VALUE ecs, const char *fmt, ...);
|
||||
static void ole_initialize(void);
|
||||
static void ole_msg_loop(void);
|
||||
static void ole_free(struct oledata *pole);
|
||||
|
@ -1055,46 +1051,6 @@ ole_wc2mb(LPWSTR pw)
|
|||
return ole_wc2mb_alloc(pw, ole_alloc_str, NULL);
|
||||
}
|
||||
|
||||
static VALUE
|
||||
ole_hresult2msg(HRESULT hr)
|
||||
{
|
||||
VALUE msg = Qnil;
|
||||
char *p_msg = NULL;
|
||||
char *term = NULL;
|
||||
DWORD dwCount;
|
||||
|
||||
char strhr[100];
|
||||
sprintf(strhr, " HRESULT error code:0x%08x\n ", (unsigned)hr);
|
||||
msg = rb_str_new2(strhr);
|
||||
dwCount = FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER |
|
||||
FORMAT_MESSAGE_FROM_SYSTEM |
|
||||
FORMAT_MESSAGE_IGNORE_INSERTS,
|
||||
NULL, hr,
|
||||
MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US),
|
||||
(LPTSTR)&p_msg, 0, NULL);
|
||||
if (dwCount == 0) {
|
||||
dwCount = FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER |
|
||||
FORMAT_MESSAGE_FROM_SYSTEM |
|
||||
FORMAT_MESSAGE_IGNORE_INSERTS,
|
||||
NULL, hr, cWIN32OLE_lcid,
|
||||
(LPTSTR)&p_msg, 0, NULL);
|
||||
}
|
||||
if (dwCount > 0) {
|
||||
term = p_msg + strlen(p_msg);
|
||||
while (p_msg < term) {
|
||||
term--;
|
||||
if (*term == '\r' || *term == '\n')
|
||||
*term = '\0';
|
||||
else break;
|
||||
}
|
||||
if (p_msg[0] != '\0') {
|
||||
rb_str_cat2(msg, p_msg);
|
||||
}
|
||||
}
|
||||
LocalFree(p_msg);
|
||||
return msg;
|
||||
}
|
||||
|
||||
static void
|
||||
ole_freeexceptinfo(EXCEPINFO *pExInfo)
|
||||
{
|
||||
|
@ -1145,24 +1101,6 @@ ole_excepinfo2msg(EXCEPINFO *pExInfo)
|
|||
return error_msg;
|
||||
}
|
||||
|
||||
static void
|
||||
ole_raise(HRESULT hr, VALUE ecs, const char *fmt, ...)
|
||||
{
|
||||
va_list args;
|
||||
VALUE msg;
|
||||
VALUE err_msg;
|
||||
va_init_list(args, fmt);
|
||||
msg = rb_vsprintf(fmt, args);
|
||||
va_end(args);
|
||||
|
||||
err_msg = ole_hresult2msg(hr);
|
||||
if(err_msg != Qnil) {
|
||||
rb_str_cat2(msg, "\n");
|
||||
rb_str_append(msg, err_msg);
|
||||
}
|
||||
rb_exc_raise(rb_exc_new_str(ecs, msg));
|
||||
}
|
||||
|
||||
void
|
||||
ole_uninitialize(void)
|
||||
{
|
||||
|
@ -9676,6 +9614,7 @@ free_enc2cp(void)
|
|||
void
|
||||
Init_win32ole(void)
|
||||
{
|
||||
cWIN32OLE_lcid = LOCALE_SYSTEM_DEFAULT;
|
||||
g_ole_initialized_init();
|
||||
ary_ole_event = rb_ary_new();
|
||||
rb_gc_register_mark_object(ary_ole_event);
|
||||
|
@ -9972,23 +9911,7 @@ Init_win32ole(void)
|
|||
rb_define_method(cWIN32OLE_RECORD, "ole_instance_variable_set", folerecord_ole_instance_variable_set, 2);
|
||||
rb_define_method(cWIN32OLE_RECORD, "inspect", folerecord_inspect, 0);
|
||||
|
||||
/*
|
||||
* Document-class: WIN32OLERuntimeError
|
||||
*
|
||||
* Raised when OLE processing failed.
|
||||
*
|
||||
* EX:
|
||||
*
|
||||
* obj = WIN32OLE.new("NonExistProgID")
|
||||
*
|
||||
* raises the exception:
|
||||
*
|
||||
* WIN32OLERuntimeError: unknown OLE server: `NonExistProgID'
|
||||
* HRESULT error code:0x800401f3
|
||||
* Invalid class string
|
||||
*
|
||||
*/
|
||||
eWIN32OLERuntimeError = rb_define_class("WIN32OLERuntimeError", rb_eRuntimeError);
|
||||
Init_win32ole_error();
|
||||
|
||||
init_enc2cp();
|
||||
atexit((void (*)(void))free_enc2cp);
|
||||
|
|
|
@ -35,11 +35,11 @@
|
|||
#endif
|
||||
#include <objidl.h>
|
||||
|
||||
#define DOUT fprintf(stderr,"[%d]\n",__LINE__)
|
||||
#define DOUTS(x) fprintf(stderr,"[%d]:" #x "=%s\n",__LINE__,x)
|
||||
#define DOUTMSG(x) fprintf(stderr, "[%d]:" #x "\n",__LINE__)
|
||||
#define DOUTI(x) fprintf(stderr, "[%ld]:" #x "=%d\n",__LINE__,x)
|
||||
#define DOUTD(x) fprintf(stderr, "[%d]:" #x "=%f\n",__LINE__,x)
|
||||
#define DOUT fprintf(stderr,"%s(%d)\n", __FILE__, __LINE__)
|
||||
#define DOUTS(x) fprintf(stderr,"%s(%d):" #x "=%s\n",__FILE__, __LINE__,x)
|
||||
#define DOUTMSG(x) fprintf(stderr, "%s(%d):" #x "\n",__FILE__, __LINE__)
|
||||
#define DOUTI(x) fprintf(stderr, "%s(%d):" #x "=%d\n",__FILE__, __LINE__,x)
|
||||
#define DOUTD(x) fprintf(stderr, "%s(%d):" #x "=%f\n",__FILE__, __LINE__,x)
|
||||
|
||||
#if (defined(__GNUC__)) && (GNUC_OLDER_3_4_4)
|
||||
#define V_UNION1(X, Y) ((X)->u.Y)
|
||||
|
@ -85,6 +85,9 @@
|
|||
|
||||
VALUE cWIN32OLE;
|
||||
|
||||
LCID cWIN32OLE_lcid;
|
||||
|
||||
#include "win32ole_variant_m.h"
|
||||
#include "win32ole_error.h"
|
||||
|
||||
#endif
|
||||
|
|
82
ext/win32ole/win32ole_error.c
Normal file
82
ext/win32ole/win32ole_error.c
Normal file
|
@ -0,0 +1,82 @@
|
|||
#include "win32ole.h"
|
||||
|
||||
static VALUE ole_hresult2msg(HRESULT hr);
|
||||
|
||||
static VALUE
|
||||
ole_hresult2msg(HRESULT hr)
|
||||
{
|
||||
VALUE msg = Qnil;
|
||||
char *p_msg = NULL;
|
||||
char *term = NULL;
|
||||
DWORD dwCount;
|
||||
|
||||
char strhr[100];
|
||||
sprintf(strhr, " HRESULT error code:0x%08x\n ", (unsigned)hr);
|
||||
msg = rb_str_new2(strhr);
|
||||
dwCount = FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER |
|
||||
FORMAT_MESSAGE_FROM_SYSTEM |
|
||||
FORMAT_MESSAGE_IGNORE_INSERTS,
|
||||
NULL, hr,
|
||||
MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US),
|
||||
(LPTSTR)&p_msg, 0, NULL);
|
||||
if (dwCount == 0) {
|
||||
dwCount = FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER |
|
||||
FORMAT_MESSAGE_FROM_SYSTEM |
|
||||
FORMAT_MESSAGE_IGNORE_INSERTS,
|
||||
NULL, hr, cWIN32OLE_lcid,
|
||||
(LPTSTR)&p_msg, 0, NULL);
|
||||
}
|
||||
if (dwCount > 0) {
|
||||
term = p_msg + strlen(p_msg);
|
||||
while (p_msg < term) {
|
||||
term--;
|
||||
if (*term == '\r' || *term == '\n')
|
||||
*term = '\0';
|
||||
else break;
|
||||
}
|
||||
if (p_msg[0] != '\0') {
|
||||
rb_str_cat2(msg, p_msg);
|
||||
}
|
||||
}
|
||||
LocalFree(p_msg);
|
||||
return msg;
|
||||
}
|
||||
|
||||
void
|
||||
ole_raise(HRESULT hr, VALUE ecs, const char *fmt, ...)
|
||||
{
|
||||
va_list args;
|
||||
VALUE msg;
|
||||
VALUE err_msg;
|
||||
va_init_list(args, fmt);
|
||||
msg = rb_vsprintf(fmt, args);
|
||||
va_end(args);
|
||||
|
||||
err_msg = ole_hresult2msg(hr);
|
||||
if(err_msg != Qnil) {
|
||||
rb_str_cat2(msg, "\n");
|
||||
rb_str_append(msg, err_msg);
|
||||
}
|
||||
rb_exc_raise(rb_exc_new_str(ecs, msg));
|
||||
}
|
||||
|
||||
void
|
||||
Init_win32ole_error() {
|
||||
/*
|
||||
* Document-class: WIN32OLERuntimeError
|
||||
*
|
||||
* Raised when OLE processing failed.
|
||||
*
|
||||
* EX:
|
||||
*
|
||||
* obj = WIN32OLE.new("NonExistProgID")
|
||||
*
|
||||
* raises the exception:
|
||||
*
|
||||
* WIN32OLERuntimeError: unknown OLE server: `NonExistProgID'
|
||||
* HRESULT error code:0x800401f3
|
||||
* Invalid class string
|
||||
*
|
||||
*/
|
||||
eWIN32OLERuntimeError = rb_define_class("WIN32OLERuntimeError", rb_eRuntimeError);
|
||||
}
|
8
ext/win32ole/win32ole_error.h
Normal file
8
ext/win32ole/win32ole_error.h
Normal file
|
@ -0,0 +1,8 @@
|
|||
#ifndef WIN32OLE_ERROR_H
|
||||
#define WIN32OLE_ERROR_H 1
|
||||
|
||||
VALUE eWIN32OLERuntimeError;
|
||||
void ole_raise(HRESULT hr, VALUE ecs, const char *fmt, ...);
|
||||
void Init_win32ole_error();
|
||||
|
||||
#endif
|
Loading…
Reference in a new issue