Le 02/03/2018 à 13:00, Stéphane Mottelet a écrit :
Le 01/03/2018 à 23:44, Samuel Gougeon a écrit :
Le 01/03/2018 à 23:26, Stéphane Mottelet a écrit :
Le 01/03/2018 à 21:57, Stéphane Mottelet a écrit :
Hello,

Le 1 mars 2018 à 20:18, Samuel Gougeon <sgoug...@free.fr> a écrit :

Le 01/03/2018 à 20:09, Stéphane Mottelet a écrit :
Hello,

I have tried to implement a (naïve) hijacking mechanism that works *like a charm* under scilab 5.5.2:

newfun('scilab_set',funptr('set'));
clearfun('set');
function set(varargin)
    scilab_set(varargin(:))
    printf("...\n")
endfunction
// test the hijacked "set"
f=gcf()
set(f,"tag","1")
f.tag="2"

When I test this under  6.0.0 or 6.0.1, the last line always crashes Scilab. Is there an evident reason why ? When trying this on the command line (scilab -nw)

--> set(f,"tag","1")
...

--> f.tag="2"
...
/Applications/scilab-6.0.1.app/Contents/MacOS/bin/scilab: line 972: 27117 Illegal instruction: 4  "$SCILABBIN" "$@"
I can see that the problem occurs *after* the insertion code f.tag="2" has delegated the operation to the hijacked "set", hence the crash occurs in the built-in function which does the insertion. In order to understand why this crash occurs (under Linux or OSX), I would like to know which module is in charge of the insertion for handles (a kind of %h_i but built-in) ?
You may have a look at
SCI\modules\graphic_objects\src\cpp\setGraphicObjectProperty.cpp
and
SCI\modules\graphic_objects\src\java\org\scilab\modules\graphic_objects\*
Hmm, the crash occurs *after* the property has been set. So my question was rather about the generic code that handles field insertion, which is delegated to “set” for handles.

S.


I have localized many methods for handle type in modules/ast/src/cpp/types/graphichandle.cpp. Although I don't know much of C++, I can see that GraphicHandle::invoke is delegated to the overloaded %h_e macro, hence is an extraction method, but I am not able to find any *insertion* method in this file. Maybe someone knows ?

Maybe
edit generic_i_h
I found it in modules/ast/src/cpp/ast/visitor_common.cpp

When you don't have any idea of where to look, sometimes a "grep theStringToFind -r ." is useful :

