Re: mono_method_desc_search_in_image problem, and some question...
pierre <[email protected]> Tue, 13 Feb 2018 09:16:53 +0100
| Newsgroups | gmane.comp.gnome.mono.devel |
|---|---|
| Message-ID | <[email protected]> |
This is a multi-part message in MIME format.
--===============7463937923093858435==
Content-Type: multipart/alternative;
boundary="------------64354E958C211416D4F04914"
Content-Language: en-US
This is a multi-part message in MIME format.
--------------64354E958C211416D4F04914
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 8bit
Thanks for the answer.
> you 100% sure the old files are all overwritten?
Yes, I have checked the file time... and also included a
remove(fileName);
to be sure!
>There are a couple of different ways to get compiled binary at runtime
without a system() call
Which ones?
I have tried something:
calling mono_image_open_from_data_with_name and
mono_assembly_load_from_full with a different file name on every compile
and it is working!!!
so, the following code is not reloading properly:
monoEngine->fileName = strdup("code.dll");
monoEngine->image = mono_image_open_from_data_with_name(data, dataLen,
TRUE /* copy data */,
&status,
FALSE /* ref only */,
monoEngine->fileName);
if (status != MONO_IMAGE_OK || monoEngine->image == NULL)
{
}
monoEngine->assembly = mono_assembly_load_from_full(monoEngine->image,
monoEngine->fileName,
&status, FALSE);
if (status != MONO_IMAGE_OK || monoEngine->assembly == NULL)
{
}
but, the same with a different file name on every run (only the
monoEngine->fileName creation differ) is working:
static int version = 1;
...
sprintf(monoEngine->fileName, "code%03d.dll", version);
version ++;
monoEngine->image = mono_image_open_from_data_with_name(data, dataLen,
TRUE /*
copy data */,
&status,
FALSE /* ref only */,
monoEngine->fileName);
if (status != MONO_IMAGE_OK || monoEngine->image == NULL)
{
}
monoEngine->assembly = mono_assembly_load_from_full(monoEngine->image,
monoEngine->fileName,
&status, FALSE);
if (status != MONO_IMAGE_OK || monoEngine->assembly == NULL)
{
}
Is there a wait to be introduced after a mono_domain_unload? It is like
doing mono_domain_unload, mono_image_open_from_data_with_name and
mono_assembly_load_from_full with the same file name is detected and the
unload is not performed....
> This is more likely to be a problem outside of mono.
I do agree... but I am running out of idea on why!!!
and for mono_method_desc_search_in_image? is it bug?
Pierre
On 13/02/2018 07:15, R Zaghi wrote:
> I think we need to know a bit more about what you are doing in the
> code exactly but as a quick first guess if you are recompiling using a
> system() call then are you 100% sure the old files are all
> overwritten? There are a couple of different ways to get compiled
> binary at runtime without a system() call which I prefer but if you
> are using a system() call then have you tried two separate calls with
> two parallel binaries loaded as a start to debug your code?
>
> This is more likely to be a problem outside of mono.
>
> Ramin
>
>
>
>
> Ramin Zaghi
>
> *Mosaic3DX™ | User Interface Technology*
> St John's Innovation Centre,
> Cowley Road,
> Cambridge,
> CB4 0WS, UK*
> *
> *E*:**[email protected] <mailto:[email protected]>
> *T*: +44 1223 421 311 <tel:+44%201223%20421311>
> http://linkedin.com/in/raminzaghi
>
>
>
> On Tue, 13 Feb 2018 at 01:27, pierre <[email protected]
> <mailto:[email protected]>> wrote:
>
> Hi,
>
> I am trying to embed mono... and I ran into a problem with the code:
>
> monoMethodDesc = mono_method_desc_new("Script:Main", 0);
> method = mono_method_desc_search_in_image(monoMethodDesc,
> monoEngine->image);
>
>
> It is returning a method on the cs code:
>
> public class Script
> {
> static public void Main ()
> {
> ScriptEngine.report("--Main Called ");
> }
> }
>
>
> but it is also returning a method on the cs code (with the wrong
> class name):
>
> public class Script*2*
> {
> static public void Main ()
> {
> ScriptEngine.report("--Main Called ");
> }
> }
>
> while it should only return for:
>
> monoMethodDesc = mono_method_desc_new("Script2:Main", 0);
>
>
> Am i doing something wrong or is this a bug? It seem that
> mono_method_desc_search_in_image is returning a value if the
> actual class name is starting with the given class name.... so,
> the same method is returned if I look for "Script:Main" but the
> declared class is "Script:Main", "Script_test:Main" or
> "Script2:Main"...
>
> and a question:
> is there a way to know if mono_domain_unload was successful or not?
>
> I am creating an app domain per script so that I can recompile and
> reload the script at will...
> I do not detect any error, but the new script seems not to replace
> the old one...
> Basically, I am doing:
>
> res = mono_domain_set(rootDomain, FALSE);
> mono_domain_unload(monoEngine->domain);
> monoEngine->domain =
> mono_domain_create_appdomain("ScriptEngine-sub", NULL);
>
> data = readFile(f, &dataLen);
> fclose(f);
> monoEngine->image = mono_image_open_from_data_with_name(data,
> dataLen,
> TRUE /* copy data */,
> &status,
> FALSE /* ref only */,
> monoEngine->fileName);
> free(data);
> if (status != MONO_IMAGE_OK || monoEngine->image == NULL)
> {
> return FALSE;
> }
>
> // load the assembly
> monoEngine->assembly =
> mono_assembly_load_from_full(monoEngine->image,
> monoEngine->fileName,
> &status, FALSE);
> if (status != MONO_IMAGE_OK || monoEngine->assembly == NULL)
> {
> mono_image_close(monoEngine->image);
> return FALSE;
> }
>
> but it does not seem to work. The code that runs is always the
> first loaded one!!
>
> I also added the following code to my engine:
>
> mono_trace_set_log_handler(monoLogCallback, NULL);
> mono_trace_set_print_handler(monoPrintCallback);
> mono_trace_set_printerr_handler(monoPrintCallback);
> mono_trace_set_level_string ("debug");
>
>
> but it is reporting debug info only on the first run... is there a
> way to having it working on every run?
>
> Lastly, Is there a way to compile cs source without launching a
>
> system("msc.code.cs -target:library");
>
> thanks in advance
>
> Pierre
>
>
>
> _______________________________________________
> Mono-list maillist [email protected] <mailto:[email protected]>
> http://lists.dot.net/mailman/listinfo/mono-list
>
> _______________________________________________
> Mono-devel-list mailing list
> [email protected] <mailto:[email protected]>
> http://lists.dot.net/mailman/listinfo/mono-devel-list
>
> --
>
>
>
> Ramin Zaghi
>
> *Mosaic3DX™ | User Interface Technology*
> St John's Innovation Centre,
> Cowley Road,
> Cambridge,
> CB4 0WS, UK*
> *
> *E*:**[email protected] <mailto:[email protected]>
> *T*: +44 1223 421 311
> http://linkedin.com/in/raminzaghi
>
--------------64354E958C211416D4F04914
Content-Type: text/html; charset=utf-8
Content-Transfer-Encoding: 8bit
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body text="#000000" bgcolor="#FFFFFF">
<div class="moz-cite-prefix">Thanks for the answer.<br>
<br>
> you 100% sure the old files are all overwritten? <br>
Yes, I have checked the file time... and also included a<br>
<blockquote><tt>remove(fileName);</tt><br>
</blockquote>
to be sure!<br>
<br>
>There are a couple of different ways to get compiled binary at
runtime without a system() call <br>
Which ones? <br>
<br>
I have tried something: <br>
calling <tt>mono_image_open_from_data_with_name</tt> and <tt>mono_assembly_load_from_full
</tt>with a different file name on every compile and it is
working!!!<br>
<br>
so, the following code is not reloading properly:<br>
<blockquote><tt>monoEngine->fileName = strdup("code.dll");</tt><br>
<tt>monoEngine->image =
mono_image_open_from_data_with_name(data, dataLen, </tt><br>
<tt>
TRUE /* copy data */, </tt><br>
<tt>
&status, </tt><br>
<tt>
FALSE /* ref only */, </tt><br>
<tt>
monoEngine->fileName);</tt><br>
<tt>if (status != MONO_IMAGE_OK || monoEngine->image == NULL)</tt><br>
<tt>{</tt><br>
<tt>}</tt><br>
<tt>monoEngine->assembly =
mono_assembly_load_from_full(monoEngine->image, </tt><br>
<tt>
monoEngine->fileName, </tt><br>
<tt>
&status, FALSE);</tt><br>
<tt>if (status != MONO_IMAGE_OK || monoEngine->assembly ==
NULL)</tt><br>
<tt>{</tt><br>
<tt>}</tt><br>
</blockquote>
<br>
but, the same with a different file name on every run (only the <tt>monoEngine->fileName</tt>
creation differ<tt>) is working</tt>:<br>
<blockquote><tt>static int version = 1;</tt><br>
<tt>...</tt><br>
<br>
<tt>sprintf(monoEngine->fileName, "code%03d.dll", version);</tt><br>
<tt>version ++;</tt><br>
<tt>monoEngine->image =
mono_image_open_from_data_with_name(data, dataLen, </tt><br>
<tt>
TRUE
/* copy data */, </tt><br>
<tt>
&status, </tt><br>
<tt>
FALSE /* ref only */, </tt><br>
<tt>
monoEngine->fileName);</tt><br>
<tt>
if (status != MONO_IMAGE_OK || monoEngine->image == NULL)</tt><br>
<tt>
{</tt><br>
<tt>
}</tt><br>
<tt>
monoEngine->assembly =
mono_assembly_load_from_full(monoEngine->image, </tt><br>
<tt>
monoEngine->fileName, </tt><br>
<tt>
&status, FALSE);</tt><br>
<tt>
if (status != MONO_IMAGE_OK || monoEngine->assembly ==
NULL)</tt><br>
<tt>
{</tt><br>
<tt>
}</tt><br>
</blockquote>
Is there a wait to be introduced after a mono_domain_unload? It is
like doing <tt>mono_domain_unload,
mono_image_open_from_data_with_name and </tt><tt>mono_assembly_load_from_full
</tt>with the same file name is detected <tt>and the unload is
not performed....<br>
</tt><tt> </tt><br>
<br>
> This is more likely to be a problem outside of mono.<br>
I do agree... but I am running out of idea on why!!!<br>
<br>
<br>
and for mono_method_desc_search_in_image? is it bug?<br>
<br>
Pierre<br>
<br>
On 13/02/2018 07:15, R Zaghi wrote:<br>
</div>
<blockquote type="cite"
cite="mid:CAFLMc5v3aT2-C22k3XV2vsc_ByieY_t-LTLpZSM-GOZwkQ3xWA@mail.gmail.com">
<div>
<div>
<div dir="auto">I think we need to know a bit more about what
you are doing in the code exactly but as a quick first guess
if you are recompiling using a system() call then are you
100% sure the old files are all overwritten? There are a
couple of different ways to get compiled binary at runtime
without a system() call which I prefer but if you are using
a system() call then have you tried two separate calls with
two parallel binaries loaded as a start to debug your code?</div>
<div dir="auto"><br>
</div>
<div dir="auto">This is more likely to be a problem outside of
mono.</div>
<div dir="auto"><br>
</div>
<div dir="auto">Ramin</div>
</div>
</div>
<div>
<div>
<div dir="auto"><br>
</div>
<div dir="auto"><br>
</div>
<div dir="auto"><br>
</div>
<div dir="auto"><br>
</div>
<div dir="auto">
<div dir="ltr"
style="color:rgb(117,117,117);word-spacing:1px;font-size:1rem;line-height:normal!important">Ramin
Zaghi</div>
<div dir="ltr"
style="color:rgb(117,117,117);word-spacing:1px;line-height:normal!important"><br
style="line-height:normal!important">
<div style="line-height:normal!important"><img
src="https://drive.google.com/uc?id=0B3xiwa7kf1uwRlYxenBFM1o2NEk&export=download"
style="line-height: normal !important; overflow-wrap:
break-word !important;" moz-do-not-send="true"><b
style="line-height:normal!important;font-size:1rem">Mosaic3DX™
| <font
style="line-height:normal!important;font-size:0.625rem">User
Interface Technology</font></b></div>
<div style="line-height:normal!important">
<div
style="line-height:normal!important;font-size:0.8125rem">St
John's Innovation Centre,</div>
<div
style="line-height:normal!important;font-size:0.8125rem">Cowley
Road,</div>
<div
style="line-height:normal!important;font-size:0.8125rem">Cambridge,</div>
<div
style="line-height:normal!important;font-size:0.8125rem">CB4
0WS, UK<b style="line-height:normal!important"><br
style="line-height:normal!important">
</b></div>
<div
style="line-height:normal!important;font-size:0.8125rem"><b
style="line-height:normal!important;font-size:0.8125rem">E</b>:<b
style="line-height:normal!important"> </b><a
href="mailto:[email protected]" target="_blank"
style="font-size:0.8125rem;line-height:normal!important"
moz-do-not-send="true">[email protected]</a></div>
<div
style="line-height:normal!important;font-size:0.8125rem"><b
style="line-height:normal!important;font-size:0.8125rem">T</b>: <a
href="tel:+44%201223%20421311" value="+441223421311"
target="_blank"
style="font-size:0.8125rem;line-height:normal!important"
moz-do-not-send="true">+44 1223 421 311</a></div>
</div>
<div style="line-height:normal!important"><font
style="line-height:normal!important" size="2"><a
href="http://linkedin.com/in/raminzaghi"
target="_blank"
style="font-size:0.8125rem;line-height:normal!important"
moz-do-not-send="true">http://linkedin.com/in/raminzaghi</a></font></div>
<div style="line-height:normal!important" dir="auto"><br>
</div>
</div>
</div>
<div dir="auto"><br>
</div>
<br>
<div class="gmail_quote">
<div>On Tue, 13 Feb 2018 at 01:27, pierre <<a
href="mailto:[email protected]"
target="_blank" moz-do-not-send="true">[email protected]</a>>
wrote:<br>
</div>
<blockquote class="gmail_quote" style="margin:0 0 0
.8ex;border-left:1px #ccc solid;padding-left:1ex">
<div text="#000000" bgcolor="#FFFFFF">
<div
class="m_5069017230163669461m_-3097578244239708022moz-text-html"
lang="x-western"> Hi,<br>
<br>
I am trying to embed mono... and I ran into a problem
with the code: <br>
<blockquote><tt>monoMethodDesc =
mono_method_desc_new("Script:Main", 0);</tt><tt><br>
</tt><tt>method =
mono_method_desc_search_in_image(monoMethodDesc,
monoEngine->image);</tt><br>
</blockquote>
<br>
It is returning a method on the cs code:<br>
<blockquote><tt>public class Script</tt><tt><br>
</tt><tt>{</tt><tt><br>
</tt><tt> static public void Main ()</tt><tt><br>
</tt><tt> {</tt><tt><br>
</tt><tt> ScriptEngine.report("--Main Called ");</tt><tt><br>
</tt><tt> }</tt><tt><br>
</tt><tt>}</tt><br>
</blockquote>
<br>
but it is also returning a method on the cs code (with
the wrong class name):<br>
<br>
<blockquote><tt>public class Script<b>2</b></tt><tt><br>
</tt><tt> {</tt><tt><br>
</tt><tt> static public void Main ()</tt><tt><br>
</tt><tt> {</tt><tt><br>
</tt><tt> ScriptEngine.report("--Main Called ");</tt><tt><br>
</tt><tt> }</tt><tt><br>
</tt><tt> }</tt><br>
</blockquote>
while it should only return for:<br>
<blockquote><tt>monoMethodDesc =
mono_method_desc_new("Script2:Main", 0);</tt><br>
</blockquote>
<tt> </tt><br>
Am i doing something wrong or is this a bug? It seem
that <tt>mono_method_desc_search_in_image </tt>is
returning a value if the actual class name is starting
with the given class name.... so, the same method is
returned if I look for "Script:Main" but the declared
class is "Script:Main", "Script_test:Main" or
"Script2:Main"...<br>
<br>
and a question:<br>
is there a way to know if mono_domain_unload was
successful or not? <br>
<br>
I am creating an app domain per script so that I can
recompile and reload the script at will... <br>
I do not detect any error, but the new script seems
not to replace the old one...<br>
Basically, I am doing:<br>
<blockquote><tt>res = mono_domain_set(rootDomain,
FALSE);</tt><br>
<tt>mono_domain_unload(monoEngine->domain);</tt><br>
<tt>monoEngine->domain =
mono_domain_create_appdomain("ScriptEngine-sub",
NULL);</tt><br>
<br>
<tt>data = readFile(f, &dataLen);</tt><br>
<tt>fclose(f);</tt><br>
<tt>monoEngine->image =
mono_image_open_from_data_with_name(data, dataLen,
</tt><br>
<tt>
TRUE /* copy data */, </tt><br>
<tt>
&status, </tt><br>
<tt>
FALSE /* ref only */, </tt><br>
<tt>
monoEngine->fileName);</tt><br>
<tt> free(data);</tt><br>
<tt> if (status != MONO_IMAGE_OK ||
monoEngine->image == NULL)</tt><br>
<tt> {</tt><br>
<tt> return FALSE;</tt><br>
<tt> }</tt><br>
<br>
<tt> // load the assembly</tt><br>
<tt> monoEngine->assembly =
mono_assembly_load_from_full(monoEngine->image,
</tt><br>
<tt>
monoEngine->fileName, </tt><br>
<tt>
&status, FALSE);</tt><br>
<tt> if (status != MONO_IMAGE_OK ||
monoEngine->assembly == NULL)</tt><br>
<tt> {</tt><br>
<tt> mono_image_close(monoEngine->image);</tt><br>
<tt> return FALSE;</tt><br>
<tt> }</tt><br>
</blockquote>
but it does not seem to work. The code that runs is
always the first loaded one!! <br>
<br>
I also added the following code to my engine:<br>
<blockquote><tt>mono_trace_set_log_handler(monoLogCallback,
NULL);</tt><br>
<tt>mono_trace_set_print_handler(monoPrintCallback);</tt><br>
<tt>mono_trace_set_printerr_handler(monoPrintCallback);</tt><br>
<tt>mono_trace_set_level_string ("debug");</tt><br>
</blockquote>
<br>
but it is reporting debug info only on the first
run... is there a way to having it working on every
run?<br>
<br>
Lastly, Is there a way to compile cs source without
launching a <br>
<blockquote><tt>system("msc.code.cs -target:library");</tt><br>
</blockquote>
thanks in advance<br>
<br>
Pierre<br>
<br>
</div>
<br>
<fieldset
class="m_5069017230163669461m_-3097578244239708022mimeAttachmentHeader"></fieldset>
<br>
<div
class="m_5069017230163669461m_-3097578244239708022moz-text-plain"
style="font-family:-moz-fixed;font-size:14px"
lang="x-unicode">
<pre>_______________________________________________
Mono-list maillist - <a class="m_5069017230163669461m_-3097578244239708022moz-txt-link-abbreviated" href="mailto:[email protected]" target="_blank" moz-do-not-send="true">[email protected]</a>
<a class="m_5069017230163669461m_-3097578244239708022moz-txt-link-freetext" href="http://lists.dot.net/mailman/listinfo/mono-list" target="_blank" moz-do-not-send="true">http://lists.dot.net/mailman/listinfo/mono-list</a>
</pre>
</div>
</div>
_______________________________________________<br>
Mono-devel-list mailing list<br>
<a href="mailto:[email protected]"
target="_blank" moz-do-not-send="true">[email protected]</a><br>
<a
href="http://lists.dot.net/mailman/listinfo/mono-devel-list"
rel="noreferrer" target="_blank" moz-do-not-send="true">http://lists.dot.net/mailman/listinfo/mono-devel-list</a><br>
</blockquote>
</div>
</div>
</div>
<div dir="ltr">-- <br>
</div>
<div class="gmail_signature" data-smartmail="gmail_signature">
<div dir="ltr">
<div>
<div dir="ltr">
<div>
<div dir="ltr">
<div>
<div dir="ltr">
<div>
<div dir="ltr"><br>
</div>
<div dir="ltr"><br>
</div>
<div dir="ltr"><br>
</div>
<div dir="ltr">Ramin Zaghi</div>
<div dir="ltr"><br>
<div><img
src="https://drive.google.com/uc?id=0B3xiwa7kf1uwRlYxenBFM1o2NEk&export=download"
moz-do-not-send="true"><b>Mosaic3DX™ | <font
size="1">User Interface Technology</font></b></div>
<div>
<div style="font-size:small">St John's
Innovation Centre,</div>
<div style="font-size:small">Cowley Road,</div>
<div style="font-size:small">Cambridge,</div>
<div style="font-size:small">CB4 0WS, UK<b><br>
</b></div>
<div style="font-size:small"><b>E</b>:<b> </b><a
href="mailto:[email protected]"
target="_blank" moz-do-not-send="true">[email protected]</a></div>
<div style="font-size:small"><b>T</b>: +44
1223 421 311</div>
</div>
<div><font size="2"><a
href="http://linkedin.com/in/raminzaghi"
target="_blank" moz-do-not-send="true">http://linkedin.com/in/raminzaghi</a></font></div>
<div><font size="2"><br>
</font></div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</blockquote>
<p><br>
</p>
</body>
</html>
--------------64354E958C211416D4F04914--
--===============7463937923093858435==
Content-Type: text/plain; charset="utf-8"
MIME-Version: 1.0
Content-Transfer-Encoding: base64
Content-Disposition: inline
X19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX18KTW9uby1kZXZl
bC1saXN0IG1haWxpbmcgbGlzdApNb25vLWRldmVsLWxpc3RAbGlzdHMuZG90Lm5ldApodHRwOi8v
bGlzdHMuZG90Lm5ldC9tYWlsbWFuL2xpc3RpbmZvL21vbm8tZGV2ZWwtbGlzdAo=
--===============7463937923093858435==--