Csound Csound-dev Csound-tekno Search About

[Csnd-dev] Python Opcodes and Library Loading

Date2016-09-22 20:29
FromSteven Yi
Subject[Csnd-dev] Python Opcodes and Library Loading
Hi All,

I took a look at csmodules.c and I wonder if this could be a cause of the issue:

PUBLIC int csoundOpenLibrary(void **library, const char *libraryPath)
{
    int flg = RTLD_NOW;
    if (libraryPath != NULL) {
      int len = (int) strlen(libraryPath);
      /* ugly hack to fix importing modules in Python opcodes */
      if (len >= 9 && strcmp(&(libraryPath[len - 9]), "/libpy.so") == 0)
        flg |= RTLD_GLOBAL;
    }
    *library = (void*) dlopen(libraryPath, flg);
    return (*library != NULL ? 0 : -1);
}

Note the "ugly hack" comment.  Also note that the it explicitly
contains .so in the name. If the issue Oeyvind and Rory reported is
only happening on OSX, it could be that this hack needs application to
the libpy.dylib that Csound loads.

Could someone on OSX give this a try?

Date2016-09-22 20:31
FromVictor Lazzarini
SubjectRe: [Csnd-dev] Python Opcodes and Library Loading
Are they having trouble importing modules?

Victor Lazzarini
Dean of Arts, Celtic Studies, and Philosophy
Maynooth University
Ireland

> On 22 Sep 2016, at 20:29, Steven Yi  wrote:
> 
> Hi All,
> 
> I took a look at csmodules.c and I wonder if this could be a cause of the issue:
> 
> PUBLIC int csoundOpenLibrary(void **library, const char *libraryPath)
> {
>    int flg = RTLD_NOW;
>    if (libraryPath != NULL) {
>      int len = (int) strlen(libraryPath);
>      /* ugly hack to fix importing modules in Python opcodes */
>      if (len >= 9 && strcmp(&(libraryPath[len - 9]), "/libpy.so") == 0)
>        flg |= RTLD_GLOBAL;
>    }
>    *library = (void*) dlopen(libraryPath, flg);
>    return (*library != NULL ? 0 : -1);
> }
> 
> Note the "ugly hack" comment.  Also note that the it explicitly
> contains .so in the name. If the issue Oeyvind and Rory reported is
> only happening on OSX, it could be that this hack needs application to
> the libpy.dylib that Csound loads.
> 
> Could someone on OSX give this a try?
> 

Date2016-09-22 20:44
FromOeyvind Brandtsegg
SubjectRe: [Csnd-dev] Python Opcodes and Library Loading
The initial report came from me, but I'm not on OSX myself, so not 100% sure,
but afaicr it only happens when the Python code resides in an external
(py) file.
The py file would then be imported like a module yes.

2016-09-22 12:31 GMT-07:00 Victor Lazzarini :
> Are they having trouble importing modules?
>
> Victor Lazzarini
> Dean of Arts, Celtic Studies, and Philosophy
> Maynooth University
> Ireland
>
>> On 22 Sep 2016, at 20:29, Steven Yi  wrote:
>>
>> Hi All,
>>
>> I took a look at csmodules.c and I wonder if this could be a cause of the issue:
>>
>> PUBLIC int csoundOpenLibrary(void **library, const char *libraryPath)
>> {
>>    int flg = RTLD_NOW;
>>    if (libraryPath != NULL) {
>>      int len = (int) strlen(libraryPath);
>>      /* ugly hack to fix importing modules in Python opcodes */
>>      if (len >= 9 && strcmp(&(libraryPath[len - 9]), "/libpy.so") == 0)
>>        flg |= RTLD_GLOBAL;
>>    }
>>    *library = (void*) dlopen(libraryPath, flg);
>>    return (*library != NULL ? 0 : -1);
>> }
>>
>> Note the "ugly hack" comment.  Also note that the it explicitly
>> contains .so in the name. If the issue Oeyvind and Rory reported is
>> only happening on OSX, it could be that this hack needs application to
>> the libpy.dylib that Csound loads.
>>
>> Could someone on OSX give this a try?
>>
>> steven



-- 

Oeyvind Brandtsegg
Professor of Music Technology
NTNU
7491 Trondheim
Norway
Cell: +47 92 203 205

http://www.partikkelaudio.com/
http://soundcloud.com/brandtsegg
http://flyndresang.no/

Date2016-09-22 20:50
FromTarmo Johannes
SubjectRe: [Csnd-dev] Python Opcodes and Library Loading
Thanks for pointing it out, that was it! On OSX it works now. 

I had installed Csound before the release to check CsoundQt against it and forgot it was somewhat pre-release version.

I will check later for Windows, if there is a newer installer, too that I have.

Gratefully,
tarmo

2016-09-22 15:31 GMT-04:00 Victor Lazzarini <Victor.Lazzarini@nuim.ie>:
Are they having trouble importing modules?

Victor Lazzarini
Dean of Arts, Celtic Studies, and Philosophy
Maynooth University
Ireland

> On 22 Sep 2016, at 20:29, Steven Yi <stevenyi@GMAIL.COM> wrote:
>
> Hi All,
>
> I took a look at csmodules.c and I wonder if this could be a cause of the issue:
>
> PUBLIC int csoundOpenLibrary(void **library, const char *libraryPath)
> {
>    int flg = RTLD_NOW;
>    if (libraryPath != NULL) {
>      int len = (int) strlen(libraryPath);
>      /* ugly hack to fix importing modules in Python opcodes */
>      if (len >= 9 && strcmp(&(libraryPath[len - 9]), "/libpy.so") == 0)
>        flg |= RTLD_GLOBAL;
>    }
>    *library = (void*) dlopen(libraryPath, flg);
>    return (*library != NULL ? 0 : -1);
> }
>
> Note the "ugly hack" comment.  Also note that the it explicitly
> contains .so in the name. If the issue Oeyvind and Rory reported is
> only happening on OSX, it could be that this hack needs application to
> the libpy.dylib that Csound loads.
>
> Could someone on OSX give this a try?
>
> steven


