Index: TODO =================================================================== diff -u -r6a3cd1a111aa693839ec3d788262ce18be74bf91 -r17ad6747e40c1724810371f92f0108b12c1d5284 --- TODO (.../TODO) (revision 6a3cd1a111aa693839ec3d788262ce18be74bf91) +++ TODO (.../TODO) (revision 17ad6747e40c1724810371f92f0108b12c1d5284) @@ -3914,6 +3914,8 @@ - treating incompatible forwarding to slot vs. slot option noaccessor - extended regression test +- don't allow object creation to overwrite non-object cmds (e.g. procs) + ======================================================================== TODO: Index: generic/nsf.c =================================================================== diff -u -ra6e6e5de115f92c579b867bb88323a9916aec4d4 -r17ad6747e40c1724810371f92f0108b12c1d5284 --- generic/nsf.c (.../nsf.c) (revision a6e6e5de115f92c579b867bb88323a9916aec4d4) +++ generic/nsf.c (.../nsf.c) (revision 17ad6747e40c1724810371f92f0108b12c1d5284) @@ -22144,7 +22144,20 @@ * Check whether we have to call recreate (i.e. when the * object exists already). */ - newObject = GetObjectFromString(interp, nameString); + { + Tcl_Command cmd = NSFindCommand(interp, nameString); + if (cmd) { + newObject = NsfGetObjectFromCmdPtr(cmd); + if (newObject == NULL) { + /* + * We have a cmd, but no object. Don't allow to overwrite an ordinary + * cmd by an nsf object. + */ + result = NsfPrintError(interp, "cannot overwrite cmd %s; delete/rename it before overwriting", nameString); + goto create_method_exit; + } + } + } /*fprintf(stderr, "+++ createspecifiedName '%s', nameString '%s', newObject=%p ismeta(%s) %d, ismeta(%s) %d\n", specifiedName, nameString, newObject, Index: library/xotcl/tests/testx.xotcl =================================================================== diff -u -r59e100d383b22ea1407f5e5c40e303f2c6bb9027 -r17ad6747e40c1724810371f92f0108b12c1d5284 --- library/xotcl/tests/testx.xotcl (.../testx.xotcl) (revision 59e100d383b22ea1407f5e5c40e303f2c6bb9027) +++ library/xotcl/tests/testx.xotcl (.../testx.xotcl) (revision 17ad6747e40c1724810371f92f0108b12c1d5284) @@ -476,6 +476,7 @@ Object instfilter f x + rename x "" ::errorCheck $::a::e xxx \ "filterAddRemove: instvar test -- proc set failed" Index: tests/destroy.test =================================================================== diff -u -r33d4fb2329d25b2a4e9ba05d312dfde2c73c3409 -r17ad6747e40c1724810371f92f0108b12c1d5284 --- tests/destroy.test (.../destroy.test) (revision 33d4fb2329d25b2a4e9ba05d312dfde2c73c3409) +++ tests/destroy.test (.../destroy.test) (revision 17ad6747e40c1724810371f92f0108b12c1d5284) @@ -190,6 +190,7 @@ ? "set ::firstDestroy" 0 "firstDestroy called" ? "set ::ObjectDestroy" 0 "ObjectDestroy called" +rename o "" # # namespace delete: tcl delays delete until the namespace is not @@ -334,8 +335,8 @@ # create an other cmd with the current object's name. # xotcl 1.6 crashed on this test # -set case "redefined current object as proc" -Test case redefined-current-object-as-proc +set case "redefine current object as proc" +Test case redefine-current-object-as-proc Object create o Class create C -superclass O C method destroy {} {incr ::firstDestroy; puts stderr " *** [current] destroy"; next} @@ -357,8 +358,8 @@ ? "set ::firstDestroy" 1 "firstDestroy called" ? "set ::ObjectDestroy" 1 "ObjectDestroy called" +rename c1 "" - # # delete the active class # Index: tests/object-system.test =================================================================== diff -u -rf80347fbea8fd50ae92c0bd7412cd4af80c78a54 -r17ad6747e40c1724810371f92f0108b12c1d5284 --- tests/object-system.test (.../object-system.test) (revision f80347fbea8fd50ae92c0bd7412cd4af80c78a54) +++ tests/object-system.test (.../object-system.test) (revision 17ad6747e40c1724810371f92f0108b12c1d5284) @@ -341,6 +341,25 @@ ? {::nsf::object::exists nx::Class} 1 # +# Test overwriting of procs/methods +# +proc foo {} {;} +# +# Don't allow object to overwrite pre-existing proc/cmd, +# which is not an object. +# +? {catch {nx::Object create foo}} 1 +rename foo "" +nx::Object create foo { + :method bar {} {;} + # + # Don't allow subobject to overwrite object specific method + # + ? {catch {nx::Object create [self]::bar}} 1 +} + + +# # Test instances of diamond class structure. # # Leave class structure around until exit to test handling of Index: tests/submethods.test =================================================================== diff -u -rabc4e7b7e4192e83072f23bf7849ab3e2b61c09c -r17ad6747e40c1724810371f92f0108b12c1d5284 --- tests/submethods.test (.../submethods.test) (revision abc4e7b7e4192e83072f23bf7849ab3e2b61c09c) +++ tests/submethods.test (.../submethods.test) (revision 17ad6747e40c1724810371f92f0108b12c1d5284) @@ -325,7 +325,9 @@ ? {obj foo} {wrong # args: should be ":info"} # now we overwrite the object specific method with an object - Object create obj::info + ? {Object create obj::info} "cannot overwrite cmd ::ns1::obj::info; delete/rename it before overwriting" + rename obj::info "" + ? {Object create obj::info} ::ns1::obj::info ? [list obj $infolookup info] ::ns1::obj::info ? [list obj $infomethod type ::ns1::obj::info] object @@ -339,14 +341,12 @@ # method via ensemle-next. #? {obj foo} ::nx::Object ? {obj foo} {::ns1::obj::info: unable to dispatch method 'class'} - } # # Leaf next: Do not trigger unknown handling (see also # NextSearchAndInvoke()) # - nx::Test case leaf-next-in-submethods { Object create container { set :x 0