[26139] trunk/base/src/tclobjc1.0/tclobjc.m
source_changes at macosforge.org
source_changes at macosforge.org
Wed Jun 13 17:27:02 PDT 2007
Revision: 26139
http://trac.macosforge.org/projects/macports/changeset/26139
Author: landonf at macports.org
Date: 2007-06-13 17:27:02 -0700 (Wed, 13 Jun 2007)
Log Message:
-----------
Fix a leak in argument composition, and clean up the function. This needs a proper unit test framework.
Modified Paths:
--------------
trunk/base/src/tclobjc1.0/tclobjc.m
Modified: trunk/base/src/tclobjc1.0/tclobjc.m
===================================================================
--- trunk/base/src/tclobjc1.0/tclobjc.m 2007-06-14 00:13:02 UTC (rev 26138)
+++ trunk/base/src/tclobjc1.0/tclobjc.m 2007-06-14 00:27:02 UTC (rev 26139)
@@ -58,9 +58,11 @@
if (objc < 2) {
Tcl_WrongNumArgs(interp, 1, objv, "arguments");
- return (TCL_ERROR);
+ result = TCL_ERROR;
+ goto cleanup;
}
+ /* Look up the selector */
selname = Tcl_NewObj();
for (i = 1; i < objc; i += 2) {
Tcl_AppendObjToObj(selname, objv[i]);
@@ -73,59 +75,64 @@
#elif defined(APPLE_RUNTIME)
selector = sel_getUid(Tcl_GetString(selname));
#endif
-
+
+ /* If the selector isn't found, error out */
if (!selector) {
Tcl_Obj* tcl_result = Tcl_NewStringObj("Invalid selector specified", -1);
Tcl_SetObjResult(interp, tcl_result);
result = TCL_ERROR;
- } else {
+ goto cleanup;
+ }
+
// fprintf(stderr, "target = %08x\n", target);
- NSMethodSignature* signature = [target methodSignatureForSelector:selector];
- NSInvocation* invocation = [NSInvocation invocationWithMethodSignature:signature];
- [invocation setTarget:target];
- [invocation setSelector:selector];
-
- for (i = 2; i < objc; i += 2) {
- int arg_num = i / 2 + 1;
+ NSMethodSignature* signature = [target methodSignatureForSelector:selector];
+ NSInvocation* invocation = [NSInvocation invocationWithMethodSignature:signature];
+ [invocation setTarget:target];
+ [invocation setSelector:selector];
- const char* arg_type = [signature getArgumentTypeStringAtIndex:arg_num];
- fprintf(stderr, "argument type %s\n", arg_type);
- if (arg_type[0] == _C_ID) {
- id obj;
- if (TclObjC_GetIdFromObj(interp, objv[i], &obj) == TCL_OK) {
- [invocation setArgument:&obj atIndex:arg_num];
- }
- } else if (arg_type[0] == _C_INT) {
- int word = 0;
- if (Tcl_GetIntFromObj(interp, objv[i], &word) == TCL_OK) {
- [invocation setArgument:&word atIndex:arg_num];
- }
- } else if (arg_type[0] == _C_CHARPTR) {
- int length;
- char* buf = Tcl_GetStringFromObj(objv[i], &length);
- if (buf)
- [invocation setArgument:&buf atIndex:arg_num];
- } else {
- NSString* str = [NSString stringWithFormat:@"unexpected argument type %s at %s:%d", arg_type, __FILE__, __LINE__];
- Tcl_Obj* tcl_result = Tcl_NewStringObj([str cString], -1);
- Tcl_SetObjResult(interp, tcl_result);
- result = TCL_ERROR;
- break;
+ /* Build our arguments list */
+ for (i = 2; i < objc; i += 2) {
+ int arg_num = i / 2 + 1;
+
+ const char* arg_type = [signature getArgumentTypeStringAtIndex:arg_num];
+ fprintf(stderr, "argument type %s\n", arg_type);
+ if (arg_type[0] == _C_ID) {
+ id obj;
+ if (TclObjC_GetIdFromObj(interp, objv[i], &obj) == TCL_OK) {
+ [invocation setArgument:&obj atIndex:arg_num];
}
- }
-
- if (result == TCL_OK) {
- Tcl_Obj *tcl_result;
- [invocation invoke];
- fprintf(stderr, "result size = %d\n", [signature methodReturnLength]);
- void* result_ptr;
- [invocation getReturnValue:&result_ptr];
- const char* result_type = [signature methodReturnTypeString];
- result = objc_to_tclobj(interp, &tcl_result, result_type, result_ptr);
+ } else if (arg_type[0] == _C_INT) {
+ int word = 0;
+ if (Tcl_GetIntFromObj(interp, objv[i], &word) == TCL_OK) {
+ [invocation setArgument:&word atIndex:arg_num];
+ }
+ } else if (arg_type[0] == _C_CHARPTR) {
+ int length;
+ char* buf = Tcl_GetStringFromObj(objv[i], &length);
+ if (buf)
+ [invocation setArgument:&buf atIndex:arg_num];
+ } else {
+ NSString* str = [NSString stringWithFormat:@"unexpected argument type %s at %s:%d", arg_type, __FILE__, __LINE__];
+ Tcl_Obj* tcl_result = Tcl_NewStringObj([str cString], -1);
Tcl_SetObjResult(interp, tcl_result);
+ result = TCL_ERROR;
+ break;
}
}
-
+
+ /* If all is well, invoke the Objective-C method. */
+ if (result == TCL_OK) {
+ Tcl_Obj *tcl_result;
+ [invocation invoke];
+ fprintf(stderr, "result size = %d\n", [signature methodReturnLength]);
+ void* result_ptr;
+ [invocation getReturnValue:&result_ptr];
+ const char* result_type = [signature methodReturnTypeString];
+ result = objc_to_tclobj(interp, &tcl_result, result_type, result_ptr);
+ Tcl_SetObjResult(interp, tcl_result);
+ }
+
+cleanup:
[pool release];
return result;
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.macosforge.org/pipermail/macports-changes/attachments/20070613/4d108303/attachment.html
More information about the macports-changes
mailing list