/* -*- c-file-style: "ruby"; indent-tabs-mode: nil -*- */ <%= header_comment # This file is processed by apiwrap.rb. %> #define API_WRAP_C 1 #include "apiwrap.h" #ifdef HAVE_RB_THREAD_BLOCKING_REGION #define BLOCKING_FUNCTION_EPILOGUE(svcctx) do { (svcctx)->executing_thread = Qnil; } while (0) #else #define BLOCKING_FUNCTION_EPILOGUE(svcctx) do { } while (0) #endif <% prev_name = '' funcs.each do |f| next if f.name == prev_name prev_name = f.name %> /* <%=f.name%> */ #if defined RUNTIME_API_CHECK typedef <%=f.ret%> (*oci8_<%=f.name%>_func_t)(<%=f.args.collect {|arg| arg.dcl}.join(', ')%>); static oci8_<%=f.name%>_func_t oci8_<%=f.name%>_func; #define <%=f.name%> oci8_<%=f.name%>_func #elif ORACLE_CLIENT_VERSION < <%=f.version_num%> #define <%=f.name%>(<%=f.args.collect {|a| a.name}.join(', ')%>) (0) #endif <% end # funcs.each funcs.each do |f| if f.remote ###################################################################### ## ## remote API with runtime-check - start ## ###################################################################### %> /* * <%=f.name%>_nb */ typedef struct { oci8_svcctx_t *svcctx; <% f.ret != 'void' %> <%= f.ret %> rv; <% f.args.each do |a| %> <%= a.dcl %>; <% end %>} oci8_<%=f.name%>_data_t; #if defined RUNTIME_API_CHECK int oci8_have_<%=f.name%>_nb; #endif #if defined RUNTIME_API_CHECK || ORACLE_CLIENT_VERSION >= <%=f.version_num%> static VALUE oci8_<%=f.name%>_cb(void *user_data) { oci8_<%=f.name%>_data_t *data = (oci8_<%=f.name%>_data_t *)user_data; <% if f.ret == 'void' %> <%=f.name%>(<%= f.args.collect do |a| 'data->' + a.name; end.join(', ') %>); <% else %> data->rv = <%=f.name%>(<%= f.args.collect do |a| 'data->' + a.name; end.join(', ') %>); <% end %> <% if f.ret == 'sword' %> BLOCKING_FUNCTION_EPILOGUE(data->svcctx); return (VALUE)data->rv; <% else %> BLOCKING_FUNCTION_EPILOGUE(data->svcctx); return (VALUE)0; <% end %> } #else #define oci8_<%=f.name%>_cb NULL #endif <%=f.ret%> oci8_<%=f.name%>_nb(oci8_svcctx_t *svcctx, <%=f.args.collect {|arg| arg.dcl}.join(', ')%>, const char *file, int line) { if (have_<%=f.name%>_nb) { oci8_<%=f.name%>_data_t data; data.svcctx = svcctx; <% f.args.each do |a| %> data.<%=a.name%> = <%=a.name%>; <% end %> oci8_blocking_region(svcctx, oci8_<%=f.name%>_cb, &data); <% if f.ret != 'void' %> return data.rv; <% end %> } else { rb_raise(rb_eRuntimeError, "undefined OCI function %s is called", "<%=f.name%>_nb"); } } <% ###################################################################### ## ## remote API with runtime-check - end ## ###################################################################### else ###################################################################### ## ## local API with runtime-check - start ## ###################################################################### %> /* * <%=f.name%> */ #if defined RUNTIME_API_CHECK int oci8_have_<%=f.name%>; #endif <%=f.ret%> oci8_<%=f.name%>(<%=f.args.collect {|arg| arg.dcl}.join(', ')%>, const char *file, int line) { if (have_<%=f.name%>) { <% if f.ret == 'void' %> <%=f.name%>(<%=f.args.collect {|arg| arg.name}.join(', ')%>); <% else %> return <%=f.name%>(<%=f.args.collect {|arg| arg.name}.join(', ')%>); <% end %> } else { <% if f.code_if_not_found %><%=f.code_if_not_found.split("\n").collect {|line| " " + line}.join("\n")%> <% else %> rb_raise(rb_eRuntimeError, "undefined OCI function %s is called", "<%=f.name%>"); <% end %> } } <% ###################################################################### ## ## local API with runtime-check - end ## ###################################################################### end end # funcs.each ###################################################################### ## ## RUNTIME_API_CHECK ## ###################################################################### current_version_num = funcs[0].version_num current_version_str = funcs[0].version_str have_vars = [] %> #if defined RUNTIME_API_CHECK int oracle_client_version; void Init_oci8_apiwrap(void) { oracle_client_version = 0; <% funcs.each do |f| if current_version_num != f.version_num unless have_vars.empty? %> /* pass Oracle <%=current_version_str%> API */ oracle_client_version = <%=current_version_num%>; <% have_vars.each do |v| %> <%=v%> = 1; <% end end have_vars = [] current_version_num = f.version_num current_version_str = f.version_str %> /* * checking Oracle <%=f.version_str%> API */ <% end have_vars << 'have_' + f.name + (f.remote ? '_nb' : '') %> oci8_<%=f.name%>_func = (oci8_<%=f.name%>_func_t)oci8_find_symbol("<%=f.name%>"); if (oci8_<%=f.name%>_func == NULL) return; <% end %> /* pass Oracle <%=current_version_str%> API */ oracle_client_version = <%=current_version_num%>; <% have_vars.each do |v| %> <%=v%> = 1; <% end %>} #endif /* RUNTIME_API_CHECK */