1. Ronald Oussoren
  2. pyobjc

Commits

Ronald Oussoren  committed 30aade5

Make it possible to replace registered pointer-wrappers by other wrappers.

  • Participants
  • Parent commits 2bdab51
  • Branches pyobjc-ancient

Comments (0)

Files changed (1)

File Modules/objc/pointer-support.m

View file
  • Ignore whitespace
 static struct wrapper* items = 0;
 static int item_count = 0;
 
+static struct wrapper*
+FindWrapper(const char* signature)
+{
+	int i;
+	int len;
+
+	len = strlen(signature);
+
+	for (i = 0; i < item_count; i++) {
+		if (strncmp(signature, items[i].signature, items[i].offset) == 0) {
+			if (signature[1] != _C_STRUCT_B || signature[items[i].offset] == '=' || signature[items[i].offset] == _C_STRUCT_E) {
+				return items + i;
+			}
+		}
+	}
+	return NULL;
+}
+
 int 
 PyObjCPointerWrapper_Register(
 	const char* signature,
 {
 	struct wrapper* value;
 
+	/*
+	 * Check if we already have a wrapper, if so replace that.
+	 * This makes it possible to replace a default wrapper by something
+	 * better.
+	 */
+	value = FindWrapper(signature);
+	if (value != NULL) {
+		value->pythonify = pythonify;
+		value->depythonify = depythonify;
+		return 0;
+	}
+
 	if (items == NULL) {
 		items = PyMem_Malloc(sizeof(struct wrapper));
 		if (items == NULL) {
 	return 0;
 }
 
-static struct wrapper*
-FindWrapper(const char* signature)
-{
-	int i;
-	int len;
-
-	len = strlen(signature);
-
-	for (i = 0; i < item_count; i++) {
-		if (strncmp(signature, items[i].signature, items[i].offset) == 0) {
-			if (signature[1] != _C_STRUCT_B || signature[items[i].offset] == '=' || signature[items[i].offset] == _C_STRUCT_E) {
-				return items + i;
-			}
-		}
-	}
-	return NULL;
-}
 
 
 PyObject*