Date2016-09-22 21:05
FromVictor Lazzarini
SubjectRe: [Csnd-dev] Python Opcodes and Library Loading
Ok, so it's something we can try. I can fire off a package from develop for one of you to try tomorrow, if you wish.

Victor Lazzarini
Dean of Arts, Celtic Studies, and Philosophy
Maynooth University
Ireland

> On 22 Sep 2016, at 20:44, Oeyvind Brandtsegg  wrote:
> 
> The initial report came from me, but I'm not on OSX myself, so not 100% sure,
> but afaicr it only happens when the Python code resides in an external
> (py) file.
> The py file would then be imported like a module yes.
> 
> 2016-09-22 12:31 GMT-07:00 Victor Lazzarini :
>> Are they having trouble importing modules?
>> 
>> Victor Lazzarini
>> Dean of Arts, Celtic Studies, and Philosophy
>> Maynooth University
>> Ireland
>> 
>>> On 22 Sep 2016, at 20:29, Steven Yi  wrote:
>>> 
>>> Hi All,
>>> 
>>> I took a look at csmodules.c and I wonder if this could be a cause of the issue:
>>> 
>>> PUBLIC int csoundOpenLibrary(void **library, const char *libraryPath)
>>> {
>>>   int flg = RTLD_NOW;
>>>   if (libraryPath != NULL) {
>>>     int len = (int) strlen(libraryPath);
>>>     /* ugly hack to fix importing modules in Python opcodes */
>>>     if (len >= 9 && strcmp(&(libraryPath[len - 9]), "/libpy.so") == 0)
>>>       flg |= RTLD_GLOBAL;
>>>   }
>>>   *library = (void*) dlopen(libraryPath, flg);
>>>   return (*library != NULL ? 0 : -1);
>>> }
>>> 
>>> Note the "ugly hack" comment.  Also note that the it explicitly
>>> contains .so in the name. If the issue Oeyvind and Rory reported is
>>> only happening on OSX, it could be that this hack needs application to
>>> the libpy.dylib that Csound loads.
>>> 
>>> Could someone on OSX give this a try?
>>> 
>>> steven
> 
> 
> 
> -- 
> 
> Oeyvind Brandtsegg
> Professor of Music Technology
> NTNU
> 7491 Trondheim
> Norway
> Cell: +47 92 203 205
> 
> http://www.partikkelaudio.com/
> http://soundcloud.com/brandtsegg
> http://flyndresang.no/

Date2016-09-22 22:19
FromRory Walsh
SubjectRe: [Csnd-dev] Python Opcodes and Library Loading
That would be great. Just send us on the link and I will try it here. 

On 22 September 2016 at 21:05, Victor Lazzarini <Victor.Lazzarini@nuim.ie> wrote:
Ok, so it's something we can try. I can fire off a package from develop for one of you to try tomorrow, if you wish.

Victor Lazzarini
Dean of Arts, Celtic Studies, and Philosophy
Maynooth University
Ireland

> On 22 Sep 2016, at 20:44, Oeyvind Brandtsegg <oyvind.brandtsegg@NTNU.NO> wrote:
>
> The initial report came from me, but I'm not on OSX myself, so not 100% sure,
> but afaicr it only happens when the Python code resides in an external
> (py) file.
> The py file would then be imported like a module yes.
>
> 2016-09-22 12:31 GMT-07:00 Victor Lazzarini <Victor.Lazzarini@nuim.ie>:
>> Are they having trouble importing modules?
>>
>> Victor Lazzarini
>> Dean of Arts, Celtic Studies, and Philosophy
>> Maynooth University
>> Ireland
>>
>>> On 22 Sep 2016, at 20:29, Steven Yi <stevenyi@GMAIL.COM> wrote:
>>>
>>> Hi All,
>>>
>>> I took a look at csmodules.c and I wonder if this could be a cause of the issue:
>>>
>>> PUBLIC int csoundOpenLibrary(void **library, const char *libraryPath)
>>> {
>>>   int flg = RTLD_NOW;
>>>   if (libraryPath != NULL) {
>>>     int len = (int) strlen(libraryPath);
>>>     /* ugly hack to fix importing modules in Python opcodes */
>>>     if (len >= 9 && strcmp(&(libraryPath[len - 9]), "/libpy.so") == 0)
>>>       flg |= RTLD_GLOBAL;
>>>   }
>>>   *library = (void*) dlopen(libraryPath, flg);
>>>   return (*library != NULL ? 0 : -1);
>>> }
>>>
>>> Note the "ugly hack" comment.  Also note that the it explicitly
>>> contains .so in the name. If the issue Oeyvind and Rory reported is
>>> only happening on OSX, it could be that this hack needs application to
>>> the libpy.dylib that Csound loads.
>>>
>>> Could someone on OSX give this a try?
>>>
>>> steven
>
>
>
> --
>
> Oeyvind Brandtsegg
> Professor of Music Technology
> NTNU
> 7491 Trondheim
> Norway
> Cell: +47 92 203 205
>
> http://www.partikkelaudio.com/
> http://soundcloud.com/brandtsegg
> http://flyndresang.no/
> http://soundcloud.com/t-emp