Commit graph

2,720 commits

Author SHA1 Message Date
William S Fulton
c17f77750a Merge pull request #176 from v-for-vandal/lua_eq
Add default __eq implementation for Lua
2014-06-02 19:52:07 +01:00
William S Fulton
22be94d207 Fix std::vector<bool> compile problems on OSX for Javascript 2014-05-31 19:58:42 +01:00
Karl Wette
5c5510842b Octave: remove Python code from std_carray.i 2014-05-29 23:42:55 +02:00
Artem Serebriyskiy
4457d96e54 Moving variable declaration to the beginning of the block 2014-05-28 22:02:47 +04:00
Artem Serebriyskiy
2b4c49d017 Add default __eq implementation
* Renamed SWIG_Lua_equal to SWIG_Lua_class_equal
* If class has no __eq implemented, then default __eq is provided.
  Default __eq compares actual pointers stored inside Lua userdata
2014-05-28 22:01:23 +04:00
Olly Betts
703862dc3a Fix unused variable warning in Lua bindings 2014-05-28 23:04:06 +12:00
Eric Wing
1766e67a1a JavaScriptCore: Improved code that uses JSObjectMakeError instead of JSValueToObject to create the exception object.
JSObjectMakeError automatically populates the "message" field, and possibly other fields I don't know about. This seems to be the most robust way to create an exception object.

Thanks to Brian Barnes again for the tip on JSObjectMakeError.
2014-05-26 22:35:28 +02:00
Eric Wing
e7b20624cc JavaScriptCore: Reverted 2 of the JSValueMakeUndefined replacements because those functions are tied to JSObjectRef instead of JSValueRef. The C compiler will allow this, but C++ will reject the conversion.
It is unclear what the correct handling is for JavaScriptCore. (Nobody bothers to document this in JSCore.) Unlike our other problem where we incorrectly assume JSObjectRef when the functions want JSValueRef, this time Apple is demanding the JSObjectRef. Like our other problem, I assume it is unsafe to try to convert Undefined into a JSObjectRef.

So reverting to NULL seems like the safer bet for this specific case. Perhaps the other alternative is to return an exception object or an error object. But I would like to see JSCore document this before trying.
2014-05-26 22:35:27 +02:00
Eric Wing
f1c331f2c5 JavaScriptCore: Returning NULL for wrapper functions that expect JSValueRef may crash program.
According to this:
http://parmanoir.com/Taming_JavascriptCore_within_and_without_WebView
Returning NULL instead of an actual JSValueRef for a return value of a function could lead to crashes. I think I have seen related weirdness in the past when I failed to return a proper type to JSCore which resulted in very hard to understand behavior.

So this patch changes those return NULLs to return JSValueMakeUndefined().

I thought about JSObjectMakeError, but I don't fully understand the intent of the Error object and can't find any relevant real world examples of it being used. However, everybody seems to be using JSValueMakeUndefined().

This patch should be low impact since this is only triggered on an error condition.
2014-05-26 22:35:27 +02:00
Eric Wing
6f69555225 JavaScriptCore: Fixed exception object so sourceURL (file name), line (number), and message can be recovered.
The current implementation only returns an error string. But this is insufficient for debugging (what file and line number did it fail at?).

As documented here:
http://parmanoir.com/Taming_JavascriptCore_within_and_without_WebView
converting the JSValueRef of string to an JSObjectRef (via JSValueToObject) will trigger JSCore into filling the "sourceURL" and "line" properties into the object so they can be inspected by the caller.

Additionally, JavaScriptCore has a "message" property which contains the message string. JSCore doesn't seem to be filling this in for us automatically, unlike "sourceURL" and "line". So this patch also fills that property in too.

Thanks to Brian Barnes for the detailed information about "sourceURL", "line", and "message".

