igormarfin / shedskin

Automatically exported from code.google.com/p/shedskin
0 stars 0 forks source link

"getloadavg()" undefined under Cygwin #111

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. Python program with "import os", using some OS fn, but not "getloadavg"
2. Run ShedSkin on said program.

What is the expected output? What do you see instead?

$ make
g++  -O2 -msse2 -fomit-frame-pointer -pipe -Wno-deprecated  -I. 
-I/home/nagle/shedskin/shedskin-0.6/shedskin/lib /home/nagle/shedski
n/shedskin-0.6/shedskin/lib/stat.cpp rfc822.cpp rfc822date.cpp 
/home/nagle/shedskin/shedskin-0.6/shedskin/lib/sys.cpp /home/nagle/sh
edskin/shedskin-0.6/shedskin/lib/builtin.cpp 
/home/nagle/shedskin/shedskin-0.6/shedskin/lib/time.cpp 
/home/nagle/shedskin/shedskin-0
.6/shedskin/lib/os/__init__.cpp 
/home/nagle/shedskin/shedskin-0.6/shedskin/lib/os/path.cpp 
/home/nagle/shedskin/shedskin-0.6/shedski
n/lib/re.cpp -lgc -lpcre  -lutil -o rfc822
/home/nagle/shedskin/shedskin-0.6/shedskin/lib/os/__init__.cpp: In function 
`__shedskin__::tuple2<double, double>* __os__::getloadav
g()':
/home/nagle/shedskin/shedskin-0.6/shedskin/lib/os/__init__.cpp:857: error: 
`::getloadavg' has not been declared
make: *** [rfc822] Error 1

What version of the product are you using? On what operating system?

ShedSkin 0.6 on Cygwin on Windows 7.

Please provide any additional information below.

Windows doesn't offer anything comparable to "getloadavg", and Cygwin doesn't 
even try to fake it.  "getloadavg()" is simply undefined on Cygwin.  This is 
the only thing so far I've found that gives Shed Skin a problem under Cygwin. 

Suggested fix to "lib/os/__init__.cpp: 

#ifndef __CYGWIN__  // unsupported on Cygwin.
tuple2<double, double> *getloadavg() {
    double load[3];
    if(::getloadavg(load, 3) != 3)
        throw new OSError(new str("os.getloadavg"));
    return new tuple2<double, double>(3, load[0], load[1], load[2]);
}
#endif // CYGWIN

A more elegant solution would be to throw an "unimplemented" exception.

Original issue reported on code.google.com by na...@animats.com on 10 Nov 2010 at 3:46

GoogleCodeExporter commented 8 years ago
thanks.. :-) there are a few more functions that are not supported under 
Windows. I guess CPython also throws an unimplemented exception here? we really 
should try to follow CPython as closely as possible, so for example, if it 
returns bogus values here, we should do that too.

Original comment by mark.duf...@gmail.com on 10 Nov 2010 at 9:21

GoogleCodeExporter commented 8 years ago
CPython on Cygwin returns

$ python testgetloadavg.py
Traceback (most recent call last):
  File "testgetloadavg.py", line 2, in <module>
    avgs = os.getloadavg()
AttributeError: 'module' object has no attribute 'getloadavg'

Same thing happens with CPython 2.6 on Windows, without Cygwin.

That's consistent with the documentation, which says "Availablity: UNIX".

It's not a very useful function. The problem is that importing the "os" module 
produces a linker error on Cygwin, even if this function isn't being used.  So 
just making the definition of the function conditional on platform is 
consistent. 

Original comment by na...@animats.com on 11 Nov 2010 at 6:12

GoogleCodeExporter commented 8 years ago
this issue was marked as an 'easy task' in the wiki section.

Original comment by mark.duf...@gmail.com on 14 Nov 2010 at 12:00

GoogleCodeExporter commented 8 years ago
note that the new windows version for 0.7 (packaged with mingw) does not have 
this problem.

Original comment by mark.duf...@gmail.com on 11 Dec 2010 at 10:57

GoogleCodeExporter commented 8 years ago
okay, decided to raise a NotImplementedError for cygwin here, as you suggest. 
thanks!

Original comment by mark.duf...@gmail.com on 22 Jul 2011 at 6:45