<html>
<head>
<meta content="text/html; charset=ISO-8859-1"
http-equiv="Content-Type">
</head>
<body bgcolor="#FFFFFF" text="#000000">
<div class="moz-cite-prefix">Hi!<br>
<br>
You do not need to file a bug, I saw the error in the doc a few
weeks ago and corrected it in master. It will be correct in R16. <br>
The port_driver.c code looks like this in master:<br>
---------------------<br>
/* port_driver.c */<br>
<br>
#include <stdio.h><br>
#include "erl_driver.h"<br>
<br>
typedef struct {<br>
ErlDrvPort port;<br>
} example_data;<br>
<br>
static ErlDrvData example_drv_start(ErlDrvPort port, char *buff)<br>
{<br>
example_data* d =
(example_data*)driver_alloc(sizeof(example_data));<br>
d->port = port;<br>
return (ErlDrvData)d;<br>
}<br>
<br>
static void example_drv_stop(ErlDrvData handle)<br>
{<br>
driver_free((char*)handle);<br>
}<br>
<br>
static void example_drv_output(ErlDrvData handle, char *buff, <br>
ErlDrvSizeT bufflen)<br>
{<br>
example_data* d = (example_data*)handle;<br>
char fn = buff[0], arg = buff[1], res;<br>
if (fn == 1) {<br>
res = foo(arg);<br>
} else if (fn == 2) {<br>
res = bar(arg);<br>
}<br>
driver_output(d->port, &res, 1);<br>
}<br>
<br>
ErlDrvEntry example_driver_entry = {<br>
NULL, /* F_PTR init, called when driver is loaded
*/<br>
example_drv_start, /* L_PTR start, called when port is
opened */<br>
example_drv_stop, /* F_PTR stop, called when port is
closed */<br>
example_drv_output, /* F_PTR output, called when erlang
has sent */<br>
NULL, /* F_PTR ready_input, called when input
descriptor ready */<br>
NULL, /* F_PTR ready_output, called when output
descriptor ready */<br>
"example_drv", /* char *driver_name, the argument to
open_port */<br>
NULL, /* F_PTR finish, called when unloaded */<br>
NULL, /* void *handle, Reserved by VM */<br>
NULL, /* F_PTR control, port_command callback */<br>
NULL, /* F_PTR timeout, reserved */<br>
NULL, /* F_PTR outputv, reserved */<br>
NULL, /* F_PTR ready_async, only for
async drivers */<br>
NULL, /* F_PTR flush, called when port
is about <br>
to be closed, but there is data in driver <br>
queue */<br>
NULL, /* F_PTR call, much like control,
sync call<br>
to driver */<br>
NULL, /* F_PTR event, called when an
event selected <br>
by driver_event() occurs. */<br>
ERL_DRV_EXTENDED_MARKER, /* int extended marker, Should
always be <br>
set to indicate driver versioning */<br>
ERL_DRV_EXTENDED_MAJOR_VERSION, /* int major_version, should
always be <br>
set to this value */<br>
ERL_DRV_EXTENDED_MINOR_VERSION, /* int minor_version, should
always be <br>
set to this value */<br>
0, /* int driver_flags, see
documentation */<br>
NULL, /* void *handle2, reserved for VM
use */<br>
NULL, /* F_PTR process_exit, called when
a <br>
monitored process dies */<br>
NULL /* F_PTR stop_select, called to
close an <br>
event object */<br>
};<br>
<br>
DRIVER_INIT(example_drv) /* must match name in driver_entry */<br>
{<br>
return &example_driver_entry;<br>
}<br>
-------------------------------<br>
<br>
Cheers,<br>
/Patrik<br>
On 01/04/2013 04:18 AM, Jeffrey Rennie wrote:<br>
</div>
<blockquote cite="mid:00b601cdea2a$2c538710$84fa9530$@com"
type="cite">
<meta http-equiv="Content-Type" content="text/html;
charset=ISO-8859-1">
<meta name="Generator" content="Microsoft Word 12 (filtered
medium)">
<style><!--
/* Font Definitions */
@font-face
{font-family:"MS Mincho";
panose-1:2 2 6 9 4 2 5 8 3 4;}
@font-face
{font-family:"Cambria Math";
panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
{font-family:Calibri;
panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
{font-family:Tahoma;
panose-1:2 11 6 4 3 5 4 4 2 4;}
@font-face
{font-family:Consolas;
panose-1:2 11 6 9 2 2 4 3 2 4;}
@font-face
{font-family:"\@MS Mincho";
panose-1:2 2 6 9 4 2 5 8 3 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{margin:0in;
margin-bottom:.0001pt;
font-size:12.0pt;
font-family:"Times New Roman","serif";}
a:link, span.MsoHyperlink
{mso-style-priority:99;
color:blue;
text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
{mso-style-priority:99;
color:purple;
text-decoration:underline;}
p
{mso-style-priority:99;
mso-margin-top-alt:auto;
margin-right:0in;
mso-margin-bottom-alt:auto;
margin-left:0in;
font-size:12.0pt;
font-family:"Times New Roman","serif";}
pre
{mso-style-priority:99;
mso-style-link:"HTML Preformatted Char";
margin:0in;
margin-bottom:.0001pt;
font-size:10.0pt;
font-family:"Courier New";}
span.HTMLPreformattedChar
{mso-style-name:"HTML Preformatted Char";
mso-style-priority:99;
mso-style-link:"HTML Preformatted";
font-family:Consolas;}
span.EmailStyle20
{mso-style-type:personal-reply;
font-family:"Calibri","sans-serif";
color:#1F497D;}
.MsoChpDefault
{mso-style-type:export-only;}
@page WordSection1
{size:8.5in 11.0in;
margin:1.0in 1.0in 1.0in 1.0in;}
div.WordSection1
{page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
<div class="WordSection1">
<p class="MsoNormal"><span
style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D">Here's
the first real clue. The example driver is being unloaded
before it's invoked! See below for the call stack of the
unload.<o:p></o:p></span></p>
<p class="MsoNormal"><span
style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D"><o:p> </o:p></span></p>
<p class="MsoNormal"><span
style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D">This
must be either a bug in the documentation at <o:p></o:p></span></p>
<p class="MsoNormal"><a moz-do-not-send="true"
href="http://www.erlang.org/doc/tutorial/c_portdriver.html"
target="_blank">http://www.erlang.org/doc/tutorial/c_portdriver.html</a><o:p></o:p></p>
<p class="MsoNormal"><span
style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D">or
a bug in the erlang itself.<o:p></o:p></span></p>
<p class="MsoNormal"><span
style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D"><o:p> </o:p></span></p>
<p class="MsoNormal"><span
style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D">What's
the process for filing a bug?<o:p></o:p></span></p>
<p class="MsoNormal"><span
style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D"><o:p> </o:p></span></p>
<p class="MsoNormal"><span
style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D"><o:p> </o:p></span></p>
<p class="MsoNormal"><span
style="font-size:11.0pt;font-family:"Courier
New";color:#1F497D">0439f644 517572e2
example_drv!example_drv_finish(void)+0x1e
[c:\users\jeff\code\code\port_driver\port_driver.cpp @ 64]<o:p></o:p></span></p>
<p class="MsoNormal"><span
style="font-size:11.0pt;font-family:"Courier
New";color:#1F497D">0439f654 51757729
beam_smp!do_unload_driver_entry(struct DE_Handle * dh =
0x00000000, unsigned long * save_name = 0x00000000)+0x72
[c:\users\jeff\github\otp\erts\emulator\beam\erl_bif_ddll.c
@ 1655]<o:p></o:p></span></p>
<p class="MsoNormal"><span
style="font-size:11.0pt;font-family:"Courier
New";color:#1F497D">0439f680 51797c2b
beam_smp!ddll_no_more_references(void * vdh =
0x517576d0)+0x59
[c:\users\jeff\github\otp\erts\emulator\beam\erl_bif_ddll.c
@ 1221]<o:p></o:p></span></p>
<p class="MsoNormal"><span
style="font-size:11.0pt;font-family:"Courier
New";color:#1F497D">0439f69c 5179b89f
beam_smp!exec_misc_ops(struct ErtsRunQueue_ * rq =
0x518c3b8c)+0x7b
[c:\users\jeff\github\otp\erts\emulator\beam\erl_process.c @
7231]<o:p></o:p></span></p>
<p class="MsoNormal"><span
style="font-size:11.0pt;font-family:"Courier
New";color:#1F497D">0439f6c8 51801be7
beam_smp!schedule(struct process * p = 0x00000002, int calls
= 0)+0x5df
[c:\users\jeff\github\otp\erts\emulator\beam\erl_process.c @
6891]<o:p></o:p></span></p>
<p class="MsoNormal"><span
style="font-size:11.0pt;font-family:"Courier
New";color:#1F497D">0439f6fc 7714c7c5
beam_smp!process_main+0x167<o:p></o:p></span></p>
<p class="MsoNormal"><span
style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D"><o:p> </o:p></span></p>
<p class="MsoNormal"><span
style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D"><o:p> </o:p></span></p>
<div style="border:none;border-left:solid blue 1.5pt;padding:0in
0in 0in 4.0pt">
<div>
<div style="border:none;border-top:solid #B5C4DF
1.0pt;padding:3.0pt 0in 0in 0in">
<p class="MsoNormal"><b><span
style="font-size:10.0pt;font-family:"Tahoma","sans-serif"">From:</span></b><span
style="font-size:10.0pt;font-family:"Tahoma","sans-serif"">
Robert Raschke [<a class="moz-txt-link-freetext" href="mailto:rtrlists@googlemail.com">mailto:rtrlists@googlemail.com</a>] <br>
<b>Sent:</b> Thursday, January 03, 2013 12:37 AM<br>
<b>To:</b> SurferJeff<br>
<b>Cc:</b> <a class="moz-txt-link-abbreviated" href="mailto:erlang-questions@erlang.org">erlang-questions@erlang.org</a>;
<a class="moz-txt-link-abbreviated" href="mailto:erlang-programming@googlegroups.com">erlang-programming@googlegroups.com</a><br>
<b>Subject:</b> Re: [erlang-questions] open_port
returns enoent even when driver init function executes
correctly.<o:p></o:p></span></p>
</div>
</div>
<p class="MsoNormal"><o:p> </o:p></p>
<p>You can try running erl.exe with sasl enabled to get better
error messages.<o:p></o:p></p>
<p>The messages you see at the moment are coming out
interleaved, like in the old joke "When faced with a problem
you decide to use threading, ..." :-)<o:p></o:p></p>
<p>Robby<o:p></o:p></p>
<div>
<p class="MsoNormal">On Jan 3, 2013 4:53 AM, "SurferJeff"
<<a moz-do-not-send="true"
href="mailto:surferjeff@gmail.com">surferjeff@gmail.com</a>>
wrote:<o:p></o:p></p>
<div>
<p class="MsoNormal">I found the recipe to build debug:<o:p></o:p></p>
</div>
<div>
<pre>$ cd $ERL_TOP<o:p></o:p></pre>
<pre>$ rm bin/win32/erlexec.dll<o:p></o:p></pre>
<pre>$ cd erts/emulator<o:p></o:p></pre>
<pre>$ make debug<o:p></o:p></pre>
<pre>$ cd ../etc<o:p></o:p></pre>
<pre>$ make debug<o:p></o:p></pre>
</div>
<div>
<p class="MsoNormal"> <o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">And it succeeded. However, the next
command in the recipe fails:<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><a moz-do-not-send="true"
href="mailto:jeff@lenovo" target="_blank"><span
style="font-family:"Courier New"">jeff@lenovo</span></a><span
style="font-family:"Courier New"">
/cygdrive/c/Users/jeff/GitHub/otp<br>
$ make local_setup<br>
make[1]: Entering directory
`/cygdrive/c/Users/jeff/GitHub/otp/erts'<br>
make[2]: Entering directory
`/cygdrive/c/Users/jeff/GitHub/otp/erts/start_script<br>
s'<br>
make[2]: Nothing to be done for `debug'.<br>
make[2]: Leaving directory
`/cygdrive/c/Users/jeff/GitHub/otp/erts/start_scripts<br>
'<br>
ct_run.exe dialyzer.exe erl.ini erl_crash.dump
escript.exe run_test.exe typer.ex<br>
e werl.exe win32<br>
make[2]: Entering directory
`/cygdrive/c/Users/jeff/GitHub/otp/erts/start_script<br>
s'<br>
/usr/bin/install -c -d
/cygdrive/c/users/jeff/github/otp/erts/start_scripts/tmp<br>
( cd
/cygdrive/c/users/jeff/github/otp/erts/start_scripts/tmp
&& \<br>
erlc -W
-I/cygdrive/c/users/jeff/github/otp/lib/kernel/ebin
-I/cygdrive/c/use<br>
rs/jeff/github/otp/lib/stdlib/ebin
-I/cygdrive/c/users/jeff/github/otp/lib/sasl/<br>
ebin +no_warn_sasl +otp_build -o
/cygdrive/c/users/jeff/github/otp/bin/start.scr<br>
ipt
/cygdrive/c/users/jeff/github/otp/erts/start_scripts/start_clean.rel
)<br>
File not found:
"c:/cygdrive/c/users/jeff/github/otp/erts/start_scripts/start_cl<br>
ean.rel"<br>
Makefile:129: recipe for target
`/cygdrive/c/users/jeff/github/otp/bin/start.scr<br>
ipt' failed<br>
make[2]: ***
[/cygdrive/c/users/jeff/github/otp/bin/start.script]
Error 1<br>
make[2]: Leaving directory
`/cygdrive/c/Users/jeff/GitHub/otp/erts/start_scripts<br>
'<br>
Makefile:69: recipe for target `local_setup' failed<br>
make[1]: *** [local_setup] Error 2<br>
make[1]: Leaving directory
`/cygdrive/c/Users/jeff/GitHub/otp/erts'<br>
Makefile:883: recipe for target `local_setup' failed<br>
make: *** [local_setup] Error 2</span><o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"> <o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"> <o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">And now my erl.exe is completely
hosed:<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><a moz-do-not-send="true"
href="mailto:jeff@lenovo" target="_blank"><span
style="font-family:"Courier New"">jeff@lenovo</span></a><span
style="font-family:"Courier New"">
/cygdrive/c/Users/jeff/GitHub/otp/bin/win32<br>
$ ./erl.exe<br>
{(no error logger present"i)n ietr rtoerr:
m"iEnrartoirn gi ni np rdooc_ebsoost<br>
"<,0{.b2a.d0a>r wgi,t[h{ eerxli_tp rviaml_uleo:a
d{ebra,dcahregc,k[_{feirlle__pr<br>
reismu_llto,a3d,e[r{,fcihleec,k"_efrill_ep_rriems_ullota,d3er,[.{efrill"e},,\{"l<br>
eirnle_,p28r3i}m]_}l,o{aidneirt.,egrelt\_"b}o,o{tl,i1n,e[,{2f8i3l}e,]"}i,n{iitn.<br>
ite,rgle"t},_{bloionte,,178,5[}{]f}i,l{ei,n\i"ti,ngiett._ebrolo\t",}2,,{[l{ifnie<br>
l,e7,8"5i}n]i}t,.{eirnli"t},,g{elti_nbeo,o77t2,}2]},,[{{ifniilte,,d\o"_ibnoiott.<br>
,e3r,l[\{"f}i,l{el,i"nien,i7t7.2e}r]l}",}{,i{nliitn,ed,o73_9b}o]o}t],}3},<br>
[{file,\"init.erl\"},{line,739}]}]}\n"</span><o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><span
style="font-family:"Courier New"">Crash dump
was written to: erl_crash.dump<br>
init terminating in do_boot ()</span><o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"> <o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><br>
On Wednesday, January 2, 2013 7:26:09 PM UTC-8,
SurferJeff wrote:<o:p></o:p></p>
</div>
<blockquote style="border:none;border-left:solid #CCCCCC
1.0pt;padding:0in 0in 0in
6.0pt;margin-left:4.8pt;margin-right:0in">
<p class="MsoNormal">I'm working through the example here:
<br>
<a moz-do-not-send="true"
href="http://www.erlang.org/doc/tutorial/c_portdriver.html"
target="_blank">http://www.erlang.org/doc/tutorial/c_portdriver.html</a>
<br>
And I'm trying to get it to run on Windows. I reordered
the code in the C <br>
source so that it compiles, and added a module.def file
so that erlang <br>
actually finds and executes the driver init function. <br>
<br>
I attached a debugger. Walking back up the stack, I
observe that: <br>
The driver init function returns correctly. <br>
erts_sys_ddll_call_init() returns correctly. <br>
do_load_driver_entry() returns ERL_DE_NO_ERROR. <br>
load_driver_entry() returns ERL_DE_NO_ERROR. <br>
erl_ddll_try_load_3 returns t = TUPLE2(hp, am_ok,
ok_term); on line 417 of <br>
erl_bif_ddl.c. <br>
But the next higher call on the stack is
_process_main(), which was compiled <br>
with gcc and has no debug symbols so I can't step
through and figure out why <br>
the end result is: <br>
<br>
=ERROR REPORT==== 2-Jan-2013::19:14:22 === <br>
Error in process <0.31.0> with exit value: <br>
{enoent,[{erlang,open_port,[{spawn,"example_drv"},[]],[]},{complex5,init,1,[
<br>
{file,"c:/Users/jeff/code/code/port_driver/complex5.erl"},{line,19}]}]}
<br>
<br>
Has anyone seen this before? <br>
<br>
If not, how do I recompile erl.exe purely with cl.exe
(no gcc) so that it <br>
generates debug symbols? And while I'm recompiling, how
do I turn off all <br>
optimizations? I can read basic make files, but I get
lost in the configure <br>
scripts and .in and .mk files. Please take pity on a
Windows programmer ;-) <br>
<br>
<br>
_______________________________________________ <br>
erlang-questions mailing list <br>
<a moz-do-not-send="true"
href="mailto:erlang-questions@erlang.org"
target="_blank">erlang-questions@erlang.org</a> <br>
<a moz-do-not-send="true"
href="http://erlang.org/mailman/listinfo/erlang-questions"
target="_blank">http://erlang.org/mailman/listinfo/erlang-questions</a>
<o:p></o:p></p>
</blockquote>
<p class="MsoNormal" style="margin-bottom:12.0pt"><br>
_______________________________________________<br>
erlang-questions mailing list<br>
<a moz-do-not-send="true"
href="mailto:erlang-questions@erlang.org">erlang-questions@erlang.org</a><br>
<a moz-do-not-send="true"
href="http://erlang.org/mailman/listinfo/erlang-questions"
target="_blank">http://erlang.org/mailman/listinfo/erlang-questions</a><o:p></o:p></p>
</div>
</div>
</div>
<br>
<fieldset class="mimeAttachmentHeader"></fieldset>
<br>
<pre wrap="">_______________________________________________
erlang-questions mailing list
<a class="moz-txt-link-abbreviated" href="mailto:erlang-questions@erlang.org">erlang-questions@erlang.org</a>
<a class="moz-txt-link-freetext" href="http://erlang.org/mailman/listinfo/erlang-questions">http://erlang.org/mailman/listinfo/erlang-questions</a>
</pre>
</blockquote>
<br>
</body>
</html>