Below is an example (derived from Brian Barnes's information) on how you typically use/extract these exception details.

void script_exception_to_string(JSContextRef js_context,JSValueRef exception_value_ref,char* return_error_string, int return_error_string_max_length)
{
	JSObjectRef exception_object;
	JSValueRef value_ref;
	JSStringRef jsstring_property_name = NULL;
	JSValueRef temporary_exception = NULL;
	JSStringRef js_return_string = NULL;
	size_t bytes_needed;
	char* c_result_string = NULL;
	exception_object = JSValueToObject(js_context, exception_value_ref, NULL);
	// source and line numbers

	strcpy(return_error_string,"[");

	jsstring_property_name = JSStringCreateWithUTF8CString("sourceURL");
	value_ref = JSObjectGetProperty(js_context, exception_object, jsstring_property_name, &temporary_exception);
	JSStringRelease(jsstring_property_name);
	js_return_string = JSValueToStringCopy(js_context, value_ref, NULL);
	bytes_needed = JSStringGetMaximumUTF8CStringSize(js_return_string);
	c_result_string = (char*)calloc(bytes_needed, sizeof(char));
	JSStringGetUTF8CString(js_return_string, c_result_string, bytes_needed);
	SDL_Log("c_result_string: %s\n", c_result_string);
	JSStringRelease(js_return_string);
	strncat(return_error_string, c_result_string, return_error_string_max_length-1);
	free(c_result_string);

	strncat(return_error_string, ":", return_error_string_max_length-1);

	jsstring_property_name = JSStringCreateWithUTF8CString("line");
	value_ref = JSObjectGetProperty(js_context, exception_object, jsstring_property_name, &temporary_exception);
	JSStringRelease(jsstring_property_name);
	js_return_string = JSValueToStringCopy(js_context, value_ref, NULL);
	bytes_needed = JSStringGetMaximumUTF8CStringSize(js_return_string);
	c_result_string = (char*)calloc(bytes_needed, sizeof(char));
	JSStringGetUTF8CString(js_return_string, c_result_string, bytes_needed);
	SDL_Log("c_result_string: %s\n", c_result_string);
	JSStringRelease(js_return_string);
	strncat(return_error_string, c_result_string, return_error_string_max_length-1);
	//SDL_Log("c_result_string: %s\n", c_result_string);
	free(c_result_string);

	strncat(return_error_string, "]", return_error_string_max_length-1);

	/* get message */
	jsstring_property_name = JSStringCreateWithUTF8CString("message");
	value_ref = JSObjectGetProperty(js_context, exception_object, jsstring_property_name, &temporary_exception);
	JSStringRelease(jsstring_property_name);
	if(NULL == value_ref)
	{
		strncat(return_error_string, "Unknown Error", return_error_string_max_length-1);
	}
	else
	{
		js_return_string = JSValueToStringCopy(js_context, value_ref, NULL);
		bytes_needed = JSStringGetMaximumUTF8CStringSize(js_return_string);
		c_result_string = (char*)calloc(bytes_needed, sizeof(char));
		JSStringGetUTF8CString(js_return_string, c_result_string, bytes_needed);
		SDL_Log("c_result_string: %s\n", c_result_string);
		JSStringRelease(js_return_string);
		strncat(return_error_string, c_result_string, return_error_string_max_length-1);
		//SDL_Log("c_result_string: %s\n", c_result_string);
		free(c_result_string);
	}
}

To use:
if(js_exception)
{
	char return_error_string[256];
	script_exception_to_string(js_context, js_exception, return_error_string, 256);
	SDL_Log("Compile error is %s", return_error_string);
}
2014-05-26 22:35:27 +02:00
William S Fulton
d1f95ab6fd Merge pull request #165 from hfalcic/master
Python 3 byte string output: use errors="surrogateescape"
2014-05-24 17:54:55 +01:00
William S Fulton
10cbd2781f Refactor Lua class base search to make ISO c/c++ compliant 2014-05-24 14:13:24 +01:00
William S Fulton
c2368a40b2 Javascript warnings for c++98 - remove vla 2014-05-24 14:13:24 +01:00
William S Fulton
3191473523 Fix compiler warnings in generated code when using -std=c++98 -std=gnu89 -pedantic -Wreturn-type 2014-05-24 14:13:19 +01:00
Olly Betts
1a0b8abec7 Fix comment typo 2014-05-24 11:11:51 +12:00
Olly Betts
8d3902a666 Work towards C90 compatibility for Lua 2014-05-24 11:10:57 +12:00
Harvey Falcic
9846f3f1ea Python 3 byte string output: use errors="surrogateescape"
... if available on the version of Python that's in use. This allows
obtaining the original byte string (and potentially trying a fallback
encoding) if the bytes can't be decoded as UTF-8.

Previously, a UnicodeDecodeError would be raised with no way to treat
the data as bytes or try another codec.
2014-05-23 15:40:01 -04:00
Oliver Buchtala
61b7da1671 JavascriptCore: Bugfix for null-pointer support.
This solution must be considered as a preliminary workaround.
2014-05-19 16:04:22 +02:00
Oliver Buchtala
3f0f588891 Javascript: support null pointers.
We allow to set pointer types using JS null.
2014-05-19 16:04:22 +02:00
Eric Wing
d5ea32d760 JavaScriptCore: ConvertPtr should allow JavaScript null to be a valid value.
It is common in C to accept NULL to functions for pointer parameters.
extern void DoSomething(struct Foo* foo);
...
DoSomething(NULL);

Thus, JavaScript null should be allowed:
module.DoSomething(null);

But the current ConvertPtr definition accepts only objects. This modifies it to allow null.
2014-05-19 16:04:22 +02:00
Oliver Buchtala
d9bb3a8415 Revert "JavaScriptCore: ConvertPtr should allow JavaScript null to be a valid value."
This reverts commit 05ed0325dc.
2014-05-19 11:46:29 +02:00
Oliver Buchtala
7cc617a19d Revert "Javascript: support null pointers."
This reverts commit 11963788e0.
2014-05-19 11:46:21 +02:00
Oliver Buchtala
11963788e0 Javascript: support null pointers.
We allow to set pointer types using JS null.
2014-05-19 00:21:21 +02:00
Oliver Buchtala
7824322b14 Javascript: fix warnings in li_std_string test.
Old typemaps for std::string were in place instead of delegating to UTL.
2014-05-18 22:40:22 +02:00
Eric Wing
05ed0325dc JavaScriptCore: ConvertPtr should allow JavaScript null to be a valid value.
It is common in C to accept NULL to functions for pointer parameters.
extern void DoSomething(struct Foo* foo);
...
DoSomething(NULL);

Thus, JavaScript null should be allowed:
module.DoSomething(null);

But the current ConvertPtr definition accepts only objects. This modifies it to allow null.
2014-05-18 21:27:54 +02:00
Eric Wing
8498e4878d JavaScriptCore: More missing static modifiers. 2014-05-18 21:27:54 +02:00
Eric Wing
fade0bcbde JavaScriptCore: C89: declare variables at the top for antiquated compilers like Microsoft Visual Studio. 2014-05-18 21:27:54 +02:00
Eric Wing
486e903de1 JavaScriptCore: Bug fix for SWIGJSC_AppendOutput. This function requires a return value. I think it should be arr, but somebody should scrutinize this. 2014-05-18 21:27:54 +02:00
Oliver Buchtala
fcb4833660 JavascriptCore: fix cleanup code. 2014-05-18 21:27:54 +02:00
Eric Wing
b4534a481a JavaScriptCore: Bug fix for finalizer. The finalizer needs to be set on the objectDefinition, not the classDefinition. Otherwise, all the finalize callbacks get NULL back for the PrivateData and can't free the SwigPrivData, causing massive leakage. 2014-05-18 21:27:54 +02:00
Eric Wing
aa55154ccf JavaScript: Added missing static modifiers to avoid duplicate symbol problems with multiple SWIG modules. 2014-05-18 21:27:53 +02:00
Olly Betts
95f09b49d2 Don't use // comments in C code. 2014-05-18 20:38:43 +12:00
Karl Wette
6fc07c5dc9 Fix segmentation fault in some Javascript examples
- memory allocated with malloc() was then being freed with delete[],
  which is overridden by Javascript libraries (jsc), leading to segfault
- replacing malloc with %new_array seems to work though
2014-05-11 21:31:32 +02:00
Karl Wette
66555ad2a7 Fix go configuration and SWIG_GCC_VERSION
- in configure.ac: modify sed expression to only look at first line of
  gccgo --version, extract the last numeric token, and remove periods;
  this parses e.g. "gccgo (Debian 4.7.2-5) 4.7.2"
- in goruntime.swg: fix typo in __GNUC_PATCHLEVEL__ (SF Bug #1298)
2014-05-02 21:44:52 +02:00
Karl Wette
b6c1889c08 Fix {python|perl5|ruby|tcl}/java examples
- in Lib/gcj/cni.i: remove JvAllocObject(), change
  JvCreateJavaVM() argument from void* to JvVMInitArgs*
- in Examples/{python|perl5|ruby|tcl}/java/Makefile:
  pass full class name to gcjh, add Example.h as dependency,
  do not override CXX for compiling C++ sources
- in Examples/python/java/example.i:
  add destructor to class to prevent memory loss complaint
2014-05-02 21:44:42 +02:00
Karl Wette
d5b765d388 Whitespace cleanup of all Makefiles*
- some of the %.clean rules in the test-suite Makefiles were using a single tab
  as an empty rule, dangerous! I've replaced these with the safer '@exit 0'.
2014-05-02 20:06:11 +02:00
Karl Wette
7cd9063b52 Remove execute permissions from various non-executable files
- source files and Makefiles need never be executable
- scripts are run directly by their interpreters in the
  test suites, so also do not need to be executable
2014-05-02 20:06:11 +02:00
William S Fulton
f51be1ca5c Merge branch 'master' into javascript
* master:
  Fix some typos
  [PHP] The generated __isset() method now returns true for read-only properties.
  Eliminate needless casting away const from string constants
  Fix typos
  Fix missing ")" in code example
  Fix comment typos
  Fix m4 quoting of checks for yodl2man and yodl2html versions
  Fixed errors from previous commit.
  Removed all unnecessary asserts
  Remove unused variable
  Another go html fix
  Fix intgosize arg documentation
  Optimize metamethods inheritance resolving
  Updating documentation
  Whitespace cleanup of Example Makefiles
  .gitignore: ignore Lib/swigwarn.swg
  Fixing unused variable warnings
  Finish implementation with proxy functions
  Remove duplicate declarations of strtoimax and strtoumax in inttypes.i
  Ignored enum fixes.
  Further shift operator regression fixes
  Fix use of shift operators in expressions regression since 3.0.0
  Fix seg fault with extra ) brackets and >>
  More efficient end of template bracket (>>) handling
  beautify scanner.c
  Tidy up scanner.c
  DOH readme correction
  Fix typo in -lua -help output
  Remove extra </div>
  Update documentation for deprecation and removal of Close()
  Fix segfault when there are too many closing round brackets in parsed code
  Refix operator<< definition giving a syntax error
  Fix regression in 3.0.0 where legal code following an operator<< definition might give a syntax error.
  Remove unnecessary block from PHP version of SWIG_exception macro
  [PHP] Fix wrapping director constructors with default parameters with a ZTS-enabled build of PHP.
  Fix potential bugs found by Coverity analysis
  Eliminate unused parameter from SWIG_Php_GetModule()
  Fix comment typo
  Fix compiler warnings in generated Lua code
  [PHP] Pass the ZTS context we already have to avoid needing to call TSRMLS_FETCH, which is relatively expensive.
  [PHP] Pass ZTS context through to t_output_helper() so it works with a ZTS-enabled build of PHP.  Reported by Pierre Labastie in github PR#155.
  Lua test-suite can now be run out of source
  Fix out of source test-suite runs for Octave
  Add runtime test for commit 7a96fba836
  Add C++11 constexpr runtime test
2014-05-01 19:01:20 +01:00
William S Fulton
80953ccfc9 Fix some typos 2014-05-01 18:49:42 +01:00
William S Fulton
5792e97a44 Javascript: ensure banner appears before %begin code 2014-05-01 18:13:35 +01:00
Olly Betts
4c86f17bcb Merge pull request #159 from v-for-vandal/issue_154
Fixing issue 154
2014-04-29 11:19:58 +12:00
Oliver Buchtala
e8ef490716 Removed obsolete 'node.i'. 2014-04-26 22:25:09 +02:00
Oliver Buchtala
cc16812c4f Added a comment about V8_VERSION macro. 2014-04-26 22:24:51 +02:00
Artem Serebriyskiy
c1ca144ed2 Fixed errors from previous commit.
Also in previous commit also fixed warning with unsigned vs signed
comparison
2014-04-23 01:48:10 +04:00
Artem Serebriyskiy
5506c7f624 Removed all unnecessary asserts 2014-04-23 01:37:14 +04:00
Artem Serebriyskiy
d120c05fcc Optimize metamethods inheritance resolving
* a table of metamethods that should be inherited is now stored in
  SWIG registry table. It optimizes memory usage.
2014-04-22 14:31:41 +04:00
William S Fulton
9587c133c5 Fix typo in Javascript exception 2014-04-19 15:55:12 +01:00
Artem Serebriyskiy
8512bad8c2 Fixing unused variable warnings
* Fixing unused variable warning. Generated code should compile
  with -Wall -Werror flags

* Fixing forgotten __Module -> SwigModule renaming
2014-04-16 03:37:27 +04:00
Artem Serebriyskiy
7c8405368e Finish implementation with proxy functions 2014-04-15 03:38:45 +04:00
William S Fulton
d7f6167e02 Remove duplicate declarations of strtoimax and strtoumax in inttypes.i 2014-04-08 23:47:22 +01:00