Просмотр исходного кода

Fixes to allow cross compilation with https://github.com/hone/mruby-cli docker image

mingodad 7 лет назад
Родитель
Сommit
ca0f948a70

+ 4 - 2
SquiLu-ext/sq_mongoose.cpp

@@ -6,6 +6,7 @@
 
 #include "squirrel.h"
 #include "sqstdblobimpl.h"
+#include "squtils.h"
 SQ_OPT_STRING_STRLEN();
 
 #ifdef USE_SQ_SQLITE3
@@ -161,7 +162,8 @@ sq_http_request_read(HSQUIRRELVM v)
         if(!blob || !blob->IsValid())
             return sq_throwerror(v,_SC("the blob is invalid"));
     } else {
-        blob = new SQBlob(0, rlen);
+        sq_new(blob, SQBlob);
+		blob->Reserve(rlen);
     }
 
     if (((ssize_t)rlen) > n) rlen = n;  /* cannot read more than asked */
@@ -175,7 +177,7 @@ sq_http_request_read(HSQUIRRELVM v)
 
     if(_top_ <= 2) {
         sq_pushstring(v, (const SQChar *)blob->GetBuf(), blob->Len());  /* close buffer */
-        delete blob;
+        if(blob) sq_delete(blob, SQBlob);
         return 1;
     }
     return 0;

+ 7 - 4
SquiLu-ext/sq_sqlite3.cpp

@@ -4,6 +4,7 @@
 #include <assert.h>
 #include <stdlib.h>
 #include "lua-regex.h"
+#include "squtils.h"
 
 SQ_OPT_STRING_STRLEN();
 
@@ -25,7 +26,9 @@ static SQRESULT getOptionalBlob(HSQUIRRELVM v, SQInteger idx, SQBlob **blob)
         if(!(*blob) || !(*blob)->IsValid())
             return sq_throwerror(v,_SC("the blob is invalid"));
     } else {
-        *blob = new SQBlob(0, 8192);
+        SQBlob *nblob;
+        sq_new(nblob, SQBlob);
+        *blob = nblob;
         return 0;
     }
     return 1;
@@ -1063,7 +1066,7 @@ static SQRESULT sq_sqlite3_stmt_asJsonArray(HSQUIRRELVM v)
 
     if(has_blob) return 0;
     sq_pushstring(v, (const SQChar*)json->GetBuf(), json->Len());
-    delete json;
+    if(json) sq_delete(json, SQBlob);
 
     return 1;
 }
@@ -1115,7 +1118,7 @@ static SQRESULT sq_sqlite3_stmt_asJsonObject(HSQUIRRELVM v)
     if(has_blob) return 0;
     if(record_count) sq_pushstring(v, (const SQChar*)json->GetBuf(), json->Len());
     else sq_pushnull(v);
-    delete json;
+    if(json) sq_delete(json, SQBlob);
 
     return 1;
 }
@@ -1402,7 +1405,7 @@ static SQRESULT sq_sqlite3_stmt_asSleArray(HSQUIRRELVM v)
 
     if(has_blob) return 0;
     sq_pushstring(v, (const SQChar*)sle->GetBuf(), sle->Len());
-    delete sle;
+    if(sle) sq_delete(sle, SQBlob);
     return 1;
 }
 

+ 7 - 1
SquiLu/sq/sq.c

@@ -616,6 +616,7 @@ SQRESULT sqext_register_pcre2(HSQUIRRELVM v);
 SQRESULT sqext_register_freetype(HSQUIRRELVM v);
 SQRESULT sqext_register_tre(HSQUIRRELVM v);
 SQRESULT sqext_register_hunspell(HSQUIRRELVM v);
