Skip to content

Commit

Permalink
don't recognize ^v as a CF type + misc cleaning
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.macosforge.org/repository/ruby/MacRuby/trunk@4151 23306eb0-4c56-4727-a40e-e92c0eb68959
  • Loading branch information
lrz committed May 25, 2010
1 parent 8bdb235 commit 4a99756
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 20 deletions.
5 changes: 5 additions & 0 deletions bridgesupport.cpp
Expand Up @@ -1252,6 +1252,11 @@ RoxorCore::bs_parse_cb(bs_element_type_t type, void *value, void *ctx)
case BS_ELEMENT_CFTYPE:
{
bs_element_cftype_t *bs_cftype = (bs_element_cftype_t *)value;
assert(bs_cftype->type[0] == _C_PTR);
if (bs_cftype->type[1] == _C_VOID) {
// Do not register ^v as a valid CFType.
break;
}
std::map<std::string, bs_element_cftype_t *>::iterator
iter = bs_cftypes.find(bs_cftype->type);
if (iter == bs_cftypes.end()) {
Expand Down
2 changes: 1 addition & 1 deletion bs.c
Expand Up @@ -1075,7 +1075,7 @@ bs_parser_parse(bs_parser_t *parser, const char *path,
free(fptr_args[i].type);
}
snprintf(new_type, sizeof(new_type),
"%c%s%c", _C_FPTR_B, tmp_type, _C_FPTR_E);
"%c%s%c", _MR_C_FPTR_B, tmp_type, _MR_C_FPTR_E);

if (atom->val == BS_XML_RETVAL) {
bs_element_retval_t *retval =
Expand Down
4 changes: 2 additions & 2 deletions bs.h
Expand Up @@ -37,8 +37,8 @@ extern "C" {
#include <objc/runtime.h>

/* Extend objc/runtime.h and add function pointers tokens */
#define _C_FPTR_B '<'
#define _C_FPTR_E '>'
#define _MR_C_FPTR_B '<'
#define _MR_C_FPTR_E '>'

/* Attribute and element representations.
* See BridgeSupport(5) for more information.
Expand Down
24 changes: 17 additions & 7 deletions compiler.cpp
Expand Up @@ -5248,7 +5248,8 @@ RoxorCompiler::compile_conversion_to_c(const char *type, Value *val,
{
type = SkipTypeModifiers(type);

if (*type == _C_PTR && GET_CORE()->find_bs_cftype(type) != NULL) {
if (type[0] == _C_PTR && type[1] != _C_VOID
&& GET_CORE()->find_bs_cftype(type) != NULL) {
type = "@";
}

Expand Down Expand Up @@ -5377,7 +5378,7 @@ RoxorCompiler::compile_conversion_to_c(const char *type, Value *val,
}
break;

case _C_FPTR_B:
case _MR_C_FPTR_B:
{
GlobalVariable *proc_gvar =
new GlobalVariable(*RoxorCompiler::module,
Expand All @@ -5395,7 +5396,7 @@ RoxorCompiler::compile_conversion_to_c(const char *type, Value *val,

std::vector<std::string> arg_ctypes;
std::vector<const Type *> arg_types;
while (*p != _C_FPTR_E) {
while (*p != _MR_C_FPTR_E) {
p = GetFirstType(p, buf, buf_len);
arg_ctypes.push_back(std::string(buf));
arg_types.push_back(convert_type(buf));
Expand Down Expand Up @@ -5606,7 +5607,8 @@ RoxorCompiler::compile_conversion_to_ruby(const char *type,
{
type = SkipTypeModifiers(type);

if (*type == _C_PTR && GET_CORE()->find_bs_cftype(type) != NULL) {
if (type[0] == _C_PTR && type[1] != _C_VOID
&& GET_CORE()->find_bs_cftype(type) != NULL) {
type = "@";
}

Expand Down Expand Up @@ -5826,7 +5828,7 @@ RoxorCompiler::convert_type(const char *type)
}
break;

case _C_FPTR_B:
case _MR_C_FPTR_B:
return PtrTy;

case _C_STRUCT_B:
Expand Down Expand Up @@ -6256,6 +6258,9 @@ RoxorCompiler::compile_objc_stub(Function *ruby_func, IMP ruby_imp,
arg_types.push_back(buf);
}

free(buf);
buf = NULL;

// Create the function.
FunctionType *ft = FunctionType::get(f_ret_type, f_types, false);
Function *f = cast<Function>(module->getOrInsertFunction("", ft));
Expand Down Expand Up @@ -6316,9 +6321,10 @@ RoxorCompiler::compile_objc_stub(Function *ruby_func, IMP ruby_imp,
}

// Call the Ruby implementation.
Value *ret_val = compile_protected_call(imp, params);
Instruction *ruby_call_insn = compile_protected_call(imp, params);

// Convert the return value into Objective-C type (if any).
Value *ret_val = ruby_call_insn;
if (f_ret_type != VoidTy) {
ret_val = compile_conversion_to_c(ret_type.c_str(), ret_val,
new AllocaInst(f_ret_type, "", bb));
Expand Down Expand Up @@ -6353,7 +6359,11 @@ RoxorCompiler::compile_objc_stub(Function *ruby_func, IMP ruby_imp,
rescue_invoke_bb = old_rescue_invoke_bb;
#endif

free(buf);
// Now that the function is finished, we can inline the Ruby method.
if (CallInst::classof(ruby_call_insn)) {
CallInst *insn = cast<CallInst>(ruby_call_insn);
InlineFunction(insn);
}

return f;
}
Expand Down
20 changes: 10 additions & 10 deletions objc.h
Expand Up @@ -118,30 +118,30 @@ SkipFirstType(const char *type)
{
while (1) {
switch (*type++) {
case _C_CONST:
case _C_PTR:
case 'O': /* bycopy */
case 'n': /* in */
case 'o': /* out */
case 'N': /* inout */
case 'r': /* const */
case 'V': /* oneway */
case '^': /* pointers */
break;

/* arrays */
case '[':
return type + SubtypeUntil (type, ']') + 1;
case _C_ARY_B:
return type + SubtypeUntil (type, _C_ARY_E) + 1;

/* structures */
case '{':
return type + SubtypeUntil (type, '}') + 1;
case _C_STRUCT_B:
return type + SubtypeUntil (type, _C_STRUCT_E) + 1;

/* unions */
case '(':
return type + SubtypeUntil (type, ')') + 1;
case _C_UNION_B:
return type + SubtypeUntil (type, _C_UNION_E) + 1;

/* Function pointers */
case '<':
return type + SubtypeUntil (type, '>') + 1;
case _MR_C_FPTR_B:
return type + SubtypeUntil (type, _MR_C_FPTR_E) + 1;

/* basic types */
default:
Expand Down

0 comments on commit 4a99756

Please sign in to comment.