comparison pyvamp-main.cpp @ 17:5b8167619b76

* Add simple hack for preloading python on OS/X
author cannam
date Thu, 25 Jun 2009 16:23:30 +0000
parents acaa8ff2c606
children e9cf443b18f5
comparison
equal deleted inserted replaced
16:acaa8ff2c606 17:5b8167619b76
121 return true; 121 return true;
122 } 122 }
123 123
124 static bool preloadPython() 124 static bool preloadPython()
125 { 125 {
126 // Linux-specific 126 // useless on Windows
127 127
128 string pyver = Py_GetVersion(); 128 string pyver = Py_GetVersion();
129 int dots = 2; 129 int dots = 2;
130 string shortver; 130 string shortver;
131 for (int i = 0; i < pyver.length(); ++i) { 131 for (int i = 0; i < pyver.length(); ++i) {
145 pfxs.push_back("/usr/lib/"); 145 pfxs.push_back("/usr/lib/");
146 pfxs.push_back("/usr/local/lib/"); 146 pfxs.push_back("/usr/local/lib/");
147 char buffer[5]; 147 char buffer[5];
148 148
149 // hahaha! grossness is like a brother to us 149 // hahaha! grossness is like a brother to us
150 #ifdef __APPLE__
151 for (int pfxidx = 0; pfxidx < pfxs.size(); ++pfxidx) {
152 for (int minor = 8; minor >= 0; --minor) {
153 sprintf(buffer, "%d", minor);
154 if (tryPreload(pfxs[pfxidx] + string("libpython") + shortver + ".dylib." + buffer)) return true;
155 }
156 if (tryPreload(pfxs[pfxidx] + string("libpython") + shortver + ".dylib")) return true;
157 if (tryPreload(pfxs[pfxidx] + string("libpython.dylib"))) return true;
158 }
159 #else
150 for (int pfxidx = 0; pfxidx < pfxs.size(); ++pfxidx) { 160 for (int pfxidx = 0; pfxidx < pfxs.size(); ++pfxidx) {
151 for (int minor = 8; minor >= 0; --minor) { 161 for (int minor = 8; minor >= 0; --minor) {
152 sprintf(buffer, "%d", minor); 162 sprintf(buffer, "%d", minor);
153 if (tryPreload(pfxs[pfxidx] + string("libpython") + shortver + ".so." + buffer)) return true; 163 if (tryPreload(pfxs[pfxidx] + string("libpython") + shortver + ".so." + buffer)) return true;
154 } 164 }
155 if (tryPreload(pfxs[pfxidx] + string("libpython") + shortver + ".so")) return true; 165 if (tryPreload(pfxs[pfxidx] + string("libpython") + shortver + ".so")) return true;
156 if (tryPreload(pfxs[pfxidx] + string("libpython.so"))) return true; 166 if (tryPreload(pfxs[pfxidx] + string("libpython.so"))) return true;
157 } 167 }
168 #endif
158 169
159 return false; 170 return false;
160 } 171 }
161 172
162 173