Procházet zdrojové kódy

Merge pull request #92 from bmx-ng/master

Merge from master
Brucey před 6 roky
rodič
revize
3dbf45241d
6 změnil soubory, kde provedl 107 přidání a 2 odebrání
  1. 46 0
      blitz.mod/blitz.bmx
  2. 26 0
      blitz.mod/blitz_gc.c
  3. 3 0
      blitz.mod/blitz_gc.h
  4. 2 0
      xml.mod/common.bmx
  5. 11 2
      xml.mod/glue.c
  6. 19 0
      xml.mod/xml.bmx

+ 46 - 0
blitz.mod/blitz.bmx

@@ -474,6 +474,34 @@ bbdoc: Private: do not use
 End Rem
 Function GCLeave()="bbGCLeave"
 
+Rem
+bbdoc: Retains a reference to the specified #Object, preventing it from being collected.
+End Rem
+Function GCRetain(obj:Object)="bbGCRetain"
+
+Rem
+bbdoc: Releases a reference from the specified #Object.
+End Rem
+Function GCRelease(obj:Object)="bbGCRelease"
+
+Rem
+bbdoc: Returns #True if the current thread is registered with the garbage collector.
+End Rem
+Function GCThreadIsRegistered:Int()="bbGCThreadIsRegistered"
+
+Rem
+bbdoc: Registers the current thread with the garbage collector.
+returns: 0 on success, 1 if the thread was already registered, or -1 if threads are not supported.
+End Rem
+Function GCRegisterMyThread:Int()="bbGCRegisterMyThread"
+
+Rem
+bbdoc: Unregisters the previously registered current thread.
+about: Note, that any memory allocated by the garbage collector from the current thread will no longer be
+accessible after the thread is unregistered.
+End Rem
+Function GCUnregisterMyThread:Int()="bbGCUnregisterMyThread"
+
 Rem
 bbdoc: Convert object to integer handle
 returns: An integer object handle
@@ -496,6 +524,18 @@ Function ArrayCopy(src:Object, srcPos:Int, dst:Object, dstPos:Int, length:Int)="
 
 End Extern
 
+Rem
+bbdoc: Provides a mechanism for releasing resources.
+End Rem
+Interface IDisposable
+
+	Rem
+	bbdoc: Performs application-defined tasks associated with freeing, releasing, or resetting resources.
+	End Rem
+	Method Dispose()
+
+End Interface
+
 'BlitzMax keyword definitions
 
 Rem
@@ -861,6 +901,12 @@ bbdoc: Denote a function for export to a shared library. The generated function
 keyword: "Export"
 End Rem
 
+Rem
+bbdoc: Indicates that a method declaration is intended to override a method declaration in a supertype.
+about: Use of #Override on a method that does not override a method will result in a compilation error.
+keyword: "Override"
+End Rem
+
 Rem
 bbdoc: Specify constraints on the types that can be used as arguments for a type parameter defined in a generic declaration
 keyword: "Where"

+ 26 - 0
blitz.mod/blitz_gc.c

@@ -190,3 +190,29 @@ void bbGCRelease( BBObject *p ) {
 		}
 	}
 }
+
+int bbGCThreadIsRegistered() {
+#ifdef GC_THREADS
+	return GC_thread_is_registered();
+#else
+	return 0;
+#endif
+}
+
+int bbGCRegisterMyThread() {
+#ifdef GC_THREADS
+	struct GC_stack_base stackBase;
+	GC_get_stack_base(&stackBase);
+	return GC_register_my_thread(&stackBase);
+#else
+	return -1;
+#endif
+}
+
+int bbGCUnregisterMyThread() {
+#ifdef GC_THREADS
+	return GC_unregister_my_thread();
+#else
+	return -1;
+#endif
+}

+ 3 - 0
blitz.mod/blitz_gc.h

@@ -58,6 +58,9 @@ void		bbGCSuspend();
 void		bbGCResume();
 void		bbGCRetain( BBObject *p );
 void		bbGCRelease( BBObject *p );
+int			bbGCThreadIsRegistered();
+int			bbGCRegisterMyThread();
+int			bbGCUnregisterMyThread();
 
 // BBRETAIN/BBRELEASE should be used to prevent an object from garbage collection.
 //

+ 2 - 0
xml.mod/common.bmx

@@ -17,6 +17,7 @@ SuperStrict
 Import Pub.mxml
 Import brl.stream
 Import brl.linkedlist
+Import brl.stringbuilder
 
 Import "glue.c"
 
@@ -54,6 +55,7 @@ Extern
 	Function bmx_mxmlSaveStream:Int(handle:Byte Ptr, stream:TStream, format:Int)
 	
 	Function bmx_mxmlSetWrapMargin(column:Int)
+	Function bmx_mxmlGetContent:String(handle:Byte Ptr)
 End Extern
 
 Rem

+ 11 - 2
xml.mod/glue.c

@@ -235,7 +235,7 @@ BBString * bmx_mxmlElementGetAttrByIndex(mxml_node_t * node, int index, BBString
 }
 
 mxml_node_t * bmx_mxmlLoadStream(BBObject * stream) {
-	return mxmlLoadStream(NULL, bmx_mxml_stream_read, stream, NULL);
+	return mxmlLoadStream(NULL, bmx_mxml_stream_read, stream, MXML_OPAQUE_CALLBACK);
 }
 
 mxml_node_t * bmx_mxmlWalkNext(mxml_node_t * node, mxml_node_t * top, int descend) {
@@ -366,9 +366,18 @@ mxml_node_t * bmx_mxmlLoadString(BBString * txt) {
 	
 	struct _string_buf buf = {txt = txt};
 
-	return mxmlLoadStream(NULL, bmx_mxml_string_read, &buf, NULL);
+	return mxmlLoadStream(NULL, bmx_mxml_string_read, &buf, MXML_OPAQUE_CALLBACK);
 }
 
 void bmx_mxmlSetWrapMargin(int column) {
 	mxmlSetWrapMargin(column);
 }
+
+BBString * bmx_mxmlGetContent(mxml_node_t * node) {
+	const char * txt = mxmlGetOpaque(node);
+
+	if (!txt || strlen(txt) == 0) {
+		return &bbEmptyString;
+	}
+	return bbStringFromUTF8String(txt);
+}

+ 19 - 0
xml.mod/xml.bmx

@@ -245,6 +245,25 @@ Type TxmlNode Extends TxmlBase
 	Method previousSibling:TxmlNode()
 		Return TxmlNode._create(bmx_mxmlGetPrevSibling(nodePtr))
 	End Method
+	
+	Rem
+	bbdoc: Reads the value of a node.
+	returns: The node content.
+	End Rem
+	Method getContent:String()
+		Local sb:TStringBuilder = New TStringBuilder()
+		sb.Append(bmx_mxmlGetContent(nodePtr))
+		
+		Local n:Byte Ptr = bmx_mxmlWalkNext(nodePtr, nodePtr, MXML_DESCEND)
+		While n
+			If bmx_mxmlGetType(n) = MXML_OPAQUE Then
+				sb.Append(bmx_mxmlGetContent(n))
+			End If
+			n = bmx_mxmlWalkNext(n, nodePtr, MXML_DESCEND)
+		Wend
+		
+		Return sb.ToString()
+	End Method
 
 	Rem
 	bbdoc: Frees a node and all of its children.