2241 <http://gitweb.scilab.org/?p=scilab.git;a=blob;f=scilab/modules/ast/src/cpp/ast/visitor_common.cpp;h=6379d14e630d747599fd48e0e9cfa907cab214cd;hb=b5bcf45d3328c87b56ed5d8f9dbec623504f7c9b#l2241>         else if (_pVar->isHandle()) 2242 <http://gitweb.scilab.org/?p=scilab.git;a=blob;f=scilab/modules/ast/src/cpp/ast/visitor_common.cpp;h=6379d14e630d747599fd48e0e9cfa907cab214cd;hb=b5bcf45d3328c87b56ed5d8f9dbec623504f7c9b#l2242>         { 2243 <http://gitweb.scilab.org/?p=scilab.git;a=blob;f=scilab/modules/ast/src/cpp/ast/visitor_common.cpp;h=6379d14e630d747599fd48e0e9cfa907cab214cd;hb=b5bcf45d3328c87b56ed5d8f9dbec623504f7c9b#l2243>             if (_pArgs->size() == 1 && (*_pArgs)[0]->isString()) 2244 <http://gitweb.scilab.org/?p=scilab.git;a=blob;f=scilab/modules/ast/src/cpp/ast/visitor_common.cpp;h=6379d14e630d747599fd48e0e9cfa907cab214cd;hb=b5bcf45d3328c87b56ed5d8f9dbec623504f7c9b#l2244>             { 2245 <http://gitweb.scilab.org/?p=scilab.git;a=blob;f=scilab/modules/ast/src/cpp/ast/visitor_common.cpp;h=6379d14e630d747599fd48e0e9cfa907cab214cd;hb=b5bcf45d3328c87b56ed5d8f9dbec623504f7c9b#l2245>                 //s(["x"]) 2246 <http://gitweb.scilab.org/?p=scilab.git;a=blob;f=scilab/modules/ast/src/cpp/ast/visitor_common.cpp;h=6379d14e630d747599fd48e0e9cfa907cab214cd;hb=b5bcf45d3328c87b56ed5d8f9dbec623504f7c9b#l2246>                 types::GraphicHandle* pH = _pVar->getAs<types::GraphicHandle>(); 2247 <http://gitweb.scilab.org/?p=scilab.git;a=blob;f=scilab/modules/ast/src/cpp/ast/visitor_common.cpp;h=6379d14e630d747599fd48e0e9cfa907cab214cd;hb=b5bcf45d3328c87b56ed5d8f9dbec623504f7c9b#l2247>                 types::String *pS = (*_pArgs)[0]->getAs<types::String>(); 2248 <http://gitweb.scilab.org/?p=scilab.git;a=blob;f=scilab/modules/ast/src/cpp/ast/visitor_common.cpp;h=6379d14e630d747599fd48e0e9cfa907cab214cd;hb=b5bcf45d3328c87b56ed5d8f9dbec623504f7c9b#l2248>                 types::typed_list in; 2249 <http://gitweb.scilab.org/?p=scilab.git;a=blob;f=scilab/modules/ast/src/cpp/ast/visitor_common.cpp;h=6379d14e630d747599fd48e0e9cfa907cab214cd;hb=b5bcf45d3328c87b56ed5d8f9dbec623504f7c9b#l2249>                 types::typed_list out; 2250 <http://gitweb.scilab.org/?p=scilab.git;a=blob;f=scilab/modules/ast/src/cpp/ast/visitor_common.cpp;h=6379d14e630d747599fd48e0e9cfa907cab214cd;hb=b5bcf45d3328c87b56ed5d8f9dbec623504f7c9b#l2250>                 types::optional_list opt; 2251 <http://gitweb.scilab.org/?p=scilab.git;a=blob;f=scilab/modules/ast/src/cpp/ast/visitor_common.cpp;h=6379d14e630d747599fd48e0e9cfa907cab214cd;hb=b5bcf45d3328c87b56ed5d8f9dbec623504f7c9b#l2251> 2252 <http://gitweb.scilab.org/?p=scilab.git;a=blob;f=scilab/modules/ast/src/cpp/ast/visitor_common.cpp;h=6379d14e630d747599fd48e0e9cfa907cab214cd;hb=b5bcf45d3328c87b56ed5d8f9dbec623504f7c9b#l2252>                 in.push_back(pH); 2253 <http://gitweb.scilab.org/?p=scilab.git;a=blob;f=scilab/modules/ast/src/cpp/ast/visitor_common.cpp;h=6379d14e630d747599fd48e0e9cfa907cab214cd;hb=b5bcf45d3328c87b56ed5d8f9dbec623504f7c9b#l2253>                 in.push_back(pS); 2254 <http://gitweb.scilab.org/?p=scilab.git;a=blob;f=scilab/modules/ast/src/cpp/ast/visitor_common.cpp;h=6379d14e630d747599fd48e0e9cfa907cab214cd;hb=b5bcf45d3328c87b56ed5d8f9dbec623504f7c9b#l2254>                 in.push_back(_pInsert); 2255 <http://gitweb.scilab.org/?p=scilab.git;a=blob;f=scilab/modules/ast/src/cpp/ast/visitor_common.cpp;h=6379d14e630d747599fd48e0e9cfa907cab214cd;hb=b5bcf45d3328c87b56ed5d8f9dbec623504f7c9b#l2255> 2256 <http://gitweb.scilab.org/?p=scilab.git;a=blob;f=scilab/modules/ast/src/cpp/ast/visitor_common.cpp;h=6379d14e630d747599fd48e0e9cfa907cab214cd;hb=b5bcf45d3328c87b56ed5d8f9dbec623504f7c9b#l2256>                 types::Function* pCall = (types::Function*)symbol::Context::getInstance()->get(symbol::Symbol(L"set")); 2257 <http://gitweb.scilab.org/?p=scilab.git;a=blob;f=scilab/modules/ast/src/cpp/ast/visitor_common.cpp;h=6379d14e630d747599fd48e0e9cfa907cab214cd;hb=b5bcf45d3328c87b56ed5d8f9dbec623504f7c9b#l2257>                 if (pCall) 2258 <http://gitweb.scilab.org/?p=scilab.git;a=blob;f=scilab/modules/ast/src/cpp/ast/visitor_common.cpp;h=6379d14e630d747599fd48e0e9cfa907cab214cd;hb=b5bcf45d3328c87b56ed5d8f9dbec623504f7c9b#l2258>                 { 2259 <http://gitweb.scilab.org/?p=scilab.git;a=blob;f=scilab/modules/ast/src/cpp/ast/visitor_common.cpp;h=6379d14e630d747599fd48e0e9cfa907cab214cd;hb=b5bcf45d3328c87b56ed5d8f9dbec623504f7c9b#l2259>                     types::Callable::ReturnValue ret = pCall->call(in, opt, 1, out); 2260 <http://gitweb.scilab.org/?p=scilab.git;a=blob;f=scilab/modules/ast/src/cpp/ast/visitor_common.cpp;h=6379d14e630d747599fd48e0e9cfa907cab214cd;hb=b5bcf45d3328c87b56ed5d8f9dbec623504f7c9b#l2260>                     if (ret == types::Callable::OK) 2261 <http://gitweb.scilab.org/?p=scilab.git;a=blob;f=scilab/modules/ast/src/cpp/ast/visitor_common.cpp;h=6379d14e630d747599fd48e0e9cfa907cab214cd;hb=b5bcf45d3328c87b56ed5d8f9dbec623504f7c9b#l2261>                     { 2262 <http://gitweb.scilab.org/?p=scilab.git;a=blob;f=scilab/modules/ast/src/cpp/ast/visitor_common.cpp;h=6379d14e630d747599fd48e0e9cfa907cab214cd;hb=b5bcf45d3328c87b56ed5d8f9dbec623504f7c9b#l2262>                         pRet = _pVar; 2263 <http://gitweb.scilab.org/?p=scilab.git;a=blob;f=scilab/modules/ast/src/cpp/ast/visitor_common.cpp;h=6379d14e630d747599fd48e0e9cfa907cab214cd;hb=b5bcf45d3328c87b56ed5d8f9dbec623504f7c9b#l2263>                     } 2264 <http://gitweb.scilab.org/?p=scilab.git;a=blob;f=scilab/modules/ast/src/cpp/ast/visitor_common.cpp;h=6379d14e630d747599fd48e0e9cfa907cab214cd;hb=b5bcf45d3328c87b56ed5d8f9dbec623504f7c9b#l2264>                     else 2265 <http://gitweb.scilab.org/?p=scilab.git;a=blob;f=scilab/modules/ast/src/cpp/ast/visitor_common.cpp;h=6379d14e630d747599fd48e0e9cfa907cab214cd;hb=b5bcf45d3328c87b56ed5d8f9dbec623504f7c9b#l2265>                     { 2266 <http://gitweb.scilab.org/?p=scilab.git;a=blob;f=scilab/modules/ast/src/cpp/ast/visitor_common.cpp;h=6379d14e630d747599fd48e0e9cfa907cab214cd;hb=b5bcf45d3328c87b56ed5d8f9dbec623504f7c9b#l2266>                         throw ast::InternalError(ConfigVariable::getLastErrorMessage(), ConfigVariable::getLastErrorNumber(), e.getLocation()); 2267 <http://gitweb.scilab.org/?p=scilab.git;a=blob;f=scilab/modules/ast/src/cpp/ast/visitor_common.cpp;h=6379d14e630d747599fd48e0e9cfa907cab214cd;hb=b5bcf45d3328c87b56ed5d8f9dbec623504f7c9b#l2267>                     } 2268 <http://gitweb.scilab.org/?p=scilab.git;a=blob;f=scilab/modules/ast/src/cpp/ast/visitor_common.cpp;h=6379d14e630d747599fd48e0e9cfa907cab214cd;hb=b5bcf45d3328c87b56ed5d8f9dbec623504f7c9b#l2268>                 } 2269 <http://gitweb.scilab.org/?p=scilab.git;a=blob;f=scilab/modules/ast/src/cpp/ast/visitor_common.cpp;h=6379d14e630d747599fd48e0e9cfa907cab214cd;hb=b5bcf45d3328c87b56ed5d8f9dbec623504f7c9b#l2269>             } 2270 <http://gitweb.scilab.org/?p=scilab.git;a=blob;f=scilab/modules/ast/src/cpp/ast/visitor_common.cpp;h=6379d14e630d747599fd48e0e9cfa907cab214cd;hb=b5bcf45d3328c87b56ed5d8f9dbec623504f7c9b#l2270>             else 2271 <http://gitweb.scilab.org/?p=scilab.git;a=blob;f=scilab/modules/ast/src/cpp/ast/visitor_common.cpp;h=6379d14e630d747599fd48e0e9cfa907cab214cd;hb=b5bcf45d3328c87b56ed5d8f9dbec623504f7c9b#l2271>             { 2272 <http://gitweb.scilab.org/?p=scilab.git;a=blob;f=scilab/modules/ast/src/cpp/ast/visitor_common.cpp;h=6379d14e630d747599fd48e0e9cfa907cab214cd;hb=b5bcf45d3328c87b56ed5d8f9dbec623504f7c9b#l2272>                 pRet = _pVar->getAs<types::GraphicHandle>()->insert(_pArgs, _pInsert); 2273 <http://gitweb.scilab.org/?p=scilab.git;a=blob;f=scilab/modules/ast/src/cpp/ast/visitor_common.cpp;h=6379d14e630d747599fd48e0e9cfa907cab214cd;hb=b5bcf45d3328c87b56ed5d8f9dbec623504f7c9b#l2273>             } 2274 <http://gitweb.scilab.org/?p=scilab.git;a=blob;f=scilab/modules/ast/src/cpp/ast/visitor_common.cpp;h=6379d14e630d747599fd48e0e9cfa907cab214cd;hb=b5bcf45d3328c87b56ed5d8f9dbec623504f7c9b#l2274>         }

