Re: [Jack-Devel] [PATCH] Jack-1: jack_port_by_name

PrevNext  Index
DateThu, 22 Jan 2015 17:46:15 +0100
From Adrian Knoth <[hidden] at drcomp dot erfurt dot thur dot de>
To[hidden] at lists dot jackaudio dot org
In-Reply-ToTim E. Real [Jack-Devel] [PATCH] Jack-1: jack_port_by_name
Follow-UpAdrian Knoth Re: [Jack-Devel] [PATCH] Jack-1: jack_port_by_name
Follow-UpTim E. Real Re: [Jack-Devel] [PATCH] Jack-1: jack_port_by_name
On 01/22/15 05:36, Tim E. Real wrote:

> https://dl.dropboxusercontent.com/u/53315356/jack1_port_by_name_fix.diff

Next time, please send the patch to this ML, so it's easier to comment
on it. Like people do on LKML, alsa-devel etc.

The other option would be a github pull request.

Here's your patch.

diff --git configure.ac configure.ac
index 5c20236..d662dfc 100644
--- configure.ac
+++ configure.ac
@@ -8,6 +8,12 @@ dnl
  dnl Check for existing JACK installs
  dnl

+
+
+AC_ARG_ENABLE(force_install,
+        AC_HELP_STRING([--enable-force-install],[force install CAUTION: 
Read warnings! (default=no)]),,
+        [ enable_force_install=no ])
+
  AC_MSG_CHECKING([existing, conflicting JACK installs])
  not_overwriting=0
  installs=
@@ -30,22 +36,28 @@ if test $not_overwriting -gt 0 ; then
      echo
      echo "Complete or partial JACK installs exist in:$installs"
      echo
-    echo "Installing this version will leave at least one of these"
-    echo "existing installations installed and this will probably break"
-    echo "JACK on your machine. "
+    echo "WARNING:"
+    echo "Installing multiple jack versions, even in different locations,"
+    echo "could cause JACK to break unless your system is setup properly."
+    echo "Be sure THIS installation is found first in your system's"
+    echo "executable and library paths. Currently some distros such as"
+    echo "Debian (or Ubuntu etc) may incorrectly set the library path."
      echo
-    echo "Before building, you should first remove the existing JACK"
-    echo "installation(s). "
+    echo "Please contact your distribution packager for JACK and"
+    echo "ask them to fix their packaging."
      echo
-    echo "Alternatively use ./configure --prefix=... to force overwriting"
-    echo "the existing install."
+    echo "Alternatively, you might be simply reinstalling THIS version."
+    echo "Or replacing some other local version you built - BE SURE TO"
+    echo "completely uninstall any such previous local install first !"
      echo
-    echo "WARNING: ON ANY DEBIAN-DERIVED DISTRIBUTION (Debian, Ubuntu etc)"
-    echo "CHANGING THE INSTALLATION PREFIX WILL NOT PRODUCE A WORKING JACK"
-    echo "INSTALL. Please contact the distribution packager for JACK and"
-    echo "ask them to fix their packaging."
+    echo "If you KNOW WHAT YOU ARE DOING and are sure you want to proceed,"
+    echo "run ./configure with --enable-force-install"
      echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
-    exit 1
+    echo
+
+    if test "x$enable_force_install" = xno; then
+      exit 1
+    fi
  fi

  AC_CONFIG_AUX_DIR(config)
diff --git include/internal.h include/internal.h
index bf622c8..ffb1d1b 100644
--- include/internal.h
+++ include/internal.h
@@ -537,7 +537,7 @@ extern jack_port_t *jack_port_by_id_int (const 
jack_client_t *client,
  					 jack_port_id_t id, int* free);

  extern jack_port_t *jack_port_by_name_int (jack_client_t *client,
-					   const char *port_name);
+					   const char *port_name, int* free);
  extern int jack_port_name_equals (jack_port_shared_t* port, const 
char* target);

  /** Get the size (in bytes) of the data structure used to store
diff --git libjack/port.c libjack/port.c
index 481f6e0..5ebfea3 100644
--- libjack/port.c
+++ libjack/port.c
@@ -487,8 +487,16 @@ jack_port_by_id (jack_client_t *client, 
jack_port_id_t id)
  }

  jack_port_t *
-jack_port_by_name_int (jack_client_t *client, const char *port_name)
+jack_port_by_name_int (jack_client_t *client, const char *port_name, 
int* free)
  {
+	JSList *node;
+	for (node = client->ports; node; node = jack_slist_next (node)) {
+		if (jack_port_name_equals(((jack_port_t *) node->data)->shared, 
port_name)) {
+			*free = FALSE;
+			return (jack_port_t *) node->data;
+		}
+	}
+	
  	unsigned long i, limit;
  	jack_port_shared_t *port;
  	
@@ -497,6 +505,7 @@ jack_port_by_name_int (jack_client_t *client, const 
char *port_name)
  	
  	for (i = 0; i < limit; i++) {
  		if (port[i].in_use && jack_port_name_equals (&port[i], port_name)) {
+			*free = TRUE;
  			return jack_port_new (client, port[i].id,
  					      client->engine);
  		}
@@ -510,6 +519,7 @@ jack_port_by_name (jack_client_t *client,  const 
char *port_name)
  {
  	JSList *node;
  	jack_port_t* port;
+	int need_free = FALSE;
  	for (node = client->ports_ext; node; node = jack_slist_next (node)) {
  		port = node->data;
  		if (jack_port_name_equals (port->shared, port_name)) {
@@ -518,10 +528,10 @@ jack_port_by_name (jack_client_t *client,  const 
char *port_name)
  		}
  	}
  	
-	/* Otherwise allocate a new port structure, keep it in the
+	/* Otherwise possibly allocate a new port structure, keep it in the
  	 * ports_ext list for later use. */
-	port = jack_port_by_name_int (client, port_name);
-	if (port != NULL)
+	port = jack_port_by_name_int (client, port_name, &need_free);
+	if (port != NULL && need_free)
  		client->ports_ext =
  			jack_slist_prepend (client->ports_ext, port);
  	return port;
PrevNext  Index

1421994739.21479_0.ltw:2, <54C12957.6000207 at drcomp dot erfurt dot thur dot de>