I am taking a look at the implementation of libsmbclient. The source code I have for samba is 4.1.13. I can find the example testXXX.c functions which shows the examples of using libsmbclient functions. I also found a header file called libsmbclient.h which has all these function prototypes definitions, such as smbc_open, smbc_read and so on. I want to see the really implementation of smbc_open() function, and some other functions. I did grep -r 'smbc_open' *, but I didn't find any place that has the implementation of this function. All I see are the callers calling this function or this prototype definition. So where can I find this function implementation?
I found it. All these smbc_open(), close() ... functions are implemented in libsmb_compat.c
Related
I am using a third-party library that is a wrapper over some C functions. Unfortunately, nearly all of the Go functions are free (they don't have a receiver, they are not methods); not the design approach I would have taken but it is what I have.
Using just Go's standard "testing" library:
Is there a solution that allows me to create tests where I can mock functions?
Or is the solution to wrap the library into structures and interfaces, then mock the interface to achieve my goal?
I have created a monte carlo simulation that also process the produced dataset. One of my evaluation algorithms looks for specific models that it then passes the third-party function for its evaluation. I know my edge cases and know what the call counts should be, and this is what I want to test.
Perhaps a simple counter is all that is needed?
Other projects using this library, that I have found, do not have full coverage or no testing at all.
You can do this by using a reference to the actual function whenever you need to call it.
Then, when you need to mock the function you just point the reference to a mock implementation.
Let's say this is your external function:
// this is the wrapper for an external function
func externalFunction(i int) int {
return i * 10 // do something with input
}
You never call this directly but instead declare a reference to it:
var processInt func(int) int = externalFunction
When you need to invoke the function you do it using the reference:
fmt.Println(processInt(5))
Then, went you want to mock the function you just assign a mock implementation to that reference:
processInt = mockFunction
This playground puts it together and might be more clear than the explanation:
https://play.golang.org/p/xBuriFHlm9
If you have a function that receives a func(int) int, you can send that function either the actual externalFunction or the mockFunction when you want it to use the mock implementation.
I use the code
clc;
clear;
getd();
a=1;
b=myFunction();
, where myFunction is defined by
function b=myFunction()
b=a+1;
endfunction
. For some strange reason, this works just fine in Scilab. I believe myFunction simply inherits a from the main function. This is in contrast with for instance Matlab, where a needs to be an input argument of myFunction in order to use it.
I want functions in Scilab to only work with local variables and variables given as input, like in Matlab. So that in this case a is not inherited from the main function.
How can I achieve this?
This works fine in Scilab because in case a function uses an undefined variable the interpreter search it in the calling scope. Although it seems strange, this is how it works and I think this behavior cannot be changed without modifying the source code as #NormalHuman said.
In your example your code is working because you have the "a" variable is defined in the calling scope, but if you execute the function in another situation it could fail. In my opinion a function defined in this way has a defect in its code.
I am using a lot Scilab and I don't see this as a real problem, but I agree with you that this behavior is quite strange and it should not exist.
However, if you are worried of developing incorrectly a function that works well while you are writing the code due to a variable defined in calling scope, the solution for that is to create some unit tests and execute them in a clean interpreter.
You can avoid this by choosing distinct names for variables you wish to be local.
Like putting a myFunction_ in front of all the local variable names. In your example, you would rename a into myFunction_a.
Unfortunately, I don't know if it would be possible to write a script that would do the work for you in case you have large matlab scripts.
(defn domready [handler]
(.addEventListener js/window "DOMContentLoaded" handler))
I borrowed this code from here. The problem is I don't totally understand what's going on. JS interop is still a bit of a mystery to me.
.addEventListener
So this is clearly a procedure call, but it's kind of generic. It's like Clojurescript took everything that was inside an object, took it out, and you use it to call that method on "objects". As long as that "object" has the ".addEventListener" property it will call this. Is that what it's doing? Why not use a keyword instead? like (:addEventListener domElement) that seems more logical to me.
js/window
What is this? Is it a namespace or an object? Are they the same thing?
"DOMContentLoaded"
A string, that's familiar.
handler
Also familiar, but does it have a notion of this? Not that I'm really going to miss this.
.addEventListener
So this is clearly a procedure call, but it's kind
of generic. It's like Clojurescript took everything that was inside an
object, took it out, and you use it to call that method on "objects".
As long as that "object" has the ".addEventListener" property it will
call this. Is that what it's doing? Why not use a keyword instead?
like (:addEventListener domElement) that seems more logical to me.
Your mental model about how this works is mostly fine. What it does when it compiles is move the function name to be run as a method on the first argument.
(.method obj ...args) get's transformed to obj.method(...args)
This type of interop comes from the parent language Clojure.
On why do we have an explicit version of calling the function that's not Clojure idiomatic, I think the idea is to have clear separation between what is native Clojure code with Clojure semantics (immutability, friendly to CLJ data structures, etc) and what is interoperating with the host environment (mutable, not friendly to CLJ data structures, etc).
In my opinion it is better to have clear separation between those two given how different the semantics of CLJS and the host platforms are. For me explicitness is better than implicit in this case (it is easy to spot looking at the code what is JS code in CLJS, and what is pure CLJS).
js/window
What is this? Is it a namespace or an object? Are they the same thing?
Both, js/ is accessing the namespace js, which is where CLJS puts the JS namespace (since there is only one and global). window is just grabbing the window variable from the js namespace.
This is no different from how you access variables in other namespaces in CLJS. If you (def a 1) in (ns cljs.test) and then run cljs.test/a that will give you 1. Same form, ns/something-in-that-ns.
"DOMContentLoaded"
A string, that's familiar.
\o/
handler
Also familiar, but does it have a notion of this? Not that I'm really going to miss this.
Not sure what this has to do with handler. It is just a higher order function passed into domready as a parameter, like you would do in JS: function domready (onReady) { window.addEventListener("DOMContentLoaded", onReady) }
I hope this helps, if you want to try it out live and learn some more, maybe visit the Talking with JS on the Diving into ClojureScript tutorial, or maybe check this section of the lt-cljs-tutorial.
I'm just learning clojurescript so I don't really know if it is the correct answer but I've done it in the following way:
(defn handler [] (js/console.log "ready"))
(js/document.addEventListener "DOMContentLoaded" handler)
which is then translated to
cljs.user.handler = (function cljs$user$handler(){
return console.log("ready");
});
document.addEventListener("DOMContentLoaded",cljs.user.handler);
to check how clojurescript translate code I've used KLIMPSE http://app.klipse.tech/
.addEventListener is a method call on the global Javascript object js/window. This method call takes two parameters: "DOMContentLoaded" and handler.
When you are doing interop (either Java or Javascript) you really are calling methods on objects. There are macros behind what is happening here. What is straight after the ( is a verb, which I usually think of as a function call (although it might also be a macro or a special form). When doing interop what comes after the verb is the instance, and after that the parameters.
If it were straight Javascript it would look like this:
function domready(handler){
window.addEventListener("DOMContentLoaded" handler);
}
I wanted to move from one point to other on a spherical earth, and when I looked up, I found there is a function named reckon in matlab that does exactly what I need. But when I call it, it says Undefined function 'reckon' for input arguments of type 'double. Which means that maybe the function is not in my library. So I found the m-file from the internet and tried, but then it leads to same error with a different function, which I found the function reckon depends on. So I included that in my folder too, and then again there is a new function missing... and so on.
I have Matlab R2011b.
These functions seem to be in-built matlab functions as they show up in help, but as I'm new to matlab, maybe I'm wrong. What can be done?
As i just wanted to use the functions of the Mapping Toolbox,after some looking up, i found them all in a single package on a website. If any body else wants them too, and don't have the mapping toolbox, you can get all the functions here.
http://mooring.ucsd.edu/software/matlab/doc/toolbox/geo/index.html
I'm looking for a way to inline functions in AS3.
I know that the language itself doesn't offer a native way of doing that but perhaps there is another option:
ANT precompile task
shell script
command line tool
...
Basically, anything that could eventually be integrated with ANT and run on a Hudson CI server.
You can use Joa Ebert Apparat tools to achieve such a thing and more.
You can't inline whatever function you want they are some restrictions
Basically you have to create a new class that extends Macro or Inlined following your need, and declare static function within it, then after running TDSI your function will be inlined.
Check out for example Math inlined function or Macro function
Adobe introduced native inline functions with the new ASC2 compiler in 2012. Use the -inline compiler argument to inline all getters and setters and any functions marked with the new [Inline] metadata. Inlined functions must meet these conditions:
The function is final, static or the containing scope is file or package
The function does not contain any activations
The function does not contain any try or with statements
The function does not contain any function closures
The function body contains less than 50 expressions
http://www.bytearray.org/?p=4789