+SQRESULT sqext_register_fossil (HSQUIRRELVM sqvm);
 
 static sq_modules_preload_st modules_preload[] = {
     {"blob", sqstd_register_bloblib},
@@ -628,7 +629,9 @@ static sq_modules_preload_st modules_preload[] = {
     {"sqlexer", sqext_register_SQLexer},
     {"gumbo", sqext_register_gumbo},
     {"base64", sqext_register_base64},
+#ifndef NO_SQ_PDF
     {"fpdf", sqext_register_Sq_Fpdf},
+#endif
     {"sqlite3", sqext_register_SQLite3},
     {"bitvector", sqext_register_BitVector}, //depends on sqlite3
     //{"xdj1", sqext_register_xjd1},
@@ -638,6 +641,7 @@ static sq_modules_preload_st modules_preload[] = {
     {"socket", sqext_register_sq_socket},
     {"tweetnacl", sqext_register_tweetnacl},
     {"pack", sqext_register_pack},
+    {"sqfossil", sqext_register_fossil},
 #if !defined(TARGET_IOS)
 #ifdef SQ_USE_PCRE
     {"sqpcre", sqext_register_pcre},
@@ -671,7 +675,9 @@ static sq_modules_preload_st modules_preload[] = {
     //{"miniz", sqext_register_sq_miniz},
     {"mongoose", sqext_register_mongoose},
     {"importlib", sqrat_register_importlib},
+#ifndef NO_TINYXML2
     {"tinyxml2", sqext_register_tinyxml2},
+#endif
 #ifndef _WIN32_WCE
 #ifdef WITH_MPDECIMAL
     {"decimal", sqext_register_decimal},
@@ -702,7 +708,7 @@ static sq_modules_preload_st modules_preload[] = {
 #ifdef WITH_MYSQL
     {"mysql", sqext_register_MySQL},
 #endif
-#ifndef ANDROID_BUILD
+#if !defined(ANDROID_BUILD) && !defined(NO_RS232) 
     {"rs232", sqext_register_rs232},
 #endif
 #ifdef WITH_FLTK

+ 1 - 1
SquiLu/sqstdlib/sqstdblob.cpp

@@ -16,7 +16,7 @@ static const SQChar  SQSTD_BLOB_TYPE_TAG[] = _SC("std_stream_blob");
 
 SQUserPointer SQBlob::SQBlob_TAG = (SQUserPointer)SQSTD_BLOB_TYPE_TAG;
 
-SQBlob::SQBlob(SQInteger size, SQInteger allocated) {
+void SQBlob::init(SQInteger size, SQInteger allocated) {
     _size = size;
     _allocated = allocated > size ? allocated : size;
     _buf = (unsigned char *)sq_malloc(_allocated);

+ 3 - 1
SquiLu/sqstdlib/sqstdblobimpl.h

@@ -7,7 +7,8 @@
 
 struct SQBlob : public SQStream
 {
-	SQBlob(SQInteger size, SQInteger allocated=0);
+	SQBlob() {init(0, 8192);};
+	SQBlob(SQInteger size, SQInteger allocated=0){init(size, allocated);};
 	virtual ~SQBlob();
 	SQInteger Write(const void *buffer, SQInteger size);
 	SQInteger WriteZstr(const char *zStr);
@@ -35,6 +36,7 @@ struct SQBlob : public SQStream
 	bool SetLen(SQInteger len);
 	static SQUserPointer SQBlob_TAG;
 private:
+	void init(SQInteger size, SQInteger allocated);
 	SQInteger _size;
 	SQInteger _allocated;
 	SQInteger _ptr;

+ 130 - 121
SquiLu/squirrel/squtils.h

@@ -1,123 +1,132 @@
-/*	see copyright notice in squirrel.h */
-#ifndef _SQUTILS_H_
-#define _SQUTILS_H_
-
-void *sq_vm_malloc(SQUnsignedInteger size);
-void *sq_vm_realloc(void *p,SQUnsignedInteger oldsize,SQUnsignedInteger size);
-void sq_vm_free(void *p,SQUnsignedInteger size);
-
-#define sq_new(__ptr,__type) {__ptr=(__type *)sq_vm_malloc(sizeof(__type));new (__ptr) __type;}
-#define sq_delete(__ptr,__type) {__ptr->~__type();sq_vm_free(__ptr,sizeof(__type));}
-#define SQ_MALLOC(__size) sq_vm_malloc((__size));
-#define SQ_FREE(__ptr,__size) sq_vm_free((__ptr),(__size));
-#define SQ_REALLOC(__ptr,__oldsize,__size) sq_vm_realloc((__ptr),(__oldsize),(__size));
-
-#define sq_aligning(v) (((size_t)(v) + (SQ_ALIGNMENT-1)) & (~(SQ_ALIGNMENT-1)))
-
-//sqvector mini vector class, supports objects by value
-template<typename T> class sqvector
-{
-public:
-	sqvector():_vals(NULL),_size(0),_allocated(0)
-	{
-	}
-	sqvector(const sqvector<T>& v)
-	{
-		copy(v);
-	}
-	void copy(const sqvector<T>& v)
-	{
-		if(_size) {
-			resize(0); //destroys all previous stuff
-		}
-		//resize(v._size);
-		if(v._size > _allocated) {
-			_realloc(v._size);
-		}
-		for(SQUnsignedInteger i = 0; i < v._size; i++) {
-			new ((void *)&_vals[i]) T(v._vals[i]);
-		}
-		_size = v._size;
-	}
-	~sqvector()
-	{
-		if(_allocated) {
-			for(SQUnsignedInteger i = 0; i < _size; i++)
-				_vals[i].~T();
-			SQ_FREE(_vals, (_allocated * sizeof(T)));
-		}
-	}
-	void reserve(SQUnsignedInteger newsize) { _realloc(newsize); }
-	void resize(SQUnsignedInteger newsize, const T& fill = T())
-	{
-		if(newsize > _allocated)
-			_realloc(newsize);
-		if(newsize > _size) {
-			while(_size < newsize) {
-				new ((void *)&_vals[_size]) T(fill);
-				_size++;
-			}
-		}
-		else{
-			for(SQUnsignedInteger i = newsize; i < _size; i++) {
-				_vals[i].~T();
-			}
-			_size = newsize;
-		}
-	}
-	void shrinktofit() { if(_size > 4) { _realloc(_size); } }
-	T& top() const { return _vals[_size - 1]; }
-	inline SQUnsignedInteger size() const { return _size; }
-	bool empty() const { return (_size <= 0); }
-	inline T &push_back(const T& val = T())
-	{
-		if(_allocated <= _size)
-			_realloc(_size * 2);
-		return *(new ((void *)&_vals[_size++]) T(val));
-	}
-	inline void pop_back()
-	{
-		_size--; _vals[_size].~T();
-	}
-	void insert(SQUnsignedInteger idx, const T& val)
-	{
-		resize(_size + 1);
-		for(SQUnsignedInteger i = _size - 1; i > idx; i--) {
-			_vals[i] = _vals[i - 1];
-		}
-    	_vals[idx] = val;
-	}
-	void remove(SQUnsignedInteger idx)
-	{
-		_vals[idx].~T();
-		if(idx < (_size - 1)) {
-			memmove(&_vals[idx], &_vals[idx+1], sizeof(T) * (_size - idx - 1));
-		}
-		_size--;
-	}
-	void removeFromBegining(SQUnsignedInteger count)
+/*	see copyright notice in squirrel.h */
+#ifndef _SQUTILS_H_
+#define _SQUTILS_H_
+
+#include <new>
+
+#ifndef SQ_EXCLUDE_DEFAULT_MEMFUNCTIONS
+void *sq_vm_malloc(SQUnsignedInteger size);
+void *sq_vm_realloc(void *p,SQUnsignedInteger oldsize,SQUnsignedInteger size);
+void sq_vm_free(void *p,SQUnsignedInteger size);
+#else
+#include <stdlib.h>
+#define sq_vm_malloc(x) malloc(x)
+#define sq_vm_realloc(a, b, c) realloc(a, c)
+#define sq_vm_free(x, y) free(x)
+#endif
+
+#define sq_new(__ptr,__type) {__ptr=(__type *)sq_vm_malloc(sizeof(__type));new (__ptr) __type;}
+#define sq_delete(__ptr,__type) {__ptr->~__type();sq_vm_free(__ptr,sizeof(__type));}
+#define SQ_MALLOC(__size) sq_vm_malloc((__size));
+#define SQ_FREE(__ptr,__size) sq_vm_free((__ptr),(__size));
+#define SQ_REALLOC(__ptr,__oldsize,__size) sq_vm_realloc((__ptr),(__oldsize),(__size));
+
+#define sq_aligning(v) (((size_t)(v) + (SQ_ALIGNMENT-1)) & (~(SQ_ALIGNMENT-1)))
+
+//sqvector mini vector class, supports objects by value
+template<typename T> class sqvector
+{
+public:
+	sqvector():_vals(NULL),_size(0),_allocated(0)
+	{
+	}
+	sqvector(const sqvector<T>& v)
+	{
+		copy(v);
+	}
+	void copy(const sqvector<T>& v)
+	{
+		if(_size) {
+			resize(0); //destroys all previous stuff
+		}
+		//resize(v._size);
+		if(v._size > _allocated) {
+			_realloc(v._size);
+		}
+		for(SQUnsignedInteger i = 0; i < v._size; i++) {
+			new ((void *)&_vals[i]) T(v._vals[i]);
+		}
+		_size = v._size;
+	}
+	~sqvector()
+	{
+		if(_allocated) {
+			for(SQUnsignedInteger i = 0; i < _size; i++)
+				_vals[i].~T();
+			SQ_FREE(_vals, (_allocated * sizeof(T)));
+		}
+	}
+	void reserve(SQUnsignedInteger newsize) { _realloc(newsize); }
+	void resize(SQUnsignedInteger newsize, const T& fill = T())
+	{
+		if(newsize > _allocated)
+			_realloc(newsize);
+		if(newsize > _size) {
+			while(_size < newsize) {
+				new ((void *)&_vals[_size]) T(fill);
+				_size++;
+			}
+		}
+		else{
+			for(SQUnsignedInteger i = newsize; i < _size; i++) {
+				_vals[i].~T();
+			}
+			_size = newsize;
+		}
+	}
+	void shrinktofit() { if(_size > 4) { _realloc(_size); } }
+	T& top() const { return _vals[_size - 1]; }
+	inline SQUnsignedInteger size() const { return _size; }
+	bool empty() const { return (_size <= 0); }
+	inline T &push_back(const T& val = T())
+	{
+		if(_allocated <= _size)
+			_realloc(_size * 2);
+		return *(new ((void *)&_vals[_size++]) T(val));
+	}
+	inline void pop_back()
+	{
+		_size--; _vals[_size].~T();
+	}
+	void insert(SQUnsignedInteger idx, const T& val)
+	{
+		resize(_size + 1);
+		for(SQUnsignedInteger i = _size - 1; i > idx; i--) {
+			_vals[i] = _vals[i - 1];
+		}
+    	_vals[idx] = val;
+	}
+	void remove(SQUnsignedInteger idx)
+	{
+		_vals[idx].~T();
+		if(idx < (_size - 1)) {
+			memmove(&_vals[idx], &_vals[idx+1], sizeof(T) * (_size - idx - 1));
+		}
+		_size--;
+	}
+	void removeFromBegining(SQUnsignedInteger count)
 	{
 	    if(count <= _size){
-	        for(SQUnsignedInteger i=0; i < count; ++i) _vals[i].~T();
-            if(count < (_size - 1)) {
-                memmove(&_vals[0], &_vals[count], sizeof(T) * (_size - count));
-            }
-            _size -= count;
-	    }
-	}
-	SQUnsignedInteger capacity() { return _allocated; }
-	inline T &back() const { return _vals[_size - 1]; }
-	inline T& operator[](SQUnsignedInteger pos) const{ return _vals[pos]; }
-	T* _vals;
-private:
-	void _realloc(SQUnsignedInteger newsize)
-	{
-		newsize = (newsize > 0)?newsize:4;
-		_vals = (T*)SQ_REALLOC(_vals, _allocated * sizeof(T), newsize * sizeof(T));
-		_allocated = newsize;
-	}
-	SQUnsignedInteger _size;
-	SQUnsignedInteger _allocated;
+	        for(SQUnsignedInteger i=0; i < count; ++i) _vals[i].~T();
+            if(count < (_size - 1)) {
+                memmove(&_vals[0], &_vals[count], sizeof(T) * (_size - count));
+            }
+            _size -= count;
+	    }
+	}
+	SQUnsignedInteger capacity() { return _allocated; }
+	inline T &back() const { return _vals[_size - 1]; }
+	inline T& operator[](SQUnsignedInteger pos) const{ return _vals[pos]; }
+	T* _vals;
+private:
+	void _realloc(SQUnsignedInteger newsize)
+	{
+		newsize = (newsize > 0)?newsize:4;
+		_vals = (T*)SQ_REALLOC(_vals, _allocated * sizeof(T), newsize * sizeof(T));
+		_allocated = newsize;
+	}
+	SQUnsignedInteger _size;
+	SQUnsignedInteger _allocated;
 };
 
 class SQCharBuf : public sqvector<char>
@@ -130,6 +139,6 @@ public:
         memcpy(_vals+old_size, p, count);
     }
     const char *data(){return _vals;}
-};
-
-#endif //_SQUTILS_H_
+};
+
+#endif //_SQUTILS_H_

+ 24 - 14
gumbo/README.md

@@ -46,21 +46,27 @@ Installation
 To build and install the library, issue the standard UNIX incantation from
 the root of the distribution:
 
-    $ ./autogen.sh
-    $ ./configure
-    $ make
-    $ sudo make install
+```bash
+$ ./autogen.sh
+$ ./configure
+$ make
+$ sudo make install
+```
 
 Gumbo comes with full pkg-config support, so you can use the pkg-config to
 print the flags needed to link your program against it:
 
-    $ pkg-config --cflags gumbo         # print compiler flags
-    $ pkg-config --libs gumbo           # print linker flags
-    $ pkg-config --cflags --libs gumbo  # print both
+```bash
+$ pkg-config --cflags gumbo         # print compiler flags
+$ pkg-config --libs gumbo           # print linker flags
+$ pkg-config --cflags --libs gumbo  # print both
+```
 
 For example:
 
-    $ gcc my_program.c `pkg-config --cflags --libs gumbo`
+```bash
+$ gcc my_program.c `pkg-config --cflags --libs gumbo`
+```
 
 See the pkg-config man page for more info.
 
@@ -73,18 +79,22 @@ unzipped.  The googletest maintainers recommend against using
 `make install`; instead, symlink the root googletest directory to 'gtest'
 inside gumbo's root directory, and then `make check`:
 
-    $ unzip gtest-1.6.0.zip
-    $ cd gumbo-*
-    $ ln -s ../gtest-1.6.0 gtest
-    $ make check
+```bash
+$ unzip gtest-1.6.0.zip
+$ cd gumbo-*
+$ ln -s ../gtest-1.6.0 gtest
+$ make check
+```
 
 Gumbo's `make check` has code to automatically configure & build gtest and
 then link in the library.
 
 Debian and Fedora users can install libgtest with:
 
-    $ apt-get install libgtest-dev  # Debian/Ubuntu
-    $ yum install gtest-devel       # CentOS/Fedora
+```bash
+$ apt-get install libgtest-dev  # Debian/Ubuntu
+$ yum install gtest-devel       # CentOS/Fedora
+```
 
 Note for Ubuntu users: libgtest-dev package only install source files.
 You have to make libraries yourself using cmake:

+ 3 - 1
myaxtls/os_int.h

@@ -41,7 +41,8 @@
 extern "C" {
 #endif
 
-#if defined(WIN32) && !defined(__MINGW32__)
+#if defined(WIN32)
+#if !defined(__MINGW32__)
 typedef UINT8 uint8_t;
 typedef INT8 int8_t;
 typedef UINT16 uint16_t;
@@ -50,6 +51,7 @@ typedef UINT32 uint32_t;
 typedef INT32 int32_t;
 typedef UINT64 uint64_t;
 typedef INT64 int64_t;
+#endif // "__MINGW32__
 #else   /* Not Win32 */
 
 #ifdef CONFIG_PLATFORM_SOLARIS

+ 1 - 0
myaxtls/os_port.h

@@ -152,6 +152,7 @@ EXP_FUNC int STDCALL getdomainname(char *buf, int buf_size);
 
 #else   /* Not Win32 */
 
+#include <alloca.h>
 #include <unistd.h>
 #include <pwd.h>
 #include <netdb.h>