here one can see the delegation to "set" at line 2256...2259. However, the internal overload mechanism is still very obscure to me. Now that I can build scilab_master on my Linux machine, I have played a little bit and replaced lines 2246..2268 by the sole lines

pRet = callOverload(e, L"i", _pArgs, _pInsert, _pVar); sciprint("after callOverload\n")

then recompiled the ast module. The result is a scilab with a fully working graphics, e.g. typing "plot" without arguments works as usual and triggers a lot of handle insertions (a bunch of "after callOverload" are printed). However, there is no %h_i macro, so I don't understand by which miracle it could work.

Antoine it think that you are the author of this file (/ast/src/cpp/ast/visitor_common.cpp) can you explain how it works ?

Thanks in advance,

S.

Ok, no miracle... in fact, if the callOverload is forced as explained above, then generic_i_h is called (thanks Samuel for your hint), and generic_i_h itself calls "set". So this is almost equivalent, besides the fact that "set" is called from a Scilab macro and not from visitor_common.cpp above. With this solution the hijacking I had proposed does not crash anymore.

But after all these complications, I guess that there may be a more straightforward way of implementing new handle properties at the user level...

S.

--
Stéphane Mottelet
Ingénieur de recherche
EA 4297 Transformations Intégrées de la Matière Renouvelable
Département Génie des Procédés Industriels
Sorbonne Universités - Université de Technologie de Compiègne
CS 60319, 60203 Compiègne cedex
Tel : +33(0)344234688
http://www.utc.fr/~mottelet

_______________________________________________
dev mailing list
dev@lists.scilab.org
http://lists.scilab.org/mailman/listinfo/dev

Reply via email to